GtkWidget::has_default at construct time



if you set has_default on a widget at construct time, you of course get
this warning:

bug-buddy (pid:30001): Gtk-WARNING **:
gtkwidget.c:3465:gtk_widget_grab_default(): widget not within a
GtkWindow

this patch tries to fix this this.  it works; possibly there's a better
solution though.

jacob
-- 
"In fact, can you imagine anything more terrifying than a zombie clown?"
	-- moby
Index: gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.274
diff -u -r1.274 gtkwidget.c
--- gtkwidget.c	2001/12/12 22:29:50	1.274
+++ gtkwidget.c	2001/12/13 19:57:37
@@ -216,8 +216,9 @@
 static AtkObject*	gtk_widget_ref_accessible		(AtkImplementor *implementor);
 static void             gtk_widget_invalidate_widget_windows    (GtkWidget        *widget,
 								 GdkRegion        *region);
+static void             gtk_widget_real_hierarchy_changed       (GtkWidget        *widget,
+								 GtkWidget        *previous_toplevel);
 
-
 /* --- variables --- */
 static gpointer         parent_class = NULL;
 static guint            widget_signals[LAST_SIGNAL] = { 0 };
@@ -341,7 +342,7 @@
   klass->size_allocate = gtk_widget_real_size_allocate;
   klass->state_changed = NULL;
   klass->parent_set = NULL;
-  klass->hierarchy_changed = NULL;
+  klass->hierarchy_changed = gtk_widget_real_hierarchy_changed;
   klass->style_set = gtk_widget_style_set;
   klass->direction_changed = gtk_widget_direction_changed;
   klass->grab_notify = NULL;
@@ -1138,8 +1139,15 @@
 	gtk_widget_queue_resize (widget);
       break;
     case PROP_HAS_DEFAULT:
-      if (g_value_get_boolean (value))
-	gtk_widget_grab_default (widget);
+      if (GTK_IS_WINDOW (gtk_widget_get_toplevel (widget)))
+	{
+	  if (g_value_get_boolean (value))
+	    gtk_widget_grab_default (widget);
+	}
+      else if (g_value_get_boolean (value))
+	GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_DEFAULT);
+      else
+	GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_DEFAULT);
       break;
     case PROP_RECEIVES_DEFAULT:
       if (g_value_get_boolean (value))
@@ -4198,6 +4206,24 @@
     gtk_container_forall (GTK_CONTAINER (widget),
 			  gtk_widget_set_style_recurse,
 			  NULL);
+}
+
+static void
+gtk_widget_real_hierarchy_changed (GtkWidget *widget,
+				   GtkWidget *old_toplevel)
+{
+  GtkWidget *new_toplevel;
+  
+  if (!GTK_WIDGET_HAS_DEFAULT (widget))
+    return;
+  
+  new_toplevel = gtk_widget_get_toplevel (widget);
+  
+  if (new_toplevel != old_toplevel && GTK_IS_WINDOW (new_toplevel))
+    {
+      GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_DEFAULT);
+      gtk_window_set_default (GTK_WINDOW (new_toplevel), widget);
+    }
 }
 
 static void


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