override GObjectClass->constructor() and do the setup stuff there, not in

2002-05-28  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpcontext.c: override GObjectClass->constructor() and
	do the setup stuff there, not in gimp_context_new(). This way we
	can create properly initialized contexts with g_object_new().

	* app/widgets/gimpdeviceinfo.c: Removed the "gimp" property
	again. Added a constructor() implementation and moved stuff there
	from gimp_device_info_set_property(PROP_GIMP).

	* app/config/gimpconfig-deserialize.c: made deserialization of
	value arrays work by actually using the array any not just leaking
	it ;)

	* app/core/gimpcontainer.c: removed debugging output. Call
	config_iface->deserialize(child, ...) again instead of calling
	gimp_config_deserialize_properties() directly.

	* app/widgets/gimpdevices.c: switch to using the new stuff for
	devicerc.

	* app/widgets/gimpdeviceinfo.[ch]
	* app/widgets/gimpdevices.[ch]
	* app/gimprc.c: removed all old gimprc-style devicerc stuff.

	* app/gui/menus.c
	* app/gui/test-commands.[ch]: removed devicerc testing entries
	and callbacks.
This commit is contained in:
Michael Natterer 2002-05-28 16:41:56 +00:00 committed by Michael Natterer
parent da3cce37a3
commit b7e3c716c4
14 changed files with 240 additions and 969 deletions

View file

@ -1,3 +1,32 @@
2002-05-28 Michael Natterer <mitch@gimp.org>
* app/core/gimpcontext.c: override GObjectClass->constructor() and
do the setup stuff there, not in gimp_context_new(). This way we
can create properly initialized contexts with g_object_new().
* app/widgets/gimpdeviceinfo.c: Removed the "gimp" property
again. Added a constructor() implementation and moved stuff there
from gimp_device_info_set_property(PROP_GIMP).
* app/config/gimpconfig-deserialize.c: made deserialization of
value arrays work by actually using the array any not just leaking
it ;)
* app/core/gimpcontainer.c: removed debugging output. Call
config_iface->deserialize(child, ...) again instead of calling
gimp_config_deserialize_properties() directly.
* app/widgets/gimpdevices.c: switch to using the new stuff for
devicerc.
* app/widgets/gimpdeviceinfo.[ch]
* app/widgets/gimpdevices.[ch]
* app/gimprc.c: removed all old gimprc-style devicerc stuff.
* app/gui/menus.c
* app/gui/test-commands.[ch]: removed devicerc testing entries
and callbacks.
2002-05-28 Sven Neumann <sven@gimp.org>
* autogen.sh: simplified by using a function for version checks.
@ -27,12 +56,6 @@
* app/config/gimpconfig.c (gimp_config_serialize): fixed error code
and improved error messages.
2002-05-27 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimpsizeentry.c (gimp_size_entry_attach_label):
set the spinbutton which is attached right of the label as
mnemonic_widget for the label.
2002-05-27 Maurits Rijk <lpeek.mrijk@consunet.nl>
* libgimpwidgets/gimpwidgets.c (gimp_random_seed_new):
@ -49,6 +72,12 @@
gimp_drawable_has_alpha iso seperate check on GIMP_INDEXEDA_IMAGE |
GIMP_GRAYA_IMAGE | GIMP_RGBA_IMAGE
2002-05-27 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimpsizeentry.c (gimp_size_entry_attach_label):
set the spinbutton which is attached right of the label as
mnemonic_widget for the label.
2002-05-27 Michael Natterer <mitch@gimp.org>
* app/config/gimpconfig.[ch]: added "gint nest_level" to the

View file

@ -661,6 +661,8 @@ gimp_config_deserialize_value_array (GValue *value,
return token;
}
g_value_set_boxed_take_ownership (value, array);
return G_TOKEN_RIGHT_PAREN;
}

View file

