]>
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
8 // Copyright: (c) 1998 Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #if wxUSE_DRAG_AND_DROP
20 #include "wx/toplevel.h"
21 #include "wx/gdicmn.h"
24 #include "wx/osx/private.h"
26 //----------------------------------------------------------------------------
28 //----------------------------------------------------------------------------
30 wxDragResult
wxDropTarget::OnDragOver(
31 wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
34 return CurrentDragHasSupportedFormat() ? def
: wxDragNone
;
37 wxDataFormat
wxDropTarget::GetMatchingPair()
39 wxFAIL_MSG("wxDropTarget::GetMatchingPair() not implemented in src/osx/dnd_osx.cpp");
43 bool wxDropTarget::OnDrop( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
) )
45 if (m_dataObject
== NULL
)
48 return CurrentDragHasSupportedFormat();
51 wxDragResult
wxDropTarget::OnData(
52 wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
55 if (m_dataObject
== NULL
)
58 if (!CurrentDragHasSupportedFormat())
61 return GetData() ? def
: wxDragNone
;
64 bool wxDropTarget::CurrentDragHasSupportedFormat()
66 bool supported
= false;
67 if (m_dataObject
== NULL
)
70 if ( wxDropSource
* currentSource
= wxDropSource::GetCurrentDropSource() )
72 wxDataObject
* data
= currentSource
->GetDataObject();
76 size_t formatcount
= data
->GetFormatCount();
77 wxDataFormat
*array
= new wxDataFormat
[formatcount
];
78 data
->GetAllFormats( array
);
79 for (size_t i
= 0; !supported
&& i
< formatcount
; i
++)
81 wxDataFormat format
= array
[i
];
82 if ( m_dataObject
->IsSupported( format
) )
95 supported
= m_dataObject
->HasDataInPasteboard( m_currentDragPasteboard
);
101 bool wxDropTarget::GetData()
103 if (m_dataObject
== NULL
)
106 if ( !CurrentDragHasSupportedFormat() )
109 bool transferred
= false;
110 if ( wxDropSource
* currentSource
= wxDropSource::GetCurrentDropSource() )
112 wxDataObject
* data
= currentSource
->GetDataObject();
116 size_t formatcount
= data
->GetFormatCount();
117 wxDataFormat
*array
= new wxDataFormat
[formatcount
];
118 data
->GetAllFormats( array
);
119 for (size_t i
= 0; !transferred
&& i
< formatcount
; i
++)
121 wxDataFormat format
= array
[i
];
122 if ( m_dataObject
->IsSupported( format
) )
124 int size
= data
->GetDataSize( format
);
129 m_dataObject
->SetData( format
, 0, 0 );
133 char *d
= new char[size
];
134 data
->GetDataHere( format
, (void*)d
);
135 m_dataObject
->SetData( format
, size
, d
);
147 transferred
= m_dataObject
->GetFromPasteboard( m_currentDragPasteboard
);
153 //-------------------------------------------------------------------------
155 //-------------------------------------------------------------------------
157 //-----------------------------------------------------------------------------
160 wxDropSource::~wxDropSource()
164 bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect
)
166 const wxCursor
& cursor
= GetCursor(effect
);
167 bool result
= cursor
.IsOk();
175 #endif // wxUSE_DRAG_AND_DROP