2008-07-30 Alberto Garcia <agarcia@igalia.com>
authorAlberto Garcia <agarcia@igalia.com>
Wed, 30 Jul 2008 12:39:15 +0000 (12:39 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Wed, 30 Jul 2008 12:39:15 +0000 (12:39 +0000)
* doc/hildon-docs.sgml
* doc/hildon.types
* src/Makefile.am
* src/hildon-toggle-button.c
* src/hildon-toggle-button.h
* src/hildon.h: New HildonToggleButton widget.

ChangeLog
doc/hildon-docs.sgml
doc/hildon.types
src/Makefile.am
src/hildon-toggle-button.c [new file with mode: 0644]
src/hildon-toggle-button.h [new file with mode: 0644]
src/hildon.h

index 3718194..fb229a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2008-07-30  Alberto Garcia  <agarcia@igalia.com>
 
+       * doc/hildon-docs.sgml
+       * doc/hildon.types
+       * src/Makefile.am
+       * src/hildon-toggle-button.c
+       * src/hildon-toggle-button.h
+       * src/hildon.h: New HildonToggleButton widget.
+
+2008-07-30  Alberto Garcia  <agarcia@igalia.com>
+
        * src/hildon-button.c: Add API documentation.
        (hildon_button_set_size_groups): Check input parameters
 
index 4cdd32f..56c5cdc 100644 (file)
@@ -29,6 +29,7 @@
   <chapter>
     <title>Selectors</title>
     <xi:include href="xml/hildon-button.xml"/>
+    <xi:include href="xml/hildon-toggle-button.xml"/>
     <xi:include href="xml/hildon-color-button.xml"/>
     <xi:include href="xml/hildon-color-chooser-dialog.xml"/>
     <xi:include href="xml/hildon-color-chooser.xml"/>
index adea75b..c5a848f 100644 (file)
@@ -38,6 +38,7 @@
 #include                                        <src/hildon-stackable-window.h>
 #include                                        <src/hildon-app-menu.h>
 #include                                        <src/hildon-button.h>
+#include                                        <src/hildon-toggle-button.h>
 #include                                        <src/hildon-touch-picker.h>
 #include                                        <src/hildon-time-selector.h>
 #include                                        <src/hildon-date-selector.h>
@@ -82,6 +83,7 @@ hildon_pannable_area_get_type
 hildon_stackable_window_get_type
 hildon_app_menu_get_type
 hildon_button_get_type
+hildon_toggle_button_get_type
 hildon_touch_picker_get_type
 hildon_time_selector_get_type
 hildon_date_selector_get_type
index 5ef8cd0..aeaf189 100644 (file)
@@ -73,6 +73,7 @@ libhildon_@API_VERSION_MAJOR@_la_SOURCES              = hildon-private.c                              \
                                                          hildon-bread-crumb-widget.c                   \
                                                          hildon-app-menu.c                             \
                                                          hildon-button.c                               \
+                                                         hildon-toggle-button.c                        \
                                                          hildon-dialog.c
 
 libhildon_@API_VERSION_MAJOR@_built_public_headers  = \
@@ -129,6 +130,7 @@ libhildon_@API_VERSION_MAJOR@_public_headers                = hildon-banner.h                               \
                                                          hildon-app-menu.h                             \
                                                          hildon-dialog.h                               \
                                                          hildon-button.h                               \
+                                                         hildon-toggle-button.h                        \
                                                          hildon-version.h
 
 libhildon_@API_VERSION_MAJOR@_include_HEADERS          = $(libhildon_@API_VERSION_MAJOR@_public_headers)                       \
diff --git a/src/hildon-toggle-button.c b/src/hildon-toggle-button.c
new file mode 100644 (file)
index 0000000..61cc367
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * This file is a part of hildon
+ *
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Contact: Karl Lattimer <karl.lattimer@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser Public License as published by
+ * the Free Software Foundation; version 2 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser Public License for more details.
+ *
+ */
+
+/**
+ * SECTION:hildon-toggle-button
+ * @short_description: Widget representing a toggle button in the Hildon framework.
+ *
+ * The #HildonToggleButton is a GTK widget which represents a toggle
+ * button. It is derived from the GtkToggleButton widget and provides
+ * additional commodities specific to the Hildon framework.
+ *
+ * The height of a #HildonToggleButton can be set to either "finger" height
+ * or "thumb" height. It can also be configured to use halfscreen or
+ * fullscreen width. Alternatively, either dimension can be set to
+ * "auto" so it behaves like a standard GtkToggleButton.
+ */
+
+#include                                        "hildon-toggle-button.h"
+#include                                        "hildon-enum-types.h"
+
+#define FINGER_BUTTON_HEIGHT                    70
+#define THUMB_BUTTON_HEIGHT                     105
+#define HALFSCREEN_BUTTON_WIDTH                 400
+#define FULLSCREEN_BUTTON_WIDTH                 800
+
+G_DEFINE_TYPE                                   (HildonToggleButton, hildon_toggle_button, GTK_TYPE_TOGGLE_BUTTON);
+
+enum {
+  PROP_ARRANGEMENT_FLAGS
+};
+
+static void
+hildon_toggle_button_set_arrangement            (HildonToggleButton      *button,
+                                                 HildonToggleButtonFlags  flags);
+
+static void
+hildon_toggle_button_set_property               (GObject      *object,
+                                                 guint         prop_id,
+                                                 const GValue *value,
+                                                 GParamSpec   *pspec)
+{
+    HildonToggleButton *button = HILDON_TOGGLE_BUTTON (object);
+
+    switch (prop_id)
+    {
+    case PROP_ARRANGEMENT_FLAGS:
+        hildon_toggle_button_set_arrangement (button, g_value_get_flags (value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+hildon_toggle_button_class_init                 (HildonToggleButtonClass *klass)
+{
+    GObjectClass *gobject_class = (GObjectClass *)klass;
+
+    gobject_class->set_property = hildon_toggle_button_set_property;
+
+    g_object_class_install_property (
+        gobject_class,
+        PROP_ARRANGEMENT_FLAGS,
+        g_param_spec_flags (
+            "arrangement-flags",
+            "Arrangement flags",
+            "How the button contents must be arranged",
+            HILDON_TYPE_TOGGLE_BUTTON_FLAGS,
+            HILDON_TOGGLE_BUTTON_AUTO_WIDTH | HILDON_TOGGLE_BUTTON_AUTO_HEIGHT,
+            G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+hildon_toggle_button_init                       (HildonToggleButton *self)
+{
+}
+
+/**
+ * hildon_toggle_button_new:
+ * @flags: flags to set the size of the button
+ *
+ * Creates a new #HildonToggleButton. To add a child widget use gtk_container_add().
+ *
+ * Returns: a new #HildonToggleButton
+ **/
+GtkWidget *
+hildon_toggle_button_new                        (HildonToggleButtonFlags flags)
+{
+    GtkWidget *button;
+    /* Create widget */
+    button = g_object_new (HILDON_TYPE_TOGGLE_BUTTON,
+                           "arrangement-flags", flags,
+                           NULL);
+    return button;
+}
+
+/**
+ * hildon_toggle_button_new_with_label:
+ * @flags: flags to set the size of the button
+ * @label: a text to set in the button label
+ *
+ * Creates a new #HildonToggleButton with a text label.
+ *
+ * Returns: a new #HildonToggleButton
+ **/
+GtkWidget *
+hildon_toggle_button_new_with_label             (HildonToggleButtonFlags  flags,
+                                                 const char              *label)
+{
+    GtkWidget *button;
+    /* Create widget */
+    button = g_object_new (HILDON_TYPE_TOGGLE_BUTTON,
+                           "arrangement-flags", flags,
+                           "label", label,
+                           NULL);
+    return button;
+}
+
+static void
+hildon_toggle_button_set_arrangement            (HildonToggleButton      *button,
+                                                 HildonToggleButtonFlags  flags)
+{
+    gint width = -1;
+    gint height = -1;
+    const char *widget_name = NULL;
+
+    /* Requested height */
+    if (flags & HILDON_TOGGLE_BUTTON_FINGER_HEIGHT) {
+        height = FINGER_BUTTON_HEIGHT;
+        widget_name = "hildon-finger-button";
+    } else if (flags & HILDON_TOGGLE_BUTTON_THUMB_HEIGHT) {
+        height = THUMB_BUTTON_HEIGHT;
+        widget_name = "hildon-thumb-button";
+    }
+
+    if (widget_name) {
+        gtk_widget_set_name (GTK_WIDGET (button), widget_name);
+    }
+
+    /* Requested width */
+    if (flags & HILDON_TOGGLE_BUTTON_HALFSCREEN_WIDTH) {
+        width = HALFSCREEN_BUTTON_WIDTH;
+    } else if (flags & HILDON_TOGGLE_BUTTON_FULLSCREEN_WIDTH) {
+        width = FULLSCREEN_BUTTON_WIDTH;
+    }
+
+    g_object_set (button,
+                  "width-request", width,
+                  "height-request", height,
+                  NULL);
+
+}
diff --git a/src/hildon-toggle-button.h b/src/hildon-toggle-button.h
new file mode 100644 (file)
index 0000000..292442e
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * This file is a part of hildon
+ *
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Contact: Karl Lattimer <karl.lattimer@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser Public License as published by
+ * the Free Software Foundation; version 2 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser Public License for more details.
+ *
+ */
+
+#ifndef                                         __HILDON_TOGGLE_BUTTON_H__
+#define                                         __HILDON_TOGGLE_BUTTON_H__
+
+#include                                        <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define                                         HILDON_TYPE_TOGGLE_BUTTON \
+                                                (hildon_toggle_button_get_type())
+
+#define                                         HILDON_TOGGLE_BUTTON(obj) \
+                                                (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                HILDON_TYPE_TOGGLE_BUTTON, HildonToggleButton))
+
+#define                                         HILDON_TOGGLE_BUTTON_CLASS(klass) \
+                                                (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                                HILDON_TYPE_TOGGLE_BUTTON, HildonToggleButtonClass))
+
+#define                                         HILDON_IS_TOGGLE_BUTTON(obj) \
+                                                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HILDON_TYPE_TOGGLE_BUTTON))
+
+#define                                         HILDON_IS_TOGGLE_BUTTON_CLASS(klass) \
+                                                (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_TOGGLE_BUTTON))
+
+#define                                         HILDON_TOGGLE_BUTTON_GET_CLASS(obj) \
+                                                (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                                HILDON_TYPE_TOGGLE_BUTTON, HildonToggleButtonClass))
+
+typedef struct                                  _HildonToggleButton HildonToggleButton;
+
+typedef struct                                  _HildonToggleButtonClass HildonToggleButtonClass;
+
+struct                                          _HildonToggleButtonClass
+{
+    GtkToggleButtonClass parent_class;
+};
+
+struct                                          _HildonToggleButton
+{
+    GtkToggleButton parent;
+};
+
+typedef enum {
+   HILDON_TOGGLE_BUTTON_AUTO_WIDTH              = 0,      /* leave width unset */
+   HILDON_TOGGLE_BUTTON_HALFSCREEN_WIDTH        = 1,      /* set to 50% screen width */
+   HILDON_TOGGLE_BUTTON_FULLSCREEN_WIDTH        = 2,      /* set to 100% screen width */
+   HILDON_TOGGLE_BUTTON_AUTO_HEIGHT             = 0 << 2, /* leave height unset */
+   HILDON_TOGGLE_BUTTON_FINGER_HEIGHT           = 1 << 2, /* set to finger height */
+   HILDON_TOGGLE_BUTTON_THUMB_HEIGHT            = 2 << 2, /* set to thumb height */
+}                                               HildonToggleButtonFlags;
+
+GType
+hildon_toggle_button_get_type                   (void) G_GNUC_CONST;
+
+GtkWidget *
+hildon_toggle_button_new                        (HildonToggleButtonFlags flags);
+
+GtkWidget *
+hildon_toggle_button_new_with_label             (HildonToggleButtonFlags  flags,
+                                                 const char              *label);
+
+G_END_DECLS
+
+#endif /* __HILDON_TOGGLE_BUTTON_H__ */
index 6bd5796..363b826 100644 (file)
@@ -73,6 +73,7 @@
 #include                                        "hildon-pannable-area.h"
 #include                                        "hildon-app-menu.h"
 #include                                        "hildon-button.h"
+#include                                        "hildon-toggle-button.h"
 #include                                        "hildon-dialog.h"
 
 #endif