@ -536,14 +536,8 @@ gimp_container_deserialize (GObject *object,
child = gimp_container_get_child_by_name (container, name);
if (child)
if (! child)
{
g_print ("found child \"%s\"\n", name);
}
else
{
g_print ("creating child \"%s\"\n", name);
if (GIMP_IS_GIMP (data))
{
child = g_object_new (type,
@ -552,8 +546,8 @@ gimp_container_deserialize (GObject *object,
}
else
{
child = g_object_new (type,
"name", name, NULL);
child = g_object_new (type,
"name", name, NULL);
}
gimp_container_add (container, child);
@ -563,15 +557,14 @@ gimp_container_deserialize (GObject *object,
}
{
#if 0
GimpConfigInterface *config_iface;
config_iface = GIMP_GET_CONFIG_INTERFACE (child);
#endif
if (! gimp_config_deserialize_properties (G_OBJECT (child),
scanner,
nest_level + 1,
FALSE))
if (! config_iface->deserialize (G_OBJECT (child),
scanner,
nest_level + 1,
FALSE))
{
/* warning should be already set by child */
return FALSE;

View file

@ -70,18 +70,20 @@ static void gimp_context_class_init (GimpContextClass *klass);
static void gimp_context_init (GimpContext *context);
static void gimp_context_config_iface_init (GimpConfigInterface *config_iface);
static void gimp_context_dispose (GObject *object);
static void gimp_context_finalize (GObject *object);
static void gimp_context_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_context_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gsize gimp_context_get_memsize (GimpObject *object);
static GObject * gimp_context_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_context_dispose (GObject *object);
static void gimp_context_finalize (GObject *object);
static void gimp_context_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_context_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gsize gimp_context_get_memsize (GimpObject *object);
static gboolean gimp_context_serialize_property (GObject *object,
guint property_id,
@ -544,6 +546,7 @@ gimp_context_class_init (GimpContextClass *klass)
G_TYPE_NONE, 1,
GIMP_TYPE_IMAGEFILE);
object_class->constructor = gimp_context_constructor;
object_class->set_property = gimp_context_set_property;
object_class->get_property = gimp_context_get_property;
object_class->dispose = gimp_context_dispose;
@ -683,6 +686,95 @@ gimp_context_config_iface_init (GimpConfigInterface *config_iface)
config_iface->deserialize_property = gimp_context_deserialize_property;
}
static GObject *
gimp_context_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
Gimp *gimp;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
gimp = GIMP_CONTEXT (object)->gimp;
g_assert (GIMP_IS_GIMP (gimp));
g_signal_connect_object (G_OBJECT (gimp->images), "remove",
G_CALLBACK (gimp_context_image_removed),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->displays), "remove",
G_CALLBACK (gimp_context_display_removed),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->tool_info_list), "remove",
G_CALLBACK (gimp_context_tool_removed),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->tool_info_list), "thaw",
G_CALLBACK (gimp_context_tool_list_thaw),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->brush_factory->container), "remove",
G_CALLBACK (gimp_context_brush_removed),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->brush_factory->container), "thaw",
G_CALLBACK (gimp_context_brush_list_thaw),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->pattern_factory->container), "remove",
G_CALLBACK (gimp_context_pattern_removed),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->pattern_factory->container), "thaw",
G_CALLBACK (gimp_context_pattern_list_thaw),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->gradient_factory->container), "remove",
G_CALLBACK (gimp_context_gradient_removed),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->gradient_factory->container), "thaw",
G_CALLBACK (gimp_context_gradient_list_thaw),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->palette_factory->container), "remove",
G_CALLBACK (gimp_context_palette_removed),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->palette_factory->container), "thaw",
G_CALLBACK (gimp_context_palette_list_thaw),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->named_buffers), "remove",
G_CALLBACK (gimp_context_buffer_removed),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->named_buffers), "thaw",
G_CALLBACK (gimp_context_buffer_list_thaw),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->documents), "remove",
G_CALLBACK (gimp_context_imagefile_removed),
object,
0);
g_signal_connect_object (G_OBJECT (gimp->documents), "thaw",
G_CALLBACK (gimp_context_imagefile_list_thaw),
object,
0);
return object;
}
static void
gimp_context_dispose (GObject *object)
{
@ -1091,78 +1183,6 @@ gimp_context_new (Gimp *gimp,
"gimp", gimp,
NULL);
g_signal_connect_object (G_OBJECT (gimp->images), "remove",
G_CALLBACK (gimp_context_image_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->displays), "remove",
G_CALLBACK (gimp_context_display_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->tool_info_list), "remove",
G_CALLBACK (gimp_context_tool_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->tool_info_list), "thaw",
G_CALLBACK (gimp_context_tool_list_thaw),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->brush_factory->container), "remove",
G_CALLBACK (gimp_context_brush_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->brush_factory->container), "thaw",
G_CALLBACK (gimp_context_brush_list_thaw),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->pattern_factory->container), "remove",
G_CALLBACK (gimp_context_pattern_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->pattern_factory->container), "thaw",
G_CALLBACK (gimp_context_pattern_list_thaw),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->gradient_factory->container), "remove",
G_CALLBACK (gimp_context_gradient_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->gradient_factory->container), "thaw",
G_CALLBACK (gimp_context_gradient_list_thaw),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->palette_factory->container), "remove",
G_CALLBACK (gimp_context_palette_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->palette_factory->container), "thaw",
G_CALLBACK (gimp_context_palette_list_thaw),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->named_buffers), "remove",
G_CALLBACK (gimp_context_buffer_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->named_buffers), "thaw",
G_CALLBACK (gimp_context_buffer_list_thaw),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->documents), "remove",
G_CALLBACK (gimp_context_imagefile_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->documents), "thaw",
G_CALLBACK (gimp_context_imagefile_list_thaw),
G_OBJECT (context),
0);
if (template)
{
context->defined_props = template->defined_props;

View file

@ -44,7 +44,6 @@
#include "core/gimpcoreconfig.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpdevices.h"
#include "widgets/gimpdialogfactory.h"
/*#include "tools/gimptool.h"*/
@ -83,7 +82,6 @@ typedef enum
TT_INTERP,
TT_XPREVSIZE,
TT_XUNIT,
TT_XDEVICE,
TT_XSESSIONINFO,
TT_XCOLORHISTORY,
TT_XNAVPREVSIZE,
@ -131,7 +129,6 @@ static gint parse_preview_size (gpointer val1p, gpointer val2p)
static gint parse_nav_preview_size (gpointer val1p, gpointer val2p);
static gint parse_thumbnail_size (gpointer val1p, gpointer val2p);
static gint parse_units (gpointer val1p, gpointer val2p);
static gint parse_device (gpointer val1p, gpointer val2p);
static gint parse_session_info (gpointer val1p, gpointer val2p);
static gint parse_help_browser (gpointer val1p, gpointer val2p);
static gint parse_cursor_mode (gpointer val1p, gpointer val2p);
@ -276,7 +273,6 @@ static ParseFunc funcs[] =
{ "theme-path", TT_PATH, &gimprc.theme_path, NULL },
{ "theme", TT_STRING, &gimprc.theme, NULL },
{ "device", TT_XDEVICE, NULL, NULL },
{ "session-info", TT_XSESSIONINFO, NULL, NULL },
{ "color-history", TT_XCOLORHISTORY, NULL, NULL }
};
@ -893,8 +889,6 @@ parse_statement (void)
return parse_thumbnail_size (func->val1p, func->val2p);
case TT_XUNIT:
return parse_units (func->val1p, func->val2p);
case TT_XDEVICE:
return parse_device (func->val1p, func->val2p);
case TT_XSESSIONINFO:
return parse_session_info (func->val1p, func->val2p);
case TT_XCOLORHISTORY:
@ -1644,270 +1638,6 @@ transform_path (gchar *path,
return new_path;
}
/* Copied from gtk_menu_factory_parse_accelerator() */
static void
parse_device_accelerator (const gchar *accelerator,
GdkDeviceKey *key)
{
gboolean done = FALSE;
g_return_if_fail (accelerator != NULL);
g_return_if_fail (key != NULL);
key->modifiers = 0;
while (!done)
{
if (strncmp (accelerator, "<shift>", 7) == 0)
{
accelerator += 7;
key->modifiers |= GDK_SHIFT_MASK;
}
else if (strncmp (accelerator, "<alt>", 5) == 0)
{
accelerator += 5;
key->modifiers |= GDK_MOD1_MASK;
}
else if (strncmp (accelerator, "<control>", 9) == 0)
{
accelerator += 9;
key->modifiers |= GDK_CONTROL_MASK;
}
else
{
done = TRUE;
/* Tricky, but works... ("" => keyval = 0, or no translation) */
key->keyval = accelerator[0];
}
}
}
static gint
parse_device (gpointer val1p,
gpointer val2p)
{
GimpDeviceValues values = 0;
gint i;
gint token;
/* The initialized values here are meaningless */
gchar *name = NULL;
GdkInputMode mode = GDK_MODE_DISABLED;
gint num_axes = 0;
GdkAxisUse *axes = NULL;
gint num_keys = 0;
GdkDeviceKey *keys = NULL;
gchar *tool_name = NULL;
GimpRGB foreground = { 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE };
GimpRGB background = { 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE };
gchar *brush_name = NULL;
gchar *pattern_name = NULL;
gchar *gradient_name = NULL;
token = peek_next_token ();
if (!token || (token != TOKEN_STRING))
goto error;
token = get_next_token ();
name = g_strdup (token_str);
/* Parse options for device */
while (peek_next_token () == TOKEN_LEFT_PAREN)
{
token = get_next_token ();
token = peek_next_token ();
if (!token || (token != TOKEN_SYMBOL))
goto error;
token = get_next_token ();
if (!strcmp ("mode", token_sym))
{
values |= GIMP_DEVICE_VALUE_MODE;
token = peek_next_token ();
if (!token || (token != TOKEN_SYMBOL))
goto error;
token = get_next_token ();
if (!strcmp ("disabled", token_sym))
mode = GDK_MODE_DISABLED;
else if (!strcmp ("window", token_sym))
mode = GDK_MODE_WINDOW;
else if (!strcmp ("screen", token_sym))
mode = GDK_MODE_SCREEN;
else
goto error;
}
else if (!strcmp ("axes", token_sym))
{
values |= GIMP_DEVICE_VALUE_AXES;
token = peek_next_token ();
if (!token || (token != TOKEN_NUMBER))
goto error;
token = get_next_token ();
num_axes = token_int;
axes = g_new (GdkAxisUse, num_axes);
for (i = 0; i < num_axes; i++)
{
token = peek_next_token ();
if (!token || (token != TOKEN_SYMBOL))
goto error;
token = get_next_token ();
if (!strcmp ("ignore", token_sym))
axes[i] = GDK_AXIS_IGNORE;
else if (!strcmp ("x", token_sym))
axes[i] = GDK_AXIS_X;
else if (!strcmp ("y", token_sym))
axes[i] = GDK_AXIS_Y;
else if (!strcmp ("pressure", token_sym))
axes[i] = GDK_AXIS_PRESSURE;
else if (!strcmp ("xtilt", token_sym))
axes[i] = GDK_AXIS_XTILT;
else if (!strcmp ("ytilt", token_sym))
axes[i] = GDK_AXIS_YTILT;
else if (!strcmp ("wheel", token_sym))
axes[i] = GDK_AXIS_WHEEL;
else
goto error;
}
}
else if (!strcmp ("keys", token_sym))
{
values |= GIMP_DEVICE_VALUE_KEYS;
token = peek_next_token ();
if (!token || (token != TOKEN_NUMBER))
goto error;
token = get_next_token ();
num_keys = token_int;
keys = g_new (GdkDeviceKey, num_keys);
for (i=0; i<num_keys; i++)
{
token = peek_next_token ();
if (!token || (token != TOKEN_STRING))
goto error;
token = get_next_token ();
parse_device_accelerator (token_str, &keys[i]);
}
}
else if (!strcmp ("tool", token_sym))
{
values |= GIMP_DEVICE_VALUE_TOOL;
token = peek_next_token ();
if (!token || (token != TOKEN_STRING))
goto error;
token = get_next_token ();
tool_name = g_strdup (token_str);
}
else if (!strcmp ("foreground", token_sym))
{
values |= GIMP_DEVICE_VALUE_FOREGROUND;
if (parse_color (&foreground) == ERROR)
goto error;
foreground.a = GIMP_OPACITY_OPAQUE;
}
else if (!strcmp ("background", token_sym))
{
values |= GIMP_DEVICE_VALUE_BACKGROUND;
if (parse_color (&background) == ERROR)
goto error;
background.a = GIMP_OPACITY_OPAQUE;
}
else if (!strcmp ("brush", token_sym))
{
values |= GIMP_DEVICE_VALUE_BRUSH;
token = peek_next_token ();
if (!token || (token != TOKEN_STRING))
goto error;
token = get_next_token ();
brush_name = g_strdup (token_str);
}
else if (!strcmp ("pattern", token_sym))
{
values |= GIMP_DEVICE_VALUE_PATTERN;
token = peek_next_token ();
if (!token || (token != TOKEN_STRING))
goto error;
token = get_next_token ();
pattern_name = g_strdup (token_str);
}
else if (!strcmp ("gradient", token_sym))
{
values |= GIMP_DEVICE_VALUE_GRADIENT;
token = peek_next_token ();
if (!token || (token != TOKEN_STRING))
goto error;
token = get_next_token ();
gradient_name = g_strdup (token_str);
}
else
goto error;
token = peek_next_token ();
if (!token || (token != TOKEN_RIGHT_PAREN))
goto error;
token = get_next_token ();
}
if (!token || (token != TOKEN_RIGHT_PAREN))
goto error;
token = get_next_token ();
gimp_devices_rc_update (the_gimp,
name,
values,
mode,
num_axes, axes,
num_keys, keys,
tool_name,
&foreground, &background,
brush_name,
pattern_name,
gradient_name);
g_free (tool_name);
g_free (brush_name);
g_free (pattern_name);
g_free (gradient_name);
g_free (name);
g_free (axes);
g_free (keys);
return OK;
error:
g_free (brush_name);
g_free (pattern_name);
g_free (gradient_name);
g_free (name);
g_free (axes);
g_free (keys);
return ERROR;
}
static gint
parse_session_info (gpointer val1p,
gpointer val2p)
@ -2248,7 +1978,6 @@ gimprc_value_to_str (const gchar *name)
return cursor_mode_to_str (func->val1p, func->val2p);
case TT_XCOMMENT:
return comment_to_str (func->val1p, func->val2p);
case TT_XDEVICE:
case TT_XSESSIONINFO:
case TT_XCOLORHISTORY:
return NULL;

