annotate src/offix.c @ 413:901169e5ca31

Added tag r21-2-14 for changeset 697ef44129c6
author cvs
date Mon, 13 Aug 2007 11:20:44 +0200
parents 8626e4521993
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
1 /*
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
2 This is a modified DND 1.0 library which does not depend on Xt
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
3 event handling.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
4 Modifications Copyright (c) 1997 Oliver Graf <ograf@fga.de>
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
5
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
6 Original DND lib
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
7 Copyright (C) 1996 César Crusius
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
8
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
9 This file is part of the DND Library. This library is free
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
10 software; you can redistribute it and/or modify it under the terms of
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
11 the GNU Library General Public License as published by the Free
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
12 Software Foundation; either version 2 of the License, or (at your
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
13 option) any later version. This library is distributed in the hope
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
14 that it will be useful, but WITHOUT ANY WARRANTY; without even the
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
15 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
16 PURPOSE. See the GNU Library General Public License for more details.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
17 You should have received a copy of the GNU Library General Public
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
18 License along with this library; if not, write to the Free Software
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
20 */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
21
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
22 /* #define DEBUG */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
23
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
24 #include "offix.h"
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
25 #include <X11/cursorfont.h>
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
26 #include <X11/Xatom.h>
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
27 #include <X11/Xmu/WinUtil.h>
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
28 #include <stdio.h>
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
29 #include <stdlib.h>
225
12579d965149 Import from CVS: tag r20-4b11
cvs
parents: 211
diff changeset
30 #include <limits.h>
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
31
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
32 /* Local variables */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
33 static Display *dpy; /* current display */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
34 static int DragPrecision; /* minimum dx,dy to start drag */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
35 static int Dragging; /* Drag state flag */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
36 static int DataOK; /* Non-zero if data registered */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
37 static Atom DndProtocol; /* ClientMessage identifier */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
38 static Atom DndSelection; /* For the data transfers */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
39 static Atom OldDndProtocol; /* Version 0 atom */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
40 static Atom OldDndSelection;/* Version 0 atom */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
41 static Atom WM_STATE; /* Needed for icon stuff */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
42 static Window Target; /* Drop window */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
43 static Widget MainWidget; /* Main widget of application */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
44 static int DataType; /* Current drag data type */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
45 static int RootFlag; /* Non-zero if dropped on root */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
46 static XColor Black,White; /* For the cursors */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
47
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
48 /*=========================================================================
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
49 * Data for the standard Dnd cursors
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
50 *=========================================================================*/
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
51 #include "offix-cursors.h"
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
52
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
53 /*=============================================================== CursorData
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
54 * CursorData contains all the data for the cursors bitmaps
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
55 *==========================================================================*/
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
56 typedef struct
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
57 {
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
58 int Width,Height;
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 197
diff changeset
59 unsigned char *ImageData,*MaskData;
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
60 int HotSpotX,HotSpotY;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
61 Pixmap ImagePixmap,MaskPixmap;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
62 Cursor CursorID;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
63 } CursorData;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
64
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
65 static CursorData DndCursor[DndEND]={
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
66 { 0,0,NULL,NULL,0,0,0 },
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
67 { grey_width, grey_height,grey_bits,grey_mask_bits,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
68 grey_x_hot,grey_y_hot},
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
69 { file_width,file_height,file_bits,file_mask_bits,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
70 file_x_hot,file_y_hot},
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
71 { files_width,files_height,files_bits,files_mask_bits,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
72 files_x_hot,files_y_hot},
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
73 { text_width,text_height,text_bits,text_mask_bits,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
74 text_x_hot,text_y_hot },
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
75 { dir_width,dir_height,dir_bits,dir_mask_bits,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
76 dir_x_hot,dir_y_hot },
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
77 { link_width,link_height,link_bits,link_mask_bits,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
78 link_x_hot,link_y_hot},
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
79 { app_width,app_height,app_bits,app_mask_bits,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
80 app_x_hot,app_y_hot },
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
81 { url_width,url_height,url_bits,url_mask_bits,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
82 url_x_hot,url_y_hot },
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
83 { mime_width,mime_height,mime_bits,mime_mask_bits,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
84 mime_x_hot,mime_y_hot }
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
85 };
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
86
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
87 /* Local prototypes */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
88 int DndIsDragging(void);
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
89 void DndStartAction(Widget widget,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
90 XtPointer data,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
91 XEvent *event,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
92 Boolean *p);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
93 void DndPropertyHandler(Widget widget,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
94 XtPointer data,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
95 XEvent *event,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
96 Boolean *p);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
97
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
98 /*======================================================== DndHandleDragging
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
99 * Takes care of the drag and drop process. Wait until the pointer had moved
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
100 * a little. Then takes control over the pointer until the buttons are
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
101 * released. After that send a Drag And Drop ClientMessage event. Returns
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
102 * non-zero if a drop did take place.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
103 *===========================================================================*/
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
104 int
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
105 DndHandleDragging(Widget widget,XEvent *event)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
106 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
107 XEvent Event;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
108 Window root = RootWindowOfScreen(XtScreenOfObject(widget));
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
109 XtAppContext app= XtWidgetToApplicationContext(widget);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
110 Window DispatchWindow;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
111 int DropX,DropY;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
112
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
113 if(Dragging) return 0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
114
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
115 XUngrabPointer(dpy,CurrentTime);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
116 /* Take control over the pointer */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
117 XGrabPointer(dpy,root,False,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
118 ButtonMotionMask|ButtonPressMask|ButtonReleaseMask,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
119 GrabModeSync,GrabModeAsync,root,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
120 DndCursor[DataType].CursorID,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
121 CurrentTime);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
122
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
123 /* Wait for button release */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
124 Dragging=1; RootFlag=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
125 while(Dragging)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
126 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
127 XAllowEvents(dpy,SyncPointer,CurrentTime);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
128 XtAppNextEvent(app,&Event);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
129 switch(Event.type)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
130 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
131 case ButtonRelease:
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
132 if(Event.xbutton.subwindow)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
133 RootFlag=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
134 else
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
135 RootFlag=1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
136 Dragging=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
137 break;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
138 default:
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
139 XtDispatchEvent(&Event);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
140 break;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
141 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
142 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
143 DataOK=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
144 /* Now release the pointer */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
145 XUngrabPointer(dpy,CurrentTime);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
146 /* Try to guess if the drop occurred in the root window */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
147 if(!RootFlag)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
148 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
149 Target=XmuClientWindow(dpy,Event.xbutton.subwindow);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
150 if (Target==Event.xbutton.subwindow)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
151 DispatchWindow=Target;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
152 else
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
153 DispatchWindow=PointerWindow;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
154 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
155 else
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
156 Target=DispatchWindow=XtWindow(MainWidget);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
157
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
158 /* Now build the event structure */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
159 DropX=Event.xbutton.x_root;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
160 DropY=Event.xbutton.y_root;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
161 Event.xclient.type = ClientMessage;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
162 Event.xclient.display = dpy;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
163 Event.xclient.message_type = DndProtocol;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
164 Event.xclient.format = 32;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
165 Event.xclient.window = Target;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
166 Event.xclient.data.l[0] = DataType;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
167 Event.xclient.data.l[1] = (long)event->xbutton.state;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
168 Event.xclient.data.l[2] = (long)XtWindow(widget);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
169 Event.xclient.data.l[3] = DropX + 65536L*(long)DropY;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
170 Event.xclient.data.l[4] = 1;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
171
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
172 /* Send the drop message */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
173 XSendEvent(dpy,DispatchWindow,True,NoEventMask,&Event);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
174 /* Send an old style version of the message just in case */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
175 Event.xclient.message_type = OldDndProtocol;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
176 XSendEvent(dpy,DispatchWindow,True,NoEventMask,&Event);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
177
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
178 #ifdef DEBUG
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
179 fprintf(stderr,"ClientMessage sent to 0x%x(0x%x).\n",
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
180 DispatchWindow,Target);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
181 fprintf(stderr,"The drop coordinates are (%d,%d).\n",DropX,DropY);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
182 #endif
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
183
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
184 return 1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
185 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
186
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
187 /*=============================================================== DndIsIcon
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
188 * Return non-zero if the application is iconic (widget=toplevel)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
189 *========================================================================*/
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
190 int
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
191 DndIsIcon(Widget widget)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
192 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
193 Atom JunkAtom;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
194 int JunkInt;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
195 unsigned long WinState,JunkLong;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
196 unsigned char *Property;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
197
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
198 XGetWindowProperty(dpy,XtWindow(widget),WM_STATE,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
199 0L,2L,False,AnyPropertyType,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
200 &JunkAtom,&JunkInt,&WinState,&JunkLong,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
201 &Property);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
202 WinState=(unsigned long)(*((long*)Property));
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
203 return (WinState==3);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
204 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
205
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
206 /*============================================================ DndInitialize
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
207 * Must be called anywhere before the top level widget creation and the
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
208 * main loop. Initialize global variables and bind the DndDispatch function
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
209 * to the top level widget. Creates the cursors to be used in drag actions.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
210 *=========================================================================*/
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
211 void
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
212 DndInitialize(Widget shell)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
213 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
214 int screen,i;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
215 Colormap colormap;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
216 Window root;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
217
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
218 dpy = XtDisplayOfObject(shell);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
219 screen = DefaultScreen(dpy);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
220 colormap= DefaultColormap(dpy,screen);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
221 root = DefaultRootWindow(dpy);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
222
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
223
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
224 Black.pixel=BlackPixel(dpy,screen);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
225 White.pixel=WhitePixel(dpy,screen);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
226 XQueryColor(dpy,colormap,&Black);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
227 XQueryColor(dpy,colormap,&White);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
228
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
229 for(i=1;i!=DndEND;i++)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
230 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
231 DndCursor[i].ImagePixmap=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
232 XCreateBitmapFromData(dpy,root,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
233 (char *) DndCursor[i].ImageData,
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
234 DndCursor[i].Width,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
235 DndCursor[i].Height);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
236 DndCursor[i].MaskPixmap=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
237 XCreateBitmapFromData(dpy,root,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
238 (char *) DndCursor[i].MaskData,
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
239 DndCursor[i].Width,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
240 DndCursor[i].Height);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
241 DndCursor[i].CursorID=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
242 XCreatePixmapCursor(dpy,DndCursor[i].ImagePixmap,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
243 DndCursor[i].MaskPixmap,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
244 &Black,&White,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
245 DndCursor[i].HotSpotX,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
246 DndCursor[i].HotSpotY);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
247 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
248
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
249 DndCursor[0].CursorID=XCreateFontCursor(dpy,XC_question_arrow);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
250
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
251 /* These two are for older versions */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
252 OldDndProtocol=XInternAtom(dpy,"DndProtocol",FALSE);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
253 OldDndSelection=XInternAtom(dpy,"DndSelection",FALSE);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
254 /* Now the correct stuff */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
255 DndProtocol=XInternAtom(dpy,"_DND_PROTOCOL",FALSE);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
256 DndSelection=XInternAtom(dpy,"_DND_SELECTION",FALSE);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
257
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
258 WM_STATE=XInternAtom(dpy,"WM_STATE",True);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
259 Dragging=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
260 DragPrecision=10;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
261 RootFlag=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
262 MainWidget=shell;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
263 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
264
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
265 int
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
266 DndIsDragging(void)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
267 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
268 return Dragging;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
269 }
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
270
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
271 /*================================================================= DndSetData
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
272 * Updates the selection data.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
273 *===========================================================================*/
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
274 void
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
275 DndSetData(int Type,unsigned char *Data,unsigned long Size)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
276 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
277 Window root = DefaultRootWindow(dpy);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
278 int AuxSize;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
279 unsigned char *AuxData;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
280 unsigned long BackSize=Size;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
281
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
282 if (DataOK) return;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
283
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
284 /* Set the data type -- allow any type */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
285 DataType = Type;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
286
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
287 /* Set the data */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
288 AuxData = Data;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
289 AuxSize = ( Size <= INT_MAX ? (int)Size : INT_MAX );
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
290 XChangeProperty(dpy,root,DndSelection,XA_STRING,8,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
291 PropModeReplace,Data,AuxSize);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
292 for(Size-=(unsigned long)AuxSize;Size;Size-=(unsigned long)AuxSize)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
293 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
294 Data+=AuxSize;
225
12579d965149 Import from CVS: tag r20-4b11
cvs
parents: 211
diff changeset
295 AuxSize = ( (Size<=(INT_MAX)) ? (int)Size : (INT_MAX) );
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
296 XChangeProperty(dpy,root,DndSelection,XA_STRING,8,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
297 PropModeAppend,Data,AuxSize);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
298 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
299
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
300 /* Set the data for old DND version */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
301 Size = BackSize;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
302 AuxData = Data;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
303 AuxSize = ( Size <= INT_MAX ? (int)Size : INT_MAX );
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
304 XChangeProperty(dpy,root,OldDndSelection,XA_STRING,8,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
305 PropModeReplace,Data,AuxSize);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
306 for(Size-=(unsigned long)AuxSize;Size;Size-=(unsigned long)AuxSize)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
307 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
308 Data+=AuxSize;
225
12579d965149 Import from CVS: tag r20-4b11
cvs
parents: 211
diff changeset
309 AuxSize = ( (Size<=(INT_MAX)) ? (int)Size : (INT_MAX) );
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
310 XChangeProperty(dpy,root,OldDndSelection,XA_STRING,8,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
311 PropModeAppend,Data,AuxSize);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
312 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
313
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
314 /* Everything is now ok */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
315 DataOK=1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
316 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
317
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
318 /*================================================================== DndGetData
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
319 * Return a pointer to the current data. See HOWTO for more details.
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
320 *===========================================================================*/
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
321 void
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
322 DndGetData(XEvent *event, unsigned char **Data,unsigned long *Size)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
323 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
324 Window root = DefaultRootWindow(dpy);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
325
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
326 Atom ActualType,ActualDndSelection;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
327 int ActualFormat;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
328 unsigned long RemainingBytes;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
329
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
330 ActualDndSelection=(DndProtocolVersion(event) == 0L ?
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
331 OldDndSelection :
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
332 DndSelection );
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
333
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
334 XGetWindowProperty(dpy,root,ActualDndSelection,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
335 0L,1000000L,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
336 FALSE,AnyPropertyType,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
337 &ActualType,&ActualFormat,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
338 Size,&RemainingBytes,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
339 Data);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
340 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
341
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
342 /*================================== DndDataType DndDragButtons DndSourceWidget
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
343 *
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
344 * Return information about the Dnd event received. If a non-dnd event is
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
345 * passed, the function DndDataType returns DndNotDnd, and the others
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
346 * return zero.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
347 *===========================================================================*/
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
348 int
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
349 DndDataType(XEvent *event)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
350 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
351 int Type;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
352
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
353 if(!DndIsDropMessage(event)) return DndNotDnd;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
354 Type=(int)(event->xclient.data.l[0]);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
355 if(Type>=DndEND) Type=DndUnknown;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
356 return Type;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
357 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
358
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
359 unsigned int
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
360 DndDragButtons(XEvent *event)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
361 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
362 if(!DndIsDropMessage(event)) return 0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
363 return (unsigned int)(event->xclient.data.l[1]);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
364 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
365
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
366 Window
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
367 DndSourceWindow(XEvent *event)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
368 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
369 if(!DndIsDropMessage(event)) return 0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
370 if(DndProtocolVersion(event)<__DragAndDropH__)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
371 /* We will try to do something about it, but nothing is certain */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
372 return XtWindow((Widget)(event->xclient.data.l[2]));
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
373 return (Window)(event->xclient.data.l[2]);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
374 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
375
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
376 void
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
377 DndDropRootCoordinates(XEvent *event,int *x,int *y)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
378 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
379 if(!DndIsDropMessage(event))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
380 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
381 *x=0; *y=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
382 return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
383 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
384
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
385 /* If it is an old protocol version we try to get the coordinates
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
386 using the current pointer position. Of course, the pointer may have
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
387 moved since the drop, but there's nothing we can do about it.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
388 */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
389 if(DndProtocolVersion(event)<1L)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
390 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
391 Window root_return,child_return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
392 int win_x_return,win_y_return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
393 unsigned int mask_return;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
394
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
395 XQueryPointer(dpy,DefaultRootWindow(dpy),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
396 &root_return,&child_return,x,y,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
397 &win_x_return,&win_y_return,&mask_return);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
398 return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
399 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
400 /* Thanks god you are using a decent protocol version */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
401 *x=(int)((long)(event->xclient.data.l[3]) & 0xffff);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
402 *y=(int)((long)(event->xclient.data.l[3])/65536);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
403 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
404
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
405 void
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
406 DndDropCoordinates(Widget widget,XEvent *event,int *x,int *y)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
407 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
408 int root_x,root_y;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
409 Window child_return;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
410
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
411 DndDropRootCoordinates(event,&root_x,&root_y);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
412 XTranslateCoordinates(dpy,DefaultRootWindow(dpy),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
413 XtWindow(widget),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
414 root_x,root_y,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
415 x,y,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
416 &child_return);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
417 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
418
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
419 long
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
420 DndProtocolVersion(XEvent *event)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
421 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
422 if(!DndIsDropMessage(event)) return -1L;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
423 return event->xclient.data.l[4];
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
424 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
425
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
426 int
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
427 DndIsDropMessage(XEvent *event)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
428 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
429 if(event->xclient.type != ClientMessage) return 0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
430 if(event->xclient.message_type == OldDndProtocol &&
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
431 event->xclient.data.l[4]==0) return 1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
432 if(event->xclient.message_type == DndProtocol) return 1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
433 return 0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
434 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
435
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
436 void
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
437 DndChangeCursor(int Type,int width,int height,char *image,char *mask,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 225
diff changeset
438 int hot_x,int hot_y)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
439 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
440 DndCursor[Type].ImagePixmap=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
441 XCreateBitmapFromData(dpy,DefaultRootWindow(dpy),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
442 image,width,height);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
443 DndCursor[Type].MaskPixmap=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
444 XCreateBitmapFromData(dpy,DefaultRootWindow(dpy),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
445 mask,width,height);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
446 DndCursor[Type].CursorID=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
447 XCreatePixmapCursor(dpy,DndCursor[Type].ImagePixmap,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
448 DndCursor[Type].MaskPixmap,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
449 &Black,&White,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
450 hot_x,hot_y);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
451 }