Mercurial > pidgin.yaz
changeset 21885:f5d961556972
Refactor some of the tooltip drawing functions. And add some pretend docs.
Also, fix a bug where a tooltip would popup when hovering over the treeview
headers (in the roomlist, for example).
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Tue, 18 Dec 2007 09:17:39 +0000 |
parents | b40a6bb267a1 |
children | 5814ae85e756 |
files | pidgin/gtkblist.c pidgin/gtkroomlist.c pidgin/pidgintooltip.c pidgin/pidgintooltip.h |
diffstat | 4 files changed, 77 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/gtkblist.c Tue Dec 18 06:32:42 2007 +0000 +++ b/pidgin/gtkblist.c Tue Dec 18 09:17:39 2007 +0000 @@ -2632,7 +2632,8 @@ return td; } -static gboolean pidgin_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, gpointer data) +static gboolean +pidgin_blist_paint_tip(GtkWidget *widget, gpointer null) { GtkStyle *style; int current_height, max_width;
--- a/pidgin/gtkroomlist.c Tue Dec 18 06:32:42 2007 +0000 +++ b/pidgin/gtkroomlist.c Tue Dec 18 09:17:39 2007 +0000 @@ -346,7 +346,7 @@ #define TOOLTIP_BORDER 12 static gboolean -pidgin_roomlist_paint_tooltip(GtkWidget *widget, GdkEventExpose *event, gpointer user_data) +pidgin_roomlist_paint_tooltip(GtkWidget *widget, gpointer user_data) { PurpleRoomlist *list = user_data; PidginRoomlist *grl = list->ui_data;
--- a/pidgin/pidgintooltip.c Tue Dec 18 06:32:42 2007 +0000 +++ b/pidgin/pidgintooltip.c Tue Dec 18 09:17:39 2007 +0000 @@ -28,6 +28,7 @@ #include "prefs.h" #include "pidgin.h" #include "pidgintooltip.h" +#include "debug.h" struct { @@ -66,17 +67,35 @@ } } -static void +static gboolean pidgin_tooltip_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) { if (pidgin_tooltip.paint_tooltip) - pidgin_tooltip.paint_tooltip(widget, event, data); + pidgin_tooltip.paint_tooltip(widget, data); + return FALSE; +} + +static GtkWidget* +setup_tooltip_window() +{ + const char *name; + GtkWidget *tipwindow; + + tipwindow = gtk_window_new(GTK_WINDOW_POPUP); + name = gtk_window_get_title(GTK_WINDOW(pidgin_tooltip.widget)); + gtk_window_set_type_hint(GTK_WINDOW(tipwindow), GDK_WINDOW_TYPE_HINT_TOOLTIP); + gtk_widget_set_app_paintable(tipwindow, TRUE); + gtk_window_set_title(GTK_WINDOW(tipwindow), name ? name : _("Pidgin Tooltip")); + gtk_window_set_resizable(GTK_WINDOW(tipwindow), FALSE); + gtk_widget_set_name(tipwindow, "gtk-tooltips"); + gtk_widget_ensure_style(tipwindow); + gtk_widget_realize(tipwindow); + return tipwindow; } static void -setup_tooltip_window(gpointer data, int w, int h) +setup_tooltip_window_position(gpointer data, int w, int h) { - const char *name; int sig; int scr_w, scr_h, x, y; #if GTK_CHECK_VERSION(2,2,0) @@ -86,14 +105,6 @@ GdkRectangle mon_size; GtkWidget *tipwindow = pidgin_tooltip.tipwindow; - name = gtk_window_get_title(GTK_WINDOW(pidgin_tooltip.widget)); - gtk_widget_set_app_paintable(tipwindow, TRUE); - gtk_window_set_title(GTK_WINDOW(tipwindow), name ? name : _("Pidgin Tooltip")); - gtk_window_set_resizable(GTK_WINDOW(tipwindow), FALSE); - gtk_widget_set_name(tipwindow, "gtk-tooltips"); - g_signal_connect(G_OBJECT(tipwindow), "expose_event", - G_CALLBACK(pidgin_tooltip_expose_event), data); - #if GTK_CHECK_VERSION(2,2,0) gdk_display_get_pointer(gdk_display_get_default(), &screen, &x, &y, NULL); mon_num = gdk_screen_get_monitor_at_point(screen, x, y); @@ -141,6 +152,9 @@ gtk_window_move(GTK_WINDOW(tipwindow), x, y); gtk_widget_show(tipwindow); + g_signal_connect(G_OBJECT(tipwindow), "expose_event", + G_CALLBACK(pidgin_tooltip_expose_event), data); + /* Hide the tooltip when the widget is destroyed */ sig = g_signal_connect(G_OBJECT(pidgin_tooltip.widget), "destroy", G_CALLBACK(pidgin_tooltip_destroy), NULL); g_signal_connect_swapped(G_OBJECT(tipwindow), "destroy", G_CALLBACK(g_source_remove), GINT_TO_POINTER(sig)); @@ -153,17 +167,16 @@ int w, h; pidgin_tooltip_destroy(); - pidgin_tooltip.tipwindow = tipwindow = gtk_window_new(GTK_WINDOW_POPUP); - gtk_window_set_type_hint(GTK_WINDOW(tipwindow), GDK_WINDOW_TYPE_HINT_TOOLTIP); + pidgin_tooltip.widget = gtk_widget_get_toplevel(widget); + pidgin_tooltip.tipwindow = tipwindow = setup_tooltip_window(); pidgin_tooltip.paint_tooltip = paint_tooltip; - gtk_widget_ensure_style(tipwindow); if (!create_tooltip(tipwindow, userdata, &w, &h)) { pidgin_tooltip_destroy(); return; } - setup_tooltip_window(userdata, w, h); + setup_tooltip_window_position(userdata, w, h); } static void @@ -198,11 +211,10 @@ } pidgin_tooltip_destroy(); - pidgin_tooltip.tipwindow = tipwindow = gtk_window_new(GTK_WINDOW_POPUP); - gtk_window_set_type_hint(GTK_WINDOW(tipwindow), GDK_WINDOW_TYPE_HINT_TOOLTIP); + pidgin_tooltip.widget = gtk_widget_get_toplevel(data->widget); + pidgin_tooltip.tipwindow = tipwindow = setup_tooltip_window(); pidgin_tooltip.paint_tooltip = data->paint_tooltip; - gtk_widget_ensure_style(tipwindow); if (!data->create_tooltip(tipwindow, path, data->userdata, &w, &h)) { pidgin_tooltip_destroy(); @@ -210,8 +222,9 @@ return; } + setup_tooltip_window_position(data->userdata, w, h); + data->path = path; - setup_tooltip_window(data->userdata, w, h); g_signal_connect_swapped(G_OBJECT(tipwindow), "destroy", G_CALLBACK(reset_data_treepath), data); } @@ -230,6 +243,9 @@ GtkTreePath *path; int delay; + if (event->window != gtk_tree_view_get_bin_window(GTK_TREE_VIEW(tv))) + return FALSE; /* The cursor is probably on the TreeView's header. */ + /* XXX: probably use something more generic? */ delay = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/blist/tooltip_delay"); if (delay == 0) @@ -250,9 +266,8 @@ } gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, &pidgin_tooltip.tip_rect); + gtk_tree_path_free(path); - if (path) - gtk_tree_path_free(path); pidgin_tooltip.timeout = g_timeout_add(delay, (GSourceFunc)pidgin_tooltip_timeout, userdata); return FALSE;
--- a/pidgin/pidgintooltip.h Tue Dec 18 06:32:42 2007 +0000 +++ b/pidgin/pidgintooltip.h Tue Dec 18 09:17:39 2007 +0000 @@ -28,26 +28,57 @@ #include <gtk/gtk.h> -typedef gboolean (*PidginTooltipCreateForTree)(GtkWidget *window, GtkTreePath *path, gpointer userdata, int *w, int *h); -typedef gboolean (*PidginTooltipCreate)(GtkWidget *window, gpointer userdata, int *w, int *h); -typedef gboolean (*PidginTooltipPaint)(GtkWidget *widget, GdkEventExpose *event, gpointer data); +/** + * @param tipwindow The window for the tooltip. + * @param path The GtkTreePath representing the row under the cursor. + * @param userdata The userdata set during pidgin_tooltip_setup_for_treeview. + * @param w The value of this should be set to the desired width of the tooltip window. + * @param h The value of this should be set to the desired height of the tooltip window. + * + * @return @c TRUE if the tooltip was created correctly, @c FALSE otherwise. + * @since 2.4.0 + */ +typedef gboolean (*PidginTooltipCreateForTree)(GtkWidget *tipwindow, + GtkTreePath *path, gpointer userdata, int *w, int *h); + +/** + * @param tipwindow The window for the tooltip. + * @param userdata The userdata set during pidgin_tooltip_show. + * @param w The value of this should be set to the desired width of the tooltip window. + * @param h The value of this should be set to the desired height of the tooltip window. + * + * @return @c TRUE if the tooltip was created correctly, @c FALSE otherwise. + * @since 2.4.0 + */ +typedef gboolean (*PidginTooltipCreate)(GtkWidget *tipwindow, + gpointer userdata, int *w, int *h); + +/** + * @param tipwindow The window for the tooltip. + * @param userdata The userdata set during pidgin_tooltip_setup_for_treeview or pidgin_tooltip_show. + * + * @return @c TRUE if the tooltip was painted correctly, @c FALSE otherwise. + * @since 2.4.0 + */ +typedef gboolean (*PidginTooltipPaint)(GtkWidget *tipwindow, gpointer userdata); /** * Setup tooltip drawing functions for a treeview. * * @param tree The treeview * @param userdata The userdata to send to the callback functions - * @param create_cb Callback function to create the tooltip from the GtkTreePath + * @param create_cb Callback function to create the tooltip for a GtkTreePath * @param paint_cb Callback function to paint the tooltip * * @return @c TRUE if the tooltip callbacks were setup correctly. - * @since + * @since 2.4.0 */ gboolean pidgin_tooltip_setup_for_treeview(GtkWidget *tree, gpointer userdata, PidginTooltipCreateForTree create_cb, PidginTooltipPaint paint_cb); /** * Destroy the tooltip. + * @since 2.4.0 */ void pidgin_tooltip_destroy(void); @@ -59,7 +90,7 @@ * @param create_cb Callback function to create the tooltip from the GtkTreePath * @param paint_cb Callback function to paint the tooltip * - * @since + * @since 2.4.0 */ void pidgin_tooltip_show(GtkWidget *widget, gpointer userdata, PidginTooltipCreate create_cb, PidginTooltipPaint paint_cb);