]>
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 //-------------------------------------------------------------------------
46 class wxDropTarget
: public wxObject
53 /* may be overridden to react to events */
54 virtual void OnEnter();
55 virtual void OnLeave();
57 /* may be overridden to reject certain formats or drops
58 on certain areas. always returns TRUE by default
59 indicating that you'd accept the data from the drag. */
60 virtual bool OnMove( int x
, int y
);
62 /* has to be overridden to accept a drop event. call
63 IsSupported() to ask which formats are available
64 and then call RequestData() to indicate the format
66 virtual bool OnDrop( int x
, int y
);
68 /* this gets called once the data has actually arrived. get
69 it with GetData(). this has to be overridden. */
70 virtual bool OnData( int x
, int y
);
72 /* called from within OnDrop() to request a certain format
73 from the drop event. */
74 bool RequestData( wxDataFormat format
);
76 /* called to query what formats are available */
77 bool IsSupported( wxDataFormat format
);
79 /* fill data with data from the dragging source */
80 bool GetData( wxDataObject
*data
);
84 void RegisterWidget( GtkWidget
*widget
);
85 void UnregisterWidget( GtkWidget
*widget
);
87 GdkDragContext
*m_dragContext
;
88 GtkWidget
*m_dragWidget
;
89 GtkSelectionData
*m_dragData
;
91 bool m_firstMotion
; /* gdk has no "gdk_drag_enter" event */
93 void SetDragContext( GdkDragContext
*dc
) { m_dragContext
= dc
; }
94 void SetDragWidget( GtkWidget
*w
) { m_dragWidget
= w
; }
95 void SetDragData( GtkSelectionData
*sd
) { m_dragData
= sd
; }
96 void SetDragTime( guint time
) { m_dragTime
= time
; }
99 //-------------------------------------------------------------------------
101 //-------------------------------------------------------------------------
103 class wxTextDropTarget
: public wxDropTarget
107 wxTextDropTarget() {}
109 virtual bool OnMove( int x
, int y
);
110 virtual bool OnDrop( int x
, int y
);
111 virtual bool OnData( int x
, int y
);
113 /* you have to override OnDropData to get at the text */
114 virtual bool OnDropText( int x
, int y
, const char *text
) = 0;
118 //-------------------------------------------------------------------------
119 // wxPrivateDropTarget
120 //-------------------------------------------------------------------------
122 class wxPrivateDropTarget
: public wxDropTarget
126 /* sets id to "application/myprogram" where "myprogram" is the
127 same as wxApp->GetAppName() */
128 wxPrivateDropTarget();
129 /* see SetId() below for explanation */
130 wxPrivateDropTarget( const wxString
&id
);
132 virtual bool OnMove( int x
, int y
);
133 virtual bool OnDrop( int x
, int y
);
134 virtual bool OnData( int x
, int y
);
136 /* you have to override OnDropData to get at the data */
137 virtual bool OnDropData( int x
, int y
, void *data
, size_t size
) = 0;
139 /* the string ID identifies the format of clipboard or DnD data. a word
140 processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
141 to the clipboard - the latter with the Id "application/wxword" or
143 void SetId( const wxString
& id
) { m_id
= id
; }
144 wxString
GetId() { return m_id
; }
151 //----------------------------------------------------------------------------
152 // A drop target which accepts files (dragged from File Manager or Explorer)
153 //----------------------------------------------------------------------------
155 class wxFileDropTarget
: public wxDropTarget
159 wxFileDropTarget() {}
161 virtual bool OnMove( int x
, int y
);
162 virtual bool OnDrop( int x
, int y
);
163 virtual bool OnData( int x
, int y
);
165 /* you have to override OnDropFiles to get at the file names */
166 virtual bool OnDropFiles( int x
, int y
, size_t nFiles
, const wxChar
* const aszFiles
[] ) = 0;
170 //-------------------------------------------------------------------------
172 //-------------------------------------------------------------------------
176 wxDragError
, // error prevented the d&d operation from completing
177 wxDragNone
, // drag target didn't accept the data
178 wxDragCopy
, // the data was successfully copied
179 wxDragMove
, // the data was successfully moved (MSW only)
180 wxDragCancel
// the operation was cancelled by user (not an error)
183 class wxDropSource
: public wxObject
187 /* constructor. set data later with SetData() */
188 wxDropSource( wxWindow
*win
, const wxIcon
&go
= wxNullIcon
, const wxIcon
&stop
= wxNullIcon
);
190 /* constructor for setting one data object */
191 wxDropSource( wxDataObject
*data
, wxWindow
*win
, const wxIcon
&go
= wxNullIcon
, const wxIcon
&stop
= wxNullIcon
);
193 /* constructor for setting several data objects via wxDataBroker */
194 wxDropSource( wxDataBroker
*data
, wxWindow
*win
);
198 /* set several dataobjects via wxDataBroker */
199 void SetData( wxDataBroker
*data
);
201 /* set one dataobject */
202 void SetData( wxDataObject
*data
);
204 /* start drag action */
205 wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
207 /* override to give feedback */
208 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; }
210 /* GTK implementation */
212 void RegisterWindow();
213 void UnregisterWindow();
217 wxDragResult m_retValue
;
218 wxDataBroker
*m_data
;
220 wxCursor m_defaultCursor
;
221 wxCursor m_goaheadCursor
;
231 // wxUSE_DRAG_AND_DROP