///////////////////////////////////////////////////////////////////////////////
-// 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
bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
{
if (!m_dataObject)
- return FALSE;
+ return false;
return CurrentDragHasSupportedFormat() ;
}
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() ;
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 ;
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 ;
}
}
}
- 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() ;
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 ) ;
}
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 ;
{
FlavorFlags theFlags;
result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
- if (result == noErr)
+ if (result == noErr)
{
Size dataSize ;
Ptr theData ;
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 )
{
else
{
((wxFileDataObject*)m_dataObject)->SetData( 0 , name.c_str() ) ;
- firstFileAdded = true ;
+ firstFileAdded = true ;
}
}
else
}
}
}
- return TRUE ;
+ return true ;
}
//-------------------------------------------------------------------------
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;
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;
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() ;
#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;
{
cursor.MacInstall() ;
- return TRUE;
+ return true;
}
else
{
- return FALSE;
+ return false;
}
}
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;
GlobalToLocal(&localMouse);
-
-// if (attributes & kDragHasLeftSenderWindow)
+
+// if (attributes & kDragHasLeftSenderWindow)
{
wxPoint point(localMouse.h , localMouse.v) ;
wxWindow *win = NULL ;
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 ;
}
}
}
-
+
}
// MyTrackItemUnderMouse(localMouse, theWindow);
break;
case kDragTrackingLeaveWindow:
- if (trackingGlobals->m_currentTarget)
+ if (trackingGlobals->m_currentTarget)
{
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
trackingGlobals->m_currentTarget->OnLeave() ;
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;