From c255676e25b2aac01c8e9c2dcf65de5c909a4613 Mon Sep 17 00:00:00 2001 From: Kristian Rietveld Date: Mon, 9 Jul 2007 19:23:18 +0000 Subject: [PATCH] Replace non-deprecated API using old tooltips API, deprecate old tooltips 2007-07-09 Kristian Rietveld Replace non-deprecated API using old tooltips API, deprecate old tooltips API for real. (#451575). * gtk/gtk.symbols: updated. * gtk/gtkwidget.c (gtk_widget_real_show_help): don't call _gtk_tooltips_toggle_keyboard_mode() anymore. * gtk/gtkmenutoolbutton.[ch] (gtk_menu_tool_button_set_arrow_tooltip): deprecated, (gtk_menu_tool_button_set_arrow_tooltip_{text,markup}): replacements. * gtk/gtktoolitem.[ch] (gtk_tool_item_real_set_tooltip): use new API, (gtk_tool_item_set_tooltip): deprecated, (gtk_tool_item_set_tooltip_{text,markup): replacements. (GtkToolItemClass:set_tooltip): deprecated. * gtk/gtktooltips.[ch]: strip out all unused parts, made gtk_tooltips_set_tip() call gtk_widget_set_tooltip_text(), deprecate all of gtk_tooltips_*. * gtk/gtktoolbar.[ch] (gtk_toolbar_get_tooltips): always return TRUE, (GtkToolbar:tooltips): deprecated, renamed. * gtk/gtkaction.c (gtk_action_sync_tooltip): use new API to set the tooltip text. * tests/autotestfilechooser.c: #undef GTK_DISABLE_DEPRECATED for now, will be removed GtkFileChooserDefault has been converted. svn path=/trunk/; revision=18418 --- ChangeLog | 34 +++ gtk/gtk.symbols | 8 + gtk/gtkaction.c | 6 +- gtk/gtkmenutoolbutton.c | 43 +++ gtk/gtkmenutoolbutton.h | 7 + gtk/gtktoolbar.c | 2 +- gtk/gtktoolbar.h | 4 + gtk/gtktoolitem.c | 52 +++- gtk/gtktoolitem.h | 10 + gtk/gtktooltips.c | 502 +----------------------------------- gtk/gtktooltips.h | 9 +- gtk/gtkwidget.c | 1 - tests/autotestfilechooser.c | 1 + 13 files changed, 167 insertions(+), 512 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8316796246..6655d47db9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,37 @@ +2007-07-09 Kristian Rietveld + + Replace non-deprecated API using old tooltips API, deprecate + old tooltips API for real. (#451575). + + * gtk/gtk.symbols: updated. + + * gtk/gtkwidget.c (gtk_widget_real_show_help): don't call + _gtk_tooltips_toggle_keyboard_mode() anymore. + + * gtk/gtkmenutoolbutton.[ch] (gtk_menu_tool_button_set_arrow_tooltip): + deprecated, + (gtk_menu_tool_button_set_arrow_tooltip_{text,markup}): replacements. + + * gtk/gtktoolitem.[ch] (gtk_tool_item_real_set_tooltip): use + new API, + (gtk_tool_item_set_tooltip): deprecated, + (gtk_tool_item_set_tooltip_{text,markup): replacements. + (GtkToolItemClass:set_tooltip): deprecated. + + * gtk/gtktooltips.[ch]: strip out all unused parts, made + gtk_tooltips_set_tip() call gtk_widget_set_tooltip_text(), + deprecate all of gtk_tooltips_*. + + * gtk/gtktoolbar.[ch] (gtk_toolbar_get_tooltips): always return + TRUE, + (GtkToolbar:tooltips): deprecated, renamed. + + * gtk/gtkaction.c (gtk_action_sync_tooltip): use new API to + set the tooltip text. + + * tests/autotestfilechooser.c: #undef GTK_DISABLE_DEPRECATED for now, + will be removed GtkFileChooserDefault has been converted. + 2007-07-09 Matthias Clasen * gtk/gtktreeview.c diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 5e643261fb..e0ca78f1ab 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -2361,7 +2361,11 @@ gtk_menu_tool_button_get_menu gtk_menu_tool_button_get_type G_GNUC_CONST gtk_menu_tool_button_new gtk_menu_tool_button_new_from_stock +#ifndef GTK_DISABLE_DEPRECATED gtk_menu_tool_button_set_arrow_tooltip +#endif +gtk_menu_tool_button_set_arrow_tooltip_markup +gtk_menu_tool_button_set_arrow_tooltip_text gtk_menu_tool_button_set_menu #endif #endif @@ -4055,7 +4059,11 @@ gtk_tool_item_set_expand gtk_tool_item_set_homogeneous gtk_tool_item_set_is_important gtk_tool_item_set_proxy_menu_item +#ifndef GTK_DISABLE_DEPRECATED gtk_tool_item_set_tooltip +#endif +gtk_tool_item_set_tooltip_markup +gtk_tool_item_set_tooltip_text gtk_tool_item_set_use_drag_window gtk_tool_item_set_visible_horizontal gtk_tool_item_set_visible_vertical diff --git a/gtk/gtkaction.c b/gtk/gtkaction.c index f1b161820e..5c257a5bac 100644 --- a/gtk/gtkaction.c +++ b/gtk/gtkaction.c @@ -1456,10 +1456,8 @@ gtk_action_sync_tooltip (GtkAction *action, parent = gtk_widget_get_parent (proxy); if (GTK_IS_TOOL_ITEM (proxy) && GTK_IS_TOOLBAR (parent)) - gtk_tool_item_set_tooltip (GTK_TOOL_ITEM (proxy), - GTK_TOOLBAR (parent)->tooltips, - action->private_data->tooltip, - NULL); + gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (proxy), + action->private_data->tooltip); } static void diff --git a/gtk/gtkmenutoolbutton.c b/gtk/gtkmenutoolbutton.c index 70ccc1a517..fd43b7e971 100644 --- a/gtk/gtkmenutoolbutton.c +++ b/gtk/gtkmenutoolbutton.c @@ -596,6 +596,9 @@ gtk_menu_tool_button_get_menu (GtkMenuToolButton *button) * a tooltip on the whole #GtkMenuToolButton. * * Since: 2.6 + * + * Deprecated: 2.12: Use gtk_menu_tool_button_set_arrow_tooltip_text() + * instead. **/ void gtk_menu_tool_button_set_arrow_tooltip (GtkMenuToolButton *button, @@ -608,5 +611,45 @@ gtk_menu_tool_button_set_arrow_tooltip (GtkMenuToolButton *button, gtk_tooltips_set_tip (tooltips, button->priv->arrow_button, tip_text, tip_private); } +/** + * gtk_menu_tool_button_set_arrow_tooltip_text: + * @button: a #GtkMenuToolButton + * @text: text to be used as tooltip text for button's arrow button + * + * Sets the tooltip text to be used as tooltip for the arrow button which + * pops up the menu. See gtk_tool_item_set_tooltip() for setting a tooltip + * on the whole #GtkMenuToolButton. + * + * Since: 2.12 + **/ +void +gtk_menu_tool_button_set_arrow_tooltip_text (GtkMenuToolButton *button, + const gchar *text) +{ + g_return_if_fail (GTK_IS_MENU_TOOL_BUTTON (button)); + + gtk_widget_set_tooltip_text (button->priv->arrow_button, text); +} + +/** + * gtk_menu_tool_button_set_arrow_tooltip_markup: + * @button: a #GtkMenuToolButton + * @markup: markup text to be used as tooltip text for button's arrow button + * + * Sets the tooltip markup text to be used as tooltip for the arrow button + * which pops up the menu. See gtk_tool_item_set_tooltip() for setting a + * tooltip on the whole #GtkMenuToolButton. + * + * Since: 2.12 + **/ +void +gtk_menu_tool_button_set_arrow_tooltip_markup (GtkMenuToolButton *button, + const gchar *markup) +{ + g_return_if_fail (GTK_IS_MENU_TOOL_BUTTON (button)); + + gtk_widget_set_tooltip_markup (button->priv->arrow_button, markup); +} + #define __GTK_MENU_TOOL_BUTTON_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkmenutoolbutton.h b/gtk/gtkmenutoolbutton.h index b1e87ed52f..4eb860e317 100644 --- a/gtk/gtkmenutoolbutton.h +++ b/gtk/gtkmenutoolbutton.h @@ -68,10 +68,17 @@ void gtk_menu_tool_button_set_menu (GtkMenuToolButton *button, GtkWidget *menu); GtkWidget *gtk_menu_tool_button_get_menu (GtkMenuToolButton *button); +#ifndef GTK_DISABLE_DEPRECATED void gtk_menu_tool_button_set_arrow_tooltip (GtkMenuToolButton *button, GtkTooltips *tooltips, const gchar *tip_text, const gchar *tip_private); +#endif /* GTK_DISABLE_DEPRECATED */ + +void gtk_menu_tool_button_set_arrow_tooltip_text (GtkMenuToolButton *button, + const gchar *text); +void gtk_menu_tool_button_set_arrow_tooltip_markup (GtkMenuToolButton *button, + const gchar *markup); G_END_DECLS diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index f27c5f459d..16f7d3dc87 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -2955,7 +2955,7 @@ gtk_toolbar_get_tooltips (GtkToolbar *toolbar) { g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE); - return toolbar->tooltips->enabled; + return TRUE; } /** diff --git a/gtk/gtktoolbar.h b/gtk/gtktoolbar.h index 24c0dde34d..dbe72a8167 100644 --- a/gtk/gtktoolbar.h +++ b/gtk/gtktoolbar.h @@ -99,7 +99,11 @@ struct _GtkToolbar GtkToolbarStyle style; GtkIconSize icon_size; +#ifndef GTK_DISABLE_DEPRECATED GtkTooltips *tooltips; +#else + gpointer _tooltips; +#endif /*< private >*/ gint button_maxw; /* maximum width of homogeneous children */ diff --git a/gtk/gtktoolitem.c b/gtk/gtktoolitem.c index d82a66b147..2ae4406fb7 100644 --- a/gtk/gtktoolitem.c +++ b/gtk/gtktoolitem.c @@ -773,7 +773,7 @@ gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item, if (!child) return FALSE; - gtk_tooltips_set_tip (tooltips, child, tip_text, tip_private); + gtk_widget_set_tooltip_text (child, tip_text); return TRUE; } @@ -790,6 +790,8 @@ gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item, * to be used. See gtk_tooltips_set_tip(). * * Since: 2.4 + * + * Deprecated: 2.12: Use gtk_tool_item_set_tooltip_text() instead. **/ void gtk_tool_item_set_tooltip (GtkToolItem *tool_item, @@ -805,6 +807,54 @@ gtk_tool_item_set_tooltip (GtkToolItem *tool_item, tooltips, tip_text, tip_private, &retval); } +/** + * gtk_tool_item_set_tooltip_text: + * @tool_item: a #GtkToolItem: + * @text: text to be used as tooltip for @tool_item + * + * Sets the text to be displayed as tooltip on the item. + * See gtk_widget_set_tooltip_text(). + * + * Since: 2.12 + **/ +void +gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item, + const gchar *text) +{ + GtkWidget *child; + + g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item)); + + child = GTK_BIN (tool_item)->child; + + if (child) + gtk_widget_set_tooltip_text (child, text); +} + +/** + * gtk_tool_item_set_tooltip_markup: + * @tool_item: a #GtkToolItem: + * @markup: markup text to be used as tooltip for @tool_item + * + * Sets the markup text to be displayed as tooltip on the item. + * See gtk_widget_set_tooltip_markup(). + * + * Since: 2.12 + **/ +void +gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item, + const gchar *markup) +{ + GtkWidget *child; + + g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item)); + + child = GTK_BIN (tool_item)->child; + + if (child) + gtk_widget_set_tooltip_markup (child, markup); +} + /** * gtk_tool_item_set_use_drag_window: * @toolitem: a #GtkToolItem diff --git a/gtk/gtktoolitem.h b/gtk/gtktoolitem.h index 10cf4711ca..3cc68a2324 100644 --- a/gtk/gtktoolitem.h +++ b/gtk/gtktoolitem.h @@ -55,10 +55,14 @@ struct _GtkToolItemClass /* signals */ gboolean (* create_menu_proxy) (GtkToolItem *tool_item); void (* toolbar_reconfigured) (GtkToolItem *tool_item); +#ifndef GTK_DISABLE_DEPRECATED gboolean (* set_tooltip) (GtkToolItem *tool_item, GtkTooltips *tooltips, const gchar *tip_text, const gchar *tip_private); +#else + gpointer _set_tooltip; +#endif /* Padding for future expansion */ void (* _gtk_reserved1) (void); @@ -78,10 +82,16 @@ void gtk_tool_item_set_expand (GtkToolItem *tool_item, gboolean expand); gboolean gtk_tool_item_get_expand (GtkToolItem *tool_item); +#ifndef GTK_DISABLE_DEPRECATED void gtk_tool_item_set_tooltip (GtkToolItem *tool_item, GtkTooltips *tooltips, const gchar *tip_text, const gchar *tip_private); +#endif /* GTK_DISABLE_DEPRECATED */ +void gtk_tool_item_set_tooltip_text (GtkToolItem *toolitem, + const gchar *text); +void gtk_tool_item_set_tooltip_markup (GtkToolItem *toolitem, + const gchar *markup); void gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem, gboolean use_drag_window); diff --git a/gtk/gtktooltips.c b/gtk/gtktooltips.c index e3e64720e7..17af2736ee 100644 --- a/gtk/gtktooltips.c +++ b/gtk/gtktooltips.c @@ -63,21 +63,8 @@ static void gtk_tooltips_destroy (GtkObject *object); static void gtk_tooltips_destroy_data (GtkTooltipsData *tooltipsdata); -static void gtk_tooltips_event_handler (GtkWidget *widget, - GdkEvent *event); -static void gtk_tooltips_widget_unmap (GtkWidget *widget, - gpointer data); static void gtk_tooltips_widget_remove (GtkWidget *widget, gpointer data); -static void gtk_tooltips_set_active_widget (GtkTooltips *tooltips, - GtkWidget *widget); -static gint gtk_tooltips_timeout (gpointer data); - -static gint gtk_tooltips_paint_window (GtkTooltips *tooltips); -static void gtk_tooltips_draw_tips (GtkTooltips *tooltips); -static void gtk_tooltips_unset_tip_window (GtkTooltips *tooltips); - -static gboolean get_keyboard_mode (GtkWidget *widget); static const gchar tooltips_data_key[] = "_GtkTooltipsData"; static const gchar tooltips_info_key[] = "_GtkTooltipsInfo"; @@ -137,17 +124,9 @@ gtk_tooltips_new (void) static void gtk_tooltips_destroy_data (GtkTooltipsData *tooltipsdata) { - gtk_tooltips_widget_unmap (tooltipsdata->widget, tooltipsdata); - g_free (tooltipsdata->tip_text); g_free (tooltipsdata->tip_private); - g_signal_handlers_disconnect_by_func (tooltipsdata->widget, - gtk_tooltips_event_handler, - tooltipsdata); - g_signal_handlers_disconnect_by_func (tooltipsdata->widget, - gtk_tooltips_widget_unmap, - tooltipsdata); g_signal_handlers_disconnect_by_func (tooltipsdata->widget, gtk_tooltips_widget_remove, tooltipsdata); @@ -157,34 +136,6 @@ gtk_tooltips_destroy_data (GtkTooltipsData *tooltipsdata) g_free (tooltipsdata); } -static void -tip_window_display_closed (GdkDisplay *display, - gboolean was_error, - GtkTooltips *tooltips) -{ - gtk_tooltips_unset_tip_window (tooltips); -} - -static void -disconnect_tip_window_display_closed (GtkTooltips *tooltips) -{ - g_signal_handlers_disconnect_by_func (gtk_widget_get_display (tooltips->tip_window), - (gpointer) tip_window_display_closed, - tooltips); -} - -static void -gtk_tooltips_unset_tip_window (GtkTooltips *tooltips) -{ - if (tooltips->tip_window) - { - disconnect_tip_window_display_closed (tooltips); - - gtk_widget_destroy (tooltips->tip_window); - tooltips->tip_window = NULL; - } -} - static void gtk_tooltips_destroy (GtkObject *object) { @@ -193,79 +144,17 @@ gtk_tooltips_destroy (GtkObject *object) g_return_if_fail (tooltips != NULL); - if (tooltips->timer_tag) - { - g_source_remove (tooltips->timer_tag); - tooltips->timer_tag = 0; - } - g_hash_table_remove_all (private->tips_data_table); - gtk_tooltips_unset_tip_window (tooltips); - GTK_OBJECT_CLASS (gtk_tooltips_parent_class)->destroy (object); } -static void -gtk_tooltips_update_screen (GtkTooltips *tooltips, - gboolean new_window) -{ - gboolean screen_changed = FALSE; - - if (tooltips->active_tips_data && - tooltips->active_tips_data->widget) - { - GdkScreen *screen = gtk_widget_get_screen (tooltips->active_tips_data->widget); - - screen_changed = (screen != gtk_widget_get_screen (tooltips->tip_window)); - - if (screen_changed) - { - if (!new_window) - disconnect_tip_window_display_closed (tooltips); - - gtk_window_set_screen (GTK_WINDOW (tooltips->tip_window), screen); - } - } - - if (screen_changed || new_window) - g_signal_connect (gtk_widget_get_display (tooltips->tip_window), "closed", - G_CALLBACK (tip_window_display_closed), tooltips); - -} - void gtk_tooltips_force_window (GtkTooltips *tooltips) { g_return_if_fail (GTK_IS_TOOLTIPS (tooltips)); - if (!tooltips->tip_window) - { - tooltips->tip_window = gtk_window_new (GTK_WINDOW_POPUP); - gtk_window_set_type_hint (GTK_WINDOW (tooltips->tip_window), GDK_WINDOW_TYPE_HINT_TOOLTIP); - gtk_tooltips_update_screen (tooltips, TRUE); - gtk_widget_set_app_paintable (tooltips->tip_window, TRUE); - gtk_window_set_resizable (GTK_WINDOW (tooltips->tip_window), FALSE); - gtk_widget_set_name (tooltips->tip_window, "gtk-tooltips"); - gtk_container_set_border_width (GTK_CONTAINER (tooltips->tip_window), 4); - - g_signal_connect_swapped (tooltips->tip_window, - "expose_event", - G_CALLBACK (gtk_tooltips_paint_window), - tooltips); - - tooltips->tip_label = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (tooltips->tip_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (tooltips->tip_label), 0.5, 0.5); - gtk_widget_show (tooltips->tip_label); - - gtk_container_add (GTK_CONTAINER (tooltips->tip_window), tooltips->tip_label); - - g_signal_connect (tooltips->tip_window, - "destroy", - G_CALLBACK (gtk_widget_destroyed), - &tooltips->tip_window); - } + /* nop */ } void @@ -281,8 +170,6 @@ gtk_tooltips_disable (GtkTooltips *tooltips) { g_return_if_fail (tooltips != NULL); - gtk_tooltips_set_active_widget (tooltips, NULL); - tooltips->enabled = FALSE; } @@ -332,8 +219,6 @@ gtk_tooltips_set_tip (GtkTooltips *tooltips, tooltipsdata->tip_text = g_strdup (tip_text); tooltipsdata->tip_private = g_strdup (tip_private); - - gtk_tooltips_draw_tips (tooltips); } else { @@ -353,389 +238,15 @@ gtk_tooltips_set_tip (GtkTooltips *tooltips, g_hash_table_insert (GTK_TOOLTIPS_GET_PRIVATE (tooltips)->tips_data_table, widget, tooltipsdata); - g_signal_connect_after (widget, "event_after", - G_CALLBACK (gtk_tooltips_event_handler), - tooltipsdata); - g_object_set_data (G_OBJECT (widget), I_(tooltips_data_key), tooltipsdata); - g_signal_connect (widget, "unmap", - G_CALLBACK (gtk_tooltips_widget_unmap), - tooltipsdata); - - g_signal_connect (widget, "unrealize", - G_CALLBACK (gtk_tooltips_widget_unmap), - tooltipsdata); - g_signal_connect (widget, "destroy", G_CALLBACK (gtk_tooltips_widget_remove), tooltipsdata); } -} -static gint -gtk_tooltips_paint_window (GtkTooltips *tooltips) -{ - GtkRequisition req; - - gtk_widget_size_request (tooltips->tip_window, &req); - gtk_paint_flat_box (tooltips->tip_window->style, tooltips->tip_window->window, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - NULL, GTK_WIDGET(tooltips->tip_window), "tooltip", - 0, 0, req.width, req.height); - - return FALSE; -} - -static void -gtk_tooltips_draw_tips (GtkTooltips *tooltips) -{ - GtkRequisition requisition; - GtkWidget *widget; - gint x, y, w, h; - GtkTooltipsData *data; - gboolean keyboard_mode; - GdkScreen *screen; - GdkScreen *pointer_screen; - gint monitor_num, px, py; - GdkRectangle monitor; - GtkWindow *toplevel; - - if (!tooltips->tip_window) - gtk_tooltips_force_window (tooltips); - else if (GTK_WIDGET_VISIBLE (tooltips->tip_window)) - g_get_current_time (&tooltips->last_popdown); - - gtk_widget_ensure_style (tooltips->tip_window); - - widget = tooltips->active_tips_data->widget; - g_object_set_data (G_OBJECT (tooltips->tip_window), I_(tooltips_info_key), - tooltips); - - keyboard_mode = get_keyboard_mode (widget); - - gtk_tooltips_update_screen (tooltips, FALSE); - - screen = gtk_widget_get_screen (widget); - - data = tooltips->active_tips_data; - - gtk_label_set_text (GTK_LABEL (tooltips->tip_label), data->tip_text); - - gtk_widget_size_request (tooltips->tip_window, &requisition); - w = requisition.width; - h = requisition.height; - - gdk_window_get_origin (widget->window, &x, &y); - if (GTK_WIDGET_NO_WINDOW (widget)) - { - x += widget->allocation.x; - y += widget->allocation.y; - } - - x += widget->allocation.width / 2; - - if (!keyboard_mode) - gdk_window_get_pointer (gdk_screen_get_root_window (screen), - &x, NULL, NULL); - - x -= (w / 2 + 4); - - gdk_display_get_pointer (gdk_screen_get_display (screen), - &pointer_screen, &px, &py, NULL); - if (pointer_screen != screen) - { - px = x; - py = y; - } - monitor_num = gdk_screen_get_monitor_at_point (screen, px, py); - gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); - - if ((x + w) > monitor.x + monitor.width) - x -= (x + w) - (monitor.x + monitor.width); - else if (x < monitor.x) - x = monitor.x; - - if ((y + h + widget->allocation.height + 4) > monitor.y + monitor.height) - y = y - h - 4; - else - y = y + widget->allocation.height + 4; - - toplevel = GTK_WINDOW (gtk_widget_get_toplevel (widget)); - if (toplevel && GTK_IS_WINDOW (toplevel)) - gtk_window_set_transient_for (GTK_WINDOW (tooltips->tip_window), toplevel); - - gtk_window_move (GTK_WINDOW (tooltips->tip_window), x, y); - gtk_widget_show (tooltips->tip_window); -} - -static gboolean -gtk_tooltips_timeout (gpointer data) -{ - GtkTooltips *tooltips = (GtkTooltips *) data; - - if (tooltips->active_tips_data != NULL && - GTK_WIDGET_DRAWABLE (tooltips->active_tips_data->widget)) - gtk_tooltips_draw_tips (tooltips); - - tooltips->timer_tag = 0; - - return FALSE; -} - -static void -gtk_tooltips_set_active_widget (GtkTooltips *tooltips, - GtkWidget *widget) -{ - if (tooltips->tip_window) - { - if (GTK_WIDGET_VISIBLE (tooltips->tip_window)) - g_get_current_time (&tooltips->last_popdown); - gtk_widget_hide (tooltips->tip_window); - } - if (tooltips->timer_tag) - { - g_source_remove (tooltips->timer_tag); - tooltips->timer_tag = 0; - } - - tooltips->active_tips_data = NULL; - - if (widget && GTK_WIDGET_DRAWABLE (widget)) - { - GtkTooltipsPrivate *private = GTK_TOOLTIPS_GET_PRIVATE (tooltips); - GtkTooltipsData *tooltipsdata; - - tooltipsdata = g_hash_table_lookup (private->tips_data_table, widget); - - if (tooltipsdata) - tooltips->active_tips_data = tooltipsdata; - } - else - { - tooltips->use_sticky_delay = FALSE; - } -} - -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) -{ - GTimeVal now; - glong msec; - - g_get_current_time (&now); - msec = (now.tv_sec - tooltips->last_popdown.tv_sec) * 1000 + - (now.tv_usec - tooltips->last_popdown.tv_usec) / 1000; - return (msec < STICKY_REVERT_DELAY); -} - -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; - - g_object_set_data (G_OBJECT (toplevel), I_("gtk-tooltips-keyboard-mode"), GUINT_TO_POINTER (TRUE)); - - if (focus) - gtk_tooltips_show_tip (focus); - } -} - -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), I_("gtk-tooltips-keyboard-mode"), GUINT_TO_POINTER (FALSE)); - } -} - -static gboolean -tooltips_enabled (GtkTooltips *tooltips, GtkWidget *w) -{ - GtkSettings *settings; - gboolean touchscreen; - - if (!tooltips->enabled) - return FALSE; - - settings = gtk_widget_get_settings (w); - g_object_get (settings, "gtk-touchscreen-mode", &touchscreen, NULL); - - return !touchscreen; -} - -static void -gtk_tooltips_start_delay (GtkTooltips *tooltips, - GtkWidget *widget) -{ - GtkTooltipsData *old_tips_data; - - old_tips_data = tooltips->active_tips_data; - if (tooltips_enabled (tooltips, widget) && - (!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 = gdk_threads_add_timeout (delay, - gtk_tooltips_timeout, - (gpointer) tooltips); - } -} - -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; - - old_tips_data = gtk_tooltips_data_get (widget); - tooltips = old_tips_data->tooltips; - - if (keyboard_mode) - { - switch (event->type) - { - case GDK_FOCUS_CHANGE: - if (event->focus_change.in) - gtk_tooltips_show_tip (widget); - else - gtk_tooltips_hide_tip (widget); - break; - default: - break; - } - } - else - { - if (event->type != GDK_KEY_PRESS && event->type != GDK_KEY_RELEASE) - { - event_widget = gtk_get_event_widget (event); - if (event_widget != widget) - return; - } - - switch (event->type) - { - case GDK_EXPOSE: - /* do nothing */ - break; - case GDK_ENTER_NOTIFY: - if (!(GTK_IS_MENU_ITEM (widget) && GTK_MENU_ITEM (widget)->submenu)) - gtk_tooltips_start_delay (tooltips, widget); - 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; - - case GDK_MOTION_NOTIFY: - /* Handle menu items specially ... pend popup for each motion - * on other widgets, we ignore motion. - */ - if (GTK_IS_MENU_ITEM (widget) && !GTK_MENU_ITEM (widget)->submenu) - { - /* Completely evil hack to make sure we get the LEAVE_NOTIFY - */ - GTK_PRIVATE_SET_FLAG (widget, GTK_LEAVE_PENDING); - gtk_tooltips_set_active_widget (tooltips, NULL); - gtk_tooltips_start_delay (tooltips, widget); - break; - } - break; /* ignore */ - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_KEY_PRESS: - case GDK_KEY_RELEASE: - case GDK_PROXIMITY_IN: - case GDK_SCROLL: - gtk_tooltips_set_active_widget (tooltips, NULL); - break; - default: - break; - } - } -} - -static void -gtk_tooltips_widget_unmap (GtkWidget *widget, - gpointer data) -{ - GtkTooltipsData *tooltipsdata = (GtkTooltipsData *)data; - GtkTooltips *tooltips = tooltipsdata->tooltips; - - if (tooltips->active_tips_data && - (tooltips->active_tips_data->widget == widget)) - gtk_tooltips_set_active_widget (tooltips, NULL); + gtk_widget_set_tooltip_text (widget, tip_text); } static void @@ -749,15 +260,6 @@ gtk_tooltips_widget_remove (GtkWidget *widget, g_hash_table_remove (private->tips_data_table, tooltipsdata->widget); } -void -_gtk_tooltips_toggle_keyboard_mode (GtkWidget *widget) -{ - if (get_keyboard_mode (widget)) - stop_keyboard_mode (widget); - else - start_keyboard_mode (widget); -} - /** * gtk_tooltips_get_info_from_tip_window: * @tip_window: a #GtkWindow diff --git a/gtk/gtktooltips.h b/gtk/gtktooltips.h index 49dbcbfe47..c88a4acd03 100644 --- a/gtk/gtktooltips.h +++ b/gtk/gtktooltips.h @@ -24,6 +24,8 @@ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ +#ifndef GTK_DISABLE_DEPRECATED + #ifndef __GTK_TOOLTIPS_H__ #define __GTK_TOOLTIPS_H__ @@ -87,10 +89,8 @@ GtkTooltips* gtk_tooltips_new (void); void gtk_tooltips_enable (GtkTooltips *tooltips); void gtk_tooltips_disable (GtkTooltips *tooltips); -#ifndef GTK_DISABLE_DEPRECATED void gtk_tooltips_set_delay (GtkTooltips *tooltips, guint delay); -#endif /* GTK_DISABLE_DEPRECATED */ void gtk_tooltips_set_tip (GtkTooltips *tooltips, GtkWidget *widget, const gchar *tip_text, @@ -98,9 +98,6 @@ void gtk_tooltips_set_tip (GtkTooltips *tooltips, GtkTooltipsData* gtk_tooltips_data_get (GtkWidget *widget); void gtk_tooltips_force_window (GtkTooltips *tooltips); - -void _gtk_tooltips_toggle_keyboard_mode (GtkWidget *widget); - gboolean gtk_tooltips_get_info_from_tip_window (GtkWindow *tip_window, GtkTooltips **tooltips, GtkWidget **current_widget); @@ -108,3 +105,5 @@ gboolean gtk_tooltips_get_info_from_tip_window (GtkWindow *tip_window G_END_DECLS #endif /* __GTK_TOOLTIPS_H__ */ + +#endif /* GTK_DISABLE_DEPRECATED */ diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 36fad36974..a4390b5040 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -4684,7 +4684,6 @@ gtk_widget_real_show_help (GtkWidget *widget, { if (help_type == GTK_WIDGET_HELP_TOOLTIP) { - _gtk_tooltips_toggle_keyboard_mode (widget); _gtk_tooltip_toggle_keyboard_mode (widget); return TRUE; diff --git a/tests/autotestfilechooser.c b/tests/autotestfilechooser.c index 7973220796..ff5bc7462f 100644 --- a/tests/autotestfilechooser.c +++ b/tests/autotestfilechooser.c @@ -30,6 +30,7 @@ */ #define GTK_FILE_SYSTEM_ENABLE_UNSUPPORTED +#undef GTK_DISABLE_DEPRECATED #include #include