mirror of https://github.com/GNOME/gimp.git
gimpthrobber: Get rid of g_type_class_add_private()
It's deprecated.
This commit is contained in:
parent
97b714d428
commit
5992a42231
|
@ -37,12 +37,9 @@ enum
|
||||||
PROP_ICON_NAME,
|
PROP_ICON_NAME,
|
||||||
PROP_IMAGE
|
PROP_IMAGE
|
||||||
};
|
};
|
||||||
|
static guint toolbutton_signals[LAST_SIGNAL] = { 0 };
|
||||||
|
|
||||||
|
|
||||||
static void gimp_throbber_class_init (GimpThrobberClass *klass);
|
|
||||||
|
|
||||||
static void gimp_throbber_init (GimpThrobber *button);
|
|
||||||
|
|
||||||
static void gimp_throbber_set_property (GObject *object,
|
static void gimp_throbber_set_property (GObject *object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
const GValue *value,
|
const GValue *value,
|
||||||
|
@ -61,12 +58,6 @@ static void gimp_throbber_button_clicked (GtkWidget *widget,
|
||||||
static void gimp_throbber_construct_contents (GtkToolItem *tool_item);
|
static void gimp_throbber_construct_contents (GtkToolItem *tool_item);
|
||||||
|
|
||||||
|
|
||||||
static GObjectClass *parent_class = NULL;
|
|
||||||
static guint toolbutton_signals[LAST_SIGNAL] = { 0 };
|
|
||||||
|
|
||||||
|
|
||||||
#define GIMP_THROBBER_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIMP_TYPE_THROBBER, GimpThrobberPrivate))
|
|
||||||
|
|
||||||
|
|
||||||
struct _GimpThrobberPrivate
|
struct _GimpThrobberPrivate
|
||||||
{
|
{
|
||||||
|
@ -75,34 +66,7 @@ struct _GimpThrobberPrivate
|
||||||
gchar *icon_name;
|
gchar *icon_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpThrobber, gimp_throbber, GTK_TYPE_TOOL_ITEM)
|
||||||
GType
|
|
||||||
gimp_throbber_get_type (void)
|
|
||||||
{
|
|
||||||
static GType type = 0;
|
|
||||||
|
|
||||||
if (!type)
|
|
||||||
{
|
|
||||||
static const GTypeInfo type_info =
|
|
||||||
{
|
|
||||||
sizeof (GimpThrobberClass),
|
|
||||||
(GBaseInitFunc) NULL,
|
|
||||||
(GBaseFinalizeFunc) NULL,
|
|
||||||
(GClassInitFunc) gimp_throbber_class_init,
|
|
||||||
(GClassFinalizeFunc) NULL,
|
|
||||||
NULL,
|
|
||||||
sizeof (GimpThrobber),
|
|
||||||
0, /* n_preallocs */
|
|
||||||
(GInstanceInitFunc) gimp_throbber_init,
|
|
||||||
};
|
|
||||||
|
|
||||||
type = g_type_register_static (GTK_TYPE_TOOL_ITEM,
|
|
||||||
"GimpThrobber",
|
|
||||||
&type_info, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_throbber_class_init (GimpThrobberClass *klass)
|
gimp_throbber_class_init (GimpThrobberClass *klass)
|
||||||
|
@ -110,8 +74,6 @@ gimp_throbber_class_init (GimpThrobberClass *klass)
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
GtkToolItemClass *tool_item_class = GTK_TOOL_ITEM_CLASS (klass);
|
GtkToolItemClass *tool_item_class = GTK_TOOL_ITEM_CLASS (klass);
|
||||||
|
|
||||||
parent_class = g_type_class_peek_parent (klass);
|
|
||||||
|
|
||||||
object_class->set_property = gimp_throbber_set_property;
|
object_class->set_property = gimp_throbber_set_property;
|
||||||
object_class->get_property = gimp_throbber_get_property;
|
object_class->get_property = gimp_throbber_get_property;
|
||||||
object_class->finalize = gimp_throbber_finalize;
|
object_class->finalize = gimp_throbber_finalize;
|
||||||
|
@ -139,72 +101,70 @@ gimp_throbber_class_init (GimpThrobberClass *klass)
|
||||||
G_STRUCT_OFFSET (GimpThrobberClass, clicked),
|
G_STRUCT_OFFSET (GimpThrobberClass, clicked),
|
||||||
NULL, NULL, NULL,
|
NULL, NULL, NULL,
|
||||||
G_TYPE_NONE, 0);
|
G_TYPE_NONE, 0);
|
||||||
|
|
||||||
g_type_class_add_private (object_class, sizeof (GimpThrobberPrivate));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_throbber_init (GimpThrobber *button)
|
gimp_throbber_init (GimpThrobber *button)
|
||||||
{
|
{
|
||||||
|
GimpThrobberPrivate *priv = gimp_throbber_get_instance_private (button);
|
||||||
GtkToolItem *toolitem = GTK_TOOL_ITEM (button);
|
GtkToolItem *toolitem = GTK_TOOL_ITEM (button);
|
||||||
|
|
||||||
button->priv = GIMP_THROBBER_GET_PRIVATE (button);
|
|
||||||
|
|
||||||
gtk_tool_item_set_homogeneous (toolitem, TRUE);
|
gtk_tool_item_set_homogeneous (toolitem, TRUE);
|
||||||
|
|
||||||
button->priv->button = g_object_new (GTK_TYPE_BUTTON,
|
priv->button = g_object_new (GTK_TYPE_BUTTON,
|
||||||
"yalign", 0.0,
|
"yalign", 0.0,
|
||||||
"focus-on-click", FALSE,
|
"focus-on-click", FALSE,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
g_signal_connect_object (button->priv->button, "clicked",
|
g_signal_connect_object (priv->button, "clicked",
|
||||||
G_CALLBACK (gimp_throbber_button_clicked),
|
G_CALLBACK (gimp_throbber_button_clicked),
|
||||||
button, 0);
|
button, 0);
|
||||||
|
|
||||||
gtk_container_add (GTK_CONTAINER (button), button->priv->button);
|
gtk_container_add (GTK_CONTAINER (button), priv->button);
|
||||||
gtk_widget_show (button->priv->button);
|
gtk_widget_show (priv->button);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_throbber_construct_contents (GtkToolItem *tool_item)
|
gimp_throbber_construct_contents (GtkToolItem *tool_item)
|
||||||
{
|
{
|
||||||
GimpThrobber *button = GIMP_THROBBER (tool_item);
|
GimpThrobber *button = GIMP_THROBBER (tool_item);
|
||||||
|
GimpThrobberPrivate *priv = gimp_throbber_get_instance_private (button);
|
||||||
GtkWidget *image;
|
GtkWidget *image;
|
||||||
GtkToolbarStyle style;
|
GtkToolbarStyle style;
|
||||||
|
|
||||||
if (button->priv->image && gtk_widget_get_parent (button->priv->image))
|
if (priv->image && gtk_widget_get_parent (priv->image))
|
||||||
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (button->priv->image)),
|
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (priv->image)),
|
||||||
button->priv->image);
|
priv->image);
|
||||||
|
|
||||||
if (gtk_bin_get_child (GTK_BIN (button->priv->button)))
|
if (gtk_bin_get_child (GTK_BIN (priv->button)))
|
||||||
gtk_widget_destroy (gtk_bin_get_child (GTK_BIN (button->priv->button)));
|
gtk_widget_destroy (gtk_bin_get_child (GTK_BIN (priv->button)));
|
||||||
|
|
||||||
style = gtk_tool_item_get_toolbar_style (tool_item);
|
style = gtk_tool_item_get_toolbar_style (tool_item);
|
||||||
|
|
||||||
if (style == GTK_TOOLBAR_TEXT)
|
if (style == GTK_TOOLBAR_TEXT)
|
||||||
{
|
{
|
||||||
image = gtk_image_new_from_icon_name (button->priv->icon_name,
|
image = gtk_image_new_from_icon_name (priv->icon_name,
|
||||||
GTK_ICON_SIZE_MENU);
|
GTK_ICON_SIZE_MENU);
|
||||||
}
|
}
|
||||||
else if (style == GTK_TOOLBAR_ICONS)
|
else if (style == GTK_TOOLBAR_ICONS)
|
||||||
{
|
{
|
||||||
image = gtk_image_new_from_icon_name (button->priv->icon_name,
|
image = gtk_image_new_from_icon_name (priv->icon_name,
|
||||||
GTK_ICON_SIZE_LARGE_TOOLBAR);
|
GTK_ICON_SIZE_LARGE_TOOLBAR);
|
||||||
}
|
}
|
||||||
else if (button->priv->image)
|
else if (priv->image)
|
||||||
{
|
{
|
||||||
image = button->priv->image;
|
image = priv->image;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
image = gtk_image_new_from_icon_name (button->priv->icon_name,
|
image = gtk_image_new_from_icon_name (priv->icon_name,
|
||||||
GTK_ICON_SIZE_DND);
|
GTK_ICON_SIZE_DND);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_container_add (GTK_CONTAINER (button->priv->button), image);
|
gtk_container_add (GTK_CONTAINER (priv->button), image);
|
||||||
gtk_widget_show (image);
|
gtk_widget_show (image);
|
||||||
|
|
||||||
gtk_button_set_relief (GTK_BUTTON (button->priv->button),
|
gtk_button_set_relief (GTK_BUTTON (priv->button),
|
||||||
gtk_tool_item_get_relief_style (tool_item));
|
gtk_tool_item_get_relief_style (tool_item));
|
||||||
|
|
||||||
gtk_widget_queue_resize (GTK_WIDGET (button));
|
gtk_widget_queue_resize (GTK_WIDGET (button));
|
||||||
|
@ -241,15 +201,16 @@ gimp_throbber_get_property (GObject *object,
|
||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
GimpThrobber *button = GIMP_THROBBER (object);
|
GimpThrobber *button = GIMP_THROBBER (object);
|
||||||
|
GimpThrobberPrivate *priv = gimp_throbber_get_instance_private (button);
|
||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_ICON_NAME:
|
case PROP_ICON_NAME:
|
||||||
g_value_set_string (value, button->priv->icon_name);
|
g_value_set_string (value, priv->icon_name);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_IMAGE:
|
case PROP_IMAGE:
|
||||||
g_value_set_object (value, button->priv->image);
|
g_value_set_object (value, priv->image);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -262,14 +223,12 @@ static void
|
||||||
gimp_throbber_finalize (GObject *object)
|
gimp_throbber_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
GimpThrobber *button = GIMP_THROBBER (object);
|
GimpThrobber *button = GIMP_THROBBER (object);
|
||||||
|
GimpThrobberPrivate *priv = gimp_throbber_get_instance_private (button);
|
||||||
|
|
||||||
if (button->priv->icon_name)
|
g_free (priv->icon_name);
|
||||||
g_free (button->priv->icon_name);
|
g_clear_object (&priv->image);
|
||||||
|
|
||||||
if (button->priv->image)
|
G_OBJECT_CLASS (gimp_throbber_parent_class)->finalize (object);
|
||||||
g_object_unref (button->priv->image);
|
|
||||||
|
|
||||||
parent_class->finalize (object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -305,13 +264,14 @@ void
|
||||||
gimp_throbber_set_icon_name (GimpThrobber *button,
|
gimp_throbber_set_icon_name (GimpThrobber *button,
|
||||||
const gchar *icon_name)
|
const gchar *icon_name)
|
||||||
{
|
{
|
||||||
|
GimpThrobberPrivate *priv = gimp_throbber_get_instance_private (button);
|
||||||
gchar *old_icon_name;
|
gchar *old_icon_name;
|
||||||
|
|
||||||
g_return_if_fail (GIMP_IS_THROBBER (button));
|
g_return_if_fail (GIMP_IS_THROBBER (button));
|
||||||
|
|
||||||
old_icon_name = button->priv->icon_name;
|
old_icon_name = priv->icon_name;
|
||||||
|
|
||||||
button->priv->icon_name = g_strdup (icon_name);
|
priv->icon_name = g_strdup (icon_name);
|
||||||
gimp_throbber_construct_contents (GTK_TOOL_ITEM (button));
|
gimp_throbber_construct_contents (GTK_TOOL_ITEM (button));
|
||||||
|
|
||||||
g_object_notify (G_OBJECT (button), "icon-name");
|
g_object_notify (G_OBJECT (button), "icon-name");
|
||||||
|
@ -322,33 +282,37 @@ gimp_throbber_set_icon_name (GimpThrobber *button,
|
||||||
const gchar *
|
const gchar *
|
||||||
gimp_throbber_get_icon_name (GimpThrobber *button)
|
gimp_throbber_get_icon_name (GimpThrobber *button)
|
||||||
{
|
{
|
||||||
|
GimpThrobberPrivate *priv = gimp_throbber_get_instance_private (button);
|
||||||
|
|
||||||
g_return_val_if_fail (GIMP_IS_THROBBER (button), NULL);
|
g_return_val_if_fail (GIMP_IS_THROBBER (button), NULL);
|
||||||
|
|
||||||
return button->priv->icon_name;
|
return priv->icon_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gimp_throbber_set_image (GimpThrobber *button,
|
gimp_throbber_set_image (GimpThrobber *button,
|
||||||
GtkWidget *image)
|
GtkWidget *image)
|
||||||
{
|
{
|
||||||
|
GimpThrobberPrivate *priv = gimp_throbber_get_instance_private (button);
|
||||||
|
|
||||||
g_return_if_fail (GIMP_IS_THROBBER (button));
|
g_return_if_fail (GIMP_IS_THROBBER (button));
|
||||||
g_return_if_fail (image == NULL || GTK_IS_IMAGE (image));
|
g_return_if_fail (image == NULL || GTK_IS_IMAGE (image));
|
||||||
|
|
||||||
if (image != button->priv->image)
|
if (image != priv->image)
|
||||||
{
|
{
|
||||||
if (button->priv->image)
|
if (priv->image)
|
||||||
{
|
{
|
||||||
if (gtk_widget_get_parent (button->priv->image))
|
if (gtk_widget_get_parent (priv->image))
|
||||||
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (button->priv->image)),
|
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (priv->image)),
|
||||||
button->priv->image);
|
priv->image);
|
||||||
|
|
||||||
g_object_unref (button->priv->image);
|
g_object_unref (priv->image);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image)
|
if (image)
|
||||||
g_object_ref_sink (image);
|
g_object_ref_sink (image);
|
||||||
|
|
||||||
button->priv->image = image;
|
priv->image = image;
|
||||||
|
|
||||||
gimp_throbber_construct_contents (GTK_TOOL_ITEM (button));
|
gimp_throbber_construct_contents (GTK_TOOL_ITEM (button));
|
||||||
|
|
||||||
|
@ -359,7 +323,9 @@ gimp_throbber_set_image (GimpThrobber *button,
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
gimp_throbber_get_image (GimpThrobber *button)
|
gimp_throbber_get_image (GimpThrobber *button)
|
||||||
{
|
{
|
||||||
|
GimpThrobberPrivate *priv = gimp_throbber_get_instance_private (button);
|
||||||
|
|
||||||
g_return_val_if_fail (GIMP_IS_THROBBER (button), NULL);
|
g_return_val_if_fail (GIMP_IS_THROBBER (button), NULL);
|
||||||
|
|
||||||
return button->priv->image;
|
return priv->image;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue