changeset 12008:91aaa1b3ac30

[gaim-migrate @ 14301] sf patch #1348466, from Sadrul Habib Chowdhury Add a tooltip for the typing notification icons (and any other icon in the gtkmenutray) committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 08 Nov 2005 23:34:54 +0000
parents 8724718d387f
children 8a7553e149de
files src/gtkconv.c src/gtkmenutray.c
diffstat 2 files changed, 65 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkconv.c	Tue Nov 08 19:45:09 2005 +0000
+++ b/src/gtkconv.c	Tue Nov 08 23:34:54 2005 +0000
@@ -2581,35 +2581,44 @@
 	GaimGtkWindow *gtkwin;
 	GaimConvIm *im = NULL;
 	GaimConversation *conv = gtkconv->active_conv;
+	char *stock_id, *tooltip;
 
 	gtkwin = gtkconv->win;
 
-	if(gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM)
+	if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM)
 		im = GAIM_CONV_IM(conv);
 
-	if(gtkwin->menu.typing_icon) {
-		gtk_widget_destroy(gtkwin->menu.typing_icon);
-		gtkwin->menu.typing_icon = NULL;
+	if (gtkwin->menu.typing_icon) {
+		gtk_widget_hide(gtkwin->menu.typing_icon);
 	}
 
-	if(im && gaim_conv_im_get_typing_state(im) == GAIM_TYPING) {
-		gtkwin->menu.typing_icon =
-			gtk_image_new_from_stock(GAIM_STOCK_TYPING, GTK_ICON_SIZE_MENU);
-		gtk_tooltips_set_tip(gtkconv->tooltips, gtkwin->menu.typing_icon,
-				_("User is typing..."), NULL);
-	} else if(im && gaim_conv_im_get_typing_state(im) == GAIM_TYPED) {
-		gtkwin->menu.typing_icon =
-			gtk_image_new_from_stock(GAIM_STOCK_TYPED, GTK_ICON_SIZE_MENU);
-		gtk_tooltips_set_tip(gtkconv->tooltips, gtkwin->menu.typing_icon,
-				_("User has typed something and paused"), NULL);
+	if (!im || (gaim_conv_im_get_typing_state(im) == GAIM_NOT_TYPING))
+		return;
+
+	if (gaim_conv_im_get_typing_state(im) == GAIM_TYPING) {
+		stock_id = GAIM_STOCK_TYPING;
+		tooltip = _("User is typing...");
+	} else {
+		stock_id = GAIM_STOCK_TYPED;
+		tooltip = _("User has typed something and stopped");
 	}
-	
-	if(gtkwin->menu.typing_icon) {
-		gtk_widget_show(gtkwin->menu.typing_icon);
+
+	if (gtkwin->menu.typing_icon == NULL)
+	{
+		gtkwin->menu.typing_icon = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_MENU);
 		gaim_gtk_menu_tray_append(GAIM_GTK_MENU_TRAY(gtkwin->menu.tray),
 								  gtkwin->menu.typing_icon,
-								  _("The buddy is typing a message"));
+								  tooltip);
 	}
+	else
+	{
+		gtk_image_set_from_stock(GTK_IMAGE(gtkwin->menu.typing_icon), stock_id, GTK_ICON_SIZE_MENU);
+		gaim_gtk_menu_tray_set_tooltip(GAIM_GTK_MENU_TRAY(gtkwin->menu.tray),
+									   gtkwin->menu.typing_icon,
+									   tooltip);
+	}
+
+	gtk_widget_show(gtkwin->menu.typing_icon);
 }
 
 static gboolean
--- a/src/gtkmenutray.c	Tue Nov 08 19:45:09 2005 +0000
+++ b/src/gtkmenutray.c	Tue Nov 08 23:34:54 2005 +0000
@@ -21,6 +21,7 @@
 
 #include "gtkmenutray.h"
 
+#include <gtk/gtkeventbox.h>
 #include <gtk/gtkiconfactory.h>
 #include <gtk/gtkversion.h>
 
@@ -129,7 +130,7 @@
 	gint height = -1;
 
 	gtk_menu_item_set_right_justified(GTK_MENU_ITEM(menu_tray), TRUE);
-	
+
 	if(!GTK_IS_WIDGET(menu_tray->tray))
 		menu_tray->tray = gtk_hbox_new(FALSE, 0);
 
@@ -193,24 +194,41 @@
 	return menu_tray->tray;
 }
 
-void
-gaim_gtk_menu_tray_append(GaimGtkMenuTray *menu_tray, GtkWidget *widget, const char *tooltip)
+static void
+gaim_gtk_menu_tray_add(GaimGtkMenuTray *menu_tray, GtkWidget *widget,
+					   const char *tooltip, gboolean prepend)
 {
 	g_return_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray));
 	g_return_if_fail(GTK_IS_WIDGET(widget));
 
+	if (GTK_WIDGET_NO_WINDOW(widget))
+	{
+		GtkWidget *event;
+
+		event = gtk_event_box_new();
+		gtk_container_add(GTK_CONTAINER(event), widget);
+		gtk_widget_show(event);
+		widget = event;
+	}
+
 	gaim_gtk_menu_tray_set_tooltip(menu_tray, widget, tooltip);
-	gtk_box_pack_end(GTK_BOX(menu_tray->tray), widget, FALSE, FALSE, 0);
+
+	if (prepend)
+		gtk_box_pack_start(GTK_BOX(menu_tray->tray), widget, FALSE, FALSE, 0);
+	else
+		gtk_box_pack_end(GTK_BOX(menu_tray->tray), widget, FALSE, FALSE, 0);
+}
+
+void
+gaim_gtk_menu_tray_append(GaimGtkMenuTray *menu_tray, GtkWidget *widget, const char *tooltip)
+{
+	gaim_gtk_menu_tray_add(menu_tray, widget, tooltip, FALSE);
 }
 
 void
 gaim_gtk_menu_tray_prepend(GaimGtkMenuTray *menu_tray, GtkWidget *widget, const char *tooltip)
 {
-	g_return_if_fail(GAIM_GTK_IS_MENU_TRAY(menu_tray));
-	g_return_if_fail(GTK_IS_WIDGET(widget));
-
-	gaim_gtk_menu_tray_set_tooltip(menu_tray, widget, tooltip);
-	gtk_box_pack_start(GTK_BOX(menu_tray->tray), widget, FALSE, FALSE, 0);
+	gaim_gtk_menu_tray_add(menu_tray, widget, tooltip, TRUE);
 }
 
 void
@@ -220,10 +238,17 @@
 		return;
 
 	/* Should we check whether widget is a child of menu_tray? */
+
+	/*
+	 * If the widget does not have it's own window, then it
+	 * must have automatically been added to an event box
+	 * when it was added to the menu tray.  If this is the
+	 * case, we want to set the tooltip on the widget's parent,
+	 * not on the widget itself.
+	 */
 	if (GTK_WIDGET_NO_WINDOW(widget))
-		gaim_debug_warning("GtkMenuTray",
-				"The widget does not have it's own window. Tooltip cannot be set for this widget.\n");
-	else
-		gtk_tooltips_set_tip(menu_tray->tooltips, widget, tooltip, NULL);
+		widget = widget->parent;
+
+	gtk_tooltips_set_tip(menu_tray->tooltips, widget, tooltip, NULL);
 }