From 5684ea57fada5d9a9f025f9acd5a5d2dbba55123 Mon Sep 17 00:00:00 2001 From: Claudio Saavedra Date: Mon, 24 Aug 2009 11:36:16 +0200 Subject: [PATCH] Revert "Make HildonCheckButton derive from GtkToggleButton" This change reverts 2911cf0dc0242c87a95d2577d54c898ce060873f --- ChangeLog | 12 +++++ examples/hildon-check-button-example.c | 6 +-- hildon/hildon-check-button.c | 80 +++++++++++++++++++------------- hildon/hildon-check-button.h | 9 ++-- hildon/hildon-set-password-dialog.c | 7 +-- 5 files changed, 72 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e862c1..5e27779 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-08-24 Claudio Saavedra + + * examples/hildon-check-button-example.c: (button_toggled_cb): + * hildon/hildon-check-button.c: (hildon_check_button_toggled), + (hildon_check_button_set_active), (hildon_check_button_new), + (hildon_check_button_clicked), (hildon_check_button_class_init): + * hildon/hildon-check-button.h: + * hildon/hildon-set-password-dialog.c: (create_contents), + (hildon_set_password_response_change), (hildon_checkbox_toggled): + + Revert "Make HildonCheckButton derive from GtkToggleButton" + 2009-08-21 Alberto Garcia [Release 2.1.96] diff --git a/examples/hildon-check-button-example.c b/examples/hildon-check-button-example.c index 4fe7cfd..fca96bf 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 (GtkToggleButton *button, - GtkLabel *label) +button_toggled_cb (HildonCheckButton *button, + GtkLabel *label) { - gboolean active = gtk_toggle_button_get_active (button); + gboolean active = hildon_check_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 93cfa25..bad22cc 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. * - * #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 + * 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(). * * @@ -42,11 +42,11 @@ * Using a Hildon check button * * void - * button_toggled (GtkToggleButton *button, gpointer user_data) + * button_toggled (HildonCheckButton *button, gpointer user_data) * { * gboolean active; * - * active = gtk_toggle_button_get_active (button); + * active = hildon_check_button_get_active (button); * if (active) * g_debug ("Button is active"); * else @@ -69,15 +69,20 @@ * */ -#undef HILDON_DISABLE_DEPRECATED - #include "hildon-check-button.h" enum { + TOGGLED, + LAST_SIGNAL +}; + +enum { PROP_SIZE = 1 }; -G_DEFINE_TYPE (HildonCheckButton, hildon_check_button, GTK_TYPE_TOGGLE_BUTTON); +static guint signals[LAST_SIGNAL] = { 0 }; + +G_DEFINE_TYPE (HildonCheckButton, hildon_check_button, GTK_TYPE_BUTTON); #define HILDON_CHECK_BUTTON_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ @@ -93,8 +98,7 @@ struct _HildonCheckButtonPrivate * @button: A #HildonCheckButton * * Emits the #HildonCheckButton::toggled signal on the #HildonCheckButton. - * - * Deprecated: use gtk_toggle_button_toggled() + * There is no good reason for an application ever to call this function. * * Since: 2.2 */ @@ -103,7 +107,7 @@ hildon_check_button_toggled (HildonCheckButton *button) { g_return_if_fail (HILDON_IS_CHECK_BUTTON (button)); - gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (button)); + g_signal_emit (button, signals[TOGGLED], 0); } /** @@ -111,9 +115,9 @@ hildon_check_button_toggled (HildonCheckButton *button) * @button: A #HildonCheckButton * @is_active: new state for the button * - * Sets the status of a #HildonCheckButton. - * - * Deprecated: use gtk_toggle_button_set_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 **/ @@ -121,9 +125,16 @@ void hildon_check_button_set_active (HildonCheckButton *button, gboolean is_active) { + gboolean prev_is_active; + g_return_if_fail (HILDON_IS_CHECK_BUTTON (button)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), is_active); + 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)); + } } /** @@ -134,8 +145,6 @@ 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 @@ -143,7 +152,7 @@ hildon_check_button_get_active (HildonCheckButton *button) { g_return_val_if_fail (HILDON_IS_CHECK_BUTTON (button), FALSE); - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)); + return gtk_cell_renderer_toggle_get_active (button->priv->toggle_renderer); } /** @@ -166,17 +175,11 @@ static void hildon_check_button_clicked (GtkButton *button) { HildonCheckButton *checkbutton = HILDON_CHECK_BUTTON (button); - GtkToggleButton *togglebutton = GTK_TOGGLE_BUTTON (button); + gboolean current = hildon_check_button_get_active (checkbutton); - togglebutton->active = !togglebutton->active; - gtk_cell_renderer_toggle_set_active (checkbutton->priv->toggle_renderer, - togglebutton->active); + gtk_cell_renderer_toggle_set_active (checkbutton->priv->toggle_renderer, !current); - gtk_toggle_button_toggled (togglebutton); - - gtk_widget_queue_draw (GTK_WIDGET (button)); - - g_object_notify (G_OBJECT (button), "active"); + hildon_check_button_toggled (checkbutton); } static void @@ -223,15 +226,28 @@ 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; - 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; + + 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); gtk_widget_class_install_style_property ( widget_class, diff --git a/hildon/hildon-check-button.h b/hildon/hildon-check-button.h index 3597303..6430f13 100644 --- a/hildon/hildon-check-button.h +++ b/hildon/hildon-check-button.h @@ -50,12 +50,15 @@ typedef struct _HildonCheckButtonPrivate Hildon struct _HildonCheckButtonClass { - GtkToggleButtonClass parent_class; + GtkButtonClass parent_class; + + /* Signal handlers */ + void (* toggled) (HildonCheckButton *button); }; struct _HildonCheckButton { - GtkToggleButton parent; + GtkButton parent; /* private */ HildonCheckButtonPrivate *priv; @@ -67,7 +70,6 @@ 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); @@ -77,7 +79,6 @@ 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 57bcf42..e4c0ca3 100644 --- a/hildon/hildon-set-password-dialog.c +++ b/hildon/hildon-set-password-dialog.c @@ -252,7 +252,8 @@ create_contents (HildonSetPasswordDialog *dialog gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), priv->checkbox, TRUE, TRUE, 0); gtk_widget_show (priv->checkbox); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox), TRUE); + hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox), + TRUE); gtk_signal_connect (GTK_OBJECT (priv->checkbox), "toggled", G_CALLBACK (hildon_checkbox_toggled), dialog); @@ -428,7 +429,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 (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox))){ + if (hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->checkbox))){ /* Yes, Something is given as password as well? */ if (text1[0] != '\0') { if (strcmp (text1, text2) == 0) { @@ -590,7 +591,7 @@ hildon_checkbox_toggled (GtkWidget *widget, /* If the user enabled/disabled the password protection feature we enable/disable password entries accordingly */ - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); + active = hildon_check_button_get_active (HILDON_CHECK_BUTTON (widget)); gtk_widget_set_sensitive (GTK_WIDGET (priv->pwd1st_entry), active); gtk_widget_set_sensitive (GTK_WIDGET (priv->pwd2nd_entry), active); } -- 1.7.9.5