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