]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: dnd.cpp | |
2d120f83 | 3 | // Purpose: wxDropTarget, wxDropSource classes |
4bb6408c | 4 | // Author: Julian Smart |
2d120f83 | 5 | // Id: $Id$ |
4bb6408c | 6 | // Copyright: (c) 1998 Julian Smart |
65571936 | 7 | // Licence: wxWindows licence |
4bb6408c JS |
8 | /////////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 | 10 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
4bb6408c JS |
11 | #pragma implementation "dnd.h" |
12 | #endif | |
13 | ||
1248b41f MB |
14 | // For compilers that support precompilation, includes "wx.h". |
15 | #include "wx/wxprec.h" | |
16 | ||
2d120f83 JS |
17 | #include "wx/setup.h" |
18 | ||
19 | #if wxUSE_DRAG_AND_DROP | |
20 | ||
4bb6408c JS |
21 | #include "wx/dnd.h" |
22 | #include "wx/window.h" | |
23 | #include "wx/app.h" | |
24 | #include "wx/gdicmn.h" | |
2d120f83 JS |
25 | #include "wx/intl.h" |
26 | #include "wx/utils.h" | |
27 | #include "wx/log.h" | |
28 | ||
29 | #include <X11/Xlib.h> | |
4bb6408c JS |
30 | |
31 | // ---------------------------------------------------------------------------- | |
32 | // global | |
33 | // ---------------------------------------------------------------------------- | |
34 | ||
35 | // ---------------------------------------------------------------------------- | |
36 | // wxDropTarget | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
39 | wxDropTarget::wxDropTarget() | |
40 | { | |
2d120f83 | 41 | } |
4bb6408c JS |
42 | |
43 | wxDropTarget::~wxDropTarget() | |
44 | { | |
2d120f83 | 45 | } |
4bb6408c JS |
46 | |
47 | // ---------------------------------------------------------------------------- | |
48 | // wxTextDropTarget | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
2d120f83 | 51 | bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) |
4bb6408c | 52 | { |
2d120f83 | 53 | OnDropText( x, y, (const char*)data ); |
96be256b | 54 | return true; |
2d120f83 | 55 | } |
4bb6408c JS |
56 | |
57 | bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) | |
58 | { | |
2d120f83 JS |
59 | wxLogDebug( "Got dropped text: %s.", psz ); |
60 | wxLogDebug( "At x: %d, y: %d.", (int)x, (int)y ); | |
96be256b | 61 | return true; |
2d120f83 | 62 | } |
4bb6408c JS |
63 | |
64 | size_t wxTextDropTarget::GetFormatCount() const | |
65 | { | |
66 | return 1; | |
67 | } | |
68 | ||
69 | wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const | |
70 | { | |
71 | return wxDF_TEXT; | |
72 | } | |
73 | ||
74 | // ---------------------------------------------------------------------------- | |
75 | // wxFileDropTarget | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
2d120f83 | 78 | bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] ) |
4bb6408c | 79 | { |
2d120f83 JS |
80 | wxLogDebug( "Got %d dropped files.", (int)nFiles ); |
81 | wxLogDebug( "At x: %d, y: %d.", (int)x, (int)y ); | |
4dba84be JS |
82 | size_t i; |
83 | for (i = 0; i < nFiles; i++) | |
2d120f83 JS |
84 | { |
85 | wxLogDebug( aszFiles[i] ); | |
86 | } | |
96be256b | 87 | return true; |
4bb6408c JS |
88 | } |
89 | ||
2d120f83 | 90 | bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) |
4bb6408c | 91 | { |
2d120f83 JS |
92 | size_t number = 0; |
93 | char *text = (char*) data; | |
4dba84be JS |
94 | size_t i; |
95 | for (i = 0; i < size; i++) | |
2d120f83 JS |
96 | if (text[i] == 0) number++; |
97 | ||
96be256b | 98 | if (number == 0) return true; |
2d120f83 JS |
99 | |
100 | char **files = new char*[number]; | |
101 | ||
102 | text = (char*) data; | |
4dba84be | 103 | for ( i = 0; i < number; i++) |
2d120f83 JS |
104 | { |
105 | files[i] = text; | |
106 | int len = strlen( text ); | |
107 | text += len+1; | |
108 | } | |
109 | ||
110 | bool ret = OnDropFiles( x, y, 1, files ); | |
111 | ||
112 | free( files ); | |
113 | ||
114 | return ret; | |
4bb6408c JS |
115 | } |
116 | ||
117 | size_t wxFileDropTarget::GetFormatCount() const | |
118 | { | |
119 | return 1; | |
120 | } | |
121 | ||
122 | wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const | |
123 | { | |
124 | return wxDF_FILENAME; | |
125 | } | |
126 | ||
127 | //------------------------------------------------------------------------- | |
128 | // wxDropSource | |
129 | //------------------------------------------------------------------------- | |
130 | ||
4bb6408c JS |
131 | wxDropSource::wxDropSource( wxWindow *win ) |
132 | { | |
2d120f83 JS |
133 | #if 0 |
134 | m_window = win; | |
135 | m_data = (wxDataObject *) NULL; | |
136 | m_retValue = wxDragCancel; | |
4bb6408c | 137 | |
2d120f83 JS |
138 | m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); |
139 | m_goaheadCursor = wxCursor( wxCURSOR_HAND ); | |
140 | #endif | |
141 | } | |
4bb6408c JS |
142 | |
143 | wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win ) | |
144 | { | |
2d120f83 | 145 | #if 0 |
96be256b | 146 | g_blockEventsOnDrag = true; |
2d120f83 JS |
147 | |
148 | m_window = win; | |
149 | m_widget = win->m_widget; | |
150 | if (win->m_wxwindow) m_widget = win->m_wxwindow; | |
151 | m_retValue = wxDragCancel; | |
152 | ||
153 | m_data = &data; | |
154 | ||
155 | m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); | |
156 | m_goaheadCursor = wxCursor( wxCURSOR_HAND ); | |
157 | #endif | |
158 | } | |
4bb6408c JS |
159 | |
160 | void wxDropSource::SetData( wxDataObject &data ) | |
161 | { | |
2d120f83 JS |
162 | // m_data = &data; |
163 | } | |
4bb6408c JS |
164 | |
165 | wxDropSource::~wxDropSource(void) | |
166 | { | |
2d120f83 JS |
167 | // if (m_data) delete m_data; |
168 | } | |
4bb6408c | 169 | |
2245b2b2 | 170 | wxDragResult wxDropSource::DoDragDrop( int WXUNUSED(flags) ) |
4bb6408c | 171 | { |
2d120f83 JS |
172 | // wxASSERT_MSG( m_data, "wxDragSource: no data" ); |
173 | ||
174 | return wxDragNone; | |
175 | #if 0 | |
176 | if (!m_data) return (wxDragResult) wxDragNone; | |
177 | if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone; | |
178 | ||
179 | RegisterWindow(); | |
180 | ||
181 | // TODO | |
182 | ||
183 | UnregisterWindow(); | |
184 | ||
96be256b | 185 | g_blockEventsOnDrag = false; |
2d120f83 JS |
186 | |
187 | return m_retValue; | |
188 | #endif | |
189 | } | |
190 | ||
191 | #if 0 | |
192 | void wxDropSource::RegisterWindow(void) | |
193 | { | |
194 | if (!m_data) return; | |
195 | ||
196 | wxString formats; | |
197 | ||
198 | wxDataFormat df = m_data->GetPreferredFormat(); | |
199 | ||
200 | switch (df) | |
201 | { | |
202 | case wxDF_TEXT: | |
203 | formats += "text/plain"; | |
204 | break; | |
205 | case wxDF_FILENAME: | |
206 | formats += "file:ALL"; | |
207 | break; | |
208 | default: | |
209 | break; | |
210 | } | |
211 | ||
212 | char *str = WXSTRINGCAST formats; | |
213 | ||
214 | // TODO | |
215 | } | |
4bb6408c | 216 | |
2d120f83 JS |
217 | void wxDropSource::UnregisterWindow(void) |
218 | { | |
219 | if (!m_widget) return; | |
220 | ||
221 | // TODO | |
222 | } | |
223 | #endif | |
224 | ||
8870c26e JS |
225 | wxPrivateDropTarget::wxPrivateDropTarget() |
226 | { | |
227 | m_id = wxTheApp->GetAppName(); | |
228 | } | |
229 | ||
230 | size_t wxPrivateDropTarget::GetFormatCount() const | |
231 | { | |
232 | return 1; | |
233 | } | |
234 | ||
235 | wxDataFormat wxPrivateDropTarget::GetFormat(size_t n) const | |
236 | { | |
237 | return wxDF_INVALID; | |
238 | } | |
2d120f83 JS |
239 | |
240 | #endif | |
241 | // wxUSE_DRAG_AND_DROP |