more GDK->GTK mapping



Hi,

Patch adds:

 gtk_widget_set_cursor() 

 gtk_window_set_functions_hint()
 gtk_window_set_decorations_hint()
 gtk_window_set_role()

and deletes GTK_WINDOW_DIALOG, with compat code.

Havoc

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.1755
diff -u -u -r1.1755 ChangeLog
--- ChangeLog	2001/02/27 20:39:40	1.1755
+++ ChangeLog	2001/02/27 21:59:07
@@ -1,3 +1,21 @@
+2001-02-27  Havoc Pennington  <hp redhat com>
+
+	* gtk/gtkwindow.c (gtk_window_set_role): new function, sets the 
+	role for the session manager
+
+	* gtk/gtkwidget.c (gtk_widget_set_cursor): sets the cursor for a
+	widget
+
+	* gtk/gtkwindow.c (gtk_window_set_decorations_hint): new function
+	(gtk_window_set_functions_hint): new function
+
+	* gtk/testgtk.c (dnd_drop): remove use of GTK_WINDOW_DIALOG
+
+	* gtk/gtkcompat.h (GTK_WINDOW_DIALOG): compat #define
+	GTK_WINDOW_DIALOG GTK_WINDOW_TOPLEVEL
+
+	* gtk/gtkenums.h (enum GtkWindowType): remove GTK_WINDOW_DIALOG
+
 2001-02-26  Havoc Pennington  <hp redhat com>
 
 	* gtk/testgtk.c: test the window state stuff
Index: gtk/gtkenums.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkenums.h,v
retrieving revision 1.34
diff -u -u -r1.34 gtkenums.h
--- gtk/gtkenums.h	2001/02/19 20:06:37	1.34
+++ gtk/gtkenums.h	2001/02/27 21:59:07
@@ -356,7 +356,6 @@
 typedef enum
 {
   GTK_WINDOW_TOPLEVEL,
-  GTK_WINDOW_DIALOG,
   GTK_WINDOW_POPUP
 } GtkWindowType;
 
Index: gtk/gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.186
diff -u -u -r1.186 gtkwidget.c
--- gtk/gtkwidget.c	2001/02/27 20:40:09	1.186
+++ gtk/gtkwidget.c	2001/02/27 21:59:07
@@ -1611,14 +1611,19 @@
       
       if (!GTK_WIDGET_NO_WINDOW (widget))
 	{
+          GdkCursor *cursor;
+          
 	  mode = gtk_widget_get_extension_events (widget);
 	  if (mode != GDK_EXTENSION_EVENTS_NONE)
 	    {
 	      events = gtk_widget_get_events (widget);
 	      gdk_input_set_extension_events (widget->window, events, mode);
 	    }
+
+          cursor = g_object_get_data (G_OBJECT (widget), "gtk-widget-cursor");
+          
+          gdk_window_set_cursor (widget->window, cursor);
 	}
-      
     }
 }
 
@@ -4008,6 +4013,42 @@
   if (!extension_event_key_id)
     extension_event_key_id = g_quark_from_static_string (extension_event_key);
   gtk_object_set_data_by_id (GTK_OBJECT (widget), extension_event_key_id, modep);
