pidgin: 6d79836e: Use a small GtkButton instead of the cus...

qulogic at pidgin.im qulogic at pidgin.im
Sat Mar 20 02:51:21 EDT 2010


-----------------------------------------------------------------
Revision: 6d79836ef57805a40b20c46467e6a4595605d195
Ancestor: 1f5f9164a8d16cb4a576efa6ad40dfc6b5eb1afc
Author: karvanitis at hotmail.com
Date: 2010-03-20T06:02:11
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/6d79836ef57805a40b20c46467e6a4595605d195

Modified files:
        ChangeLog pidgin/gtkblist.c pidgin/gtkblist.h
        pidgin/gtkconv.c pidgin/gtkutils.c pidgin/gtkutils.h

ChangeLog: 

Use a small GtkButton instead of the custom "X" for close in various
places in the Buddy List and conversations. The minidialog still uses the
X, but it's a little different, anyway.

Refs #8727.

-------------- next part --------------
============================================================
--- ChangeLog	4709357f565cd99f3594b90872aaa50cf8b00859
+++ ChangeLog	1669f789de1c0518900df2ba319458502dec77b3
@@ -22,6 +22,7 @@ version 2.7.0 (??/??/????):
 	  in the distant past.  (Greg McNew)
 	* Added a menu set mood globally for all mood-supporting accounts
 	  (currently XMPP and ICQ).
+	* Use standard (but small) GTK+ buttons instead of custom "X" symbol.
 
 	Bonjour:
 	* Added support for IPv6. (Thanks to T_X for testing)
============================================================
--- pidgin/gtkblist.c	ebc64e5a0f732f8e3cf7b7bb823378f339f901bd
+++ pidgin/gtkblist.c	b934d2a4bf45c66fdddf88ba10257c0e86da4a93
@@ -70,8 +70,6 @@
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 
-#define HEADLINE_CLOSE_SIZE 11
-
 typedef struct
 {
 	PurpleAccount *account;
@@ -4983,58 +4981,16 @@ static gboolean
 }
 
 static gboolean
-headline_hover_close(int x, int y)
-{
-	GtkWidget *w = gtkblist->headline_hbox;
-	if (x <= w->allocation.width && x >= w->allocation.width - HEADLINE_CLOSE_SIZE &&
-			y >= 0 && y <= HEADLINE_CLOSE_SIZE)
-		return TRUE;
-	return FALSE;
-}
-
-static gboolean
 headline_box_enter_cb(GtkWidget *widget, GdkEventCrossing *event, PidginBuddyList *gtkblist)
 {
 	gdk_window_set_cursor(widget->window, gtkblist->hand_cursor);
-
-	if (gtkblist->headline_close) {
-		gdk_draw_pixbuf(widget->window, NULL, gtkblist->headline_close,
-					0, 0,
-					widget->allocation.width - 2 - HEADLINE_CLOSE_SIZE, 2,
-					HEADLINE_CLOSE_SIZE, HEADLINE_CLOSE_SIZE,
-					GDK_RGB_DITHER_NONE, 0, 0);
-		gtk_paint_focus(widget->style, widget->window, GTK_STATE_PRELIGHT,
-				NULL, widget, NULL,
-				widget->allocation.width - HEADLINE_CLOSE_SIZE - 3, 1,
-				HEADLINE_CLOSE_SIZE + 2, HEADLINE_CLOSE_SIZE + 2);
-	}
-
 	return FALSE;
 }
 
-#if 0
 static gboolean
-headline_box_motion_cb(GtkWidget *widget, GdkEventMotion *event, PidginBuddyList *gtkblist)
-{
-	purple_debug_fatal("motion", "%d %d\n", (int)event->x, (int)event->y);
-	if (headline_hover_close((int)event->x, (int)event->y))
-		gtk_paint_focus(widget->style, widget->window, GTK_STATE_PRELIGHT,
-				NULL, widget, NULL,
-				widget->allocation.width - HEADLINE_CLOSE_SIZE - 3, 1,
-				HEADLINE_CLOSE_SIZE + 2, HEADLINE_CLOSE_SIZE + 2);
-	return FALSE;
-}
-#endif
-
-static gboolean
 headline_box_leave_cb(GtkWidget *widget, GdkEventCrossing *event, PidginBuddyList *gtkblist)
 {
 	gdk_window_set_cursor(widget->window, gtkblist->arrow_cursor);
-	if (gtkblist->headline_close) {
-		GdkRectangle rect = {widget->allocation.width - 3 - HEADLINE_CLOSE_SIZE, 1,
-				HEADLINE_CLOSE_SIZE + 2, HEADLINE_CLOSE_SIZE + 2};
-		gdk_window_invalidate_rect(widget->window, &rect, TRUE);
-	}
 	return FALSE;
 }
 
