2008-08-14 Alberto Garcia <agarcia@igalia.com>
authorAlberto Garcia <agarcia@igalia.com>
Thu, 14 Aug 2008 14:17:12 +0000 (14:17 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Thu, 14 Aug 2008 14:17:12 +0000 (14:17 +0000)
* src/hildon-check-button.c (hildon_check_button_new):
Instead of using a custom container, display the label and the
checkbox using the standard GtkButton API.

* examples/hildon-check-button-example.c (main): Don't use
hildon_check_button_set_label() anymore

* src/hildon-check-button.h
* src/hildon-check-button.c
(hildon_check_button_set_label, hildon_check_button_get_label):
Set as deprecated, now we're using gtk_button_{get,set}_label()

ChangeLog
examples/hildon-check-button-example.c
src/hildon-check-button.c
src/hildon-check-button.h

index 6244b73..a6c54ff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-08-14  Alberto Garcia  <agarcia@igalia.com>
+
+       * src/hildon-check-button.c (hildon_check_button_new):
+       Instead of using a custom container, display the label and the
+       checkbox using the standard GtkButton API.
+
+       * examples/hildon-check-button-example.c (main): Don't use
+       hildon_check_button_set_label() anymore
+
+       * src/hildon-check-button.h
+       * src/hildon-check-button.c
+       (hildon_check_button_set_label, hildon_check_button_get_label):
+       Set as deprecated, now we're using gtk_button_{get,set}_label()
+
 2008-08-14  Alejandro G. Castro         <alex@igalia.com>
 
        * src/hildon-pannable-area.c,
index fb2e8a9..f2e8863 100644 (file)
@@ -59,7 +59,7 @@ main                                            (int    argc,
         char *text;
         GtkWidget *button = hildon_check_button_new (HILDON_SIZE_HALFSCREEN_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
         text = g_strdup_printf ("Button %d", i+1);
-        hildon_check_button_set_label (GTK_BUTTON (button), text);
+        gtk_button_set_label (GTK_BUTTON (button), text);
         g_free (text);
         gtk_table_attach_defaults (GTK_TABLE (table), button, i/2, (i/2) + 1, i%2, (i%2) + 1);
         g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), label);
index fa1c3d7..dffc6a4 100644 (file)
@@ -19,9 +19,9 @@
  * @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.
+ * label. Functions are provided to get and set the value of the check
+ * box. Note that this button does NOT support an image, so don't use
+ * gtk_button_set_image()
  *
  * <example>
  * <programlisting>
@@ -43,7 +43,7 @@
  *     GtkWidget *button;
  * <!-- -->
  *     button = hildon_check_button_new (HILDON_SIZE_AUTO);
- *     hildon_check_button_set_label (GTK_BUTTON (button), "Click me");
+ *     gtk_button_set_label (GTK_BUTTON (button), "Click me");
  * <!-- -->
  *     g_signal_connect (button, "clicked", G_CALLBACK (button_clicked), NULL);
  * <!-- -->
@@ -70,18 +70,14 @@ check_button_clicked                            (GtkButton             *button,
  * @label: New text for the label.
  *
  * Sets the text of the button label to @label.
+ *
+ * Deprecated: Use gtk_button_set_label() instead.
  **/
 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);
+    gtk_button_set_label (button, label);
 }
 
 /**
@@ -92,20 +88,13 @@ hildon_check_button_set_label                   (GtkButton   *button,
  *
  * Return value: the text of the label. This string is owned by the
  * button and must not be modified or freed.
+ *
+ * Deprecated: Use gtk_button_get_label() instead.
  **/
 const gchar *
-hildon_check_button_get_label                   (GtkButton   *button)
+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;
+    return gtk_button_get_label (button);
 }
 
 /**
@@ -155,11 +144,8 @@ hildon_check_button_get_active                  (GtkButton *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()
+ * This button has specific functions to get and set the value of the
+ * check box.
  *
  * Return value: A newly created #GtkButton widget.
  **/
@@ -169,25 +155,22 @@ 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 */
+    /* Make sure that the check box is always shown, no matter the value of gtk-button-images */
+    g_signal_connect (cell_view, "notify::visible", G_CALLBACK (gtk_widget_show), NULL);
+
+    /* Store the renderer for later use */
     g_object_set_data (G_OBJECT (button), "toggle-renderer", toggle_renderer);
-    g_object_set_data (G_OBJECT (button), "text-renderer", text_renderer);
+
+    /* Pack everything */
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cell_view), toggle_renderer, FALSE);
+    gtk_button_set_image (GTK_BUTTON (button), cell_view);
 
     return button;
 }
index a5aedcd..f096b2d 100644 (file)
@@ -26,12 +26,14 @@ G_BEGIN_DECLS
 GtkWidget *
 hildon_check_button_new                         (HildonSizeType size);
 
+#ifndef HILDON_DISABLE_DEPRECATED
 void
 hildon_check_button_set_label                   (GtkButton   *button,
                                                  const gchar *label);
 
 const gchar *
 hildon_check_button_get_label                   (GtkButton   *button);
+#endif
 
 void
 hildon_check_button_set_active                  (GtkButton *button,
@@ -40,7 +42,6 @@ hildon_check_button_set_active                  (GtkButton *button,
 gboolean
 hildon_check_button_get_active                  (GtkButton *button);
 
-
 G_END_DECLS
 
 #endif /* __HILDON_CHECK_BUTTON_H__ */