]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/dnd_osx.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/dnd_osx.cpp
3 // Purpose: Mac common wxDropTarget, wxDropSource implementations
4 // Author: Stefan Csomor
7 // Copyright: (c) 1998 Stefan Csomor
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #if wxUSE_DRAG_AND_DROP
19 #include "wx/toplevel.h"
20 #include "wx/gdicmn.h"
23 #include "wx/osx/private.h"
25 //----------------------------------------------------------------------------
27 //----------------------------------------------------------------------------
29 wxDragResult
wxDropTarget::OnDragOver(
30 wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
33 return CurrentDragHasSupportedFormat() ? def
: wxDragNone
;
36 wxDataFormat
wxDropTarget::GetMatchingPair()
38 wxFAIL_MSG("wxDropTarget::GetMatchingPair() not implemented in src/osx/dnd_osx.cpp");
42 bool wxDropTarget::OnDrop( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
) )
44 if (m_dataObject
== NULL
)
47 return CurrentDragHasSupportedFormat();
50 wxDragResult
wxDropTarget::OnData(
51 wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
54 if (m_dataObject
== NULL
)
57 if (!CurrentDragHasSupportedFormat())
60 return GetData() ? def
: wxDragNone
;
63 bool wxDropTarget::CurrentDragHasSupportedFormat()
65 bool supported
= false;
66 if (m_dataObject
== NULL
)
69 if ( wxDropSource
* currentSource
= wxDropSource::GetCurrentDropSource() )
71 wxDataObject
* data
= currentSource
->GetDataObject();
75 size_t formatcount
= data
->GetFormatCount();
76 wxDataFormat
*array
= new wxDataFormat
[formatcount
];
77 data
->GetAllFormats( array
);
78 for (size_t i
= 0; !supported
&& i
< formatcount
; i
++)
80 wxDataFormat format
= array
[i
];
81 if ( m_dataObject
->IsSupported( format
, wxDataObject::Set
) )
94 supported
= m_dataObject
->HasDataInPasteboard( m_currentDragPasteboard
);
100 bool wxDropTarget::GetData()
102 if (m_dataObject
== NULL
)
105 if ( !CurrentDragHasSupportedFormat() )
108 bool transferred
= false;
109 if ( wxDropSource
* currentSource
= wxDropSource::GetCurrentDropSource() )
111 wxDataObject
* data
= currentSource
->GetDataObject();
115 size_t formatcount
= data
->GetFormatCount();
116 wxDataFormat
*array
= new wxDataFormat
[formatcount
];
117 data
->GetAllFormats( array
);
118 for (size_t i
= 0; !transferred
&& i
< formatcount
; i
++)
120 wxDataFormat format
= array
[i
];
121 if ( m_dataObject
->IsSupported( format
, wxDataObject::Set
) )
123 int size
= data
->GetDataSize( format
);
128 m_dataObject
->SetData( format
, 0, 0 );
132 char *d
= new char[size
];
133 data
->GetDataHere( format
, (void*)d
);
134 m_dataObject
->SetData( format
, size
, d
);
146 transferred
= m_dataObject
->GetFromPasteboard( m_currentDragPasteboard
);
152 //-------------------------------------------------------------------------
154 //-------------------------------------------------------------------------
156 //-----------------------------------------------------------------------------
159 wxDropSource::~wxDropSource()
163 bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect
)
165 const wxCursor
& cursor
= GetCursor(effect
);
166 bool result
= cursor
.IsOk();
174 #endif // wxUSE_DRAG_AND_DROP