]> git.saurik.com Git - wxWidgets.git/blame - src/x11/dnd.cpp
document On{Open,Save}Document()
[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__)
88a7a4e1 14 #pragma hdrstop
521bf4ff 15#endif
83df96d6
JS
16
17#if wxUSE_DRAG_AND_DROP
18
19#include "wx/dnd.h"
88a7a4e1
WS
20
21#ifndef WX_PRECOMP
22 #include "wx/intl.h"
e4db172a 23 #include "wx/log.h"
670f9935 24 #include "wx/app.h"
de6185e2 25 #include "wx/utils.h"
cdccdfab 26 #include "wx/window.h"
dd05139a 27 #include "wx/gdicmn.h"
88a7a4e1
WS
28#endif
29
83df96d6
JS
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 );
521bf4ff 55 return true;
83df96d6
JS
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 );
521bf4ff 62 return true;
83df96d6
JS
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 }
521bf4ff 88 return true;
83df96d6
JS
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
521bf4ff
WS
99 if (number == 0) return true;
100
83df96d6 101 char **files = new char*[number];
521bf4ff 102
83df96d6
JS
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
521bf4ff
WS
111 bool ret = OnDropFiles( x, y, 1, files );
112
83df96d6 113 free( files );
521bf4ff 114
83df96d6
JS
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 = (wxDataObject *) 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
521bf4ff
WS
147 g_blockEventsOnDrag = true;
148
83df96d6
JS
149 m_window = win;
150 m_widget = win->m_widget;
151 if (win->m_wxwindow) m_widget = win->m_wxwindow;
152 m_retValue = wxDragCancel;
521bf4ff 153
83df96d6
JS
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}
521bf4ff 170
2245b2b2 171wxDragResult wxDropSource::DoDragDrop( int WXUNUSED(flags) )
83df96d6
JS
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;
521bf4ff 179
83df96d6 180 RegisterWindow();
521bf4ff 181
83df96d6 182 // TODO
521bf4ff 183
83df96d6 184 UnregisterWindow();
521bf4ff 185
670f9935 186 g_blockEventsOnDrag = false;
521bf4ff 187
83df96d6
JS
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;
521bf4ff 198
83df96d6 199 wxDataFormat df = m_data->GetPreferredFormat();
521bf4ff
WS
200
201 switch (df)
83df96d6 202 {
521bf4ff 203 case wxDF_TEXT:
83df96d6 204 formats += "text/plain";
521bf4ff 205 break;
83df96d6
JS
206 case wxDF_FILENAME:
207 formats += "file:ALL";
521bf4ff 208 break;
83df96d6
JS
209 default:
210 break;
211 }
521bf4ff 212
83df96d6 213 char *str = WXSTRINGCAST formats;
521bf4ff 214
83df96d6
JS
215 // TODO
216}
217
218void wxDropSource::UnregisterWindow(void)
219{
220 if (!m_widget) return;
521bf4ff 221
83df96d6
JS
222 // TODO
223}
224#endif
225
226wxPrivateDropTarget::wxPrivateDropTarget()
227{
228 m_id = wxTheApp->GetAppName();
229}
521bf4ff 230
83df96d6
JS
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