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: Two-label buttons in the Hildon framework.
23 * The #HildonButton is a clickable button for Hildon applications.
24 * 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.
354 hildon_button_add_title_size_group (HildonButton *button,
355 GtkSizeGroup *size_group)
357 HildonButtonPrivate *priv;
359 g_return_if_fail (HILDON_IS_BUTTON (button));
360 g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
362 priv = HILDON_BUTTON_GET_PRIVATE (button);
364 gtk_size_group_add_widget (size_group, GTK_WIDGET (priv->title));
368 * hildon_button_add_value_size_group:
369 * @button: a #HildonButton
370 * @size_group: A #GtkSizeGroup for the button value (secondary label)
372 * Adds the value label of @button to @size_group.
377 hildon_button_add_value_size_group (HildonButton *button,
378 GtkSizeGroup *size_group)
380 HildonButtonPrivate *priv;
382 g_return_if_fail (HILDON_IS_BUTTON (button));
383 g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
385 priv = HILDON_BUTTON_GET_PRIVATE (button);
387 gtk_size_group_add_widget (size_group, GTK_WIDGET (priv->value));
391 * hildon_button_add_image_size_group:
392 * @button: a #HildonButton
393 * @size_group: A #GtkSizeGroup for the button image
395 * Adds the image of @button to @size_group. You must add an image
396 * using hildon_button_set_image() before calling this function.
401 hildon_button_add_image_size_group (HildonButton *button,
402 GtkSizeGroup *size_group)
404 HildonButtonPrivate *priv;
406 g_return_if_fail (HILDON_IS_BUTTON (button));
407 g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
409 priv = HILDON_BUTTON_GET_PRIVATE (button);
411 g_return_if_fail (GTK_IS_WIDGET (priv->image));
413 gtk_size_group_add_widget (size_group, GTK_WIDGET (priv->image));
417 * hildon_button_add_size_groups:
418 * @button: a #HildonButton
419 * @title_size_group: A #GtkSizeGroup for the button title (main label), or %NULL
420 * @value_size_group: A #GtkSizeGroup group for the button value (secondary label), or %NULL
421 * @image_size_group: A #GtkSizeGroup group for the button image, or %NULL
423 * Convenience function to add title, value and image to size
424 * groups. %NULL size groups will be ignored.
429 hildon_button_add_size_groups (HildonButton *button,
430 GtkSizeGroup *title_size_group,
431 GtkSizeGroup *value_size_group,
432 GtkSizeGroup *image_size_group)
434 if (title_size_group)
435 hildon_button_add_title_size_group (button, title_size_group);
437 if (value_size_group)
438 hildon_button_add_value_size_group (button, value_size_group);
440 if (image_size_group)
441 hildon_button_add_image_size_group (button, image_size_group);
446 * @size: Flags to set the size of the button.
447 * @arrangement: How the labels must be arranged.
449 * Creates a new #HildonButton. To set text in the labels, use
450 * hildon_button_set_title() and
451 * hildon_button_set_value(). Alternatively, you can add a custom
452 * child widget using gtk_container_add().
454 * Returns: a new #HildonButton
459 hildon_button_new (HildonSizeType size,
460 HildonButtonArrangement arrangement)
462 return hildon_button_new_with_text (size, arrangement, NULL, NULL);
466 * hildon_button_new_with_text:
467 * @size: Flags to set the size of the button.
468 * @arrangement: How the labels must be arranged.
469 * @title: Title of the button (main label), or %NULL
470 * @value: Value of the button (secondary label), or %NULL
472 * Creates a new #HildonButton with two labels, @title and @value.
474 * If you just don't want to use one of the labels, set it to
475 * %NULL. You can set it to a non-%NULL value at any time later using
476 * hildon_button_set_title() or hildon_button_set_value() .
478 * Returns: a new #HildonButton
483 hildon_button_new_with_text (HildonSizeType size,
484 HildonButtonArrangement arrangement,
491 button = g_object_new (HILDON_TYPE_BUTTON,
495 "arrangement", arrangement,
502 hildon_button_set_arrangement (HildonButton *button,
503 HildonButtonArrangement arrangement)
505 HildonButtonPrivate *priv;
507 priv = HILDON_BUTTON_GET_PRIVATE (button);
509 /* Pack everything */
510 if (arrangement == HILDON_BUTTON_ARRANGEMENT_VERTICAL) {
511 priv->label_box = gtk_vbox_new (FALSE, 0);
512 hildon_helper_set_logical_font (GTK_WIDGET (priv->value), "SmallSystemFont");
514 priv->label_box = gtk_hbox_new (FALSE, 0);
517 g_object_ref_sink (priv->label_box);
519 /* If we pack both labels with (TRUE, TRUE) or (FALSE, FALSE) they
520 * can be painted outside of the button in some situations, see
521 * NB#88126 and NB#110689 */
522 gtk_box_pack_start (GTK_BOX (priv->label_box), GTK_WIDGET (priv->title), FALSE, FALSE, 0);
523 gtk_box_pack_start (GTK_BOX (priv->label_box), GTK_WIDGET (priv->value), TRUE, TRUE, 0);
525 hildon_button_construct_child (button);
529 * hildon_button_set_title:
530 * @button: a #HildonButton
531 * @title: a new title (main label) for the button, or %NULL
533 * Sets the title (main label) of @button to @title.
535 * This will clear any previously set title.
537 * If @title is set to %NULL or an empty string, the title label will
538 * be hidden and the value label will be realigned.
543 hildon_button_set_title (HildonButton *button,
546 HildonButtonPrivate *priv;
548 g_return_if_fail (HILDON_IS_BUTTON (button));
550 priv = HILDON_BUTTON_GET_PRIVATE (button);
551 gtk_label_set_text (priv->title, title);
553 /* If the button has no title, hide the label so the value is
554 * properly aligned */
555 if (title && title[0] != '\0') {
556 hildon_button_construct_child (button);
557 gtk_widget_show (GTK_WIDGET (priv->title));
559 gtk_widget_hide (GTK_WIDGET (priv->title));
562 g_object_notify (G_OBJECT (button), "title");
566 * hildon_button_set_value:
567 * @button: a #HildonButton
568 * @value: a new value (secondary label) for the button, or %NULL
570 * Sets the value (secondary label) of @button to @value.
572 * This will clear any previously set value.
574 * If @value is set to %NULL or an empty string, the value label will
575 * be hidden and the title label will be realigned.
580 hildon_button_set_value (HildonButton *button,
583 HildonButtonPrivate *priv;
585 g_return_if_fail (HILDON_IS_BUTTON (button));
587 priv = HILDON_BUTTON_GET_PRIVATE (button);
588 gtk_label_set_text (priv->value, value);
590 /* If the button has no value, hide the label so the title is
591 * properly aligned */
592 if (value && value[0] != '\0') {
593 hildon_button_construct_child (button);
594 gtk_widget_show (GTK_WIDGET (priv->value));
596 gtk_widget_hide (GTK_WIDGET (priv->value));
599 g_object_notify (G_OBJECT (button), "value");
603 * hildon_button_get_title:
604 * @button: a #HildonButton
606 * Fetches the text from the main label (title) of @button,
607 * as set by hildon_button_set_title() or hildon_button_set_text().
608 * If the label text has not been set the return value will be %NULL.
609 * This will be the case if you create an empty button with
610 * hildon_button_new() to use as a container.
612 * Returns: The text of the title label. This string is owned by the
613 * widget and must not be modified or freed.
618 hildon_button_get_title (HildonButton *button)
620 HildonButtonPrivate *priv;
622 g_return_val_if_fail (HILDON_IS_BUTTON (button), NULL);
624 priv = HILDON_BUTTON_GET_PRIVATE (button);
626 return gtk_label_get_text (priv->title);
630 * hildon_button_get_value:
631 * @button: a #HildonButton
633 * Fetches the text from the secondary label (value) of @button,
634 * as set by hildon_button_set_value() or hildon_button_set_text().
635 * If the label text has not been set the return value will be %NULL.
636 * This will be the case if you create an empty button with hildon_button_new()
637 * to use as a container.
639 * Returns: The text of the value label. This string is owned by the
640 * widget and must not be modified or freed.
645 hildon_button_get_value (HildonButton *button)
647 HildonButtonPrivate *priv;
649 g_return_val_if_fail (HILDON_IS_BUTTON (button), NULL);
651 priv = HILDON_BUTTON_GET_PRIVATE (button);
653 return gtk_label_get_text (priv->value);
657 * hildon_button_set_text:
658 * @button: a #HildonButton
659 * @title: new text for the button title (main label)
660 * @value: new text for the button value (secondary label)
662 * Convenience function to change both labels of a #HildonButton
667 hildon_button_set_text (HildonButton *button,
671 hildon_button_set_title (button, title);
672 hildon_button_set_value (button, value);
676 * hildon_button_set_image:
677 * @button: a #HildonButton
678 * @image: a widget to set as the button image
680 * Sets the image of @button to the given widget. The previous image
681 * (if any) will be removed.
686 hildon_button_set_image (HildonButton *button,
689 HildonButtonPrivate *priv;
691 g_return_if_fail (HILDON_IS_BUTTON (button));
692 g_return_if_fail (!image || GTK_IS_WIDGET (image));
694 priv = HILDON_BUTTON_GET_PRIVATE (button);
696 /* Return if there's nothing to do */
697 if (image == priv->image)
700 if (priv->image && priv->image->parent)
701 gtk_container_remove (GTK_CONTAINER (priv->image->parent), priv->image);
705 hildon_button_construct_child (button);
709 * hildon_button_get_image:
710 * @button: a #HildonButton
712 * Gets the widget that is currenty set as the image of @button,
713 * previously set with hildon_button_set_image()
715 * Returns: a #GtkWidget or %NULL in case there is no image
720 hildon_button_get_image (HildonButton *button)
722 HildonButtonPrivate *priv;
724 g_return_val_if_fail (HILDON_IS_BUTTON (button), NULL);
726 priv = HILDON_BUTTON_GET_PRIVATE (button);
732 * hildon_button_set_image_position:
733 * @button: a #HildonButton
734 * @position: the position of the image (%GTK_POS_LEFT or %GTK_POS_RIGHT)
736 * Sets the position of the image inside @button. Only %GTK_POS_LEFT
737 * and %GTK_POS_RIGHT are currently supported.
742 hildon_button_set_image_position (HildonButton *button,
743 GtkPositionType position)
745 HildonButtonPrivate *priv;
747 g_return_if_fail (HILDON_IS_BUTTON (button));
748 g_return_if_fail (position == GTK_POS_LEFT || position == GTK_POS_RIGHT);
750 priv = HILDON_BUTTON_GET_PRIVATE (button);
752 /* Return if there's nothing to do */
753 if (priv->image_position == position)
756 priv->image_position = position;
758 hildon_button_construct_child (button);
762 * hildon_button_set_alignment:
763 * @button: a #HildonButton
764 * @xalign: the horizontal alignment of the contents, from 0 (left) to 1 (right).
765 * @yalign: the vertical alignment of the contents, from 0 (top) to 1 (bottom).
766 * @xscale: the amount that the child widget expands horizontally to fill up unused space, from 0 to 1
767 * @yscale: the amount that the child widget expands vertically to fill up unused space, from 0 to 1
769 * Sets the alignment of the contents of the widget. If you don't need
770 * to change @xscale or @yscale you can just use
771 * gtk_button_set_alignment() instead.
773 * Note that for this method to work properly the, child widget of
774 * @button must be a #GtkAlignment. That's what #HildonButton uses by
775 * default, so this function will work unless you add a custom widget
781 hildon_button_set_alignment (HildonButton *button,
787 HildonButtonPrivate *priv;
790 g_return_if_fail (HILDON_IS_BUTTON (button));
792 priv = HILDON_BUTTON_GET_PRIVATE (button);
794 child = gtk_bin_get_child (GTK_BIN (button));
796 /* If the button has no child, use priv->alignment, which is the default one */
798 child = priv->alignment;
800 if (GTK_IS_ALIGNMENT (child)) {
801 gtk_alignment_set (GTK_ALIGNMENT (priv->alignment), xalign, yalign, xscale, yscale);
806 * hildon_button_set_title_alignment:
807 * @button: a #HildonButton
808 * @xalign: the horizontal alignment of the title label, from 0 (left) to 1 (right).
809 * @yalign: the vertical alignment of the title label, from 0 (top) to 1 (bottom).
811 * Sets the alignment of the title label. See also
812 * hildon_button_set_alignment() to set the alignment of the whole
813 * contents of the button.
818 hildon_button_set_title_alignment (HildonButton *button,
822 HildonButtonPrivate *priv;
824 g_return_if_fail (HILDON_IS_BUTTON (button));
826 priv = HILDON_BUTTON_GET_PRIVATE (button);
828 gtk_misc_set_alignment (GTK_MISC (priv->title), xalign, yalign);
832 * hildon_button_set_value_alignment:
833 * @button: a #HildonButton
834 * @xalign: the horizontal alignment of the value label, from 0 (left) to 1 (right).
835 * @yalign: the vertical alignment of the value label, from 0 (top) to 1 (bottom).
837 * Sets the alignment of the value label. See also
838 * hildon_button_set_alignment() to set the alignment of the whole
839 * contents of the button.
844 hildon_button_set_value_alignment (HildonButton *button,
848 HildonButtonPrivate *priv;
850 g_return_if_fail (HILDON_IS_BUTTON (button));
852 priv = HILDON_BUTTON_GET_PRIVATE (button);
854 gtk_misc_set_alignment (GTK_MISC (priv->value), xalign, yalign);
858 * hildon_button_set_image_alignment:
859 * @button: a #HildonButton
860 * @xalign: the horizontal alignment of the image, from 0 (left) to 1 (right).
861 * @yalign: the vertical alignment of the image, from 0 (top) to 1 (bottom).
863 * Sets the alignment of the image. See also
864 * hildon_button_set_alignment() to set the alignment of the whole
865 * contents of the button.
870 hildon_button_set_image_alignment (HildonButton *button,
874 HildonButtonPrivate *priv;
876 g_return_if_fail (HILDON_IS_BUTTON (button));
878 priv = HILDON_BUTTON_GET_PRIVATE (button);
880 /* Return if there's nothing to do */
881 if (priv->image_xalign == xalign && priv->image_yalign == yalign)
884 priv->image_xalign = xalign;
885 priv->image_yalign = yalign;
887 hildon_button_construct_child (button);
891 * hildon_button_set_style:
892 * @button: A #HildonButton
893 * @style: A #HildonButtonStyle for @button
895 * Sets the style of @button to @style. This changes the visual
896 * appearance of the button (colors, font sizes) according to the
897 * particular style chosen, but the general layout is not altered.
899 * Use %HILDON_BUTTON_STYLE_NORMAL to make it look like a normal
900 * #HildonButton, or %HILDON_BUTTON_STYLE_PICKER to make it look like
901 * a #HildonPickerButton.
906 hildon_button_set_style (HildonButton *button,
907 HildonButtonStyle style)
909 HildonButtonPrivate *priv;
912 g_return_if_fail (HILDON_IS_BUTTON (button));
915 case HILDON_BUTTON_STYLE_NORMAL:
916 color = "SecondaryTextColor";
918 case HILDON_BUTTON_STYLE_PICKER:
919 color = "ActiveTextColor";
922 g_return_if_reached ();
925 priv = HILDON_BUTTON_GET_PRIVATE (button);
927 hildon_helper_set_logical_color (GTK_WIDGET (priv->value), GTK_RC_FG, GTK_STATE_NORMAL, color);
928 hildon_helper_set_logical_color (GTK_WIDGET (priv->value), GTK_RC_FG, GTK_STATE_PRELIGHT, color);
932 g_object_notify (G_OBJECT (button), "style");
936 * hildon_button_get_style:
937 * @button: A #HildonButton
939 * Gets the visual style of the button.
941 * Returns: a #HildonButtonStyle
946 hildon_button_get_style (HildonButton *button)
948 HildonButtonPrivate *priv;
950 g_return_val_if_fail (HILDON_IS_BUTTON (button), HILDON_BUTTON_STYLE_NORMAL);
952 priv = HILDON_BUTTON_GET_PRIVATE (button);
958 hildon_button_construct_child (HildonButton *button)
960 HildonButtonPrivate *priv = HILDON_BUTTON_GET_PRIVATE (button);
963 const gchar *title, *value;
965 /* Don't do anything if the button is not constructed yet */
966 if (G_UNLIKELY (priv->label_box == NULL))
969 /* Don't do anything if the button has no contents */
970 title = gtk_label_get_text (priv->title);
971 value = gtk_label_get_text (priv->value);
972 if (!priv->image && !title[0] && !value[0])
975 /* Save a ref to the image, and remove it from its container if necessary */
977 g_object_ref (priv->image);
978 if (priv->image->parent != NULL)
979 gtk_container_remove (GTK_CONTAINER (priv->image->parent), priv->image);
982 if (priv->label_box->parent != NULL) {
983 gtk_container_remove (GTK_CONTAINER (priv->label_box->parent), priv->label_box);
986 /* Remove the child from the container and add priv->alignment */
987 child = gtk_bin_get_child (GTK_BIN (button));
988 if (child != NULL && child != priv->alignment) {
989 gtk_container_remove (GTK_CONTAINER (button), child);
994 gtk_container_add (GTK_CONTAINER (button), GTK_WIDGET (priv->alignment));
997 /* Create a new hbox */
999 gtk_container_remove (GTK_CONTAINER (priv->alignment), GTK_WIDGET (priv->hbox));
1001 gtk_widget_style_get (GTK_WIDGET (button), "image-spacing", &image_spacing, NULL);
1002 priv->hbox = GTK_BOX (gtk_hbox_new (FALSE, image_spacing));
1003 gtk_container_add (GTK_CONTAINER (priv->alignment), GTK_WIDGET (priv->hbox));
1005 /* Pack the image and the alignment in the new hbox */
1006 if (priv->image && priv->image_position == GTK_POS_LEFT)
1007 gtk_box_pack_start (priv->hbox, priv->image, FALSE, FALSE, 0);
1009 gtk_box_pack_start (priv->hbox, priv->label_box, TRUE, TRUE, 0);
1011 if (priv->image && priv->image_position == GTK_POS_RIGHT)
1012 gtk_box_pack_start (priv->hbox, priv->image, FALSE, FALSE, 0);
1014 /* Set image alignment and remove previously set ref */
1016 gtk_misc_set_alignment (GTK_MISC (priv->image), priv->image_xalign, priv->image_yalign);
1017 g_object_unref (priv->image);
1020 /* Show everything */
1021 gtk_widget_show_all (GTK_WIDGET (priv->alignment));