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