1 /*
2  * Motif
3  *
4  * Copyright (c) 1987-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22 */
23 #ifndef _XmDragICCI_h
24 #define _XmDragICCI_h
25 
26 #include <Xm/XmP.h>
27 #include <Xm/Display.h>
28 #include <X11/Xmd.h>
29 #include "DragCI.h"
30 #include "DropSMgrI.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 
37 /*
38  *  Xm ICC internal definitions
39  *
40  */
41 
42 #define MAXSHORT 32767
43 #define MINSHORT -MAXSHORT
44 
45 /*
46  *  Swap the byte order of 4- and 2- byte quantities.
47  *  These macros work for bitfields.
48  */
49 
50 #define swap4bytes(l) {\
51 	struct {\
52 	  unsigned t :32;\
53 	} bit32;\
54         char n,	*tp = (char *) &bit32;\
55 	bit32.t = l;\
56 	n = tp[0]; tp[0] = tp[3]; tp[3] = n;\
57 	n = tp[1]; tp[1] = tp[2]; tp[2] = n;\
58         l = bit32.t;\
59 }
60 
61 #define swap2bytes(s) {\
62 	struct {\
63 	  unsigned t :16;\
64 	} bit16;\
65         char n, *tp = (char *) &bit16;\
66 	bit16.t = s;\
67 	n = tp[0]; tp[0] = tp[1]; tp[1] = n;\
68         s = bit16.t;\
69 }
70 
71 
72 
73 typedef struct {
74 /* the message type field contains the following:
75  *
76  *  80      originator
77  *  7F      message_type
78  */
79 
80     BYTE		message_type;
81     BYTE		byte_order;
82 /*
83  * the flags field contains the following:
84  *
85  *	000F	operation
86  *	00F0	dropSiteStatus
87  *	0F00	operations
88  *	F000	completionStatus
89  */
90     CARD16		flags B16;
91     CARD32		time B32;
92 }xmICCAnyMessageStruct, *xmICCAnyMessage;
93 
94 typedef struct {
95     BYTE		message_type;
96     BYTE		byte_order;
97     CARD16		flags B16;
98     CARD32		time B32;
99     CARD32		src_window B32;
100     CARD32		icc_handle B32;
101 }xmICCTopLevelEnterMessageStruct;
102 
103 typedef struct {
104     BYTE		message_type;
105     BYTE		byte_order;
106     CARD16		flags B16;
107     CARD32		time B32;
108     CARD32		src_window B32;
109 }xmICCTopLevelLeaveMessageStruct;
110 
111 typedef struct {
112     BYTE		message_type;
113     BYTE		byte_order;
114     CARD16		flags B16;
115     CARD32		time B32;
116     INT16		x B16;
117     INT16		y B16;
118 }xmICCDragMotionMessageStruct;
119 
120 typedef struct {
121     BYTE		message_type;
122     BYTE		byte_order;
123     CARD16		flags B16;
124     CARD32		time B32;
125 }xmICCOperationChangedMessageStruct;
126 
127 typedef struct {
128     BYTE		message_type;
129     BYTE		byte_order;
130     CARD16		flags B16;
131     CARD32		time B32;
132     INT16		x B16;
133     INT16		y B16;
134 }xmICCDropSiteEnterMessageStruct;
135 
136 typedef struct {
137     BYTE		message_type;
138     BYTE		byte_order;
139     CARD16		flags B16;
140     CARD32		time B32;
141 }xmICCDropSiteLeaveMessageStruct;
142 
143 typedef struct {
144     BYTE		message_type;
145     BYTE		byte_order;
146     CARD16		flags B16;
147     CARD32		time B32;
148     INT16		x B16;
149     INT16		y B16;
150     CARD32		icc_handle B32;
151     CARD32		src_window B32;
152 }xmICCDropMessageStruct;
153 
154 typedef union _xmICCMessageStruct{
155     xmICCAnyMessageStruct			any;
156     xmICCTopLevelEnterMessageStruct		topLevelEnter;
157     xmICCTopLevelLeaveMessageStruct		topLevelLeave;
158     xmICCDragMotionMessageStruct		dragMotion;
159     xmICCOperationChangedMessageStruct		operationChanged;
160     xmICCDropSiteEnterMessageStruct		dropSiteEnter;
161     xmICCDropSiteLeaveMessageStruct		dropSiteLeave;
162     xmICCDropMessageStruct			drop;
163 }xmICCMessageStruct, *xmICCMessage;
164 
165 
166 typedef union _XmICCCallbackStruct{
167     XmAnyICCCallbackStruct			any;
168     XmTopLevelEnterCallbackStruct		topLevelEnter;
169     XmTopLevelLeaveCallbackStruct		topLevelLeave;
170     XmDragMotionCallbackStruct			dragMotion;
171     XmOperationChangedCallbackStruct		operationChanged;
172     XmDropSiteEnterCallbackStruct		dropSiteEnter;
173     XmDropSiteLeaveCallbackStruct		dropSiteLeave;
174     XmDropSiteTreeAddCallbackStruct		dropSiteTreeAdd;
175     XmDropSiteTreeRemoveCallbackStruct		dropSiteTreeRemove;
176     XmDropSiteTreeUpdateCallbackStruct		dropSiteTreeUpdate;
177 }XmICCCallbackStruct, *XmICCCallback;
178 
179 typedef struct _xmByteBufRec{
180     BYTE	*bytes;
181     BYTE	*stack;
182     BYTE	*curr;
183     size_t	size;
184     Cardinal	max;
185 }xmByteBufRec;
186 
187 typedef struct _xmPropertyBufferRec{
188     xmByteBufRec	data;
189     xmByteBufRec	heap;
190 }xmPropertyBufferRec, *xmPropertyBuffer;
191 
192 /* for argument passing between DropSite and ICC routines */
193 
194 typedef struct _XmICCDropSiteHeaderRec {
195     unsigned char	dropType;
196     unsigned char	dropActivity;
197     unsigned char	traversalType;
198     unsigned char	operations;
199     unsigned char	animationStyle;
200     unsigned short	importTargetsID;
201     XmRegion		region;
202 } XmICCDropSiteHeaderRec, *XmICCDropSiteHeader;
203 
204 typedef struct _XmICCDropSiteNoneDataRec {
205     Dimension		borderWidth;
206 } XmICCDropSiteNoneDataRec, *XmICCDropSiteNoneData;
207 
208 typedef struct _XmICCDropSiteHighlightDataRec {
209     Dimension		borderWidth;
210     Dimension		highlightThickness;
211     Pixel		background;
212     Pixel		highlightColor;
213     Pixmap		highlightPixmap;
214 } XmICCDropSiteHighlightDataRec, *XmICCDropSiteHighlightData;
215 
216 typedef struct _XmICCDropSiteShadowDataRec {
217     Dimension		borderWidth;
218     Dimension		highlightThickness;
219     Dimension		shadowThickness;
220     Pixel		foreground;
221     Pixel		topShadowColor;
222     Pixmap		topShadowPixmap;
223     Pixel		bottomShadowColor;
224     Pixmap		bottomShadowPixmap;
225 } XmICCDropSiteShadowDataRec, *XmICCDropSiteShadowData;
226 
227 typedef struct _XmICCDropSitePixmapDataRec {
228     Dimension		borderWidth;
229     Dimension		highlightThickness;
230     Dimension		shadowThickness;
231     Pixel		foreground;
232     Pixel		background;
233     Pixmap		animationPixmap;
234     Cardinal		animationPixmapDepth;
235     Pixmap		animationMask;
236 } XmICCDropSitePixmapDataRec, *XmICCDropSitePixmapData;
237 
238 typedef struct _XmICCDropSiteNoneRec {
239     XmICCDropSiteHeaderRec		header;
240     XmICCDropSiteNoneDataRec	animation_data;
241 } XmICCDropSiteNoneRec, *XmICCDropSiteNone;
242 
243 typedef struct _XmICCDropSiteHighlightRec {
244     XmICCDropSiteHeaderRec		header;
245     XmICCDropSiteHighlightDataRec	animation_data;
246 } XmICCDropSiteHighlightRec, *XmICCDropSiteHighlight;
247 
248 typedef struct _XmICCDropSiteShadowRec {
249     XmICCDropSiteHeaderRec	header;
250     XmICCDropSiteShadowDataRec	animation_data;
251 } XmICCDropSiteShadowRec, *XmICCDropSiteShadow;
252 
253 typedef struct _XmICCDropSitePixmapRec {
254     XmICCDropSiteHeaderRec	header;
255     XmICCDropSitePixmapDataRec	animation_data;
256 } XmICCDropSitePixmapRec, *XmICCDropSitePixmap;
257 
258 typedef union _XmICCDropSiteInfoStruct {
259     XmICCDropSiteHeaderRec	header;
260     XmICCDropSiteHighlightRec	highlightDS;
261     XmICCDropSiteShadowRec	shadowDS;
262     XmICCDropSitePixmapRec	pixmapDS;
263 } XmICCDropSiteInfoStruct, *XmICCDropSiteInfo;
264 
265 typedef struct _XmReceiverDSTreeStruct{
266     xmPropertyBufferRec	propBufRec;
267     unsigned char	byteOrder;
268     Cardinal		numDropSites;
269     Cardinal		currDropSite;
270 }XmReceiverDSTreeStruct, *XmReceiverDSTree;
271 
272 /*
273  *  The following structures are for property access.
274  *  They must have 64-bit multiple lengths to support 64-bit architectures.
275  */
276 
277 typedef struct _xmDragInitiatorInfoStruct{
278     BYTE	byte_order;
279     BYTE	protocol_version;
280     CARD16	targets_index B16;
281     CARD32	icc_handle B32;
282 }xmDragInitiatorInfoStruct;
283 
284 typedef struct _xmDragReceiverInfoStruct{
285     BYTE	byte_order;
286     BYTE	protocol_version;
287     BYTE	drag_protocol_style;
288     BYTE	pad1;
289     CARD32	proxy_window B32;
290     CARD16	num_drop_sites B16;
291     CARD16	pad2 B16;
292     CARD32	heap_offset B32;
293 }xmDragReceiverInfoStruct;
294 
295 typedef struct {
296     INT16	x1 B16;
297     INT16	x2 B16;
298     INT16	y1 B16;
299     INT16	y2 B16;
300 }xmICCRegBoxRec;
301 
302 typedef struct _xmDSHeaderStruct{
303 /*
304  * the flags field contains the following:
305  *
306  *	0003	traversalType
307  *	000C	dropActivity
308  *	00F0	dropType
309  *	0F00	operations
310  *	F000	animationStyle
311  */
312     CARD16	flags B16;
313     CARD16	import_targets_id B16;
314     CARD32	dsRegionNumBoxes B32;
315 }xmDSHeaderStruct, *xmDSHeader;
316 
317 typedef struct _xmDSNoneDataStruct{
318     CARD16	borderWidth B16;
319     CARD16	pad1 B16;
320     CARD32	pad2 B32;
321 }xmDSNoneDataStruct, *xmDSNoneData;
322 
323 typedef struct _xmDSHighlightDataStruct{
324     CARD16	borderWidth B16;
325     CARD16	highlightThickness B16;
326 
327     CARD32	background B32;
328     CARD32	highlightColor B32;
329     CARD32	highlightPixmap B32;
330 }xmDSHighlightDataStruct, *xmDSHighlightData;
331 
332 typedef struct _xmDSShadowDataStruct{
333     CARD16	borderWidth B16;
334     CARD16	highlightThickness B16;
335     CARD16	shadowThickness B16;
336     CARD16	pad1 B16;
337 
338     CARD32	foreground B32;
339     CARD32	topShadowColor B32;
340     CARD32	bottomShadowColor B32;
341     CARD32	topShadowPixmap B32;
342     CARD32	bottomShadowPixmap B32;
343     CARD32	pad2 B32;
344 }xmDSShadowDataStruct, *xmDSShadowData;
345 
346 typedef struct _xmDSPixmapDataStruct{
347     CARD16	borderWidth B16;
348     CARD16	highlightThickness B16;
349     CARD16	shadowThickness B16;
350     CARD16	animationPixmapDepth B16;
351 
352     CARD32	foreground B32;
353     CARD32	background B32;
354     CARD32	animationPixmap B32;
355     CARD32	animationMask B32;
356 }xmDSPixmapDataStruct, *xmDSPixmapData;
357 
358 
359 /* Macros for the manipulation of ICCmessages and xmDSData */
360 
361 #define _XM_TRAVERSAL_TYPE_MASK ((CARD16) 0x0003)
362 #define _XM_TRAVERSAL_TYPE_SHIFT 0
363 
364 #define _XM_DS_ACTIVITY_MASK ((CARD16) 0x000C)
365 #define _XM_DS_ACTIVITY_SHIFT 2
366 
367 #define _XM_DND_OPERATION_MASK ((CARD16) 0x000F)
368 #define _XM_DND_OPERATION_SHIFT 0
369 
370 #define _XM_DND_SITE_STATUS_MASK ((CARD16) 0x00F0)
371 #define _XM_DND_SITE_STATUS_SHIFT 4
372 
373 #define _XM_DS_TYPE_MASK ((CARD16) 0x00F0)
374 #define _XM_DS_TYPE_SHIFT 4
375 
376 #define _XM_DND_MULTIOPS_MASK ((CARD16) 0x0F00)
377 #define _XM_DND_MULTIOPS_SHIFT 8
378 
379 #define _XM_DND_COMPLETION_MASK ((CARD16) 0xF000)
380 #define _XM_DND_COMPLETION_SHIFT 12
381 
382 #define _XM_ANIMATION_STYLE_MASK ((CARD16) 0xF000)
383 #define _XM_ANIMATION_STYLE_SHIFT 12
384 
385 #define GET_OPERATION(flags) \
386   ((unsigned char) \
387    ((int)((flags) & _XM_DND_OPERATION_MASK) >> _XM_DND_OPERATION_SHIFT))
388 
389 #define PUT_OPERATION(operation) \
390   (((CARD16)(operation) << _XM_DND_OPERATION_SHIFT)\
391    & _XM_DND_OPERATION_MASK)
392 
393 #define GET_SITE_STATUS(flags) \
394   ((unsigned char) \
395    ((int)((flags) & _XM_DND_SITE_STATUS_MASK) >> _XM_DND_SITE_STATUS_SHIFT))
396 
397 #define PUT_SITE_STATUS(site_status) \
398   (((CARD16)(site_status) << _XM_DND_SITE_STATUS_SHIFT)\
399    & _XM_DND_SITE_STATUS_MASK)
400 
401 #define GET_MULTIOPS(flags) \
402   ((unsigned char) \
403    ((int)((flags) & _XM_DND_MULTIOPS_MASK) >> _XM_DND_MULTIOPS_SHIFT))
404 
405 #define PUT_MULTIOPS(operation) \
406   (((CARD16)(operation) << _XM_DND_MULTIOPS_SHIFT)\
407    & _XM_DND_MULTIOPS_MASK)
408 
409 #define GET_COMPLETION(flags) \
410   ((unsigned char) \
411    ((int)((flags) & _XM_DND_COMPLETION_MASK) >> _XM_DND_COMPLETION_SHIFT))
412 
413 #define PUT_COMPLETION(completion) \
414   (((CARD16)(completion) << _XM_DND_COMPLETION_SHIFT)\
415    & _XM_DND_COMPLETION_MASK)
416 
417 #define GET_TRAVERSAL_TYPE(flags) \
418   ((unsigned char) \
419    ((int)((flags) & _XM_TRAVERSAL_TYPE_MASK) >> _XM_TRAVERSAL_TYPE_SHIFT))
420 
421 #define PUT_TRAVERSAL_TYPE(traversal_type) \
422   (((CARD16)(traversal_type) << _XM_TRAVERSAL_TYPE_SHIFT)\
423    & _XM_TRAVERSAL_TYPE_MASK)
424 
425 #define GET_DS_TYPE(flags) \
426   ((unsigned char) \
427    ((int)((flags) & _XM_DS_TYPE_MASK) >> _XM_DS_TYPE_SHIFT))
428 
429 #define PUT_DS_TYPE(ds_type) \
430   (((CARD16)(ds_type) << _XM_DS_TYPE_SHIFT)\
431    & _XM_DS_TYPE_MASK)
432 
433 #define GET_DS_ACTIVITY(flags) \
434   ((unsigned char) \
435    ((int)((flags) & _XM_DS_ACTIVITY_MASK) >> _XM_DS_ACTIVITY_SHIFT))
436 
437 #define PUT_DS_ACTIVITY(ds_activity) \
438   (((CARD16)(ds_activity) << _XM_DS_ACTIVITY_SHIFT)\
439    & _XM_DS_ACTIVITY_MASK)
440 
441 #define GET_ANIMATION_STYLE(flags) \
442   ((unsigned char) \
443    ((int)((flags) & _XM_ANIMATION_STYLE_MASK) >> _XM_ANIMATION_STYLE_SHIFT))
444 
445 #define PUT_ANIMATION_STYLE(animation_style) \
446   (((CARD16)(animation_style) << _XM_ANIMATION_STYLE_SHIFT)\
447    & _XM_ANIMATION_STYLE_MASK)
448 
449 
450 /*
451  * We consume the high order bit of the messageType in order
452  * to indicate whether this is an initiator generated event
453  * or a receiver generated event.
454  *
455  * This is all wrapped in macros in case we want to use more bits
456  * later.
457  */
458 
459 typedef enum {
460 	XmICC_INITIATOR_EVENT,
461 	XmICC_RECEIVER_EVENT
462 } XmICCEventType;
463 
464 #define _XM_ICC_EVENT_TYPE_MASK  ((BYTE)0x80)
465 #define _XM_ICC_EVENT_TYPE_SHIFT 7
466 
467 #define GET_ICC_EVENT_TYPE(type) \
468   ((XmICCEventType) \
469     ((int)((type) & _XM_ICC_EVENT_TYPE_MASK) >> _XM_ICC_EVENT_TYPE_SHIFT))
470 
471 #define PUT_ICC_EVENT_TYPE(type) \
472   (((BYTE)(type) << _XM_ICC_EVENT_TYPE_SHIFT) \
473     & _XM_ICC_EVENT_TYPE_MASK)
474 
475 #define CLEAR_ICC_EVENT_TYPE  ((BYTE)0x7F)
476 
477 
478 #define _MOTIF_DRAG_PROTOCOL_VERSION	(BYTE)0
479 
480 
481 externalref unsigned char _XmByteOrderChar;
482 
483 
484 /********    Private Function Declarations    ********/
485 
486 extern unsigned char _XmReasonToMessageType(
487                         int reason) ;
488 extern unsigned int _XmMessageTypeToReason(
489 #if NeedWidePrototypes
490                         unsigned int messageType) ;
491 #else
492                         unsigned char messageType) ;
493 #endif /* NeedWidePrototypes */
494 extern void _XmICCCallbackToICCEvent(
495                         Display *display,
496                         Window window,
497                         XmICCCallback callback,
498                         XClientMessageEvent *cmev,
499                         XmICCEventType type) ;
500 extern void _XmSendICCCallback(
501                         Display *display,
502                         Window window,
503                         XmICCCallback callback,
504                         XmICCEventType type) ;
505 extern Boolean _XmICCEventToICCCallback(
506                         XClientMessageEvent *msgEv,
507                         XmICCCallback callback,
508                         XmICCEventType type) ;
509 extern CARD16 _XmReadDragBuffer(
510                         xmPropertyBuffer propBuf,
511 #if NeedWidePrototypes
512                         int which,
513 #else
514                         BYTE which,
515 #endif /* NeedWidePrototypes */
516                         BYTE *ptr,
517                         CARD32 size) ;
518 extern CARD16 _XmWriteDragBuffer(
519                         xmPropertyBuffer propBuf,
520 #if NeedWidePrototypes
521                         int which,
522 #else
523                         BYTE which,
524 #endif /* NeedWidePrototypes */
525                         BYTE *ptr,
526                         CARD32 size) ;
527 extern void _XmWriteInitiatorInfo(
528                         Widget dc) ;
529 extern void _XmReadInitiatorInfo(
530                         Widget dc) ;
531 extern Boolean _XmGetDragReceiverInfo(
532                         Display *display,
533                         Window window,
534                         XmDragReceiverInfoStruct *receiverInfoRtn) ;
535 extern Boolean _XmReadDSFromStream(
536                         XmDropSiteManagerObject dsm,
537                         XtPointer iccInfo,
538                         XmICCDropSiteInfo dropSiteInfoRtn) ;
539 extern void _XmWriteDSToStream(
540                         XmDropSiteManagerObject dsm,
541                         XtPointer stream,
542                         XmICCDropSiteInfo dropSiteInfo) ;
543 extern void _XmFreeDragReceiverInfo(
544                         XtPointer info) ;
545 extern void _XmClearDragReceiverInfo(
546                         Widget shell) ;
547 extern void _XmSetDragReceiverInfo(
548                         XmDisplay dd,
549                         Widget shell) ;
550 extern void _XmInitByteOrderChar( void ) ;
551 
552 /********    End Private Function Declarations    ********/
553 
554 #define _XmInitDragICC(dd)	_XmInitByteOrderChar()
555 
556 
557 #ifdef __cplusplus
558 }  /* Close scope of 'extern "C"' declaration which encloses file. */
559 #endif
560 
561 #endif /* _XmDragICCI_h */
562