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-object-pixmap.h"
27 #include "tbo-window.h"
29 static GtkWidget *DND_IMAGE = NULL;
32 drag_data_received_handl (GtkWidget *widget,
33 GdkDragContext *context,
35 GtkSelectionData *selection_data,
41 float zoom = tbo_drawing_get_zoom (TBO_DRAWING (tbo->drawing));
44 gboolean dnd_success = FALSE;
45 gboolean delete_selection_data = FALSE;
47 /* Deal with what we are given from source */
48 if ((selection_data != NULL) && (gtk_selection_data_get_length (selection_data) >= 0))
50 if (gdk_drag_context_get_selected_action (context) == GDK_ACTION_ASK)
52 /* Ask the user to move or copy, then set the context action. */
55 if (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE)
56 delete_selection_data = TRUE;
58 /* Check that we got the format we can use */
62 _sdata = gtk_selection_data_get_data (selection_data);
65 Frame *frame = tbo_drawing_get_current_frame (TBO_DRAWING (tbo->drawing));
66 adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (tbo->dw_scroll));
67 int rx = tbo_frame_get_base_x ((x + gtk_adjustment_get_value(adj)) / zoom);
68 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (tbo->dw_scroll));
69 int ry = tbo_frame_get_base_y ((y + gtk_adjustment_get_value(adj)) / zoom);
71 if (tbo_files_is_svg_file ((gchar *)_sdata)) {
72 image = TBO_OBJECT_BASE (tbo_object_svg_new_with_params (rx, ry, 0, 0, (gchar*)_sdata));
74 image = TBO_OBJECT_BASE (tbo_object_pixmap_new_with_params (rx, ry, 0, 0, (gchar*)_sdata));
77 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
78 tbo_frame_add_obj (frame, TBO_OBJECT_BASE (image));
84 g_print ("nothing good");
88 if (dnd_success == FALSE)
90 g_print ("DnD data transfer failed!\n");
93 gtk_drag_finish (context, dnd_success, delete_selection_data, time);
97 drag_data_get_handl (GtkWidget *widget,
98 GdkDragContext *context,
99 GtkSelectionData *selection_data,
104 g_assert (selection_data != NULL);
108 gtk_selection_data_set (selection_data,
109 gtk_selection_data_get_target (selection_data),
115 /* Default to some a safe target instead of fail. */
116 g_assert_not_reached ();
121 drag_begin_handl (GtkWidget *widget,
122 GdkDragContext *context,
125 DND_IMAGE = gtk_image_new_from_file (svg);
126 GdkPixbuf *pix = gtk_image_get_pixbuf (GTK_IMAGE (DND_IMAGE));
127 gtk_drag_set_icon_pixbuf (context, pix, 0, 0);
131 drag_end_handl (GtkWidget *widget,
132 GdkDragContext *context,
137 gtk_widget_destroy (GTK_WIDGET (DND_IMAGE));