annotate src/offix.c @ 225:12579d965149 r20-4b11

Import from CVS: tag r20-4b11
author cvs
date Mon, 13 Aug 2007 10:11:40 +0200
parents 78478c60bfcd
children c5d627a313b1
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
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
54 * CursorData contains all the data for the cursors bitmaps
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
55 *==========================================================================*/
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
56 typedef struct
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
57 {
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,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
84 mime_x_hot,mime_y_hot }
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 */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
88 int DndIsDragging(void);
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 *===========================================================================*/
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
104 int DndHandleDragging(Widget widget,XEvent *event)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
105 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
106 XEvent Event;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
107 Window root = RootWindowOfScreen(XtScreenOfObject(widget));
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
108 XtAppContext app= XtWidgetToApplicationContext(widget);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
109 Window DispatchWindow;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
110 int DropX,DropY;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
111
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
112 if(Dragging) return 0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
113
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
114 XUngrabPointer(dpy,CurrentTime);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
115 /* Take control over the pointer */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
116 XGrabPointer(dpy,root,False,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
117 ButtonMotionMask|ButtonPressMask|ButtonReleaseMask,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
118 GrabModeSync,GrabModeAsync,root,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
119 DndCursor[DataType].CursorID,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
120 CurrentTime);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
121
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
122 /* Wait for button release */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
123 Dragging=1; RootFlag=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
124 while(Dragging)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
125 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
126 XAllowEvents(dpy,SyncPointer,CurrentTime);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
127 XtAppNextEvent(app,&Event);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
128 switch(Event.type)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
129 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
130 case ButtonRelease:
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
131 if(Event.xbutton.subwindow)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
132 RootFlag=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
133 else
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
134 RootFlag=1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
135 Dragging=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
136 break;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
137 default:
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
138 XtDispatchEvent(&Event);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
139 break;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
140 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
141 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
142 DataOK=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
143 /* Now release the pointer */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
144 XUngrabPointer(dpy,CurrentTime);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
145 /* Try to guess if the drop occurred in the root window */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
146 if(!RootFlag)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
147 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
148 Target=XmuClientWindow(dpy,Event.xbutton.subwindow);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
149 if (Target==Event.xbutton.subwindow)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
150 DispatchWindow=Target;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
151 else
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
152 DispatchWindow=PointerWindow;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
153 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
154 else
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
155 Target=DispatchWindow=XtWindow(MainWidget);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
156
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
157 /* Now build the event structure */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
158 DropX=Event.xbutton.x_root;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
159 DropY=Event.xbutton.y_root;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
160 Event.xclient.type = ClientMessage;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
161 Event.xclient.display = dpy;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
162 Event.xclient.message_type = DndProtocol;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
163 Event.xclient.format = 32;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
164 Event.xclient.window = Target;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
165 Event.xclient.data.l[0] = DataType;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
166 Event.xclient.data.l[1] = (long)event->xbutton.state;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
167 Event.xclient.data.l[2] = (long)XtWindow(widget);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
168 Event.xclient.data.l[3] = DropX + 65536L*(long)DropY;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
169 Event.xclient.data.l[4] = 1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
170
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
171 /* Send the drop message */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
172 XSendEvent(dpy,DispatchWindow,True,NoEventMask,&Event);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
173 /* Send an old style version of the message just in case */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
174 Event.xclient.message_type = OldDndProtocol;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
175 XSendEvent(dpy,DispatchWindow,True,NoEventMask,&Event);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
176
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
177 #ifdef DEBUG
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
178 fprintf(stderr,"ClientMessage sent to 0x%x(0x%x).\n",
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
179 DispatchWindow,Target);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
180 fprintf(stderr,"The drop coordinates are (%d,%d).\n",DropX,DropY);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
181 #endif
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
182
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
183 return 1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
184 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
185
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
186 /*=============================================================== DndIsIcon
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
187 * Return non-zero if the application is iconic (widget=toplevel)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
188 *========================================================================*/
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
189 int
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
190 DndIsIcon(Widget widget)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
191 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
192 Atom JunkAtom;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
193 int JunkInt;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
194 unsigned long WinState,JunkLong;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
195 unsigned char *Property;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
196
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
197 XGetWindowProperty(dpy,XtWindow(widget),WM_STATE,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
198 0L,2L,False,AnyPropertyType,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
199 &JunkAtom,&JunkInt,&WinState,&JunkLong,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
200 &Property);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
201 WinState=(unsigned long)(*((long*)Property));
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
202 return (WinState==3);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
203 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
204
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
205 /*============================================================ DndInitialize
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
206 * Must be called anywhere before the top level widget creation and the
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
207 * main loop. Initialize global variables and bind the DndDispatch function
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
208 * 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
209 *=========================================================================*/
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
210 void
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
211 DndInitialize(Widget shell)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
212 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
213 int screen,i;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
214 Colormap colormap;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
215 Window root;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
216
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
217 dpy = XtDisplayOfObject(shell);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
218 screen = DefaultScreen(dpy);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
219 colormap= DefaultColormap(dpy,screen);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
220 root = DefaultRootWindow(dpy);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
221
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
222
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
223 Black.pixel=BlackPixel(dpy,screen);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
224 White.pixel=WhitePixel(dpy,screen);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
225 XQueryColor(dpy,colormap,&Black);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
226 XQueryColor(dpy,colormap,&White);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
227
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
228 for(i=1;i!=DndEND;i++)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
229 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
230 DndCursor[i].ImagePixmap=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
231 XCreateBitmapFromData(dpy,root,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
232 DndCursor[i].ImageData,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
233 DndCursor[i].Width,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
234 DndCursor[i].Height);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
235 DndCursor[i].MaskPixmap=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
236 XCreateBitmapFromData(dpy,root,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
237 DndCursor[i].MaskData,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
238 DndCursor[i].Width,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
239 DndCursor[i].Height);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
240 DndCursor[i].CursorID=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
241 XCreatePixmapCursor(dpy,DndCursor[i].ImagePixmap,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
242 DndCursor[i].MaskPixmap,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
243 &Black,&White,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
244 DndCursor[i].HotSpotX,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
245 DndCursor[i].HotSpotY);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
246 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
247
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
248 DndCursor[0].CursorID=XCreateFontCursor(dpy,XC_question_arrow);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
249
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
250 /* These two are for older versions */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
251 OldDndProtocol=XInternAtom(dpy,"DndProtocol",FALSE);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
252 OldDndSelection=XInternAtom(dpy,"DndSelection",FALSE);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
253 /* Now the correct stuff */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
254 DndProtocol=XInternAtom(dpy,"_DND_PROTOCOL",FALSE);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
255 DndSelection=XInternAtom(dpy,"_DND_SELECTION",FALSE);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
256
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
257 WM_STATE=XInternAtom(dpy,"WM_STATE",True);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
258 Dragging=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
259 DragPrecision=10;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
260 RootFlag=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
261 MainWidget=shell;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
262 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
263
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
264 int DndIsDragging(void) { return Dragging; }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
265
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
266 /*================================================================= DndSetData
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
267 * Updates the selection data.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
268 *===========================================================================*/
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
269 void DndSetData(int Type,unsigned char *Data,unsigned long Size)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
270 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
271 Window root = DefaultRootWindow(dpy);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
272 int AuxSize;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
273 unsigned char *AuxData;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
274 unsigned long BackSize=Size;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
275
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
276 if (DataOK) return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
277
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
278 /* Set the data type -- allow any type */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
279 DataType = Type;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
280
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
281 /* Set the data */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
282 AuxData = Data;
225
12579d965149 Import from CVS: tag r20-4b11
cvs
parents: 211
diff changeset
283 AuxSize = ( Size <= INT_MAX ? (int)Size : INT_MAX );
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
284 XChangeProperty(dpy,root,DndSelection,XA_STRING,8,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
285 PropModeReplace,Data,AuxSize);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
286 for(Size-=(unsigned long)AuxSize;Size;Size-=(unsigned long)AuxSize)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
287 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
288 Data+=AuxSize;
225
12579d965149 Import from CVS: tag r20-4b11
cvs
parents: 211
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 PropModeAppend,Data,AuxSize);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
292 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
293
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
294 /* Set the data for old DND version */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
295 Size = BackSize;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
296 AuxData = Data;
225
12579d965149 Import from CVS: tag r20-4b11
cvs
parents: 211
diff changeset
297 AuxSize = ( Size <= INT_MAX ? (int)Size : INT_MAX );
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
298 XChangeProperty(dpy,root,OldDndSelection,XA_STRING,8,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
299 PropModeReplace,Data,AuxSize);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
300 for(Size-=(unsigned long)AuxSize;Size;Size-=(unsigned long)AuxSize)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
301 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
302 Data+=AuxSize;
225
12579d965149 Import from CVS: tag r20-4b11
cvs
parents: 211
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 PropModeAppend,Data,AuxSize);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
306 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
307
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
308 /* Everything is now ok */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
309 DataOK=1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
310 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
311
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
312 /*================================================================== DndGetData
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
313 * Return a pointer to the current data. Se HOWTO for more details.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
314 *===========================================================================*/
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
315 void DndGetData(XEvent *event, unsigned char **Data,unsigned long *Size)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
316 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
317 Window root = DefaultRootWindow(dpy);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
318
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
319 Atom ActualType,ActualDndSelection;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
320 int ActualFormat;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
321 unsigned long RemainingBytes;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
322
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
323 ActualDndSelection=(DndProtocolVersion(event) == 0L ?
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
324 OldDndSelection :
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
325 DndSelection );
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
326
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
327 XGetWindowProperty(dpy,root,ActualDndSelection,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
328 0L,1000000L,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
329 FALSE,AnyPropertyType,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
330 &ActualType,&ActualFormat,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
331 Size,&RemainingBytes,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
332 Data);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
333 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
334
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
335 /*================================== DndDataType DndDragButtons DndSourceWidget
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
336 *
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
337 * Return information about the Dnd event received. If a non-dnd event is
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
338 * passed, the function DndDataType returns DndNotDnd, and the others
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
339 * return zero.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
340 *===========================================================================*/
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
341 int DndDataType(XEvent *event)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
342 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
343 int Type;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
344
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
345 if(!DndIsDropMessage(event)) return DndNotDnd;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
346 Type=(int)(event->xclient.data.l[0]);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
347 if(Type>=DndEND) Type=DndUnknown;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
348 return Type;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
349 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
350
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
351 unsigned int DndDragButtons(XEvent *event)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
352 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
353 if(!DndIsDropMessage(event)) return 0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
354 return (unsigned int)(event->xclient.data.l[1]);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
355 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
356
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
357 Window DndSourceWindow(XEvent *event)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
358 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
359 if(!DndIsDropMessage(event)) return 0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
360 if(DndProtocolVersion(event)<__DragAndDropH__)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
361 /* We will try to do something about it, but nothing is certain */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
362 return XtWindow((Widget)(event->xclient.data.l[2]));
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
363 return (Window)(event->xclient.data.l[2]);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
364 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
365
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
366 void DndDropRootCoordinates(XEvent *event,int *x,int *y)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
367 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
368 if(!DndIsDropMessage(event))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
369 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
370 *x=0; *y=0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
371 return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
372 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
373
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
374 /* If it is an old protocol version we try to get the coordinates
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
375 using the current pointer position. Of course, the pointer may have
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
376 moved since the drop, but there's nothing we can do about it.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
377 */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
378 if(DndProtocolVersion(event)<1L)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
379 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
380 Window root_return,child_return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
381 int win_x_return,win_y_return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
382 unsigned int mask_return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
383
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
384 XQueryPointer(dpy,DefaultRootWindow(dpy),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
385 &root_return,&child_return,x,y,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
386 &win_x_return,&win_y_return,&mask_return);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
387 return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
388 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
389 /* Thanks god you are using a decent protocol version */
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
390 *x=(int)((long)(event->xclient.data.l[3]) & 0xffff);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
391 *y=(int)((long)(event->xclient.data.l[3])/65536);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
392 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
393
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
394 void DndDropCoordinates(Widget widget,XEvent *event,int *x,int *y)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
395 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
396 int root_x,root_y;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
397 Window child_return;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
398
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
399 DndDropRootCoordinates(event,&root_x,&root_y);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
400 XTranslateCoordinates(dpy,DefaultRootWindow(dpy),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
401 XtWindow(widget),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
402 root_x,root_y,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
403 x,y,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
404 &child_return);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
405 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
406
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
407 long DndProtocolVersion(XEvent *event)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
408 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
409 if(!DndIsDropMessage(event)) return -1L;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
410 return event->xclient.data.l[4];
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
411 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
412
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
413 int DndIsDropMessage(XEvent *event)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
414 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
415 if(event->xclient.type != ClientMessage) return 0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
416 if(event->xclient.message_type == OldDndProtocol &&
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
417 event->xclient.data.l[4]==0) return 1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
418 if(event->xclient.message_type == DndProtocol) return 1;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
419 return 0;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
420 }
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
421
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
422 void DndChangeCursor(int Type,int width,int height,char *image,char *mask,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
423 int hot_x,int hot_y)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
424 {
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
425 DndCursor[Type].ImagePixmap=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
426 XCreateBitmapFromData(dpy,DefaultRootWindow(dpy),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
427 image,width,height);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
428 DndCursor[Type].MaskPixmap=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
429 XCreateBitmapFromData(dpy,DefaultRootWindow(dpy),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
430 mask,width,height);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
431 DndCursor[Type].CursorID=
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
432 XCreatePixmapCursor(dpy,DndCursor[Type].ImagePixmap,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
433 DndCursor[Type].MaskPixmap,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
434 &Black,&White,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
435 hot_x,hot_y);
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
436 }