]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/classic/dnd.cpp
Back to previous call with -1 replacement.
[wxWidgets.git] / src / mac / classic / dnd.cpp
index 3628ec5088fbb1a2e9c8272822569b9f4632ce33..e770b842d9ca0c94527ac4cfdeb558fa8ad6323f 100644 (file)
@@ -1,27 +1,31 @@
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        dnd.cpp
+// Name:        src/mac/classic/dnd.cpp
 // Purpose:     wxDropTarget, wxDropSource, wxDataObject implementation
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     1998-01-01
 // RCS-ID:      $Id$
 // Copyright:   (c) 1998 Stefan Csomor
-// Licence:     wxWidgets licence
+// Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation "dnd.h"
-#endif
+#include "wx/wxprec.h"
 
-#include "wx/defs.h"
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
 
 #if wxUSE_DRAG_AND_DROP
 
 #include "wx/dnd.h"
-#include "wx/window.h"
-#include "wx/toplevel.h"
-#include "wx/app.h"
-#include "wx/gdicmn.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/app.h"
+    #include "wx/window.h"
+    #include "wx/toplevel.h"
+    #include "wx/gdicmn.h"
+#endif // WX_PRECOMP
+
 #include "wx/mac/private.h"
 
 // ----------------------------------------------------------------------------
 
 void wxMacEnsureTrackingHandlersInstalled() ;
 
-typedef struct 
+typedef struct
 {
     wxWindow* m_currentTargetWindow ;
     wxDropTarget* m_currentTarget ;
     wxDropSource* m_currentSource ;
 } MacTrackingGlobals ;
 
-MacTrackingGlobals gTrackingGlobals ; 
+MacTrackingGlobals gTrackingGlobals ;
 
 //----------------------------------------------------------------------------
 // wxDropTarget
@@ -60,7 +64,7 @@ wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x),
 bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
 {
     if (!m_dataObject)
-        return FALSE;
+        return false;
 
     return CurrentDragHasSupportedFormat() ;
 }
@@ -77,13 +81,13 @@ wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
     return GetData() ? def : wxDragNone;
 }
 
