diff options
author | Owen Taylor <otaylor@redhat.com> | 2002-02-13 20:54:11 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2002-02-13 20:54:11 +0000 |
commit | 803a1f6fbcbad1f3006681d0b8ac0748bbe61746 (patch) | |
tree | d2019558d71c7cce73c57ef63ed03f84a32f1d14 /gtk/gtktooltips.c | |
parent | 6b838a22d1e55ed50d079f7a7eca8afdd3714ddc (diff) | |
download | gtk+-803a1f6fbcbad1f3006681d0b8ac0748bbe61746.tar.gz |
Implement Control-F1 as toggle-tooltips-mode.
Wed Feb 13 15:42:42 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtktooltips.[ch] gtkwidget.c: Implement Control-F1
as toggle-tooltips-mode.
* gtk/gtktooltips.c: Remove parsing of tooltips style
string from here ... now in gtkrc.c.
Diffstat (limited to 'gtk/gtktooltips.c')
-rw-r--r-- | gtk/gtktooltips.c | 232 |
1 files changed, 151 insertions, 81 deletions
diff --git a/gtk/gtktooltips.c b/gtk/gtktooltips.c index ec4c21d808..04a46d0664 100644 --- a/gtk/gtktooltips.c +++ b/gtk/gtktooltips.c @@ -49,7 +49,7 @@ static void gtk_tooltips_class_init (GtkTooltipsClass *klass); static void gtk_tooltips_init (GtkTooltips *tooltips); static void gtk_tooltips_destroy (GtkObject *object); -static gint gtk_tooltips_event_handler (GtkWidget *widget, +static void gtk_tooltips_event_handler (GtkWidget *widget, GdkEvent *event); static void gtk_tooltips_widget_unmap (GtkWidget *widget, gpointer data); @@ -62,6 +62,8 @@ static gint gtk_tooltips_timeout (gpointer data); static gint gtk_tooltips_paint_window (GtkTooltips *tooltips); static void gtk_tooltips_draw_tips (GtkTooltips *tooltips); +static gboolean get_keyboard_mode (GtkWidget *widget); + static GtkObjectClass *parent_class; static const gchar *tooltips_data_key = "_GtkTooltipsData"; @@ -104,19 +106,6 @@ gtk_tooltips_class_init (GtkTooltipsClass *class) static void gtk_tooltips_init (GtkTooltips *tooltips) { - static gboolean have_rc = FALSE; - if (!have_rc) - { - have_rc = TRUE; - - gtk_rc_parse_string ("style \"gtk-default-tooltips-style\" {\n" - " bg[NORMAL] = \"#ffffc0\"\n" - " fg[NORMAL] = \"#000000\"\n" - "}\n" - "\n" - "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-style\"\n"); - } - tooltips->tip_window = NULL; tooltips->active_tips_data = NULL; tooltips->tips_data_list = NULL; @@ -293,7 +282,7 @@ gtk_tooltips_set_tip (GtkTooltips *tooltips, tooltips->tips_data_list = g_list_append (tooltips->tips_data_list, tooltipsdata); - gtk_signal_connect_after (GTK_OBJECT (widget), "event", + gtk_signal_connect_after (GTK_OBJECT (widget), "event-after", (GtkSignalFunc) gtk_tooltips_event_handler, tooltipsdata); @@ -326,13 +315,14 @@ gtk_tooltips_paint_window (GtkTooltips *tooltips) } static void -gtk_tooltips_draw_tips (GtkTooltips * tooltips) +gtk_tooltips_draw_tips (GtkTooltips *tooltips) { GtkRequisition requisition; GtkWidget *widget; GtkStyle *style; gint x, y, w, h, scr_w, scr_h; GtkTooltipsData *data; + gboolean keyboard_mode; if (!tooltips->tip_window) gtk_tooltips_force_window (tooltips); @@ -344,6 +334,8 @@ gtk_tooltips_draw_tips (GtkTooltips * tooltips) widget = tooltips->active_tips_data->widget; + keyboard_mode = get_keyboard_mode (widget); + scr_w = gdk_screen_width (); scr_h = gdk_screen_height (); @@ -355,10 +347,17 @@ gtk_tooltips_draw_tips (GtkTooltips * tooltips) w = requisition.width; h = requisition.height; - gdk_window_get_pointer (NULL, &x, NULL, NULL); - gdk_window_get_origin (widget->window, NULL, &y); + gdk_window_get_origin (widget->window, &x, &y); if (GTK_WIDGET_NO_WINDOW (widget)) - y += widget->allocation.y; + { + x += widget->allocation.x; + y += widget->allocation.y; + } + + x += widget->allocation.width / 2; + + if (!keyboard_mode) + gdk_window_get_pointer (NULL, &x, NULL, NULL); x -= (w / 2 + 4); @@ -434,6 +433,35 @@ gtk_tooltips_set_active_widget (GtkTooltips *tooltips, } } +static void +gtk_tooltips_show_tip (GtkWidget *widget) +{ + GtkTooltipsData *tooltipsdata; + + tooltipsdata = gtk_tooltips_data_get (widget); + + if (tooltipsdata && + (!tooltipsdata->tooltips->active_tips_data || + tooltipsdata->tooltips->active_tips_data->widget != widget)) + { + gtk_tooltips_set_active_widget (tooltipsdata->tooltips, widget); + gtk_tooltips_draw_tips (tooltipsdata->tooltips); + } +} + +static void +gtk_tooltips_hide_tip (GtkWidget *widget) +{ + GtkTooltipsData *tooltipsdata; + + tooltipsdata = gtk_tooltips_data_get (widget); + + if (tooltipsdata && + (tooltipsdata->tooltips->active_tips_data && + tooltipsdata->tooltips->active_tips_data->widget == widget)) + gtk_tooltips_set_active_widget (tooltipsdata->tooltips, NULL); +} + static gboolean gtk_tooltips_recently_shown (GtkTooltips *tooltips) { @@ -446,67 +474,122 @@ gtk_tooltips_recently_shown (GtkTooltips *tooltips) return (msec < STICKY_REVERT_DELAY); } -static gint +static gboolean +get_keyboard_mode (GtkWidget *widget) +{ + GtkWidget *toplevel = gtk_widget_get_toplevel (widget); + if (GTK_IS_WINDOW (toplevel)) + return GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (toplevel), "gtk-tooltips-keyboard-mode")); + else + return FALSE; +} + +static void +start_keyboard_mode (GtkWidget *widget) +{ + GtkWidget *toplevel = gtk_widget_get_toplevel (widget); + if (GTK_IS_WINDOW (toplevel)) + { + GtkWidget *focus = GTK_WINDOW (toplevel)->focus_widget; + if (focus) + gtk_tooltips_show_tip (focus); + + g_object_set_data (G_OBJECT (toplevel), "gtk-tooltips-keyboard-mode", GUINT_TO_POINTER (TRUE)); + } +} + +static void +stop_keyboard_mode (GtkWidget *widget) +{ + GtkWidget *toplevel = gtk_widget_get_toplevel (widget); + if (GTK_IS_WINDOW (toplevel)) + { + GtkWidget *focus = GTK_WINDOW (toplevel)->focus_widget; + if (focus) + gtk_tooltips_hide_tip (focus); + + g_object_set_data (G_OBJECT (toplevel), "gtk-tooltips-keyboard-mode", GUINT_TO_POINTER (FALSE)); + } +} + +static void gtk_tooltips_event_handler (GtkWidget *widget, GdkEvent *event) { GtkTooltips *tooltips; GtkTooltipsData *old_tips_data; GtkWidget *event_widget; + gboolean keyboard_mode = get_keyboard_mode (widget); if ((event->type == GDK_LEAVE_NOTIFY || event->type == GDK_ENTER_NOTIFY) && event->crossing.detail == GDK_NOTIFY_INFERIOR) return FALSE; - event_widget = gtk_get_event_widget (event); - if (event_widget != widget) - return FALSE; - old_tips_data = gtk_tooltips_data_get (widget); tooltips = old_tips_data->tooltips; - switch (event->type) + if (keyboard_mode) { - case GDK_MOTION_NOTIFY: - case GDK_EXPOSE: - /* do nothing */ - break; - - case GDK_ENTER_NOTIFY: - old_tips_data = tooltips->active_tips_data; - if (tooltips->enabled && - (!old_tips_data || old_tips_data->widget != widget)) + switch (event->type) { - guint delay; - - gtk_tooltips_set_active_widget (tooltips, widget); + case GDK_FOCUS_CHANGE: + if (event->focus_change.in) + gtk_tooltips_show_tip (widget); + else + gtk_tooltips_hide_tip (widget); + break; + default: + break; + } + } + else + { + event_widget = gtk_get_event_widget (event); + if (event_widget != widget) + return FALSE; + + switch (event->type) + { + case GDK_MOTION_NOTIFY: + case GDK_EXPOSE: + /* do nothing */ + break; - if (tooltips->use_sticky_delay && + case GDK_ENTER_NOTIFY: + old_tips_data = tooltips->active_tips_data; + if (tooltips->enabled && + (!old_tips_data || old_tips_data->widget != widget)) + { + guint delay; + + gtk_tooltips_set_active_widget (tooltips, widget); + + if (tooltips->use_sticky_delay && gtk_tooltips_recently_shown (tooltips)) - delay = STICKY_DELAY; - else - delay = tooltips->delay; - tooltips->timer_tag = gtk_timeout_add (delay, - gtk_tooltips_timeout, - (gpointer) tooltips); + delay = STICKY_DELAY; + else + delay = tooltips->delay; + tooltips->timer_tag = gtk_timeout_add (delay, + gtk_tooltips_timeout, + (gpointer) tooltips); + } + break; + + case GDK_LEAVE_NOTIFY: + { + gboolean use_sticky_delay; + + use_sticky_delay = tooltips->tip_window && + GTK_WIDGET_VISIBLE (tooltips->tip_window); + gtk_tooltips_set_active_widget (tooltips, NULL); + tooltips->use_sticky_delay = use_sticky_delay; + } + break; + + default: + gtk_tooltips_set_active_widget (tooltips, NULL); + break; } - break; - - case GDK_LEAVE_NOTIFY: - { - gboolean use_sticky_delay; - - use_sticky_delay = tooltips->tip_window && - GTK_WIDGET_VISIBLE (tooltips->tip_window); - gtk_tooltips_set_active_widget (tooltips, NULL); - tooltips->use_sticky_delay = use_sticky_delay; - } - break; - - default: - gtk_tooltips_set_active_widget (tooltips, NULL); - return FALSE; - break; } return FALSE; @@ -537,25 +620,12 @@ gtk_tooltips_widget_remove (GtkWidget *widget, gtk_tooltips_destroy_data (tooltipsdata); } -gboolean -_gtk_tooltips_show_tip (GtkWidget *widget) +void +_gtk_tooltips_toggle_keyboard_mode (GtkWidget *widget) { - /* Showing the tip from the keyboard */ - - /* FIXME this function is completely broken right now, - * popdown doesn't occur when it should. - */ - - GtkTooltipsData *tooltipsdata; - - tooltipsdata = gtk_tooltips_data_get (widget); - - if (tooltipsdata == NULL) - return FALSE; - - gtk_tooltips_set_active_widget (tooltipsdata->tooltips, - widget); - - gtk_tooltips_timeout (tooltipsdata->tooltips); - return TRUE; + if (get_keyboard_mode (widget)) + stop_keyboard_mode (widget); + else + start_keyboard_mode (widget); } + |