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
4 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
7 +/* Modified for Nokia Oyj during 2002-2005. See CHANGES file for list
15 #include "gtkiconfactory.h"
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] =
40 #define CHILD_SPACING 1
42 +/* Take this away after font drawing is fixed */
43 +#define OSSO_FONT_HACK TRUE
45 static const GtkBorder default_default_border = { 1, 1, 1, 1 };
46 static const GtkBorder default_default_outside_border = { 0, 0, 0, 0 };
53 + PROP_AUTOMATIC_DETAIL,
54 + PROP_KEYBOARD_BUTTON
57 #define GTK_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_BUTTON, GtkButtonPrivate))
61 guint image_is_stock : 1;
63 + gboolean automatic_detail;
64 + gboolean keyboard_button;
65 + GtkLabel *keyboard_label;
68 static void gtk_button_class_init (GtkButtonClass *klass);
70 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
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"),
78 + G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
80 + g_object_class_install_property (gobject_class,
82 g_param_spec_boolean ("use_stock",
85 P_("Whether stock icons should be shown in buttons"),
89 + gtk_widget_class_install_style_property (widget_class,
90 + g_param_spec_int ("child_spacing",
92 + _("Spacing between button edges and child."),
97 + /* Osso additions below */
98 + g_object_class_install_property (gobject_class,
100 + g_param_spec_string ("detail",
102 + P_("The detail the button is drawn with."),
104 + G_PARAM_READWRITE));
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."),
112 + G_PARAM_READWRITE));
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."),
122 + G_PARAM_READABLE));
124 + /* OSSO: This is used to find out whether
125 + * button is a GtkTreeView column Listbox
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 )" ),
132 + G_PARAM_READABLE));
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 )" ),
142 + G_PARAM_READABLE));
144 + gtk_widget_class_install_style_property (widget_class,
145 + g_param_spec_boxed ("padding",
147 + P_("Paddings around the button child"),
149 + G_PARAM_READABLE));
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"),
158 + G_PARAM_READABLE));
160 g_type_class_add_private (gobject_class, sizeof (GtkButtonPrivate));
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;
172 + g_object_set (G_OBJECT (button), "tap_and_hold_state",
173 + GTK_STATE_ACTIVE, NULL);
179 gtk_button_set_alignment (button, priv->xalign, g_value_get_float (value));
183 + g_free (priv->detail);
184 + priv->detail = g_strdup (g_value_get_string (value));
185 + gtk_widget_queue_draw (GTK_WIDGET (button));
187 + case PROP_AUTOMATIC_DETAIL:
188 + priv->automatic_detail = g_value_get_boolean (value);
190 + case PROP_KEYBOARD_BUTTON:
191 + priv->keyboard_button = g_value_get_boolean (value);
194 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
198 g_value_set_float (value, priv->yalign);
201 + g_value_set_string (value, priv->detail);
203 + case PROP_AUTOMATIC_DETAIL:
204 + g_value_set_boolean (value, priv->automatic_detail);
206 + case PROP_KEYBOARD_BUTTON:
207 + g_value_set_boolean (value, priv->keyboard_button);
210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
213 if (button->label_text == NULL)
216 + if (priv->keyboard_button)
218 + if (priv->keyboard_label)
220 + gtk_label_set_label (priv->keyboard_label, button->label_text);
224 + GtkWidget *label = gtk_label_new (button->label_text);
225 + priv->keyboard_label = GTK_LABEL (label);
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);
236 if (GTK_BIN (button)->child)
238 if (priv->image && !priv->image_is_stock)
239 @@ -944,16 +1107,20 @@
240 GtkBorder default_border;
243 + gint child_spacing;
244 + gint separator_height;
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,
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;
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))
265 GtkRequisition child_requisition;
266 + GtkBorder *padding;
267 + gint minimum_width;
269 gtk_widget_size_request (GTK_BIN (button)->child, &child_requisition);
271 + gtk_widget_style_get (widget,
280 + requisition->width += padding->left + padding->right;
281 + requisition->height += padding->top + padding->bottom;
284 requisition->width += child_requisition.width;
285 requisition->height += child_requisition.height;
287 + if (requisition->width < minimum_width)
288 + requisition->width = minimum_width;
291 requisition->width += 2 * (focus_width + focus_pad);
292 requisition->height += 2 * (focus_width + focus_pad);
294 + requisition->height += separator_height;
298 @@ -989,14 +1176,15 @@
299 GtkBorder default_border;
302 + gint child_spacing;
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,
313 widget->allocation = *allocation;
315 if (GTK_WIDGET_REALIZED (widget))
316 @@ -1008,14 +1196,27 @@
318 if (GTK_BIN (button)->child && GTK_WIDGET_VISIBLE (GTK_BIN (button)->child))
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;
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 -
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 -
332 +#ifdef OSSO_FONT_HACK
334 + gint child_offset_y;
336 + gtk_widget_style_get (widget, "child_offset_y", &child_offset_y, NULL);
338 + if( GTK_IS_LABEL(GTK_BIN (button)->child) )
340 + child_allocation.y += child_offset_y;
345 if (GTK_WIDGET_CAN_DEFAULT (button))
347 child_allocation.x += default_border.left;
348 @@ -1066,7 +1267,14 @@
349 gboolean interior_focus;
353 + gint separator_height;
354 + gboolean listboxheader;
355 + GtkButtonPrivate *priv;
357 + g_return_if_fail (GTK_IS_BUTTON (button));
359 + priv = GTK_BUTTON_GET_PRIVATE (button);
361 if (GTK_WIDGET_DRAWABLE (button))
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,
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;
379 + /* this changes everything! */
380 + PangoLayout *layout;
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);
390 + gtk_paint_layout (widget->style,
401 + g_object_unref (layout);
403 + /* draw separator */
404 + gtk_paint_hline (widget->style,
409 + "listboxseparator",
410 + area->x - focus_width - focus_pad,
411 + area->x + area->width + focus_width + focus_pad,
412 + layout_height + separator_height * 2);
416 if (GTK_WIDGET_HAS_DEFAULT (widget) &&
417 GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL)
419 - gtk_paint_box (widget->style, widget->window,
420 + /* This comment is here because it's part of the
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); */
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,
435 - shadow_type, area, widget, "button",
436 + shadow_type, area, widget, priv->detail,
437 x, y, width, height);
439 if (GTK_WIDGET_HAS_FOCUS (widget))
440 @@ -1151,10 +1403,14 @@
441 x += child_displacement_x;
442 y += child_displacement_y;
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);
450 + gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
451 + area, widget, priv->detail,
452 + x, y, width, height);
456 @@ -1786,5 +2042,13 @@
462 +void osso_gtk_button_set_detail_from_attach_flags (GtkButton *button,OssoGtkButtonAttachFlags flags)
464 + g_return_if_fail (GTK_IS_BUTTON (button));
465 + g_object_set (G_OBJECT (button),
466 + "automatic_detail",
469 + osso_gtk_button_attach_details[flags],