[gtk+/client-side-decorations: 16/50] put title label in an hbox



commit b0dfd6a237964b5f8f8ac0c68f3a266c6db8d8a7
Author: Cody Russell <crussell canonical com>
Date:   Thu May 21 11:35:43 2009 +0200

    put title label in an hbox

 gtk/gtkwindow.c |   53 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 33 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 0af2ba1..a8da4b8 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -41,6 +41,7 @@
 #include "gtkwindow-decorate.h"
 #include "gtklabel.h"
 #include "gtkbindings.h"
+#include "gtkhbox.h"
 #include "gtkkeyhash.h"
 #include "gtkmain.h"
 #include "gtkmnemonichash.h"
@@ -198,6 +199,7 @@ struct _GtkWindowPrivate
   gchar *startup_id;
 
   GtkWidget *title_label;
+  GtkWidget *title_hbox;
 };
 
 static void gtk_window_dispose            (GObject           *object);
@@ -959,6 +961,7 @@ gtk_window_init (GtkWindow *window)
 {
   //GdkColormap *colormap;
   GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
+  GtkWidget *label;
   
   GTK_WIDGET_UNSET_FLAGS (window, GTK_NO_WINDOW);
   GTK_WIDGET_SET_FLAGS (window, GTK_TOPLEVEL);
@@ -1006,7 +1009,10 @@ gtk_window_init (GtkWindow *window)
                                    GDK_DECOR_TITLE  |
                                    GDK_DECOR_MAXIMIZE);
   priv->old_decorations = 0;
-  gtk_window_set_label_widget (window, gtk_label_new (""));
+
+  label = gtk_label_new ("");
+  gtk_widget_show (label);
+  gtk_window_set_label_widget (window, label);
 
   //colormap = _gtk_widget_peek_colormap ();
   //if (colormap)
@@ -1438,9 +1444,17 @@ gtk_window_set_label_widget (GtkWindow *window,
   if (priv->title_label == label)
     return;
 
+  if (!priv->title_hbox)
+    {
+      priv->title_hbox = gtk_hbox_new (FALSE, 0);
+      gtk_widget_set_parent (priv->title_hbox, GTK_WIDGET (window));
+      gtk_widget_show (priv->title_hbox);
+    }
+
   if (priv->title_label)
     {
-      gtk_widget_unparent (priv->title_label);
+      gtk_container_remove (GTK_CONTAINER (priv->title_hbox), priv->title_label);
+      //g_object_unref (priv->title_label);
     }
 
   priv->title_label = label;
@@ -1449,9 +1463,11 @@ gtk_window_set_label_widget (GtkWindow *window,
     {
       priv->title_label = label;
 
-      gtk_widget_set_parent (label, GTK_WIDGET (window));
+      gtk_box_pack_start (GTK_BOX (priv->title_hbox), label, FALSE, FALSE, 0);
     }
 
+  gtk_widget_show_all (priv->title_hbox);
+
   if (GTK_WIDGET_VISIBLE (window))
     {
       gtk_widget_queue_resize (GTK_WIDGET (window));
@@ -4728,11 +4744,11 @@ gtk_window_map (GtkWidget *widget)
       !GTK_WIDGET_MAPPED (window->bin.child))
     gtk_widget_map (window->bin.child);
 
-  if (priv->title_label &&
+  if (priv->title_hbox &&
       GTK_WIDGET_VISIBLE (priv->title_label) &&
       !GTK_WIDGET_MAPPED (priv->title_label))
     {
-      gtk_widget_map (priv->title_label);
+      gtk_widget_map (priv->title_hbox);
     }
 
   if (window->frame)
@@ -4932,11 +4948,11 @@ gtk_window_realize (GtkWidget *widget)
     {
       attributes.event_mask |= GDK_BUTTON_PRESS_MASK;
 
-      if (priv->title_label && GTK_WIDGET_VISIBLE (priv->title_label))
+      if (priv->title_hbox && GTK_WIDGET_VISIBLE (priv->title_hbox))
         {
           GtkRequisition label_requisition;
 
-          gtk_widget_get_child_requisition (priv->title_label, &label_requisition);
+          gtk_widget_get_child_requisition (priv->title_hbox, &label_requisition);
           label_height = label_requisition.height;
         }
       else
@@ -5080,9 +5096,9 @@ gtk_window_size_request (GtkWidget      *widget,
   if (priv->client_side_decorated && window->type != GTK_WINDOW_POPUP)
     {
       gint child_height = 0;
-      if (priv->title_label && GTK_WIDGET_VISIBLE (priv->title_label))
+      if (priv->title_hbox && GTK_WIDGET_VISIBLE (priv->title_hbox))
         {
-          gtk_widget_size_request (priv->title_label, &child_requisition);
+          gtk_widget_size_request (priv->title_hbox, &child_requisition);
           child_height = child_requisition.height;
         }
 
@@ -5118,16 +5134,16 @@ gtk_window_size_allocate (GtkWidget     *widget,
 
   deco_allocation.width = deco_allocation.height = 0;
 
-  if (priv->client_side_decorated && priv->title_label && GTK_WIDGET_VISIBLE (priv->title_label))
+  if (priv->client_side_decorated && priv->title_hbox && GTK_WIDGET_VISIBLE (priv->title_hbox))
     {
-      gtk_widget_get_child_requisition (priv->title_label, &deco_requisition);
+      gtk_widget_get_child_requisition (priv->title_hbox, &deco_requisition);
 
       deco_allocation.x = window->frame_left;
       deco_allocation.y = window->frame_top;
       deco_allocation.width = deco_requisition.width;
       deco_allocation.height = deco_requisition.height;
 
-      gtk_widget_size_allocate (priv->title_label, &deco_allocation);
+      gtk_widget_size_allocate (priv->title_hbox, &deco_allocation);
     }
 
   if (window->bin.child && GTK_WIDGET_VISIBLE (window->bin.child))
@@ -5178,9 +5194,9 @@ gtk_window_real_compute_child_allocation (GtkWindow      *window,
   GtkRequisition child_requisition;
   gint top_margin;
 
-  if (priv->title_label)
+  if (priv->title_hbox)
     {
-      gtk_widget_get_child_requisition (priv->title_label, &child_requisition);
+      gtk_widget_get_child_requisition (priv->title_hbox, &child_requisition);
       top_margin = MAX (child_requisition.height, widget->style->ythickness);
     }
   else
@@ -5636,10 +5652,7 @@ gtk_window_remove (GtkContainer *container,
 {
   GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (container);
 
-  if (priv->title_label == child)
-    gtk_window_set_label_widget (GTK_WINDOW (container), NULL);
-  else
-    GTK_CONTAINER_CLASS (gtk_window_parent_class)->remove (container, child);
+  GTK_CONTAINER_CLASS (gtk_window_parent_class)->remove (container, child);
 }
 
 static void
@@ -5654,8 +5667,8 @@ gtk_window_forall (GtkContainer   *container,
   if (bin->child)
     (* callback) (bin->child, callback_data);
 
-  if (priv->title_label)
-    (* callback) (priv->title_label, callback_data);
+  if (priv->title_hbox)
+    (* callback) (priv->title_hbox, callback_data);
 }
 
 static gboolean



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