Commit 2c186657 authored by Emmanuele Bassi's avatar Emmanuele Bassi

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
parent 7e43841f
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:
......
......@@ -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)
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment