1 /**
2  *
3  * $Id: DragDropI.h,v 1.1 2004/08/28 19:23:29 dannybackx Exp $
4  *
5  * Copyright (C) 1995 Free Software Foundation, Inc.
6  * Copyright (C) 1995-2001 LessTif Development Team
7  *
8  * This file is part of the GNU LessTif Library.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free
22  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  **/
25 
26 /***********************************************************/
27 /* Copyright 1996 Daniel Dardailler.
28 Permission to use, copy, modify, distribute, and sell this software
29 for any purpose is hereby granted without fee, provided that the above
30 copyright notice appear in all copies and that both that copyright
31 notice and this permission notice appear in supporting documentation,
32 and that the name of Daniel Dardailler not be used in advertising or
33 publicity pertaining to distribution of the software without specific,
34 written prior permission.  Daniel Dardailler makes no representations
35 about the suitability of this software for any purpose.  It is
36 provided "as is" without express or implied warranty.
37 ************************************************************/
38 
39 #ifndef _XMI_DRAGDROPI_H
40 #define _XMI_DRAGDROPI_H
41 
42 #include <X11/Xmd.h>
43 
44 #include <Xm/DragCP.h>
45 #include <Xm/DragOverSP.h>
46 
47 /*
48  * for drop transfer
49  */
50 #define XmInheritStartTransferProc \
51 	(XmDropTransferStartTransferProc)(_XtInherit)
52 #define XmInheritAddTransferProc \
53 	(XmDropTransferAddTransferProc)(_XtInherit)
54 
55 /*
56  * for drop site manager
57  */
58 #define XmInheritCreateInfoProc		(XmDSMCreateInfoProc)(_XtInherit)
59 #define XmInheritDestroyInfoProc	(XmDSMDestroyInfoProc)(_XtInherit)
60 #define XmInheritStartUpdateProc	(XmDSMStartUpdateProc)(_XtInherit)
61 #define XmInheritRetrieveInfoProc	(XmDSMRetrieveInfoProc)(_XtInherit)
62 #define XmInheritUpdateInfoProc		(XmDSMUpdateInfoProc)(_XtInherit)
63 #define XmInheritEndUpdateProc		(XmDSMEndUpdateProc)(_XtInherit)
64 #define XmInheritUpdateProc		(XmDSMUpdateProc)(_XtInherit)
65 #define XmInheritProcessMotionProc	(XmDSMProcessMotionProc)(_XtInherit)
66 #define XmInheritProcessDropProc	(XmDSMProcessDropProc)(_XtInherit)
67 #define XmInheritOperationChangedProc	(XmDSMOperationChangedProc)(_XtInherit)
68 #define XmInheritChangeRootProc		(XmDSMChangeRootProc)(_XtInherit)
69 #define XmInheritInsertInfoProc		(XmDSMInsertInfoProc)(_XtInherit)
70 #define XmInheritRemoveInfoProc		(XmDSMRemoveInfoProc)(_XtInherit)
71 #define XmInheritSyncTreeProc		(XmDSMSyncTreeProc)(_XtInherit)
72 #define XmInheritGetTreeFromDSMProc	(XmDSMGetTreeFromDSMProc)(_XtInherit)
73 #define XmInheritCreateDSInfoTable	(XmDSMCreateDSInfoTable)(_XtInherit)
74 #define XmInheritDestroyDSInfoTable	(XmDSMDestroyDSInfoTable)(_XtInherit)
75 #define XmInheritRegisterInfoProc	(XmDSMRegisterInfoProc)(_XtInherit)
76 #define XmInheritWidgetToInfoProc	(XmDSMWidgetToInfoProc)(_XtInherit)
77 #define XmInheritUnregisterInfoProc	(XmDSMUnregisterInfoProc)(_XtInherit)
78 
79 /*
80  * for DragContext
81  */
82 #define XmInheritDragStartProc	(XmDragStartProc)(_XtInherit)
83 #define XmInheritDragCancelProc	(XmDragCancelProc)(_XtInherit)
84 
85 /*
86  * properties
87  */
88 typedef struct _XmDndSourceProp {
89     BYTE	byte_order;
90     BYTE	protocol_version;
91     CARD16	target_index;
92     CARD32	selection;
93 } XmDndSourceProp;
94 
95 typedef struct _XmDndReceiverProp {
96     BYTE	byte_order;
97     BYTE	protocol_version;
98     BYTE	protocol_style;
99     BYTE	pad1;
100     CARD32	proxy_window;
101     CARD16	num_drop_sites;
102     CARD16	pad2;
103     CARD32	total_size;
104 } XmDndReceiverProp;
105 
106 /*
107  * need to use some union hack since window and property are in
108  * different order depending on the message ...
109  */
110 typedef struct _XmDndTop {
111     CARD32	src_window;
112     CARD32	property;
113 } XmDndTop;
114 
115 typedef struct _XmDndPot {
116     INT16	x;
117     INT16	y;
118     CARD32	property;
119     CARD32	src_window;
120 } XmDndPot;
121 
122 typedef struct _XmDndMessage {
123     BYTE	reason;
124     BYTE	byte_order;
125     CARD16	flags;
126     CARD32	time;
127     union {
128 	XmDndTop top;
129 	XmDndPot pot;
130     } data;
131 } XmDndMessage;
132 
133 /*
134  * this structure is reused for DRAG_ATOM_PAIRS and DRAG_ATOMS...
135  */
136 typedef struct _XmDndTargets {
137     BYTE		byte_order;
138     BYTE		protocol_version;
139     CARD16		num_target_lists;
140     CARD32		data_size;
141     /* then come series of CARD16,CARD32,CARD32,CARD32... */
142 } XmDndTargets;
143 
144 typedef struct _XmDndAtomPairs {
145     BYTE		byte_order;
146     BYTE		protocol_version;
147     CARD16		num_pairs;
148     CARD32		data_size;
149 } XmDndAtomPairs;
150 
151 typedef struct _XmDndAtoms {
152     BYTE		byte_order;
153     BYTE		protocol_version;
154     CARD16		num_atoms;
155     CARD32		data_size;
156 } XmDndAtoms;
157 
158 /* protocol version */
159 #define DND_PROTOCOL_VERSION 0
160 
161 #define DND_EVENT_TYPE_MASK  ((BYTE)0x80)
162 #define DND_EVENT_TYPE_SHIFT 7
163 #define DND_CLEAR_EVENT_TYPE  ((BYTE)0x7F)
164 
165 /*
166  * message_type is data[0] of the client_message
167  * this return 1 (receiver bit up) or 0 (initiator)
168  */
169 #define DND_GET_EVENT_TYPE(message_type) \
170   ((char) (((message_type) & DND_EVENT_TYPE_MASK) >> DND_EVENT_TYPE_SHIFT))
171 
172 /*
173  * event_type can be 0 (initiator) or 1 (receiver)
174  */
175 #define DND_SET_EVENT_TYPE(event_type) \
176   (((BYTE)(event_type) << DND_EVENT_TYPE_SHIFT) & DND_EVENT_TYPE_MASK)
177 
178 #define XmINITIATOR	0
179 #define XmRECEIVER	1
180 
181 #define DND_OPERATION_MASK ((CARD16) 0x000F)
182 #define DND_OPERATION_SHIFT 0
183 #define DND_STATUS_MASK ((CARD16) 0x00F0)
184 #define DND_STATUS_SHIFT 4
185 #define DND_OPERATIONS_MASK ((CARD16) 0x0F00)
186 #define DND_OPERATIONS_SHIFT 8
187 #define DND_COMPLETION_MASK ((CARD16) 0xF000)
188 #define DND_COMPLETION_SHIFT 12
189 
190 #define DND_GET_OPERATION(flags) \
191   ((unsigned char) \
192    (((flags) & DND_OPERATION_MASK) >> DND_OPERATION_SHIFT))
193 
194 #define DND_SET_OPERATION(operation) \
195   (((CARD16)(operation) << DND_OPERATION_SHIFT)\
196    & DND_OPERATION_MASK)
197 
198 #define DND_GET_STATUS(flags) \
199   ((unsigned char) \
200    (((flags) & DND_STATUS_MASK) >> DND_STATUS_SHIFT))
201 
202 #define DND_SET_STATUS(status) \
203   (((CARD16)(status) << DND_STATUS_SHIFT)\
204    & DND_STATUS_MASK)
205 
206 #define DND_GET_OPERATIONS(flags) \
207   ((unsigned char) \
208    (((flags) & DND_OPERATIONS_MASK) >> DND_OPERATIONS_SHIFT))
209 
210 #define DND_SET_OPERATIONS(operation) \
211   (((CARD16)(operation) << DND_OPERATIONS_SHIFT)\
212    & DND_OPERATIONS_MASK)
213 
214 #define DND_GET_COMPLETION(flags) \
215   ((unsigned char) \
216    (((flags) & DND_COMPLETION_MASK) >> DND_COMPLETION_SHIFT))
217 
218 #define DND_SET_COMPLETION(completion) \
219   (((CARD16)(completion) << DND_COMPLETION_SHIFT)\
220    & DND_COMPLETION_MASK)
221 
222 
223 #define SWAP4BYTES(l) {\
224 	struct { unsigned t :32;} bit32;\
225         char n,	*tp = (char *) &bit32;\
226 	bit32.t = l;\
227 	n = tp[0]; tp[0] = tp[3]; tp[3] = n;\
228 	n = tp[1]; tp[1] = tp[2]; tp[2] = n;\
229         l = bit32.t;\
230 }
231 
232 #define SWAP2BYTES(s) {\
233 	struct { unsigned t :16; } bit16;\
234         char n, *tp = (char *) &bit16;\
235 	bit16.t = s;\
236 	n = tp[0]; tp[0] = tp[1]; tp[1] = n;\
237         s = bit16.t;\
238 }
239 
240 /***** Targets/Index stuff */
241 
242 typedef struct {
243     CARD32			atom;
244     CARD16			namelen;
245     CARD16			pad;		/* Align to 64 bits */
246 } XmDndAtomPair;
247 
248 typedef struct {
249     Atom			atom;
250     Time			time;
251 } XmDndAtomsTableEntryRec, *XmDndAtomsTableEntry;
252 
253 typedef struct {
254     int				num_entries;
255     XmDndAtomsTableEntry	entries;
256 } XmDndAtomsTableRec, *XmDndAtomsTable;
257 
258 typedef struct {
259     int				num_targets;
260     Atom			*targets;
261 } XmDndTargetsTableEntryRec, *XmDndTargetsTableEntry;
262 
263 typedef struct {
264     int				num_entries;
265     XmDndTargetsTableEntry	entries;
266 } XmDndTargetsTableRec, *XmDndTargetsTable;
267 
268 /*
269  * the next structure is used for reading and writing drag info
270  */
271 typedef struct {
272     char		*atoms;
273     char		*atom_ptr;
274     char		*atom_start;
275     int			atom_size;
276     int			atom_avail;
277     char		*names;
278     char		*name_ptr;
279     char		*name_start;
280     int			name_size;
281     int			name_avail;
282 } XmDndBufMgrRec, *XmDndBufMgr;
283 
284 /*
285  * iccInfo in XmDragReceiverInfoStruct points
286  * to this.
287  */
288 typedef struct _XmShellDropSiteInfo {
289     XmDndBufMgrRec info;
290     unsigned char byte_order;
291     int num_drop_sites;
292 } XmShellDropSiteInfoRec, *XmShellDropSiteInfo;
293 
294 #define DSI_Info(x) \
295     (((XmShellDropSiteInfo)(x))->info)
296 
297 #define DSI_ByteOrder(x) \
298     (((XmShellDropSiteInfo)(x))->byte_order)
299 
300 #define DSI_NumDropSites(x) \
301     (((XmShellDropSiteInfo)(x))->num_drop_sites)
302 
303 /*
304  * this is the per widget drop site info
305  */
306 typedef struct _XmDropSiteInfo {
307 
308     struct _XmDropSiteInfo	*next;
309 
310     Boolean		external;
311     Boolean		leaf;
312     Boolean             implicit;		/* indicates this DS implicitly created */
313     Boolean		isShell;
314     Boolean		userRegion;
315     Boolean		registered;
316 
317     struct _XmDropSiteInfo 	*parent;	/* SIMPLE's pointer to parent */
318     struct _XmDropSiteInfo	**children;	/* list of children in parent */
319 
320     int 	 	inUpdate;
321     short		target_index;
322     short		numChildren;
323     short		maxChildren;
324     XmRegion		region;
325 
326     unsigned char	dropSiteOperations;
327     XtCallbackProc	dragProc;
328     XtCallbackProc	dropProc;
329     Widget		dropSite;
330     unsigned char	dropSiteType;
331     unsigned char	animationStyle;
332     unsigned char	dropSiteActivity;
333     Atom		*importTargets;		/* volatile */
334     Cardinal		numImportTargets;
335     XRectangle		*dropRectangles;	/* volatile */
336     Cardinal		numDropRectangles;
337     Pixmap		animationPixmap;
338     Cardinal		animationPixmapDepth;
339     Pixmap		animationMask;
340 
341 } XmDropSiteInfoRec, *XmDropSiteInfo;
342 
343 /*
344  * this is the table that the drop site manager uses to
345  * store per-widget info
346  */
347 typedef struct {
348     long num_buckets;
349     XmDropSiteInfo *buckets;
350 } DSInfoTable;
351 
352 /*
353  * this is used to pass info to the tree update proc
354  * the numbering picks up where DragC.h leaves off.
355  */
356 #define XmCR_ADD_DROP_SITE	9
357 #define XmCR_REMOVE_DROP_SITE	10
358 
359 typedef struct {
360     int	reason;
361     XEvent *event;
362     Widget widget;
363 } XmTreeUpdateCallbackStruct;
364 
365 /*
366  * for processing drag motion
367  */
368 typedef struct {
369     Time time;
370     Window window;
371     Window subwindow;
372     Position xroot, yroot;
373     unsigned int state;
374 } XmMotionRec;
375 
376 typedef struct {
377     XmDragReceiverInfo	curReceiver;
378     int			num_motions;
379     int			max_motions;
380     XmMotionRec		*motions;
381 } XmMotionBuffer;
382 
383 /*
384  * this union is used as a short cut in DragC.c
385  */
386 typedef union {
387     XmAnyICCCallbackStruct			any;
388     XmTopLevelEnterCallbackStruct		tle;
389     XmTopLevelLeaveCallbackStruct		tll;
390     XmDropSiteEnterCallbackStruct		dse;
391     XmDropSiteLeaveCallbackStruct		dsl;
392     XmDragMotionCallbackStruct			dm;
393     XmOperationChangedCallbackStruct		oc;
394     XmDropStartCallbackStruct			ds;
395     XmDropFinishCallbackStruct			df;
396     XmDragDropFinishCallbackStruct		ddf;
397 } XmDragDropCallbackStruct;
398 
399 /*
400  * these next two are used for notifying the DropSMgr from the DragC.
401  */
402 typedef struct {
403     XmDragOverShellWidget	dos;
404     Boolean			sourceIsExternal;
405     Window			window;
406     Widget			shell;
407     Position			xOrigin, yOrigin;
408     Dimension			width, height;
409     XtPointer			iccInfo;
410 } XmDragTopLevelClientDataStruct;
411 
412 typedef struct {
413     XmDragOverShellWidget	dos;
414     Window			window;
415 } XmDragMotionClientDataStruct;
416 
417 /*
418  * some atoms
419  */
420 #define _XA_MOTIF_DRAG_WINDOW		"_MOTIF_DRAG_WINDOW"
421 #define _XA_MOTIF_DRAG_PROXY_WINDOW	"_MOTIF_DRAG_PROXY_WINDOW"
422 #define _XA_MOTIF_DRAG_ATOM_PAIRS	"_MOTIF_DRAG_ATOM_PAIRS"
423 #define _XA_MOTIF_DRAG_ATOMS		"_MOTIF_DRAG_ATOMS"
424 #define _XA_MOTIF_ATOM_0		"_MOTIF_ATOM_0"
425 #define _XA_MOTIF_ATOM_FORMAT		"_MOTIF_ATOM_%d"
426 #define _XA_MOTIF_DRAG_TARGETS		"_MOTIF_DRAG_TARGETS"
427 #define _XA_MOTIF_DRAG_INITIATOR_INFO	"_MOTIF_DRAG_INITIATOR_INFO"
428 #define _XA_MOTIF_DRAG_RECEIVER_INFO	"_MOTIF_DRAG_RECEIVER_INFO"
429 #define _XA_MOTIF_MESSAGE		"_MOTIF_DRAG_MESSAGE"
430 #define _XA_MOTIF_WM_QUERY_N		"_MOTIF_WM_QUERY_%d"
431 #define _XA_MOTIF_DRAG_AND_DROP_MESSAGE	"_MOTIF_DRAG_AND_DROP_MESSAGE"
432 
433 /* functions */
434 
435 Boolean _XmGetDragReceiverInfo(Display *display, Window win,
436                                XmDragReceiverInfo ri);
437 void _XmSetDragReceiverInfo(Widget w, Widget widget);
438 void _XmClearDragReceiverInfo(Widget shell);
439 void _XmFreeDragReceiverInfo(XmShellDropSiteInfo di);
440 unsigned char _XmByteOrder(void);
441 int _XmMessageTypeToReason(BYTE reason);
442 void _XmICCEventToICCCallback(XmDndMessage *msg, XmDragDropCallbackStruct *cbs);
443 
444 /* DragBS.c */
445 int _XmReadDragBuffer(XmDndBufMgr bmgr, Boolean read_string,
446                       char *retbuf, int bufsize);
447 int _XmWriteDragBuffer(XmDndBufMgr bmgr, Boolean write_string,
448                        char *data, int size);
449 
450 
451 /*
452  * resources from DropSMgrI.c
453  */
454 extern XtResource _XmDSResources[];
455 extern int _XmNumDSResources;
456 /* functions for MBC */
457 void _XmDSIAddChild(void* a, void* b, int c);
458 void _XmDSIRemoveChild(void* a, void* b);
459 void _XmDSIDestroy(void* a, int b);
460 int _XmDSIGetBorderWidth(void* a);
461 int _XmDSIReplaceChild(void* a);
462 int _XmDSIGetChildPosition(void* a, void* b);
463 void _XmDSISwapChildren(void* a, void* b, void* c);
464 
465 /* from TextIn.c */
466 void _Lttext_process_drop(Widget w, XtPointer client_data, XtPointer call_data);
467 
468 
469 #endif /* _XMI_DRAGDROPI_H */
470