]> git.saurik.com Git - wxWidgets.git/blob - src/x11/dnd.cpp
Check encoding names case insensitively
[wxWidgets.git] / src / x11 / dnd.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/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 // for compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #if defined(__BORLANDC__)
14 #pragma hdrstop
15 #endif
16
17 #if wxUSE_DRAG_AND_DROP
18
19 #include "wx/dnd.h"
20 #include "wx/window.h"
21 #include "wx/app.h"
22 #include "wx/gdicmn.h"
23 #include "wx/intl.h"
24 #include "wx/utils.h"
25 #include "wx/log.h"
26
27 #include <X11/Xlib.h>
28
29 // ----------------------------------------------------------------------------
30 // global
31 // ----------------------------------------------------------------------------
32
33 // ----------------------------------------------------------------------------
34 // wxDropTarget
35 // ----------------------------------------------------------------------------
36
37 wxDropTarget::wxDropTarget()
38 {
39 }
40
41 wxDropTarget::~wxDropTarget()
42 {
43 }
44
45 // ----------------------------------------------------------------------------
46 // wxTextDropTarget
47 // ----------------------------------------------------------------------------
48
49 bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) )
50 {
51 OnDropText( x, y, (const char*)data );
52 return true;
53 }
54
55 bool wxTextDropTarget::OnDropText( long x, long y, const char *psz )
56 {
57 wxLogDebug( "Got dropped text: %s.", psz );
58 wxLogDebug( "At x: %d, y: %d.", (int)x, (int)y );
59 return true;
60 }
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
76 bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] )
77 {
78 wxLogDebug( "Got %d dropped files.", (int)nFiles );
79 wxLogDebug( "At x: %d, y: %d.", (int)x, (int)y );
80 size_t i;
81 for (i = 0; i < nFiles; i++)
82 {
83 wxLogDebug( aszFiles[i] );
84 }
85 return true;
86 }
87
88 bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size )
89 {
90 size_t number = 0;
91 char *text = (char*) data;
92 size_t i;
93 for (i = 0; i < size; i++)
94 if (text[i] == 0) number++;
95
96 if (number == 0) return true;
97
98 char **files = new char*[number];
99
100 text = (char*) data;
101 for ( i = 0; i < number; i++)
102 {
103 files[i] = text;
104 int len = strlen( text );
105 text += len+1;
106 }
107
108 bool ret = OnDropFiles( x, y, 1, files );
109
110 free( files );
111
112 return ret;
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
129 wxDropSource::wxDropSource( wxWindow *win )
130 {
131 #if 0
132 m_window = win;
133 m_data = (wxDataObject *) NULL;
134 m_retValue = wxDragCancel;
135
136 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
137 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
138 #endif
139 }
140
141 wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win )
142 {
143 #if 0
144 g_blockEventsOnDrag = true;
145
146 m_window = win;
147 m_widget = win->m_widget;
148 if (win->m_wxwindow) m_widget = win->m_wxwindow;
149 m_retValue = wxDragCancel;
150
151 m_data = &data;
152
153 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
154 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
155 #endif
156 }
157
158 void wxDropSource::SetData( wxDataObject &data )
159 {
160 // m_data = &data;
161 }
162
163 wxDropSource::~wxDropSource(void)
164 {
165 // if (m_data) delete m_data;
166 }
167
168 wxDragResult wxDropSource::DoDragDrop( int WXUNUSED(flags) )
169 {
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;
176
177 RegisterWindow();
178
179 // TODO
180
181 UnregisterWindow();
182
183 g_blockEventsOnDrag = FALSE;
184
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;
195
196 wxDataFormat df = m_data->GetPreferredFormat();
197
198 switch (df)
199 {
200 case wxDF_TEXT:
201 formats += "text/plain";
202 break;
203 case wxDF_FILENAME:
204 formats += "file:ALL";
205 break;
206 default:
207 break;
208 }
209
210 char *str = WXSTRINGCAST formats;
211
212 // TODO
213 }
214
215 void wxDropSource::UnregisterWindow(void)
216 {
217 if (!m_widget) return;
218
219 // TODO
220 }
221 #endif
222
223 wxPrivateDropTarget::wxPrivateDropTarget()
224 {
225 m_id = wxTheApp->GetAppName();
226 }
227
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 }
237
238 #endif
239 // wxUSE_DRAG_AND_DROP