Codepage messages related translated & other stuff...
[midnight-commander.git] / gtkedit / xdnd.h
blob98467e5a342d43bfc942e7402de4ae4dfbafed61
1 /* xdnd.c, xdnd.h - C program library for handling the Xdnd protocol
2 Copyright (C) 1998 Paul Sheer
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307, USA.
20 #ifndef _X_DND_H
21 #define _X_DND_H
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
27 /* you can set this to either 2 (which support 0 and 1 as well) or 3 */
28 #define XDND_VERSION 2
29 /* #define XDND_VERSION 3 */
32 /* XdndEnter */
33 #define XDND_THREE 3
34 #define XDND_ENTER_SOURCE_WIN(e) ((e)->xclient.data.l[0])
35 #define XDND_ENTER_THREE_TYPES(e) (((e)->xclient.data.l[1] & 0x1UL) == 0)
36 #define XDND_ENTER_THREE_TYPES_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
37 #define XDND_ENTER_VERSION(e) ((e)->xclient.data.l[1] >> 24)
38 #define XDND_ENTER_VERSION_SET(e,v) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~(0xFF << 24)) | ((v) << 24)
39 #define XDND_ENTER_TYPE(e,i) ((e)->xclient.data.l[2 + i]) /* i => (0, 1, 2) */
41 /* XdndPosition */
42 #define XDND_POSITION_SOURCE_WIN(e) ((e)->xclient.data.l[0])
43 #define XDND_POSITION_ROOT_X(e) ((e)->xclient.data.l[2] >> 16)
44 #define XDND_POSITION_ROOT_Y(e) ((e)->xclient.data.l[2] & 0xFFFFUL)
45 #define XDND_POSITION_ROOT_SET(e,x,y) (e)->xclient.data.l[2] = ((x) << 16) | ((y) & 0xFFFFUL)
46 #define XDND_POSITION_TIME(e) ((e)->xclient.data.l[3])
47 #define XDND_POSITION_ACTION(e) ((e)->xclient.data.l[4])
49 /* XdndStatus */
50 #define XDND_STATUS_TARGET_WIN(e) ((e)->xclient.data.l[0])
51 #define XDND_STATUS_WILL_ACCEPT(e) ((e)->xclient.data.l[1] & 0x1L)
52 #define XDND_STATUS_WILL_ACCEPT_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
53 #define XDND_STATUS_WANT_POSITION(e) ((e)->xclient.data.l[1] & 0x2UL)
54 #define XDND_STATUS_WANT_POSITION_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x2UL) | (((b) == 0) ? 0 : 0x2UL)
55 #define XDND_STATUS_RECT_X(e) ((e)->xclient.data.l[2] >> 16)
56 #define XDND_STATUS_RECT_Y(e) ((e)->xclient.data.l[2] & 0xFFFFL)
57 #define XDND_STATUS_RECT_WIDTH(e) ((e)->xclient.data.l[3] >> 16)
58 #define XDND_STATUS_RECT_HEIGHT(e) ((e)->xclient.data.l[3] & 0xFFFFL)
59 #define XDND_STATUS_RECT_SET(e,x,y,w,h) {(e)->xclient.data.l[2] = ((x) << 16) | ((y) & 0xFFFFUL); (e)->xclient.data.l[3] = ((w) << 16) | ((h) & 0xFFFFUL); }
60 #define XDND_STATUS_ACTION(e) ((e)->xclient.data.l[4])
62 /* XdndLeave */
63 #define XDND_LEAVE_SOURCE_WIN(e) ((e)->xclient.data.l[0])
65 /* XdndDrop */
66 #define XDND_DROP_SOURCE_WIN(e) ((e)->xclient.data.l[0])
67 #define XDND_DROP_TIME(e) ((e)->xclient.data.l[2])
69 /* XdndFinished */
70 #define XDND_FINISHED_TARGET_WIN(e) ((e)->xclient.data.l[0])
72 struct _DndCursor {
73 int width, height;
74 int x, y;
75 unsigned char *image_data, *mask_data;
76 char *_action;
77 Pixmap image_pixmap, mask_pixmap;
78 Cursor cursor;
79 Atom action;
82 typedef struct _DndCursor DndCursor;
83 typedef struct _DndClass DndClass;
85 struct _DndClass {
86 /* insert chars sequentionally into the target widget, type will be the same as `desired_type'
87 returned from widget_apply_position. This may be called several times in succession
88 with sequention blocks of data. Must return non-zero on failure */
89 int (*widget_insert_drop) (DndClass * dnd, unsigned char *data, int length, int remaining, Window into, Window from, Atom type);
91 /* In response to DELETE requests : FIXME - not yet used */
92 int (*widget_delete_selection) (DndClass * dnd, Window window, Window from);
94 /* returns 1 if widget exists, zero otherwise. If this method is not
95 set then the code assumes that no widgets have support for recieving drops.
96 In this case none of the widget methods need be set. */
97 int (*widget_exists) (DndClass * dnd, Window window);
99 /* must update the widgets border to its default appearance */
100 void (*widget_apply_leave) (DndClass * dnd, Window widgets_window);
102 /* must update the widgets border to give the appearance of being able to recieve a drop,
103 plus return all data to pointers. As per the protocol, if the widget cannot
104 perform the action specified by `action' then it should return either XdndActionPrivate
105 or XdndActionCopy into supported_action (leaving 0 supported_action unchanged is equivalent
106 to XdndActionCopy). Returns 1 if ready to ok drop */
107 int (*widget_apply_position) (DndClass * dnd, Window widgets_window, Window from,
108 Atom action, int x, int y, Time t, Atom * typelist,
109 int *want_position, Atom * supported_action, Atom * desired_type,
110 XRectangle * rectangle);
112 /* returns drag data of the specified type. This will be one of `typelist' given to xdnd_drag */
113 void (*widget_get_data) (DndClass * dnd, Window window, unsigned char **data, int *length, Atom type);
115 /* this is called from with the main event loop if an expose event is recieved and is optional */
116 void (*handle_expose_events) (DndClass * dnd, XEvent * xevent);
118 /* creates a chooser dialog if the action is XdndActionAsk. Returns non-zero on cancel */
119 int (*action_choose_dialog) (DndClass * dnd, char **descriptions, Atom * actions, Atom * result);
121 void *pad1[8];
123 DndCursor *cursors;
125 Display *display;
127 Atom XdndAware;
128 Atom XdndSelection;
129 Atom XdndEnter;
130 Atom XdndLeave;
131 Atom XdndPosition;
132 Atom XdndDrop;
133 Atom XdndFinished;
134 Atom XdndStatus;
135 Atom XdndActionCopy;
136 Atom XdndActionMove;
137 Atom XdndActionLink;
138 Atom XdndActionAsk;
139 Atom XdndActionPrivate;
140 Atom XdndTypeList;
141 Atom XdndActionList;
142 Atom XdndActionDescription;
144 Atom Xdnd_NON_PROTOCOL_ATOM;
145 Atom version;
147 Atom pad2[16];
149 Window root_window;
151 #define XDND_DROP_STAGE_IDLE 0
152 #define XDND_DRAG_STAGE_DRAGGING 1
153 #define XDND_DRAG_STAGE_ENTERED 2
154 #define XDND_DROP_STAGE_CONVERTING 3
155 #define XDND_DROP_STAGE_ENTERED 4
156 int stage;
157 int dragging_version;
158 int internal_drag;
159 int want_position;
160 int ready_to_drop;
161 int will_accept;
162 XRectangle rectangle;
163 Window dropper_window, dragger_window;
164 Atom *dragger_typelist;
165 Atom desired_type;
166 Atom supported_action;
167 Time time;
168 /* drop position from last XdndPosition */
169 int x, y;
170 int pad3[16];
172 /* move euclidian pixels before considering this to be an actual drag */
173 float drag_threshold;
175 /* block for only this many seconds on not receiving a XdndFinished from target, default : 10 */
176 int time_out;
178 #define XDND_OPTION_NO_HYSTERESIS (1<<0)
179 int options;
181 /* user hooks */
182 void *user_hook1;
183 void *user_hook2;
184 void *user_hook3;
185 void *pad4[16];
188 void xdnd_init (DndClass * dnd, Display * display);
189 void xdnd_shut (DndClass *dnd);
190 void xdnd_set_dnd_aware (DndClass * dnd, Window window, Atom * typelist);
191 int xdnd_is_dnd_aware (DndClass * dnd, Window window, int *version, Atom * typelist);
192 void xdnd_set_type_list (DndClass * dnd, Window window, Atom * typelist);
193 void xdnd_set_actions (DndClass * dnd, Window window, Atom * actions, char **descriptions);
194 int xdnd_get_actions (DndClass * dnd, Window window, Atom ** actions, char ***descriptions);
195 int xdnd_choose_action_dialog (DndClass * dnd, Atom * actions, char **descriptions, Atom * result);
196 void xdnd_send_enter (DndClass * dnd, Window window, Window from, Atom * typelist);
197 void xdnd_send_position (DndClass * dnd, Window window, Window from, Atom action, int x, int y, unsigned long etime);
198 void xdnd_send_status (DndClass * dnd, Window window, Window from, int will_accept,
199 int want_position, int x, int y, int w, int h, Atom action);
200 void xdnd_send_leave (DndClass * dnd, Window window, Window from);
201 void xdnd_send_drop (DndClass * dnd, Window window, Window from, unsigned long etime);
202 void xdnd_send_finished (DndClass * dnd, Window window, Window from, int error);
203 int xdnd_convert_selection (DndClass * dnd, Window window, Window requester, Atom type);
204 void xdnd_selection_send (DndClass * dnd, XSelectionRequestEvent * request, unsigned char *data, int length);
205 int xdnd_get_selection (DndClass * dnd, Window from, Atom property, Window insert);
206 Atom xdnd_drag (DndClass * dnd, Window from, Atom action, Atom * typelist);
208 /* Returns 1 if event is handled, This must be placed in the widget libraries main event
209 loop and be called if the event type is ClientMessage or SelectionNotify */
210 int xdnd_handle_drop_events (DndClass * dnd, XEvent * xevent);
211 Atom xdnd_get_drop (Display * display, XEvent * xevent, Atom * typelist, Atom * actionlist,
212 unsigned char **data, int *length, Atom * type, int *x, int *y);
214 #ifdef __cplusplus
216 #endif
218 #endif /* !_X_DND_H */