View file

@ -240,12 +240,6 @@ static GimpItemFactoryEntry toolbox_entries[] =
{ { "/File/Debug/Deserialize User Context", NULL,
test_deserialize_context_cmd_callback, 0 },
NULL, NULL, NULL },
{ { "/File/Debug/Serialize test-devicerc", NULL,
test_serialize_devicerc_cmd_callback, 0 },
NULL, NULL, NULL },
{ { "/File/Debug/Deserialize test-devicerc", NULL,
test_deserialize_devicerc_cmd_callback, 0 },
NULL, NULL, NULL },
#endif
SEPARATOR ("/File/---"),

View file

@ -340,25 +340,3 @@ test_deserialize_context_cmd_callback (GtkWidget *widget,
g_free (filename);
}
void
test_serialize_devicerc_cmd_callback (GtkWidget *widget,
gpointer data)
{
Gimp *gimp;
gimp = GIMP (data);
gimp_devices_save_test (gimp);
}
void
test_deserialize_devicerc_cmd_callback (GtkWidget *widget,
gpointer data)
{
Gimp *gimp;
gimp = GIMP (data);
gimp_devices_restore_test (gimp);
}

View file

@ -29,10 +29,6 @@ void test_serialize_context_cmd_callback (GtkWidget *widget,
gpointer data);
void test_deserialize_context_cmd_callback (GtkWidget *widget,
gpointer data);
void test_serialize_devicerc_cmd_callback (GtkWidget *widget,
gpointer data);
void test_deserialize_devicerc_cmd_callback (GtkWidget *widget,
gpointer data);
#endif /* __TEST_COMMANDS_H__ */

