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