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