-bool wxDropTarget::CurrentDragHasSupportedFormat() 
+bool wxDropTarget::CurrentDragHasSupportedFormat()
 {
     bool supported = false ;
     if ( gTrackingGlobals.m_currentSource != NULL )
     {
         wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
-        
+
         if ( data )
         {
             size_t formatcount = data->GetFormatCount() ;
@@ -92,7 +96,7 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
             for (size_t i = 0; !supported && i < formatcount ; i++)
             {
                 wxDataFormat format = array[i] ;
-                if ( m_dataObject->IsSupported( format ) ) 
+                if ( m_dataObject->IsSupported( format ) )
                 {
                     supported = true ;
                     break ;
@@ -106,7 +110,7 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
         UInt16 items ;
         OSErr result;
         CountDragItems((DragReference)m_currentDrag, &items);
-        for (UInt16 index = 1; index <= items && supported == false ; ++index) 
+        for (UInt16 index = 1; index <= items && supported == false ; ++index)
         {
             ItemReference theItem;
             FlavorType theType ;
@@ -124,22 +128,22 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
             }
         }
     }
-    return supported ;   
+    return supported ;
 }
 
 bool wxDropTarget::GetData()
 {
     if (!m_dataObject)
-        return FALSE;
-    
+        return false;
+
     if ( !CurrentDragHasSupportedFormat() )
-        return FALSE ;
-    
-    bool transferred = false ;   
+        return false ;
+
+    bool transferred = false ;
     if ( gTrackingGlobals.m_currentSource != NULL )
     {
         wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
-        
+
         if ( data )
         {
             size_t formatcount = data->GetFormatCount() ;
@@ -148,12 +152,12 @@ bool wxDropTarget::GetData()
             for (size_t i = 0; !transferred && i < formatcount ; i++)
             {
                 wxDataFormat format = array[i] ;
-                if ( m_dataObject->IsSupported( format ) ) 
+                if ( m_dataObject->IsSupported( format ) )
                 {
                     int size = data->GetDataSize( format );
                     transferred = true ;
-                    
-                    if (size == 0) 
+
+                    if (size == 0)
                     {
                         m_dataObject->SetData(format , 0 , 0 ) ;
                     }
@@ -175,7 +179,7 @@ bool wxDropTarget::GetData()
         OSErr result;
         bool firstFileAdded = false ;
         CountDragItems((DragReference)m_currentDrag, &items);
-        for (UInt16 index = 1; index <= items; ++index) 
+        for (UInt16 index = 1; index <= items; ++index)
         {
             ItemReference theItem;
             FlavorType theType ;
@@ -190,7 +194,7 @@ bool wxDropTarget::GetData()
                 {
                     FlavorFlags theFlags;
                     result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
-                    if (result == noErr) 
+                    if (result == noErr)
                     {
                         Size dataSize ;
                         Ptr theData ;
@@ -202,12 +206,12 @@ bool wxDropTarget::GetData()
                             dataSize++ ;
                         }
                         theData = new char[dataSize];
-                        GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L); 
+                        GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L);
                         if( theType == 'TEXT' )
                         {
-                            theData[dataSize]=0 ; 
-                            wxString convert( theData , wxConvLocal ) ;    
-                            m_dataObject->SetData( format, convert.Length() * sizeof(wxChar), (const wxChar*) convert );
+                            theData[dataSize]=0 ;
+                            wxString convert( theData , wxConvLocal ) ;
+                            m_dataObject->SetData( format, convert.length() * sizeof(wxChar), (const wxChar*) convert );
                         }
                         else if ( theType == kDragFlavorTypeHFS )
                         {
@@ -218,7 +222,7 @@ bool wxDropTarget::GetData()
                             else
                             {
                                 ((wxFileDataObject*)m_dataObject)->SetData( 0 , name.c_str() ) ;
-                                firstFileAdded = true ;    
+                                firstFileAdded = true ;
                             }
                         }
                         else
@@ -232,7 +236,7 @@ bool wxDropTarget::GetData()
             }
         }
     }
-    return TRUE ;   
+    return true ;
 }
 
 //-------------------------------------------------------------------------
@@ -272,13 +276,13 @@ wxDropSource::~wxDropSource()
 wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
 {
     wxASSERT_MSG( m_data, wxT("Drop source: no data") );
-    
+
     if (!m_data)
         return (wxDragResult) wxDragNone;
-    
+
     if (m_data->GetFormatCount() == 0)
         return (wxDragResult) wxDragNone;
-    
+
     OSErr result;
     DragReference theDrag;
     RgnHandle dragRegion;
@@ -310,9 +314,9 @@ wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
             HFSFlavor  theFlavor ;
             OSErr err = noErr;
             CInfoPBRec cat;
-            
+
             wxMacFilename2FSSpec( dataPtr , &theFlavor.fileSpec ) ;
-            
+
             cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name;
             cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
             cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
@@ -331,20 +335,20 @@ wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
                     theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator;
                     theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
                 }
-                AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0);  
-            }    
+                AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0);
+            }
         }
         else
         {
-            AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);      
+            AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);
         }
         delete[] dataPtr ;
     }
     delete[] formats ;
-    
+
     dragRegion = NewRgn();
     RgnHandle tempRgn = NewRgn() ;
-    
+
     EventRecord* ev = NULL ;
 #if !TARGET_CARBON // TODO
     ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
@@ -355,29 +359,29 @@ wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
 #endif
     const short dragRegionOuterBoundary = 10 ;
     const short dragRegionInnerBoundary = 9 ;
