[gdl] Use standard GtkBox size allocation functions in GdlDockBar



commit 375b5cd665200de4f51e21f3e423a46d15cd892e
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Sun May 27 12:32:43 2012 +0200

    Use standard GtkBox size allocation functions in GdlDockBar

 gdl/gdl-dock-bar.c |  611 ----------------------------------------------------
 1 files changed, 0 insertions(+), 611 deletions(-)
---
diff --git a/gdl/gdl-dock-bar.c b/gdl/gdl-dock-bar.c
index 0a22d07..563ee8e 100644
--- a/gdl/gdl-dock-bar.c
+++ b/gdl/gdl-dock-bar.c
@@ -106,7 +106,6 @@ void
 gdl_dock_bar_class_init (GdlDockBarClass *klass)
 {
     GObjectClass       *object_class;
-    GtkWidgetClass     *widget_class;
 
     object_class = G_OBJECT_CLASS (klass);
 
@@ -140,11 +139,6 @@ gdl_dock_bar_class_init (GdlDockBarClass *klass)
                            GDL_DOCK_BAR_BOTH,
                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
-    widget_class = GTK_WIDGET_CLASS (klass);
-    widget_class->get_preferred_width = gdl_dock_bar_get_preferred_width;
-    widget_class->get_preferred_height = gdl_dock_bar_get_preferred_height;
-    widget_class->size_allocate = gdl_dock_bar_size_allocate;
-
     g_type_class_add_private (object_class, sizeof (GdlDockBarPrivate));
 }
 
@@ -437,611 +431,6 @@ gdl_dock_bar_attach (GdlDockBar    *dockbar,
     update_dock_items (dockbar, FALSE);
 }
 