+}
+
+/**
+ * gtk_widget_set_cursor:
+ * @widget: a #GtkWidget
+ * @cursor: a #GdkCursor, or %NULL
+ *
+ * Sets the mouse pointer for a widget. Only works on widgets that
+ * have a #GdkWindow; for widgets that don't, place them inside a
+ * #GtkEventBox and set the cursor on the event box. Setting the
+ * cursor to %NULL will cause a widget to its parent widget's cursor.
+ * Obtain a cursor with gdk_cursor_new().
+ * 
+ **/
+void
+gtk_widget_set_cursor (GtkWidget *widget,
+                       GdkCursor *cursor)
+{
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  if (GTK_WIDGET_NO_WINDOW (widget))
+    {
+      g_warning (G_STRLOC": you can't set cursors on GTK_NO_WINDOW widgets such as the %s widget; instead, place the widget inside a GtkEventBox, and set the cursor on the event box",
+                 g_type_name (G_TYPE_FROM_INSTANCE (widget)));
+      return;
+    }
+  
+  if (cursor)
+    gdk_cursor_ref (cursor);
+
+  g_object_set_data_full (G_OBJECT (widget),
+                          "gtk-widget-cursor",
+                          cursor,
+                          cursor ? (GDestroyNotify) gdk_cursor_unref : NULL);
+
+  if (widget->window)
+    gdk_window_set_cursor (widget->window, cursor);
 }
 
 /**
Index: gtk/gtkwidget.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.h,v
retrieving revision 1.90
diff -u -u -r1.90 gtkwidget.h
--- gtk/gtkwidget.h	2001/02/27 20:40:10	1.90
+++ gtk/gtkwidget.h	2001/02/27 21:59:07
@@ -520,6 +520,8 @@
 					   gint	                events);
 void	   gtk_widget_set_extension_events (GtkWidget		*widget,
 					    GdkExtensionMode	mode);
+void       gtk_widget_set_cursor          (GtkWidget           *widget,
+                                           GdkCursor           *cursor);
 
 GdkExtensionMode gtk_widget_get_extension_events (GtkWidget	*widget);
 GtkWidget*   gtk_widget_get_toplevel	(GtkWidget	*widget);
Index: gtk/gtkwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.c,v
retrieving revision 1.98
diff -u -u -r1.98 gtkwindow.c
--- gtk/gtkwindow.c	2001/02/27 20:40:12	1.98
+++ gtk/gtkwindow.c	2001/02/27 21:59:07
@@ -441,9 +441,13 @@
  * contain other widgets. Nearly always, the type of the window should
  * be #GTK_WINDOW_TOPLEVEL. If you're implementing something like a
  * popup menu from scratch (which is a bad idea, just use #GtkMenu),
- * you might use #GTK_WINDOW_TOPLEVEL. #GTK_WINDOW_DIALOG is not
- * useful; dialogs should be of type #GTK_WINDOW_TOPLEVEL.  (Probably
- * you want to use the #GtkDialog widget for dialogs anyway).
+ * you might use #GTK_WINDOW_POPUP. #GTK_WINDOW_POPUP is not for
+ * dialogs, though in some other toolkits dialogs are called "popups."
+ * In GTK+, #GTK_WINDOW_POPUP means a pop-up menu or pop-up tooltip.
+ * Popup windows are not controlled by the window manager.
+ *
+ * If you simply want an undecorated window (no window borders), use
+ * gtk_window_set_decorations_hint(), don't use #GTK_WINDOW_POPUP.
  * 
  * Return value: a new #GtkWindow.
  **/
@@ -499,13 +503,14 @@
  * @wmclass_name: window name hint
  * @wmclass_class: window class hint
  *
- * This function sets the X Window System "class" and "name" hints for a window.
- * According to the ICCCM, you should always set these to the same value for
- * all windows in an application, and GTK sets them to that value by default,
- * so calling this function is sort of pointless. However, you may want to
- * call gtk_window_set_role() on each window in your application, for the
- * benefit of the session manager. Setting the role allows the window manager
- * to restore window positions when loading a saved session.
+ * Don't use this function. It sets the X Window System "class" and
+ * "name" hints for a window.  According to the ICCCM, you should
+ * always set these to the same value for all windows in an
+ * application, and GTK sets them to that value by default, so calling
+ * this function is sort of pointless. However, you may want to call
+ * gtk_window_set_role() on each window in your application, for the
+ * benefit of the session manager. Setting the role allows the window
+ * manager to restore window positions when loading a saved session.
  * 
  **/
 void
@@ -523,10 +528,38 @@
   window->wmclass_class = g_strdup (wmclass_class);
 
   if (GTK_WIDGET_REALIZED (window))
