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