2 * This file is part of TBO, a gnome comic editor
3 * Copyright (C) 2010 Daniel Garcia Moreno <dani@danigm.net>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "tbo-drawing.h"
25 #include "tbo-object-svg.h"
26 #include "tbo-window.h"
28 static GtkWidget *DND_IMAGE = NULL;
31 drag_data_received_handl (GtkWidget *widget,
32 GdkDragContext *context,
34 GtkSelectionData *selection_data,
40 float zoom = tbo_drawing_get_zoom (TBO_DRAWING (tbo->drawing));
43 gboolean dnd_success = FALSE;
44 gboolean delete_selection_data = FALSE;
46 /* Deal with what we are given from source */
47 if ((selection_data != NULL) && (gtk_selection_data_get_length (selection_data) >= 0))
49 if (gdk_drag_context_get_selected_action (context) == GDK_ACTION_ASK)
51 /* Ask the user to move or copy, then set the context action. */
54 if (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE)
55 delete_selection_data = TRUE;
57 /* Check that we got the format we can use */
61 _sdata = gtk_selection_data_get_data (selection_data);
63 Frame *frame = tbo_drawing_get_current_frame (TBO_DRAWING (tbo->drawing));
64 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (tbo->dw_scroll));
65 int rx = tbo_frame_get_base_x ((x + gtk_adjustment_get_value(adj)) / zoom);
66 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (tbo->dw_scroll));
67 int ry = tbo_frame_get_base_y ((y + gtk_adjustment_get_value(adj)) / zoom);
69 TboObjectSvg *svgimage = TBO_OBJECT_SVG (tbo_object_svg_new_with_params (rx, ry, 0, 0, (gchar*)_sdata));
70 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
71 tbo_frame_add_obj (frame, TBO_OBJECT_BASE (svgimage));
77 g_print ("nothing good");
81 if (dnd_success == FALSE)
83 g_print ("DnD data transfer failed!\n");
86 gtk_drag_finish (context, dnd_success, delete_selection_data, time);
90 drag_data_get_handl (GtkWidget *widget,
91 GdkDragContext *context,
92 GtkSelectionData *selection_data,
97 g_assert (selection_data != NULL);
101 gtk_selection_data_set (selection_data,
102 gtk_selection_data_get_target (selection_data),
108 /* Default to some a safe target instead of fail. */
109 g_assert_not_reached ();
114 drag_begin_handl (GtkWidget *widget,
115 GdkDragContext *context,
118 DND_IMAGE = gtk_image_new_from_file (svg);
119 GdkPixbuf *pix = gtk_image_get_pixbuf (GTK_IMAGE (DND_IMAGE));
120 gtk_drag_set_icon_pixbuf (context, pix, 0, 0);
124 drag_end_handl (GtkWidget *widget,
125 GdkDragContext *context,
130 gtk_widget_destroy (GTK_WIDGET (DND_IMAGE));