]>
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 ///////////////////////////////////////////////////////////////////////////////
18 #if wxUSE_DRAG_AND_DROP
20 #include "wx/object.h"
21 #include "wx/string.h"
22 #include "wx/dataobj.h"
23 #include "wx/cursor.h"
25 #include "wx/gdicmn.h"
27 //-------------------------------------------------------------------------
29 //-------------------------------------------------------------------------
34 class wxTextDropTarget
;
35 class wxFileDropTarget
;
36 class wxPrivateDropTarget
;
40 //-------------------------------------------------------------------------
42 //-------------------------------------------------------------------------
44 class wxDropTarget
: public wxObject
51 /* may be overridden to react to events */
52 virtual void OnEnter();
53 virtual void OnLeave();
55 /* may be overridden to reject certain formats or drops
56 on certain areas. always returns TRUE by default
57 indicating that you'd accept the data from the drag. */
58 virtual bool OnMove( long x
, long y
);
60 /* has to be overridden to accept a drop event. call
61 IsSupported() to ask which formats are available
62 and then call RequestData() to indicate the format
64 virtual bool OnDrop( long x
, long y
);
66 /* this gets called once the data has actually arrived. get
67 it with GetData(). this has to be overridden. */
68 virtual bool OnData( long x
, long y
);
70 /* called from within OnDrop() to request a certain format
71 from the drop event. */
72 bool RequestData( wxDataFormat format
);
74 /* called to query what formats are available */
75 bool IsSupported( wxDataFormat format
);
77 /* fill data with data from the dragging source */
78 bool GetData( wxDataObject
*data
);
80 virtual size_t GetFormatCount() const = 0;
81 virtual wxDataFormat
GetFormat(size_t n
) const = 0;
85 void RegisterWidget( GtkWidget
*widget
);
86 void UnregisterWidget( GtkWidget
*widget
);
88 GdkDragContext
*m_dragContext
;
89 GtkWidget
*m_dragWidget
;
90 GtkSelectionData
*m_dragData
;
92 bool m_firstMotion
; /* gdk has no "gdk_drag_enter" event */
94 void SetDragContext( GdkDragContext
*dc
) { m_dragContext
= dc
; }
95 void SetDragWidget( GtkWidget
*w
) { m_dragWidget
= w
; }
96 void SetDragData( GtkSelectionData
*sd
) { m_dragData
= sd
; }
97 void SetDragTime( guint time
) { m_dragTime
= time
; }
100 //-------------------------------------------------------------------------
102 //-------------------------------------------------------------------------
104 class wxTextDropTarget
: public wxDropTarget
108 wxTextDropTarget() {}
110 virtual bool OnData( long x
, long y
);
112 /* you have to override OnDropData to get at the text */
113 virtual bool OnDropText( long x
, long y
, const wxChar
*text
) = 0;
115 virtual size_t GetFormatCount() const
117 virtual wxDataFormat
GetFormat(size_t n
) const
118 { return wxDF_TEXT
; }
121 //-------------------------------------------------------------------------
122 // wxPrivateDropTarget
123 //-------------------------------------------------------------------------
126 class wxPrivateDropTarget: public wxDropTarget
130 wxPrivateDropTarget();
131 wxPrivateDropTarget( const wxString &id );
133 virtual bool OnMove( long x, long y );
134 virtual bool OnDrop( long x, long y );
135 virtual bool OnData( long x, long y );
137 virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
139 void SetId( const wxString& id ) { m_id = id; }
140 wxString GetId() { return m_id; }
148 //----------------------------------------------------------------------------
149 // A drop target which accepts files (dragged from File Manager or Explorer)
150 //----------------------------------------------------------------------------
152 class wxFileDropTarget
: public wxDropTarget
156 wxFileDropTarget() {}
158 virtual bool OnData( long x
, long y
);
160 virtual bool OnDropFiles( long x
, long y
, size_t nFiles
, const wxChar
* const aszFiles
[] ) = 0;
162 virtual size_t GetFormatCount() const
164 virtual wxDataFormat
GetFormat(size_t n
) const
165 { return wxDF_FILENAME
; }
168 //-------------------------------------------------------------------------
170 //-------------------------------------------------------------------------
172 class wxDropSource
: public wxObject
175 /* constructor. set data later with SetData() */
176 wxDropSource( wxWindow
*win
,
177 const wxIcon
&go
= wxNullIcon
,
178 const wxIcon
&stop
= wxNullIcon
);
180 /* constructor for setting one data object */
181 wxDropSource( wxDataObject
& data
,
183 const wxIcon
&go
= wxNullIcon
,
184 const wxIcon
&stop
= wxNullIcon
);
188 /* start drag action */
189 virtual wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
191 /* GTK implementation */
192 void RegisterWindow();
193 void UnregisterWindow();
197 wxDragResult m_retValue
;
198 wxDataObject
*m_data
;
200 wxCursor m_defaultCursor
;
201 wxCursor m_goaheadCursor
;
211 // wxUSE_DRAG_AND_DROP