]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/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
121 virtual bool OnMove( int x
, int y
);
123 /* has to be overridden to accept drop. call GetData() to
124 indicate the format you request and get the data. */
125 virtual bool OnDrop( int x
, int y
);
127 /* called to query what formats are available */
128 bool IsSupported( wxDataFormat format
);
130 /* fill data with data from the dragging source */
131 bool GetData( wxDataObject
*data
);
135 void RegisterWidget( GtkWidget
*widget
);
136 void UnregisterWidget( GtkWidget
*widget
);
138 GdkDragContext
*m_dragContext
;
139 GtkWidget
*m_dragWidget
;
141 bool m_firstMotion
; /* gdk has no "gdk_drag_enter" event */
142 bool m_waiting
; /* asynchronous process */
143 bool m_dataRetrieveSuccess
;
144 wxDataObject
*m_currentDataObject
;
146 void SetDragContext( GdkDragContext
*dc
) { m_dragContext
= dc
; }
147 void SetDragWidget( GtkWidget
*w
) { m_dragWidget
= w
; }
148 void SetDragTime( guint time
) { m_dragTime
= time
; }
151 //-------------------------------------------------------------------------
153 //-------------------------------------------------------------------------
155 class wxTextDropTarget
: public wxDropTarget
159 wxTextDropTarget() {}
161 virtual bool OnMove( int x
, int y
);
162 virtual bool OnDrop( int x
, int y
);
164 /* you have to override OnDropData to get at the text */
165 virtual bool OnDropText( int x
, int y
, const char *text
) = 0;
169 //-------------------------------------------------------------------------
170 // wxPrivateDropTarget
171 //-------------------------------------------------------------------------
173 class wxPrivateDropTarget
: public wxDropTarget
177 /* sets id to "application/myprogram" where "myprogram" is the
178 same as wxApp->GetAppName() */
179 wxPrivateDropTarget();
180 /* see SetId() below for explanation */
181 wxPrivateDropTarget( const wxString
&id
);
183 virtual bool OnMove( int x
, int y
);
184 virtual bool OnDrop( int x
, int y
);
186 /* you have to override OnDropData to get at the data */
187 virtual bool OnDropData( int x
, int y
, void *data
, size_t size
) = 0;
189 /* the string ID identifies the format of clipboard or DnD data. a word
190 processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
191 to the clipboard - the latter with the Id "application/wxword" or
193 void SetId( const wxString
& id
) { m_id
= id
; }
194 wxString
GetId() { return m_id
; }
201 //----------------------------------------------------------------------------
202 // A drop target which accepts files (dragged from File Manager or Explorer)
203 //----------------------------------------------------------------------------
205 class wxFileDropTarget
: public wxDropTarget
209 wxFileDropTarget() {}
211 virtual bool OnMove( int x
, int y
);
212 virtual bool OnDrop( int x
, int y
);
213 virtual void OnData( int x
, int y
);
215 /* you have to override OnDropFiles to get at the file names */
216 virtual bool OnDropFiles( int x
, int y
, size_t nFiles
, const char * const aszFiles
[] ) = 0;
222 //-------------------------------------------------------------------------
224 //-------------------------------------------------------------------------
226 class wxDropTarget
: public wxObject
233 virtual void OnEnter() { }
234 virtual void OnLeave() { }
235 virtual void OnMouseMove( long WXUNUSED(x
), long WXUNUSED(y
) ) { }
236 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
) = 0;
238 // Override these to indicate what kind of data you support:
240 virtual size_t GetFormatCount() const = 0;
241 virtual wxDataFormat
&GetFormat(size_t n
) const;
245 void RegisterWidget( GtkWidget
*widget
);
246 void UnregisterWidget( GtkWidget
*widget
);
248 wxDataFormat
*m_format
;
251 //-------------------------------------------------------------------------
253 //-------------------------------------------------------------------------
255 class wxTextDropTarget
: public wxDropTarget
260 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
);
261 virtual bool OnDropText( long x
, long y
, const char *psz
);
265 virtual size_t GetFormatCount() const;
268 //-------------------------------------------------------------------------
269 // wxPrivateDropTarget
270 //-------------------------------------------------------------------------
272 class wxPrivateDropTarget
: public wxDropTarget
276 wxPrivateDropTarget();
278 // you have to override OnDrop to get at the data
280 // the string ID identifies the format of clipboard or DnD data. a word
281 // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
282 // to the clipboard - the latter with the Id "application/wxword" or
285 void SetId( const wxString
& id
);
292 virtual size_t GetFormatCount() const;
297 //----------------------------------------------------------------------------
298 // A drop target which accepts files (dragged from File Manager or Explorer)
299 //----------------------------------------------------------------------------
301 class wxFileDropTarget
: public wxDropTarget
307 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
);
308 virtual bool OnDropFiles( long x
, long y
,
309 size_t nFiles
, const char * const aszFiles
[] );
313 virtual size_t GetFormatCount() const;
321 // wxUSE_DRAG_AND_DROP