1 --- gtk+-2.6.4/gtk/gtkhbbox.c 2004-08-09 19:59:52.000000000 +0300
2 +++ gtk+-2.6.4/gtk/gtkhbbox.c 2005-04-06 16:19:36.644967480 +0300
4 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
7 +/* Modified for Nokia Oyj during 2002-2005. See CHANGES file for list
11 +/* Hildon : Button spacing according to the spec. */
12 +#define HILDON_BUTTON_SPACING 5
13 +/* Selecting hetefogenous mode for a childlayout */
14 +#define GTK_BUTTONBOX_HETEROGENOUS 6
20 +/* Hildon : We need this to mess with buttons graphics. */
21 +#include "gtkbutton.h"
23 static void gtk_hbutton_box_class_init (GtkHButtonBoxClass *klass);
24 static void gtk_hbutton_box_init (GtkHButtonBox *box);
26 static void gtk_hbutton_box_size_allocate (GtkWidget *widget,
27 GtkAllocation *allocation);
29 +static void osso_gtk_hbutton_child_showhide_handler (GtkWidget *widget,
30 + gpointer user_data);
31 +static void osso_gtk_hbutton_box_remove_child_signal_handlers (GtkHButtonBox *hbbox,
32 + GtkWidget *removed_widget,
34 +static void osso_gtk_hbutton_box_find_button_detail (GtkHButtonBox *hbbox,
35 + GtkWidget *addremovewidget,
38 static gint default_spacing = 30;
39 static gint default_layout_style = GTK_BUTTONBOX_EDGE;
43 widget_class->size_request = gtk_hbutton_box_size_request;
44 widget_class->size_allocate = gtk_hbutton_box_size_allocate;
47 + * Name buttons only if hildon like style property is set
49 + gtk_widget_class_install_style_property (widget_class,
50 + g_param_spec_boolean
53 + "Name buttons, 1/0",
55 + G_PARAM_READABLE) );
59 gtk_hbutton_box_init (GtkHButtonBox *hbutton_box)
61 - /* button_box_init has done everything allready */
62 + /* button_box_init has done everything allready */
68 hbutton_box = g_object_new (GTK_TYPE_HBUTTON_BOX, NULL);
70 + /* Attach signal handler for 'hildonizing' buttons.
71 + * gtk_hbutton_box_hildonize_buttons will check the name
72 + * and if it is something we're interested in i.e.
74 + * hildon_dialogbuttons
75 + * hildon_viewbuttons
77 + * it will do the hildonizing
79 + g_signal_connect_after (G_OBJECT (hbutton_box), "remove",
80 + G_CALLBACK (osso_gtk_hbutton_box_remove_child_signal_handlers),
82 + g_signal_connect_after( G_OBJECT( hbutton_box ), "add",
83 + G_CALLBACK( osso_gtk_hbutton_box_find_button_detail ),
85 + g_signal_connect_after( G_OBJECT( hbutton_box ), "remove",
86 + G_CALLBACK( osso_gtk_hbutton_box_find_button_detail ),
88 return GTK_WIDGET (hbutton_box);
94 GtkButtonBoxStyle layout;
96 + GtkBoxChild *child_req;
97 + GList *children_req;
98 + GtkRequisition treq;
101 box = GTK_BOX (widget);
102 bbox = GTK_BUTTON_BOX (widget);
107 + /* should GTK_BUTTONBOX_HETEROGENOUS add into the GtkButtonBoxStyle
110 + if( !box->homogeneous )
111 + layout = GTK_BUTTONBOX_HETEROGENOUS;
113 if (nvis_children == 0)
115 requisition->width = 0;
116 @@ -177,11 +236,36 @@
117 case GTK_BUTTONBOX_END:
118 requisition->width = nvis_children*child_width + ((nvis_children-1)*spacing);
120 + case GTK_BUTTONBOX_HETEROGENOUS:
121 + children_req = GTK_BOX (box)->children;
122 + child_req = children_req->data;
123 + requisition->width = 0;
125 + while (children_req)
127 + child_req = children_req->data;
128 + children_req = children_req->next;
130 + if (GTK_WIDGET_VISIBLE (child_req->widget))
132 + gtk_widget_get_child_requisition( child_req->widget,
134 + requisition->width += treq.width;
136 + gtk_widget_style_get(widget,
137 + "child-internal-pad-x",
138 + &(child_xpad), NULL);
139 + requisition->width += (child_xpad*2);
142 + requisition->width += ((nvis_children-1)*spacing);
146 g_assert_not_reached();
151 requisition->height = child_height;
156 widget->allocation = *allocation;
157 width = allocation->width - GTK_CONTAINER (box)->border_width*2;
159 + if( !base_box->homogeneous )
160 + layout = GTK_BUTTONBOX_HETEROGENOUS;
164 case GTK_BUTTONBOX_SPREAD:
166 - GTK_CONTAINER (box)->border_width;
167 secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
169 + case GTK_BUTTONBOX_HETEROGENOUS:
172 + GtkBoxChild *child_h;
173 + GList *children_h = GTK_BOX (box)->children;
174 + /* heterogenous sized childs onto center */
175 + childspacing = spacing;
176 + child_h = children_h->data;
178 + while (children_h )
180 + if ( g_list_length (children_h) == 0 ) break;
182 + child_h = children_h->data;
183 + children_h = children_h->next;
185 + if (GTK_WIDGET_VISIBLE (child_h->widget))
187 + gint child_xpad = 0;
188 + GtkRequisition treq;
189 + gtk_widget_get_child_requisition( child_h->widget, &(treq) );
190 + sumwidth += treq.width;
192 + gtk_widget_style_get(widget,
193 + "child-internal-pad-x",
194 + &(child_xpad), NULL);
195 + sumwidth += (child_xpad*2);
198 + x = secondary_x = allocation->x +
199 + ( (allocation->width - sumwidth - (spacing * (nvis_children - 1)))/2 );
203 g_assert_not_reached();
205 @@ -282,10 +403,33 @@
207 if (GTK_WIDGET_VISIBLE (child->widget))
209 - child_allocation.width = child_width;
210 child_allocation.height = child_height;
211 child_allocation.y = y;
213 + if(layout != GTK_BUTTONBOX_HETEROGENOUS)
215 + child_allocation.width = child_width;
217 + else /* if layout will be hetergenous */
219 + gint child_hwidth = 0;
220 + GtkRequisition treq;
221 + gint child_xpad = 0;
223 + gtk_widget_get_child_requisition( child->widget, &(treq) );
224 + child_hwidth += treq.width;
226 + gtk_widget_style_get(widget,
227 + "child-internal-pad-x",
228 + &child_xpad, NULL);
229 + child_hwidth += (child_xpad*2);
231 + child_allocation.width = child_hwidth;
232 + childspace = child_hwidth + childspacing;
236 + /* calculate the horizontal location */
237 if (child->is_secondary)
239 child_allocation.x = secondary_x;
240 @@ -304,4 +448,104 @@
245 +/* Function to wrap "hide" and "show" signals to call
246 + * osso_gtk_hbutton_box_find_button_detail -function.*/
247 +static void osso_gtk_hbutton_child_showhide_handler (GtkWidget *widget,
248 + gpointer user_data)
250 + osso_gtk_hbutton_box_find_button_detail (widget, GTK_WIDGET (user_data), NULL);
253 +/* Function to remove "show"&"hide" signal handlers
254 + * from a child when it's removed. */
255 +static void osso_gtk_hbutton_box_remove_child_signal_handlers (GtkHButtonBox *hbbox,
256 + GtkWidget *removed_widget,
259 + g_signal_handlers_disconnect_by_func (G_OBJECT (removed_widget), osso_gtk_hbutton_box_find_button_detail, hbbox);
262 +/* Signal handler called when we have to set
263 + * painting detail values for buttons in this
264 + * gtk_horizontal_button_box.
266 +static void osso_gtk_hbutton_box_find_button_detail (GtkHButtonBox *hbbox,
267 + GtkWidget *addremovewidget,
271 + gint visible_buttons = 0;
272 + gint secondary_buttons = 0;
273 + GtkWidget *leftmost_button = NULL;
274 + GtkWidget *rightmost_button = NULL;
276 + for( child = GTK_BOX (hbbox)->children ; child ; child = child->next )
278 + GtkBoxChild *box_child = child->data;
279 + GtkWidget *child_widget = box_child->widget;
280 + gulong signal_handler = g_signal_handler_find ( G_OBJECT( child_widget ),
281 + G_SIGNAL_MATCH_FUNC,
283 + G_CALLBACK (osso_gtk_hbutton_child_showhide_handler),
286 + if (signal_handler == 0)
288 + g_signal_connect_object ( G_OBJECT( child_widget ),
290 + G_CALLBACK ( osso_gtk_hbutton_child_showhide_handler ),
291 + hbbox, G_CONNECT_SWAPPED);
292 + g_signal_connect_object ( G_OBJECT( child_widget ),
294 + G_CALLBACK ( osso_gtk_hbutton_child_showhide_handler ),
295 + hbbox, G_CONNECT_SWAPPED);
298 + if ((GTK_WIDGET_VISIBLE (child_widget)) &&
299 + (GTK_IS_BUTTON (child_widget)))
304 + if (leftmost_button == NULL)
305 + leftmost_button = child_widget;
307 + if (secondary_buttons == 0)
308 + rightmost_button = child_widget;
310 + if (box_child->is_secondary)
312 + rightmost_button = child_widget;
313 + secondary_buttons++;
316 + if (box_child->is_secondary)
317 + rightmost_button = child_widget;
320 + if (visible_buttons == 0)
323 + for( child = GTK_BOX (hbbox)->children ; child ; child = child->next )
325 + GtkBoxChild *box_child = child->data;
326 + GtkWidget *child_widget = box_child->widget;
327 + OssoGtkButtonAttachFlags attachflags = OSSO_GTK_BUTTON_ATTACH_NORTH | OSSO_GTK_BUTTON_ATTACH_SOUTH;
328 + gboolean automatic_detail;
330 + if (!((GTK_WIDGET_VISIBLE (child_widget)) &&
331 + (GTK_IS_BUTTON (child_widget))))
334 + if (child_widget == leftmost_button)
335 + attachflags |= OSSO_GTK_BUTTON_ATTACH_WEST;
337 + if (child_widget == rightmost_button)
338 + attachflags |= OSSO_GTK_BUTTON_ATTACH_EAST;
340 + g_object_get (G_OBJECT (child_widget), "automatic_detail", &automatic_detail, NULL);
341 + if (automatic_detail == TRUE)
342 + g_object_set (G_OBJECT (child_widget), "detail", osso_gtk_button_attach_details[attachflags], NULL);