2008-08-08 Alberto Garcia <agarcia@igalia.com>
authorAlberto Garcia <agarcia@igalia.com>
Fri, 8 Aug 2008 16:52:24 +0000 (16:52 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Fri, 8 Aug 2008 16:52:24 +0000 (16:52 +0000)
* doc/hildon-docs.sgml
* src/Makefile.am
* src/hildon.h
* src/hildon-check-button.h
* src/hildon-check-button.c: New functions to create the Hildon
Touch Checkbox.

* src/hildon-gtk.h
* src/hildon-gtk.c (hildon_gtk_check_button_new): Removed.

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

index 5d060f5..b2e16b3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2008-08-08  Alberto Garcia  <agarcia@igalia.com>
 
+       * doc/hildon-docs.sgml
+       * src/Makefile.am
+       * src/hildon.h
+       * src/hildon-check-button.h
+       * src/hildon-check-button.c: New functions to create the Hildon
+       Touch Checkbox.
+
+       * src/hildon-gtk.h
+       * src/hildon-gtk.c (hildon_gtk_check_button_new): Removed.
+
+2008-08-08  Alberto Garcia  <agarcia@igalia.com>
+
        * src/hildon-button.h
        * src/hildon-button.c
        (hildon_button_add_title_size_group)
index 441ced2..fa59208 100644 (file)
@@ -29,6 +29,7 @@
   <chapter>
     <title>Selectors</title>
     <xi:include href="xml/hildon-button.xml"/>
+    <xi:include href="xml/hildon-check-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 0a1a780..90c99b4 100644 (file)
@@ -77,6 +77,7 @@ libhildon_@API_VERSION_MAJOR@_la_SOURCES = \
                hildon-bread-crumb-widget.c             \
                hildon-app-menu.c                       \
                hildon-button.c                         \
+               hildon-check-button.c                   \
                hildon-gtk.c                            \
                hildon-dialog.c
 
@@ -137,6 +138,7 @@ libhildon_@API_VERSION_MAJOR@_public_headers = \
                hildon-app-menu.h                       \
                hildon-dialog.h                         \
                hildon-button.h                         \
+               hildon-check-button.h                   \
                hildon-gtk.h                            \
                hildon-version.h
 
diff --git a/src/hildon-check-button.c b/src/hildon-check-button.c
new file mode 100644 (file)
index 0000000..fa1c3d7
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * This file is a part of hildon
+ *
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * 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-check-button
+ * @short_description: Button with a check box inside
+ *
+ * This is a standard GtkButton which contains a check box and a
+ * label. Functions are provided to get and set the values of both the
+ * check box and the label. Standard GtkButton methods must not be
+ * used for that.
+ *
+ * <example>
+ * <programlisting>
+ * void
+ * button_clicked (GtkButton *button, gpointer user_data)
+ * {
+ *     gboolean active;
+ * <!-- -->
+ *     active = hildon_check_button_get_active (button);
+ *     if (active)
+ *        g_debug ("Button is active");
+ *     else
+ *        g_debug ("Button is not active");
+ * }
+ * <!-- -->
+ * GtkWidget *
+ * create_button (void)
+ * {
+ *     GtkWidget *button;
+ * <!-- -->
+ *     button = hildon_check_button_new (HILDON_SIZE_AUTO);
+ *     hildon_check_button_set_label (GTK_BUTTON (button), "Click me");
+ * <!-- -->
+ *     g_signal_connect (button, "clicked", G_CALLBACK (button_clicked), NULL);
+ * <!-- -->
+ *     return button;
+ * }
+ * </programlisting>
+ * </example>
+
+ */
+
+#include                                        "hildon-check-button.h"
+
+static void
+check_button_clicked                            (GtkButton             *button,
+                                                 GtkCellRendererToggle *renderer)
+{
+    gboolean current = gtk_cell_renderer_toggle_get_active (renderer);
+    gtk_cell_renderer_toggle_set_active (renderer, !current);
+}
+
+/**
+ * hildon_check_button_set_label:
+ * @button: A #GtkButton created with hildon_check_button_new()
+ * @label: New text for the label.
+ *
+ * Sets the text of the button label to @label.
+ **/
+void
+hildon_check_button_set_label                   (GtkButton   *button,
+                                                 const gchar *label)
+{
+    GtkCellRendererText *text_renderer;
+
+    g_return_if_fail (GTK_IS_BUTTON (button));
+    text_renderer = GTK_CELL_RENDERER_TEXT (g_object_get_data (G_OBJECT (button), "text-renderer"));
+    g_return_if_fail (GTK_IS_CELL_RENDERER_TEXT (text_renderer));
+
+    g_object_set (text_renderer, "text", label, NULL);
+}
+
+/**
+ * hildon_check_button_get_label:
+ * @button: A #GtkButton created with hildon_check_button_new()
+ *
+ * Gets the text of the label inside the button.
+ *
+ * Return value: the text of the label. This string is owned by the
+ * button and must not be modified or freed.
+ **/
+const gchar *
+hildon_check_button_get_label                   (GtkButton   *button)
+{
+    GtkCellRendererText *text_renderer;
+    const gchar *text;
+
+    g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);
+    text_renderer = GTK_CELL_RENDERER_TEXT (g_object_get_data (G_OBJECT (button), "text-renderer"));
+    g_return_val_if_fail (GTK_IS_CELL_RENDERER_TEXT (text_renderer), NULL);
+
+    g_object_get (text_renderer, "text", &text, NULL);
+
+    return text;
+}
+
+/**
+ * hildon_check_button_set_active:
+ * @button: A #GtkButton created with hildon_check_button_new()
+ * @is_active: new state for the check box
+ *
+ * Sets the state of the check box.
+ **/
+void
+hildon_check_button_set_active                  (GtkButton *button,
+                                                 gboolean   is_active)
+{
+    GtkCellRendererToggle *toggle_renderer;
+
+    g_return_if_fail (GTK_IS_BUTTON (button));
+    toggle_renderer = GTK_CELL_RENDERER_TOGGLE (g_object_get_data (G_OBJECT (button), "toggle-renderer"));
+    g_return_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle_renderer));
+
+    gtk_cell_renderer_toggle_set_active (toggle_renderer, is_active);
+}
+
+/**
+ * hildon_check_button_get_active:
+ * @button: A #GtkButton created with hildon_check_button_new()
+ *
+ * Gets the state of the check box.
+ *
+ * Return value: %TRUE if the check box is active, %FALSE otherwise.
+ **/
+gboolean
+hildon_check_button_get_active                  (GtkButton *button)
+{
+    GtkCellRendererToggle *toggle_renderer;
+
+    g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
+    toggle_renderer = GTK_CELL_RENDERER_TOGGLE (g_object_get_data (G_OBJECT (button), "toggle-renderer"));
+    g_return_val_if_fail (GTK_IS_CELL_RENDERER_TOGGLE (toggle_renderer), FALSE);
+
+    return gtk_cell_renderer_toggle_get_active (toggle_renderer);
+}
+
+/**
+ * hildon_check_button_new:
+ * @size: Flags indicating the size of the new button
+ *
+ * This function creates a #GtkButton containing a label and a check
+ * box.
+ *
+ * This button has specific functions to get and set the values of the
+ * label and the check box. You must not use the standard #GtkButton
+ * methods for that.
+ *
+ * To set the alignment you can use gtk_button_set_alignment()
+ *
+ * Return value: A newly created #GtkButton widget.
+ **/
+GtkWidget *
+hildon_check_button_new                         (HildonSizeType size)
+{
+    GtkWidget *button = gtk_button_new ();
+    GtkWidget *cell_view = gtk_cell_view_new ();
+    GtkCellRenderer *toggle_renderer = gtk_cell_renderer_toggle_new ();
+    GtkCellRenderer *text_renderer = gtk_cell_renderer_text_new ();
+    GtkWidget *alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+
+    /* Set the size of the button */
+    hildon_gtk_widget_set_theme_size (button, size);
+
+    /* Pack everything */
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cell_view), toggle_renderer, FALSE);
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cell_view), text_renderer, FALSE);
+    gtk_container_add (GTK_CONTAINER (alignment), cell_view);
+    gtk_container_add (GTK_CONTAINER (button), alignment);
+    gtk_widget_show_all (GTK_WIDGET (alignment));
+
+    /* Toggle the check box when the button is clicked */
+    g_signal_connect (button, "clicked", G_CALLBACK (check_button_clicked), toggle_renderer);
+
+    /* Set the data */
+    g_object_set_data (G_OBJECT (button), "toggle-renderer", toggle_renderer);
+    g_object_set_data (G_OBJECT (button), "text-renderer", text_renderer);
+
+    return button;
+}
diff --git a/src/hildon-check-button.h b/src/hildon-check-button.h
new file mode 100644 (file)
index 0000000..a5aedcd
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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_CHECK_BUTTON_H__
+#define                                         __HILDON_CHECK_BUTTON_H__
+
+#include                                        "hildon-gtk.h"
+
+G_BEGIN_DECLS
+
+GtkWidget *
+hildon_check_button_new                         (HildonSizeType size);
+
+void
+hildon_check_button_set_label                   (GtkButton   *button,
+                                                 const gchar *label);
+
+const gchar *
+hildon_check_button_get_label                   (GtkButton   *button);
+
+void
+hildon_check_button_set_active                  (GtkButton *button,
+                                                 gboolean   is_active);
+
+gboolean
+hildon_check_button_get_active                  (GtkButton *button);
+
+
+G_END_DECLS
+
+#endif /* __HILDON_CHECK_BUTTON_H__ */
index fa2cacb..5fc8d67 100644 (file)
@@ -109,23 +109,6 @@ hildon_gtk_toggle_button_new                    (HildonSizeType size)
 }
 
 /**
- * hildon_gtk_check_button_new:
- * @size: Flags indicating the size of the new button
- *
- * This is a convenience function to create a #GtkCheckButton setting
- * its size to one of the pre-defined Hildon sizes.
- *
- * Return value: A newly created #GtkCheckButton widget.
- **/
-GtkWidget *
-hildon_gtk_check_button_new                     (HildonSizeType size)
-{
-    GtkWidget *button = gtk_check_button_new ();
-    hildon_gtk_widget_set_theme_size (button, size);
-    return button;
-}
-
-/**
  * hildon_gtk_radio_button_new:
  * @size: Flags indicating the size of the new button
  * @group: An existing radio button group, or %NULL if you are
index a506794..6b8431c 100644 (file)
@@ -42,9 +42,6 @@ GtkWidget *
 hildon_gtk_toggle_button_new                    (HildonSizeType size);
 
 GtkWidget *
-hildon_gtk_check_button_new                     (HildonSizeType size);
-
-GtkWidget *
 hildon_gtk_radio_button_new                     (HildonSizeType  size,
                                                  GSList         *group);
 
index 7af7e30..66bb3d8 100644 (file)
@@ -74,6 +74,7 @@
 #include                                        "hildon-pannable-area.h"
 #include                                        "hildon-app-menu.h"
 #include                                        "hildon-button.h"
+#include                                        "hildon-check-button.h"
 #include                                        "hildon-gtk.h"
 #include                                        "hildon-dialog.h"