]>
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
;
100 #if (GTK_MINOR_VERSION > 0)
102 //-------------------------------------------------------------------------
104 //-------------------------------------------------------------------------
106 class wxDropTarget
: public wxObject
113 /* may be overridden to react to events */
114 virtual void OnEnter();
115 virtual void OnLeave();
117 /* may be overridden to reject certain formats or drops
119 virtual bool OnMove( int x
, int y
);
121 /* has to be overridden to accept drop. call GetData() to
122 indicate the format you request and get the data. */
123 virtual bool OnDrop( int x
, int y
);
125 /* called to query what formats are available */
126 bool IsSupported( wxDataFormat format
);
128 /* fill data with data from the dragging source */
129 bool GetData( wxDataObject
*data
);
133 void RegisterWidget( GtkWidget
*widget
);
134 void UnregisterWidget( GtkWidget
*widget
);
136 GdkDragContext
*m_dragContext
;
137 GtkWidget
*m_dragWidget
;
139 bool m_firstMotion
; /* gdk has no "gdk_drag_enter" event */
140 bool m_waiting
; /* asynchronous process */
141 bool m_dataRetrieveSuccess
;
142 wxDataObject
*m_currentDataObject
;
144 void SetDragContext( GdkDragContext
*dc
) { m_dragContext
= dc
; }
145 void SetDragWidget( GtkWidget
*w
) { m_dragWidget
= w
; }
146 void SetDragTime( guint time
) { m_dragTime
= time
; }
149 //-------------------------------------------------------------------------
151 //-------------------------------------------------------------------------
153 class wxTextDropTarget
: public wxDropTarget
157 wxTextDropTarget() {}
159 virtual bool OnMove( int x
, int y
);
160 virtual bool OnDrop( int x
, int y
);
162 /* you have to override OnDropData to get at the text */
163 virtual bool OnDropText( int x
, int y
, const char *text
) = 0;
167 //-------------------------------------------------------------------------
168 // wxPrivateDropTarget
169 //-------------------------------------------------------------------------
171 class wxPrivateDropTarget
: public wxDropTarget
175 /* sets id to "application/myprogram" where "myprogram" is the
176 same as wxApp->GetAppName() */
177 wxPrivateDropTarget();
178 /* see SetId() below for explanation */
179 wxPrivateDropTarget( const wxString
&id
);
181 virtual bool OnMove( int x
, int y
);
182 virtual bool OnDrop( int x
, int y
);
184 /* you have to override OnDropData to get at the data */
185 virtual bool OnDropData( int x
, int y
, void *data
, size_t size
) = 0;
187 /* the string ID identifies the format of clipboard or DnD data. a word
188 processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
189 to the clipboard - the latter with the Id "application/wxword" or
191 void SetId( const wxString
& id
) { m_id
= id
; }
192 wxString
GetId() { return m_id
; }
199 //----------------------------------------------------------------------------
200 // A drop target which accepts files (dragged from File Manager or Explorer)
201 //----------------------------------------------------------------------------
203 class wxFileDropTarget
: public wxDropTarget
207 wxFileDropTarget() {}
209 virtual bool OnMove( int x
, int y
);
210 virtual bool OnDrop( int x
, int y
);
211 virtual void OnData( int x
, int y
);
213 /* you have to override OnDropFiles to get at the file names */
214 virtual bool OnDropFiles( int x
, int y
, size_t nFiles
, const char * const aszFiles
[] ) = 0;
220 //-------------------------------------------------------------------------
222 //-------------------------------------------------------------------------
224 class wxDropTarget
: public wxObject
231 virtual void OnEnter() { }
232 virtual void OnLeave() { }
233 virtual void OnMouseMove( long WXUNUSED(x
), long WXUNUSED(y
) ) { }
234 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
) = 0;
236 // Override these to indicate what kind of data you support:
238 virtual size_t GetFormatCount() const = 0;
239 virtual wxDataFormat
&GetFormat(size_t n
) const;
243 void RegisterWidget( GtkWidget
*widget
);
244 void UnregisterWidget( GtkWidget
*widget
);
246 wxDataFormat
*m_format
;
249 //-------------------------------------------------------------------------
251 //-------------------------------------------------------------------------
253 class wxTextDropTarget
: public wxDropTarget
258 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
);
259 virtual bool OnDropText( long x
, long y
, const char *psz
);
263 virtual size_t GetFormatCount() const;
266 //-------------------------------------------------------------------------
267 // wxPrivateDropTarget
268 //-------------------------------------------------------------------------
270 class wxPrivateDropTarget
: public wxDropTarget
274 wxPrivateDropTarget();
276 // you have to override OnDrop to get at the data
278 // the string ID identifies the format of clipboard or DnD data. a word
279 // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
280 // to the clipboard - the latter with the Id "application/wxword" or
283 void SetId( const wxString
& id
);
290 virtual size_t GetFormatCount() const;
295 //----------------------------------------------------------------------------
296 // A drop target which accepts files (dragged from File Manager or Explorer)
297 //----------------------------------------------------------------------------
299 class wxFileDropTarget
: public wxDropTarget
305 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
);
306 virtual bool OnDropFiles( long x
, long y
,
307 size_t nFiles
, const char * const aszFiles
[] );
311 virtual size_t GetFormatCount() const;
319 // wxUSE_DRAG_AND_DROP