1 /* -*- Mode: C; indent-tabs-mode: f; c-basic-offset: 4; tab-width: 4 -*- */
2 
3 /* nemo-dnd.h - Common Drag & drop handling code shared by the icon container
4    and the list view.
5 
6    Copyright (C) 2000 Eazel, Inc.
7 
8    The Gnome Library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Library General Public License as
10    published by the Free Software Foundation; either version 2 of the
11    License, or (at your option) any later version.
12 
13    The Gnome Library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Library General Public License for more details.
17 
18    You should have received a copy of the GNU Library General Public
19    License along with the Gnome Library; see the file COPYING.LIB.  If not,
20    write to the Free Software Foundation, Inc., 51 Franklin Street - Suite 500,
21    Boston, MA 02110-1335, USA.
22 
23    Authors: Pavel Cisler <pavel@eazel.com>,
24 	    Ettore Perazzoli <ettore@gnu.org>
25 */
26 
27 #ifndef NEMO_DND_H
28 #define NEMO_DND_H
29 
30 #include <gtk/gtk.h>
31 
32 /* Drag & Drop target names. */
33 #define NEMO_ICON_DND_GNOME_ICON_LIST_TYPE	"x-special/gnome-icon-list"
34 #define NEMO_ICON_DND_URI_LIST_TYPE		"text/uri-list"
35 #define NEMO_ICON_DND_NETSCAPE_URL_TYPE	"_NETSCAPE_URL"
36 #define NEMO_ICON_DND_BGIMAGE_TYPE		"property/bgimage"
37 #define NEMO_ICON_DND_ROOTWINDOW_DROP_TYPE	"application/x-rootwindow-drop"
38 #define NEMO_ICON_DND_XDNDDIRECTSAVE_TYPE	"XdndDirectSave0" /* XDS Protocol Type */
39 #define NEMO_ICON_DND_RAW_TYPE	"application/octet-stream"
40 
41 /* Item of the drag selection list */
42 typedef struct {
43 	char *uri;
44 	gboolean got_icon_position;
45 	int icon_x, icon_y;
46 	int icon_width, icon_height;
47 } NemoDragSelectionItem;
48 
49 /* Standard Drag & Drop types. */
50 typedef enum {
51 	NEMO_ICON_DND_GNOME_ICON_LIST,
52 	NEMO_ICON_DND_URI_LIST,
53 	NEMO_ICON_DND_NETSCAPE_URL,
54 	NEMO_ICON_DND_TEXT,
55 	NEMO_ICON_DND_XDNDDIRECTSAVE,
56 	NEMO_ICON_DND_RAW,
57 	NEMO_ICON_DND_ROOTWINDOW_DROP
58 } NemoIconDndTargetType;
59 
60 typedef enum {
61 	NEMO_DND_ACTION_FIRST = GDK_ACTION_ASK << 1,
62 	NEMO_DND_ACTION_SET_AS_BACKGROUND = NEMO_DND_ACTION_FIRST << 0,
63 	NEMO_DND_ACTION_SET_AS_FOLDER_BACKGROUND = NEMO_DND_ACTION_FIRST << 1,
64 	NEMO_DND_ACTION_SET_AS_GLOBAL_BACKGROUND = NEMO_DND_ACTION_FIRST << 2
65 } NemoDndAction;
66 
67 /* drag&drop-related information. */
68 typedef struct {
69 	GtkTargetList *target_list;
70 
71     gchar *source_fs;
72     gboolean can_delete_source;
73 
74 	/* Stuff saved at "receive data" time needed later in the drag. */
75 	gboolean got_drop_data_type;
76 	NemoIconDndTargetType data_type;
77 	GtkSelectionData *selection_data;
78 	char *direct_save_uri;
79 
80 	/* Start of the drag, in window coordinates. */
81 	int start_x, start_y;
82 
83 	/* List of NemoDragSelectionItems, representing items being dragged, or NULL
84 	 * if data about them has not been received from the source yet.
85 	 */
86 	GList *selection_list;
87 
88 	/* has the drop occured ? */
89 	gboolean drop_occured;
90 
91 	/* whether or not need to clean up the previous dnd data */
92 	gboolean need_to_destroy;
93 
94 	/* autoscrolling during dragging */
95 	int auto_scroll_timeout_id;
96 	gboolean waiting_to_autoscroll;
97 	gint64 start_auto_scroll_in;
98 
99 } NemoDragInfo;
100 
101 typedef void		(* NemoDragEachSelectedItemDataGet)	(const char *url,
102 								 int x, int y, int w, int h,
103 								 gpointer data);
104 typedef void		(* NemoDragEachSelectedItemIterator)	(NemoDragEachSelectedItemDataGet iteratee,
105 								 gpointer iterator_context,
106 								 gpointer data);
107 
108 void			    nemo_drag_init				(NemoDragInfo		      *drag_info,
109 									 const GtkTargetEntry		      *drag_types,
110 									 int				       drag_type_count,
111 									 gboolean			       add_text_targets);
112 void			    nemo_drag_finalize			(NemoDragInfo		      *drag_info);
113 NemoDragSelectionItem  *nemo_drag_selection_item_new		(void);
114 void			    nemo_drag_destroy_selection_list	(GList				      *selection_list);
115 GList			   *nemo_drag_build_selection_list		(GtkSelectionData		      *data);
116 
117 char **			    nemo_drag_uri_array_from_selection_list (const GList			      *selection_list);
118 GList *			    nemo_drag_uri_list_from_selection_list	(const GList			      *selection_list);
119 
120 char **			    nemo_drag_uri_array_from_list		(const GList			      *uri_list);
121 GList *			    nemo_drag_uri_list_from_array		(const char			     **uris);
122 
123 gboolean		    nemo_drag_items_local			(const char			      *target_uri,
124 									 const GList			      *selection_list);
125 gboolean		    nemo_drag_uris_local			(const char			      *target_uri,
126 									 const GList			      *source_uri_list);
127 gboolean		    nemo_drag_items_in_trash		(const GList			      *selection_list);
128 gboolean		    nemo_drag_items_on_desktop		(const GList			      *selection_list);
129 void                nemo_drag_default_drop_action_for_icons (GdkDragContext *context,
130                                                              const char     *target_uri_string,
131                                                              const GList    *items,
132                                                              int            *action,
133                                                              gchar         **source_fs,
134                                                              gboolean       *can_delete_source);
135 GdkDragAction		    nemo_drag_default_drop_action_for_netscape_url (GdkDragContext			     *context);
136 GdkDragAction		    nemo_drag_default_drop_action_for_uri_list     (GdkDragContext			     *context,
137 										const char			     *target_uri_string);
138 gboolean		    nemo_drag_drag_data_get			(GtkWidget			      *widget,
139 									 GdkDragContext			      *context,
140 									 GtkSelectionData		      *selection_data,
141 									 guint				       info,
142 									 guint32			       time,
143 									 gpointer			       container_context,
144 									 NemoDragEachSelectedItemIterator  each_selected_item_iterator);
145 int			    nemo_drag_modifier_based_action		(int				       default_action,
146 									 int				       non_default_action);
147 
148 GdkDragAction		    nemo_drag_drop_action_ask		(GtkWidget			      *widget,
149 									 GdkDragAction			       possible_actions);
150 
151 gboolean		    nemo_drag_autoscroll_in_scroll_region	(GtkWidget			      *widget);
152 void			    nemo_drag_autoscroll_calculate_delta	(GtkWidget			      *widget,
153 									 float				      *x_scroll_delta,
154 									 float				      *y_scroll_delta);
155 void			    nemo_drag_autoscroll_start		(NemoDragInfo		      *drag_info,
156 									 GtkWidget			      *widget,
157 									 GSourceFunc			       callback,
158 									 gpointer			       user_data);
159 void			    nemo_drag_autoscroll_stop		(NemoDragInfo		      *drag_info);
160 
161 gboolean		    nemo_drag_selection_includes_special_link (GList			      *selection_list);
162 
163 #endif
164