diff options
author | Emmanuele Bassi <ebassi@src.gnome.org> | 2007-06-10 15:32:02 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@src.gnome.org> | 2007-06-10 15:32:02 +0000 |
commit | 2c1866574317c8a85caacf6e1e581e275230a409 (patch) | |
tree | 3ee975f21863738b084ee4ebda84c3fa7424491b | |
parent | 7e43841f4da3bc7ff5bb1afb31edfabca2f83bca (diff) | |
download | gtk+-2c1866574317c8a85caacf6e1e581e275230a409.tar.gz |
Fix code style and warts in GtkScaleButton
This patch fixes the code style inconsistencies and some weird bits of
the GtkScaleButton widget implementation.
svn path=/trunk/; revision=18092
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | gtk/gtkscalebutton.c | 107 | ||||
-rw-r--r-- | gtk/gtkscalebutton.h | 11 |
3 files changed, 84 insertions, 48 deletions
@@ -1,3 +1,17 @@ +2007-06-10 Emmanuele Bassi <ebassi@gnome.org> + + * gtk/gtkscalebutton.[ch]: Fix some coding style bits. + + (gtk_scale_button_dispose), (gtk_scale_button_class_init), + (gtk_scale_button_init): Use the GObject private data API instead + of allocating the private structure ourselves. + + (gtk_scale_button_dispose), (gtk_scale_button_finalize): Free + the icons string vector inside ::finalize and not in ::dispose. + + (gtk_scale_button_update_icon): Use g_strv_length() instead + of an empty for loop. + 2007-06-09 Matthias Clasen <mclasen@redhat.com> * gtk/gtkwidget.c: diff --git a/gtk/gtkscalebutton.c b/gtk/gtkscalebutton.c index 7662fb62cd..78c912ac3d 100644 --- a/gtk/gtkscalebutton.c +++ b/gtk/gtkscalebutton.c @@ -62,35 +62,48 @@ #define SCALE_SIZE 100 #define CLICK_TIMEOUT 250 -enum { +enum +{ VALUE_CHANGED, POPUP, POPDOWN, + LAST_SIGNAL }; -enum { +enum +{ PROP_0, + PROP_VALUE, PROP_SIZE, PROP_ADJUSTMENT, PROP_ICONS }; -struct _GtkScaleButtonPrivate { - GtkWidget *dock, *scale, *image; +#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SCALE_BUTTON, GtkScaleButtonPrivate)) + +struct _GtkScaleButtonPrivate +{ + GtkWidget *dock; + GtkWidget *scale; + GtkWidget *image; + GtkIconSize size; + guint click_id; + gint click_timeout; + guint timeout : 1; gdouble direction; guint32 pop_time; + gchar **icon_list; - gint click_timeout; - guint timeout : 1; -} _GtkScaleButtonPrivate; +}; static void gtk_scale_button_class_init (GtkScaleButtonClass *klass); static void gtk_scale_button_init (GtkScaleButton *button); static void gtk_scale_button_dispose (GObject *object); +static void gtk_scale_button_finalize (GObject *object); static void gtk_scale_button_set_property (GObject *object, guint prop_id, const GValue *value, @@ -139,23 +152,24 @@ static GtkWidget *gtk_scale_button_scale_new (GtkScaleButton *button, gdouble max, gdouble step); -static GtkButtonClass *parent_class = NULL; -static guint signals[LAST_SIGNAL] = { 0 }; +static guint signals[LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE (GtkScaleButton, gtk_scale_button, GTK_TYPE_BUTTON) static void gtk_scale_button_class_init (GtkScaleButtonClass *klass) { - GtkBindingSet *binding_set; GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GtkBindingSet *binding_set; - parent_class = g_type_class_peek_parent (klass); + g_type_class_add_private (klass, sizeof (GtkScaleButtonPrivate)); + gobject_class->finalize = gtk_scale_button_finalize; gobject_class->dispose = gtk_scale_button_dispose; gobject_class->set_property = gtk_scale_button_set_property; gobject_class->get_property = gtk_scale_button_get_property; + widget_class->button_press_event = gtk_scale_button_press; widget_class->key_release_event = gtk_scale_button_key_release; widget_class->scroll_event = gtk_scale_button_scroll; @@ -233,6 +247,7 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass) NULL, NULL, _gtk_marshal_VOID__DOUBLE, G_TYPE_NONE, 1, G_TYPE_DOUBLE); + signals[POPUP] = _gtk_binding_signal_new (I_("popup"), G_OBJECT_CLASS_TYPE (klass), @@ -271,8 +286,7 @@ gtk_scale_button_init (GtkScaleButton *button) GtkWidget *frame, *box; GtkScaleButtonPrivate *priv; - button->priv = g_new0 (GtkScaleButtonPrivate, 1); - priv = button->priv; + button->priv = priv = GET_PRIVATE (button); priv->timeout = FALSE; priv->click_id = 0; @@ -409,37 +423,39 @@ gtk_scale_button_get_property (GObject *object, } static void -gtk_scale_button_dispose (GObject *object) +gtk_scale_button_finalize (GObject *object) { - GtkScaleButton *button; - GtkScaleButtonPrivate *priv; - - button = GTK_SCALE_BUTTON (object); + GtkScaleButton *button = GTK_SCALE_BUTTON (object); + GtkScaleButtonPrivate *priv = button->priv; + + if (priv->icon_list) + { + g_strfreev (priv->icon_list); + priv->icon_list = NULL; + } + + G_OBJECT_CLASS (gtk_scale_button_parent_class)->finalize (object); +} - priv = button->priv; +static void +gtk_scale_button_dispose (GObject *object) +{ + GtkScaleButton *button = GTK_SCALE_BUTTON (object); + GtkScaleButtonPrivate *priv = button->priv; - if (priv && priv->dock) + if (priv->dock) { gtk_widget_destroy (priv->dock); priv->dock = NULL; } - if (priv && priv->click_id != 0) + if (priv->click_id != 0) { g_source_remove (priv->click_id); priv->click_id = 0; } - if (priv && priv->icon_list) - { - g_strfreev (priv->icon_list); - priv->icon_list = NULL; - } - - g_free (priv); - button->priv = NULL; - - G_OBJECT_CLASS (parent_class)->dispose (object); + G_OBJECT_CLASS (gtk_scale_button_parent_class)->dispose (object); } /** @@ -742,7 +758,7 @@ gtk_scale_popup (GtkWidget *widget, gtk_window_move (GTK_WINDOW (priv->dock), x, y); if (event->type == GDK_BUTTON_PRESS) - GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, (GdkEventButton *) event); + GTK_WIDGET_CLASS (gtk_scale_button_parent_class)->button_press_event (widget, (GdkEventButton *) event); /* grab focus */ gtk_grab_add (priv->dock); @@ -912,8 +928,9 @@ cb_button_press (GtkWidget *widget, else priv->direction = - fabs (adj->page_increment); - priv->click_id = g_timeout_add (priv->click_timeout, - (GSourceFunc) cb_button_timeout, button); + priv->click_id = gdk_threads_add_timeout (priv->click_timeout, + cb_button_timeout, + button); cb_button_timeout (button); return TRUE; @@ -1086,8 +1103,6 @@ static gboolean gtk_scale_button_scale_press (GtkWidget *widget static gboolean gtk_scale_button_scale_release (GtkWidget *widget, GdkEventButton *event); -static GtkVScaleClass *scale_parent_class = NULL; - G_DEFINE_TYPE (GtkScaleButtonScale, gtk_scale_button_scale, GTK_TYPE_VSCALE) static void @@ -1096,8 +1111,6 @@ gtk_scale_button_scale_class_init (GtkScaleButtonScaleClass *klass) GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass); GtkRangeClass *gtkrange_class = GTK_RANGE_CLASS (klass); - scale_parent_class = g_type_class_peek_parent (klass); - gtkwidget_class->button_press_event = gtk_scale_button_scale_press; gtkwidget_class->button_release_event = gtk_scale_button_scale_release; gtkrange_class->value_changed = gtk_scale_button_scale_value_changed; @@ -1141,7 +1154,7 @@ gtk_scale_button_scale_press (GtkWidget *widget, * horribly wrong, so let's not do that. */ gtk_grab_remove (priv->dock); - return GTK_WIDGET_CLASS (scale_parent_class)->button_press_event (widget, event); + return GTK_WIDGET_CLASS (gtk_scale_button_scale_parent_class)->button_press_event (widget, event); } static gboolean @@ -1150,24 +1163,30 @@ gtk_scale_button_scale_release (GtkWidget *widget, { GtkScaleButtonScale *scale; GtkScaleButtonPrivate *priv; + GtkWidgetClass *widget_class; gboolean res; scale = GTK_SCALE_BUTTON_SCALE (widget); priv = scale->button->priv; + widget_class = GTK_WIDGET_CLASS (gtk_scale_button_scale_parent_class); + if (priv->timeout) { /* if we did a quick click, leave the window open; else, hide it */ if (event->time > priv->pop_time + priv->click_timeout) { + gtk_scale_button_release_grab (scale->button, event); - GTK_WIDGET_CLASS (scale_parent_class)->button_release_event (widget, event); + widget_class->button_release_event (widget, event); + return TRUE; } + priv->timeout = FALSE; } - res = GTK_WIDGET_CLASS (scale_parent_class)->button_release_event (widget, event); + res = widget_class->button_release_event (widget, event); /* the scale will release input; right after that, we *have to* grab * it back so we can catch out-of-scale clicks and hide the popup, @@ -1191,15 +1210,15 @@ gtk_scale_button_update_icon (GtkScaleButton *button) priv = button->priv; - if (priv->icon_list == NULL || priv->icon_list[0] == NULL) + if (!priv->icon_list || priv->icon_list[0] == '\0') { gtk_image_set_from_stock (GTK_IMAGE (priv->image), GTK_STOCK_MISSING_IMAGE, priv->size); return; } - - for (num_icons = 0; priv->icon_list[num_icons] != NULL; num_icons++) {} + + num_icons = g_strv_length (priv->icon_list); /* The 1-icon special case */ if (num_icons == 1) diff --git a/gtk/gtkscalebutton.h b/gtk/gtkscalebutton.h index ee41caf543..0644ace28d 100644 --- a/gtk/gtkscalebutton.h +++ b/gtk/gtkscalebutton.h @@ -67,9 +67,12 @@ struct _GtkScaleButtonClass struct _GtkScaleButton { - GtkButton parent; - GtkWidget *plus_button; - GtkWidget *minus_button; + GtkButton parent; + + GtkWidget *plus_button; + GtkWidget *minus_button; + + /*< private >*/ GtkScaleButtonPrivate *priv; }; @@ -80,7 +83,7 @@ GtkWidget* gtk_scale_button_new (GtkIconSize size, gdouble step, const gchar **icons); void gtk_scale_button_set_icons (GtkScaleButton *button, - const gchar **icons); + const gchar **icons); gdouble gtk_scale_button_get_value (GtkScaleButton *button); void gtk_scale_button_set_value (GtkScaleButton *button, gdouble value); |