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