various fixes, scrollview scrollers, text painting
[wmaker-crm.git] / WINGs / dragdestination.c
blob2c0441dfb4352300c058aa1ca7dbe90e8bf869fc
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 printf("%x drag entered\n", W_VIEW_DRAWABLE(self));
100 return WDOperationNone;
103 static unsigned defDraggingUpdated(WMView *self, WMDraggingInfo *info)
105 printf("%x drag updat\n", W_VIEW_DRAWABLE(self));
106 return WDOperationNone;
109 static void defDraggingExited(WMView *self, WMDraggingInfo *info)
111 printf("%x drag exit\n", W_VIEW_DRAWABLE(self));
114 static Bool defPrepareForDragOperation(WMView *self, WMDraggingInfo *info)
116 printf("%x drag prep\n", W_VIEW_DRAWABLE(self));
117 return False;
120 static Bool defPerformDragOperation(WMView *self, WMDraggingInfo *info)
122 printf("%x drag perf\n", W_VIEW_DRAWABLE(self));
123 return False;
126 static void defConcludeDragOperation(WMView *self, WMDraggingInfo *info)
128 printf("%x drag concl\n", W_VIEW_DRAWABLE(self));
133 void
134 WMSetViewDragDestinationProcs(WMView *view, WMDragDestinationProcs *procs)
136 if (view->dragDestinationProcs == NULL) {
137 view->dragDestinationProcs = wmalloc(sizeof(WMDragDestinationProcs));
138 } else {
139 free(view->dragDestinationProcs);
141 *view->dragDestinationProcs = *procs;
143 /*XXX fill in non-implemented stuffs */
144 if (procs->draggingEntered == NULL) {
145 view->dragDestinationProcs->draggingEntered = defDraggingEntered;
147 if (procs->draggingUpdated == NULL) {
148 view->dragDestinationProcs->draggingUpdated = defDraggingUpdated;
150 if (procs->draggingExited == NULL) {
151 view->dragDestinationProcs->draggingExited = defDraggingExited;
153 if (procs->prepareForDragOperation == NULL) {
154 view->dragDestinationProcs->prepareForDragOperation =
155 defPrepareForDragOperation;
157 if (procs->performDragOperation == NULL) {
158 view->dragDestinationProcs->performDragOperation =
159 defPerformDragOperation;
161 if (procs->concludeDragOperation == NULL) {
162 view->dragDestinationProcs->concludeDragOperation =
163 defConcludeDragOperation;
173 WMPoint WMGetDraggingInfoImageLocation(WMDraggingInfo *info)
175 return info->imageLocation;
180 static void
181 receivedData(WMView *view, Atom selection, Atom target, Time timestamp,
182 void *cdata, WMData *data)
189 Bool WMRequestDroppedData(WMView *view, WMDraggingInfo *info, char *type,
190 WMDropDataCallback *callback)
192 WMScreen *scr = W_VIEW_SCREEN(view);
193 #if 0
194 if (info->finished) {
195 return False;
198 if (type != NULL) {
199 if (!WMRequestSelection(scr->dragInfo.destView,
200 scr->xdndSelectionAtom,
201 XInternAtom(scr->display, type, False),
202 scr->dragInfo.timestamp,
203 receivedData, &scr->dragInfo)) {
204 wwarning("could not request data for dropped data");
206 /* send finished message */
207 sendClientMessage(scr->display, source,
208 scr->xdndFinishedAtom,
209 scr->dragInfo.destinationWindow,
210 0, 0, 0, 0);
212 } else {
213 /* send finished message */
214 sendClientMessage(scr->display, source,
215 scr->xdndFinishedAtom,
216 scr->dragInfo.destinationWindow,
217 0, 0, 0, 0);
219 #endif