Commit 7684721c authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

virtualized GimpView::set_viewable.

2005-03-25  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimpview.[ch]: virtualized GimpView::set_viewable.

	* app/widgets/gimptoolbox-image-area.c: hook into "set_viewable"
	and add an XDS drag source.

	* app/widgets/gimpdnd-xds.c
	* app/widgets/gimpdnd.c: unset the XdndDirectSave0 property when
	the drag ends, minor cleanups.
parent 0bc3233b
2005-03-25 Sven Neumann <sven@gimp.org>
* app/widgets/gimpview.[ch]: virtualized GimpView::set_viewable.
* app/widgets/gimptoolbox-image-area.c: hook into "set_viewable"
and add an XDS drag source.
* app/widgets/gimpdnd-xds.c
* app/widgets/gimpdnd.c: unset the XdndDirectSave0 property when
the drag ends, minor cleanups.
2005-03-25 Sven Neumann <sven@gimp.org>
* app/widgets/Makefile.am
......
......@@ -43,6 +43,13 @@
*/
#ifdef DEBUG_DND
#define D(stmnt) stmnt
#else
#define D(stmnt)
#endif
#define MAX_URI_LEN 4096
......@@ -56,6 +63,8 @@ gimp_dnd_xds_source_set (GdkDragContext *context,
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
D (g_printerr ("\ngimp_dnd_xds_source_set\n"));
property = gdk_atom_intern ("XdndDirectSave0", FALSE);
if (image && (filename = gimp_image_get_filename (image)))
......@@ -93,6 +102,8 @@ gimp_dnd_xds_save_image (GdkDragContext *context,
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
g_return_if_fail (GIMP_IS_IMAGE (image));
D (g_printerr ("\ngimp_dnd_xds_save_image\n"));
if (! gdk_property_get (context->source_window, property, type,
0, MAX_URI_LEN, FALSE,
NULL, NULL, &length, &data))
......
......@@ -45,6 +45,8 @@
#include "vectors/gimpvectors.h"
/* #define DEBUG_DND */
#include "gimpdnd.h"
#include "gimpdnd-xds.h"
#include "gimpview.h"
......@@ -57,7 +59,6 @@
#define DRAG_PREVIEW_SIZE 32
#define DRAG_ICON_OFFSET -8
/* #define DEBUG_DND */
#ifdef DEBUG_DND
#define D(stmnt) stmnt
......@@ -89,11 +90,11 @@ struct _GimpDndDataDef
{
GtkTargetEntry target_entry;
gchar *get_data_func_name;
gchar *get_data_data_name;
const gchar *get_data_func_name;
const gchar *get_data_data_name;
gchar *set_data_func_name;
gchar *set_data_data_name;
const gchar *set_data_func_name;
const gchar *set_data_data_name;
GimpDndGetIconFunc get_icon_func;
GimpDndDragDataFunc get_data_func;
......@@ -260,7 +261,7 @@ static gboolean gimp_dnd_set_tool_data (GtkWidget *widget,
static GimpDndDataDef dnd_data_defs[] =
static const GimpDndDataDef dnd_data_defs[] =
{
{
{ NULL, 0, -1 },
......@@ -633,16 +634,16 @@ gimp_dnd_data_drag_begin (GtkWidget *widget,
GdkDragContext *context,
gpointer data)
{
GimpDndType data_type;
GimpDndDataDef *dnd_data;
GCallback get_data_func = NULL;
gpointer get_data_data = NULL;
GtkWidget *icon_widget;
const GimpDndDataDef *dnd_data;
GimpDndType data_type;
GCallback get_data_func = NULL;
gpointer get_data_data = NULL;
GtkWidget *icon_widget;
data_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
"gimp-dnd-get-data-type"));
D (g_print ("\ngimp_dnd_data_drag_begin (%d)\n", data_type));
D (g_printerr ("\ngimp_dnd_data_drag_begin (%d)\n", data_type));
if (! data_type)
return;
......@@ -697,7 +698,7 @@ gimp_dnd_data_drag_end (GtkWidget *widget,
{
GtkWidget *icon_widget;
D (g_print ("\ngimp_dnd_data_drag_end\n"));
D (g_printerr ("\ngimp_dnd_data_drag_end\n"));
icon_widget = g_object_get_data (G_OBJECT (widget), "gimp-dnd-data-widget");
......@@ -727,20 +728,20 @@ gimp_dnd_data_drag_handle (GtkWidget *widget,
gpointer get_data_data = NULL;
GimpDndType data_type;
D (g_print ("\ngimp_dnd_data_drag_handle(%d)\n", info));
D (g_printerr ("\ngimp_dnd_data_drag_handle(%d)\n", info));
for (data_type = GIMP_DND_TYPE_NONE + 1;
data_type <= GIMP_DND_TYPE_LAST;
data_type++)
{
GimpDndDataDef *dnd_data = dnd_data_defs + data_type;
const GimpDndDataDef *dnd_data = dnd_data_defs + data_type;
if (dnd_data->target_entry.info == info)
{
GdkAtom atom;
D (g_print ("gimp_dnd_data_drag_handle(%s)\n",
dnd_data->target_entry.target));
D (g_printerr ("gimp_dnd_data_drag_handle(%s)\n",
dnd_data->target_entry.target));
if (dnd_data->get_data_func_name)
get_data_func = g_object_get_data (G_OBJECT (widget),
......@@ -779,7 +780,7 @@ gimp_dnd_data_drop_handle (GtkWidget *widget,
{
GimpDndType data_type;
D (g_print ("\ngimp_dnd_data_drop_handle(%d)\n", info));
D (g_printerr ("\ngimp_dnd_data_drop_handle(%d)\n", info));
if (selection_data->length <= 0)
{
......@@ -791,15 +792,15 @@ gimp_dnd_data_drop_handle (GtkWidget *widget,
data_type <= GIMP_DND_TYPE_LAST;
data_type++)
{
GimpDndDataDef *dnd_data = dnd_data_defs + data_type;
const GimpDndDataDef *dnd_data = dnd_data_defs + data_type;
if (dnd_data->target_entry.info == info)
{
GCallback set_data_func = NULL;
gpointer set_data_data = NULL;
D (g_print ("gimp_dnd_data_drop_handle(%s)\n",
dnd_data->target_entry.target));
D (g_printerr ("gimp_dnd_data_drop_handle(%s)\n",
dnd_data->target_entry.target));
if (dnd_data->set_data_func_name)
set_data_func = g_object_get_data (G_OBJECT (widget),
......@@ -831,9 +832,9 @@ gimp_dnd_data_source_add (GimpDndType data_type,
GCallback get_data_func,
gpointer get_data_data)
{
GimpDndDataDef *dnd_data;
GtkTargetList *target_list;
gboolean drag_connected;
const GimpDndDataDef *dnd_data;
GtkTargetList *target_list;
gboolean drag_connected;
dnd_data = dnd_data_defs + data_type;
......@@ -896,9 +897,9 @@ static void
gimp_dnd_data_source_remove (GimpDndType data_type,
GtkWidget *widget)
{
GimpDndDataDef *dnd_data;
GtkTargetList *target_list;
gboolean drag_connected;
const GimpDndDataDef *dnd_data;
GtkTargetList *target_list;
gboolean drag_connected;
drag_connected =
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
......@@ -935,9 +936,9 @@ gimp_dnd_data_dest_add (GimpDndType data_type,
gpointer set_data_func,
gpointer set_data_data)
{
GimpDndDataDef *dnd_data;
GtkTargetList *target_list;
gboolean drop_connected;
const GimpDndDataDef *dnd_data;
GtkTargetList *target_list;
gboolean drop_connected;
/* set a default drag dest if not already done */
if (! g_object_get_data (G_OBJECT (widget), "gtk-drag-dest"))
......@@ -990,8 +991,8 @@ static void
gimp_dnd_data_dest_remove (GimpDndType data_type,
GtkWidget *widget)
{
GimpDndDataDef *dnd_data;
GtkTargetList *target_list;
const GimpDndDataDef *dnd_data;
GtkTargetList *target_list;
dnd_data = dnd_data_defs + data_type;
......@@ -1139,12 +1140,11 @@ gimp_dnd_get_xds_data (GtkWidget *widget,
static void
gimp_dnd_xds_drag_begin (GtkWidget *widget,
GdkDragContext *context,
gpointer data)
GdkDragContext *context)
{
GimpDndDataDef *dnd_data = dnd_data_defs + GIMP_DND_TYPE_XDS;
GCallback get_data_func;
gpointer get_data_data;
const GimpDndDataDef *dnd_data = dnd_data_defs + GIMP_DND_TYPE_XDS;
GCallback get_data_func;
gpointer get_data_data;
get_data_func = g_object_get_data (G_OBJECT (widget),
dnd_data->get_data_func_name);
......@@ -1160,6 +1160,13 @@ gimp_dnd_xds_drag_begin (GtkWidget *widget,
}
}
static void
gimp_dnd_xds_drag_end (GtkWidget *widget,
GdkDragContext *context)
{
gimp_dnd_xds_source_set (context, NULL);
}
void
gimp_dnd_xds_source_add (GtkWidget *widget,
GimpDndDragViewableFunc get_image_func,
......@@ -1184,6 +1191,18 @@ gimp_dnd_xds_source_add (GtkWidget *widget,
g_object_set_data (G_OBJECT (widget), "gimp-dnd-xds-drag-begin",
GUINT_TO_POINTER (handler));
}
handler = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget),
"gimp-dnd-xds-drag-end"));
if (! handler)
{
handler = g_signal_connect (widget, "drag_end",
G_CALLBACK (gimp_dnd_xds_drag_end),
NULL);
g_object_set_data (G_OBJECT (widget), "gimp-dnd-xds-drag-end",
GUINT_TO_POINTER (handler));
}
}
void
......@@ -1201,6 +1220,14 @@ gimp_dnd_xds_source_remove (GtkWidget *widget)
g_object_set_data (G_OBJECT (widget), "gimp-dnd-xds-drag-begin", NULL);
}
handler = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget),
"gimp-dnd-xds-drag-end"));
if (handler)
{
g_signal_handler_disconnect (widget, handler);
g_object_set_data (G_OBJECT (widget), "gimp-dnd-xds-drag-end", NULL);
}
gimp_dnd_data_source_remove (GIMP_DND_TYPE_XDS, widget);
}
......@@ -1722,8 +1749,8 @@ gimp_dnd_viewable_dest_remove (GtkWidget *widget,
GimpViewable *
gimp_dnd_get_drag_data (GtkWidget *widget)
{
const GimpDndDataDef *dnd_data;
GimpDndType data_type;
GimpDndDataDef *dnd_data;
GimpDndDragViewableFunc get_data_func = NULL;
gpointer get_data_data = NULL;
......
......@@ -39,8 +39,8 @@
#include "gimp-intl.h"
#define CELL_WIDTH 48
#define CELL_HEIGHT 48
#define CELL_WIDTH 48
#define CELL_HEIGHT 48
static void
......@@ -65,6 +65,15 @@ image_preview_drop_image (GtkWidget *widget,
gimp_context_set_image (context, GIMP_IMAGE (viewable));
}
static void
image_preview_set_viewable (GimpView *view,
GimpViewable *viewable)
{
if (viewable)
gimp_dnd_xds_source_add (GTK_WIDGET (view),
(GimpDndDragViewableFunc) gimp_view_get_viewable,
NULL);
}
/* public functions */
......@@ -80,12 +89,17 @@ gimp_toolbox_image_area_create (GimpToolbox *toolbox,
context = GIMP_DOCK (toolbox)->context;
image_view =
gimp_view_new_full_by_types (GIMP_TYPE_VIEW, GIMP_TYPE_IMAGE,
width, height, 0,
FALSE, TRUE, TRUE);
image_view = gimp_view_new_full_by_types (GIMP_TYPE_VIEW, GIMP_TYPE_IMAGE,
width, height, 0,
FALSE, TRUE, TRUE);
g_signal_connect (image_view, "set_viewable",
G_CALLBACK (image_preview_set_viewable),
NULL);
gimp_view_set_viewable (GIMP_VIEW (image_view),
(GimpViewable *) gimp_context_get_image (context));
gtk_widget_show (image_view);
gimp_help_set_help_data (image_view,
......@@ -94,8 +108,7 @@ gimp_toolbox_image_area_create (GimpToolbox *toolbox,
g_signal_connect_object (context, "image_changed",
G_CALLBACK (gimp_view_set_viewable),
image_view,
G_CONNECT_SWAPPED);
image_view, G_CONNECT_SWAPPED);
g_signal_connect (image_view, "clicked",
G_CALLBACK (image_preview_clicked),
......
......@@ -50,6 +50,7 @@
enum
{
SET_VIEWABLE,
CLICKED,
DOUBLE_CLICKED,
CONTEXT,
......@@ -80,6 +81,9 @@ static gboolean gimp_view_enter_notify_event (GtkWidget *widget,
static gboolean gimp_view_leave_notify_event (GtkWidget *widget,
GdkEventCrossing *event);
static void gimp_view_real_set_viewable (GimpView *view,
GimpViewable *viewable);
static void gimp_view_update_callback (GimpViewRenderer *renderer,
GimpView *view);
......@@ -129,6 +133,16 @@ gimp_view_class_init (GimpViewClass *klass)
parent_class = g_type_class_peek_parent (klass);
view_signals[SET_VIEWABLE] =
g_signal_new ("set-viewable",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpViewClass, set_viewable),
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_VIEWABLE);
view_signals[CLICKED] =
g_signal_new ("clicked",
G_TYPE_FROM_CLASS (klass),
......@@ -172,6 +186,7 @@ gimp_view_class_init (GimpViewClass *klass)
widget_class->enter_notify_event = gimp_view_enter_notify_event;
widget_class->leave_notify_event = gimp_view_leave_notify_event;
klass->set_viewable = gimp_view_real_set_viewable;
klass->clicked = NULL;
klass->double_clicked = NULL;
klass->context = NULL;
......@@ -500,8 +515,7 @@ gimp_view_button_release_event (GtkWidget *widget,
if (view->clickable && view->in_button)
{
g_signal_emit (widget, view_signals[CLICKED], 0,
view->press_state);
g_signal_emit (widget, view_signals[CLICKED], 0, view->press_state);
}
}
else
......@@ -544,6 +558,60 @@ gimp_view_leave_notify_event (GtkWidget *widget,
return FALSE;
}
static void
gimp_view_real_set_viewable (GimpView *view,
GimpViewable *viewable)
{
GType viewable_type = G_TYPE_NONE;
if (viewable == view->viewable)
return;
if (viewable)
{
viewable_type = G_TYPE_FROM_INSTANCE (viewable);
g_return_if_fail (g_type_is_a (viewable_type,
view->renderer->viewable_type));
}
if (view->viewable)
{
g_object_remove_weak_pointer (G_OBJECT (view->viewable),
(gpointer *) &view->viewable);
if (! viewable && ! view->renderer->is_popup)
{
if (gimp_dnd_viewable_source_remove (GTK_WIDGET (view),
G_TYPE_FROM_INSTANCE (view->viewable)))
{
gtk_drag_source_unset (GTK_WIDGET (view));
}
}
}
else if (viewable && ! view->renderer->is_popup)
{
if (gimp_dnd_drag_source_set_by_type (GTK_WIDGET (view),
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
viewable_type,
GDK_ACTION_COPY))
{
gimp_dnd_viewable_source_add (GTK_WIDGET (view),
viewable_type,
gimp_view_drag_viewable,
NULL);
}
}
gimp_view_renderer_set_viewable (view->renderer, viewable);
view->viewable = viewable;
if (view->viewable)
{
g_object_add_weak_pointer (G_OBJECT (view->viewable),
(gpointer *) &view->viewable);
}
}
/* public functions */
......@@ -668,62 +736,25 @@ gimp_view_new_full_by_types (GType view_type,
return GTK_WIDGET (view);
}
GimpViewable *
gimp_view_get_viewable (GimpView *view)
{
g_return_val_if_fail (GIMP_IS_VIEW (view), NULL);
return view->viewable;
}
void
gimp_view_set_viewable (GimpView *view,
GimpViewable *viewable)
{
GType viewable_type = G_TYPE_NONE;
g_return_if_fail (GIMP_IS_VIEW (view));
g_return_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable));
if (viewable == view->viewable)
return;
if (viewable)
{
viewable_type = G_TYPE_FROM_INSTANCE (viewable);
g_return_if_fail (g_type_is_a (viewable_type,
view->renderer->viewable_type));
}
if (view->viewable)
{
g_object_remove_weak_pointer (G_OBJECT (view->viewable),
(gpointer *) &view->viewable);
if (! viewable && ! view->renderer->is_popup)
{
if (gimp_dnd_viewable_source_remove (GTK_WIDGET (view),
G_TYPE_FROM_INSTANCE (view->viewable)))
{
gtk_drag_source_unset (GTK_WIDGET (view));
}
}
}
else if (viewable && ! view->renderer->is_popup)
{
if (gimp_dnd_drag_source_set_by_type (GTK_WIDGET (view),
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
viewable_type,
GDK_ACTION_COPY))
{
gimp_dnd_viewable_source_add (GTK_WIDGET (view),
viewable_type,
gimp_view_drag_viewable,
NULL);
}
}
gimp_view_renderer_set_viewable (view->renderer, viewable);
view->viewable = viewable;
if (view->viewable)
{
g_object_add_weak_pointer (G_OBJECT (view->viewable),
(gpointer *) &view->viewable);
}
g_signal_emit (view, view_signals[SET_VIEWABLE], 0, viewable);
}
void
......
......@@ -58,6 +58,8 @@ struct _GimpViewClass
GtkWidgetClass parent_class;
/* signals */
void (* set_viewable) (GimpView *view,
GimpViewable *viewable);
void (* clicked) (GimpView *view,
GdkModifierType modifier_state);
void (* double_clicked) (GimpView *view);
......@@ -92,10 +94,11 @@ GtkWidget * gimp_view_new_full_by_types (GType view_type,
gboolean clickable,
gboolean show_popup);
void gimp_view_set_viewable (GimpView *view,
GimpViewable *viewable);
void gimp_view_set_expand (GimpView *view,
gboolean expand);
GimpViewable * gimp_view_get_viewable (GimpView *view);
void gimp_view_set_viewable (GimpView *view,
GimpViewable *viewable);
void gimp_view_set_expand (GimpView *view,
gboolean expand);
#endif /* __GIMP_VIEW_H__ */
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