]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dnd.h
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of the wxDropTarget class
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling
7 // Licence: wxWindows license
8 ///////////////////////////////////////////////////////////////////////////////
20 #if wxUSE_DRAG_AND_DROP
22 #include "wx/object.h"
23 #include "wx/string.h"
24 #include "wx/dataobj.h"
25 #include "wx/cursor.h"
27 #include "wx/gdicmn.h"
29 //-------------------------------------------------------------------------
31 //-------------------------------------------------------------------------
36 class wxTextDropTarget
;
37 class wxFileDropTarget
;
38 class wxPrivateDropTarget
;
42 //-------------------------------------------------------------------------
44 //-------------------------------------------------------------------------
48 wxDragError
, // error prevented the d&d operation from completing
49 wxDragNone
, // drag target didn't accept the data
50 wxDragCopy
, // the data was successfully copied
51 wxDragMove
, // the data was successfully moved (MSW only)
52 wxDragCancel
// the operation was cancelled by user (not an error)
55 class wxDropSource
: public wxObject
59 /* constructor. set data later with SetData() */
60 wxDropSource( wxWindow
*win
, const wxIcon
&go
= wxNullIcon
, const wxIcon
&stop
= wxNullIcon
);
62 /* constructor for setting one data object */
63 wxDropSource( wxDataObject
*data
, wxWindow
*win
, const wxIcon
&go
= wxNullIcon
, const wxIcon
&stop
= wxNullIcon
);
65 /* constructor for setting several data objects via wxDataBroker */
66 wxDropSource( wxDataBroker
*data
, wxWindow
*win
);
70 /* set several dataobjects via wxDataBroker */
71 void SetData( wxDataBroker
*data
);
73 /* set one dataobject */
74 void SetData( wxDataObject
*data
);
76 /* start drag action */
77 wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
79 /* override to give feedback */
80 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; }
82 /* GTK implementation */
84 void RegisterWindow();
85 void UnregisterWindow();
89 wxDragResult m_retValue
;
92 wxCursor m_defaultCursor
;
93 wxCursor m_goaheadCursor
;
102 #if (GTK_MINOR_VERSION > 0)
104 //-------------------------------------------------------------------------
106 //-------------------------------------------------------------------------
108 class wxDropTarget
: public wxObject
115 /* may be overridden to react to events */
116 virtual void OnEnter();
117 virtual void OnLeave();
119 /* may be overridden to reject certain formats or drops
120 on certain areas. always returns TRUE by default
121 indicating that you'd accept the data from the drag. */
122 virtual bool OnMove( int x
, int y
);
124 /* has to be overridden to accept a drop event. call
125 IsSupported() to ask which formats are available
126 and then call RequestData() to indicate the format
128 virtual bool OnDrop( int x
, int y
);
130 /* this gets called once the data has actually arrived. get
131 it with GetData(). this has to be overridden. */
132 virtual bool OnData( int x
, int y
);
134 /* called from within OnDrop() to request a certain format
135 from the drop event. */
136 bool RequestData( wxDataFormat format
);
138 /* called to query what formats are available */
139 bool IsSupported( wxDataFormat format
);
141 /* fill data with data from the dragging source */
142 bool GetData( wxDataObject
*data
);
146 void RegisterWidget( GtkWidget
*widget
);
147 void UnregisterWidget( GtkWidget
*widget
);
149 GdkDragContext
*m_dragContext
;
150 GtkWidget
*m_dragWidget
;
151 GtkSelectionData
*m_dragData
;
153 bool m_firstMotion
; /* gdk has no "gdk_drag_enter" event */
155 void SetDragContext( GdkDragContext
*dc
) { m_dragContext
= dc
; }
156 void SetDragWidget( GtkWidget
*w
) { m_dragWidget
= w
; }
157 void SetDragData( GtkSelectionData
*sd
) { m_dragData
= sd
; }
158 void SetDragTime( guint time
) { m_dragTime
= time
; }
161 //-------------------------------------------------------------------------
163 //-------------------------------------------------------------------------
165 class wxTextDropTarget
: public wxDropTarget
169 wxTextDropTarget() {}
171 virtual bool OnMove( int x
, int y
);
172 virtual bool OnDrop( int x
, int y
);
173 virtual bool OnData( int x
, int y
);
175 /* you have to override OnDropData to get at the text */
176 virtual bool OnDropText( int x
, int y
, const char *text
) = 0;
180 //-------------------------------------------------------------------------
181 // wxPrivateDropTarget
182 //-------------------------------------------------------------------------
184 class wxPrivateDropTarget
: public wxDropTarget
188 /* sets id to "application/myprogram" where "myprogram" is the
189 same as wxApp->GetAppName() */
190 wxPrivateDropTarget();
191 /* see SetId() below for explanation */
192 wxPrivateDropTarget( const wxString
&id
);
194 virtual bool OnMove( int x
, int y
);
195 virtual bool OnDrop( int x
, int y
);
196 virtual bool OnData( int x
, int y
);
198 /* you have to override OnDropData to get at the data */
199 virtual bool OnDropData( int x
, int y
, void *data
, size_t size
) = 0;
201 /* the string ID identifies the format of clipboard or DnD data. a word
202 processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
203 to the clipboard - the latter with the Id "application/wxword" or
205 void SetId( const wxString
& id
) { m_id
= id
; }
206 wxString
GetId() { return m_id
; }
213 //----------------------------------------------------------------------------
214 // A drop target which accepts files (dragged from File Manager or Explorer)
215 //----------------------------------------------------------------------------
217 class wxFileDropTarget
: public wxDropTarget
221 wxFileDropTarget() {}
223 virtual bool OnMove( int x
, int y
);
224 virtual bool OnDrop( int x
, int y
);
225 virtual bool OnData( int x
, int y
);
227 /* you have to override OnDropFiles to get at the file names */
228 virtual bool OnDropFiles( int x
, int y
, size_t nFiles
, const wxChar
* const aszFiles
[] ) = 0;
234 //-------------------------------------------------------------------------
236 //-------------------------------------------------------------------------
238 class wxDropTarget
: public wxObject
245 virtual void OnEnter() { }
246 virtual void OnLeave() { }
247 virtual void OnMouseMove( long WXUNUSED(x
), long WXUNUSED(y
) ) { }
248 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
) = 0;
250 // Override these to indicate what kind of data you support:
252 virtual size_t GetFormatCount() const = 0;
253 virtual wxDataFormat
&GetFormat(size_t n
) const;
257 void RegisterWidget( GtkWidget
*widget
);
258 void UnregisterWidget( GtkWidget
*widget
);
260 wxDataFormat
*m_format
;
263 //-------------------------------------------------------------------------
265 //-------------------------------------------------------------------------
267 class wxTextDropTarget
: public wxDropTarget
272 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
);
273 virtual bool OnDropText( long x
, long y
, const char *psz
);
277 virtual size_t GetFormatCount() const;
280 //-------------------------------------------------------------------------
281 // wxPrivateDropTarget
282 //-------------------------------------------------------------------------
284 class wxPrivateDropTarget
: public wxDropTarget
288 wxPrivateDropTarget();
290 // you have to override OnDrop to get at the data
292 // the string ID identifies the format of clipboard or DnD data. a word
293 // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
294 // to the clipboard - the latter with the Id "application/wxword" or
297 void SetId( const wxString
& id
);
304 virtual size_t GetFormatCount() const;
309 //----------------------------------------------------------------------------
310 // A drop target which accepts files (dragged from File Manager or Explorer)
311 //----------------------------------------------------------------------------
313 class wxFileDropTarget
: public wxDropTarget
319 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
);
320 virtual bool OnDropFiles( long x
, long y
,
321 size_t nFiles
, const char * const aszFiles
[] );
325 virtual size_t GetFormatCount() const;
333 // wxUSE_DRAG_AND_DROP