more cursor motion and text entry fixes, esp. for graphic blocks...
[wmaker-crm.git] / WINGs / dragdestination.c
blob3497ed085d95194e5953df32ada3487f12709e27
3 #include <X11/Xatom.h>
5 #include "WINGsP.h"
8 /* dropping */
10 typedef struct W_DNDTargetInfo {
11 /* data types accepted for drops */
12 Atom *dropTypes;
13 int dropTypeCount;
16 } DNDTargetInfo;
19 static Atom XDNDversion = XDND_VERSION;
22 static void
23 realizedObserver(void *self, WMNotification *notif)
25 WMView *view = (WMView*)WMGetNotificationObject(notif);
27 XChangeProperty(W_VIEW_SCREEN(view)->display, W_VIEW_DRAWABLE(view),
28 W_VIEW_SCREEN(view)->xdndAwareAtom,
29 XA_ATOM, 32, PropModeReplace,
30 (unsigned char*)&XDNDversion, 1);
32 WMRemoveNotificationObserver(self);
36 void
37 W_SetXdndAwareProperty(WMScreen *scr, WMView *view, Atom *types, int typeCount)
39 Display *dpy = scr->display;
41 view = W_TopLevelOfView(view);
43 if (!view->flags.xdndHintSet) {
44 view->flags.xdndHintSet = 1;
46 if (view->flags.realized) {
47 XChangeProperty(dpy, W_VIEW_DRAWABLE(view), scr->xdndAwareAtom,
48 XA_ATOM, 32, PropModeReplace,
49 (unsigned char*)&XDNDversion, 1);
50 } else {
51 WMAddNotificationObserver(realizedObserver,
52 /* just use as an id */
53 &view->dragDestinationProcs,
54 WMViewRealizedNotification,
55 view);
62 void
63 WMRegisterViewForDraggedTypes(WMView *view, char *acceptedTypes[])
65 Atom *types;
66 int typeCount;
67 int i;
69 typeCount = 0;
70 while (acceptedTypes[typeCount++]);
72 types = wmalloc(sizeof(Atom)*(typeCount+1));
74 for (i = 0; i < typeCount; i++) {
75 types[i] = XInternAtom(W_VIEW_SCREEN(view)->display,
76 acceptedTypes[i], False);
78 types[i] = 0;
80 view->droppableTypes = types;
82 W_SetXdndAwareProperty(W_VIEW_SCREEN(view), view, types, typeCount);
86 void
87 WMUnregisterViewDraggedTypes(WMView *view)
89 if (view->droppableTypes != NULL)
90 wfree(view->droppableTypes);
91 view->droppableTypes = NULL;
94 /***********************************************************************/
97 static unsigned defDraggingEntered(WMView *self, WMDraggingInfo *info)
99 return WDOperationNone;
102 static unsigned defDraggingUpdated(WMView *self, WMDraggingInfo *info)
104 return WDOperationNone;
107 static void defDraggingExited(WMView *self, WMDraggingInfo *info)
111 static Bool defPrepareForDragOperation(WMView *self, WMDraggingInfo *info)
113 return False;
116 static Bool defPerformDragOperation(WMView *self, WMDraggingInfo *info)
118 return False;
121 static void defConcludeDragOperation(WMView *self, WMDraggingInfo *info)
127 void
128 WMSetViewDragDestinationProcs(WMView *view, WMDragDestinationProcs *procs)
130 if (view->dragDestinationProcs == NULL) {
131 view->dragDestinationProcs = wmalloc(sizeof(WMDragDestinationProcs));
132 } else {
133 free(view->dragDestinationProcs);
135 *view->dragDestinationProcs = *procs;
137 /*XXX fill in non-implemented stuffs */
138 if (procs->draggingEntered == NULL) {
139 view->dragDestinationProcs->draggingEntered = defDraggingEntered;
141 if (procs->draggingUpdated == NULL) {
142 view->dragDestinationProcs->draggingUpdated = defDraggingUpdated;
144 if (procs->draggingExited == NULL) {
145 view->dragDestinationProcs->draggingExited = defDraggingExited;
147 if (procs->prepareForDragOperation == NULL) {
148 view->dragDestinationProcs->prepareForDragOperation =
149 defPrepareForDragOperation;
151 if (procs->performDragOperation == NULL) {
152 view->dragDestinationProcs->performDragOperation =
153 defPerformDragOperation;
155 if (procs->concludeDragOperation == NULL) {
156 view->dragDestinationProcs->concludeDragOperation =
157 defConcludeDragOperation;
167 WMPoint WMGetDraggingInfoImageLocation(WMDraggingInfo *info)
169 return info->imageLocation;
174 static void
175 receivedData(WMView *view, Atom selection, Atom target, Time timestamp,
176 void *cdata, WMData *data)
183 Bool WMRequestDroppedData(WMView *view, WMDraggingInfo *info, char *type,
184 WMDropDataCallback *callback)
186 WMScreen *scr = W_VIEW_SCREEN(view);
187 #if 0
188 if (info->finished) {
189 return False;
192 if (type != NULL) {
193 if (!WMRequestSelection(scr->dragInfo.destView,
194 scr->xdndSelectionAtom,
195 XInternAtom(scr->display, type, False),
196 scr->dragInfo.timestamp,
197 receivedData, &scr->dragInfo)) {
198 wwarning("could not request data for dropped data");
200 /* send finished message */
201 sendClientMessage(scr->display, source,
202 scr->xdndFinishedAtom,
203 scr->dragInfo.destinationWindow,
204 0, 0, 0, 0);
206 } else {
207 /* send finished message */
208 sendClientMessage(scr->display, source,
209 scr->xdndFinishedAtom,
210 scr->dragInfo.destinationWindow,
211 0, 0, 0, 0);
213 #endif