]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/gtk+/gtk+-2.6.4-1.osso7/gtkbutton.c.diff
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / gtk+ / gtk+-2.6.4-1.osso7 / gtkbutton.c.diff
1 --- gtk+-2.6.4/gtk/gtkbutton.c  2005-01-25 22:54:43.000000000 +0200
2 +++ gtk+-2.6.4/gtk/gtkbutton.c  2005-04-06 16:19:36.249027672 +0300
3 @@ -24,6 +24,10 @@
4   * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
5   */
6  
7 +/* Modified for Nokia Oyj during 2002-2005. See CHANGES file for list
8 + * of changes.
9 + */
10 +
11  #include <config.h>
12  #include <string.h>
13  #include "gtkalias.h"
14 @@ -38,8 +42,33 @@
15  #include "gtkiconfactory.h"
16  #include "gtkintl.h"
17  
18 +/* Osso addition:
19 + * Here are the details for each attach 
20 + * bitmask combination. */
21 +const gchar *osso_gtk_button_attach_details [OSSO_GTK_BUTTON_ATTACH_ENUM_END] =
22 +  { "osso_button",
23 +    "osso_button_n",
24 +    "osso_button_e",
25 +    "osso_button_ne",
26 +    "osso_button_s",
27 +    "osso_button_ns",
28 +    "osso_button_es",
29 +    "osso_button_nes",
30 +    "osso_button_w",
31 +    "osso_button_nw",
32 +    "osso_button_ew",
33 +    "osso_button_new",
34 +    "osso_button_sw",
35 +    "osso_button_nsw",
36 +    "osso_button_esw",
37 +    "osso_button_nesw",
38 +  };
39 +
40  #define CHILD_SPACING     1
41  
42 +/* Take this away after font drawing is fixed */
43 +#define OSSO_FONT_HACK TRUE
44 +
45  static const GtkBorder default_default_border = { 1, 1, 1, 1 };
46  static const GtkBorder default_default_outside_border = { 0, 0, 0, 0 };
47  
48 @@ -68,6 +97,9 @@
49    PROP_FOCUS_ON_CLICK,
50    PROP_XALIGN,
51    PROP_YALIGN,
52 +  PROP_DETAIL,
53 +  PROP_AUTOMATIC_DETAIL,
54 +  PROP_KEYBOARD_BUTTON
55  };
56  
57  #define GTK_BUTTON_GET_PRIVATE(o)       (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_BUTTON, GtkButtonPrivate))
58 @@ -80,6 +112,10 @@
59    GtkWidget   *image;
60    guint        align_set : 1;
61    guint        image_is_stock : 1;
62 +  gchar       *detail;
63 +  gboolean     automatic_detail;
64 +  gboolean     keyboard_button;
65 +  GtkLabel    *keyboard_label;
66  };
67  
68  static void gtk_button_class_init     (GtkButtonClass   *klass);
69 @@ -231,6 +267,14 @@
70                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
71    
72    g_object_class_install_property (gobject_class,
73 +                                  PROP_KEYBOARD_BUTTON,
74 +                                   g_param_spec_boolean ("keyboard_button",
75 +                                                        P_("Keyboard button"),
76 +                                                        P_("If set, label foo"),
77 +                                                        FALSE,
78 +                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
79 +  
80 +  g_object_class_install_property (gobject_class,
81                                     PROP_USE_STOCK,
82                                     g_param_spec_boolean ("use_stock",
83                                                          P_("Use stock"),
84 @@ -418,6 +462,77 @@
85                                                        P_("Whether stock icons should be shown in buttons"),
86                                                        TRUE,
87                                                        G_PARAM_READWRITE));
88 +
89 +  gtk_widget_class_install_style_property (widget_class,
90 +                                          g_param_spec_int ("child_spacing",
91 +                                                            _("Child spacing"),
92 +                                                            _("Spacing between button edges and child."),
93 +                                                            0,
94 +                                                            G_MAXINT,
95 +                                                            CHILD_SPACING,
96 +                                                            G_PARAM_READABLE));
97 +  /* Osso additions below */
98 +  g_object_class_install_property (gobject_class,
99 +                                  PROP_DETAIL,
100 +                                  g_param_spec_string ("detail",
101 +                                                       P_("Detail"),
102 +                                                       P_("The detail the button is drawn with."),
103 +                                                       "buttondefault",
104 +                                                       G_PARAM_READWRITE));
105 +
106 +  g_object_class_install_property (gobject_class,
107 +                                  PROP_AUTOMATIC_DETAIL,
108 +                                  g_param_spec_boolean ("automatic_detail",
109 +                                                        P_("Automatic Detail"),
110 +                                                        P_("Whether setting detail is automatic based on GtkTable/GtkHButtonBox."),
111 +                                                        TRUE,
112 +                                                        G_PARAM_READWRITE));
113 +
114 +
115 +  gtk_widget_class_install_style_property (widget_class,
116 +                                          g_param_spec_int ("child_offset_y",
117 +                                                            _("Child Y Offset"),
118 +                                                            _("Enable hack how many pixels to add/take away from GtkButton's child size allocation."),
119 +                                                            G_MININT,
120 +                                                            G_MAXINT,
121 +                                                            0,
122 +                                                            G_PARAM_READABLE));
123 +
124 +  /* OSSO: This is used to find out whether
125 +   * button is a GtkTreeView column Listbox
126 +   * header or not */
127 +  gtk_widget_class_install_style_property (widget_class,
128 +                                          g_param_spec_boolean ("listboxheader",
129 +                                                                P_( "Listbox header" ),
130 +                                                                P_( "Listbox header ( FALSE / TRUE )" ),
131 +                                                                FALSE,
132 +                                                                G_PARAM_READABLE));
133 +
134 +  /* OSSO: Column Listbox header separator height */
135 +  gtk_widget_class_install_style_property (widget_class,
136 +                                          g_param_spec_int ("separator-height",
137 +                                                            P_( "Separator height" ),
138 +                                                            P_( "Listbox header separator height ( FALSE / TRUE )" ),
139 +                                                            0,
140 +                                                            G_MAXINT,
141 +                                                            0,
142 +                                                            G_PARAM_READABLE));
143 +
144 +  gtk_widget_class_install_style_property (widget_class,
145 +                                          g_param_spec_boxed ("padding",
146 +                                                              P_("Padding"),
147 +                                                              P_("Paddings around the button child"),
148 +                                                              GTK_TYPE_BORDER,
149 +                                                              G_PARAM_READABLE));
150 +
151 +  gtk_widget_class_install_style_property (widget_class,
152 +                                          g_param_spec_int ("minimum_width",
153 +                                                            P_("Minimum Width"),
154 +                                                            P_("Minimum width of the button"),
155 +                                                            0,
156 +                                                            G_MAXINT,
157 +                                                            0,
158 +                                                            G_PARAM_READABLE));
159    
160    g_type_class_add_private (gobject_class, sizeof (GtkButtonPrivate));  
161  }
162 @@ -445,7 +560,14 @@
163    priv->xalign = 0.5;
164    priv->yalign = 0.5;
165    priv->align_set = 0;
166 +  priv->detail = g_strdup("buttondefault");
167 +  priv->automatic_detail = TRUE;
168 +  priv->keyboard_button = FALSE;
169 +  priv->keyboard_label = NULL;
170    priv->image_is_stock = TRUE;
171 +
172 +  g_object_set (G_OBJECT (button), "tap_and_hold_state",
173 +                GTK_STATE_ACTIVE, NULL);
174  }
175  
176  static void
177 @@ -560,6 +682,18 @@
178      case PROP_YALIGN:
179        gtk_button_set_alignment (button, priv->xalign, g_value_get_float (value));
180        break;
181 +    case PROP_DETAIL:
182 +      if (priv->detail)
183 +        g_free (priv->detail);
184 +      priv->detail = g_strdup (g_value_get_string (value));
185 +      gtk_widget_queue_draw (GTK_WIDGET (button));
186 +      break;
187 +    case PROP_AUTOMATIC_DETAIL:
188 +      priv->automatic_detail = g_value_get_boolean (value);
189 +      break;
190 +    case PROP_KEYBOARD_BUTTON:
191 +      priv->keyboard_button = g_value_get_boolean (value);
192 +      break;
193      default:
194        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
195        break;
196 @@ -601,6 +735,15 @@
197      case PROP_YALIGN:
198        g_value_set_float (value, priv->yalign);
199        break;
200 +    case PROP_DETAIL:
201 +      g_value_set_string (value, priv->detail);
202 +      break;
203 +    case PROP_AUTOMATIC_DETAIL:
204 +      g_value_set_boolean (value, priv->automatic_detail);
205 +      break;
206 +    case PROP_KEYBOARD_BUTTON:
207 +      g_value_set_boolean (value, priv->keyboard_button);
208 +      break;
209      default:
210        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
211        break;
212 @@ -641,6 +784,26 @@
213    if (button->label_text == NULL)
214      return;
215  
216 +  if (priv->keyboard_button)
217 +    {
218 +      if (priv->keyboard_label)
219 +       {
220 +         gtk_label_set_label (priv->keyboard_label, button->label_text);
221 +       }
222 +      else
223 +       {
224 +         GtkWidget *label = gtk_label_new (button->label_text);
225 +         priv->keyboard_label = GTK_LABEL (label);
226 +         
227 +         if (priv->align_set)
228 +           gtk_misc_set_alignment (GTK_MISC (label),
229 +                                   priv->xalign, priv->yalign);
230 +         gtk_widget_show (priv->keyboard_label);
231 +         gtk_container_add (GTK_CONTAINER (button), label);
232 +       }
233 +      return;
234 +    }
235 +
236    if (GTK_BIN (button)->child)
237      {
238        if (priv->image && !priv->image_is_stock)
239 @@ -944,16 +1107,20 @@
240    GtkBorder default_border;
241    gint focus_width;
242    gint focus_pad;
243 +  gint child_spacing;
244 +  gint separator_height;
245  
246    gtk_button_get_props (button, &default_border, NULL, NULL);
247    gtk_widget_style_get (GTK_WIDGET (widget),
248                         "focus-line-width", &focus_width,
249                         "focus-padding", &focus_pad,
250 +                       "child-spacing", &child_spacing,
251 +                       "separator-height", &separator_height,
252                         NULL);
253   
254 -  requisition->width = (GTK_CONTAINER (widget)->border_width + CHILD_SPACING +
255 +  requisition->width = (GTK_CONTAINER (widget)->border_width + child_spacing +
256                         GTK_WIDGET (widget)->style->xthickness) * 2;
257 -  requisition->height = (GTK_CONTAINER (widget)->border_width + CHILD_SPACING +
258 +  requisition->height = (GTK_CONTAINER (widget)->border_width + child_spacing +
259                          GTK_WIDGET (widget)->style->ythickness) * 2;
260  
261    if (GTK_WIDGET_CAN_DEFAULT (widget))
262 @@ -965,15 +1132,35 @@
263    if (GTK_BIN (button)->child && GTK_WIDGET_VISIBLE (GTK_BIN (button)->child))
264      {
265        GtkRequisition child_requisition;
266 +      GtkBorder *padding;
267 +      gint minimum_width;
268  
269        gtk_widget_size_request (GTK_BIN (button)->child, &child_requisition);
270  
271 +      gtk_widget_style_get (widget,
272 +                           "padding",
273 +                           &padding,
274 +                           "minimum_width",
275 +                           &minimum_width,
276 +                           NULL);
277 +               
278 +      if ( padding )
279 +       {
280 +         requisition->width += padding->left + padding->right;
281 +         requisition->height += padding->top + padding->bottom;
282 +       }
283 +
284        requisition->width += child_requisition.width;
285        requisition->height += child_requisition.height;
286 +
287 +      if (requisition->width < minimum_width)
288 +        requisition->width = minimum_width;
289      }
290    
291    requisition->width += 2 * (focus_width + focus_pad);
292    requisition->height += 2 * (focus_width + focus_pad);
293 +
294 +  requisition->height += separator_height;
295  }
296  
297  static void
298 @@ -989,14 +1176,15 @@
299    GtkBorder default_border;
300    gint focus_width;
301    gint focus_pad;
302 +  gint child_spacing;
303  
304    gtk_button_get_props (button, &default_border, NULL, NULL);
305    gtk_widget_style_get (GTK_WIDGET (widget),
306                         "focus-line-width", &focus_width,
307                         "focus-padding", &focus_pad,
308 +                       "child-spacing", &child_spacing,
309                         NULL);
310
311 -                           
312 +
313    widget->allocation = *allocation;
314  
315    if (GTK_WIDGET_REALIZED (widget))
316 @@ -1008,14 +1196,27 @@
317  
318    if (GTK_BIN (button)->child && GTK_WIDGET_VISIBLE (GTK_BIN (button)->child))
319      {
320 -      child_allocation.x = widget->allocation.x + border_width + CHILD_SPACING + xthickness;
321 -      child_allocation.y = widget->allocation.y + border_width + CHILD_SPACING + ythickness;
322 +      child_allocation.x = widget->allocation.x + border_width + child_spacing + xthickness;
323 +      child_allocation.y = widget->allocation.y + border_width + child_spacing + ythickness;
324        
325 -      child_allocation.width = MAX (1, widget->allocation.width - (CHILD_SPACING + xthickness) * 2 -
326 +      child_allocation.width = MAX (1, widget->allocation.width - (child_spacing + xthickness) * 2 -
327                                     border_width * 2);
328 -      child_allocation.height = MAX (1, widget->allocation.height - (CHILD_SPACING + ythickness) * 2 -
329 +      child_allocation.height = MAX (1, widget->allocation.height - (child_spacing + ythickness) * 2 -
330                                      border_width * 2);
331  
332 +#ifdef OSSO_FONT_HACK
333 +      {
334 +       gint child_offset_y;
335 +       
336 +       gtk_widget_style_get (widget, "child_offset_y", &child_offset_y, NULL);
337 +       
338 +       if( GTK_IS_LABEL(GTK_BIN (button)->child) )
339 +         {
340 +           child_allocation.y += child_offset_y;
341 +         }
342 +      }
343 +#endif
344 +      
345        if (GTK_WIDGET_CAN_DEFAULT (button))
346         {
347           child_allocation.x += default_border.left;
348 @@ -1066,7 +1267,14 @@
349    gboolean interior_focus;
350    gint focus_width;
351    gint focus_pad;
352 -   
353 +  gint separator_height;
354 +  gboolean listboxheader;
355 +  GtkButtonPrivate *priv;
356 +
357 +  g_return_if_fail (GTK_IS_BUTTON (button));
358 +  
359 +  priv = GTK_BUTTON_GET_PRIVATE (button);
360 +  
361    if (GTK_WIDGET_DRAWABLE (button))
362      {
363        widget = GTK_WIDGET (button);
364 @@ -1076,6 +1284,8 @@
365        gtk_widget_style_get (GTK_WIDGET (widget),
366                             "focus-line-width", &focus_width,
367                             "focus-padding", &focus_pad,
368 +                            "listboxheader", &listboxheader,
369 +                            "separator-height", &separator_height,
370                             NULL); 
371         
372        x = widget->allocation.x + border_width;
373 @@ -1083,13 +1293,55 @@
374        width = widget->allocation.width - border_width * 2;
375        height = widget->allocation.height - border_width * 2;
376  
377 +      if (listboxheader)
378 +        {
379 +          /* this changes everything! */
380 +          PangoLayout *layout;
381 +          int layout_height;
382 +
383 +          /* construct layout - see get_layout in gtkcellrenderertext.c */
384 +          layout = gtk_widget_create_pango_layout (widget, /* use parent treeview instead? */
385 +                                                   button->label_text);
386 +          pango_layout_set_width (layout, -1);
387 +          pango_layout_get_pixel_size (layout, NULL, &layout_height);
388 +
389 +          /* render text */
390 +          gtk_paint_layout (widget->style,
391 +                            widget->window,
392 +                            GTK_STATE_NORMAL,
393 +                            TRUE,
394 +                            area,
395 +                            widget,
396 +                            "listboxheader",
397 +                            x,
398 +                            y,
399 +                            layout);
400 +
401 +          g_object_unref (layout);
402 +
403 +          /* draw separator */
404 +          gtk_paint_hline (widget->style,
405 +                           widget->window,
406 +                           GTK_STATE_NORMAL,
407 +                           area,
408 +                           widget,
409 +                           "listboxseparator",
410 +                           area->x - focus_width - focus_pad,
411 +                           area->x + area->width + focus_width + focus_pad,
412 +                           layout_height + separator_height * 2);
413 +          return;
414 +        }
415 +
416        if (GTK_WIDGET_HAS_DEFAULT (widget) &&
417           GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL)
418         {
419 -         gtk_paint_box (widget->style, widget->window,
420 +          /* This comment is here because it's part of the
421 +           * normal GtkButton
422 +           */
423 +         /*  gtk_paint_box (widget->style, widget->window,
424                          GTK_STATE_NORMAL, GTK_SHADOW_IN,
425                          area, widget, "buttondefault",
426 -                        x, y, width, height);
427 +                        x, y, width, height); */
428  
429           x += default_border.left;
430           y += default_border.top;
431 @@ -1116,7 +1368,7 @@
432           GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT)
433         gtk_paint_box (widget->style, widget->window,
434                        state_type,
435 -                      shadow_type, area, widget, "button",
436 +                      shadow_type, area, widget, priv->detail,
437                        x, y, width, height);
438         
439        if (GTK_WIDGET_HAS_FOCUS (widget))
440 @@ -1151,10 +1403,14 @@
441               x += child_displacement_x;
442               y += child_displacement_y;
443             }
444 -
445 +          /* Comment exists, because it is part of normal GtkButton
446           gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
447                            area, widget, "button",
448                            x, y, width, height);
449 +          */
450 +         gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
451 +                          area, widget, priv->detail,
452 +                          x, y, width, height);
453         }
454      }
455  }
456 @@ -1786,5 +2042,13 @@
457    
458    return priv->image;
459  }
460 -  
461 -  
462 +void osso_gtk_button_set_detail_from_attach_flags (GtkButton *button,OssoGtkButtonAttachFlags flags)
463 +{
464 +  g_return_if_fail (GTK_IS_BUTTON (button));
465 +  g_object_set (G_OBJECT (button),
466 +                "automatic_detail",
467 +               FALSE,
468 +               "detail",
469 +               osso_gtk_button_attach_details[flags],
470 +               NULL);
471 +}