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