From: Alberto Garcia Date: Fri, 21 Aug 2009 08:40:52 +0000 (+0200) Subject: Make HildonCheckButton derive from GtkToggleButton X-Git-Tag: 2.1.96-1~1 X-Git-Url: https://vcs.maemo.org/git/?p=hildon;a=commitdiff_plain;h=2911cf0dc0242c87a95d2577d54c898ce060873f Make HildonCheckButton derive from GtkToggleButton * hildon/hildon-check-button.h * hildon/hildon-check-button.c (hildon_check_button_clicked, hildon_check_button_class_init): Make HildonCheckButton derive from GtkToggleButton (hildon_check_button_toggled, hildon_check_button_set_active) (hildon_check_button_get_active): Deprecate unnecessary HildonCheckButton API and use the one from GtkToggleButton instead. * hildon/hildon-set-password-dialog.c (create_contents) (hildon_set_password_response_change, hildon_checkbox_toggled) * examples/hildon-check-button-example.c (button_toggled_cb): Update to use the GtkToggleButton API Fixes: MB#4739 (HildonCheckButton should inherit from GtkToggleButton) Fixes: NB#132661 (HildonCheckButton should inherit from GtkToggleButton) --- diff --git a/ChangeLog b/ChangeLog index 8849e93..7f33046 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2009-08-21 Alberto Garcia + + * hildon/hildon-check-button.h + * hildon/hildon-check-button.c + (hildon_check_button_clicked, hildon_check_button_class_init): + Make HildonCheckButton derive from GtkToggleButton + (hildon_check_button_toggled, hildon_check_button_set_active) + (hildon_check_button_get_active): + Deprecate unnecessary HildonCheckButton API and use the + one from GtkToggleButton instead. + + * hildon/hildon-set-password-dialog.c (create_contents) + (hildon_set_password_response_change, hildon_checkbox_toggled) + * examples/hildon-check-button-example.c (button_toggled_cb): + Update to use the GtkToggleButton API + + Fixes: MB#4739 (HildonCheckButton should inherit from + GtkToggleButton) + + Fixes: NB#132661 (HildonCheckButton should inherit from + GtkToggleButton) + 2009-08-20 Alberto Garcia * hildon/hildon-pannable-area.c diff --git a/examples/hildon-check-button-example.c b/examples/hildon-check-button-example.c index fca96bf..4fe7cfd 100644 --- a/examples/hildon-check-button-example.c +++ b/examples/hildon-check-button-example.c @@ -23,10 +23,10 @@ #include static void -button_toggled_cb (HildonCheckButton *button, - GtkLabel *label) +button_toggled_cb (GtkToggleButton *button, + GtkLabel *label) { - gboolean active = hildon_check_button_get_active (button); + gboolean active = gtk_toggle_button_get_active (button); const gchar *labeltext = gtk_button_get_label (GTK_BUTTON (button)); char *text = g_strconcat (labeltext, active ? " (checked)" : " (unchecked)", NULL); gtk_label_set_text (label, text); diff --git a/hildon/hildon-check-button.c b/hildon/hildon-check-button.c index bad22cc..93cfa25 100644 --- a/hildon/hildon-check-button.c +++ b/hildon/hildon-check-button.c @@ -26,9 +26,9 @@ * with a different appearance that combines a standard button and a * check box. * - * 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 + * #HildonCheckButton derives from #GtkToggleButton so its state can + * be set with gtk_toggle_button_set_active(), and retrieved using + * gtk_toggle_button_get_active(). The label can be set using * gtk_button_set_label() and retrieved using gtk_button_get_label(). * * @@ -42,11 +42,11 @@ * Using a Hildon check button * * void - * button_toggled (HildonCheckButton *button, gpointer user_data) + * button_toggled (GtkToggleButton *button, gpointer user_data) * { * gboolean active; * - * active = hildon_check_button_get_active (button); + * active = gtk_toggle_button_get_active (button); * if (active) * g_debug ("Button is active"); * else @@ -69,20 +69,15 @@ * */ -#include "hildon-check-button.h" +#undef HILDON_DISABLE_DEPRECATED -enum { - TOGGLED, - LAST_SIGNAL -}; +#include "hildon-check-button.h" enum { PROP_SIZE = 1 }; -static guint signals[LAST_SIGNAL] = { 0 }; - -G_DEFINE_TYPE (HildonCheckButton, hildon_check_button, GTK_TYPE_BUTTON); +G_DEFINE_TYPE (HildonCheckButton, hildon_check_button, GTK_TYPE_TOGGLE_BUTTON); #define HILDON_CHECK_BUTTON_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ @@ -98,7 +93,8 @@ struct _HildonCheckButtonPrivate * @button: A #HildonCheckButton * * Emits the #HildonCheckButton::toggled signal on the #HildonCheckButton. - * There is no good reason for an application ever to call this function. + * + * Deprecated: use gtk_toggle_button_toggled() * * Since: 2.2 */ @@ -107,7 +103,7 @@ hildon_check_button_toggled (HildonCheckButton *button) { g_return_if_fail (HILDON_IS_CHECK_BUTTON (button)); - g_signal_emit (button, signals[TOGGLED], 0); + gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (button)); } /** @@ -115,9 +111,9 @@ hildon_check_button_toggled (HildonCheckButton *button) * @button: A #HildonCheckButton * @is_active: new state for the button * - * 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. + * Sets the status of a #HildonCheckButton. + * + * Deprecated: use gtk_toggle_button_set_active() * * Since: 2.2 **/ @@ -125,16 +121,9 @@ void hildon_check_button_set_active (HildonCheckButton *button, gboolean is_active) { - gboolean prev_is_active; - g_return_if_fail (HILDON_IS_CHECK_BUTTON (button)); - prev_is_active = hildon_check_button_get_active (button); - - if (prev_is_active != is_active) { - gtk_button_clicked (GTK_BUTTON (button)); - gtk_widget_queue_draw (GTK_WIDGET (button)); - } + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), is_active); } /** @@ -145,6 +134,8 @@ hildon_check_button_set_active (HildonCheckButton *button, * * Return value: %TRUE if @button is active, %FALSE otherwise. * + * Deprecated: use gtk_toggle_button_get_active() + * * Since: 2.2 **/ gboolean @@ -152,7 +143,7 @@ hildon_check_button_get_active (HildonCheckButton *button) { g_return_val_if_fail (HILDON_IS_CHECK_BUTTON (button), FALSE); - return gtk_cell_renderer_toggle_get_active (button->priv->toggle_renderer); + return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)); } /** @@ -175,11 +166,17 @@ static void hildon_check_button_clicked (GtkButton *button) { HildonCheckButton *checkbutton = HILDON_CHECK_BUTTON (button); - gboolean current = hildon_check_button_get_active (checkbutton); + GtkToggleButton *togglebutton = GTK_TOGGLE_BUTTON (button); - gtk_cell_renderer_toggle_set_active (checkbutton->priv->toggle_renderer, !current); + togglebutton->active = !togglebutton->active; + gtk_cell_renderer_toggle_set_active (checkbutton->priv->toggle_renderer, + togglebutton->active); - hildon_check_button_toggled (checkbutton); + gtk_toggle_button_toggled (togglebutton); + + gtk_widget_queue_draw (GTK_WIDGET (button)); + + g_object_notify (G_OBJECT (button), "active"); } static void @@ -226,28 +223,15 @@ hildon_check_button_class_init (HildonCheckButtonClass *klass) GObjectClass *gobject_class = (GObjectClass*) klass; GtkWidgetClass *widget_class = (GtkWidgetClass*) klass; GtkButtonClass *button_class = (GtkButtonClass*) klass; + GtkButtonClass *gtk_button_class = g_type_class_peek_parent (hildon_check_button_parent_class); gobject_class->set_property = set_property; 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. - * - * Since: 2.2 - */ - signals[TOGGLED] = - g_signal_new ("toggled", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCheckButtonClass, toggled), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); + button_class->pressed = gtk_button_class->pressed; + button_class->released = gtk_button_class->released; + button_class->enter = gtk_button_class->enter; + button_class->leave = gtk_button_class->leave; gtk_widget_class_install_style_property ( widget_class, diff --git a/hildon/hildon-check-button.h b/hildon/hildon-check-button.h index 6430f13..3597303 100644 --- a/hildon/hildon-check-button.h +++ b/hildon/hildon-check-button.h @@ -50,15 +50,12 @@ typedef struct _HildonCheckButtonPrivate Hildon struct _HildonCheckButtonClass { - GtkButtonClass parent_class; - - /* Signal handlers */ - void (* toggled) (HildonCheckButton *button); + GtkToggleButtonClass parent_class; }; struct _HildonCheckButton { - GtkButton parent; + GtkToggleButton parent; /* private */ HildonCheckButtonPrivate *priv; @@ -70,6 +67,7 @@ hildon_check_button_get_type (void) G_GNUC_CONST; GtkWidget * hildon_check_button_new (HildonSizeType size); +#ifndef HILDON_DISABLE_DEPRECATED void hildon_check_button_set_active (HildonCheckButton *button, gboolean is_active); @@ -79,6 +77,7 @@ hildon_check_button_get_active (HildonCheckButton *button); void hildon_check_button_toggled (HildonCheckButton *button); +#endif G_END_DECLS diff --git a/hildon/hildon-set-password-dialog.c b/hildon/hildon-set-password-dialog.c index e4c0ca3..57bcf42 100644 --- a/hildon/hildon-set-password-dialog.c +++ b/hildon/hildon-set-password-dialog.c @@ -252,8 +252,7 @@ create_contents (HildonSetPasswordDialog *dialog gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), priv->checkbox, TRUE, TRUE, 0); gtk_widget_show (priv->checkbox); - hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox), - TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox), TRUE); gtk_signal_connect (GTK_OBJECT (priv->checkbox), "toggled", G_CALLBACK (hildon_checkbox_toggled), dialog); @@ -429,7 +428,7 @@ hildon_set_password_response_change (GtkDialog *dialog, /* User accepted the dialog */ if (arg1 == GTK_RESPONSE_OK) { /* Is the checkbox marked, so password protection is still in use? */ - if (hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->checkbox))){ + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox))){ /* Yes, Something is given as password as well? */ if (text1[0] != '\0') { if (strcmp (text1, text2) == 0) { @@ -591,7 +590,7 @@ hildon_checkbox_toggled (GtkWidget *widget, /* If the user enabled/disabled the password protection feature we enable/disable password entries accordingly */ - active = hildon_check_button_get_active (HILDON_CHECK_BUTTON (widget)); + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); gtk_widget_set_sensitive (GTK_WIDGET (priv->pwd1st_entry), active); gtk_widget_set_sensitive (GTK_WIDGET (priv->pwd2nd_entry), active); }