]> Pileus Git - ~andy/gtk/commitdiff
new function to set the current focus_child of a container, does proper
authorTim Janik <timj@gtk.org>
Sun, 3 May 1998 15:45:08 +0000 (15:45 +0000)
committerTim Janik <timj@src.gnome.org>
Sun, 3 May 1998 15:45:08 +0000 (15:45 +0000)
Sun May  3 16:55:43 1998  Tim Janik  <timj@gtk.org>

        * gtk/gtkcontainer.c (gtk_container_set_focus_child): new function to
                set the current focus_child of a container, does proper referencing and
                        adjusts the vadjustment/hadjustment associated with the focus widget.

                                * gtk/gtkwidget.c (gtk_widget_grab_focus): set the focused child on
                                        containers via gtk_container_set_focus_child.

                                                * gtk/gtknotebook.c: modifications to use gtk_container_set_focus_child
                                                        where appropriate.

                                                                * gtk/gtkcontainer.c (gtk_container_remove): removed unsetting of focus
                                                                        child since not every child removal goes through this function (this
                                                                                showed up after gtk_container_set_focus_child() started to reference the
                                                                                        focus_child of a container).

                                                                                                * gtk/gtkwidget.c (gtk_widget_unparent): moved unsetting the focus_child
                                                                                                        of a container from gtk_container_remove into this place.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkcontainer.c
gtk/gtkcontainer.h
gtk/gtknotebook.c
gtk/gtkwidget.c

index 08226dd5a40b93d8f0e81a2dee575a5640b2c5b4..c334a7ddf282308ab38e954237a0d55a05a09317 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+Sun May  3 16:55:43 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): new function to
+       set the current focus_child of a container, does proper referencing and
+       adjusts the vadjustment/hadjustment associated with the focus widget.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): set the focused child on
+       containers via gtk_container_set_focus_child.
+
+       * gtk/gtknotebook.c: modifications to use gtk_container_set_focus_child
+       where appropriate.
+
+       * gtk/gtkcontainer.c (gtk_container_remove): removed unsetting of focus
+       child since not every child removal goes through this function (this
+       showed up after gtk_container_set_focus_child() started to reference the
+       focus_child of a container).
+
+       * gtk/gtkwidget.c (gtk_widget_unparent): moved unsetting the focus_child
+       of a container from gtk_container_remove into this place.
+
 Sat May  2 22:33:45 1998  Tim Janik  <timj@gtk.org>
 
        * gtk/gtksignal.c: added new functions to operate on intermediate
index 08226dd5a40b93d8f0e81a2dee575a5640b2c5b4..c334a7ddf282308ab38e954237a0d55a05a09317 100644 (file)
@@ -1,3 +1,23 @@
+Sun May  3 16:55:43 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): new function to
+       set the current focus_child of a container, does proper referencing and
+       adjusts the vadjustment/hadjustment associated with the focus widget.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): set the focused child on
+       containers via gtk_container_set_focus_child.
+
+       * gtk/gtknotebook.c: modifications to use gtk_container_set_focus_child
+       where appropriate.
+
+       * gtk/gtkcontainer.c (gtk_container_remove): removed unsetting of focus
+       child since not every child removal goes through this function (this
+       showed up after gtk_container_set_focus_child() started to reference the
+       focus_child of a container).
+
+       * gtk/gtkwidget.c (gtk_widget_unparent): moved unsetting the focus_child
+       of a container from gtk_container_remove into this place.
+
 Sat May  2 22:33:45 1998  Tim Janik  <timj@gtk.org>
 
        * gtk/gtksignal.c: added new functions to operate on intermediate
index 08226dd5a40b93d8f0e81a2dee575a5640b2c5b4..c334a7ddf282308ab38e954237a0d55a05a09317 100644 (file)
@@ -1,3 +1,23 @@
+Sun May  3 16:55:43 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): new function to
+       set the current focus_child of a container, does proper referencing and
+       adjusts the vadjustment/hadjustment associated with the focus widget.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): set the focused child on
+       containers via gtk_container_set_focus_child.
+
+       * gtk/gtknotebook.c: modifications to use gtk_container_set_focus_child
+       where appropriate.
+
+       * gtk/gtkcontainer.c (gtk_container_remove): removed unsetting of focus
+       child since not every child removal goes through this function (this
+       showed up after gtk_container_set_focus_child() started to reference the
+       focus_child of a container).
+
+       * gtk/gtkwidget.c (gtk_widget_unparent): moved unsetting the focus_child
+       of a container from gtk_container_remove into this place.
+
 Sat May  2 22:33:45 1998  Tim Janik  <timj@gtk.org>
 
        * gtk/gtksignal.c: added new functions to operate on intermediate
