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