1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Drag and drop classes declarations
4 // Author: Vadim Zeitlin, Robert Roebling
8 // Copyright: (c) wxWindows Team
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DND_H_BASE_
13 #define _WX_DND_H_BASE_
17 #if wxUSE_DRAG_AND_DROP
19 #include "wx/dataobj.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 // result of wxDropSource::DoDragDrop() call
28 wxDragError
, // error prevented the d&d operation from completing
29 wxDragNone
, // drag target didn't accept the data
30 wxDragCopy
, // the data was successfully copied
31 wxDragMove
, // the data was successfully moved (MSW only)
32 wxDragCancel
// the operation was cancelled by user (not an error)
35 // ----------------------------------------------------------------------------
36 // wxDropSource is the object you need to create (and call DoDragDrop on it)
37 // to initiate a drag-and-drop operation
38 // ----------------------------------------------------------------------------
40 class WXDLLEXPORT wxDropSourceBase
43 wxDropSourceBase() { m_data
= (wxDataObject
*)NULL
; }
44 virtual ~wxDropSourceBase() { }
46 // set the data which is transfered by drag and drop
47 void SetData(wxDataObject
& data
)
50 wxDataObject
*GetDataObject()
53 // start drag action, see enum wxDragResult for return value description
55 // if bAllowMove is TRUE, data can be moved, if not - only copied
56 virtual wxDragResult
DoDragDrop(bool bAllowMove
= FALSE
) = 0;
58 // override to give feedback depending on the current operation result
60 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
),
61 bool WXUNUSED(bScrolling
) )
70 // ----------------------------------------------------------------------------
71 // wxDropTarget should be associated with a window if it wants to be able to
72 // receive data via drag and drop.
74 // To use this class, you should derive from wxDropTarget and implement
75 // OnData() pure virtual method. You may also wish to override OnDrop() if you
76 // want to accept the data only inside some region of the window (this may
77 // avoid having to copy the data to this application which happens only when
78 // OnData() is called)
79 // ----------------------------------------------------------------------------
81 class WXDLLEXPORT wxDropTargetBase
84 // ctor takes a pointer to heap-allocated wxDataObject which will be owned
85 // by wxDropTarget and deleted by it automatically. If you don't give it
86 // here, you can use SetDataObject() later.
87 wxDropTargetBase(wxDataObject
*dataObject
= (wxDataObject
*)NULL
)
88 { m_dataObject
= dataObject
; }
89 // dtor deletes our data object
90 virtual ~wxDropTargetBase()
91 { delete m_dataObject
; }
93 // get/set the associated wxDataObject
94 wxDataObject
*GetDataObject() const
95 { return m_dataObject
; }
96 void SetDataObject(wxDataObject
*dataObject
)
97 { if (m_dataObject
) delete m_dataObject
;
98 m_dataObject
= dataObject
; }
100 // these functions are called when data is moved over position (x, y) and
101 // may return either wxDragCopy, wxDragMove or wxDragNone depending on
102 // what would happen if the data were dropped here.
104 // the last parameter is what would happen by default and is determined by
105 // the platform-specific logic (for example, under Windows it's wxDragCopy
106 // if Ctrl key is pressed and wxDragMove otherwise) except that it will
107 // always be wxDragNone if the carried data is in an unsupported format.
109 // called when the mouse enters the window (only once until OnLeave())
110 virtual wxDragResult
OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
)
111 { return OnDragOver(x
, y
, def
); }
113 // called when the mouse moves in the window - shouldn't take long to
114 // execute or otherwise mouse movement would be too slow
115 virtual wxDragResult
OnDragOver(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
119 // called when mouse leaves the window: might be used to remove the
120 // feedback which was given in OnEnter()
121 virtual void OnLeave() { }
123 // this function is called when data is dropped at position (x, y) - if it
124 // returns TRUE, OnData() will be called immediately afterwards which will
125 // allow to retrieve the data dropped.
126 virtual bool OnDrop(wxCoord x
, wxCoord y
) = 0;
128 // called after OnDrop() returns TRUE: you will usually just call
129 // GetData() from here and, probably, also refresh something to update the
131 virtual bool OnData(wxCoord x
, wxCoord y
) = 0;
133 // may be called *only* from inside OnData() and will fill m_dataObject
134 // with the data from the drop source if it returns TRUE
135 virtual bool GetData() = 0;
138 wxDataObject
*m_dataObject
;
141 // ----------------------------------------------------------------------------
142 // the platform-specific headers also define standard wxDropTarget
143 // implementations wxTextDropTarget and wxFileDropTarget
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
147 // include platform dependent class declarations
148 // ----------------------------------------------------------------------------
150 #if defined(__WXMSW__)
151 #include "wx/msw/ole/dropsrc.h"
152 #include "wx/msw/ole/droptgt.h"
153 #elif defined(__WXMOTIF__)
154 #include "wx/motif/dnd.h"
155 #elif defined(__WXGTK__)
156 #include "wx/gtk/dnd.h"
157 #elif defined(__WXQT__)
158 #include "wx/qt/dnd.h"
159 #elif defined(__WXMAC__)
160 #include "wx/mac/dnd.h"
161 #elif defined(__WXPM__)
162 #include "wx/os2/dnd.h"
163 #elif defined(__WXSTUBS__)
164 #include "wx/stubs/dnd.h"
167 #endif // wxUSE_DRAG_AND_DROP
169 #endif // _WX_DND_H_BASE_