View file

@ -240,12 +240,6 @@ static GimpItemFactoryEntry toolbox_entries[] =
{ { "/File/Debug/Deserialize User Context", NULL,
test_deserialize_context_cmd_callback, 0 },
NULL, NULL, NULL },
{ { "/File/Debug/Serialize test-devicerc", NULL,
test_serialize_devicerc_cmd_callback, 0 },
NULL, NULL, NULL },
{ { "/File/Debug/Deserialize test-devicerc", NULL,
test_deserialize_devicerc_cmd_callback, 0 },
NULL, NULL, NULL },
#endif
SEPARATOR ("/File/---"),

View file

@ -46,7 +46,6 @@ enum
enum
{
PROP_0,
PROP_GIMP,
PROP_MODE,
PROP_AXES,
PROP_KEYS
@ -58,15 +57,18 @@ enum
static void gimp_device_info_class_init (GimpDeviceInfoClass *klass);
static void gimp_device_info_init (GimpDeviceInfo *device_info);
static void gimp_device_info_finalize (GObject *object);
static void gimp_device_info_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_device_info_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static GObject * gimp_device_info_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_device_info_finalize (GObject *object);
static void gimp_device_info_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_device_info_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static GimpContextClass *parent_class = NULL;
@ -121,17 +123,11 @@ gimp_device_info_class_init (GimpDeviceInfoClass *klass)
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->constructor = gimp_device_info_constructor;
object_class->finalize = gimp_device_info_finalize;
object_class->set_property = gimp_device_info_set_property;
object_class->get_property = gimp_device_info_get_property;
g_object_class_install_property (object_class, PROP_GIMP,
g_param_spec_object ("gimp",
NULL, NULL,
GIMP_TYPE_GIMP,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_MODE, "mode",
GDK_TYPE_INPUT_MODE,
GDK_MODE_DISABLED);
@ -169,6 +165,52 @@ gimp_device_info_init (GimpDeviceInfo *device_info)
device_info->keys = NULL;
}
static GObject *
gimp_device_info_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
Gimp *gimp;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
gimp = GIMP_CONTEXT (object)->gimp;
g_assert (GIMP_IS_GIMP (gimp));
gimp_context_define_properties (GIMP_CONTEXT (object),
GIMP_DEVICE_INFO_CONTEXT_MASK,
FALSE);
gimp_context_copy_properties (gimp_get_user_context (gimp),
GIMP_CONTEXT (object),
GIMP_DEVICE_INFO_CONTEXT_MASK);
/* FIXME: this is ugly and needs to be done via "notify" once
* the contexts' properties are dynamic.
*/
g_signal_connect (object, "foreground_changed",
G_CALLBACK (gimp_device_info_changed),
NULL);
g_signal_connect (object, "background_changed",
G_CALLBACK (gimp_device_info_changed),
NULL);
g_signal_connect (object, "tool_changed",
G_CALLBACK (gimp_device_info_changed),
NULL);
g_signal_connect (object, "brush_changed",
G_CALLBACK (gimp_device_info_changed),
NULL);
g_signal_connect (object, "pattern_changed",
G_CALLBACK (gimp_device_info_changed),
NULL);
g_signal_connect (object, "gradient_changed",
G_CALLBACK (gimp_device_info_changed),
NULL);
return object;
}
static void
gimp_device_info_finalize (GObject *object)
{
@ -200,51 +242,6 @@ gimp_device_info_set_property (GObject *object,
switch (property_id)
{
case PROP_GIMP:
{
GimpContext *context;
Gimp *gimp;
context = GIMP_CONTEXT (device_info);
gimp = g_value_get_object (value);
/* we override GimpContext's "gimp" property, so we need to
* register the context just like GimpContext would do it.
*/
context->gimp = gimp;
gimp->context_list = g_list_prepend (gimp->context_list, context);
gimp_context_define_properties (context,
GIMP_DEVICE_INFO_CONTEXT_MASK,
FALSE);
gimp_context_copy_properties (gimp_get_user_context (gimp),
context,
GIMP_DEVICE_INFO_CONTEXT_MASK);
/* FIXME: this is ugly and needs to be done via "notify" once
* the contexts' properties are dynamic.
*/
g_signal_connect_swapped (G_OBJECT (context), "foreground_changed",
G_CALLBACK (gimp_device_info_changed),
device_info);
g_signal_connect_swapped (G_OBJECT (context), "background_changed",
G_CALLBACK (gimp_device_info_changed),
device_info);
g_signal_connect_swapped (G_OBJECT (context), "tool_changed",
G_CALLBACK (gimp_device_info_changed),
device_info);
g_signal_connect_swapped (G_OBJECT (context), "brush_changed",
G_CALLBACK (gimp_device_info_changed),
device_info);
g_signal_connect_swapped (G_OBJECT (context), "pattern_changed",
G_CALLBACK (gimp_device_info_changed),
device_info);
g_signal_connect_swapped (G_OBJECT (context), "gradient_changed",
G_CALLBACK (gimp_device_info_changed),
device_info);
}
break;
case PROP_MODE:
if (device_info->device)
gdk_device_set_mode (device_info->device, g_value_get_enum (value));
@ -358,10 +355,6 @@ gimp_device_info_get_property (GObject *object,
switch (property_id)
{
case PROP_GIMP:
g_value_set_object (value, GIMP_CONTEXT (device_info)->gimp);
break;
case PROP_MODE:
if (device)
g_value_set_enum (value, device->mode);
@ -490,162 +483,6 @@ gimp_device_info_set_from_device (GimpDeviceInfo *device_info,
return device_info;
}
GimpDeviceInfo *
gimp_device_info_set_from_rc (GimpDeviceInfo *device_info,
GimpDeviceValues values,
GdkInputMode mode,
gint num_axes,
const GdkAxisUse *axes,
gint num_keys,
const GdkDeviceKey *keys,
const gchar *tool_name,
const GimpRGB *foreground,
const GimpRGB *background,
const gchar *brush_name,
const gchar *pattern_name,
const gchar *gradient_name)
{
GimpContext *context;
g_return_val_if_fail (GIMP_IS_DEVICE_INFO (device_info), NULL);
context = GIMP_CONTEXT (device_info);
if (values & GIMP_DEVICE_VALUE_MODE)
{
device_info->mode = mode;
if (device_info->device)
{
gdk_device_set_mode (device_info->device, mode);
}
}
if (values & GIMP_DEVICE_VALUE_AXES)
{
device_info->num_axes = num_axes;
device_info->axes = g_new (GdkAxisUse, num_axes);
memcpy (device_info->axes, axes, num_axes * sizeof (GdkAxisUse));
if (device_info->device && (num_axes >= device_info->device->num_axes))
{
gint i;
for (i = 0; i < MIN (num_axes, device_info->device->num_axes); i++)
{
gdk_device_set_axis_use (device_info->device, i, axes[i]);
}
}
}
if (values & GIMP_DEVICE_VALUE_KEYS)
{
device_info->num_keys = num_keys;
device_info->keys = g_new (GdkDeviceKey, num_keys);
memcpy (device_info->keys, axes, num_keys * sizeof (GdkDeviceKey));
if (device_info->device && (num_keys >= device_info->device->num_keys))
{
gint i;
for (i = 0; i < MIN (num_keys, device_info->device->num_keys); i++)
{
gdk_device_set_key (device_info->device, i,
keys[i].keyval,
keys[i].modifiers);
}
}
}
if (values & GIMP_DEVICE_VALUE_TOOL)
{
GimpToolInfo *tool_info;
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (context->gimp->tool_info_list,
tool_name);
if (tool_info)
{
gimp_context_set_tool (context, tool_info);
}
else
{
g_free (context->tool_name);
context->tool_name = g_strdup (tool_name);
}
}
if (values & GIMP_DEVICE_VALUE_FOREGROUND)
{
gimp_context_set_foreground (context, foreground);
}
if (values & GIMP_DEVICE_VALUE_BACKGROUND)
{
gimp_context_set_background (context, background);
}
if (values & GIMP_DEVICE_VALUE_BRUSH)
{
GimpBrush *brush;
brush = (GimpBrush *)
gimp_container_get_child_by_name (context->gimp->brush_factory->container,
brush_name);
if (brush)
{
gimp_context_set_brush (context, brush);
}
else if (context->gimp->no_data)
{
g_free (context->brush_name);
context->brush_name = g_strdup (brush_name);
}
}
if (values & GIMP_DEVICE_VALUE_PATTERN)
{
GimpPattern *pattern;
pattern = (GimpPattern *)
gimp_container_get_child_by_name (context->gimp->pattern_factory->container,
pattern_name);
if (pattern)
{
gimp_context_set_pattern (context, pattern);
}
else if (context->gimp->no_data)
{
g_free (context->pattern_name);
context->pattern_name = g_strdup (pattern_name);
}
}
if (values & GIMP_DEVICE_VALUE_GRADIENT)
{
GimpGradient *gradient;
gradient = (GimpGradient *)
gimp_container_get_child_by_name (context->gimp->gradient_factory->container,
gradient_name);
if (gradient)
{
gimp_context_set_gradient (context, gradient);
}
else if (context->gimp->no_data)
{
g_free (context->gradient_name);
context->gradient_name = g_strdup (gradient_name);
}
}
return device_info;
}
void
gimp_device_info_changed (GimpDeviceInfo *device_info)
{
@ -654,161 +491,6 @@ gimp_device_info_changed (GimpDeviceInfo *device_info)
g_signal_emit (G_OBJECT (device_info), device_info_signals[CHANGED], 0);
}
void
gimp_device_info_save (GimpDeviceInfo *device_info,
FILE *fp)
{
GimpContext *context;
GdkDevice *device;
gchar *mode = NULL;
gint i;
g_return_if_fail (GIMP_IS_DEVICE_INFO (device_info));
g_return_if_fail (fp != NULL);
context = GIMP_CONTEXT (device_info);
device = device_info->device;
fprintf (fp, "(device \"%s\"", GIMP_OBJECT (device_info)->name);
switch (device ? device->mode : device_info->mode)
{
case GDK_MODE_DISABLED:
mode = "disabled";
break;
case GDK_MODE_SCREEN:
mode = "screen";
break;
case GDK_MODE_WINDOW:
mode = "window";
break;
}
fprintf (fp, "\n (mode %s)", mode);
fprintf (fp, "\n (axes %d",
device ? device->num_axes : device_info->num_axes);
for (i = 0; i < (device ? device->num_axes : device_info->num_axes); i++)
{
gchar *axis_type = NULL;
switch (device ? device->axes[i].use : device_info->axes[i])
{
case GDK_AXIS_IGNORE:
axis_type = "ignore";
break;
case GDK_AXIS_X:
axis_type = "x";
break;
case GDK_AXIS_Y:
axis_type = "y";
break;
case GDK_AXIS_PRESSURE:
axis_type = "pressure";
break;
case GDK_AXIS_XTILT:
axis_type = "xtilt";
break;
case GDK_AXIS_YTILT:
axis_type = "ytilt";
break;
case GDK_AXIS_WHEEL:
axis_type = "wheel";
break;
}
fprintf (fp, " %s",axis_type);
}
fprintf (fp,")");
fprintf (fp, "\n (keys %d",
device ? device->num_keys : device_info->num_keys);
for (i = 0; i < (device ? device->num_keys : device_info->num_keys); i++)
{
GdkModifierType modifiers = (device ? device->keys[i].modifiers :
device_info->keys[i].modifiers);
guint keyval = (device ? device->keys[i].keyval :
device_info->keys[i].keyval);
if (keyval)
{
/* FIXME: integrate this back with menus_install_accelerator */
gchar accel[64];
gchar t2[2];
accel[0] = '\0';
if (modifiers & GDK_CONTROL_MASK)
strcat (accel, "<control>");
if (modifiers & GDK_SHIFT_MASK)
strcat (accel, "<shift>");
if (modifiers & GDK_MOD1_MASK)
strcat (accel, "<alt>");
t2[0] = keyval;
t2[1] = '\0';
strcat (accel, t2);
fprintf (fp, " \"%s\"",accel);
}
else
{
fprintf (fp, " \"\"");
}
}
fprintf (fp,")");
if (gimp_context_get_tool (context))
{
fprintf (fp, "\n (tool \"%s\")",
GIMP_OBJECT (gimp_context_get_tool (context))->name);
}
{
GimpRGB color;
gchar buf[3][G_ASCII_DTOSTR_BUF_SIZE];
gimp_context_get_foreground (context, &color);
g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", color.r);
g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", color.g);
g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", color.b);
fprintf (fp, "\n (foreground (color-rgb %s %s %s))",
buf[0], buf[1], buf[2]);
gimp_context_get_background (context, &color);
g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", color.r);
g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", color.g);
g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", color.b);
fprintf (fp, "\n (background (color-rgb %s %s %s))",
buf[0], buf[1], buf[2]);
}
if (gimp_context_get_brush (context))
{
fprintf (fp, "\n (brush \"%s\")",
GIMP_OBJECT (gimp_context_get_brush (context))->name);
}
if (gimp_context_get_pattern (context))
{
fprintf (fp, "\n (pattern \"%s\")",
GIMP_OBJECT (gimp_context_get_pattern (context))->name);
}
if (gimp_context_get_gradient (context))
{
fprintf (fp, "\n (gradient \"%s\")",
GIMP_OBJECT (gimp_context_get_gradient (context))->name);
}
fprintf(fp,")\n");
}
GimpDeviceInfo *
gimp_device_info_get_by_device (GdkDevice *device)
{

View file

@ -69,33 +69,17 @@ struct _GimpDeviceInfoClass
};
GType gimp_device_info_get_type (void) G_GNUC_CONST;
GType gimp_device_info_get_type (void) G_GNUC_CONST;
GimpDeviceInfo * gimp_device_info_new (Gimp *gimp,
const gchar *name);
GimpDeviceInfo * gimp_device_info_new (Gimp *gimp,
const gchar *name);
GimpDeviceInfo * gimp_device_info_set_from_device (GimpDeviceInfo *device_info,
GdkDevice *device);
GimpDeviceInfo * gimp_device_info_set_from_rc (GimpDeviceInfo *device_info,
GimpDeviceValues values,
GdkInputMode mode,
gint num_axes,
const GdkAxisUse *axes,
gint num_keys,
const GdkDeviceKey *keys,
const gchar *tool_name,
const GimpRGB *foreground,
const GimpRGB *background,
const gchar *brush_name,
const gchar *pattern_name,
const gchar *gradient_name);
GimpDeviceInfo * gimp_device_info_set_from_device (GimpDeviceInfo *device_info,
GdkDevice *device);
void gimp_device_info_changed (GimpDeviceInfo *device_info);
void gimp_device_info_changed (GimpDeviceInfo *device_info);
void gimp_device_info_save (GimpDeviceInfo *device_info,
FILE *fp);
GimpDeviceInfo * gimp_device_info_get_by_device (GdkDevice *device);
void gimp_device_info_changed_by_device (GdkDevice *device);
GimpDeviceInfo * gimp_device_info_get_by_device (GdkDevice *device);
void gimp_device_info_changed_by_device (GdkDevice *device);
G_END_DECLS

View file

@ -42,8 +42,6 @@
#include "gimpdeviceinfo.h"
#include "gimpdevices.h"
#include "gimprc.h"
#define GIMP_DEVICE_MANAGER_DATA_KEY "gimp-device-manager"
@ -94,6 +92,8 @@ gimp_devices_init (Gimp *gimp,
{
device = (GdkDevice *) list->data;
g_print ("############# adding %s\n", device->name);
device_info = gimp_device_info_new (gimp, device->name);
gimp_container_add (manager->device_info_list, GIMP_OBJECT (device_info));
g_object_unref (G_OBJECT (device_info));
@ -124,6 +124,7 @@ gimp_devices_restore (Gimp *gimp)
GimpDeviceInfo *device_info;
GimpContext *user_context;
gchar *filename;
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
@ -131,11 +132,24 @@ gimp_devices_restore (Gimp *gimp)
g_return_if_fail (manager != NULL);
/* Augment with information from rc file */
filename = gimp_personal_rc_file ("devicerc");
gimprc_parse_file (filename);
if (! gimp_config_deserialize (G_OBJECT (manager->device_info_list),
filename,
gimp,
&error))
{
g_message ("Could not read devicerc: %s", error->message);
g_clear_error (&error);
/* don't bail out here */
}
g_free (filename);
GIMP_LIST (manager->device_info_list)->list =
g_list_reverse (GIMP_LIST (manager->device_info_list)->list);
device_info = gimp_device_info_get_by_device (manager->current_device);
g_return_if_fail (GIMP_IS_DEVICE_INFO (device_info));
@ -152,7 +166,7 @@ gimp_devices_save (Gimp *gimp)
{
GimpDeviceManager *manager;
gchar *filename;
FILE *fp;
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
@ -161,88 +175,15 @@ gimp_devices_save (Gimp *gimp)
g_return_if_fail (manager != NULL);
filename = gimp_personal_rc_file ("devicerc");
fp = fopen (filename, "wb");
if (fp)
{
gimp_container_foreach (manager->device_info_list,
(GFunc) gimp_device_info_save, fp);
fclose (fp);
}
else
{
g_warning ("%s: could not open \"%s\" for writing: %s",
G_STRLOC, filename, g_strerror (errno));
}
g_free (filename);
}
void
gimp_devices_restore_test (Gimp *gimp)
{
GimpDeviceManager *manager;
GimpDeviceInfo *device_info;
GimpContext *user_context;
gchar *filename;
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
manager = gimp_device_manager_get (gimp);
g_return_if_fail (manager != NULL);
filename = gimp_personal_rc_file ("test-devicerc");
if (! gimp_config_deserialize (G_OBJECT (manager->device_info_list),
filename,
gimp,
&error))
{
g_message ("Could not read test-devicerc: %s", error->message);
g_clear_error (&error);
g_free (filename);
return;
}
g_free (filename);
device_info = gimp_device_info_get_by_device (manager->current_device);
g_return_if_fail (GIMP_IS_DEVICE_INFO (device_info));
user_context = gimp_get_user_context (gimp);
gimp_context_copy_properties (GIMP_CONTEXT (device_info), user_context,
GIMP_DEVICE_INFO_CONTEXT_MASK);
gimp_context_set_parent (GIMP_CONTEXT (device_info), user_context);
}
void
gimp_devices_save_test (Gimp *gimp)
{
GimpDeviceManager *manager;
gchar *filename;
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
manager = gimp_device_manager_get (gimp);
g_return_if_fail (manager != NULL);
filename = gimp_personal_rc_file ("test-devicerc");
if (! gimp_config_serialize (G_OBJECT (manager->device_info_list),
filename,
"# test-devicerc\n",
"# end test-devicerc",
"# GIMP devicerc\n",
"# end devicerc",
NULL,
&error))
{
g_message ("Could not write test-devicerc: %s", error->message);
g_message ("Could not write devicerc: %s", error->message);
g_clear_error (&error);
}
@ -349,61 +290,6 @@ gimp_devices_check_change (Gimp *gimp,
return FALSE;
}
void
gimp_devices_rc_update (Gimp *gimp,
const gchar *name,
GimpDeviceValues values,
GdkInputMode mode,
gint num_axes,
const GdkAxisUse *axes,
gint num_keys,
const GdkDeviceKey *keys,
const gchar *tool_name,
const GimpRGB *foreground,
const GimpRGB *background,
const gchar *brush_name,
const gchar *pattern_name,
const gchar *gradient_name)
{
GimpDeviceManager *manager;
GimpDeviceInfo *device_info = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (name != NULL);
manager = gimp_device_manager_get (gimp);
g_return_if_fail (manager != NULL);
/* Find device if we have it */
device_info = (GimpDeviceInfo *)
gimp_container_get_child_by_name (manager->device_info_list, name);
if (! device_info)
{
device_info = gimp_device_info_new (gimp, name);
gimp_container_add (manager->device_info_list, GIMP_OBJECT (device_info));
g_object_unref (G_OBJECT (device_info));
}
else if (! device_info->device)
{
g_warning ("%s: called multiple times for not present device",
G_STRLOC);
return;
}
gimp_device_info_set_from_rc (device_info,
values,
mode,
num_axes, axes,
num_keys, keys,
tool_name,
foreground, background,
brush_name,
pattern_name,
gradient_name);
}
/* private functions */

View file

@ -30,9 +30,6 @@ void gimp_devices_exit (Gimp *gimp);
void gimp_devices_restore (Gimp *gimp);
void gimp_devices_save (Gimp *gimp);
void gimp_devices_restore_test (Gimp *gimp);
void gimp_devices_save_test (Gimp *gimp);
GdkDevice * gimp_devices_get_current (Gimp *gimp);
gboolean gimp_devices_check_change (Gimp *gimp,
@ -40,20 +37,5 @@ gboolean gimp_devices_check_change (Gimp *gimp,
void gimp_devices_select_device (Gimp *gimp,
GdkDevice *device);
void gimp_devices_rc_update (Gimp *gimp,
const gchar *name,
GimpDeviceValues values,
GdkInputMode mode,
gint num_axes,
const GdkAxisUse *axes,
gint num_keys,
const GdkDeviceKey *keys,
const gchar *tool_name,
const GimpRGB *foreground,
const GimpRGB *background,
const gchar *brush_name,
const gchar *pattern_name,
const gchar *gradient_name);
#endif /* __GIMP_DEVICES_H__ */

View file

@ -661,6 +661,8 @@ gimp_config_deserialize_value_array (GValue *value,
return token;
}
g_value_set_boxed_take_ownership (value, array);
return G_TOKEN_RIGHT_PAREN;
}