]> git.saurik.com Git - wxWidgets.git/blame - src/x11/dnd.cpp
don't compare invalid iterators/node pointers
[wxWidgets.git] / src / x11 / dnd.cpp
CommitLineData
83df96d6 1///////////////////////////////////////////////////////////////////////////////
521bf4ff 2// Name: src/x11/dnd.cpp
83df96d6
JS
3// Purpose: wxDropTarget, wxDropSource classes
4// Author: Julian Smart
5// Id: $Id$
6// Copyright: (c) 1998 Julian Smart
521bf4ff 7// Licence: wxWindows licence
83df96d6
JS
8///////////////////////////////////////////////////////////////////////////////
9
521bf4ff
WS
10// for compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if defined(__BORLANDC__)
14#pragma hdrstop
15#endif
83df96d6
JS
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
37wxDropTarget::wxDropTarget()
38{
39}
40
41wxDropTarget::~wxDropTarget()
42{
43}
44
45// ----------------------------------------------------------------------------
46// wxTextDropTarget
47// ----------------------------------------------------------------------------
48
49bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) )
50{
51 OnDropText( x, y, (const char*)data );
521bf4ff 52 return true;
83df96d6
JS
53}
54
55bool 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 );
521bf4ff 59 return true;
83df96d6
JS
60}
61
62size_t wxTextDropTarget::GetFormatCount() const
63{
64 return 1;
65}
66
67wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const
68{
69 return wxDF_TEXT;
70}
71
72// ----------------------------------------------------------------------------
73// wxFileDropTarget
74// ----------------------------------------------------------------------------
75
76bool 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 }
521bf4ff 85 return true;
83df96d6
JS
86}
87
88bool 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
521bf4ff
WS
96 if (number == 0) return true;
97
83df96d6 98 char **files = new char*[number];
521bf4ff 99
83df96d6
JS
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
521bf4ff
WS
108 bool ret = OnDropFiles( x, y, 1, files );
109
83df96d6 110 free( files );
521bf4ff 111
83df96d6
JS
112 return ret;
113}
114
115size_t wxFileDropTarget::GetFormatCount() const
116{
117 return 1;
118}
119
120wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const
121{
122 return wxDF_FILENAME;
123}
124
125//-------------------------------------------------------------------------
126// wxDropSource
127//-------------------------------------------------------------------------
128
129wxDropSource::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
141wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win )
142{
143#if 0
521bf4ff
WS
144 g_blockEventsOnDrag = true;
145
83df96d6
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;
521bf4ff 150
83df96d6
JS
151 m_data = &data;
152
153 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
154 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
155#endif
156}
157
158void wxDropSource::SetData( wxDataObject &data )
159{
160// m_data = &data;
161}
162
163wxDropSource::~wxDropSource(void)
164{
165// if (m_data) delete m_data;
166}
521bf4ff 167
2245b2b2 168wxDragResult wxDropSource::DoDragDrop( int WXUNUSED(flags) )
83df96d6
JS
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;
521bf4ff 176
83df96d6 177 RegisterWindow();
521bf4ff 178
83df96d6 179 // TODO
521bf4ff 180
83df96d6 181 UnregisterWindow();
521bf4ff 182
83df96d6 183 g_blockEventsOnDrag = FALSE;
521bf4ff 184
83df96d6
JS
185 return m_retValue;
186#endif
187}
188
189#if 0
190void wxDropSource::RegisterWindow(void)
191{
192 if (!m_data) return;
193
194 wxString formats;
521bf4ff 195
83df96d6 196 wxDataFormat df = m_data->GetPreferredFormat();
521bf4ff
WS
197
198 switch (df)
83df96d6 199 {
521bf4ff 200 case wxDF_TEXT:
83df96d6 201 formats += "text/plain";
521bf4ff 202 break;
83df96d6
JS
203 case wxDF_FILENAME:
204 formats += "file:ALL";
521bf4ff 205 break;
83df96d6
JS
206 default:
207 break;
208 }
521bf4ff 209
83df96d6 210 char *str = WXSTRINGCAST formats;
521bf4ff 211
83df96d6
JS
212 // TODO
213}
214
215void wxDropSource::UnregisterWindow(void)
216{
217 if (!m_widget) return;
521bf4ff 218
83df96d6
JS
219 // TODO
220}
221#endif
222
223wxPrivateDropTarget::wxPrivateDropTarget()
224{
225 m_id = wxTheApp->GetAppName();
226}
521bf4ff 227
83df96d6
JS
228size_t wxPrivateDropTarget::GetFormatCount() const
229{
230 return 1;
231}
232
233wxDataFormat wxPrivateDropTarget::GetFormat(size_t n) const
234{
235 return wxDF_INVALID;
236}
237
238#endif
239 // wxUSE_DRAG_AND_DROP