1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ 2 3 /* caja-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 Mate 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 Mate 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 Mate Library; see the file COPYING.LIB. If not, 20 write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 21 Boston, MA 02110-1301, USA. 22 23 Authors: Pavel Cisler <pavel@eazel.com>, 24 Ettore Perazzoli <ettore@gnu.org> 25 */ 26 27 #ifndef CAJA_DND_H 28 #define CAJA_DND_H 29 30 #include <gtk/gtk.h> 31 32 #include "caja-window-slot-info.h" 33 34 /* Drag & Drop target names. */ 35 #define CAJA_ICON_DND_MATE_ICON_LIST_TYPE "x-special/mate-icon-list" 36 #define CAJA_ICON_DND_URI_LIST_TYPE "text/uri-list" 37 #define CAJA_ICON_DND_NETSCAPE_URL_TYPE "_NETSCAPE_URL" 38 #define CAJA_ICON_DND_COLOR_TYPE "application/x-color" 39 #define CAJA_ICON_DND_BGIMAGE_TYPE "property/bgimage" 40 #define CAJA_ICON_DND_KEYWORD_TYPE "property/keyword" 41 #define CAJA_ICON_DND_RESET_BACKGROUND_TYPE "x-special/mate-reset-background" 42 #define CAJA_ICON_DND_ROOTWINDOW_DROP_TYPE "application/x-rootwindow-drop" 43 #define CAJA_ICON_DND_XDNDDIRECTSAVE_TYPE "XdndDirectSave0" /* XDS Protocol Type */ 44 #define CAJA_ICON_DND_RAW_TYPE "application/octet-stream" 45 46 /* Item of the drag selection list */ 47 typedef struct 48 { 49 char *uri; 50 gboolean got_icon_position; 51 int icon_x, icon_y; 52 int icon_width, icon_height; 53 } CajaDragSelectionItem; 54 55 /* Standard Drag & Drop types. */ 56 typedef enum 57 { 58 CAJA_ICON_DND_MATE_ICON_LIST, 59 CAJA_ICON_DND_URI_LIST, 60 CAJA_ICON_DND_NETSCAPE_URL, 61 CAJA_ICON_DND_COLOR, 62 CAJA_ICON_DND_BGIMAGE, 63 CAJA_ICON_DND_KEYWORD, 64 CAJA_ICON_DND_TEXT, 65 CAJA_ICON_DND_RESET_BACKGROUND, 66 CAJA_ICON_DND_XDNDDIRECTSAVE, 67 CAJA_ICON_DND_RAW, 68 CAJA_ICON_DND_ROOTWINDOW_DROP 69 } CajaIconDndTargetType; 70 71 typedef enum 72 { 73 CAJA_DND_ACTION_FIRST = GDK_ACTION_ASK << 1, 74 CAJA_DND_ACTION_SET_AS_BACKGROUND = CAJA_DND_ACTION_FIRST << 0, 75 CAJA_DND_ACTION_SET_AS_FOLDER_BACKGROUND = CAJA_DND_ACTION_FIRST << 1, 76 CAJA_DND_ACTION_SET_AS_GLOBAL_BACKGROUND = CAJA_DND_ACTION_FIRST << 2 77 } CajaDndAction; 78 79 /* drag&drop-related information. */ 80 typedef struct 81 { 82 GtkTargetList *target_list; 83 84 /* Stuff saved at "receive data" time needed later in the drag. */ 85 gboolean got_drop_data_type; 86 CajaIconDndTargetType data_type; 87 GtkSelectionData *selection_data; 88 char *direct_save_uri; 89 90 /* Start of the drag, in window coordinates. */ 91 int start_x, start_y; 92 93 /* List of CajaDragSelectionItems, representing items being dragged, or NULL 94 * if data about them has not been received from the source yet. 95 */ 96 GList *selection_list; 97 98 /* has the drop occured ? */ 99 gboolean drop_occured; 100 101 /* whether or not need to clean up the previous dnd data */ 102 gboolean need_to_destroy; 103 104 /* autoscrolling during dragging */ 105 int auto_scroll_timeout_id; 106 gboolean waiting_to_autoscroll; 107 gint64 start_auto_scroll_in; 108 109 } CajaDragInfo; 110 111 typedef struct 112 { 113 /* NB: the following elements are managed by us */ 114 gboolean have_data; 115 gboolean have_valid_data; 116 117 gboolean drop_occured; 118 119 unsigned int info; 120 union 121 { 122 GList *selection_list; 123 GList *uri_list; 124 char *netscape_url; 125 } data; 126 127 /* NB: the following elements are managed by the caller of 128 * caja_drag_slot_proxy_init() */ 129 130 /* a fixed location, or NULL to use slot's location */ 131 GFile *target_location; 132 /* a fixed slot, or NULL to use the window's active slot */ 133 CajaWindowSlotInfo *target_slot; 134 } CajaDragSlotProxyInfo; 135 136 typedef void (* CajaDragEachSelectedItemDataGet) (const char *url, 137 int x, int y, int w, int h, 138 gpointer data); 139 typedef void (* CajaDragEachSelectedItemIterator) (CajaDragEachSelectedItemDataGet iteratee, 140 gpointer iterator_context, 141 gpointer data); 142 143 void caja_drag_init (CajaDragInfo *drag_info, 144 const GtkTargetEntry *drag_types, 145 int drag_type_count, 146 gboolean add_text_targets); 147 void caja_drag_finalize (CajaDragInfo *drag_info); 148 CajaDragSelectionItem *caja_drag_selection_item_new (void); 149 void caja_drag_destroy_selection_list (GList *selection_list); 150 GList *caja_drag_build_selection_list (GtkSelectionData *data); 151 152 GList * caja_drag_uri_list_from_selection_list (const GList *selection_list); 153 154 GList * caja_drag_uri_list_from_array (const char **uris); 155 156 gboolean caja_drag_items_local (const char *target_uri, 157 const GList *selection_list); 158 gboolean caja_drag_uris_local (const char *target_uri, 159 const GList *source_uri_list); 160 gboolean caja_drag_items_on_desktop (const GList *selection_list); 161 void caja_drag_default_drop_action_for_icons (GdkDragContext *context, 162 const char *target_uri, 163 const GList *items, 164 int *action); 165 GdkDragAction caja_drag_default_drop_action_for_netscape_url (GdkDragContext *context); 166 GdkDragAction caja_drag_default_drop_action_for_uri_list (GdkDragContext *context, 167 const char *target_uri_string); 168 gboolean caja_drag_drag_data_get (GtkWidget *widget, 169 GdkDragContext *context, 170 GtkSelectionData *selection_data, 171 guint info, 172 guint32 time, 173 gpointer container_context, 174 CajaDragEachSelectedItemIterator each_selected_item_iterator); 175 int caja_drag_modifier_based_action (int default_action, 176 int non_default_action); 177 178 GdkDragAction caja_drag_drop_action_ask (GtkWidget *widget, 179 GdkDragAction possible_actions); 180 GdkDragAction caja_drag_drop_background_ask (GtkWidget *widget, 181 GdkDragAction possible_actions); 182 183 gboolean caja_drag_autoscroll_in_scroll_region (GtkWidget *widget); 184 void caja_drag_autoscroll_calculate_delta (GtkWidget *widget, 185 float *x_scroll_delta, 186 float *y_scroll_delta); 187 void caja_drag_autoscroll_start (CajaDragInfo *drag_info, 188 GtkWidget *widget, 189 GSourceFunc callback, 190 gpointer user_data); 191 void caja_drag_autoscroll_stop (CajaDragInfo *drag_info); 192 193 gboolean caja_drag_selection_includes_special_link (GList *selection_list); 194 195 void caja_drag_slot_proxy_init (GtkWidget *widget, 196 CajaDragSlotProxyInfo *drag_info); 197 198 #endif 199