-    
-    SetRectRgn( dragRegion , ev->where.h - dragRegionOuterBoundary , 
+
+    SetRectRgn( dragRegion , ev->where.h - dragRegionOuterBoundary ,
         ev->where.v  - dragRegionOuterBoundary ,
-        ev->where.h + dragRegionOuterBoundary , 
+        ev->where.h + dragRegionOuterBoundary ,
         ev->where.v + dragRegionOuterBoundary ) ;
-    
-    SetRectRgn( tempRgn , ev->where.h - dragRegionInnerBoundary , 
+
+    SetRectRgn( tempRgn , ev->where.h - dragRegionInnerBoundary ,
         ev->where.v  - dragRegionInnerBoundary ,
-        ev->where.h + dragRegionInnerBoundary , 
+        ev->where.h + dragRegionInnerBoundary ,
         ev->where.v + dragRegionInnerBoundary ) ;
-    
+
     DiffRgn( dragRegion , tempRgn , dragRegion ) ;
-    DisposeRgn( tempRgn ) ;    
-    
+    DisposeRgn( tempRgn ) ;
+
     // TODO:work with promises in order to return data only when drag
     // was successfully completed
-    
+
     gTrackingGlobals.m_currentSource = this ;
     result = TrackDrag(theDrag, ev , dragRegion);
     DisposeRgn(dragRegion);
     DisposeDrag(theDrag);
     gTrackingGlobals.m_currentSource = NULL ;
-    
+
     KeyMap keymap;
     GetKeys(keymap);
     bool optionDown = keymap[1] & 4;
@@ -392,11 +396,11 @@ bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
     {
         cursor.MacInstall() ;
 
-        return TRUE;
+        return true;
     }
     else
     {
-        return FALSE;
+        return false;
     }
 }
 
@@ -427,19 +431,19 @@ void wxMacEnsureTrackingHandlersInstalled()
 
 pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
   void *handlerRefCon, DragReference theDrag)
-{ 
+{
     MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
     Point mouse, localMouse;
     DragAttributes attributes;
     GetDragAttributes(theDrag, &attributes);
-    wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ; 
+    wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( (WXWindow) theWindow ) ;
 
     KeyMap keymap;
     GetKeys(keymap);
     bool optionDown = keymap[1] & 4;
     wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
 
-    switch(theMessage) 
+    switch(theMessage)
     {
         case kDragTrackingEnterHandler:
             break;
@@ -458,8 +462,8 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
             GlobalToLocal(&localMouse);
 
 
-            
-//            if (attributes & kDragHasLeftSenderWindow) 
+
+//            if (attributes & kDragHasLeftSenderWindow)
             {
                 wxPoint point(localMouse.h , localMouse.v) ;
                 wxWindow *win = NULL ;
@@ -491,14 +495,14 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
                         trackingGlobals->m_currentTarget = win->GetDropTarget() ;
                         {
 
-                               if ( trackingGlobals->m_currentTarget )
-                               {
-                               trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
-                               result = trackingGlobals->m_currentTarget->OnEnter(
-                                       localx , localy , result ) ;
+                            if ( trackingGlobals->m_currentTarget )
+                            {
+                                trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
+                                result = trackingGlobals->m_currentTarget->OnEnter(
+                                    localx , localy , result ) ;
                             }
-                                
-                           
+
+
                             if ( result != wxDragNone )
                             {
                                 int x , y ;
@@ -556,12 +560,12 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
                       }
                   }
                 }
-                
+
           }
             // MyTrackItemUnderMouse(localMouse, theWindow);
             break;
         case kDragTrackingLeaveWindow:
-            if (trackingGlobals->m_currentTarget) 
+            if (trackingGlobals->m_currentTarget)
             {
                 trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                 trackingGlobals->m_currentTarget->OnLeave() ;
@@ -577,13 +581,13 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
 pascal OSErr wxMacWindowDragReceiveHandler(WindowPtr theWindow,
                                            void *handlerRefCon,
                                            DragReference theDrag)
-{ 
+{
     MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
     if ( trackingGlobals->m_currentTarget )
     {
         Point mouse,localMouse ;
         int localx,localy ;
-        
+
         trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
         GetDragMouse(theDrag, &mouse, 0L);
         localMouse = mouse;