summaryrefslogtreecommitdiff
path: root/packages/gtk+/gtk+-2.6.4-1.osso7/gtkhbbox.c.diff
blob: e43db37f5c17466ec8f34fb0b825ac14d0868ec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
--- gtk+-2.6.4/gtk/gtkhbbox.c	2004-08-09 19:59:52.000000000 +0300
+++ gtk+-2.6.4/gtk/gtkhbbox.c	2005-04-06 16:19:36.644967480 +0300
@@ -24,10 +24,20 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+/* Modified for Nokia Oyj during 2002-2005. See CHANGES file for list
+ * of changes.
+ */
+
+/* Hildon : Button spacing according to the spec. */
+#define HILDON_BUTTON_SPACING 5
+/* Selecting hetefogenous mode for a childlayout */
+#define GTK_BUTTONBOX_HETEROGENOUS 6
+
 #include <config.h>
 #include "gtkalias.h"
 #include "gtkhbbox.h"
-
+/* Hildon : We need this to mess with buttons graphics. */
+#include "gtkbutton.h"
 
 static void gtk_hbutton_box_class_init    (GtkHButtonBoxClass   *klass);
 static void gtk_hbutton_box_init          (GtkHButtonBox        *box);
@@ -36,6 +46,15 @@
 static void gtk_hbutton_box_size_allocate (GtkWidget      *widget,
 					   GtkAllocation  *allocation);
 
+static void osso_gtk_hbutton_child_showhide_handler (GtkWidget *widget,
+						     gpointer user_data);
+static void osso_gtk_hbutton_box_remove_child_signal_handlers (GtkHButtonBox *hbbox,
+							       GtkWidget *removed_widget,
+							       gpointer data);
+static void osso_gtk_hbutton_box_find_button_detail (GtkHButtonBox *hbbox,
+					      GtkWidget *addremovewidget,
+					      gpointer data);
+
 static gint default_spacing = 30;
 static gint default_layout_style = GTK_BUTTONBOX_EDGE;
 
@@ -76,12 +95,23 @@
 
   widget_class->size_request = gtk_hbutton_box_size_request;
   widget_class->size_allocate = gtk_hbutton_box_size_allocate;
+
+  /* HILDON:
+   * Name buttons only if hildon like style property is set
+   */
+  gtk_widget_class_install_style_property (widget_class,
+					   g_param_spec_boolean 
+					   ( "hildonlike",
+					     "hildonlike looks",
+					     "Name buttons, 1/0",
+					     FALSE,
+					     G_PARAM_READABLE) );
 }
 
 static void
 gtk_hbutton_box_init (GtkHButtonBox *hbutton_box)
 {
-	/* button_box_init has done everything allready */
+  /* button_box_init has done everything allready */
 }
 
 GtkWidget*
@@ -91,6 +121,24 @@
 
   hbutton_box = g_object_new (GTK_TYPE_HBUTTON_BOX, NULL);
 
+  /* Attach signal handler for 'hildonizing' buttons.
+   * gtk_hbutton_box_hildonize_buttons will check the name
+   * and if it is something we're interested in i.e.
+   *
+   *   hildon_dialogbuttons
+   *   hildon_viewbuttons
+   *
+   * it will do the hildonizing
+   */
+  g_signal_connect_after (G_OBJECT (hbutton_box), "remove",
+		    G_CALLBACK (osso_gtk_hbutton_box_remove_child_signal_handlers),
+		    NULL);
+  g_signal_connect_after( G_OBJECT( hbutton_box ), "add",
+		  G_CALLBACK( osso_gtk_hbutton_box_find_button_detail ),
+		  NULL );
+  g_signal_connect_after( G_OBJECT( hbutton_box ), "remove",
+		  G_CALLBACK( osso_gtk_hbutton_box_find_button_detail ),
+		  NULL );
   return GTK_WIDGET (hbutton_box);
 }
 
@@ -145,6 +193,11 @@
   gint child_height;
   gint spacing;
   GtkButtonBoxStyle layout;
+  gint child_xpad=0;
+  GtkBoxChild *child_req;
+  GList *children_req;
+  GtkRequisition treq;
+
   
   box = GTK_BOX (widget);
   bbox = GTK_BUTTON_BOX (widget);
@@ -159,6 +212,12 @@
                                      &child_width,
                                      &child_height);
 
