]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: dnd.cpp | |
3 | // Purpose: wxDropTarget, wxDropSource, wxDataObject implementation | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) 1998 Stefan Csomor |
e9576ca5 SC |
9 | // Licence: wxWindows licence |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dnd.h" | |
14 | #endif | |
15 | ||
ff143598 GD |
16 | #include "wx/defs.h" |
17 | ||
18 | #if wxUSE_DRAG_AND_DROP | |
19 | ||
e9576ca5 SC |
20 | #include "wx/dnd.h" |
21 | #include "wx/window.h" | |
ff143598 | 22 | #include "wx/toplevel.h" |
e9576ca5 SC |
23 | #include "wx/app.h" |
24 | #include "wx/gdicmn.h" | |
76a5e5d2 | 25 | #include "wx/mac/private.h" |
e9576ca5 SC |
26 | |
27 | // ---------------------------------------------------------------------------- | |
28 | // global | |
29 | // ---------------------------------------------------------------------------- | |
30 | ||
a07c1212 | 31 | void wxMacEnsureTrackingHandlersInstalled() ; |
e9576ca5 | 32 | |
a07c1212 | 33 | typedef struct |
e9576ca5 | 34 | { |
a07c1212 SC |
35 | wxWindow* m_currentTargetWindow ; |
36 | wxDropTarget* m_currentTarget ; | |
37 | wxDropSource* m_currentSource ; | |
38 | } MacTrackingGlobals ; | |
e9576ca5 | 39 | |
a07c1212 | 40 | MacTrackingGlobals gTrackingGlobals ; |
e9576ca5 | 41 | |
a07c1212 SC |
42 | //---------------------------------------------------------------------------- |
43 | // wxDropTarget | |
44 | //---------------------------------------------------------------------------- | |
e9576ca5 | 45 | |
a07c1212 SC |
46 | wxDropTarget::wxDropTarget( wxDataObject *data ) |
47 | : wxDropTargetBase( data ) | |
e9576ca5 | 48 | { |
a07c1212 | 49 | wxMacEnsureTrackingHandlersInstalled() ; |
e9576ca5 SC |
50 | } |
51 | ||
a07c1212 SC |
52 | wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x), |
53 | wxCoord WXUNUSED(y), | |
54 | wxDragResult def ) | |
e9576ca5 | 55 | { |
e9576ca5 | 56 | |
a07c1212 SC |
57 | return CurrentDragHasSupportedFormat() ? def : wxDragNone; |
58 | } | |
e9576ca5 | 59 | |
a07c1212 | 60 | bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) ) |
e9576ca5 | 61 | { |
a07c1212 SC |
62 | if (!m_dataObject) |
63 | return FALSE; | |
64 | ||
65 | return CurrentDragHasSupportedFormat() ; | |
e9576ca5 SC |
66 | } |
67 | ||
a07c1212 SC |
68 | wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), |
69 | wxDragResult def ) | |
e9576ca5 | 70 | { |
a07c1212 SC |
71 | if (!m_dataObject) |
72 | return wxDragNone; | |
73 | ||
74 | if (!CurrentDragHasSupportedFormat()) | |
75 | return wxDragNone; | |
76 | ||
77 | return GetData() ? def : wxDragNone; | |
e9576ca5 SC |
78 | } |
79 | ||
a07c1212 | 80 | bool wxDropTarget::CurrentDragHasSupportedFormat() |
e9576ca5 | 81 | { |
a07c1212 SC |
82 | bool supported = false ; |
83 | if ( gTrackingGlobals.m_currentSource != NULL ) | |
84 | { | |
e40298d5 JS |
85 | wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ; |
86 | ||
87 | if ( data ) | |
a07c1212 | 88 | { |
e40298d5 JS |
89 | size_t formatcount = data->GetFormatCount() ; |
90 | wxDataFormat *array = new wxDataFormat[ formatcount ]; | |
91 | data->GetAllFormats( array ); | |
92 | for (size_t i = 0; !supported && i < formatcount ; i++) | |
a07c1212 | 93 | { |
e40298d5 JS |
94 | wxDataFormat format = array[i] ; |
95 | if ( m_dataObject->IsSupported( format ) ) | |
96 | { | |
97 | supported = true ; | |
98 | break ; | |
99 | } | |
a07c1212 | 100 | } |
e40298d5 | 101 | delete[] array ; |
a07c1212 | 102 | } |
a07c1212 SC |
103 | } |
104 | if ( !supported ) | |
105 | { | |
e40298d5 JS |
106 | UInt16 items ; |
107 | OSErr result; | |
108 | CountDragItems((DragReference)m_currentDrag, &items); | |
109 | for (UInt16 index = 1; index <= items && supported == false ; ++index) | |
110 | { | |
111 | ItemReference theItem; | |
112 | FlavorType theType ; | |
113 | UInt16 flavors = 0 ; | |
114 | GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem); | |
115 | CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ; | |
116 | for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor ) | |
a07c1212 | 117 | { |
e40298d5 JS |
118 | result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType); |
119 | if ( m_dataObject->IsSupportedFormat( wxDataFormat( theType ) ) ) | |
120 | { | |
121 | supported = true ; | |
122 | break ; | |
123 | } | |
a07c1212 | 124 | } |
e40298d5 | 125 | } |
a07c1212 SC |
126 | } |
127 | return supported ; | |
e9576ca5 SC |
128 | } |
129 | ||
a07c1212 | 130 | bool wxDropTarget::GetData() |
e9576ca5 | 131 | { |
a07c1212 SC |
132 | if (!m_dataObject) |
133 | return FALSE; | |
e40298d5 | 134 | |
a07c1212 SC |
135 | if ( !CurrentDragHasSupportedFormat() ) |
136 | return FALSE ; | |
e40298d5 | 137 | |
a07c1212 SC |
138 | bool transferred = false ; |
139 | if ( gTrackingGlobals.m_currentSource != NULL ) | |
140 | { | |
e40298d5 JS |
141 | wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ; |
142 | ||
143 | if ( data ) | |
a07c1212 | 144 | { |
e40298d5 JS |
145 | size_t formatcount = data->GetFormatCount() ; |
146 | wxDataFormat *array = new wxDataFormat[ formatcount ]; | |
147 | data->GetAllFormats( array ); | |
148 | for (size_t i = 0; !transferred && i < formatcount ; i++) | |
a07c1212 | 149 | { |
e40298d5 JS |
150 | wxDataFormat format = array[i] ; |
151 | if ( m_dataObject->IsSupported( format ) ) | |
152 | { | |
153 | int size = data->GetDataSize( format ); | |
154 | transferred = true ; | |
155 | ||
156 | if (size == 0) | |
157 | { | |
158 | m_dataObject->SetData(format , 0 , 0 ) ; | |
159 | } | |
160 | else | |
161 | { | |
162 | char *d = new char[size]; | |
163 | data->GetDataHere( format , (void*) d ); | |
164 | m_dataObject->SetData( format , size , d ) ; | |
165 | delete[] d ; | |
166 | } | |
167 | } | |
a07c1212 | 168 | } |
e40298d5 JS |
169 | delete[] array ; |
170 | } | |
a07c1212 SC |
171 | } |
172 | if ( !transferred ) | |
173 | { | |
e40298d5 JS |
174 | UInt16 items ; |
175 | OSErr result; | |
176 | bool firstFileAdded = false ; | |
177 | CountDragItems((DragReference)m_currentDrag, &items); | |
178 | for (UInt16 index = 1; index <= items; ++index) | |
179 | { | |
180 | ItemReference theItem; | |
181 | FlavorType theType ; | |
182 | UInt16 flavors = 0 ; | |
183 | GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem); | |
184 | CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ; | |
185 | for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor ) | |
a07c1212 | 186 | { |
e40298d5 JS |
187 | result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType); |
188 | wxDataFormat format(theType) ; | |
189 | if ( m_dataObject->IsSupportedFormat( format ) ) | |
190 | { | |
191 | FlavorFlags theFlags; | |
192 | result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags); | |
193 | if (result == noErr) | |
a07c1212 | 194 | { |
e40298d5 JS |
195 | Size dataSize ; |
196 | Ptr theData ; | |
197 | GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize); | |
198 | if ( theType == 'TEXT' ) | |
199 | { | |
200 | // this increment is only valid for allocating, on the next GetFlavorData | |
201 | // call it is reset again to the original value | |
202 | dataSize++ ; | |
203 | } | |
204 | theData = new char[dataSize]; | |
205 | GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L); | |
206 | if( theType == 'TEXT' ) | |
207 | { | |
427ff662 | 208 | theData[dataSize]=0 ; |
939fba6c | 209 | wxString convert( theData , wxConvLocal ) ; |
427ff662 | 210 | m_dataObject->SetData( format, convert.Length() * sizeof(wxChar), (const wxChar*) convert ); |
e40298d5 JS |
211 | } |
212 | else if ( theType == kDragFlavorTypeHFS ) | |
213 | { | |
214 | HFSFlavor* theFile = (HFSFlavor*) theData ; | |
215 | wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec ) ; | |
216 | if ( firstFileAdded ) | |
217 | ((wxFileDataObject*)m_dataObject)->AddFile( name ) ; | |
218 | else | |
219 | { | |
220 | ((wxFileDataObject*)m_dataObject)->SetData( 0 , name.c_str() ) ; | |
221 | firstFileAdded = true ; | |
222 | } | |
223 | } | |
224 | else | |
225 | { | |
226 | m_dataObject->SetData( format, dataSize, theData ); | |
227 | } | |
228 | delete[] theData; | |
a07c1212 | 229 | } |
e40298d5 JS |
230 | break ; |
231 | } | |
a07c1212 | 232 | } |
e40298d5 | 233 | } |
a07c1212 SC |
234 | } |
235 | return TRUE ; | |
e9576ca5 SC |
236 | } |
237 | ||
238 | //------------------------------------------------------------------------- | |
239 | // wxDropSource | |
240 | //------------------------------------------------------------------------- | |
241 | ||
242 | //----------------------------------------------------------------------------- | |
243 | // drag request | |
244 | ||
a07c1212 | 245 | wxDropSource::wxDropSource(wxWindow *win, |
da804130 SC |
246 | const wxCursor &cursorCopy, |
247 | const wxCursor &cursorMove, | |
248 | const wxCursor &cursorStop) | |
249 | : wxDropSourceBase(cursorCopy, cursorMove, cursorStop) | |
e9576ca5 | 250 | { |
a07c1212 SC |
251 | wxMacEnsureTrackingHandlersInstalled() ; |
252 | m_window = win; | |
253 | } | |
e9576ca5 | 254 | |
a07c1212 SC |
255 | wxDropSource::wxDropSource(wxDataObject& data, |
256 | wxWindow *win, | |
da804130 SC |
257 | const wxCursor &cursorCopy, |
258 | const wxCursor &cursorMove, | |
259 | const wxCursor &cursorStop) | |
260 | : wxDropSourceBase(cursorCopy, cursorMove, cursorStop) | |
a07c1212 SC |
261 | { |
262 | wxMacEnsureTrackingHandlersInstalled() ; | |
263 | SetData( data ); | |
264 | m_window = win; | |
265 | } | |
e9576ca5 | 266 | |
a07c1212 | 267 | wxDropSource::~wxDropSource() |
e9576ca5 | 268 | { |
a07c1212 | 269 | } |
e9576ca5 | 270 | |
e9576ca5 | 271 | |
2245b2b2 | 272 | wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags)) |
e9576ca5 | 273 | { |
a07c1212 | 274 | wxASSERT_MSG( m_data, wxT("Drop source: no data") ); |
e40298d5 | 275 | |
a07c1212 SC |
276 | if (!m_data) |
277 | return (wxDragResult) wxDragNone; | |
e40298d5 | 278 | |
a07c1212 SC |
279 | if (m_data->GetFormatCount() == 0) |
280 | return (wxDragResult) wxDragNone; | |
e40298d5 | 281 | |
a07c1212 SC |
282 | OSErr result; |
283 | DragReference theDrag; | |
284 | RgnHandle dragRegion; | |
0cd51b2d | 285 | if ((result = NewDrag(&theDrag))) |
a07c1212 SC |
286 | { |
287 | return wxDragNone ; | |
288 | } | |
289 | // add data to drag | |
290 | size_t formatCount = m_data->GetFormatCount() ; | |
291 | wxDataFormat *formats = new wxDataFormat[formatCount] ; | |
292 | m_data->GetAllFormats( formats ) ; | |
293 | ItemReference theItem = 1 ; | |
0cd51b2d | 294 | for ( size_t i = 0 ; i < formatCount ; ++i ) |
a07c1212 SC |
295 | { |
296 | size_t dataSize = m_data->GetDataSize( formats[i] ) ; | |
297 | Ptr dataPtr = new char[dataSize] ; | |
298 | m_data->GetDataHere( formats[i] , dataPtr ) ; | |
299 | OSType type = formats[i].GetFormatId() ; | |
300 | if ( type == 'TEXT' ) | |
301 | { | |
e40298d5 | 302 | dataSize-- ; |
427ff662 SC |
303 | dataPtr[ dataSize ] = 0 ; |
304 | wxString st( (wxChar*) dataPtr ) ; | |
939fba6c | 305 | wxCharBuffer buf = st.mb_str( wxConvLocal) ; |
427ff662 | 306 | AddDragItemFlavor(theDrag, theItem, type , buf.data(), strlen(buf), 0); |
a07c1212 SC |
307 | } |
308 | else if (type == kDragFlavorTypeHFS ) | |
309 | { | |
e40298d5 JS |
310 | HFSFlavor theFlavor ; |
311 | OSErr err = noErr; | |
312 | CInfoPBRec cat; | |
313 | ||
314 | wxMacFilename2FSSpec( dataPtr , &theFlavor.fileSpec ) ; | |
315 | ||
316 | cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name; | |
317 | cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum; | |
318 | cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID; | |
319 | cat.hFileInfo.ioFDirIndex = 0; | |
320 | err = PBGetCatInfoSync(&cat); | |
321 | if (err == noErr ) | |
322 | { | |
323 | theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags; | |
324 | if (theFlavor.fileSpec.parID == fsRtParID) { | |
325 | theFlavor.fileCreator = 'MACS'; | |
326 | theFlavor.fileType = 'disk'; | |
327 | } else if ((cat.hFileInfo.ioFlAttrib & ioDirMask) != 0) { | |
328 | theFlavor.fileCreator = 'MACS'; | |
329 | theFlavor.fileType = 'fold'; | |
330 | } else { | |
331 | theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator; | |
332 | theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType; | |
333 | } | |
334 | AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0); | |
335 | } | |
a07c1212 SC |
336 | } |
337 | else | |
338 | { | |
e40298d5 | 339 | AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0); |
a07c1212 SC |
340 | } |
341 | delete[] dataPtr ; | |
342 | } | |
343 | delete[] formats ; | |
344 | ||
345 | dragRegion = NewRgn(); | |
346 | RgnHandle tempRgn = NewRgn() ; | |
347 | ||
45a0fd37 SC |
348 | EventRecord* ev = NULL ; |
349 | #if !TARGET_CARBON // TODO | |
e40298d5 | 350 | ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; |
45a0fd37 | 351 | #else |
e40298d5 JS |
352 | EventRecord rec ; |
353 | ev = &rec ; | |
354 | wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; | |
45a0fd37 | 355 | #endif |
a07c1212 SC |
356 | const short dragRegionOuterBoundary = 10 ; |
357 | const short dragRegionInnerBoundary = 9 ; | |
358 | ||
359 | SetRectRgn( dragRegion , ev->where.h - dragRegionOuterBoundary , | |
e40298d5 JS |
360 | ev->where.v - dragRegionOuterBoundary , |
361 | ev->where.h + dragRegionOuterBoundary , | |
362 | ev->where.v + dragRegionOuterBoundary ) ; | |
363 | ||
a07c1212 | 364 | SetRectRgn( tempRgn , ev->where.h - dragRegionInnerBoundary , |
e40298d5 JS |
365 | ev->where.v - dragRegionInnerBoundary , |
366 | ev->where.h + dragRegionInnerBoundary , | |
367 | ev->where.v + dragRegionInnerBoundary ) ; | |
368 | ||
a07c1212 SC |
369 | DiffRgn( dragRegion , tempRgn , dragRegion ) ; |
370 | DisposeRgn( tempRgn ) ; | |
e40298d5 | 371 | |
a07c1212 SC |
372 | // TODO:work with promises in order to return data only when drag |
373 | // was successfully completed | |
e40298d5 | 374 | |
a07c1212 SC |
375 | gTrackingGlobals.m_currentSource = this ; |
376 | result = TrackDrag(theDrag, ev , dragRegion); | |
377 | DisposeRgn(dragRegion); | |
378 | DisposeDrag(theDrag); | |
379 | gTrackingGlobals.m_currentSource = NULL ; | |
e40298d5 | 380 | |
f43084de | 381 | KeyMap keymap; |
595ec11a | 382 | GetKeys(keymap); |
f43084de JS |
383 | bool optionDown = keymap[1] & 4; |
384 | wxDragResult dndresult = optionDown ? wxDragCopy : wxDragMove; | |
385 | return dndresult; | |
a07c1212 SC |
386 | } |
387 | ||
da804130 SC |
388 | bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect) |
389 | { | |
390 | const wxCursor& cursor = GetCursor(effect); | |
391 | if ( cursor.Ok() ) | |
392 | { | |
393 | cursor.MacInstall() ; | |
394 | ||
395 | return TRUE; | |
396 | } | |
397 | else | |
398 | { | |
399 | return FALSE; | |
400 | } | |
401 | } | |
402 | ||
a07c1212 SC |
403 | bool gTrackingGlobalsInstalled = false ; |
404 | ||
405 | // passing the globals via refcon is not needed by the CFM and later architectures anymore | |
406 | // but I'll leave it in there, just in case... | |
407 | ||
408 | pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow, | |
409 | void *handlerRefCon, DragReference theDrag) ; | |
410 | pascal OSErr wxMacWindowDragReceiveHandler(WindowPtr theWindow, void *handlerRefCon, | |
411 | DragReference theDrag) ; | |
412 | ||
413 | void wxMacEnsureTrackingHandlersInstalled() | |
e9576ca5 | 414 | { |
a07c1212 SC |
415 | if( !gTrackingGlobalsInstalled ) |
416 | { | |
417 | OSErr result; | |
418 | ||
419 | result = InstallTrackingHandler(NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L,&gTrackingGlobals); | |
420 | wxASSERT( result == noErr ) ; | |
421 | result = InstallReceiveHandler(NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals); | |
422 | wxASSERT( result == noErr ) ; | |
e9576ca5 | 423 | |
a07c1212 SC |
424 | gTrackingGlobalsInstalled = true ; |
425 | } | |
426 | } | |
427 | ||
428 | pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow, | |
429 | void *handlerRefCon, DragReference theDrag) | |
430 | { | |
431 | MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon; | |
432 | Point mouse, localMouse; | |
433 | DragAttributes attributes; | |
a07c1212 SC |
434 | GetDragAttributes(theDrag, &attributes); |
435 | wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ; | |
f43084de JS |
436 | |
437 | KeyMap keymap; | |
595ec11a | 438 | GetKeys(keymap); |
f43084de JS |
439 | bool optionDown = keymap[1] & 4; |
440 | wxDragResult result = optionDown ? wxDragCopy : wxDragMove; | |
441 | ||
a07c1212 SC |
442 | switch(theMessage) |
443 | { | |
444 | case kDragTrackingEnterHandler: | |
445 | break; | |
446 | case kDragTrackingLeaveHandler: | |
447 | break; | |
448 | case kDragTrackingEnterWindow: | |
e40298d5 | 449 | trackingGlobals->m_currentTargetWindow = NULL ; |
a07c1212 SC |
450 | trackingGlobals->m_currentTarget = NULL ; |
451 | break; | |
452 | case kDragTrackingInWindow: | |
453 | if (toplevel == NULL) | |
454 | break; | |
455 | ||
456 | GetDragMouse(theDrag, &mouse, 0L); | |
457 | localMouse = mouse; | |
458 | GlobalToLocal(&localMouse); | |
f43084de JS |
459 | |
460 | ||
a07c1212 SC |
461 | |
462 | // if (attributes & kDragHasLeftSenderWindow) | |
463 | { | |
464 | wxPoint point(localMouse.h , localMouse.v) ; | |
465 | wxWindow *win = NULL ; | |
2877659b SC |
466 | ControlPartCode controlPart ; |
467 | ControlRef control = wxMacFindControlUnderMouse( localMouse , | |
468 | theWindow , &controlPart ) ; | |
469 | if ( control ) | |
470 | win = wxFindControlFromMacControl( control ) ; | |
facd6764 | 471 | // TODO toplevel->MacGetWindowFromPointSub( point , &win ) ; |
a07c1212 SC |
472 | int localx , localy ; |
473 | localx = localMouse.h ; | |
474 | localy = localMouse.v ; | |
475 | //TODO : should we use client coordinates | |
476 | if ( win ) | |
477 | win->MacRootWindowToWindow( &localx , &localy ) ; | |
478 | if ( win != trackingGlobals->m_currentTargetWindow ) | |
479 | { | |
480 | if ( trackingGlobals->m_currentTargetWindow ) | |
481 | { | |
482 | // this window is left | |
483 | if ( trackingGlobals->m_currentTarget ) | |
484 | { | |
485 | HideDragHilite(theDrag); | |
486 | trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ; | |
487 | trackingGlobals->m_currentTarget->OnLeave() ; | |
488 | trackingGlobals->m_currentTarget = NULL; | |
489 | trackingGlobals->m_currentTargetWindow = NULL ; | |
490 | } | |
491 | } | |
492 | if ( win ) | |
493 | { | |
494 | // this window is entered | |
495 | trackingGlobals->m_currentTargetWindow = win ; | |
496 | trackingGlobals->m_currentTarget = win->GetDropTarget() ; | |
a07c1212 | 497 | { |
f43084de | 498 | |
da804130 SC |
499 | if ( trackingGlobals->m_currentTarget ) |
500 | { | |
501 | trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ; | |
502 | result = trackingGlobals->m_currentTarget->OnEnter( | |
f43084de | 503 | localx , localy , result ) ; |
da804130 SC |
504 | } |
505 | ||
da804130 SC |
506 | |
507 | if ( result != wxDragNone ) | |
a07c1212 | 508 | { |
da804130 SC |
509 | int x , y ; |
510 | x = y = 0 ; | |
511 | win->MacWindowToRootWindow( &x , &y ) ; | |
512 | RgnHandle hiliteRgn = NewRgn() ; | |
2877659b SC |
513 | Rect r = { y , x , y+win->GetSize().y , x+win->GetSize().x } ; |
514 | RectRgn( hiliteRgn , &r ) ; | |
da804130 SC |
515 | ShowDragHilite(theDrag, hiliteRgn, true); |
516 | DisposeRgn( hiliteRgn ) ; | |
a07c1212 SC |
517 | } |
518 | } | |
519 | } | |
520 | } | |
521 | else | |
522 | { | |
523 | if( trackingGlobals->m_currentTarget ) | |
524 | { | |
525 | trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ; | |
526 | trackingGlobals->m_currentTarget->OnDragOver( | |
f43084de JS |
527 | localx , localy , result ) ; |
528 | } | |
529 | } | |
530 | ||
531 | // set cursor for OnEnter and OnDragOver | |
532 | if ( trackingGlobals->m_currentSource && trackingGlobals->m_currentSource->GiveFeedback( result ) == FALSE ) | |
533 | { | |
534 | if ( trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) == FALSE ) | |
535 | { | |
eb7f8ac5 | 536 | switch( result ) |
f43084de | 537 | { |
eb7f8ac5 VZ |
538 | case wxDragCopy : |
539 | { | |
540 | wxCursor cursor(wxCURSOR_COPY_ARROW) ; | |
541 | cursor.MacInstall() ; | |
542 | } | |
543 | break ; | |
544 | case wxDragMove : | |
545 | { | |
546 | wxCursor cursor(wxCURSOR_ARROW) ; | |
547 | cursor.MacInstall() ; | |
548 | } | |
549 | break ; | |
550 | case wxDragNone : | |
551 | { | |
552 | wxCursor cursor(wxCURSOR_NO_ENTRY) ; | |
553 | cursor.MacInstall() ; | |
554 | } | |
555 | break ; | |
556 | ||
557 | case wxDragError: | |
558 | case wxDragLink: | |
559 | case wxDragCancel: | |
560 | // put these here to make gcc happy | |
561 | ; | |
f43084de | 562 | } |
f43084de | 563 | } |
a07c1212 SC |
564 | } |
565 | ||
566 | } | |
567 | // MyTrackItemUnderMouse(localMouse, theWindow); | |
568 | break; | |
569 | case kDragTrackingLeaveWindow: | |
570 | if (trackingGlobals->m_currentTarget) | |
571 | { | |
572 | trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ; | |
573 | trackingGlobals->m_currentTarget->OnLeave() ; | |
574 | HideDragHilite(theDrag); | |
575 | trackingGlobals->m_currentTarget = NULL ; | |
576 | } | |
577 | trackingGlobals->m_currentTargetWindow = NULL ; | |
578 | break; | |
579 | } | |
580 | return(noErr); | |
581 | } | |
582 | ||
f2af4afb GD |
583 | pascal OSErr wxMacWindowDragReceiveHandler(WindowPtr theWindow, |
584 | void *handlerRefCon, | |
585 | DragReference theDrag) | |
a07c1212 SC |
586 | { |
587 | MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon; | |
588 | if ( trackingGlobals->m_currentTarget ) | |
589 | { | |
590 | Point mouse,localMouse ; | |
591 | int localx,localy ; | |
592 | ||
593 | trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ; | |
594 | GetDragMouse(theDrag, &mouse, 0L); | |
595 | localMouse = mouse; | |
596 | GlobalToLocal(&localMouse); | |
597 | localx = localMouse.h ; | |
598 | localy = localMouse.v ; | |
599 | //TODO : should we use client coordinates | |
600 | if ( trackingGlobals->m_currentTargetWindow ) | |
601 | trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx , &localy ) ; | |
602 | if ( trackingGlobals->m_currentTarget->OnDrop( localx , localy ) ) | |
603 | { | |
f43084de | 604 | KeyMap keymap; |
595ec11a | 605 | GetKeys(keymap); |
f43084de JS |
606 | bool optionDown = keymap[1] & 4; |
607 | wxDragResult result = optionDown ? wxDragCopy : wxDragMove; | |
608 | trackingGlobals->m_currentTarget->OnData( localx , localy , result ) ; | |
a07c1212 SC |
609 | } |
610 | } | |
611 | return(noErr); | |
612 | } | |
03e11df5 | 613 | #endif |