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