Commit c1c876a9 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Some DND fixes / cleanup:

2005-07-25  Michael Natterer  <mitch@gimp.org>

	Some DND fixes / cleanup:

	* app/widgets/widgets-enums.h: renamed GIMP_DND_TYPE_TOOL to
	GIMP_DND_TYPE_TOOL_INFO.

	* app/widgets/gimpselectiondata.[ch]: s/tool/tool_info/g. Moved
	private functions to the end of the file. Include GIMP's PID in
	all GtkSelectionData strings which are used to pass around stuff
	by reference. For things which are referenced by name, also encode
	the object's address in the GtkSelectionData so having a brush
	called "Standard" or a named buffer called "Global Buffer" will
	work together with DND.

	* app/widgets/gimpdnd.[ch]: s/tool/tool_info/g. Renamed
	gimp_dnd_get_data_data() to gimp_dnd_get_object_data() since it's
	not limited to GimpData objects. Follow above selection data API
	changes. Cleanup.

	* libgimp/gimpbrushmenu.c
	* libgimp/gimpdrawablecombobox.c
	* libgimp/gimpfontselectbutton.c
	* libgimp/gimpgradientmenu.c
	* libgimp/gimpimagecombobox.c
	* libgimp/gimppalettemenu.c
	* libgimp/gimppatternmenu.c: follow GtkSelectionData format change
	and check the dropped things' PID against the return value of
	gimp_getpid().