-static void gdl_dock_bar_size_request (GtkWidget *widget,
-		                       GtkRequisition *requisition )
-{
-    GdlDockBar *dockbar;
-
-    dockbar = GDL_DOCK_BAR (widget);
-
-    /* default to vertical for unknown values */
-    switch (gtk_orientable_get_orientation (GTK_ORIENTABLE (dockbar))) {
-	case GTK_ORIENTATION_HORIZONTAL:
-		gdl_dock_bar_size_hrequest (widget, requisition);
-		break;
-	case GTK_ORIENTATION_VERTICAL:
-	default:
-		gdl_dock_bar_size_vrequest (widget, requisition);
-		break;
-    }
-}
-
-static void gdl_dock_bar_get_preferred_width (GtkWidget *widget,
-                                              gint      *minimum,
-                                              gint      *natural)
-{
-    GtkRequisition requisition;
-
-    gdl_dock_bar_size_request (widget, &requisition);
-
-   *minimum = *natural = requisition.width;
-}
-
-static void gdl_dock_bar_get_preferred_height (GtkWidget *widget,
-                                               gint      *minimum,
-                                               gint      *natural)
-{
-    GtkRequisition requisition;
-
-    gdl_dock_bar_size_request (widget, &requisition);
-
-   *minimum = *natural = requisition.height;
-}
-
-static void gdl_dock_bar_size_allocate (GtkWidget *widget,
-		                       GtkAllocation *allocation )
-{
-    GdlDockBar *dockbar;
-
-    dockbar = GDL_DOCK_BAR (widget);
-
-    /* default to vertical for unknown values */
-    switch (gtk_orientable_get_orientation (GTK_ORIENTABLE (dockbar))) {
-	case GTK_ORIENTATION_HORIZONTAL:
-		gdl_dock_bar_size_hallocate (widget, allocation);
-		break;
-	case GTK_ORIENTATION_VERTICAL:
-	default:
-		gdl_dock_bar_size_vallocate (widget, allocation);
-		break;
-    }
-}
-
-static void gdl_dock_bar_size_vrequest (GtkWidget *widget,
-                                        GtkRequisition *requisition )
-{
-    GtkBox *box;
-    GtkRequisition child_requisition;
-    GList *child;
-    gint nvis_children;
-    gint height;
-    guint border_width;
-
-    box = GTK_BOX (widget);
-    requisition->width = 0;
-    requisition->height = 0;
-    nvis_children = 0;
-
-
-    for (child = gtk_container_get_children (GTK_CONTAINER (box));
-         child != NULL; child = g_list_next (child))
-    {
-        if (gtk_widget_get_visible (GTK_WIDGET (child->data)))
-        {
-            guint padding;
-            gboolean expand;
-            gboolean fill;
-            GtkPackType pack_type;
-
-            gtk_widget_get_preferred_size (GTK_WIDGET (child->data), &child_requisition, NULL);
-
-            gtk_box_query_child_packing (box,
-                                         child->data,
-                                         &expand,
-                                         &fill,
-                                         &padding,
-                                         &pack_type);
-
-            if (gtk_box_get_homogeneous (box))
-            {
-                height = child_requisition.height +  padding * 2;
-                requisition->height = MAX (requisition->height, height);
-            }
-            else
-            {
-                requisition->height += child_requisition.height + padding * 2;
-            }
-
-            requisition->width = MAX (requisition->width, child_requisition.width);
-
-            nvis_children += 1;
-        }
-    }
-
-    if (nvis_children > 0)
-    {
-        if (gtk_box_get_homogeneous (box))
-            requisition->height *= nvis_children;
-        requisition->height += (nvis_children - 1) * gtk_box_get_spacing (box);
-    }
-
-    border_width = gtk_container_get_border_width (GTK_CONTAINER (box));
-    requisition->width += border_width * 2;
-    requisition->height += border_width * 2;
-
-}
-
-static void gdl_dock_bar_size_vallocate (GtkWidget     *widget,
-                                         GtkAllocation *allocation)
-{
-    GtkBox *box;
-    GList *child;
-    GtkAllocation child_allocation;
-    gint nvis_children;
-    gint nexpand_children;
-    gint child_height;
-    gint height;
-    gint extra;
-    gint y;
-    guint border_width;
-    GtkRequisition requisition;
-
-    box = GTK_BOX (widget);
-    gtk_widget_set_allocation (widget, allocation);
-
-    gtk_widget_get_requisition (widget, &requisition);
-
-    nvis_children = 0;
-    nexpand_children = 0;
-
-    for (child = gtk_container_get_children (GTK_CONTAINER (box));
-         child != NULL; child = g_list_next (child))
-    {
-        guint padding;
-        gboolean expand;
-        gboolean fill;
-        GtkPackType pack_type;
-
-        gtk_box_query_child_packing (box,
-                                     child->data,
-                                     &expand,
-                                     &fill,
-                                     &padding,
-                                     &pack_type);
-        if (gtk_widget_get_visible (GTK_WIDGET(child->data)))
-        {
-            nvis_children += 1;
-            if (expand)
-                nexpand_children += 1;
-        }
-    }
-
-    border_width = gtk_container_get_border_width (GTK_CONTAINER (box));
-
-    if (nvis_children > 0)
-    {
-        if (gtk_box_get_homogeneous (box))
-        {
-            height = (allocation->height -
-                      border_width * 2 -
-                      (nvis_children - 1) * gtk_box_get_spacing (box));
-            extra = height / nvis_children;
-        }
-        else if (nexpand_children > 0)
-        {
-            height = (gint) allocation->height - (gint) requisition.height;
-            extra = height / nexpand_children;
-        }
-        else
-        {
-            height = 0;
-            extra = 0;
-        }
-
-        y = allocation->y + border_width;
-        child_allocation.x = allocation->x + border_width;
-        child_allocation.width = MAX (1, (gint) allocation->width - (gint) border_width * 2);
-
-        for (child = gtk_container_get_children (GTK_CONTAINER (box));
-             child != NULL; child = g_list_next (child))
-        {
-            guint padding;
-            gboolean expand;
-            gboolean fill;
-            GtkPackType pack_type;
-
-            gtk_box_query_child_packing (box,
-                                         child->data,
-                                         &expand,
-                                         &fill,
-                                         &padding,
-                                         &pack_type);
-
-            if ((pack_type == GTK_PACK_START) && gtk_widget_get_visible (GTK_WIDGET (child->data)))
-            {
-                if (gtk_box_get_homogeneous (box))
-                {
-                    if (nvis_children == 1)
-                        child_height = height;
-                    else
-                        child_height = extra;
-
-                    nvis_children -= 1;
-                    height -= extra;
-                }
-                else
-                {
-                    GtkRequisition child_requisition;
-
-                    gtk_widget_get_preferred_size (GTK_WIDGET (child->data), &child_requisition, NULL);
-                    child_height = child_requisition.height + padding * 2;
-
-                    if (expand)
-                    {
-                        if (nexpand_children == 1)
-                            child_height += height;
-                        else
-                            child_height += extra;
-
-                        nexpand_children -= 1;
-                        height -= extra;
-                    }
-                }
-
-                if (fill)
-                {
-                    child_allocation.height = MAX (1, child_height - padding * 2);
-                    child_allocation.y = y + padding;
-                }
-                else
-                {
-                    GtkRequisition child_requisition;
-
-                    gtk_widget_get_preferred_size (GTK_WIDGET (child->data), &child_requisition, NULL);
-                    child_allocation.height = child_requisition.height;
-                    child_allocation.y = y + (child_height - child_allocation.height) / 2;
-                }
-
-                gtk_widget_size_allocate (GTK_WIDGET (child->data), &child_allocation);
-
-                y += child_height + gtk_box_get_spacing (box);
-            }
-        }
-
-        y = allocation->y + allocation->height - border_width;
-
-        for (child = gtk_container_get_children (GTK_CONTAINER (box));
-             child != NULL; child = g_list_next (child))
-        {
-            guint padding;
-            gboolean expand;
-            gboolean fill;
-            GtkPackType pack_type;
-
-            gtk_box_query_child_packing (box,
-                                         child->data,
-                                         &expand,
-                                         &fill,
-                                         &padding,
-                                         &pack_type);
-
-            if ((pack_type == GTK_PACK_END) && gtk_widget_get_visible (GTK_WIDGET (child->data)))
-            {
-                GtkRequisition child_requisition;
-                gtk_widget_get_preferred_size (GTK_WIDGET (child->data), &child_requisition, NULL);
-
-                if (gtk_box_get_homogeneous (box))
-                {
-                    if (nvis_children == 1)
-                        child_height = height;
-                    else
-                        child_height = extra;
-
-                    nvis_children -= 1;
-                    height -= extra;
-                }
-                else
-                {
-                    child_height = child_requisition.height + padding * 2;
-
-                    if (expand)
-                    {
-                        if (nexpand_children == 1)
-                            child_height += height;
-                        else
-                            child_height += extra;
-
-                        nexpand_children -= 1;
-                        height -= extra;
-                    }
-                }
-
-                if (fill)
-                {
-                    child_allocation.height = MAX (1, child_height - padding * 2);
-                    child_allocation.y = y + padding - child_height;
-                }
-                else
-                {
-                    child_allocation.height = child_requisition.height;
-                    child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
-                }
-
-                gtk_widget_size_allocate (GTK_WIDGET (child->data), &child_allocation);
-
-                y -= (child_height + gtk_box_get_spacing (box));
-            }
-        }
-    }
-}
-
-static void gdl_dock_bar_size_hrequest (GtkWidget *widget,
-                                        GtkRequisition *requisition )
-{
-    GtkBox *box;
-    GList *child;
-    gint nvis_children;
-    gint width;
-    guint border_width;
-
-    box = GTK_BOX (widget);
-    requisition->width = 0;
-    requisition->height = 0;
-    nvis_children = 0;
-
-    for (child = gtk_container_get_children (GTK_CONTAINER (box));
-         child != NULL; child = g_list_next (child))
-    {
-        guint padding;
-        gboolean expand;
-        gboolean fill;
-        GtkPackType pack_type;
-
-        gtk_box_query_child_packing (box,
-                                     child->data,
-                                     &expand,
-                                     &fill,
-                                     &padding,
-                                     &pack_type);
-
-
-        if (gtk_widget_get_visible (GTK_WIDGET (child->data)))
-        {
-            GtkRequisition child_requisition;
-
-            gtk_widget_get_preferred_size (GTK_WIDGET (child->data), &child_requisition, NULL);
-
-            if (gtk_box_get_homogeneous (box))
-            {
-                width = child_requisition.width + padding * 2;
-                requisition->width = MAX (requisition->width, width);
-            }
-            else
-            {
-                requisition->width += child_requisition.width + padding * 2;
-            }
-
-            requisition->height = MAX (requisition->height, child_requisition.height);
-
-            nvis_children += 1;
-        }
-    }
-
-    if (nvis_children > 0)
-    {
-        if (gtk_box_get_homogeneous (box))
-            requisition->width *= nvis_children;
-        requisition->width += (nvis_children - 1) * gtk_box_get_spacing (box);
-    }
-
-    border_width = gtk_container_get_border_width (GTK_CONTAINER (box));
-    requisition->width += border_width * 2;
-    requisition->height += border_width * 2;
-}
-
-static void gdl_dock_bar_size_hallocate (GtkWidget     *widget,
-                                         GtkAllocation *allocation)
-{
-    GtkBox *box;
-    GList *child;
-    GtkAllocation child_allocation;
-    gint nvis_children;
-    gint nexpand_children;
-    gint child_width;
-    gint width;
-    gint extra;
-    gint x;
-    guint border_width;
-    GtkTextDirection direction;
-    GtkRequisition requisition;
-
-    box = GTK_BOX (widget);
-    gtk_widget_set_allocation (widget, allocation);
-    gtk_widget_get_requisition (widget, &requisition);
-
-    direction = gtk_widget_get_direction (widget);
-
-    nvis_children = 0;
-    nexpand_children = 0;
-
-    for (child = gtk_container_get_children (GTK_CONTAINER (box));
-         child != NULL; child = g_list_next (child))
-    {
-        guint padding;
-        gboolean expand;
-        gboolean fill;
-        GtkPackType pack_type;
-
-        gtk_box_query_child_packing (box,
-                                     child->data,
-                                     &expand,
-                                     &fill,
-                                     &padding,
-                                     &pack_type);
-
-        if (gtk_widget_get_visible (GTK_WIDGET (child->data)))
-        {
-            nvis_children += 1;
-            if (expand)
-                nexpand_children += 1;
-        }
-    }
-
-    border_width = gtk_container_get_border_width (GTK_CONTAINER (box));
-
-    if (nvis_children > 0)
-    {
-        if (gtk_box_get_homogeneous (box))
-        {
-            width = (allocation->width -
-                     border_width * 2 -
-                     (nvis_children - 1) * gtk_box_get_spacing (box));
-            extra = width / nvis_children;
-        }
-        else if (nexpand_children > 0)
-        {
-            width = (gint) allocation->width - (gint) requisition.width;
-            extra = width / nexpand_children;
-        }
-        else
-        {
-            width = 0;
-            extra = 0;
-        }
-
-        x = allocation->x + border_width;
-        child_allocation.y = allocation->y + border_width;
-        child_allocation.height = MAX (1, (gint) allocation->height - (gint) border_width * 2);
-
-        for (child = gtk_container_get_children (GTK_CONTAINER (box));
-             child != NULL; child = g_list_next (child))
-        {
-            guint padding;
-            gboolean expand;
-            gboolean fill;
-            GtkPackType pack_type;
-
-            gtk_box_query_child_packing (box,
-                                         child->data,
-                                         &expand,
-                                         &fill,
-                                         &padding,
-                                         &pack_type);
-
-            if ((pack_type == GTK_PACK_START) && gtk_widget_get_visible (GTK_WIDGET (child->data)))
-            {
-                if (gtk_box_get_homogeneous (box))
-                {
-                    if (nvis_children == 1)
-                        child_width = width;
-                    else
-                        child_width = extra;
-
-                    nvis_children -= 1;
-                    width -= extra;
-                }
-                else
-                {
-                    GtkRequisition child_requisition;
-
-                    gtk_widget_get_preferred_size (GTK_WIDGET (child->data), &child_requisition, NULL);
-
-                    child_width = child_requisition.width + padding * 2;
-
-                    if (expand)
-                    {
-                        if (nexpand_children == 1)
-                            child_width += width;
-                        else
-                            child_width += extra;
-
-                        nexpand_children -= 1;
-                        width -= extra;
-                    }
-                }
-
-                if (fill)
-                {
-                    child_allocation.width = MAX (1, child_width - padding * 2);
-                    child_allocation.x = x + padding;
-                }
-                else
-                {
-                    GtkRequisition child_requisition;
-
-                    gtk_widget_get_preferred_size (GTK_WIDGET (child->data), &child_requisition, NULL);
-                    child_allocation.width = child_requisition.width;
-                    child_allocation.x = x + (child_width - child_allocation.width) / 2;
-                }
-
-                if (direction == GTK_TEXT_DIR_RTL)
-                    child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
-
-                gtk_widget_size_allocate (GTK_WIDGET (child->data), &child_allocation);
-
-                x += child_width + gtk_box_get_spacing (box);
-            }
-        }
-
-        x = allocation->x + allocation->width - border_width;
-
-        for (child = gtk_container_get_children (GTK_CONTAINER (box));
-             child != NULL; child = g_list_next (child))
-        {
-            guint padding;
-            gboolean expand;
-            gboolean fill;
-            GtkPackType pack_type;
-
-            gtk_box_query_child_packing (box,
-                                         child->data,
-                                         &expand,
-                                         &fill,
-                                         &padding,
-                                         &pack_type);
-
-            if ((pack_type == GTK_PACK_END) && gtk_widget_get_visible (GTK_WIDGET (child->data)))
-            {
-                GtkRequisition child_requisition;
-                gtk_widget_get_preferred_size (GTK_WIDGET (child->data), &child_requisition, NULL);
-
-                if (gtk_box_get_homogeneous (box))
-                {
-                    if (nvis_children == 1)
-                        child_width = width;
-                    else
-                        child_width = extra;
-
-                    nvis_children -= 1;
-                    width -= extra;
-                }
-                else
-                {
-                    child_width = child_requisition.width + padding * 2;
-
-                    if (expand)
-                    {
-                        if (nexpand_children == 1)
-                            child_width += width;
-                        else
-                            child_width += extra;
-
-                        nexpand_children -= 1;
-                        width -= extra;
-                    }
-                }
-
-                if (fill)
-                {
-                    child_allocation.width = MAX (1, child_width - padding * 2);
-                    child_allocation.x = x + padding - child_width;
-                }
-                else
-                {
-                    child_allocation.width = child_requisition.width;
-                    child_allocation.x = x + (child_width - child_allocation.width) / 2 - child_width;
-                }
-
-                if (direction == GTK_TEXT_DIR_RTL)
-                    child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
-
-                gtk_widget_size_allocate (GTK_WIDGET (child->data), &child_allocation);
-
-                x -= (child_width + gtk_box_get_spacing (box));
-            }
-        }
-    }
-}
 
 /**
  * gdl_dock_bar_new:



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