index 08226dd5a40b93d8f0e81a2dee575a5640b2c5b4..c334a7ddf282308ab38e954237a0d55a05a09317 100644 (file)
@@ -1,3 +1,23 @@
+Sun May  3 16:55:43 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): new function to
+       set the current focus_child of a container, does proper referencing and
+       adjusts the vadjustment/hadjustment associated with the focus widget.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): set the focused child on
+       containers via gtk_container_set_focus_child.
+
+       * gtk/gtknotebook.c: modifications to use gtk_container_set_focus_child
+       where appropriate.
+
+       * gtk/gtkcontainer.c (gtk_container_remove): removed unsetting of focus
+       child since not every child removal goes through this function (this
+       showed up after gtk_container_set_focus_child() started to reference the
+       focus_child of a container).
+
+       * gtk/gtkwidget.c (gtk_widget_unparent): moved unsetting the focus_child
+       of a container from gtk_container_remove into this place.
+
 Sat May  2 22:33:45 1998  Tim Janik  <timj@gtk.org>
 
        * gtk/gtksignal.c: added new functions to operate on intermediate
index 08226dd5a40b93d8f0e81a2dee575a5640b2c5b4..c334a7ddf282308ab38e954237a0d55a05a09317 100644 (file)
@@ -1,3 +1,23 @@
+Sun May  3 16:55:43 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): new function to
+       set the current focus_child of a container, does proper referencing and
+       adjusts the vadjustment/hadjustment associated with the focus widget.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): set the focused child on
+       containers via gtk_container_set_focus_child.
+
+       * gtk/gtknotebook.c: modifications to use gtk_container_set_focus_child
+       where appropriate.
+
+       * gtk/gtkcontainer.c (gtk_container_remove): removed unsetting of focus
+       child since not every child removal goes through this function (this
+       showed up after gtk_container_set_focus_child() started to reference the
+       focus_child of a container).
+
+       * gtk/gtkwidget.c (gtk_widget_unparent): moved unsetting the focus_child
+       of a container from gtk_container_remove into this place.
+
 Sat May  2 22:33:45 1998  Tim Janik  <timj@gtk.org>
 
        * gtk/gtksignal.c: added new functions to operate on intermediate
index 08226dd5a40b93d8f0e81a2dee575a5640b2c5b4..c334a7ddf282308ab38e954237a0d55a05a09317 100644 (file)
@@ -1,3 +1,23 @@
+Sun May  3 16:55:43 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): new function to
+       set the current focus_child of a container, does proper referencing and
+       adjusts the vadjustment/hadjustment associated with the focus widget.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): set the focused child on
+       containers via gtk_container_set_focus_child.
+
+       * gtk/gtknotebook.c: modifications to use gtk_container_set_focus_child
+       where appropriate.
+
+       * gtk/gtkcontainer.c (gtk_container_remove): removed unsetting of focus
+       child since not every child removal goes through this function (this
+       showed up after gtk_container_set_focus_child() started to reference the
+       focus_child of a container).
+
+       * gtk/gtkwidget.c (gtk_widget_unparent): moved unsetting the focus_child
+       of a container from gtk_container_remove into this place.
+
 Sat May  2 22:33:45 1998  Tim Janik  <timj@gtk.org>
 
        * gtk/gtksignal.c: added new functions to operate on intermediate
index 08226dd5a40b93d8f0e81a2dee575a5640b2c5b4..c334a7ddf282308ab38e954237a0d55a05a09317 100644 (file)
@@ -1,3 +1,23 @@
+Sun May  3 16:55:43 1998  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkcontainer.c (gtk_container_set_focus_child): new function to
+       set the current focus_child of a container, does proper referencing and
+       adjusts the vadjustment/hadjustment associated with the focus widget.
+
+       * gtk/gtkwidget.c (gtk_widget_grab_focus): set the focused child on
+       containers via gtk_container_set_focus_child.
+
+       * gtk/gtknotebook.c: modifications to use gtk_container_set_focus_child
+       where appropriate.
+
+       * gtk/gtkcontainer.c (gtk_container_remove): removed unsetting of focus
+       child since not every child removal goes through this function (this
+       showed up after gtk_container_set_focus_child() started to reference the
+       focus_child of a container).
+
+       * gtk/gtkwidget.c (gtk_widget_unparent): moved unsetting the focus_child
+       of a container from gtk_container_remove into this place.
+
 Sat May  2 22:33:45 1998  Tim Janik  <timj@gtk.org>
 
        * gtk/gtksignal.c: added new functions to operate on intermediate