+  /* should GTK_BUTTONBOX_HETEROGENOUS add into the GtkButtonBoxStyle 
+     enum struct 
+  */ 
+   if( !box->homogeneous )
+     layout = GTK_BUTTONBOX_HETEROGENOUS; 
+
   if (nvis_children == 0)
   {
     requisition->width = 0; 
@@ -177,11 +236,36 @@
     case GTK_BUTTONBOX_END:
       requisition->width = nvis_children*child_width + ((nvis_children-1)*spacing);
       break;
+    case GTK_BUTTONBOX_HETEROGENOUS:
+      children_req = GTK_BOX (box)->children;
+      child_req = children_req->data;
+      requisition->width = 0; 
+
+      while (children_req)
+	{ 
+	  child_req = children_req->data;
+	  children_req = children_req->next;
+
+	  if (GTK_WIDGET_VISIBLE (child_req->widget))
+	    {
+	      gtk_widget_get_child_requisition( child_req->widget, 
+						&(treq) );   	      
+	      requisition->width += treq.width;
+	 
+              gtk_widget_style_get(widget, 
+				   "child-internal-pad-x", 
+				   &(child_xpad), NULL);
+	      requisition->width  += (child_xpad*2);	      
+	    }
+      	}
+      requisition->width += ((nvis_children-1)*spacing);
+
+      break; 
     default:
       g_assert_not_reached();
       break;
     }
-	  
+    
     requisition->height = child_height;
   }
 	  
@@ -227,6 +311,10 @@
                                      &child_height);
   widget->allocation = *allocation;
   width = allocation->width - GTK_CONTAINER (box)->border_width*2;
+
+  if( !base_box->homogeneous )
+     layout = GTK_BUTTONBOX_HETEROGENOUS;
+
   switch (layout)
   {
   case GTK_BUTTONBOX_SPREAD:
@@ -264,6 +352,39 @@
       - GTK_CONTAINER (box)->border_width;
     secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
     break;
+  case GTK_BUTTONBOX_HETEROGENOUS:
+    {
+      gint sumwidth = 0;
+      GtkBoxChild *child_h;
+      GList *children_h = GTK_BOX (box)->children;
+        /* heterogenous sized childs onto center */
+      childspacing = spacing;
+      child_h = children_h->data;
+
+      while (children_h )
+	{
+	  if ( g_list_length (children_h) == 0 ) break;  
+
+	  child_h = children_h->data;
+	  children_h = children_h->next;
+
+	  if (GTK_WIDGET_VISIBLE (child_h->widget))
+	    {
+	      gint child_xpad = 0;
+	      GtkRequisition treq;
+	      gtk_widget_get_child_requisition( child_h->widget, &(treq) );  
+	      sumwidth += treq.width;
+
+	      gtk_widget_style_get(widget, 
+				   "child-internal-pad-x", 
+				   &(child_xpad), NULL); 
+	      sumwidth += (child_xpad*2);
+	    }
+	}
+      x = secondary_x = allocation->x + 
+       ( (allocation->width - sumwidth - (spacing * (nvis_children - 1)))/2 );
+      break; 
+    }
   default:
     g_assert_not_reached();
     break;
@@ -282,10 +403,33 @@
 
       if (GTK_WIDGET_VISIBLE (child->widget))
 	{
-	  child_allocation.width = child_width;
 	  child_allocation.height = child_height;
 	  child_allocation.y = y;
 	  
+	  if(layout != GTK_BUTTONBOX_HETEROGENOUS)
+	    {
+	      child_allocation.width = child_width; 
+	    }
+	  else /* if layout will be hetergenous */
+	    {
+	      gint child_hwidth = 0;
+	      GtkRequisition treq;
+	      gint child_xpad = 0;
+
+	      gtk_widget_get_child_requisition( child->widget, &(treq) );
+	      child_hwidth += treq.width;      
+
+	      gtk_widget_style_get(widget, 
+				   "child-internal-pad-x", 
+				   &child_xpad, NULL);
+	      child_hwidth += (child_xpad*2);
+	         
+	      child_allocation.width =  child_hwidth;
+	      childspace = child_hwidth + childspacing;
+
+	    }
+	  
+	  /* calculate the horizontal location */
 	  if (child->is_secondary)
 	    {
 	      child_allocation.x = secondary_x;
@@ -304,4 +448,104 @@
 	}
     }
 }
