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