* gcustom-layout.c, gprefs.c: Make the preferences dialog
[midnight-commander.git] / gtkedit / xdnd.h
blob227804bb7196eab9557d32990f6c026b56dfb4c9
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., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef _X_DND_H
20 #define _X_DND_H
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
26 #define XDND_VERSION 2
28 /* XdndEnter */
29 #define XDND_THREE 3
30 #define XDND_ENTER_SOURCE_WIN(e) ((e)->xclient.data.l[0])
31 #define XDND_ENTER_THREE_TYPES(e) (((e)->xclient.data.l[1] & 0x1UL) == 0)
32 #define XDND_ENTER_THREE_TYPES_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
33 #define XDND_ENTER_VERSION(e) ((e)->xclient.data.l[1] >> 24)
34 #define XDND_ENTER_VERSION_SET(e,v) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~(0xFF << 24)) | ((v) << 24)
35 #define XDND_ENTER_TYPE(e,i) ((e)->xclient.data.l[2 + i]) /* i => (0, 1, 2) */
37 /* XdndPosition */
38 #define XDND_POSITION_SOURCE_WIN(e) ((e)->xclient.data.l[0])
39 #define XDND_POSITION_ROOT_X(e) ((e)->xclient.data.l[2] >> 16)
40 #define XDND_POSITION_ROOT_Y(e) ((e)->xclient.data.l[2] & 0xFFFFUL)
41 #define XDND_POSITION_ROOT_SET(e,x,y) (e)->xclient.data.l[2] = ((x) << 16) | ((y) & 0xFFFFUL)
42 #define XDND_POSITION_TIME(e) ((e)->xclient.data.l[3])
43 #define XDND_POSITION_ACTION(e) ((e)->xclient.data.l[4])
45 /* XdndStatus */
46 #define XDND_STATUS_TARGET_WIN(e) ((e)->xclient.data.l[0])
47 #define XDND_STATUS_WILL_ACCEPT(e) ((e)->xclient.data.l[1] & 0x1L)
48 #define XDND_STATUS_WILL_ACCEPT_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
49 #define XDND_STATUS_WANT_POSITION(e) ((e)->xclient.data.l[1] & 0x2UL)
50 #define XDND_STATUS_WANT_POSITION_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x2UL) | (((b) == 0) ? 0 : 0x2UL)
51 #define XDND_STATUS_RECT_X(e) ((e)->xclient.data.l[2] >> 16)
52 #define XDND_STATUS_RECT_Y(e) ((e)->xclient.data.l[2] & 0xFFFFL)
53 #define XDND_STATUS_RECT_WIDTH(e) ((e)->xclient.data.l[3] >> 16)
54 #define XDND_STATUS_RECT_HEIGHT(e) ((e)->xclient.data.l[3] & 0xFFFFL)
55 #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); }
56 #define XDND_STATUS_ACTION(e) ((e)->xclient.data.l[4])
58 /* XdndLeave */
59 #define XDND_LEAVE_SOURCE_WIN(e) ((e)->xclient.data.l[0])
61 /* XdndDrop */
62 #define XDND_DROP_SOURCE_WIN(e) ((e)->xclient.data.l[0])
63 #define XDND_DROP_TIME(e) ((e)->xclient.data.l[2])
65 /* XdndFinished */
66 #define XDND_FINISHED_TARGET_WIN(e) ((e)->xclient.data.l[0])
68 struct _DndCursor {
69 int width, height;
70 int x, y;
71 unsigned char *image_data, *mask_data;
72 char *_action;
73 Pixmap image_pixmap, mask_pixmap;
74 Cursor cursor;
75 Atom action;
78 typedef struct _DndCursor DndCursor;
79 typedef struct _DndClass DndClass;
81 struct _DndClass {
82 /* insert chars sequentionally into the target widget, type will be the same as `desired_type'
83 returned from widget_apply_position. This may be called several times in succession
84 with sequention blocks of data. Must return non-zero on failure */
85 int (*widget_insert_drop) (DndClass * dnd, unsigned char *data, int length, int remaining, Window into, Window from, Atom type);
87 /* In response to DELETE requests : FIXME - not yet used */
88 int (*widget_delete_selection) (DndClass * dnd, Window window, Window from);
90 /* returns 1 if widget exists, zero otherwise. If this method is not
91 set then the code assumes that no widgets have support for recieving drops.
92 In this case none of the widget methods need be set. */
93 int (*widget_exists) (DndClass * dnd, Window window);
95 /* must update the widgets border to its default appearance */
96 void (*widget_apply_leave) (DndClass * dnd, Window widgets_window);
98 /* must update the widgets border to give the appearance of being able to recieve a drop,
99 plus return all data to pointers. As per the protocol, if the widget cannot
100 perform the action specified by `action' then it should return either XdndActionPrivate
101 or XdndActionCopy into supported_action (leaving 0 supported_action unchanged is equivalent
102 to XdndActionCopy). Returns 1 if ready to ok drop */
103 int (*widget_apply_position) (DndClass * dnd, Window widgets_window, Window from,
104 Atom action, int x, int y, Time t, Atom * typelist,
105 int *want_position, Atom * supported_action, Atom * desired_type,
106 XRectangle * rectangle);
108 /* returns drag data of the specified type. This will be one of `typelist' given to xdnd_drag */
109 void (*widget_get_data) (DndClass * dnd, Window window, unsigned char **data, int *length, Atom type);
111 /* this is called from with the main event loop if an expose event is recieved and is optional */
112 void (*handle_expose_events) (DndClass * dnd, XEvent * xevent);
114 /* creates a chooser dialog if the action is XdndActionAsk. Returns non-zero on cancel */
115 int (*action_choose_dialog) (DndClass * dnd, char **descriptions, Atom * actions, Atom * result);
117 void *pad1[8];
119 DndCursor *cursors;
121 Display *display;
123 Atom XdndAware;
124 Atom XdndSelection;
125 Atom XdndEnter;
126 Atom XdndLeave;
127 Atom XdndPosition;
128 Atom XdndDrop;
129 Atom XdndFinished;
130 Atom XdndStatus;
131 Atom XdndActionCopy;
132 Atom XdndActionMove;
133 Atom XdndActionLink;
134 Atom XdndActionAsk;
135 Atom XdndActionPrivate;
136 Atom XdndTypeList;
137 Atom XdndActionList;
138 Atom XdndActionDescription;
140 Atom Xdnd_NON_PROTOCOL_ATOM;
141 Atom version;
143 Atom pad2[16];
145 Window root_window;
147 #define XDND_DROP_STAGE_IDLE 0
148 #define XDND_DRAG_STAGE_DRAGGING 1
149 #define XDND_DRAG_STAGE_ENTERED 2
150 #define XDND_DROP_STAGE_CONVERTING 3
151 #define XDND_DROP_STAGE_ENTERED 4
152 int stage;
153 int dragging_version;
154 int internal_drag;
155 int want_position;
156 int ready_to_drop;
157 int will_accept;
158 XRectangle rectangle;
159 Window dropper_window, dragger_window;
160 Atom *dragger_typelist;
161 Atom desired_type;
162 Atom supported_action;
163 Time time;
164 /* drop position from last XdndPosition */
165 int x, y;
166 int pad3[16];
168 /* move euclidian pixels before considering this to be an actual drag */
169 float drag_threshold;
171 /* block for only this many seconds on not receiving a XdndFinished from target, default : 10 */
172 int time_out;
174 #define XDND_OPTION_NO_HYSTERESIS (1<<0)
175 int options;
177 /* user hooks */
178 void *user_hook1;
179 void *user_hook2;
180 void *user_hook3;
181 void *pad4[16];
184 void xdnd_init (DndClass * dnd, Display * display);
185 void xdnd_shut (DndClass *dnd);
186 void xdnd_set_dnd_aware (DndClass * dnd, Window window, Atom * typelist);
187 int xdnd_is_dnd_aware (DndClass * dnd, Window window, int *version, Atom * typelist);
188 void xdnd_set_type_list (DndClass * dnd, Window window, Atom * typelist);
189 void xdnd_set_actions (DndClass * dnd, Window window, Atom * actions, char **descriptions);
190 int xdnd_get_actions (DndClass * dnd, Window window, Atom ** actions, char ***descriptions);
191 int xdnd_choose_action_dialog (DndClass * dnd, Atom * actions, char **descriptions, Atom * result);
192 void xdnd_send_enter (DndClass * dnd, Window window, Window from, Atom * typelist);
193 void xdnd_send_position (DndClass * dnd, Window window, Window from, Atom action, int x, int y, unsigned long etime);
194 void xdnd_send_status (DndClass * dnd, Window window, Window from, int will_accept,
195 int want_position, int x, int y, int w, int h, Atom action);
196 void xdnd_send_leave (DndClass * dnd, Window window, Window from);
197 void xdnd_send_drop (DndClass * dnd, Window window, Window from, unsigned long etime);
198 void xdnd_send_finished (DndClass * dnd, Window window, Window from, int error);
199 int xdnd_convert_selection (DndClass * dnd, Window window, Window requester, Atom type);
200 void xdnd_selection_send (DndClass * dnd, XSelectionRequestEvent * request, unsigned char *data, int length);
201 int xdnd_get_selection (DndClass * dnd, Window from, Atom property, Window insert);
202 Atom xdnd_drag (DndClass * dnd, Window from, Atom action, Atom * typelist);
204 /* Returns 1 if event is handled, This must be placed in the widget libraries main event
205 loop and be called if the event type is ClientMessage or SelectionNotify */
206 int xdnd_handle_drop_events (DndClass * dnd, XEvent * xevent);
207 Atom xdnd_get_drop (Display * display, XEvent * xevent, Atom * typelist, Atom * actionlist,
208 unsigned char **data, int *length, Atom * type, int *x, int *y);
210 #ifdef __cplusplus
212 #endif
214 #endif /* !_X_DND_H */