-    g_warning ("shouldn't set wmclass after window is realized!\n");
+    g_warning (G_STRLOC": shouldn't set wmclass after window is realized!\n");
 }
 
 /**
+ * gtk_window_set_role:
+ * @window: a #GtkWindow
+ * @role: unique identifier for the window to be used when restoring a session
+ *
+ * The window role allows a window manager to identify "the same" window
+ * when an application is restarted. So for example you might set the
+ * "toolbox" role on your app's toolbox window, so that when
+ * the user restarts their session, the window manager can put the toolbox
+ * back in the same place.
+ * 
+ **/
+void
+gtk_window_set_role (GtkWindow   *window,
+                     const gchar *role)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  if (role == window->wm_role)
+    return;
+  
+  g_free (window->wm_role);
+  window->wm_role = g_strdup (role);
+  
+  if (GTK_WIDGET_REALIZED (window))
+    g_warning (G_STRLOC": shouldn't set role after window is realized!\n");
+}
+
+/**
  * gtk_window_set_focus:
  * @window: a #GtkWindow
  * @focus: widget to be the new focus widget
@@ -926,7 +959,7 @@
  * e.g. keep the dialog on top of the main window, or center the
  * dialog over the main window. gtk_dialog_new_with_buttons() and
  * other convenience functions in GTK+ will sometimes call
- * gtk_window_set_transient_for() on yoru behalf.
+ * gtk_window_set_transient_for() on your behalf.
  * 
  **/
 void       
@@ -1087,6 +1120,82 @@
 }
 
 /**
+ * gtk_window_set_decorations_hint:
+ * @window: a #GtkWindow
+ * @decorations: flags hinting which window manager decorations to use
+ *
+ * Provides a hint to the window manager (or equivalent, on Windows or
+ * framebuffer) indicating which window decorations (titlebar, border,
+ * etc.) you would like the window to have. The window manager is free
+ * to ignore your hint, or allow the user to override it, due to the
+ * nature of the X Window System. See also gtk_window_set_functions_hint().
+ *
+ * You should not use this function purely because a window is a
+ * dialog box; as long as you set the transient parent of a dialog
+ * using gtk_window_set_transient_for(), the window manager already
+ * knows it's a dialog and can decorate it differently according to
+ * user preferences. So you don't want to hardcode things in your
+ * application, just let the WM handle it.
+ * 
+ **/
+void
+gtk_window_set_decorations_hint (GtkWindow	    *window,
+                                 GdkWMDecoration  decorations)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  window->decorations_set = TRUE;
+  
+  g_object_set_data (G_OBJECT (window),
+                     "gtk-window-decorations",
+                     GINT_TO_POINTER (decorations));
+
+  if (GTK_WIDGET (window)->window)
+    {
+      gdk_window_set_decorations (GTK_WIDGET (window)->window,
+                                  decorations);
+    }
+}
+
+/**
+ * gtk_window_set_functions_hint:
+ * @window: a #GtkWindow
+ * @functions: flags hinting at operations the window should support
+ *
+ * Provides a hint to the window manager (or Windows/framebuffer
+ * equivalent) indicating which operations can be performed on the
+ * window. The window manager may then for example not display the
+ * controls used to perform the given operation. See also
+ * gtk_window_set_decorations_hint().
+ *
+ * You should not use this function purely because a window is a
+ * dialog box; as long as you set the transient parent of a dialog
+ * using gtk_window_set_transient_for(), the window manager already
+ * knows it's a dialog and can decorate it differently according to
+ * user preferences. So you don't want to hardcode things in your
+ * application, just let the WM handle it.
+ * 
+ **/
+void
+gtk_window_set_functions_hint (GtkWindow    *window,
+                               GdkWMFunction functions)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  window->functions_set = TRUE;
+  
+  g_object_set_data (G_OBJECT (window),
+                     "gtk-window-functions",
+                     GINT_TO_POINTER (functions));
+
+  if (GTK_WIDGET (window)->window)
+    {
+      gdk_window_set_functions (GTK_WIDGET (window)->window,
+                                functions);
+    }
+}
+
+/**
  * gtk_window_set_default_size:
  * @window: a #GtkWindow
  * @width: width in pixels, or -1 to leave the default width unchanged
@@ -1351,12 +1460,12 @@
     case GTK_WINDOW_TOPLEVEL:
       attributes.window_type = GDK_WINDOW_TOPLEVEL;
       break;
-    case GTK_WINDOW_DIALOG:
-      attributes.window_type = GDK_WINDOW_DIALOG;
-      break;
     case GTK_WINDOW_POPUP:
       attributes.window_type = GDK_WINDOW_TEMP;
       break;
+    default:
+      g_warning (G_STRLOC": Unknown window type %d!", window->type);
+      break;
     }
    
   attributes.title = window->title;
@@ -1428,6 +1537,23 @@
       GTK_WIDGET_REALIZED (window->transient_parent))
     gdk_window_set_transient_for (widget->window,
 				  GTK_WIDGET (window->transient_parent)->window);
+
+  if (window->wm_role)
+    gdk_window_set_role (widget->window, window->wm_role);
+  
+  if (window->decorations_set)
+    {
+      gdk_window_set_decorations (widget->window,
+                                  GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
+                                                                      "gtk-window-decorations")));
+    }
+
+  if (window->functions_set)
+    {
+      gdk_window_set_functions (widget->window,
+                                GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
+                                                                    "gtk-window-functions")));
+    }
 }
 
 static void
Index: gtk/gtkwindow.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.h,v
retrieving revision 1.26
diff -u -u -r1.26 gtkwindow.h
--- gtk/gtkwindow.h	2001/02/27 20:40:14	1.26
+++ gtk/gtkwindow.h	2001/02/27 21:59:07
@@ -57,6 +57,7 @@
   gchar *title;
   gchar *wmclass_name;
   gchar *wmclass_class;
+  gchar *wm_role;
   GtkWindowType type;
 
   GdkWindow *frame;
@@ -89,6 +90,10 @@
   guint iconify_initially : 1;
   guint stick_initially : 1;
   guint maximize_initially : 1;
+
+  /* Decorations/functions are set */
+  guint decorations_set : 1;
+  guint functions_set : 1;
   
   guint frame_left;
   guint frame_top;
