* SECTION:hildon-check-button
* @short_description: Button with a check box inside
*
- * This is a button containing a check box and a label. Functions are
- * provided to get and set the value of the check box. For the label
- * use gtk_button_set_label(). Note that this button does NOT support
- * an image, so don't use gtk_button_set_image()
+ * #HildonCheckButton is a button containing a label and a check box
+ * which will remain 'pressed-in' when clicked. Clicking again will
+ * make the check box toggle its state.
+ *
+ * The state of a #HildonCheckButton can be set using
+ * hildon_check_button_set_active(), and retrieved using
+ * hildon_check_button_get_active(). The label can be set using
+ * gtk_button_set_label() and retrieved using gtk_button_get_label().
+ *
+ * <note>
+ * <para>
+ * #HildonCheckButton does NOT support an image, so don't use
+ * gtk_button_set_image().
+ * </para>
+ * </note>
*
* <example>
* <title>Using a Hildon check button</title>
* }
* </programlisting>
* </example>
-
*/
#include "hildon-check-button.h"
* @button: A #HildonCheckButton
*
* Emits the #HildonCheckButton::toggled signal on the #HildonCheckButton.
+ * There is no good reason for an application ever to call this function.
+ *
+ * Since: 2.2
*/
void
hildon_check_button_toggled (HildonCheckButton *button)
* @button: A #HildonCheckButton
* @is_active: new state for the button
*
- * Sets the state of @button to @is_active
+ * Sets the status of a #HildonCheckButton. Set to %TRUE if you want
+ * @button to be 'pressed-in', and %FALSE to raise it. This action
+ * causes the #HildonCheckButton::toggled signal to be emitted.
+ *
+ * Since: 2.2
**/
void
hildon_check_button_set_active (HildonCheckButton *button,
g_return_if_fail (HILDON_IS_CHECK_BUTTON (button));
- prev_is_active = gtk_cell_renderer_toggle_get_active (button->priv->toggle_renderer);
+ prev_is_active = hildon_check_button_get_active (button);
if (prev_is_active != is_active) {
gtk_button_clicked (GTK_BUTTON (button));
* hildon_check_button_get_active:
* @button: A #HildonCheckButton
*
- * Gets the state of the button.
+ * Gets the current state of @button.
*
* Return value: %TRUE if @button is active, %FALSE otherwise.
+ *
+ * Since: 2.2
**/
gboolean
hildon_check_button_get_active (HildonCheckButton *button)
* hildon_check_button_new:
* @size: Flags indicating the size of the new button
*
- * This function creates a #HildonCheckButton.
+ * Creates a new #HildonCheckButton.
*
* Return value: A newly created #HildonCheckButton
+ *
+ * Since: 2.2
**/
GtkWidget *
hildon_check_button_new (HildonSizeType size)
static void
hildon_check_button_clicked (GtkButton *button)
{
- HildonCheckButtonPrivate *priv = HILDON_CHECK_BUTTON (button)->priv;
- gboolean current = gtk_cell_renderer_toggle_get_active (priv->toggle_renderer);
+ HildonCheckButton *checkbutton = HILDON_CHECK_BUTTON (button);
+ gboolean current = hildon_check_button_get_active (checkbutton);
+
+ gtk_cell_renderer_toggle_set_active (checkbutton->priv->toggle_renderer, !current);
+
+ hildon_check_button_toggled (checkbutton);
+}
+
+static void
+hildon_check_button_apply_style (GtkWidget *widget)
+{
+ guint checkbox_size;
+ HildonCheckButtonPrivate *priv = HILDON_CHECK_BUTTON (widget)->priv;
- gtk_cell_renderer_toggle_set_active (priv->toggle_renderer, !current);
+ gtk_widget_style_get (widget, "checkbox-size", &checkbox_size, NULL);
- hildon_check_button_toggled (HILDON_CHECK_BUTTON (button));
+ g_object_set (priv->toggle_renderer, "indicator-size", checkbox_size, NULL);
+}
+
+static void
+hildon_check_button_style_set (GtkWidget *widget,
+ GtkStyle *previous_style)
+{
+ if (GTK_WIDGET_CLASS (hildon_check_button_parent_class)->style_set)
+ GTK_WIDGET_CLASS (hildon_check_button_parent_class)->style_set (widget, previous_style);
+
+ hildon_check_button_apply_style (widget);
}
static void
hildon_check_button_class_init (HildonCheckButtonClass *klass)
{
GObjectClass *gobject_class = (GObjectClass*) klass;
+ GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
GtkButtonClass *button_class = (GtkButtonClass*) klass;
+ widget_class->style_set = hildon_check_button_style_set;
button_class->clicked = hildon_check_button_clicked;
klass->toggled = NULL;
/**
* HildonCheckButton::toggled
*
- * Emitted when the #HildonCheckButton's state is changed
+ * Emitted when the #HildonCheckButton's state is changed.
+ *
+ * Since: 2.2
*/
signals[TOGGLED] =
g_signal_new ("toggled",
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ gtk_widget_class_install_style_property (
+ widget_class,
+ g_param_spec_uint (
+ "checkbox-size",
+ "Size of the check box",
+ "Size of the check box",
+ 0, G_MAXUINT, 26,
+ G_PARAM_READABLE));
+
g_type_class_add_private (klass, sizeof (HildonCheckButtonPrivate));
}
/* Add cell view to the image */
gtk_button_set_image (GTK_BUTTON (button), cell_view);
+
+ gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
+
+ hildon_check_button_apply_style (GTK_WIDGET (button));
}