mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-18 13:53:46 +00:00
libgimpwidgets: move all GimpChainButton members to a private struct
This commit is contained in:
parent
482be36a00
commit
fd45ea2051
|
@ -63,6 +63,25 @@ enum
|
|||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
|
||||
typedef struct _GimpChainButtonPrivate GimpChainButtonPrivate;
|
||||
|
||||
struct _GimpChainButtonPrivate
|
||||
{
|
||||
GimpChainPosition position;
|
||||
gboolean active;
|
||||
|
||||
GtkWidget *button;
|
||||
GtkWidget *line1;
|
||||
GtkWidget *line2;
|
||||
GtkWidget *image;
|
||||
};
|
||||
|
||||
#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE (obj, \
|
||||
GIMP_TYPE_CHAIN_BUTTON, \
|
||||
GimpChainButtonPrivate)
|
||||
|
||||
|
||||
static void gimp_chain_button_constructed (GObject *object);
|
||||
static void gimp_chain_button_set_property (GObject *object,
|
||||
guint property_id,
|
||||
|
@ -131,21 +150,25 @@ gimp_chain_button_class_init (GimpChainButtonClass *klass)
|
|||
GIMP_CHAIN_TOP,
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (GimpChainButtonPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_chain_button_init (GimpChainButton *button)
|
||||
{
|
||||
button->position = GIMP_CHAIN_TOP;
|
||||
button->active = FALSE;
|
||||
button->image = gtk_image_new ();
|
||||
button->button = gtk_button_new ();
|
||||
GimpChainButtonPrivate *private = GET_PRIVATE (button);
|
||||
|
||||
gtk_button_set_relief (GTK_BUTTON (button->button), GTK_RELIEF_NONE);
|
||||
gtk_container_add (GTK_CONTAINER (button->button), button->image);
|
||||
gtk_widget_show (button->image);
|
||||
private->position = GIMP_CHAIN_TOP;
|
||||
private->active = FALSE;
|
||||
private->image = gtk_image_new ();
|
||||
private->button = gtk_button_new ();
|
||||
|
||||
g_signal_connect (button->button, "clicked",
|
||||
gtk_button_set_relief (GTK_BUTTON (private->button), GTK_RELIEF_NONE);
|
||||
gtk_container_add (GTK_CONTAINER (private->button), private->image);
|
||||
gtk_widget_show (private->image);
|
||||
|
||||
g_signal_connect (private->button, "clicked",
|
||||
G_CALLBACK (gimp_chain_button_clicked_callback),
|
||||
button);
|
||||
}
|
||||
|
@ -153,39 +176,40 @@ gimp_chain_button_init (GimpChainButton *button)
|
|||
static void
|
||||
gimp_chain_button_constructed (GObject *object)
|
||||
{
|
||||
GimpChainButton *button = GIMP_CHAIN_BUTTON (object);
|
||||
GimpChainButton *button = GIMP_CHAIN_BUTTON (object);
|
||||
GimpChainButtonPrivate *private = GET_PRIVATE (button);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->constructed (object);
|
||||
|
||||
button->line1 = gimp_chain_line_new (button->position, 1);
|
||||
button->line2 = gimp_chain_line_new (button->position, -1);
|
||||
private->line1 = gimp_chain_line_new (private->position, 1);
|
||||
private->line2 = gimp_chain_line_new (private->position, -1);
|
||||
|
||||
gimp_chain_button_update_image (button);
|
||||
|
||||
if (button->position & GIMP_CHAIN_LEFT) /* are we a vertical chainbutton? */
|
||||
if (private->position & GIMP_CHAIN_LEFT) /* are we a vertical chainbutton? */
|
||||
{
|
||||
gtk_table_resize (GTK_TABLE (button), 3, 1);
|
||||
gtk_table_attach (GTK_TABLE (button), button->button, 0, 1, 1, 2,
|
||||
gtk_table_attach (GTK_TABLE (button), private->button, 0, 1, 1, 2,
|
||||
GTK_SHRINK, GTK_SHRINK, 0, 0);
|
||||
gtk_table_attach_defaults (GTK_TABLE (button),
|
||||
button->line1, 0, 1, 0, 1);
|
||||
private->line1, 0, 1, 0, 1);
|
||||
gtk_table_attach_defaults (GTK_TABLE (button),
|
||||
button->line2, 0, 1, 2, 3);
|
||||
private->line2, 0, 1, 2, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_table_resize (GTK_TABLE (button), 1, 3);
|
||||
gtk_table_attach (GTK_TABLE (button), button->button, 1, 2, 0, 1,
|
||||
gtk_table_attach (GTK_TABLE (button), private->button, 1, 2, 0, 1,
|
||||
GTK_SHRINK, GTK_SHRINK, 0, 0);
|
||||
gtk_table_attach_defaults (GTK_TABLE (button),
|
||||
button->line1, 0, 1, 0, 1);
|
||||
private->line1, 0, 1, 0, 1);
|
||||
gtk_table_attach_defaults (GTK_TABLE (button),
|
||||
button->line2, 2, 3, 0, 1);
|
||||
private->line2, 2, 3, 0, 1);
|
||||
}
|
||||
|
||||
gtk_widget_show (button->button);
|
||||
gtk_widget_show (button->line1);
|
||||
gtk_widget_show (button->line2);
|
||||
gtk_widget_show (private->button);
|
||||
gtk_widget_show (private->line1);
|
||||
gtk_widget_show (private->line2);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -194,12 +218,12 @@ gimp_chain_button_set_property (GObject *object,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpChainButton *button = GIMP_CHAIN_BUTTON (object);
|
||||
GimpChainButtonPrivate *private = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_POSITION:
|
||||
button->position = g_value_get_enum (value);
|
||||
private->position = g_value_get_enum (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -214,12 +238,12 @@ gimp_chain_button_get_property (GObject *object,
|
|||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpChainButton *button = GIMP_CHAIN_BUTTON (object);
|
||||
GimpChainButtonPrivate *private = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_POSITION:
|
||||
g_value_set_enum (value, button->position);
|
||||
g_value_set_enum (value, private->position);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -266,11 +290,15 @@ void
|
|||
gimp_chain_button_set_active (GimpChainButton *button,
|
||||
gboolean active)
|
||||
{
|
||||
GimpChainButtonPrivate *private;
|
||||
|
||||
g_return_if_fail (GIMP_IS_CHAIN_BUTTON (button));
|
||||
|
||||
if (button->active != active)
|
||||
private = GET_PRIVATE (button);
|
||||
|
||||
if (private->active != active)
|
||||
{
|
||||
button->active = active ? TRUE : FALSE;
|
||||
private->active = active ? TRUE : FALSE;
|
||||
|
||||
gimp_chain_button_update_image (button);
|
||||
}
|
||||
|
@ -287,18 +315,45 @@ gimp_chain_button_set_active (GimpChainButton *button,
|
|||
gboolean
|
||||
gimp_chain_button_get_active (GimpChainButton *button)
|
||||
{
|
||||
GimpChainButtonPrivate *private;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CHAIN_BUTTON (button), FALSE);
|
||||
|
||||
return button->active;
|
||||
private = GET_PRIVATE (button);
|
||||
|
||||
return private->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_chain_button_get_button
|
||||
* @button: A #GimpChainButton.
|
||||
*
|
||||
* Returns: The #GimpChainButton's button.
|
||||
*
|
||||
* Since: GIMP 3.0
|
||||
*/
|
||||
GtkWidget *
|
||||
gimp_chain_button_get_button (GimpChainButton *button)
|
||||
{
|
||||
GimpChainButtonPrivate *private;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CHAIN_BUTTON (button), FALSE);
|
||||
|
||||
private = GET_PRIVATE (button);
|
||||
|
||||
return private->button;
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
static void
|
||||
gimp_chain_button_clicked_callback (GtkWidget *widget,
|
||||
GimpChainButton *button)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_CHAIN_BUTTON (button));
|
||||
GimpChainButtonPrivate *private = GET_PRIVATE (button);
|
||||
|
||||
gimp_chain_button_set_active (button, ! button->active);
|
||||
gimp_chain_button_set_active (button, ! private->active);
|
||||
|
||||
g_signal_emit (button, gimp_chain_button_signals[TOGGLED], 0);
|
||||
}
|
||||
|
@ -306,11 +361,12 @@ gimp_chain_button_clicked_callback (GtkWidget *widget,
|
|||
static void
|
||||
gimp_chain_button_update_image (GimpChainButton *button)
|
||||
{
|
||||
guint i;
|
||||
GimpChainButtonPrivate *private = GET_PRIVATE (button);
|
||||
guint i;
|
||||
|
||||
i = ((button->position & GIMP_CHAIN_LEFT) << 1) + (button->active ? 0 : 1);
|
||||
i = ((private->position & GIMP_CHAIN_LEFT) << 1) + (private->active ? 0 : 1);
|
||||
|
||||
gtk_image_set_from_icon_name (GTK_IMAGE (button->image),
|
||||
gtk_image_set_from_icon_name (GTK_IMAGE (private->image),
|
||||
gimp_chain_icon_names[i],
|
||||
GTK_ICON_SIZE_BUTTON);
|
||||
}
|
||||
|
|
|
@ -45,19 +45,11 @@ G_BEGIN_DECLS
|
|||
#define GIMP_CHAIN_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CHAIN_BUTTON, GimpChainButtonClass))
|
||||
|
||||
|
||||
typedef struct _GimpChainButtonClass GimpChainButtonClass;
|
||||
typedef struct _GimpChainButtonClass GimpChainButtonClass;
|
||||
|
||||
struct _GimpChainButton
|
||||
{
|
||||
GtkTable parent_instance;
|
||||
|
||||
GimpChainPosition position;
|
||||
gboolean active;
|
||||
|
||||
GtkWidget *button;
|
||||
GtkWidget *line1;
|
||||
GtkWidget *line2;
|
||||
GtkWidget *image;
|
||||
GtkTable parent_instance;
|
||||
};
|
||||
|
||||
struct _GimpChainButtonClass
|
||||
|
@ -82,6 +74,8 @@ void gimp_chain_button_set_active (GimpChainButton *button,
|
|||
gboolean active);
|
||||
gboolean gimp_chain_button_get_active (GimpChainButton *button);
|
||||
|
||||
GtkWidget * gimp_chain_button_get_button (GimpChainButton *button);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -901,7 +901,7 @@ load_dialog (const gchar *filename,
|
|||
gtk_table_attach_defaults (GTK_TABLE (table2), constrain, 1, 2, 0, 2);
|
||||
gtk_widget_show (constrain);
|
||||
|
||||
gimp_help_set_help_data (GIMP_CHAIN_BUTTON (constrain)->button,
|
||||
gimp_help_set_help_data (gimp_chain_button_get_button (GIMP_CHAIN_BUTTON (constrain)),
|
||||
_("Constrain aspect ratio"), NULL);
|
||||
|
||||
gtk_widget_show (table2);
|
||||
|
|
|
@ -685,7 +685,7 @@ load_dialog (const gchar *filename)
|
|||
gtk_table_attach_defaults (GTK_TABLE (table2), constrain, 1, 2, 0, 2);
|
||||
gtk_widget_show (constrain);
|
||||
|
||||
gimp_help_set_help_data (GIMP_CHAIN_BUTTON (constrain)->button,
|
||||
gimp_help_set_help_data (gimp_chain_button_get_button (GIMP_CHAIN_BUTTON (constrain)),
|
||||
_("Constrain aspect ratio"), NULL);
|
||||
|
||||
gtk_widget_show (table2);
|
||||
|
|
Loading…
Reference in a new issue