@@ -114,6 +119,8 @@
 void       gtk_window_set_wmclass              (GtkWindow           *window,
 						const gchar         *wmclass_name,
 						const gchar         *wmclass_class);
+void       gtk_window_set_role                 (GtkWindow           *window,
+                                                const gchar         *role);
 void       gtk_window_set_policy               (GtkWindow           *window,
 						gint                 allow_shrink,
 						gint                 allow_grow,
@@ -135,6 +142,11 @@
 						GtkWidget           *geometry_widget,
 						GdkGeometry         *geometry,
 						GdkWindowHints       geom_mask);
+void       gtk_window_set_decorations_hint     (GtkWindow	    *window,
+                                                GdkWMDecoration      decorations);
+void       gtk_window_set_functions_hint       (GtkWindow	    *window,
+                                                GdkWMFunction	     functions);
+
 /* The following differs from gtk_widget_set_usize, in that
  * gtk_widget_set_usize() overrides the requisition, so sets a minimum
  * size, while this only sets the size requested from the WM.
Index: gtk/testgtk.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/testgtk.c,v
retrieving revision 1.221
diff -u -u -r1.221 testgtk.c
--- gtk/testgtk.c	2001/02/27 20:40:15	1.221
+++ gtk/testgtk.c	2001/02/27 21:59:08
@@ -7213,7 +7213,7 @@
   if (window)
     return;
 
-  window = gtk_window_new(GTK_WINDOW_DIALOG);
+  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_container_set_border_width (GTK_CONTAINER(window), 10);
 
   gtk_signal_connect (GTK_OBJECT (window), "destroy",




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