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