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