index ec2f869547e7dd76fe541ed839694b4e2b8a767a..2265826f2a52a17b759712930c085293c9464fc8 100644 (file)
@@ -359,9 +359,6 @@ gtk_container_remove (GtkContainer *container,
   g_return_if_fail (widget->parent == GTK_WIDGET (container));
   
   gtk_signal_emit (GTK_OBJECT (container), container_signals[REMOVE], widget);
-
-  if (container->focus_child == widget)
-    container->focus_child = NULL;
 }
 
 void
@@ -538,6 +535,47 @@ gtk_container_unregister_toplevel (GtkContainer *container)
   gtk_widget_unref (GTK_WIDGET (container));
 }
 
+void
+gtk_container_set_focus_child (GtkContainer     *container,
+                              GtkWidget        *child)
+{
+  g_return_if_fail (container != NULL);
+  g_return_if_fail (GTK_IS_CONTAINER (container));
+  if (child)
+    g_return_if_fail (GTK_IS_WIDGET (child));
+
+  if (child != container->focus_child)
+    {
+      if (container->focus_child)
+       gtk_widget_unref (container->focus_child);
+      container->focus_child = child;
+      if (container->focus_child)
+       gtk_widget_ref (container->focus_child);
+    }
+
+
+  /* check for h/v adjustments
+   */
+  if (container->focus_child)
+    {
+      GtkAdjustment *adjustment;
+      
+      adjustment = gtk_object_get_data_by_id (GTK_OBJECT (container), vadjustment_key_id);
+      if (adjustment)
+       gtk_adjustment_clamp_page (adjustment,
+                                  container->focus_child->allocation.y,
+                                  (container->focus_child->allocation.y +
+                                   container->focus_child->allocation.height));
+
+      adjustment = gtk_object_get_data_by_id (GTK_OBJECT (container), hadjustment_key_id);
+      if (adjustment)
+       gtk_adjustment_clamp_page (adjustment,
+                                  container->focus_child->allocation.x,
+                                  (container->focus_child->allocation.x +
+                                   container->focus_child->allocation.width));
+    }
+}
+
 static void
 gtk_container_marshal_signal_1 (GtkObject      *object,
                                GtkSignalFunc   func,
@@ -617,7 +655,6 @@ gtk_real_container_focus (GtkContainer     *container,
   GList *tmp_list;
   GList *tmp_list2;
   gint return_val;
-  GtkAdjustment *adjustment;
 
   g_return_val_if_fail (container != NULL, FALSE);
   g_return_val_if_fail (GTK_IS_CONTAINER (container), FALSE);
@@ -679,25 +716,6 @@ gtk_real_container_focus (GtkContainer     *container,
        }
     }
 
-  /* check for h/v adjustments
-   */
-  if (container->focus_child)
-    {
-      adjustment = gtk_object_get_data_by_id (GTK_OBJECT (container), vadjustment_key_id);
-      if (adjustment)
-       gtk_adjustment_clamp_page (adjustment,
-                                  container->focus_child->allocation.y,
-                                  (container->focus_child->allocation.y +
-                                   container->focus_child->allocation.height));
-
-      adjustment = gtk_object_get_data_by_id (GTK_OBJECT (container), hadjustment_key_id);
-      if (adjustment)
-       gtk_adjustment_clamp_page (adjustment,
-                                  container->focus_child->allocation.x,
-                                  (container->focus_child->allocation.x +
-                                   container->focus_child->allocation.width));
-    }
-
   return return_val;
 }
 
