2 * This file is a part of hildon
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser Public License as published by
10 * the Free Software Foundation; version 2 of the license.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser Public License for more details.
20 * SECTION:hildon-button
21 * @short_description: Widget representing a button in the Hildon framework.
23 * The #HildonButton is a GTK widget which represents a clickable
24 * button. It is derived from the #GtkButton widget and provides
25 * additional commodities specific to the Hildon framework.
27 * The height of a #HildonButton can be set to either "finger" height
28 * or "thumb" height. It can also be configured to use halfscreen or
29 * fullscreen width. Alternatively, either dimension can be set to
30 * "auto" so it behaves like a standard #GtkButton.
32 * The #HildonButton can hold any valid child widget, but it usually
33 * contains two labels, named title and value, and it can also contain
34 * an image. The contents of the button are packed together inside a
35 * #GtkAlignment and they do not expand by default (they don't use the
36 * full space of the button).
38 * To change the alignment of both labels, use gtk_button_set_alignment()
40 * To make them expand and use the full space of the button, use
41 * hildon_button_set_alignment().
43 * To change the relative alignment of each label, use
44 * hildon_button_set_title_alignment() and
45 * hildon_button_set_value_alignment().
47 * In hildon-button-example.c included in the Hildon distribution you
48 * can see examples of how to create the most common button
51 * If only one label is needed, #GtkButton can be used as well, see
52 * also hildon_gtk_button_new().
55 * <title>Creating a HildonButton</title>
58 * button_clicked (HildonButton *button, gpointer user_data)
60 * const gchar *title, *value;
62 * title = hildon_button_get_title (button);
63 * value = hildon_button_get_value (button);
64 * g_debug ("Button clicked with title '%s' and value '%s'", title, value);
68 * create_button (void)
73 * button = hildon_button_new (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT,
74 * HILDON_BUTTON_ARRANGEMENT_VERTICAL);
75 * hildon_button_set_text (HILDON_BUTTON (button), "Some title", "Some value");
77 * image = gtk_image_new_from_stock (GTK_STOCK_INFO, GTK_ICON_SIZE_BUTTON);
78 * hildon_button_set_image (HILDON_BUTTON (button), image);
79 * hildon_button_set_image_position (HILDON_BUTTON (button), GTK_POS_RIGHT);
81 * gtk_button_set_alignment (GTK_BUTTON (button), 0.0, 0.5);
83 * g_signal_connect (button, "clicked", G_CALLBACK (button_clicked), NULL);
91 #include "hildon-button.h"
92 #include "hildon-enum-types.h"
93 #include "hildon-gtk.h"
94 #include "hildon-helper.h"
96 G_DEFINE_TYPE (HildonButton, hildon_button, GTK_TYPE_BUTTON);
98 #define HILDON_BUTTON_GET_PRIVATE(obj) \
99 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
100 HILDON_TYPE_BUTTON, HildonButtonPrivate));
102 typedef struct _HildonButtonPrivate HildonButtonPrivate;
104 struct _HildonButtonPrivate
109 GtkWidget *label_box;
110 GtkWidget *alignment;
112 GtkPositionType image_position;
115 HildonButtonStyle style;
127 hildon_button_set_arrangement (HildonButton *button,
128 HildonButtonArrangement arrangement);
131 hildon_button_construct_child (HildonButton *button);
134 hildon_button_set_property (GObject *object,
139 HildonButton *button = HILDON_BUTTON (object);
144 hildon_button_set_title (button, g_value_get_string (value));
147 hildon_button_set_value (button, g_value_get_string (value));
150 hildon_gtk_widget_set_theme_size (GTK_WIDGET (button), g_value_get_flags (value));
152 case PROP_ARRANGEMENT:
153 hildon_button_set_arrangement (button, g_value_get_enum (value));
156 hildon_button_set_style (button, g_value_get_enum (value));
159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
165 hildon_button_get_property (GObject *object,
170 HildonButton *button = HILDON_BUTTON (object);
175 g_value_set_string (value, hildon_button_get_title (button));
178 g_value_set_string (value, hildon_button_get_value (button));
181 g_value_set_enum (value, hildon_button_get_style (button));
184 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
190 hildon_button_style_set (GtkWidget *widget,
191 GtkStyle *previous_style)
193 guint horizontal_spacing, vertical_spacing, image_spacing;
194 HildonButtonPrivate *priv = HILDON_BUTTON_GET_PRIVATE (widget);
196 if (GTK_WIDGET_CLASS (hildon_button_parent_class)->style_set)
197 GTK_WIDGET_CLASS (hildon_button_parent_class)->style_set (widget, previous_style);
199 gtk_widget_style_get (widget,
200 "horizontal-spacing", &horizontal_spacing,
201 "vertical-spacing", &vertical_spacing,
202 "image-spacing", &image_spacing,
205 if (GTK_IS_HBOX (priv->label_box)) {
206 gtk_box_set_spacing (GTK_BOX (priv->label_box), horizontal_spacing);
208 gtk_box_set_spacing (GTK_BOX (priv->label_box), vertical_spacing);
211 if (GTK_IS_BOX (priv->hbox)) {
212 gtk_box_set_spacing (priv->hbox, image_spacing);
217 hildon_button_finalize (GObject *object)
219 HildonButtonPrivate *priv = HILDON_BUTTON_GET_PRIVATE (object);
221 g_object_unref (priv->alignment);
222 g_object_unref (priv->label_box);
224 G_OBJECT_CLASS (hildon_button_parent_class)->finalize (object);
228 hildon_button_class_init (HildonButtonClass *klass)
230 GObjectClass *gobject_class = (GObjectClass *)klass;
231 GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
233 gobject_class->set_property = hildon_button_set_property;
234 gobject_class->get_property = hildon_button_get_property;
235 gobject_class->finalize = hildon_button_finalize;
236 widget_class->style_set = hildon_button_style_set;
238 g_object_class_install_property (
241 g_param_spec_string (
244 "Text of the title label inside the button",
248 g_object_class_install_property (
251 g_param_spec_string (
254 "Text of the value label inside the button",
258 g_object_class_install_property (
264 "Size request for the button",
265 HILDON_TYPE_SIZE_TYPE,
267 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
269 g_object_class_install_property (
275 "How the button contents must be arranged",
276 HILDON_TYPE_BUTTON_ARRANGEMENT,
277 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
278 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
280 g_object_class_install_property (
286 "Visual style of the button",
287 HILDON_TYPE_BUTTON_STYLE,
288 HILDON_BUTTON_STYLE_NORMAL,
291 gtk_widget_class_install_style_property (
294 "horizontal-spacing",
295 "Horizontal spacing between labels",
296 "Horizontal spacing between the title and value labels, when in horizontal mode",
300 gtk_widget_class_install_style_property (
304 "Vertical spacing between labels",
305 "Vertical spacing between the title and value labels, when in vertical mode",
309 g_type_class_add_private (klass, sizeof (HildonButtonPrivate));
313 hildon_button_init (HildonButton *self)
315 HildonButtonPrivate *priv = HILDON_BUTTON_GET_PRIVATE (self);
317 priv->title = GTK_LABEL (gtk_label_new (NULL));
318 priv->value = GTK_LABEL (gtk_label_new (NULL));
319 priv->alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
321 priv->image_position = GTK_POS_LEFT;
322 priv->image_xalign = 0.5;
323 priv->image_yalign = 0.5;
325 priv->label_box = NULL;
327 gtk_widget_set_name (GTK_WIDGET (priv->title), "hildon-button-title");
328 gtk_widget_set_name (GTK_WIDGET (priv->value), "hildon-button-value");
330 hildon_button_set_style (self, HILDON_BUTTON_STYLE_NORMAL);
332 gtk_misc_set_alignment (GTK_MISC (priv->title), 0, 0.5);
333 gtk_misc_set_alignment (GTK_MISC (priv->value), 0, 0.5);
335 g_object_ref_sink (priv->alignment);
337 /* The labels are not shown automatically, see hildon_button_set_(title|value) */
338 gtk_widget_set_no_show_all (GTK_WIDGET (priv->title), TRUE);
339 gtk_widget_set_no_show_all (GTK_WIDGET (priv->value), TRUE);
341 gtk_button_set_focus_on_click (GTK_BUTTON (self), FALSE);
345 * hildon_button_add_title_size_group:
346 * @button: a #HildonButton
347 * @size_group: A #GtkSizeGroup for the button title (main label)
349 * Adds the title label of @button to @size_group.
352 hildon_button_add_title_size_group (HildonButton *button,
353 GtkSizeGroup *size_group)
355 HildonButtonPrivate *priv;
357 g_return_if_fail (HILDON_IS_BUTTON (button));
358 g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
360 priv = HILDON_BUTTON_GET_PRIVATE (button);
362 gtk_size_group_add_widget (size_group, GTK_WIDGET (priv->title));
366 * hildon_button_add_value_size_group:
367 * @button: a #HildonButton
368 * @size_group: A #GtkSizeGroup for the button value (secondary label)
370 * Adds the value label of @button to @size_group.
373 hildon_button_add_value_size_group (HildonButton *button,
374 GtkSizeGroup *size_group)
376 HildonButtonPrivate *priv;
378 g_return_if_fail (HILDON_IS_BUTTON (button));
379 g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
381 priv = HILDON_BUTTON_GET_PRIVATE (button);
383 gtk_size_group_add_widget (size_group, GTK_WIDGET (priv->value));
387 * hildon_button_add_image_size_group:
388 * @button: a #HildonButton
389 * @size_group: A #GtkSizeGroup for the button image
391 * Adds the image of @button to @size_group. You must add an image
392 * using hildon_button_set_image() before calling this function.
395 hildon_button_add_image_size_group (HildonButton *button,
396 GtkSizeGroup *size_group)
398 HildonButtonPrivate *priv;
400 g_return_if_fail (HILDON_IS_BUTTON (button));
401 g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
403 priv = HILDON_BUTTON_GET_PRIVATE (button);
405 g_return_if_fail (GTK_IS_WIDGET (priv->image));
407 gtk_size_group_add_widget (size_group, GTK_WIDGET (priv->image));
411 * hildon_button_add_size_groups:
412 * @button: a #HildonButton
413 * @title_size_group: A #GtkSizeGroup for the button title (main label), or %NULL
414 * @value_size_group: A #GtkSizeGroup group for the button value (secondary label), or %NULL
415 * @image_size_group: A #GtkSizeGroup group for the button image, or %NULL
417 * Convenience function to add title, value and image to size
418 * groups. %NULL size groups will be ignored.
421 hildon_button_add_size_groups (HildonButton *button,
422 GtkSizeGroup *title_size_group,
423 GtkSizeGroup *value_size_group,
424 GtkSizeGroup *image_size_group)
426 if (title_size_group)
427 hildon_button_add_title_size_group (button, title_size_group);
429 if (value_size_group)
430 hildon_button_add_value_size_group (button, value_size_group);
432 if (image_size_group)
433 hildon_button_add_image_size_group (button, image_size_group);
438 * @size: Flags to set the size of the button.
439 * @arrangement: How the labels must be arranged.
441 * Creates a new #HildonButton. To set text in the labels, use
442 * hildon_button_set_title() and
443 * hildon_button_set_value(). Alternatively, you can add a custom
444 * child widget using gtk_container_add().
446 * Returns: a new #HildonButton
451 hildon_button_new (HildonSizeType size,
452 HildonButtonArrangement arrangement)
454 return hildon_button_new_with_text (size, arrangement, NULL, NULL);
458 * hildon_button_new_with_text:
459 * @size: Flags to set the size of the button.
460 * @arrangement: How the labels must be arranged.
461 * @title: Title of the button (main label), or %NULL
462 * @value: Value of the button (secondary label), or %NULL
464 * Creates a new #HildonButton with two labels, @title and @value.
466 * If you just don't want to use one of the labels, set it to
467 * %NULL. You can set it to a non-%NULL value at any time later using
468 * hildon_button_set_title() or hildon_button_set_value() .
470 * Returns: a new #HildonButton
475 hildon_button_new_with_text (HildonSizeType size,
476 HildonButtonArrangement arrangement,
483 button = g_object_new (HILDON_TYPE_BUTTON,
487 "arrangement", arrangement,
494 hildon_button_set_arrangement (HildonButton *button,
495 HildonButtonArrangement arrangement)
497 HildonButtonPrivate *priv;
499 priv = HILDON_BUTTON_GET_PRIVATE (button);
501 /* Pack everything */
502 if (arrangement == HILDON_BUTTON_ARRANGEMENT_VERTICAL) {
503 priv->label_box = gtk_vbox_new (FALSE, 0);
504 hildon_helper_set_logical_font (GTK_WIDGET (priv->value), "SmallSystemFont");
506 priv->label_box = gtk_hbox_new (FALSE, 0);
509 g_object_ref_sink (priv->label_box);
511 /* If we pack both labels with (TRUE, TRUE) or (FALSE, FALSE) they
512 * can be painted outside of the button in some situations, see
514 gtk_box_pack_start (GTK_BOX (priv->label_box), GTK_WIDGET (priv->title), TRUE, TRUE, 0);
515 gtk_box_pack_start (GTK_BOX (priv->label_box), GTK_WIDGET (priv->value), FALSE, FALSE, 0);
517 hildon_button_construct_child (button);
521 * hildon_button_set_title:
522 * @button: a #HildonButton
523 * @title: a new title (main label) for the button, or %NULL
525 * Sets the title (main label) of @button to @title.
527 * This will clear any previously set title.
529 * If @title is set to %NULL, the title label will be hidden and the
530 * value label will be realigned.
535 hildon_button_set_title (HildonButton *button,
538 HildonButtonPrivate *priv;
540 g_return_if_fail (HILDON_IS_BUTTON (button));
542 priv = HILDON_BUTTON_GET_PRIVATE (button);
543 gtk_label_set_text (priv->title, title);
545 /* If the button has no title, hide the label so the value is
546 * properly aligned */
548 hildon_button_construct_child (button);
549 gtk_widget_show (GTK_WIDGET (priv->title));
551 gtk_widget_hide (GTK_WIDGET (priv->title));
554 g_object_notify (G_OBJECT (button), "title");
558 * hildon_button_set_value:
559 * @button: a #HildonButton
560 * @value: a new value (secondary label) for the button, or %NULL
562 * Sets the value (secondary label) of @button to @value.
564 * This will clear any previously set value.
566 * If @value is set to %NULL, the value label will be hidden and the
567 * title label will be realigned.
573 hildon_button_set_value (HildonButton *button,
576 HildonButtonPrivate *priv;
578 g_return_if_fail (HILDON_IS_BUTTON (button));
580 priv = HILDON_BUTTON_GET_PRIVATE (button);
581 gtk_label_set_text (priv->value, value);
583 /* If the button has no value, hide the label so the title is
584 * properly aligned */
586 hildon_button_construct_child (button);
587 gtk_widget_show (GTK_WIDGET (priv->value));
589 gtk_widget_hide (GTK_WIDGET (priv->value));
592 g_object_notify (G_OBJECT (button), "value");
596 * hildon_button_get_title:
597 * @button: a #HildonButton
599 * Fetches the text from the main label (title) of @button,
600 * as set by hildon_button_set_title() or hildon_button_set_text().
601 * If the label text has not been set the return value will be %NULL.
602 * This will be the case if you create an empty button with
603 * hildon_button_new() to use as a container.
605 * Returns: The text of the title label. This string is owned by the
606 * widget and must not be modified or freed.
611 hildon_button_get_title (HildonButton *button)
613 HildonButtonPrivate *priv;
615 g_return_val_if_fail (HILDON_IS_BUTTON (button), NULL);
617 priv = HILDON_BUTTON_GET_PRIVATE (button);
619 return gtk_label_get_text (priv->title);
623 * hildon_button_get_value:
624 * @button: a #HildonButton
626 * Fetches the text from the secondary label (value) of @button,
627 * as set by hildon_button_set_value() or hildon_button_set_text().
628 * If the label text has not been set the return value will be %NULL.
629 * This will be the case if you create an empty button with hildon_button_new()
630 * to use as a container.
632 * Returns: The text of the value label. This string is owned by the
633 * widget and must not be modified or freed.
638 hildon_button_get_value (HildonButton *button)
640 HildonButtonPrivate *priv;
642 g_return_val_if_fail (HILDON_IS_BUTTON (button), NULL);
644 priv = HILDON_BUTTON_GET_PRIVATE (button);
646 return gtk_label_get_text (priv->value);
650 * hildon_button_set_text:
651 * @button: a #HildonButton
652 * @title: new text for the button title (main label)
653 * @value: new text for the button value (secondary label)
655 * Convenience function to change both labels of a #HildonButton
660 hildon_button_set_text (HildonButton *button,
664 hildon_button_set_title (button, title);
665 hildon_button_set_value (button, value);
669 * hildon_button_set_image:
670 * @button: a #HildonButton
671 * @image: a widget to set as the button image
673 * Sets the image of @button to the given widget. The previous image
674 * (if any) will be removed.
679 hildon_button_set_image (HildonButton *button,
682 HildonButtonPrivate *priv;
684 g_return_if_fail (HILDON_IS_BUTTON (button));
685 g_return_if_fail (!image || GTK_IS_WIDGET (image));
687 priv = HILDON_BUTTON_GET_PRIVATE (button);
689 /* Return if there's nothing to do */
690 if (image == priv->image)
693 if (priv->image && priv->image->parent)
694 gtk_container_remove (GTK_CONTAINER (priv->image->parent), priv->image);
698 hildon_button_construct_child (button);
702 * hildon_button_get_image:
703 * @button: a #HildonButton
705 * Gets the widget that is currenty set as the image of @button,
706 * previously set with hildon_button_set_image()
708 * Returns: a #GtkWidget or %NULL in case there is no image
713 hildon_button_get_image (HildonButton *button)
715 HildonButtonPrivate *priv;
717 g_return_val_if_fail (HILDON_IS_BUTTON (button), NULL);
719 priv = HILDON_BUTTON_GET_PRIVATE (button);
725 * hildon_button_set_image_position:
726 * @button: a #HildonButton
727 * @position: the position of the image (%GTK_POS_LEFT or %GTK_POS_RIGHT)
729 * Sets the position of the image inside @button. Only %GTK_POS_LEFT
730 * and %GTK_POS_RIGHT are currently supported.
735 hildon_button_set_image_position (HildonButton *button,
736 GtkPositionType position)
738 HildonButtonPrivate *priv;
740 g_return_if_fail (HILDON_IS_BUTTON (button));
741 g_return_if_fail (position == GTK_POS_LEFT || position == GTK_POS_RIGHT);
743 priv = HILDON_BUTTON_GET_PRIVATE (button);
745 /* Return if there's nothing to do */
746 if (priv->image_position == position)
749 priv->image_position = position;
751 hildon_button_construct_child (button);
755 * hildon_button_set_alignment:
756 * @button: a #HildonButton
757 * @xalign: the horizontal alignment of the contents, from 0 (left) to 1 (right).
758 * @yalign: the vertical alignment of the contents, from 0 (top) to 1 (bottom).
759 * @xscale: the amount that the child widget expands horizontally to fill up unused space, from 0 to 1
760 * @yscale: the amount that the child widget expands vertically to fill up unused space, from 0 to 1
762 * Sets the alignment of the contents of the widget. If you don't need
763 * to change @xscale or @yscale you can just use
764 * gtk_button_set_alignment() instead.
766 * Note that for this method to work properly the, child widget of
767 * @button must be a #GtkAlignment. That's what #HildonButton uses by
768 * default, so this function will work unless you add a custom widget
774 hildon_button_set_alignment (HildonButton *button,
780 HildonButtonPrivate *priv;
783 g_return_if_fail (HILDON_IS_BUTTON (button));
785 priv = HILDON_BUTTON_GET_PRIVATE (button);
787 child = gtk_bin_get_child (GTK_BIN (button));
789 /* If the button has no child, use priv->alignment, which is the default one */
791 child = priv->alignment;
793 if (GTK_IS_ALIGNMENT (child)) {
794 gtk_alignment_set (GTK_ALIGNMENT (priv->alignment), xalign, yalign, xscale, yscale);
799 * hildon_button_set_title_alignment:
800 * @button: a #HildonButton
801 * @xalign: the horizontal alignment of the title label, from 0 (left) to 1 (right).
802 * @yalign: the vertical alignment of the title label, from 0 (top) to 1 (bottom).
804 * Sets the alignment of the title label. See also
805 * hildon_button_set_alignment() to set the alignment of the whole
806 * contents of the button.
811 hildon_button_set_title_alignment (HildonButton *button,
815 HildonButtonPrivate *priv;
817 g_return_if_fail (HILDON_IS_BUTTON (button));
819 priv = HILDON_BUTTON_GET_PRIVATE (button);
821 gtk_misc_set_alignment (GTK_MISC (priv->title), xalign, yalign);
825 * hildon_button_set_value_alignment:
826 * @button: a #HildonButton
827 * @xalign: the horizontal alignment of the value label, from 0 (left) to 1 (right).
828 * @yalign: the vertical alignment of the value label, from 0 (top) to 1 (bottom).
830 * Sets the alignment of the value label. See also
831 * hildon_button_set_alignment() to set the alignment of the whole
832 * contents of the button.
837 hildon_button_set_value_alignment (HildonButton *button,
841 HildonButtonPrivate *priv;
843 g_return_if_fail (HILDON_IS_BUTTON (button));
845 priv = HILDON_BUTTON_GET_PRIVATE (button);
847 gtk_misc_set_alignment (GTK_MISC (priv->value), xalign, yalign);
851 * hildon_button_set_image_alignment:
852 * @button: a #HildonButton
853 * @xalign: the horizontal alignment of the image, from 0 (left) to 1 (right).
854 * @yalign: the vertical alignment of the image, from 0 (top) to 1 (bottom).
856 * Sets the alignment of the image. See also
857 * hildon_button_set_alignment() to set the alignment of the whole
858 * contents of the button.
863 hildon_button_set_image_alignment (HildonButton *button,
867 HildonButtonPrivate *priv;
869 g_return_if_fail (HILDON_IS_BUTTON (button));
871 priv = HILDON_BUTTON_GET_PRIVATE (button);
873 /* Return if there's nothing to do */
874 if (priv->image_xalign == xalign && priv->image_yalign == yalign)
877 priv->image_xalign = xalign;
878 priv->image_yalign = yalign;
880 hildon_button_construct_child (button);
884 * hildon_button_set_style:
885 * @button: A #HildonButton
886 * @style: A #HildonButtonStyle for @button
888 * Sets the style of @button to @style. This changes the visual
889 * appearance of the button (colors, font sizes) according to the
890 * particular style chosen, but the general layout is not altered.
892 * Use %HILDON_BUTTON_STYLE_NORMAL to make it look like a normal
893 * #HildonButton, or %HILDON_BUTTON_STYLE_PICKER to make it look like
894 * a #HildonPickerButton.
899 hildon_button_set_style (HildonButton *button,
900 HildonButtonStyle style)
902 HildonButtonPrivate *priv;
905 g_return_if_fail (HILDON_IS_BUTTON (button));
908 case HILDON_BUTTON_STYLE_NORMAL:
909 color = "SecondaryTextColor";
911 case HILDON_BUTTON_STYLE_PICKER:
912 color = "ActiveTextColor";
915 g_return_if_reached ();
918 priv = HILDON_BUTTON_GET_PRIVATE (button);
920 hildon_helper_set_logical_color (GTK_WIDGET (priv->value), GTK_RC_FG, GTK_STATE_NORMAL, color);
921 hildon_helper_set_logical_color (GTK_WIDGET (priv->value), GTK_RC_FG, GTK_STATE_PRELIGHT, color);
925 g_object_notify (G_OBJECT (button), "style");
929 * hildon_button_get_style:
930 * @button: A #HildonButton
932 * Gets the visual style of the button.
934 * Returns: a #HildonButtonStyle
939 hildon_button_get_style (HildonButton *button)
941 HildonButtonPrivate *priv;
943 g_return_val_if_fail (HILDON_IS_BUTTON (button), HILDON_BUTTON_STYLE_NORMAL);
945 priv = HILDON_BUTTON_GET_PRIVATE (button);
951 hildon_button_construct_child (HildonButton *button)
953 HildonButtonPrivate *priv = HILDON_BUTTON_GET_PRIVATE (button);
956 const gchar *title, *value;
958 /* Don't do anything if the button is not constructed yet */
959 if (G_UNLIKELY (priv->label_box == NULL))
962 /* Don't do anything if the button has no contents */
963 title = gtk_label_get_text (priv->title);
964 value = gtk_label_get_text (priv->value);
965 if (!priv->image && !title[0] && !value[0])
968 /* Save a ref to the image, and remove it from its container if necessary */
970 g_object_ref (priv->image);
971 if (priv->image->parent != NULL)
972 gtk_container_remove (GTK_CONTAINER (priv->image->parent), priv->image);
975 if (priv->label_box->parent != NULL) {
976 gtk_container_remove (GTK_CONTAINER (priv->label_box->parent), priv->label_box);
979 /* Remove the child from the container and add priv->alignment */
980 child = gtk_bin_get_child (GTK_BIN (button));
981 if (child != NULL && child != priv->alignment) {
982 gtk_container_remove (GTK_CONTAINER (button), child);
987 gtk_container_add (GTK_CONTAINER (button), GTK_WIDGET (priv->alignment));
990 /* Create a new hbox */
992 gtk_container_remove (GTK_CONTAINER (priv->alignment), GTK_WIDGET (priv->hbox));
994 gtk_widget_style_get (GTK_WIDGET (button), "image-spacing", &image_spacing, NULL);
995 priv->hbox = GTK_BOX (gtk_hbox_new (FALSE, image_spacing));
996 gtk_container_add (GTK_CONTAINER (priv->alignment), GTK_WIDGET (priv->hbox));
998 /* Pack the image and the alignment in the new hbox */
999 if (priv->image && priv->image_position == GTK_POS_LEFT)
1000 gtk_box_pack_start (priv->hbox, priv->image, FALSE, FALSE, 0);
1002 gtk_box_pack_start (priv->hbox, priv->label_box, TRUE, TRUE, 0);
1004 if (priv->image && priv->image_position == GTK_POS_RIGHT)
1005 gtk_box_pack_start (priv->hbox, priv->image, FALSE, FALSE, 0);
1007 /* Set image alignment and remove previously set ref */
1009 gtk_misc_set_alignment (GTK_MISC (priv->image), priv->image_xalign, priv->image_yalign);
1010 g_object_unref (priv->image);
1013 /* Show everything */
1014 gtk_widget_show_all (GTK_WIDGET (priv->alignment));