annotate src/offix.c @ 3179:15139dbf89f4

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