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