2008-11-27 Alberto Garcia <agarcia@igalia.com>
authorAlberto Garcia <agarcia@igalia.com>
Thu, 27 Nov 2008 12:49:55 +0000 (12:49 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Thu, 27 Nov 2008 12:49:55 +0000 (12:49 +0000)
* src/hildon-button.h
* src/hildon-button.c (hildon_button_set_property)
(hildon_button_get_property, hildon_button_class_init)
(hildon_button_set_style, hildon_button_get_style):
New "style" property to change the visual appearance of the
button.

* src/hildon-picker-button.c (hildon_picker_button_new):
Set the new "style" property to HILDON_BUTTON_STYLE_PICKER.

Fixes: NB#93281 (new API: hildon_button_set_picker_style() to set
HildonButton look like PickerButton)

ChangeLog
src/hildon-button.c
src/hildon-button.h
src/hildon-picker-button.c

index f20b09b..b9e22bc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2008-11-27  Alberto Garcia  <agarcia@igalia.com>
+
+       * src/hildon-button.h
+       * src/hildon-button.c (hildon_button_set_property)
+       (hildon_button_get_property, hildon_button_class_init)
+       (hildon_button_set_style, hildon_button_get_style):
+       New "style" property to change the visual appearance of the
+       button.
+
+       * src/hildon-picker-button.c (hildon_picker_button_new):
+       Set the new "style" property to HILDON_BUTTON_STYLE_PICKER.
+
+       Fixes: NB#93281 (new API: hildon_button_set_picker_style() to set
+       HildonButton look like PickerButton)
+
 2008-11-27  Claudio Saavedra  <csaavedra@igalia.com>
 
        * src/hildon-touch-selector.c: (_default_print_func): Get the correct
index e6b6141..2c366ee 100644 (file)
@@ -98,13 +98,15 @@ struct                                          _HildonButtonPrivate
     GtkPositionType image_position;
     gfloat image_xalign;
     gfloat image_yalign;
+    HildonButtonStyle style;
 };
 
 enum {
     PROP_TITLE = 1,
     PROP_VALUE,
     PROP_SIZE,
-    PROP_ARRANGEMENT
+    PROP_ARRANGEMENT,
+    PROP_STYLE
 };
 
 static void
@@ -136,6 +138,9 @@ hildon_button_set_property                      (GObject      *object,
     case PROP_ARRANGEMENT:
         hildon_button_set_arrangement (button, g_value_get_enum (value));
         break;
+    case PROP_STYLE:
+        hildon_button_set_style (button, g_value_get_enum (value));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -158,6 +163,9 @@ hildon_button_get_property                      (GObject    *object,
     case PROP_VALUE:
         g_value_set_string (value, hildon_button_get_value (button));
         break;
+    case PROP_STYLE:
+        g_value_set_enum (value, hildon_button_get_style (button));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -255,6 +263,17 @@ hildon_button_class_init                        (HildonButtonClass *klass)
             HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
             G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 
+    g_object_class_install_property (
+        gobject_class,
+        PROP_STYLE,
+        g_param_spec_enum (
+            "style",
+            "Style",
+            "Visual style of the button",
+            HILDON_TYPE_BUTTON_STYLE,
+            HILDON_BUTTON_STYLE_NORMAL,
+            G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
     gtk_widget_class_install_style_property (
         widget_class,
         g_param_spec_uint (
@@ -800,6 +819,69 @@ hildon_button_set_image_alignment               (HildonButton *button,
     hildon_button_construct_child (button);
 }
 
+/**
+ * hildon_button_set_style:
+ * @button: A #HildonButton
+ * @style: A #HildonButtonStyle for @button
+ *
+ * Sets the style of @button to @style. This changes the visual
+ * appearance of the button (colors, font sizes) according to the
+ * particular style chosen, but the general layout is not altered.
+ *
+ * Use %HILDON_BUTTON_STYLE_NORMAL to make it look like a normal
+ * #HildonButton, or %HILDON_BUTTON_STYLE_PICKER to make it look like
+ * a #HildonPickerButton.
+ */
+void
+hildon_button_set_style                         (HildonButton      *button,
+                                                 HildonButtonStyle  style)
+{
+    HildonButtonPrivate *priv;
+    const gchar *color;
+
+    g_return_if_fail (HILDON_IS_BUTTON (button));
+
+    switch (style) {
+    case HILDON_BUTTON_STYLE_NORMAL:
+        color = "SecondaryTextColor";
+        break;
+    case HILDON_BUTTON_STYLE_PICKER:
+        color = "ActiveTextColor";
+        break;
+    default:
+        g_return_if_reached ();
+    }
+
+    priv = HILDON_BUTTON_GET_PRIVATE (button);
+
+    hildon_helper_set_logical_color (GTK_WIDGET (priv->value), GTK_RC_FG, GTK_STATE_NORMAL, color);
+    hildon_helper_set_logical_color (GTK_WIDGET (priv->value), GTK_RC_FG, GTK_STATE_PRELIGHT, color);
+
+    priv->style = style;
+
+    g_object_notify (G_OBJECT (button), "style");
+}
+
+/**
+ * hildon_button_get_style:
+ * @button: A #HildonButton
+ *
+ * Gets the visual style of the button.
+ *
+ * Returns: a #HildonButtonStyle
+ */
+HildonButtonStyle
+hildon_button_get_style                         (HildonButton *button)
+{
+    HildonButtonPrivate *priv;
+
+    g_return_val_if_fail (HILDON_IS_BUTTON (button), HILDON_BUTTON_STYLE_NORMAL);
+
+    priv = HILDON_BUTTON_GET_PRIVATE (button);
+
+    return priv->style;
+}
+
 static void
 hildon_button_construct_child                   (HildonButton *button)
 {
index 7019ff7..0d95d25 100644 (file)
@@ -63,6 +63,11 @@ typedef enum {
    HILDON_BUTTON_ARRANGEMENT_VERTICAL
 }                                               HildonButtonArrangement;
 
+typedef enum {
+   HILDON_BUTTON_STYLE_NORMAL,
+   HILDON_BUTTON_STYLE_PICKER
+}                                               HildonButtonStyle;
+
 GType
 hildon_button_get_type                          (void) G_GNUC_CONST;
 
@@ -144,6 +149,13 @@ hildon_button_add_size_groups                   (HildonButton *button,
                                                  GtkSizeGroup *value_size_group,
                                                  GtkSizeGroup *image_size_group);
 
+void
+hildon_button_set_style                         (HildonButton      *button,
+                                                 HildonButtonStyle  style);
+
+HildonButtonStyle
+hildon_button_get_style                         (HildonButton *button);
+
 G_END_DECLS
 
 #endif /* __HILDON_BUTTON_H__ */
index 6165d5c..a3e49c0 100644 (file)
@@ -313,7 +313,8 @@ hildon_picker_button_new (HildonSizeType          size,
   GtkWidget *button;
 
   button = g_object_new (HILDON_TYPE_PICKER_BUTTON,
-                         "arrangement", arrangement, "size", size, NULL);
+                         "arrangement", arrangement, "size", size,
+                         "style", HILDON_BUTTON_STYLE_PICKER, NULL);
 
   return button;
 }