]>
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( long x
, long 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( long x
, long 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( long x
, long 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
);
82 virtual size_t GetFormatCount() const = 0;
83 virtual wxDataFormat
GetFormat(size_t n
) const = 0;
87 void RegisterWidget( GtkWidget
*widget
);
88 void UnregisterWidget( GtkWidget
*widget
);
90 GdkDragContext
*m_dragContext
;
91 GtkWidget
*m_dragWidget
;
92 GtkSelectionData
*m_dragData
;
94 bool m_firstMotion
; /* gdk has no "gdk_drag_enter" event */
96 void SetDragContext( GdkDragContext
*dc
) { m_dragContext
= dc
; }
97 void SetDragWidget( GtkWidget
*w
) { m_dragWidget
= w
; }
98 void SetDragData( GtkSelectionData
*sd
) { m_dragData
= sd
; }
99 void SetDragTime( guint time
) { m_dragTime
= time
; }
102 //-------------------------------------------------------------------------
104 //-------------------------------------------------------------------------
106 class wxTextDropTarget
: public wxDropTarget
110 wxTextDropTarget() {}
112 virtual bool OnData( long x
, long y
);
114 /* you have to override OnDropData to get at the text */
115 virtual bool OnDropText( long x
, long y
, const wxChar
*text
) = 0;
117 virtual size_t GetFormatCount() const
119 virtual wxDataFormat
GetFormat(size_t n
) const
120 { return wxDF_TEXT
; }
123 //-------------------------------------------------------------------------
124 // wxPrivateDropTarget
125 //-------------------------------------------------------------------------
128 class wxPrivateDropTarget: public wxDropTarget
132 wxPrivateDropTarget();
133 wxPrivateDropTarget( const wxString &id );
135 virtual bool OnMove( long x, long y );
136 virtual bool OnDrop( long x, long y );
137 virtual bool OnData( long x, long y );
139 virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
141 void SetId( const wxString& id ) { m_id = id; }
142 wxString GetId() { return m_id; }
150 //----------------------------------------------------------------------------
151 // A drop target which accepts files (dragged from File Manager or Explorer)
152 //----------------------------------------------------------------------------
154 class wxFileDropTarget
: public wxDropTarget
158 wxFileDropTarget() {}
160 virtual bool OnData( long x
, long y
);
162 virtual bool OnDropFiles( long x
, long y
, size_t nFiles
, const wxChar
* const aszFiles
[] ) = 0;
164 virtual size_t GetFormatCount() const
166 virtual wxDataFormat
GetFormat(size_t n
) const
167 { return wxDF_FILENAME
; }
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 wxDropSource( wxDataObject
& data
, wxWindow
*win
, const wxIcon
&go
= wxNullIcon
, const wxIcon
&stop
= wxNullIcon
);
193 void SetData( wxDataObject
& data
);
195 /* start drag action */
196 wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
198 /* override to give feedback */
199 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; }
201 /* GTK implementation */
203 void RegisterWindow();
204 void UnregisterWindow();
208 wxDragResult m_retValue
;
209 wxDataObject
*m_data
;
211 wxCursor m_defaultCursor
;
212 wxCursor m_goaheadCursor
;
222 // wxUSE_DRAG_AND_DROP