parent 1999d56e
2005-07-25 Michael Natterer <mitch@gimp.org>
Some DND fixes / cleanup:
* app/widgets/widgets-enums.h: renamed GIMP_DND_TYPE_TOOL to
GIMP_DND_TYPE_TOOL_INFO.
* app/widgets/gimpselectiondata.[ch]: s/tool/tool_info/g. Moved
private functions to the end of the file. Include GIMP's PID in
all GtkSelectionData strings which are used to pass around stuff
by reference. For things which are referenced by name, also encode
the object's address in the GtkSelectionData so having a brush
called "Standard" or a named buffer called "Global Buffer" will
work together with DND.
* app/widgets/gimpdnd.[ch]: s/tool/tool_info/g. Renamed
gimp_dnd_get_data_data() to gimp_dnd_get_object_data() since it's
not limited to GimpData objects. Follow above selection data API
changes. Cleanup.
* libgimp/gimpbrushmenu.c
* libgimp/gimpdrawablecombobox.c
* libgimp/gimpfontselectbutton.c
* libgimp/gimpgradientmenu.c
* libgimp/gimpimagecombobox.c
* libgimp/gimppalettemenu.c
* libgimp/gimppatternmenu.c: follow GtkSelectionData format change
and check the dropped things' PID against the return value of
gimp_getpid().
2005-07-25 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/misc.pdb: on Win32, include <process.h> for
......
......@@ -201,10 +201,10 @@ static gboolean gimp_dnd_set_item_data (GtkWidget *widget,
gpointer set_item_data,
GtkSelectionData *selection);
static void gimp_dnd_get_data_data (GtkWidget *widget,
static void gimp_dnd_get_object_data (GtkWidget *widget,
GdkDragContext *context,
GCallback get_data_func,
gpointer get_data_data,
GCallback get_object_func,
gpointer get_object_data,
GtkSelectionData *selection);
static gboolean gimp_dnd_set_brush_data (GtkWidget *widget,
......@@ -255,11 +255,11 @@ static gboolean gimp_dnd_set_template_data (GtkWidget *widget,
GCallback set_template_func,
gpointer set_template_data,
GtkSelectionData *selection);
static gboolean gimp_dnd_set_tool_data (GtkWidget *widget,
static gboolean gimp_dnd_set_tool_info_data (GtkWidget *widget,
gint x,
gint y,
GCallback set_tool_func,
gpointer set_tool_data,
GCallback set_tool_info_func,
gpointer set_tool_info_data,
GtkSelectionData *selection);
......@@ -483,7 +483,7 @@ static const GimpDndDataDef dnd_data_defs[] =
"gimp-dnd-set-brush-data",
gimp_dnd_get_viewable_icon,
gimp_dnd_get_data_data,
gimp_dnd_get_object_data,
gimp_dnd_set_brush_data
},
......@@ -497,7 +497,7 @@ static const GimpDndDataDef dnd_data_defs[] =
"gimp-dnd-set-pattern-data",
gimp_dnd_get_viewable_icon,
gimp_dnd_get_data_data,
gimp_dnd_get_object_data,
gimp_dnd_set_pattern_data
},
......@@ -511,7 +511,7 @@ static const GimpDndDataDef dnd_data_defs[] =
"gimp-dnd-set-gradient-data",
gimp_dnd_get_viewable_icon,
gimp_dnd_get_data_data,
gimp_dnd_get_object_data,
gimp_dnd_set_gradient_data
},
......@@ -525,7 +525,7 @@ static const GimpDndDataDef dnd_data_defs[] =
"gimp-dnd-set-palette-data",
gimp_dnd_get_viewable_icon,
gimp_dnd_get_data_data,
gimp_dnd_get_object_data,
gimp_dnd_set_palette_data
},
......@@ -539,7 +539,7 @@ static const GimpDndDataDef dnd_data_defs[] =
"gimp-dnd-set-font-data",
gimp_dnd_get_viewable_icon,
gimp_dnd_get_data_data,
gimp_dnd_get_object_data,
gimp_dnd_set_font_data
},
......@@ -553,7 +553,7 @@ static const GimpDndDataDef dnd_data_defs[] =
"gimp-dnd-set-buffer-data",
gimp_dnd_get_viewable_icon,
gimp_dnd_get_data_data,
gimp_dnd_get_object_data,
gimp_dnd_set_buffer_data
},
......@@ -567,7 +567,7 @@ static const GimpDndDataDef dnd_data_defs[] =
"gimp-dnd-set-imagefile-data",
gimp_dnd_get_viewable_icon,
gimp_dnd_get_data_data,
gimp_dnd_get_object_data,
gimp_dnd_set_imagefile_data
},
......@@ -581,22 +581,22 @@ static const GimpDndDataDef dnd_data_defs[] =
"gimp-dnd-set-template-data",
gimp_dnd_get_viewable_icon,
gimp_dnd_get_data_data,
gimp_dnd_get_object_data,
gimp_dnd_set_template_data
},
{
GIMP_TARGET_TOOL,
GIMP_TARGET_TOOL_INFO,
"gimp-dnd-get-tool-func",
"gimp-dnd-get-tool-data",
"gimp-dnd-get-tool-info-func",
"gimp-dnd-get-tool-info-data",
"gimp-dnd-set-tool-func",
"gimp-dnd-set-tool-data",
"gimp-dnd-set-tool-info-func",
"gimp-dnd-set-tool-info-data",
gimp_dnd_get_viewable_icon,
gimp_dnd_get_data_data,
gimp_dnd_set_tool_data
gimp_dnd_get_object_data,
gimp_dnd_set_tool_info_data
},
{
......@@ -1803,7 +1803,7 @@ gimp_dnd_data_type_get_by_g_type (GType type)
}
else if (g_type_is_a (type, GIMP_TYPE_TOOL_INFO))
{
dnd_type = GIMP_DND_TYPE_TOOL;
dnd_type = GIMP_DND_TYPE_TOOL_INFO;
}
return dnd_type;
......@@ -1968,9 +1968,9 @@ gimp_dnd_get_drag_data (GtkWidget *widget)
}
/*************************/
/* image dnd functions */
/*************************/
/*****************************/
/* GimpImage dnd functions */
/*****************************/
static void
gimp_dnd_get_image_data (GtkWidget *widget,
......@@ -2009,9 +2009,9 @@ gimp_dnd_set_image_data (GtkWidget *widget,
}
/************************/
/* item dnd functions */
/************************/
/****************************/
/* GimpItem dnd functions */
/****************************/
static void
gimp_dnd_get_item_data (GtkWidget *widget,
......@@ -2050,30 +2050,30 @@ gimp_dnd_set_item_data (GtkWidget *widget,
}
/****************************/
/* GimpData dnd functions */
/****************************/
/******************************/
/* GimpObject dnd functions */
/******************************/
static void
gimp_dnd_get_data_data (GtkWidget *widget,
gimp_dnd_get_object_data (GtkWidget *widget,
GdkDragContext *context,
GCallback get_data_func,
gpointer get_data_data,
GCallback get_object_func,
gpointer get_object_data,
GtkSelectionData *selection)
{
GimpData *data;
GimpObject *object;
data = (GimpData *)
(* (GimpDndDragViewableFunc) get_data_func) (widget, get_data_data);
object = (GimpObject *)
(* (GimpDndDragViewableFunc) get_object_func) (widget, get_object_data);
if (data)
gimp_selection_data_set_viewable (selection, GIMP_VIEWABLE (data));
if (GIMP_IS_OBJECT (object))
gimp_selection_data_set_object (selection, object);
}
/*************************/
/* brush dnd functions */
/*************************/
/*****************************/
/* GimpBrush dnd functions */
/*****************************/
static gboolean
gimp_dnd_set_brush_data (GtkWidget *widget,
......@@ -2096,9 +2096,9 @@ gimp_dnd_set_brush_data (GtkWidget *widget,
}
/***************************/
/* pattern dnd functions */
/***************************/
/*******************************/
/* GimpPattern dnd functions */
/*******************************/
static gboolean
gimp_dnd_set_pattern_data (GtkWidget *widget,
......@@ -2122,9 +2122,9 @@ gimp_dnd_set_pattern_data (GtkWidget *widget,
}
/****************************/
/* gradient dnd functions */
/****************************/
/********************************/
/* GimpGradient dnd functions */
/********************************/
static gboolean
gimp_dnd_set_gradient_data (GtkWidget *widget,
......@@ -2148,9 +2148,9 @@ gimp_dnd_set_gradient_data (GtkWidget *widget,
}
/***************************/
/* palette dnd functions */
/***************************/
/*******************************/
/* GimpPalette dnd functions */
/*******************************/
static gboolean
gimp_dnd_set_palette_data (GtkWidget *widget,
......@@ -2174,9 +2174,9 @@ gimp_dnd_set_palette_data (GtkWidget *widget,
}
/************************/
/* font dnd functions */
/************************/
/****************************/
/* GimpFont dnd functions */
/****************************/
static gboolean
gimp_dnd_set_font_data (GtkWidget *widget,
......@@ -2199,9 +2199,9 @@ gimp_dnd_set_font_data (GtkWidget *widget,
}
/**************************/
/* buffer dnd functions */
/**************************/
/******************************/
/* GimpBuffer dnd functions */
/******************************/
static gboolean
gimp_dnd_set_buffer_data (GtkWidget *widget,
......@@ -2224,9 +2224,9 @@ gimp_dnd_set_buffer_data (GtkWidget *widget,
}
/*****************************/
/* imagefile dnd functions */
/*****************************/
/*********************************/
/* GimpImagefile dnd functions */
/*********************************/
static gboolean
gimp_dnd_set_imagefile_data (GtkWidget *widget,
......@@ -2250,9 +2250,9 @@ gimp_dnd_set_imagefile_data (GtkWidget *widget,
}
/*****************************/
/* template dnd functions */
/*****************************/
/********************************/
/* GimpTemplate dnd functions */
/********************************/
static gboolean
gimp_dnd_set_template_data (GtkWidget *widget,
......@@ -2276,27 +2276,27 @@ gimp_dnd_set_template_data (GtkWidget *widget,
}
/************************/
/* tool dnd functions */
/************************/
/********************************/
/* GimpToolInfo dnd functions */
/********************************/
static gboolean
gimp_dnd_set_tool_data (GtkWidget *widget,
gimp_dnd_set_tool_info_data (GtkWidget *widget,
gint x,
gint y,
GCallback set_tool_func,
gpointer set_tool_data,
GCallback set_tool_info_func,
gpointer set_tool_info_data,
GtkSelectionData *selection)
{
GimpToolInfo *tool_info = gimp_selection_data_get_tool (selection,
GimpToolInfo *tool_info = gimp_selection_data_get_tool_info (selection,
the_dnd_gimp);
if (! tool_info)
return FALSE;
(* (GimpDndDropViewableFunc) set_tool_func) (widget, x, y,
(* (GimpDndDropViewableFunc) set_tool_info_func) (widget, x, y,
GIMP_VIEWABLE (tool_info),
set_tool_data);
set_tool_info_data);
return TRUE;
}
......@@ -89,8 +89,8 @@
#define GIMP_TARGET_TEMPLATE \
{ "application/x-gimp-template-name", GTK_TARGET_SAME_APP, GIMP_DND_TYPE_TEMPLATE }
#define GIMP_TARGET_TOOL \
{ "application/x-gimp-tool-name", GTK_TARGET_SAME_APP, GIMP_DND_TYPE_TOOL }
#define GIMP_TARGET_TOOL_INFO \
{ "application/x-gimp-tool-info-name", GTK_TARGET_SAME_APP, GIMP_DND_TYPE_TOOL_INFO }
#define GIMP_TARGET_DIALOG \
{ "application/x-gimp-dialog", GTK_TARGET_SAME_APP, GIMP_DND_TYPE_DIALOG }
......
This diff is collapsed.
......@@ -72,8 +72,8 @@ GimpItem * gimp_selection_data_get_item (GtkSelectionData *selection,
/* various data */
void gimp_selection_data_set_viewable (GtkSelectionData *selection,
GimpViewable *viewable);
void gimp_selection_data_set_object (GtkSelectionData *selection,
GimpObject *object);
GimpBrush * gimp_selection_data_get_brush (GtkSelectionData *selection,
Gimp *gimp);
......@@ -91,7 +91,7 @@ GimpImagefile * gimp_selection_data_get_imagefile (GtkSelectionData *selection,
Gimp *gimp);
GimpTemplate * gimp_selection_data_get_template (GtkSelectionData *selection,
Gimp *gimp);
GimpToolInfo * gimp_selection_data_get_tool (GtkSelectionData *selection,
GimpToolInfo * gimp_selection_data_get_tool_info (GtkSelectionData *selection,
Gimp *gimp);
......
......@@ -211,7 +211,7 @@ typedef enum /*< skip >*/
GIMP_DND_TYPE_BUFFER = 20,
GIMP_DND_TYPE_IMAGEFILE = 21,
GIMP_DND_TYPE_TEMPLATE = 22,
GIMP_DND_TYPE_TOOL = 23,
GIMP_DND_TYPE_TOOL_INFO = 23,
GIMP_DND_TYPE_DIALOG = 24,
GIMP_DND_TYPE_LAST = GIMP_DND_TYPE_DIALOG
......
......@@ -604,7 +604,7 @@ gimp_brush_select_drag_data_received (GtkWidget *preview,
guint time,
GtkWidget *widget)
{
gchar *name;
gchar *str;
if ((selection->format != 8) || (selection->length < 1))
{
......@@ -612,10 +612,22 @@ gimp_brush_select_drag_data_received (GtkWidget *preview,
return;
}
name = g_strndup (selection->data, selection->length);
str = g_strndup (selection->data, selection->length);
if (g_utf8_validate (str, -1, NULL))
{
gint pid;
gpointer unused;
gint name_offset = 0;
if (sscanf (str, "%i:%p:%n", &pid, &unused, &name_offset) >= 2 &&
pid == gimp_getpid () && name_offset > 0)
{
gchar *name = str + name_offset;
if (g_utf8_validate (name, -1, NULL))
gimp_brush_select_widget_set (widget, name, -1.0, -1, -1);
}
}
g_free (name);
g_free (str);
}
......@@ -104,9 +104,7 @@ G_DEFINE_TYPE(GimpDrawableComboBox,
static void
gimp_drawable_combo_box_class_init (GimpDrawableComboBoxClass *klass)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->drag_data_received = gimp_drawable_combo_box_drag_data_received;
}
......@@ -276,9 +274,7 @@ G_DEFINE_TYPE(GimpLayerComboBox,
static void
gimp_layer_combo_box_class_init (GimpLayerComboBoxClass *klass)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->drag_data_received = gimp_drawable_combo_box_drag_data_received;
}
......@@ -402,8 +398,7 @@ gimp_drawable_combo_box_drag_data_received (GtkWidget *widget,
guint info,
guint time)
{
gchar *id;
gint ID;
gchar *str;
if ((selection->format != 8) || (selection->length < 1))
{
......@@ -411,9 +406,19 @@ gimp_drawable_combo_box_drag_data_received (GtkWidget *widget,
return;
}
id = g_strndup (selection->data, selection->length);
ID = atoi (id);
g_free (id);
str = g_strndup (selection->data, selection->length);
if (g_utf8_validate (str, -1, NULL))
{
gint pid;
gint ID;
if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_getpid ())
{
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget), ID);
}
}
g_free (str);
}
......@@ -392,7 +392,7 @@ gimp_font_select_drag_data_received (GtkWidget *widget,
guint info,
guint time)
{
gchar *name;
gchar *str;
if ((selection->format != 8) || (selection->length < 1))
{
......@@ -400,13 +400,25 @@ gimp_font_select_drag_data_received (GtkWidget *widget,
return;
}
name = g_strndup (selection->data, selection->length);
str = g_strndup (selection->data, selection->length);
if (g_utf8_validate (str, -1, NULL))
{
gint pid;
gpointer unused;
gint name_offset = 0;
if (sscanf (str, "%i:%p:%n", &pid, &unused, &name_offset) >= 2 &&
pid == gimp_getpid () && name_offset > 0)
{
gchar *name = str + name_offset;
if (g_utf8_validate (name, -1, NULL))
gimp_font_select_button_set_font_name (GIMP_FONT_SELECT_BUTTON (widget),
name);
}
}
g_free (name);
g_free (str);
}
static GtkWidget *
......
......@@ -414,7 +414,7 @@ gimp_gradient_select_drag_data_received (GtkWidget *widget,
guint info,
guint time)
{
gchar *name;
gchar *str;
if ((selection->format != 8) || (selection->length < 1))
{
......@@ -422,10 +422,22 @@ gimp_gradient_select_drag_data_received (GtkWidget *widget,
return;
}
name = g_strndup (selection->data, selection->length);
str = g_strndup (selection->data, selection->length);
if (g_utf8_validate (str, -1, NULL))
{
gint pid;
gpointer unused;
gint name_offset = 0;
if (sscanf (str, "%i:%p:%n", &pid, &unused, &name_offset) >= 2 &&
pid == gimp_getpid () && name_offset > 0)
{
gchar *name = str + name_offset;
if (g_utf8_validate (name, -1, NULL))
gimp_gradient_select_widget_set (widget, name);
}
}
g_free (name);
g_free (str);
}
......@@ -77,9 +77,7 @@ G_DEFINE_TYPE(GimpImageComboBox,
static void
gimp_image_combo_box_class_init (GimpImageComboBoxClass *klass)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->drag_data_received = gimp_image_combo_box_drag_data_received;
}
......@@ -194,8 +192,7 @@ gimp_image_combo_box_drag_data_received (GtkWidget *widget,
guint info,
guint time)
{
gchar *id;
gint ID;
gchar *str;
if ((selection->format != 8) || (selection->length < 1))
{
......@@ -203,9 +200,19 @@ gimp_image_combo_box_drag_data_received (GtkWidget *widget,
return;
}
id = g_strndup (selection->data, selection->length);
ID = atoi (id);
g_free (id);
str = g_strndup (selection->data, selection->length);
if (g_utf8_validate (str, -1, NULL))
{
gint pid;
gint ID;
if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_getpid ())
{
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget), ID);
}
}
g_free (str);
}
......@@ -104,9 +104,7 @@ G_DEFINE_TYPE(GimpDrawableComboBox,
static void
gimp_drawable_combo_box_class_init (GimpDrawableComboBoxClass *klass)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->drag_data_received = gimp_drawable_combo_box_drag_data_received;
}
......@@ -276,9 +274,7 @@ G_DEFINE_TYPE(GimpLayerComboBox,
static void
gimp_layer_combo_box_class_init (GimpLayerComboBoxClass *klass)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->drag_data_received = gimp_drawable_combo_box_drag_data_received;
}
......@@ -402,8 +398,7 @@ gimp_drawable_combo_box_drag_data_received (GtkWidget *widget,
guint info,
guint time)
{
gchar *id;
gint ID;
gchar *str;
if ((selection->format != 8) || (selection->length < 1))
{
......@@ -411,9 +406,19 @@ gimp_drawable_combo_box_drag_data_received (GtkWidget *widget,
return;
}
id = g_strndup (selection->data, selection->length);
ID = atoi (id);
g_free (id);
str = g_strndup (selection->data, selection->length);
if (g_utf8_validate (str, -1, NULL))
{
gint pid;
gint ID;
if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
pid == gimp_getpid ())
{
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget), ID);
}
}
g_free (str);
}
......@@ -264,7 +264,7 @@ gimp_palette_select_drag_data_received (GtkWidget *widget,
guint info,
guint time)
{
gchar *name;
gchar *str;
if ((selection->format != 8) || (selection->length < 1))
{
......@@ -272,10 +272,22 @@ gimp_palette_select_drag_data_received (GtkWidget *widget,
return;
}
name = g_strndup (selection->data, selection->length);
str = g_strndup (selection->data, selection->length);
if (g_utf8_validate (str, -1, NULL))
{
gint pid;
gpointer unused;
gint name_offset = 0;
if (sscanf (str, "%i:%p:%n", &pid, &unused, &name_offset) >= 2 &&
pid == gimp_getpid () && name_offset > 0)
{
gchar *name = str + name_offset;
if (g_utf8_validate (name, -1, NULL))
gimp_palette_select_widget_set (widget, name);
}
}
g_free (name);
g_free (str);
}
......@@ -498,7 +498,7 @@ gimp_pattern_select_drag_data_received (GtkWidget *preview,
guint time,
GtkWidget *widget)
{
gchar *name;
gchar *str;
if ((selection->format != 8) || (selection->length < 1))
{
......@@ -506,10 +506,22 @@ gimp_pattern_select_drag_data_received (GtkWidget *preview,
return;
}
name = g_strndup (selection->data, selection->length);
str = g_strndup (selection->data, selection->length);
if (g_utf8_validate (str, -1, NULL))
{
gint pid;
gpointer unused;
gint name_offset = 0;
if (sscanf (str, "%i:%p:%n", &pid, &unused, &name_offset) >= 2 &&
pid == gimp_getpid () && name_offset > 0)
{
gchar *name = str + name_offset;
if (g_utf8_validate (name, -1, NULL))
gimp_pattern_select_widget_set (widget, name);
}
}
g_free (name);
g_free (str);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment