]> git.saurik.com Git - wxWidgets.git/blob - src/osx/dnd_osx.cpp
Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / src / osx / dnd_osx.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/dnd_osx.cpp
3 // Purpose: Mac common wxDropTarget, wxDropSource implementations
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // Copyright: (c) 1998 Stefan Csomor
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #if wxUSE_DRAG_AND_DROP
14
15 #include "wx/dnd.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/toplevel.h"
20 #include "wx/gdicmn.h"
21 #endif // WX_PRECOMP
22
23 #include "wx/osx/private.h"
24
25 //----------------------------------------------------------------------------
26 // wxDropTarget
27 //----------------------------------------------------------------------------
28
29 wxDragResult wxDropTarget::OnDragOver(
30 wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
31 wxDragResult def )
32 {
33 return CurrentDragHasSupportedFormat() ? def : wxDragNone;
34 }
35
36 wxDataFormat wxDropTarget::GetMatchingPair()
37 {
38 wxFAIL_MSG("wxDropTarget::GetMatchingPair() not implemented in src/osx/dnd_osx.cpp");
39 return wxDF_INVALID;
40 }
41
42 bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
43 {
44 if (m_dataObject == NULL)
45 return false;
46
47 return CurrentDragHasSupportedFormat();
48 }
49
50 wxDragResult wxDropTarget::OnData(
51 wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
52 wxDragResult def )
53 {
54 if (m_dataObject == NULL)
55 return wxDragNone;
56
57 if (!CurrentDragHasSupportedFormat())
58 return wxDragNone;
59
60 return GetData() ? def : wxDragNone;
61 }
62
63 bool wxDropTarget::CurrentDragHasSupportedFormat()
64 {
65 bool supported = false;
66 if (m_dataObject == NULL)
67 return false;
68
69 if ( wxDropSource* currentSource = wxDropSource::GetCurrentDropSource() )
70 {
71 wxDataObject* data = currentSource->GetDataObject();
72
73 if ( data )
74 {
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++)
79 {
80 wxDataFormat format = array[i];
81 if ( m_dataObject->IsSupported( format, wxDataObject::Set ) )
82 {
83 supported = true;
84 break;
85 }
86 }
87
88 delete [] array;
89 }
90 }
91
92 if ( !supported )
93 {
94 supported = m_dataObject->HasDataInPasteboard( m_currentDragPasteboard );
95 }
96
97 return supported;
98 }
99
100 bool wxDropTarget::GetData()
101 {
102 if (m_dataObject == NULL)
103 return false;
104
105 if ( !CurrentDragHasSupportedFormat() )
106 return false;
107
108 bool transferred = false;
109 if ( wxDropSource* currentSource = wxDropSource::GetCurrentDropSource() )
110 {
111 wxDataObject* data = currentSource->GetDataObject();
112
113 if (data != NULL)
114 {
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++)
119 {
120 wxDataFormat format = array[i];
121 if ( m_dataObject->IsSupported( format, wxDataObject::Set ) )
122 {
123 int size = data->GetDataSize( format );
124 transferred = true;
125
126 if (size == 0)
127 {
128 m_dataObject->SetData( format, 0, 0 );
129 }
130 else
131 {
132 char *d = new char[size];
133 data->GetDataHere( format, (void*)d );
134 m_dataObject->SetData( format, size, d );
135 delete [] d;
136 }
137 }
138 }
139
140 delete [] array;
141 }
142 }
143
144 if ( !transferred )
145 {
146 transferred = m_dataObject->GetFromPasteboard( m_currentDragPasteboard );
147 }
148
149 return transferred;
150 }
151
152 //-------------------------------------------------------------------------
153 // wxDropSource
154 //-------------------------------------------------------------------------
155
156 //-----------------------------------------------------------------------------
157 // drag request
158
159 wxDropSource::~wxDropSource()
160 {
161 }
162
163 bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
164 {
165 const wxCursor& cursor = GetCursor(effect);
166 bool result = cursor.IsOk();
167
168 if ( result )
169 cursor.MacInstall();
170
171 return result;
172 }
173
174 #endif // wxUSE_DRAG_AND_DROP
175