im.pidgin.pidgin.sadrul.tooltips: 2c79eb43e6f1106231cc15098ea6467b7fc1e4d5
sadrul at pidgin.im
sadrul at pidgin.im
Tue Dec 18 04:25:49 EST 2007
-----------------------------------------------------------------
Revision: 2c79eb43e6f1106231cc15098ea6467b7fc1e4d5
Ancestor: 5454e20ce772daa3f531e1cadae0435c2f61fdd0
Author: sadrul at pidgin.im
Date: 2007-12-18T09:17:39
Branch: im.pidgin.pidgin.sadrul.tooltips
Modified files:
pidgin/gtkblist.c pidgin/gtkroomlist.c
pidgin/pidgintooltip.c pidgin/pidgintooltip.h
ChangeLog:
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).
-------------- next part --------------
============================================================
--- pidgin/gtkblist.c 830190eabd127478fc8a6632639f37c5d1c77ca2
+++ pidgin/gtkblist.c a1800be53d1538658d1fd301c347e33f73549dd4
@@ -2632,7 +2632,8 @@ static struct tooltip_data * create_tip_
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;
============================================================
--- pidgin/gtkroomlist.c 406c5ba939479f119b14cf65bedf4adbd7b1be29
+++ pidgin/gtkroomlist.c 0f0c34738c2a6729d3e7073c8157dfa2a64bbff1
@@ -346,7 +346,7 @@ static gboolean
#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;
============================================================
--- pidgin/pidgintooltip.c 7c52f3c66c230e54a1def21f8944eda16718d119
+++ pidgin/pidgintooltip.c c89a2700b41cb5a634137ba345dd8a0aff815f3a
@@ -28,6 +28,7 @@
#include "prefs.h"
#include "pidgin.h"
#include "pidgintooltip.h"
+#include "debug.h"
struct
{
@@ -66,17 +67,35 @@ void pidgin_tooltip_destroy()
}
}
-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 @@ setup_tooltip_window(gpointer data, int
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 @@ setup_tooltip_window(gpointer data, int
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 @@ void pidgin_tooltip_show(GtkWidget *widg
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_draw(PidginTooltipData *d
}
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 @@ pidgin_tooltip_draw(PidginTooltipData *d
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 @@ row_motion_cb(GtkWidget *tv, GdkEventMot
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 @@ row_motion_cb(GtkWidget *tv, GdkEventMot
}
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;
============================================================
--- pidgin/pidgintooltip.h c063d0d4afcad7a2391065c772251e5cf51cbde5
+++ pidgin/pidgintooltip.h bbed4651d99afbdcce545469a0798617b8da5844
@@ -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 @@ void pidgin_tooltip_destroy(void);
* @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);
More information about the Commits
mailing list