forked from AuroraMiddleware/gtk
Remove priv pointer from GtkStackSwitcher
This is a new widget, so lets avoid the unnecessary priv pointer while we still can.
This commit is contained in:
parent
4b13b93394
commit
d137f74fe9
@ -41,6 +41,7 @@
|
|||||||
* The GtkStackSwitcher widget was added in 3.10.
|
* The GtkStackSwitcher widget was added in 3.10.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
typedef struct _GtkStackSwitcherPrivate GtkStackSwitcherPrivate;
|
||||||
struct _GtkStackSwitcherPrivate
|
struct _GtkStackSwitcherPrivate
|
||||||
{
|
{
|
||||||
GtkStack *stack;
|
GtkStack *stack;
|
||||||
@ -62,7 +63,6 @@ gtk_stack_switcher_init (GtkStackSwitcher *switcher)
|
|||||||
GtkStackSwitcherPrivate *priv;
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
priv = gtk_stack_switcher_get_instance_private (switcher);
|
priv = gtk_stack_switcher_get_instance_private (switcher);
|
||||||
switcher->priv = priv;
|
|
||||||
|
|
||||||
priv->stack = NULL;
|
priv->stack = NULL;
|
||||||
priv->buttons = g_hash_table_new (g_direct_hash, g_direct_equal);
|
priv->buttons = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||||
@ -84,11 +84,14 @@ on_button_clicked (GtkWidget *widget,
|
|||||||
GtkStackSwitcher *self)
|
GtkStackSwitcher *self)
|
||||||
{
|
{
|
||||||
GtkWidget *child;
|
GtkWidget *child;
|
||||||
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
if (!self->priv->in_child_changed)
|
priv = gtk_stack_switcher_get_instance_private (self);
|
||||||
|
|
||||||
|
if (!priv->in_child_changed)
|
||||||
{
|
{
|
||||||
child = g_object_get_data (G_OBJECT (widget), "stack-child");
|
child = g_object_get_data (G_OBJECT (widget), "stack-child");
|
||||||
gtk_stack_set_visible_child (self->priv->stack, child);
|
gtk_stack_set_visible_child (priv->stack, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,8 +145,11 @@ update_button (GtkStackSwitcher *self,
|
|||||||
{
|
{
|
||||||
gchar *title;
|
gchar *title;
|
||||||
gchar *icon_name;
|
gchar *icon_name;
|
||||||
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
gtk_container_child_get (GTK_CONTAINER (self->priv->stack), widget,
|
priv = gtk_stack_switcher_get_instance_private (self);
|
||||||
|
|
||||||
|
gtk_container_child_get (GTK_CONTAINER (priv->stack), widget,
|
||||||
"title", &title,
|
"title", &title,
|
||||||
"icon-name", &icon_name,
|
"icon-name", &icon_name,
|
||||||
NULL);
|
NULL);
|
||||||
@ -167,8 +173,11 @@ on_title_icon_updated (GtkWidget *widget,
|
|||||||
GtkStackSwitcher *self)
|
GtkStackSwitcher *self)
|
||||||
{
|
{
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
button = g_hash_table_lookup (self->priv->buttons, widget);
|
priv = gtk_stack_switcher_get_instance_private (self);
|
||||||
|
|
||||||
|
button = g_hash_table_lookup (priv->buttons, widget);
|
||||||
update_button (self, widget, button);
|
update_button (self, widget, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,10 +188,13 @@ on_position_updated (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
gint position;
|
gint position;
|
||||||
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
button = g_hash_table_lookup (self->priv->buttons, widget);
|
priv = gtk_stack_switcher_get_instance_private (self);
|
||||||
|
|
||||||
gtk_container_child_get (GTK_CONTAINER (self->priv->stack), widget,
|
button = g_hash_table_lookup (priv->buttons, widget);
|
||||||
|
|
||||||
|
gtk_container_child_get (GTK_CONTAINER (priv->stack), widget,
|
||||||
"position", &position,
|
"position", &position,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
@ -195,6 +207,9 @@ add_child (GtkStackSwitcher *self,
|
|||||||
{
|
{
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
GList *group;
|
GList *group;
|
||||||
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
|
priv = gtk_stack_switcher_get_instance_private (self);
|
||||||
|
|
||||||
button = gtk_radio_button_new (NULL);
|
button = gtk_radio_button_new (NULL);
|
||||||
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
|
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
|
||||||
@ -216,7 +231,7 @@ add_child (GtkStackSwitcher *self,
|
|||||||
g_signal_connect (widget, "child-notify::icon-name", G_CALLBACK (on_title_icon_updated), self);
|
g_signal_connect (widget, "child-notify::icon-name", G_CALLBACK (on_title_icon_updated), self);
|
||||||
g_signal_connect (widget, "child-notify::position", G_CALLBACK (on_position_updated), self);
|
g_signal_connect (widget, "child-notify::position", G_CALLBACK (on_position_updated), self);
|
||||||
|
|
||||||
g_hash_table_insert (self->priv->buttons, widget, button);
|
g_hash_table_insert (priv->buttons, widget, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -229,7 +244,10 @@ foreach_stack (GtkWidget *widget,
|
|||||||
static void
|
static void
|
||||||
populate_switcher (GtkStackSwitcher *self)
|
populate_switcher (GtkStackSwitcher *self)
|
||||||
{
|
{
|
||||||
gtk_container_foreach (GTK_CONTAINER (self->priv->stack), (GtkCallback)foreach_stack, self);
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
|
priv = gtk_stack_switcher_get_instance_private (self);
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (priv->stack), (GtkCallback)foreach_stack, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -239,14 +257,17 @@ on_child_changed (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkWidget *child;
|
GtkWidget *child;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
|
priv = gtk_stack_switcher_get_instance_private (self);
|
||||||
|
|
||||||
child = gtk_stack_get_visible_child (GTK_STACK (widget));
|
child = gtk_stack_get_visible_child (GTK_STACK (widget));
|
||||||
button = g_hash_table_lookup (self->priv->buttons, child);
|
button = g_hash_table_lookup (priv->buttons, child);
|
||||||
if (button != NULL)
|
if (button != NULL)
|
||||||
{
|
{
|
||||||
self->priv->in_child_changed = TRUE;
|
priv->in_child_changed = TRUE;
|
||||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
|
||||||
self->priv->in_child_changed = FALSE;
|
priv->in_child_changed = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,17 +285,20 @@ on_stack_child_removed (GtkContainer *container,
|
|||||||
GtkStackSwitcher *self)
|
GtkStackSwitcher *self)
|
||||||
{
|
{
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
button = g_hash_table_lookup (self->priv->buttons, widget);
|
priv = gtk_stack_switcher_get_instance_private (self);
|
||||||
|
button = g_hash_table_lookup (priv->buttons, widget);
|
||||||
gtk_container_remove (GTK_CONTAINER (self), button);
|
gtk_container_remove (GTK_CONTAINER (self), button);
|
||||||
g_hash_table_remove (self->priv->buttons, widget);
|
g_hash_table_remove (priv->buttons, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disconnect_stack_signals (GtkStackSwitcher *switcher)
|
disconnect_stack_signals (GtkStackSwitcher *switcher)
|
||||||
{
|
{
|
||||||
GtkStackSwitcherPrivate *priv = switcher->priv;
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
|
priv = gtk_stack_switcher_get_instance_private (switcher);
|
||||||
g_signal_handlers_disconnect_by_func (priv->stack, on_stack_child_added, switcher);
|
g_signal_handlers_disconnect_by_func (priv->stack, on_stack_child_added, switcher);
|
||||||
g_signal_handlers_disconnect_by_func (priv->stack, on_stack_child_removed, switcher);
|
g_signal_handlers_disconnect_by_func (priv->stack, on_stack_child_removed, switcher);
|
||||||
g_signal_handlers_disconnect_by_func (priv->stack, on_child_changed, switcher);
|
g_signal_handlers_disconnect_by_func (priv->stack, on_child_changed, switcher);
|
||||||
@ -284,8 +308,9 @@ disconnect_stack_signals (GtkStackSwitcher *switcher)
|
|||||||
static void
|
static void
|
||||||
connect_stack_signals (GtkStackSwitcher *switcher)
|
connect_stack_signals (GtkStackSwitcher *switcher)
|
||||||
{
|
{
|
||||||
GtkStackSwitcherPrivate *priv = switcher->priv;
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
|
priv = gtk_stack_switcher_get_instance_private (switcher);
|
||||||
g_signal_connect_after (priv->stack, "add",
|
g_signal_connect_after (priv->stack, "add",
|
||||||
G_CALLBACK (on_stack_child_added), switcher);
|
G_CALLBACK (on_stack_child_added), switcher);
|
||||||
g_signal_connect_after (priv->stack, "remove",
|
g_signal_connect_after (priv->stack, "remove",
|
||||||
@ -312,10 +337,9 @@ gtk_stack_switcher_set_stack (GtkStackSwitcher *switcher,
|
|||||||
GtkStackSwitcherPrivate *priv;
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
g_return_if_fail (GTK_IS_STACK_SWITCHER (switcher));
|
g_return_if_fail (GTK_IS_STACK_SWITCHER (switcher));
|
||||||
if (stack)
|
g_return_if_fail (GTK_IS_STACK (stack) || stack == NULL);
|
||||||
g_return_if_fail (GTK_IS_STACK (stack));
|
|
||||||
|
|
||||||
priv = switcher->priv;
|
priv = gtk_stack_switcher_get_instance_private (switcher);
|
||||||
|
|
||||||
if (priv->stack == stack)
|
if (priv->stack == stack)
|
||||||
return;
|
return;
|
||||||
@ -354,9 +378,11 @@ gtk_stack_switcher_set_stack (GtkStackSwitcher *switcher,
|
|||||||
GtkStack *
|
GtkStack *
|
||||||
gtk_stack_switcher_get_stack (GtkStackSwitcher *switcher)
|
gtk_stack_switcher_get_stack (GtkStackSwitcher *switcher)
|
||||||
{
|
{
|
||||||
|
GtkStackSwitcherPrivate *priv;
|
||||||
g_return_val_if_fail (GTK_IS_STACK_SWITCHER (switcher), NULL);
|
g_return_val_if_fail (GTK_IS_STACK_SWITCHER (switcher), NULL);
|
||||||
|
|
||||||
return switcher->priv->stack;
|
priv = gtk_stack_switcher_get_instance_private (switcher);
|
||||||
|
return priv->stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -366,8 +392,9 @@ gtk_stack_switcher_get_property (GObject *object,
|
|||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
GtkStackSwitcher *switcher = GTK_STACK_SWITCHER (object);
|
GtkStackSwitcher *switcher = GTK_STACK_SWITCHER (object);
|
||||||
GtkStackSwitcherPrivate *priv = switcher->priv;
|
GtkStackSwitcherPrivate *priv;
|
||||||
|
|
||||||
|
priv = gtk_stack_switcher_get_instance_private (switcher);
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_STACK:
|
case PROP_STACK:
|
||||||
|
@ -32,15 +32,11 @@ G_BEGIN_DECLS
|
|||||||
#define GTK_STACK_SWITCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_STACK_SWITCHER, GtkStackSwitcherClass))
|
#define GTK_STACK_SWITCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_STACK_SWITCHER, GtkStackSwitcherClass))
|
||||||
|
|
||||||
typedef struct _GtkStackSwitcher GtkStackSwitcher;
|
typedef struct _GtkStackSwitcher GtkStackSwitcher;
|
||||||
typedef struct _GtkStackSwitcherPrivate GtkStackSwitcherPrivate;
|
|
||||||
typedef struct _GtkStackSwitcherClass GtkStackSwitcherClass;
|
typedef struct _GtkStackSwitcherClass GtkStackSwitcherClass;
|
||||||
|
|
||||||
struct _GtkStackSwitcher
|
struct _GtkStackSwitcher
|
||||||
{
|
{
|
||||||
GtkBox widget;
|
GtkBox widget;
|
||||||
|
|
||||||
/*< private >*/
|
|
||||||
GtkStackSwitcherPrivate *priv;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GtkStackSwitcherClass
|
struct _GtkStackSwitcherClass
|
||||||
|
Loading…
Reference in New Issue
Block a user