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
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 */
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) */
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])
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])
63 #define XDND_LEAVE_SOURCE_WIN(e) ((e)->xclient.data.l[0])
66 #define XDND_DROP_SOURCE_WIN(e) ((e)->xclient.data.l[0])
67 #define XDND_DROP_TIME(e) ((e)->xclient.data.l[2])
70 #define XDND_FINISHED_TARGET_WIN(e) ((e)->xclient.data.l[0])
75 unsigned char *image_data
, *mask_data
;
77 Pixmap image_pixmap
, mask_pixmap
;
82 typedef struct _DndCursor DndCursor
;
83 typedef struct _DndClass 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
);
139 Atom XdndActionPrivate
;
142 Atom XdndActionDescription
;
144 Atom Xdnd_NON_PROTOCOL_ATOM
;
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
157 int dragging_version
;
162 XRectangle rectangle
;
163 Window dropper_window
, dragger_window
;
164 Atom
*dragger_typelist
;
166 Atom supported_action
;
168 /* drop position from last XdndPosition */
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 */
178 #define XDND_OPTION_NO_HYSTERESIS (1<<0)
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
);
218 #endif /* !_X_DND_H */