+
+/* Function to wrap "hide" and "show" signals to call
+ * osso_gtk_hbutton_box_find_button_detail -function.*/
+static void osso_gtk_hbutton_child_showhide_handler (GtkWidget *widget,
+						     gpointer user_data)
+{
+  osso_gtk_hbutton_box_find_button_detail (widget, GTK_WIDGET (user_data), NULL);
+}
   
+/* Function to remove "show"&"hide" signal handlers
+ * from a child when it's removed. */
+static void osso_gtk_hbutton_box_remove_child_signal_handlers (GtkHButtonBox *hbbox,
+							       GtkWidget *removed_widget,
+							       gpointer data)
+{
+  g_signal_handlers_disconnect_by_func (G_OBJECT (removed_widget), osso_gtk_hbutton_box_find_button_detail, hbbox);
+}
+
+/* Signal handler called when we have to set
+ * painting detail values for buttons in this 
+ * gtk_horizontal_button_box.
+ */  
+static void osso_gtk_hbutton_box_find_button_detail (GtkHButtonBox *hbbox,
+					      GtkWidget *addremovewidget,
+					      gpointer data)
+{
+  GList *child;
+  gint visible_buttons = 0;
+  gint secondary_buttons = 0;
+  GtkWidget *leftmost_button = NULL;
+  GtkWidget *rightmost_button = NULL;
+
+  for( child = GTK_BOX (hbbox)->children ; child ; child = child->next ) 
+    {
+      GtkBoxChild *box_child = child->data;
+      GtkWidget *child_widget = box_child->widget;
+      gulong signal_handler = g_signal_handler_find ( G_OBJECT( child_widget ),
+						      G_SIGNAL_MATCH_FUNC,
+						      0, 0, NULL,
+						      G_CALLBACK (osso_gtk_hbutton_child_showhide_handler),
+						      NULL);
+
+      if (signal_handler == 0)
+	{
+	  g_signal_connect_object ( G_OBJECT( child_widget ), 
+				    "hide", 
+				    G_CALLBACK ( osso_gtk_hbutton_child_showhide_handler ), 
+				    hbbox, G_CONNECT_SWAPPED);
+	  g_signal_connect_object ( G_OBJECT( child_widget ), 
+				    "show", 
+				    G_CALLBACK ( osso_gtk_hbutton_child_showhide_handler ), 
+				    hbbox, G_CONNECT_SWAPPED);
+	}
+
+      if ((GTK_WIDGET_VISIBLE (child_widget)) &&
+         (GTK_IS_BUTTON (child_widget)))
+	visible_buttons++;
+      else
+	continue;
+
+      if (leftmost_button == NULL)
+	leftmost_button = child_widget;
+
+      if (secondary_buttons == 0)
+	rightmost_button = child_widget;
+      else 
+	if (box_child->is_secondary)
+	  {
+	    rightmost_button = child_widget;
+	    secondary_buttons++;
+	  }
+
+      if (box_child->is_secondary) 
+        rightmost_button = child_widget;
+    }
+
+  if (visible_buttons == 0)
+    return;
+
+  for( child = GTK_BOX (hbbox)->children ; child ; child = child->next ) 
+    {
+      GtkBoxChild *box_child = child->data;
+      GtkWidget *child_widget = box_child->widget;
+      OssoGtkButtonAttachFlags attachflags = OSSO_GTK_BUTTON_ATTACH_NORTH | OSSO_GTK_BUTTON_ATTACH_SOUTH;
+      gboolean automatic_detail;
+
+      if (!((GTK_WIDGET_VISIBLE (child_widget)) &&
+	  (GTK_IS_BUTTON (child_widget))))
+	continue;
+
+      if (child_widget == leftmost_button)
+	attachflags |= OSSO_GTK_BUTTON_ATTACH_WEST;
+
+      if (child_widget == rightmost_button)
+	attachflags |= OSSO_GTK_BUTTON_ATTACH_EAST;
+
+      g_object_get (G_OBJECT (child_widget), "automatic_detail", &automatic_detail, NULL);
+      if (automatic_detail == TRUE)
+        g_object_set (G_OBJECT (child_widget), "detail", osso_gtk_button_attach_details[attachflags], NULL);
+    }
+}