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
This commit is contained in:
14
ChangeLog
14
ChangeLog
@ -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>
|
2007-06-09 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkwidget.c:
|
* gtk/gtkwidget.c:
|
||||||
|
@ -62,35 +62,48 @@
|
|||||||
#define SCALE_SIZE 100
|
#define SCALE_SIZE 100
|
||||||
#define CLICK_TIMEOUT 250
|
#define CLICK_TIMEOUT 250
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
VALUE_CHANGED,
|
VALUE_CHANGED,
|
||||||
POPUP,
|
POPUP,
|
||||||
POPDOWN,
|
POPDOWN,
|
||||||
|
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
|
|
||||||
PROP_VALUE,
|
PROP_VALUE,
|
||||||
PROP_SIZE,
|
PROP_SIZE,
|
||||||
PROP_ADJUSTMENT,
|
PROP_ADJUSTMENT,
|
||||||
PROP_ICONS
|
PROP_ICONS
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GtkScaleButtonPrivate {
|
#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SCALE_BUTTON, GtkScaleButtonPrivate))
|
||||||
GtkWidget *dock, *scale, *image;
|
|
||||||
|
struct _GtkScaleButtonPrivate
|
||||||
|
{
|
||||||
|
GtkWidget *dock;
|
||||||
|
GtkWidget *scale;
|
||||||
|
GtkWidget *image;
|
||||||
|
|
||||||
GtkIconSize size;
|
GtkIconSize size;
|
||||||
|
|
||||||
guint click_id;
|
guint click_id;
|
||||||
gdouble direction;
|
|
||||||
guint32 pop_time;
|
|
||||||
gchar **icon_list;
|
|
||||||
gint click_timeout;
|
gint click_timeout;
|
||||||
guint timeout : 1;
|
guint timeout : 1;
|
||||||
} _GtkScaleButtonPrivate;
|
gdouble direction;
|
||||||
|
guint32 pop_time;
|
||||||
|
|
||||||
|
gchar **icon_list;
|
||||||
|
};
|
||||||
|
|
||||||
static void gtk_scale_button_class_init (GtkScaleButtonClass *klass);
|
static void gtk_scale_button_class_init (GtkScaleButtonClass *klass);
|
||||||
static void gtk_scale_button_init (GtkScaleButton *button);
|
static void gtk_scale_button_init (GtkScaleButton *button);
|
||||||
static void gtk_scale_button_dispose (GObject *object);
|
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,
|
static void gtk_scale_button_set_property (GObject *object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
const GValue *value,
|
const GValue *value,
|
||||||
@ -139,23 +152,24 @@ static GtkWidget *gtk_scale_button_scale_new (GtkScaleButton *button,
|
|||||||
gdouble max,
|
gdouble max,
|
||||||
gdouble step);
|
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)
|
G_DEFINE_TYPE (GtkScaleButton, gtk_scale_button, GTK_TYPE_BUTTON)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_scale_button_class_init (GtkScaleButtonClass *klass)
|
gtk_scale_button_class_init (GtkScaleButtonClass *klass)
|
||||||
{
|
{
|
||||||
GtkBindingSet *binding_set;
|
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
GtkWidgetClass *widget_class = GTK_WIDGET_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->dispose = gtk_scale_button_dispose;
|
||||||
gobject_class->set_property = gtk_scale_button_set_property;
|
gobject_class->set_property = gtk_scale_button_set_property;
|
||||||
gobject_class->get_property = gtk_scale_button_get_property;
|
gobject_class->get_property = gtk_scale_button_get_property;
|
||||||
|
|
||||||
widget_class->button_press_event = gtk_scale_button_press;
|
widget_class->button_press_event = gtk_scale_button_press;
|
||||||
widget_class->key_release_event = gtk_scale_button_key_release;
|
widget_class->key_release_event = gtk_scale_button_key_release;
|
||||||
widget_class->scroll_event = gtk_scale_button_scroll;
|
widget_class->scroll_event = gtk_scale_button_scroll;
|
||||||
@ -233,6 +247,7 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass)
|
|||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
_gtk_marshal_VOID__DOUBLE,
|
_gtk_marshal_VOID__DOUBLE,
|
||||||
G_TYPE_NONE, 1, G_TYPE_DOUBLE);
|
G_TYPE_NONE, 1, G_TYPE_DOUBLE);
|
||||||
|
|
||||||
signals[POPUP] =
|
signals[POPUP] =
|
||||||
_gtk_binding_signal_new (I_("popup"),
|
_gtk_binding_signal_new (I_("popup"),
|
||||||
G_OBJECT_CLASS_TYPE (klass),
|
G_OBJECT_CLASS_TYPE (klass),
|
||||||
@ -271,8 +286,7 @@ gtk_scale_button_init (GtkScaleButton *button)
|
|||||||
GtkWidget *frame, *box;
|
GtkWidget *frame, *box;
|
||||||
GtkScaleButtonPrivate *priv;
|
GtkScaleButtonPrivate *priv;
|
||||||
|
|
||||||
button->priv = g_new0 (GtkScaleButtonPrivate, 1);
|
button->priv = priv = GET_PRIVATE (button);
|
||||||
priv = button->priv;
|
|
||||||
|
|
||||||
priv->timeout = FALSE;
|
priv->timeout = FALSE;
|
||||||
priv->click_id = 0;
|
priv->click_id = 0;
|
||||||
@ -408,38 +422,40 @@ gtk_scale_button_get_property (GObject *object,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_scale_button_finalize (GObject *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);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_scale_button_dispose (GObject *object)
|
gtk_scale_button_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
GtkScaleButton *button;
|
GtkScaleButton *button = GTK_SCALE_BUTTON (object);
|
||||||
GtkScaleButtonPrivate *priv;
|
GtkScaleButtonPrivate *priv = button->priv;
|
||||||
|
|
||||||
button = GTK_SCALE_BUTTON (object);
|
if (priv->dock)
|
||||||
|
|
||||||
priv = button->priv;
|
|
||||||
|
|
||||||
if (priv && priv->dock)
|
|
||||||
{
|
{
|
||||||
gtk_widget_destroy (priv->dock);
|
gtk_widget_destroy (priv->dock);
|
||||||
priv->dock = NULL;
|
priv->dock = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv && priv->click_id != 0)
|
if (priv->click_id != 0)
|
||||||
{
|
{
|
||||||
g_source_remove (priv->click_id);
|
g_source_remove (priv->click_id);
|
||||||
priv->click_id = 0;
|
priv->click_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv && priv->icon_list)
|
G_OBJECT_CLASS (gtk_scale_button_parent_class)->dispose (object);
|
||||||
{
|
|
||||||
g_strfreev (priv->icon_list);
|
|
||||||
priv->icon_list = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (priv);
|
|
||||||
button->priv = NULL;
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -742,7 +758,7 @@ gtk_scale_popup (GtkWidget *widget,
|
|||||||
gtk_window_move (GTK_WINDOW (priv->dock), x, y);
|
gtk_window_move (GTK_WINDOW (priv->dock), x, y);
|
||||||
|
|
||||||
if (event->type == GDK_BUTTON_PRESS)
|
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 */
|
/* grab focus */
|
||||||
gtk_grab_add (priv->dock);
|
gtk_grab_add (priv->dock);
|
||||||
@ -912,8 +928,9 @@ cb_button_press (GtkWidget *widget,
|
|||||||
else
|
else
|
||||||
priv->direction = - fabs (adj->page_increment);
|
priv->direction = - fabs (adj->page_increment);
|
||||||
|
|
||||||
priv->click_id = g_timeout_add (priv->click_timeout,
|
priv->click_id = gdk_threads_add_timeout (priv->click_timeout,
|
||||||
(GSourceFunc) cb_button_timeout, button);
|
cb_button_timeout,
|
||||||
|
button);
|
||||||
cb_button_timeout (button);
|
cb_button_timeout (button);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -1086,8 +1103,6 @@ static gboolean gtk_scale_button_scale_press (GtkWidget *widget
|
|||||||
static gboolean gtk_scale_button_scale_release (GtkWidget *widget,
|
static gboolean gtk_scale_button_scale_release (GtkWidget *widget,
|
||||||
GdkEventButton *event);
|
GdkEventButton *event);
|
||||||
|
|
||||||
static GtkVScaleClass *scale_parent_class = NULL;
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GtkScaleButtonScale, gtk_scale_button_scale, GTK_TYPE_VSCALE)
|
G_DEFINE_TYPE (GtkScaleButtonScale, gtk_scale_button_scale, GTK_TYPE_VSCALE)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1096,8 +1111,6 @@ gtk_scale_button_scale_class_init (GtkScaleButtonScaleClass *klass)
|
|||||||
GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass);
|
GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass);
|
||||||
GtkRangeClass *gtkrange_class = GTK_RANGE_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_press_event = gtk_scale_button_scale_press;
|
||||||
gtkwidget_class->button_release_event = gtk_scale_button_scale_release;
|
gtkwidget_class->button_release_event = gtk_scale_button_scale_release;
|
||||||
gtkrange_class->value_changed = gtk_scale_button_scale_value_changed;
|
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. */
|
* horribly wrong, so let's not do that. */
|
||||||
gtk_grab_remove (priv->dock);
|
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
|
static gboolean
|
||||||
@ -1150,24 +1163,30 @@ gtk_scale_button_scale_release (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkScaleButtonScale *scale;
|
GtkScaleButtonScale *scale;
|
||||||
GtkScaleButtonPrivate *priv;
|
GtkScaleButtonPrivate *priv;
|
||||||
|
GtkWidgetClass *widget_class;
|
||||||
gboolean res;
|
gboolean res;
|
||||||
|
|
||||||
scale = GTK_SCALE_BUTTON_SCALE (widget);
|
scale = GTK_SCALE_BUTTON_SCALE (widget);
|
||||||
priv = scale->button->priv;
|
priv = scale->button->priv;
|
||||||
|
|
||||||
|
widget_class = GTK_WIDGET_CLASS (gtk_scale_button_scale_parent_class);
|
||||||
|
|
||||||
if (priv->timeout)
|
if (priv->timeout)
|
||||||
{
|
{
|
||||||
/* if we did a quick click, leave the window open; else, hide it */
|
/* if we did a quick click, leave the window open; else, hide it */
|
||||||
if (event->time > priv->pop_time + priv->click_timeout)
|
if (event->time > priv->pop_time + priv->click_timeout)
|
||||||
{
|
{
|
||||||
|
|
||||||
gtk_scale_button_release_grab (scale->button, event);
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->timeout = FALSE;
|
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
|
/* 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,
|
* 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;
|
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_image_set_from_stock (GTK_IMAGE (priv->image),
|
||||||
GTK_STOCK_MISSING_IMAGE,
|
GTK_STOCK_MISSING_IMAGE,
|
||||||
priv->size);
|
priv->size);
|
||||||
return;
|
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 */
|
/* The 1-icon special case */
|
||||||
if (num_icons == 1)
|
if (num_icons == 1)
|
||||||
|
@ -67,9 +67,12 @@ struct _GtkScaleButtonClass
|
|||||||
|
|
||||||
struct _GtkScaleButton
|
struct _GtkScaleButton
|
||||||
{
|
{
|
||||||
GtkButton parent;
|
GtkButton parent;
|
||||||
GtkWidget *plus_button;
|
|
||||||
GtkWidget *minus_button;
|
GtkWidget *plus_button;
|
||||||
|
GtkWidget *minus_button;
|
||||||
|
|
||||||
|
/*< private >*/
|
||||||
GtkScaleButtonPrivate *priv;
|
GtkScaleButtonPrivate *priv;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,7 +83,7 @@ GtkWidget* gtk_scale_button_new (GtkIconSize size,
|
|||||||
gdouble step,
|
gdouble step,
|
||||||
const gchar **icons);
|
const gchar **icons);
|
||||||
void gtk_scale_button_set_icons (GtkScaleButton *button,
|
void gtk_scale_button_set_icons (GtkScaleButton *button,
|
||||||
const gchar **icons);
|
const gchar **icons);
|
||||||
gdouble gtk_scale_button_get_value (GtkScaleButton *button);
|
gdouble gtk_scale_button_get_value (GtkScaleButton *button);
|
||||||
void gtk_scale_button_set_value (GtkScaleButton *button,
|
void gtk_scale_button_set_value (GtkScaleButton *button,
|
||||||
gdouble value);
|
gdouble value);
|
||||||
|
Reference in New Issue
Block a user