]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dnd.cpp
Added wxMotif data object classes
[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 );
79 for (size_t i = 0; i < nFiles; i++)
80 {
81 wxLogDebug( aszFiles[i] );
82 }
4bb6408c
JS
83 return TRUE;
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;
90 for (size_t i = 0; i < size; i++)
91 if (text[i] == 0) number++;
92
93 if (number == 0) return TRUE;
94
95 char **files = new char*[number];
96
97 text = (char*) data;
98 for (size_t i = 0; i < number; i++)
99 {
100 files[i] = text;
101 int len = strlen( text );
102 text += len+1;
103 }
104
105 bool ret = OnDropFiles( x, y, 1, files );
106
107 free( files );
108
109 return ret;
4bb6408c
JS
110}
111
112size_t wxFileDropTarget::GetFormatCount() const
113{
114 return 1;
115}
116
117wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const
118{
119 return wxDF_FILENAME;
120}
121
122//-------------------------------------------------------------------------
123// wxDropSource
124//-------------------------------------------------------------------------
125
4bb6408c
JS
126wxDropSource::wxDropSource( wxWindow *win )
127{
2d120f83
JS
128#if 0
129 m_window = win;
130 m_data = (wxDataObject *) NULL;
131 m_retValue = wxDragCancel;
4bb6408c 132
2d120f83
JS
133 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
134 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
135#endif
136}
4bb6408c
JS
137
138wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win )
139{
2d120f83
JS
140#if 0
141 g_blockEventsOnDrag = TRUE;
142
143 m_window = win;
144 m_widget = win->m_widget;
145 if (win->m_wxwindow) m_widget = win->m_wxwindow;
146 m_retValue = wxDragCancel;
147
148 m_data = &data;
149
150 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
151 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
152#endif
153}
4bb6408c
JS
154
155void wxDropSource::SetData( wxDataObject &data )
156{
2d120f83
JS
157// m_data = &data;
158}
4bb6408c
JS
159
160wxDropSource::~wxDropSource(void)
161{
2d120f83
JS
162// if (m_data) delete m_data;
163}
4bb6408c
JS
164
165wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
166{
2d120f83
JS
167 // wxASSERT_MSG( m_data, "wxDragSource: no data" );
168
169 return wxDragNone;
170#if 0
171 if (!m_data) return (wxDragResult) wxDragNone;
172 if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone;
173
174 RegisterWindow();
175
176 // TODO
177
178 UnregisterWindow();
179
180 g_blockEventsOnDrag = FALSE;
181
182 return m_retValue;
183#endif
184}
185
186#if 0
187void wxDropSource::RegisterWindow(void)
188{
189 if (!m_data) return;
190
191 wxString formats;
192
193 wxDataFormat df = m_data->GetPreferredFormat();
194
195 switch (df)
196 {
197 case wxDF_TEXT:
198 formats += "text/plain";
199 break;
200 case wxDF_FILENAME:
201 formats += "file:ALL";
202 break;
203 default:
204 break;
205 }
206
207 char *str = WXSTRINGCAST formats;
208
209 // TODO
210}
4bb6408c 211
2d120f83
JS
212void wxDropSource::UnregisterWindow(void)
213{
214 if (!m_widget) return;
215
216 // TODO
217}
218#endif
219
220
221#endif
222 // wxUSE_DRAG_AND_DROP