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