[maemo-commits] [maemo-commits] r9808 - in projects/haf/branches/maemo-af-desktop/hildon-desktop: . libhildondesktop
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Mon Feb 12 15:42:27 EET 2007
- Previous message: [maemo-commits] r9807 - in projects/haf/trunk/hildon-theme-layout-4: . rc
- Next message: [maemo-commits] r9809 - in projects/haf/branches/maemo-af-desktop/hildon-desktop: . src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: moimart Date: 2007-02-12 15:42:26 +0200 (Mon, 12 Feb 2007) New Revision: 9808 Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog projects/haf/branches/maemo-af-desktop/hildon-desktop/libhildondesktop/hildon-desktop-panel.c Log: * libhildondesktop/hildon-desktop-panel.c: Refactored to use GtkHBoxClass and GtkVBoxClass instead. * ChangeLog updated. Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog =================================================================== --- projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog 2007-02-12 13:32:45 UTC (rev 9807) +++ projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog 2007-02-12 13:42:26 UTC (rev 9808) @@ -1,3 +1,8 @@ +2007-02-12 Moises Martinez <moises.martinez at nokia.com> + + * libhildondesktop/hildon-desktop-panel.c: Refactored to use + GtkHBoxClass and GtkVBoxClass instead. + 2007-02-09 Moises Martinez <moises.martinez at nokia.com> * libhildondesktop/hildon-desktop-panel-expandable.c: Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/libhildondesktop/hildon-desktop-panel.c =================================================================== --- projects/haf/branches/maemo-af-desktop/hildon-desktop/libhildondesktop/hildon-desktop-panel.c 2007-02-12 13:32:45 UTC (rev 9807) +++ projects/haf/branches/maemo-af-desktop/hildon-desktop/libhildondesktop/hildon-desktop-panel.c 2007-02-12 13:42:26 UTC (rev 9808) @@ -26,6 +26,9 @@ #include "hildon-desktop-panel.h" #include "hildon-desktop-panel-item.h" +#include <gtk/gtkhbox.h> +#include <gtk/gtkvbox.h> + #define HILDON_DESKTOP_PANEL_GET_PRIVATE(object) \ (G_TYPE_INSTANCE_GET_PRIVATE ((object), HILDON_DESKTOP_TYPE_PANEL, HildonDesktopPanel)) @@ -56,39 +59,32 @@ static void hildon_desktop_panel_init (HildonDesktopPanel *panel); -static void hildon_desktop_panel_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); +static void hildon_desktop_panel_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); -static void hildon_desktop_panel_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); +static void hildon_desktop_panel_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); -static void hildon_desktop_panel_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void hildon_desktop_panel_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void hildon_desktop_panel_vbox_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void hildon_desktop_panel_hbox_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void hildon_desktop_panel_vbox_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void hildon_desktop_panel_hbox_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); +static void hildon_desktop_panel_size_request (GtkWidget *widget, GtkRequisition *requisition); -static void hildon_desktop_panel_calc_positions (HildonDesktopPanel *panel, - HildonDesktopPanelItem *item); +static void hildon_desktop_panel_size_allocate (GtkWidget *widget,GtkAllocation *allocation); -static void hildon_desktop_panel_cadd (GtkContainer *container, - GtkWidget *widget); +static void hildon_desktop_panel_calc_positions (HildonDesktopPanel *panel, + HildonDesktopPanelItem *item); +static void hildon_desktop_panel_cadd (GtkContainer *container, + GtkWidget *widget); + void hildon_desktop_panel_real_add_button (HildonDesktopPanel *panel, GtkWidget *widget); +static GtkWidgetClass *hildon_desktop_panel_get_widget_class (HildonDesktopPanel *panel); + static void hildon_desktop_panel_class_init (HildonDesktopPanelClass *panel_class) { @@ -282,502 +278,53 @@ static void hildon_desktop_panel_size_request (GtkWidget *widget, GtkRequisition *requisition) { + GtkWidgetClass *klass; HildonDesktopPanel *panel = HILDON_DESKTOP_PANEL (widget); - if (panel->orient & GTK_ORIENTATION_VERTICAL) - hildon_desktop_panel_vbox_size_request (widget,requisition); - else - hildon_desktop_panel_hbox_size_request (widget,requisition); - + klass = hildon_desktop_panel_get_widget_class (panel); + + klass->size_request (widget, requisition); } static void hildon_desktop_panel_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { + GtkWidgetClass *klass; HildonDesktopPanel *panel = HILDON_DESKTOP_PANEL (widget); - if (panel->orient & GTK_ORIENTATION_VERTICAL) - hildon_desktop_panel_vbox_size_allocate (widget,allocation); - else - hildon_desktop_panel_hbox_size_allocate (widget,allocation); -} + klass = hildon_desktop_panel_get_widget_class (panel); -/* The next 4 functions are from gtkvbox.c and gtkhbox.c - * GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - */ -static void -hildon_desktop_panel_vbox_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - GtkBox *box; - GtkBoxChild *child; - GtkRequisition child_requisition; - GList *children; - gint nvis_children; - gint height; - - box = GTK_BOX (widget); - requisition->width = 0; - requisition->height = 0; - nvis_children = 0; - - children = box->children; - while (children) - { - child = children->data; - children = children->next; - - if (GTK_WIDGET_VISIBLE (child->widget)) - { - gtk_widget_size_request (child->widget, &child_requisition); - - if (box->homogeneous) - { - height = child_requisition.height + child->padding * 2; - requisition->height = MAX (requisition->height, height); - } - else - { - requisition->height += child_requisition.height + child->padding * 2; - } - - requisition->width = MAX (requisition->width, child_requisition.width); - - nvis_children += 1; - } - } - - if (nvis_children > 0) - { - if (box->homogeneous) - requisition->height *= nvis_children; - requisition->height += (nvis_children - 1) * box->spacing; - } - - requisition->width += GTK_CONTAINER (box)->border_width * 2; - requisition->height += GTK_CONTAINER (box)->border_width * 2; + klass->size_allocate (widget, allocation); } -static void -hildon_desktop_panel_vbox_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) +static GtkWidgetClass * +hildon_desktop_panel_get_widget_class (HildonDesktopPanel *panel) { - GtkBox *box; - GtkBoxChild *child; - GList *children; - GtkAllocation child_allocation; - gint nvis_children; - gint nexpand_children; - gint child_height; - gint height; - gint extra; - gint y; + GtkWidgetClass *klass; - box = GTK_BOX (widget); - widget->allocation = *allocation; - - nvis_children = 0; - nexpand_children = 0; - children = box->children; - - while (children) + switch (panel->orient) { - child = children->data; - children = children->next; + case GTK_ORIENTATION_HORIZONTAL: + klass = GTK_WIDGET_CLASS (gtk_type_class (GTK_TYPE_HBOX)); + break; + + case GTK_ORIENTATION_VERTICAL: + klass = GTK_WIDGET_CLASS (gtk_type_class (GTK_TYPE_VBOX)); + break; - if (GTK_WIDGET_VISIBLE (child->widget)) - { - nvis_children += 1; - if (child->expand) - nexpand_children += 1; - } + default: + g_assert_not_reached (); + klass = NULL; + break; } - if (nvis_children > 0) - { - if (box->homogeneous) - { - height = (allocation->height - - GTK_CONTAINER (box)->border_width * 2 - - (nvis_children - 1) * box->spacing); - extra = height / nvis_children; - } - else if (nexpand_children > 0) - { - height = (gint) allocation->height - (gint) widget->requisition.height; - extra = height / nexpand_children; - } - else - { - height = 0; - extra = 0; - } - - y = allocation->y + GTK_CONTAINER (box)->border_width; - child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width; - child_allocation.width = MAX (1, (gint) allocation->width - (gint) GTK_CONTAINER (box)->border_width * 2); - - children = box->children; - while (children) - { - child = children->data; - children = children->next; - - if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget)) - { - if (box->homogeneous) - { - if (nvis_children == 1) - child_height = height; - else - child_height = extra; - - nvis_children -= 1; - height -= extra; - } - else - { - GtkRequisition child_requisition; - - gtk_widget_get_child_requisition (child->widget, &child_requisition); - child_height = child_requisition.height + child->padding * 2; - - if (child->expand) - { - if (nexpand_children == 1) - child_height += height; - else - child_height += extra; - - nexpand_children -= 1; - height -= extra; - } - } - - if (child->fill) - { - child_allocation.height = MAX (1, child_height - (gint)child->padding * 2); - child_allocation.y = y + child->padding; - } - else - { - GtkRequisition child_requisition; - - gtk_widget_get_child_requisition (child->widget, &child_requisition); - child_allocation.height = child_requisition.height; - child_allocation.y = y + (child_height - child_allocation.height) / 2; - } - - gtk_widget_size_allocate (child->widget, &child_allocation); - - y += child_height + box->spacing; - } - } - - y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width; - - children = box->children; - while (children) - { - child = children->data; - children = children->next; - - if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget)) - { - GtkRequisition child_requisition; - gtk_widget_get_child_requisition (child->widget, &child_requisition); - - if (box->homogeneous) - { - if (nvis_children == 1) - child_height = height; - else - child_height = extra; - - nvis_children -= 1; - height -= extra; - } - else - { - child_height = child_requisition.height + child->padding * 2; - - if (child->expand) - { - if (nexpand_children == 1) - child_height += height; - else - child_height += extra; - - nexpand_children -= 1; - height -= extra; - } - } - - if (child->fill) - { - child_allocation.height = MAX (1, child_height - (gint)child->padding * 2); - child_allocation.y = y + child->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 (child->widget, &child_allocation); - - y -= (child_height + box->spacing); - } - } - } + return klass; } static void -hildon_desktop_panel_hbox_size_request (GtkWidget *widget, - GtkRequisition *requisition) +hildon_desktop_panel_calc_positions (HildonDesktopPanel *panel, + HildonDesktopPanelItem *item) { - GtkBox *box; - GtkBoxChild *child; - GList *children; - gint nvis_children; - gint width; - - box = GTK_BOX (widget); - requisition->width = 0; - requisition->height = 0; - nvis_children = 0; - - children = box->children; - while (children) - { - child = children->data; - children = children->next; - - if (GTK_WIDGET_VISIBLE (child->widget)) - { - GtkRequisition child_requisition; - - gtk_widget_size_request (child->widget, &child_requisition); - - if (box->homogeneous) - { - width = child_requisition.width + child->padding * 2; - requisition->width = MAX (requisition->width, width); - } - else - { - requisition->width += child_requisition.width + child->padding * 2; - } - - requisition->height = MAX (requisition->height, child_requisition.height); - - nvis_children += 1; - } - } - - if (nvis_children > 0) - { - if (box->homogeneous) - requisition->width *= nvis_children; - requisition->width += (nvis_children - 1) * box->spacing; - } - - requisition->width += GTK_CONTAINER (box)->border_width * 2; - requisition->height += GTK_CONTAINER (box)->border_width * 2; -} - -static void -hildon_desktop_panel_hbox_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - GtkBox *box; - GtkBoxChild *child; - GList *children; - GtkAllocation child_allocation; - gint nvis_children; - gint nexpand_children; - gint child_width; - gint width; - gint extra; - gint x; - GtkTextDirection direction; - - box = GTK_BOX (widget); - widget->allocation = *allocation; - - direction = gtk_widget_get_direction (widget); - - nvis_children = 0; - nexpand_children = 0; - children = box->children; - - while (children) - { - child = children->data; - children = children->next; - - if (GTK_WIDGET_VISIBLE (child->widget)) - { - nvis_children += 1; - if (child->expand) - nexpand_children += 1; - } - } - - if (nvis_children > 0) - { - if (box->homogeneous) - { - width = (allocation->width - - GTK_CONTAINER (box)->border_width * 2 - - (nvis_children - 1) * box->spacing); - extra = width / nvis_children; - } - else if (nexpand_children > 0) - { - width = (gint) allocation->width - (gint) widget->requisition.width; - extra = width / nexpand_children; - } - else - { - width = 0; - extra = 0; - } - - x = allocation->x + GTK_CONTAINER (box)->border_width; - child_allocation.y = allocation->y + GTK_CONTAINER (box)->border_width; - child_allocation.height = MAX (1, (gint) allocation->height - (gint) GTK_CONTAINER (box)->border_width * 2); - - children = box->children; - while (children) - { - child = children->data; - children = children->next; - - if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget)) - { - if (box->homogeneous) - { - if (nvis_children == 1) - child_width = width; - else - child_width = extra; - - nvis_children -= 1; - width -= extra; - } - else - { - GtkRequisition child_requisition; - - gtk_widget_get_child_requisition (child->widget, &child_requisition); - - child_width = child_requisition.width + child->padding * 2; - - if (child->expand) - { - if (nexpand_children == 1) - child_width += width; - else - child_width += extra; - - nexpand_children -= 1; - width -= extra; - } - } - - if (child->fill) - { - child_allocation.width = MAX (1, (gint) child_width - (gint) child->padding * 2); - child_allocation.x = x + child->padding; - } - else - { - GtkRequisition child_requisition; - - gtk_widget_get_child_requisition (child->widget, &child_requisition); - 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 (child->widget, &child_allocation); - - x += child_width + box->spacing; - } - } - - x = allocation->x + allocation->width - GTK_CONTAINER (box)->border_width; - - children = box->children; - while (children) - { - child = children->data; - children = children->next; - - if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget)) - { - GtkRequisition child_requisition; - gtk_widget_get_child_requisition (child->widget, &child_requisition); - - if (box->homogeneous) - { - if (nvis_children == 1) - child_width = width; - else - child_width = extra; - - nvis_children -= 1; - width -= extra; - } - else - { - child_width = child_requisition.width + child->padding * 2; - - if (child->expand) - { - if (nexpand_children == 1) - child_width += width; - else - child_width += extra; - - nexpand_children -= 1; - width -= extra; - } - } - - if (child->fill) - { - child_allocation.width = MAX (1, (gint)child_width - (gint)child->padding * 2); - child_allocation.x = x + child->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 (child->widget, &child_allocation); - - x -= (child_width + box->spacing); - } - } - } -} - -static void -hildon_desktop_panel_calc_positions (HildonDesktopPanel *panel, - HildonDesktopPanelItem *item) -{ /* FIXME: Please, implement me smoothly and very optimized */ /* FIXME: This is not that smooth implementation, this only add the item*/ if (panel->pack_start) @@ -785,58 +332,44 @@ else gtk_box_pack_end (GTK_BOX (panel), GTK_WIDGET (item), FALSE, FALSE, 0); - gtk_widget_show (GTK_WIDGET (item)); + gtk_widget_show (GTK_WIDGET (item)); } -void +void hildon_desktop_panel_real_add_button (HildonDesktopPanel *panel, GtkWidget *widget) { GtkWidget *panel_widget; GtkRequisition req; gint width, height; - + g_return_if_fail (panel && - widget && + widget && HILDON_DESKTOP_IS_PANEL (panel) && - GTK_IS_WIDGET (panel)); + GTK_IS_WIDGET (panel)); panel_widget = GTK_WIDGET (panel); gtk_widget_get_child_requisition (widget, &req); - if (req.width > 0) - { + if (req.width > 0) width = req.width; - } - else if (panel->item_width > 0) - { + else + if (panel->item_width > 0) width = panel->item_width; - } else - { width = HILDON_DESKTOP_PANEL_WIDGET_DEFAULT_WIDTH; - } - - if (req.height > 0) - { + + if (req.height > 0) height = req.height; - } - else if (panel->item_height > 0) - { + else + if (panel->item_height > 0) height = panel->item_height; - } else - { height = HILDON_DESKTOP_PANEL_WIDGET_DEFAULT_HEIGHT; - } - gtk_widget_set_size_request (widget, - width, - height); - gtk_widget_set_size_request (GTK_BIN (widget)->child, - width, - height); - + gtk_widget_set_size_request (widget, width, height); + gtk_widget_set_size_request (GTK_BIN (widget)->child, width, height); + if (HILDON_DESKTOP_IS_PANEL_ITEM (widget)) { hildon_desktop_panel_calc_positions (panel, HILDON_DESKTOP_PANEL_ITEM (widget));/*FIXME: Do this! */ @@ -849,7 +382,6 @@ gtk_box_pack_end (GTK_BOX (panel), widget, FALSE, FALSE, 0); } } -/* Public declarations */ void hildon_desktop_panel_add_button (HildonDesktopPanel *panel, GtkWidget *widget) @@ -866,6 +398,8 @@ #else panel->orient = orientation; #endif + + gtk_widget_queue_resize (GTK_WIDGET (panel)); } GtkOrientation @@ -895,4 +429,6 @@ #else panel->orient = !priv->orient; #endif + + gtk_widget_queue_resize (GTK_WIDGET (panel)); }
- Previous message: [maemo-commits] r9807 - in projects/haf/trunk/hildon-theme-layout-4: . rc
- Next message: [maemo-commits] r9809 - in projects/haf/branches/maemo-af-desktop/hildon-desktop: . src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]