wxWindow* GetWindow() { return m_window ; }
void SetCurrentDragPasteboard( void* dragpasteboard ) { m_currentDragPasteboard = dragpasteboard ; }
bool MacInstallDefaultCursor(wxDragResult effect) ;
+ static wxDropSource* GetCurrentDropSource();
protected :
wxWindow *m_window;
m_window = win;
}
+wxDropSource* wxDropSource::GetCurrentDropSource()
+{
+ return gTrackingGlobals.m_currentSource;
+}
+
wxDropSource::wxDropSource(wxDataObject& data,
wxWindow *win,
const wxCursor &cursorCopy,
#include <AppKit/AppKit.h>
#include "wx/osx/private.h"
+wxDropSource* gCurrentSource = NULL;
+
wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
{
switch (code)
}
-bool wxDropTarget::CurrentDragHasSupportedFormat()
-{
- if (m_dataObject == NULL)
- return false;
-
- return m_dataObject->HasDataInPasteboard( m_currentDragPasteboard );
-}
-
-bool wxDropTarget::GetData()
-{
- if (m_dataObject == NULL)
- return false;
-
- if ( !CurrentDragHasSupportedFormat() )
- return false;
-
- return m_dataObject->GetFromPasteboard( m_currentDragPasteboard );
-}
-
//-------------------------------------------------------------------------
// wxDropSource
//-------------------------------------------------------------------------
m_window = win;
}
+wxDropSource* wxDropSource::GetCurrentDropSource()
+{
+ return gCurrentSource;
+}
+
wxDragResult wxDropSource::DoDragDrop(int flags)
{
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
NSEvent* theEvent = (NSEvent*)wxTheApp->MacGetCurrentEvent();
wxASSERT_MSG(theEvent, "DoDragDrop must be called in response to a mouse down or drag event.");
+ gCurrentSource = this;
NSImage* image = [[NSImage alloc] initWithSize: NSMakeSize(16,16)];
DropSourceDelegate* delegate = [[DropSourceDelegate alloc] init];
[delegate setImplementation: this];
result = NSDragOperationToWxDragResult([delegate code]);
[delegate release];
[image release];
+ gCurrentSource = NULL;
}
else if ( sourceDragMask & NSDragOperationMove )
result = wxDragMove;
+ // FIXME: This doesn't seem the right place for the code, as GiveFeedback
+ // will only get called when the drop target is inside the app itself
+ // but at least some cases will work now.
+ if (wxDropSource* source = wxDropSource::GetCurrentDropSource())
+ {
+ if (!source->GiveFeedback(result))
+ {
+ wxStockCursor cursorID = wxCURSOR_NONE;
+
+ switch (result)
+ {
+ case wxDragCopy:
+ cursorID = wxCURSOR_COPY_ARROW;
+ break;
+
+ case wxDragMove:
+ cursorID = wxCURSOR_ARROW;
+ break;
+
+ case wxDragNone:
+ cursorID = wxCURSOR_NO_ENTRY;
+ break;
+
+ case wxDragError:
+ case wxDragLink:
+ case wxDragCancel:
+ default:
+ // put these here to make gcc happy
+ ;
+ }
+
+ if (cursorID != wxCURSOR_NONE)
+ {
+ wxCursor cursor( cursorID );
+ cursor.MacInstall();
+ }
+ }
+ }
+
PasteboardRef pboardRef;
PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
target->SetCurrentDragPasteboard(pboardRef);
return GetData() ? def : wxDragNone;
}
+bool wxDropTarget::CurrentDragHasSupportedFormat()
+{
+ bool supported = false;
+ if (m_dataObject == NULL)
+ return false;
+
+ if ( wxDropSource* currentSource = wxDropSource::GetCurrentDropSource() )
+ {
+ wxDataObject* data = currentSource->GetDataObject();
+
+ if ( data )
+ {
+ size_t formatcount = data->GetFormatCount();
+ wxDataFormat *array = new wxDataFormat[formatcount];
+ data->GetAllFormats( array );
+ for (size_t i = 0; !supported && i < formatcount; i++)
+ {
+ wxDataFormat format = array[i];
+ if ( m_dataObject->IsSupported( format ) )
+ {
+ supported = true;
+ break;
+ }
+ }
+
+ delete [] array;
+ }
+ }
+
+ if ( !supported )
+ {
+ supported = m_dataObject->HasDataInPasteboard( m_currentDragPasteboard );
+ }
+
+ return supported;
+}
+
+bool wxDropTarget::GetData()
+{
+ if (m_dataObject == NULL)
+ return false;
+
+ if ( !CurrentDragHasSupportedFormat() )
+ return false;
+
+ bool transferred = false;
+ if ( wxDropSource* currentSource = wxDropSource::GetCurrentDropSource() )
+ {
+ wxDataObject* data = currentSource->GetDataObject();
+
+ if (data != NULL)
+ {
+ size_t formatcount = data->GetFormatCount();
+ wxDataFormat *array = new wxDataFormat[formatcount];
+ data->GetAllFormats( array );
+ for (size_t i = 0; !transferred && i < formatcount; i++)
+ {
+ wxDataFormat format = array[i];
+ if ( m_dataObject->IsSupported( format ) )
+ {
+ int size = data->GetDataSize( format );
+ transferred = true;
+
+ if (size == 0)
+ {
+ m_dataObject->SetData( format, 0, 0 );
+ }
+ else
+ {
+ char *d = new char[size];
+ data->GetDataHere( format, (void*)d );
+ m_dataObject->SetData( format, size, d );
+ delete [] d;
+ }
+ }
+ }
+
+ delete [] array;
+ }
+ }
+
+ if ( !transferred )
+ {
+ transferred = m_dataObject->GetFromPasteboard( m_currentDragPasteboard );
+ }
+
+ return transferred;
+}
+
//-------------------------------------------------------------------------
// wxDropSource
//-------------------------------------------------------------------------