@@ -5057,10 +5013,17 @@ static gboolean
 }
 
 static gboolean
+headline_close_press_cb(GtkButton *button, PidginBuddyList *gtkblist)
+{
+	gtk_widget_hide(gtkblist->headline_hbox);
+	return FALSE;
+}
+
+static gboolean
 headline_box_press_cb(GtkWidget *widget, GdkEventButton *event, PidginBuddyList *gtkblist)
 {
 	gtk_widget_hide(gtkblist->headline_hbox);
-	if (gtkblist->headline_callback && !headline_hover_close((int)event->x, (int)event->y))
+	if (gtkblist->headline_callback)
 		g_idle_add(headline_click_callback, NULL);
 	else {
 		if (gtkblist->headline_destroy)
@@ -5812,6 +5775,7 @@ static void pidgin_blist_show(PurpleBudd
 	GtkWidget *sw;
 	GtkWidget *sep;
 	GtkWidget *label;
+	GtkWidget *close;
 	char *pretty, *tmp;
 	const char *theme_name;
 	GtkAccelGroup *accel_group;
@@ -5940,11 +5904,18 @@ static void pidgin_blist_show(PurpleBudd
 			  NULL);
 	gtk_widget_set_name(gtkblist->headline_hbox, "gtk-tooltips");
 
-	gtkblist->headline_close = gtk_widget_render_icon(ebox, GTK_STOCK_CLOSE,
-		gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_MICROSCOPIC), NULL);
 	gtkblist->hand_cursor = gdk_cursor_new (GDK_HAND2);
 	gtkblist->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR);
 
+	/* Close button. */
+	close = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
+	gtkblist->headline_close = pidgin_create_small_button(close);
+	gtk_box_pack_start(GTK_BOX(gtkblist->headline_hbox), gtkblist->headline_close, FALSE, FALSE, 0);
+#if GTK_CHECK_VERSION(2,12,0)
+	gtk_widget_set_tooltip_text(gtkblist->headline_close, _("Close"));
+#endif
+	g_signal_connect(gtkblist->headline_close, "clicked", G_CALLBACK(headline_close_press_cb), gtkblist);
+
 	g_signal_connect(G_OBJECT(ebox), "enter-notify-event", G_CALLBACK(headline_box_enter_cb), gtkblist);
 	g_signal_connect(G_OBJECT(ebox), "leave-notify-event", G_CALLBACK(headline_box_leave_cb), gtkblist);
 	g_signal_connect(G_OBJECT(ebox), "button-press-event", G_CALLBACK(headline_box_press_cb), gtkblist);
@@ -6948,9 +6919,6 @@ static void pidgin_blist_destroy(PurpleB
 
 	purple_signals_disconnect_by_handle(gtkblist);
 
-	if (gtkblist->headline_close)
-		g_object_unref(G_OBJECT(gtkblist->headline_close));
-
 	gtk_widget_destroy(gtkblist->window);
 
 	pidgin_blist_tooltip_destroy();
============================================================
--- pidgin/gtkblist.h	179ac0c879f7f20d209dd08d36029a11ecd03482
+++ pidgin/gtkblist.h	04580e94eaef9e1a27ac042000f25f283f76281c
@@ -119,7 +119,7 @@ struct _PidginBuddyList {
 	GtkWidget *headline_hbox;       /**< Hbox for headline notification */
 	GtkWidget *headline_label;	/**< Label for headline notifications */
 	GtkWidget *headline_image;      /**< Image for headline notifications */
-	GdkPixbuf *headline_close;      /**< Close image for closing the headline without triggering the callback */
+	GtkWidget *headline_close;      /**< Button for closing the headline without triggering the callback */
 	GCallback headline_callback;    /**< Callback for headline notifications */
 	gpointer headline_data;         /**< User data for headline notifications */
 	GDestroyNotify headline_destroy; /**< Callback to use for destroying the headline-data */
============================================================
--- pidgin/gtkconv.c	c2aa109955ce697b8e2478453afe2c315124a492
+++ pidgin/gtkconv.c	4bf4feb4aa329504c8c3dda66c28e0d1d0c015cb
@@ -229,7 +229,7 @@ static gboolean
 }
 
 static gboolean
-close_conv_cb(GtkWidget *w, GdkEventButton *dontuse, PidginConversation *gtkconv)
+close_conv_cb(GtkButton *button, PidginConversation *gtkconv)
 {
 	/* We are going to destroy the conversations immediately only if the 'close immediately'
 	 * preference is selected. Otherwise, close the conversation after a reasonable timeout
@@ -1325,7 +1325,7 @@ menu_close_conv_cb(gpointer data, guint 
 {
 	PidginWindow *win = data;
 
-	close_conv_cb(NULL, NULL, PIDGIN_CONVERSATION(pidgin_conv_window_get_active_conversation(win)));
+	close_conv_cb(NULL, PIDGIN_CONVERSATION(pidgin_conv_window_get_active_conversation(win)));
 }
 
 static void
@@ -8677,7 +8677,7 @@ notebook_press_cb(GtkWidget *widget, Gdk
 			return FALSE;
 
 		gtkconv = pidgin_conv_window_get_gtkconv_at_index(win, tab_clicked);
-		close_conv_cb(NULL, NULL, gtkconv);
+		close_conv_cb(NULL, gtkconv);
 		return TRUE;
 	}
 
@@ -8945,7 +8945,7 @@ close_others_cb(GtkWidget *w, GObject *m
 
 		if (gconv != gtkconv)
 		{
-			close_conv_cb(NULL, NULL, gconv);
+			close_conv_cb(NULL, gconv);
 		}
 	}
 }
@@ -8957,7 +8957,7 @@ static void close_tab_cb(GtkWidget *w, G
 	gtkconv = g_object_get_data(menu, "clicked_tab");
 
 	if (gtkconv)
-		close_conv_cb(NULL, NULL, gtkconv);
+		close_conv_cb(NULL, gtkconv);
 }
 
 static gboolean
@@ -9421,7 +9421,7 @@ pidgin_conv_window_destroy(PidginWindow 
 	if (win->gtkconvs) {
 		while (win->gtkconvs) {
 			gboolean last = (win->gtkconvs->next == NULL);
-			close_conv_cb(NULL, NULL, win->gtkconvs->data);
+			close_conv_cb(NULL, win->gtkconvs->data);
 			if (last)
 				break;
 		}
@@ -9495,6 +9495,7 @@ pidgin_conv_window_add_gtkconv(PidginWin
 	GtkWidget *tab_cont = gtkconv->tab_cont;
 	PurpleConversationType conv_type;
 	const gchar *tmp_lab;
+	GtkWidget *close_image;
 
 	conv_type = purple_conversation_get_type(conv);
 
@@ -9506,12 +9507,12 @@ pidgin_conv_window_add_gtkconv(PidginWin
 
 
 	/* Close button. */
-	gtkconv->close = create_close_button();
+	close_image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
+	gtkconv->close = pidgin_create_small_button(close_image);
 	gtk_tooltips_set_tip(gtkconv->tooltips, gtkconv->close,
 	                     _("Close conversation"), NULL);
 
-	g_signal_connect(G_OBJECT(gtkconv->close), "button-press-event",
-			 G_CALLBACK(close_conv_cb), gtkconv);
+	g_signal_connect(gtkconv->close, "clicked", G_CALLBACK (close_conv_cb), gtkconv);
 
 	/* Status icon. */
 	gtkconv->icon = gtk_image_new();
============================================================
--- pidgin/gtkutils.c	3e605a2864d7b5bb44049967531d847e89962408
+++ pidgin/gtkutils.c	0b05ff9c955d8b6250d7d30da774ed9affdfaa85
@@ -153,6 +153,31 @@ GtkWidget *
 }
 
 GtkWidget *
+pidgin_create_small_button(GtkWidget *image)
+{
+	GtkWidget *button;
+	GtkRcStyle *rcstyle;
+
+	button = gtk_button_new();
+	gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
+
+	/* don't allow focus on the close button */
+	gtk_button_set_focus_on_click(GTK_BUTTON(button), FALSE);
+
+	/* make it as small as possible */
+	rcstyle = gtk_rc_style_new();
+	rcstyle->xthickness = rcstyle->ythickness = 0;
+	gtk_widget_modify_style(button, rcstyle);
+	gtk_rc_style_unref(rcstyle);
+
+	gtk_widget_show(image);
+
+	gtk_container_add(GTK_CONTAINER(button), image);
+
+	return button;
+}
+
+GtkWidget *
 pidgin_create_dialog(const char *title, guint border_width, const char *role, gboolean resizable)
 {
 	GtkWindow *wnd = NULL;
============================================================
--- pidgin/gtkutils.h	a6d326d1592e11699c276c0ad122b3bea4459329
+++ pidgin/gtkutils.h	6edab51a638a13f1838a4ec6b6adf63754993191
@@ -109,6 +109,16 @@ GtkWidget *pidgin_create_imhtml(gboolean
 GtkWidget *pidgin_create_imhtml(gboolean editable, GtkWidget **imhtml_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret);
 
 /**
+ * Creates a small button
+ *
+ * @param  image   A button image.
+ *
+ * @return   A GtkButton created from the image.
+ * @since 2.7.0
+ */
+GtkWidget *pidgin_create_small_button(GtkWidget *image);
+
+/**
  * Creates a new window
  *
  * @param title        The window title, or @c NULL


More information about the Commits mailing list