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