changeset 30016:97005a2e99d7

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. committer: Elliott Sales de Andrade <qulogic@pidgin.im>
author Kosta Arvanitis <karvanitis@hotmail.com>
date Sat, 20 Mar 2010 06:02:11 +0000
parents 24b7fa9c0c8b
children 0d613fa75e5f
files ChangeLog pidgin/gtkblist.c pidgin/gtkblist.h pidgin/gtkconv.c pidgin/gtkutils.c pidgin/gtkutils.h
diffstat 6 files changed, 65 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Mar 19 02:44:22 2010 +0000
+++ b/ChangeLog	Sat Mar 20 06:02:11 2010 +0000
@@ -22,6 +22,7 @@
 	  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)
--- a/pidgin/gtkblist.c	Fri Mar 19 02:44:22 2010 +0000
+++ b/pidgin/gtkblist.c	Sat Mar 20 06:02:11 2010 +0000
@@ -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
-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
+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 @@
 	GtkWidget *sw;
 	GtkWidget *sep;
 	GtkWidget *label;
+	GtkWidget *close;
 	char *pretty, *tmp;
 	const char *theme_name;
 	GtkAccelGroup *accel_group;
@@ -5940,11 +5904,18 @@
 			  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 @@
 
 	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();
--- a/pidgin/gtkblist.h	Fri Mar 19 02:44:22 2010 +0000
+++ b/pidgin/gtkblist.h	Sat Mar 20 06:02:11 2010 +0000
@@ -119,7 +119,7 @@
 	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 */
--- a/pidgin/gtkconv.c	Fri Mar 19 02:44:22 2010 +0000
+++ b/pidgin/gtkconv.c	Sat Mar 20 06:02:11 2010 +0000
@@ -229,7 +229,7 @@
 }
 
 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 @@
 {
 	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 @@
 			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 @@
 
 		if (gconv != gtkconv)
 		{
-			close_conv_cb(NULL, NULL, gconv);
+			close_conv_cb(NULL, gconv);
 		}
 	}
 }
@@ -8957,7 +8957,7 @@
 	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 @@
 	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 @@
 	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 @@
 
 
 	/* 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();
--- a/pidgin/gtkutils.c	Fri Mar 19 02:44:22 2010 +0000
+++ b/pidgin/gtkutils.c	Sat Mar 20 06:02:11 2010 +0000
@@ -153,6 +153,31 @@
 }
 
 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;
--- a/pidgin/gtkutils.h	Fri Mar 19 02:44:22 2010 +0000
+++ b/pidgin/gtkutils.h	Sat Mar 20 06:02:11 2010 +0000
@@ -109,6 +109,16 @@
 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