2008-08-14 Alberto Garcia <agarcia@igalia.com>
[hildon] / src / hildon-check-button.c
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;
 }