Titles for tearoff menus




The GNOME people have gone ahead and made the stable pre-1.0
branch of GNOME use GTK+'s tearoff menu items.

Because this is the first time that anybody's actually used the
tearoff menu items, they've run into one limit in the way
they work - it isn't possible to set the title of the
window that is created when the menu is torn off.

(Right now, when the File menu is torn off, it gets
the title "File", and so forth.)

While there isn't much space in the titlebar typically,
it still could be useful to set something else there,
especially for a WM that supports tooltips for truncated
titles. 

Elliot Lee added a patch to GTK+ today that I didn't like at all
- to avoid adding a function to GTK+, it made the user set some
magic object data on the "File" label. Here is an alternate
patch, that I think should be OK for 1.2.

It adds a single function to the API:

 void gtk_menu_set_title (GtkMenu *menu, const gchar *title);

This will set object data on the menu, which will be checked 
when creating a tearoff window.

This patch creates no binary or source incompatibility,
and I would consider it unlikely to introduce additional
bugs, since it is quite simple.

Regards,
                                        Owen

Index: gtkmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenu.c,v
retrieving revision 1.35
diff -u -r1.35 gtkmenu.c
--- gtkmenu.c	1998/12/23 19:16:21	1.35
+++ gtkmenu.c	1998/12/23 19:41:39
@@ -601,6 +601,7 @@
 	  if (!menu->tearoff_window)
 	    {
 	      GtkWidget *attach_widget;
+	      gchar *title;
 	      
 	      menu->tearoff_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 	      gtk_widget_set_app_paintable (menu->tearoff_window, TRUE);
@@ -610,18 +611,21 @@
 					 GTK_OBJECT (menu));
 	      gtk_widget_realize (menu->tearoff_window);
 	      
-	      attach_widget = gtk_menu_get_attach_widget (menu);
-	      if (GTK_IS_MENU_ITEM (attach_widget))
+	      title = gtk_object_get_data (GTK_OBJECT (menu), "gtk-menu-title");
+	      if (!title)
 		{
-		  GtkWidget *child = GTK_BIN (attach_widget)->child;
-		  if (GTK_IS_LABEL (child))
+		  attach_widget = gtk_menu_get_attach_widget (menu);
+		  if (GTK_IS_MENU_ITEM (attach_widget))
 		    {
-		      gchar *ret;
-		      gtk_label_get (GTK_LABEL (child), &ret);
-		      gdk_window_set_title (menu->tearoff_window->window, ret);
+		      GtkWidget *child = GTK_BIN (attach_widget)->child;
+		      if (GTK_IS_LABEL (child))
+			gtk_label_get (GTK_LABEL (child), &title);
 		    }
 		}
 
+	      if (title)
+		gdk_window_set_title (menu->tearoff_window->window, title);
+
 	      gdk_window_set_decorations (menu->tearoff_window->window, 
 					  GDK_DECOR_ALL |
 					  GDK_DECOR_RESIZEH |
@@ -643,6 +647,17 @@
 	  gtk_menu_reparent (menu, menu->toplevel, FALSE);
 	}
     }
+}
+
+void       
+gtk_menu_set_title (GtkMenu     *menu,
+		    const gchar *title)
+{
+  g_return_if_fail (menu != NULL);
+  g_return_if_fail (GTK_IS_MENU (menu));
+
+  gtk_object_set_data_full (GTK_OBJECT (menu), "gtk-menu-title",
+			    g_strdup (title), (GtkDestroyNotify) g_free);
 }
 
 static void
Index: gtkmenu.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenu.h,v
retrieving revision 1.10
diff -u -r1.10 gtkmenu.h
--- gtkmenu.h	1998/10/18 22:51:15	1.10
+++ gtkmenu.h	1998/12/23 19:41:39
@@ -128,8 +128,14 @@
 GtkWidget* gtk_menu_get_attach_widget	  (GtkMenu	       *menu);
 
 void	   gtk_menu_detach		  (GtkMenu	       *menu);
-void       gtk_menu_set_tearoff_state    (GtkMenu              *menu,
-					  gboolean              torn_off);
+void       gtk_menu_set_tearoff_state     (GtkMenu             *menu,
+					   gboolean             torn_off);
+
+/* This sets the window manager title for the window that
+ * appears when a menu is torn off
+ */
+void       gtk_menu_set_title             (GtkMenu             *menu,
+					   const gchar         *title);
 
 #ifdef __cplusplus
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]