]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dnd.cpp
[wxGTK] wxFileDialog: Use native overwrite confirmation if possible
[wxWidgets.git] / src / motif / dnd.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: dnd.cpp
3 // Purpose: wxDropTarget, wxDropSource classes
4 // Author: Julian Smart
5 // Id: $Id$
6 // Copyright: (c) 1998 Julian Smart
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "dnd.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #include "wx/setup.h"
18
19 #if wxUSE_DRAG_AND_DROP
20
21 #include "wx/dnd.h"
22 #include "wx/window.h"
23 #include "wx/app.h"
24 #include "wx/gdicmn.h"
25 #include "wx/intl.h"
26 #include "wx/utils.h"
27 #include "wx/log.h"
28
29 #include <X11/Xlib.h>
30
31 // ----------------------------------------------------------------------------
32 // global
33 // ----------------------------------------------------------------------------
34
35 // ----------------------------------------------------------------------------
36 // wxDropTarget
37 // ----------------------------------------------------------------------------
38
39 wxDropTarget::wxDropTarget()
40 {
41 }
42
43 wxDropTarget::~wxDropTarget()
44 {
45 }
46
47 // ----------------------------------------------------------------------------
48 // wxTextDropTarget
49 // ----------------------------------------------------------------------------
50
51 bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) )
52 {
53 OnDropText( x, y, (const char*)data );
54 return true;
55 }
56
57 bool 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 );
61 return true;
62 }
63
64 size_t wxTextDropTarget::GetFormatCount() const
65 {
66 return 1;
67 }
68
69 wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const
70 {
71 return wxDF_TEXT;
72 }
73
74 // ----------------------------------------------------------------------------
75 // wxFileDropTarget
76 // ----------------------------------------------------------------------------
77
78 bool 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 }
87 return true;
88 }
89
90 bool 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
98 if (number == 0) return true;
99
100 char **files = new char*[number];
101
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
110 bool ret = OnDropFiles( x, y, 1, files );
111
112 free( files );
113
114 return ret;
115 }
116
117 size_t wxFileDropTarget::GetFormatCount() const
118 {
119 return 1;
120 }
121
122 wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const
123 {
124 return wxDF_FILENAME;
125 }
126
127 //-------------------------------------------------------------------------
128 // wxDropSource
129 //-------------------------------------------------------------------------
130
131 wxDropSource::wxDropSource( wxWindow *win )
132 {
133 #if 0
134 m_window = win;
135 m_data = (wxDataObject *) NULL;
136 m_retValue = wxDragCancel;
137
138 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
139 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
140 #endif
141 }
142
143 wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win )
144 {
145 #if 0
146 g_blockEventsOnDrag = true;
147
148 m_window = win;
149 m_widget = win->m_widget;
150 if (win->m_wxwindow) m_widget = win->m_wxwindow;
151 m_retValue = wxDragCancel;
152
153 m_data = &data;
154
155 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
156 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
157 #endif
158 }
159
160 void wxDropSource::SetData( wxDataObject &data )
161 {
162 // m_data = &data;
163 }
164
165 wxDropSource::~wxDropSource(void)
166 {
167 // if (m_data) delete m_data;
168 }
169
170 wxDragResult wxDropSource::DoDragDrop( int WXUNUSED(flags) )
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;
178
179 RegisterWindow();
180
181 // TODO
182
183 UnregisterWindow();
184
185 g_blockEventsOnDrag = false;
186
187 return m_retValue;
188 #endif
189 }
190
191 #if 0
192 void wxDropSource::RegisterWindow(void)
193 {
194 if (!m_data) return;
195
196 wxString formats;
197
198 wxDataFormat df = m_data->GetPreferredFormat();
199
200 switch (df)
201 {
202 case wxDF_TEXT:
203 formats += "text/plain";
204 break;
205 case wxDF_FILENAME:
206 formats += "file:ALL";
207 break;
208 default:
209 break;
210 }
211
212 char *str = WXSTRINGCAST formats;
213
214 // TODO
215 }
216
217 void wxDropSource::UnregisterWindow(void)
218 {
219 if (!m_widget) return;
220
221 // TODO
222 }
223 #endif
224
225 wxPrivateDropTarget::wxPrivateDropTarget()
226 {
227 m_id = wxTheApp->GetAppName();
228 }
229
230 size_t wxPrivateDropTarget::GetFormatCount() const
231 {
232 return 1;
233 }
234
235 wxDataFormat wxPrivateDropTarget::GetFormat(size_t n) const
236 {
237 return wxDF_INVALID;
238 }
239
240 #endif
241 // wxUSE_DRAG_AND_DROP