@@ -1001,7 +1019,7 @@ gtk_container_focus_move (GtkContainer     *container,
   GtkWidget *child;
 
   focus_child = container->focus_child;
-  container->focus_child = NULL;
+  gtk_container_set_focus_child (container, NULL);
 
   while (children)
     {
index a07a8b9f1e0fa223ab91bc26e1d4007956278d6a..78bd37dcb3e2e15aa98a37a658a484b417ce6899 100644 (file)
@@ -105,6 +105,8 @@ void   gtk_container_register_toplevel       (GtkContainer     *container);
 void   gtk_container_unregister_toplevel (GtkContainer    *container);
 gint   gtk_container_focus                (GtkContainer     *container,
                                            GtkDirectionType  direction);
+void   gtk_container_set_focus_child      (GtkContainer     *container,
+                                           GtkWidget        *child);
 void   gtk_container_set_focus_vadjustment (GtkContainer     *container,
                                            GtkAdjustment    *adjustment);
 void   gtk_container_set_focus_hadjustment (GtkContainer     *container,
@@ -114,7 +116,6 @@ void   gtk_container_set_focus_hadjustment (GtkContainer     *container,
 
 
 
-
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 97082b8a05889a965d81f63fe5089ecbe5830409..6518f471979ff906c4e008521c5af2a60a8213b9 100644 (file)
@@ -1485,10 +1485,7 @@ gtk_notebook_button_press (GtkWidget      *widget,
   if (event->window == notebook->panel)
     {
       if (!GTK_WIDGET_HAS_FOCUS (widget))
-       {
-         GTK_CONTAINER (widget)->focus_child = NULL;
-         gtk_widget_grab_focus (widget);
-       }
+       gtk_widget_grab_focus (widget);
 
       gtk_grab_add (widget);
       notebook->button = event->button;
@@ -1557,7 +1554,7 @@ gtk_notebook_button_press (GtkWidget      *widget,
              (event->x <= (page->allocation.x + page->allocation.width)) &&
              (event->y <= (page->allocation.y + page->allocation.height)))
            {
-             GTK_CONTAINER (notebook)->focus_child = NULL;
+             gtk_container_set_focus_child (GTK_CONTAINER (notebook), NULL);
 
              if (page == notebook->cur_page &&
                   notebook->focus_tab != children && 
@@ -2088,7 +2085,7 @@ gtk_notebook_focus_in (GtkWidget     *widget,
       if (gtk_notebook_page_select (GTK_NOTEBOOK (widget)))
        return FALSE;
       else
-       GTK_CONTAINER (widget)->focus_child = NULL;
+       gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
     }
 
   GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
@@ -2647,7 +2644,7 @@ gtk_notebook_focus (GtkContainer     *container,
     return FALSE;
 
   focus_child = container->focus_child;
-  container->focus_child = NULL;
+  gtk_container_set_focus_child (container, NULL);
 
   if (!notebook->show_tabs)
     {
index 9e58abad2f60a8b4967d7b55efbe8747c320f736..3f317289c60963619f5991a02bcd78986afd3671 100644 (file)
@@ -1128,7 +1128,6 @@ void
 gtk_widget_unparent (GtkWidget *widget)
 {
   GtkWidget *toplevel;
-  GtkWidget *child;
   GtkWidget *old_parent;
   GSList *tmp_list, *prev_list;
   
@@ -1139,18 +1138,30 @@ gtk_widget_unparent (GtkWidget *widget)
   /* keep this function in sync with gtk_menu_detach()
    */
 
+  /* unset focused and default children properly
+   */
   toplevel = gtk_widget_get_toplevel (widget);
-  if (GTK_IS_WINDOW (toplevel))
+  if (GTK_CONTAINER (widget->parent)->focus_child == widget)
     {
-      child = GTK_WINDOW (toplevel)->focus_widget;
+      gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
+
+      if (GTK_IS_WINDOW (toplevel))
+       {
+         GtkWidget *child;
       
-      while (child && child != widget)
-       child = child->parent;
+         child = GTK_WINDOW (toplevel)->focus_widget;
+         
+         while (child && child != widget)
+           child = child->parent;
+         
+         if (child == widget)
+           gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
+       }
+    }
+  if (GTK_IS_WINDOW (toplevel))
+    {
+      GtkWidget *child;
       
-      if (child == widget)
-       gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
-
-
       child = GTK_WINDOW (toplevel)->default_widget;
       
       while (child && child != widget)
@@ -2249,25 +2260,25 @@ gtk_widget_grab_focus (GtkWidget *widget)
 
   if (GTK_WIDGET_CAN_FOCUS (widget))
     {
-      GtkWidget *window;
+      GtkWidget *parent;
       GtkWidget *child;
       GtkType window_type;
       
       window_type = gtk_window_get_type ();
-      window = widget->parent;
+      parent = widget->parent;
       child = widget;
       
-      while (window && !gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type))
+      while (parent && !gtk_type_is_a (GTK_WIDGET_TYPE (parent), window_type))
        {
-         GTK_CONTAINER (window)->focus_child = child;
-         child = window;
-         window = window->parent;
+         gtk_container_set_focus_child (GTK_CONTAINER (parent), child);
+         child = parent;
+         parent = parent->parent;
        }
       
-      if (window && gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type))
+      if (parent && gtk_type_is_a (GTK_WIDGET_TYPE (parent), window_type))
        {
-         GTK_CONTAINER (window)->focus_child = child;
-         gtk_window_set_focus (GTK_WINDOW (window), widget);
+         gtk_container_set_focus_child (GTK_CONTAINER (parent), child);
+         gtk_window_set_focus (GTK_WINDOW (parent), widget);
        }
     }
 }