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
)
48 { if (m_data
) delete m_data
;
51 // start drag action, see enum wxDragResult for return value description
53 // if bAllowMove is TRUE, data can be moved, if not - only copied
54 virtual wxDragResult
DoDragDrop(bool bAllowMove
= FALSE
) = 0;
56 // override to give feedback depending on the current operation result
58 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
),
59 bool WXUNUSED(bScrolling
) )
68 // ----------------------------------------------------------------------------
69 // wxDropTarget should be associated with a window if it wants to be able to
70 // receive data via drag and drop.
72 // To use this class, you should derive from wxDropTarget and implement
73 // OnData() pure virtual method. You may also wish to override OnDrop() if you
74 // want to accept the data only inside some region of the window (this may
75 // avoid having to copy the data to this application which happens only when
76 // OnData() is called)
77 // ----------------------------------------------------------------------------
79 class WXDLLEXPORT wxDropTargetBase
82 // ctor takes a pointer to heap-allocated wxDataObject which will be owned
83 // by wxDropTarget and deleted by it automatically. If you don't give it
84 // here, you can use SetDataObject() later.
85 wxDropTargetBase(wxDataObject
*dataObject
= (wxDataObject
*)NULL
)
86 { m_dataObject
= dataObject
; }
87 // dtor deletes our data object
88 virtual ~wxDropTargetBase()
89 { delete m_dataObject
; }
91 // get/set the associated wxDataObject
92 wxDataObject
*GetDataObject() const
93 { return m_dataObject
; }
94 void SetDataObject(wxDataObject
*dataObject
)
95 { if (m_dataObject
) delete m_dataObject
;
96 m_dataObject
= dataObject
; }
98 // called when mouse enters/leaves the window: might be used to give
99 // some visual feedback to the user
100 virtual void OnLeave() { }
102 // this function is called when data enters over position (x, y) - if it
103 // returns TRUE, the dragging icon can indicate that the window would
104 // accept a drop here
105 virtual bool OnEnter(wxCoord x
, wxCoord y
) = 0;
107 // this function is called when data is move over position (x, y) - if it
108 // returns TRUE, the dragging icon can indicate that the window would
109 // accept a drop here
110 virtual bool OnMove(wxCoord x
, wxCoord y
) = 0;
112 // this function is called when data is dropped at position (x, y) - if it
113 // returns TRUE, OnData() will be called immediately afterwards which will
114 // allow to retrieve the data dropped.
115 virtual bool OnDrop(wxCoord x
, wxCoord y
) = 0;
117 // called after OnDrop() returns TRUE: you will usually just call
118 // GetData() from here and, probably, also refresh something to update the
120 virtual bool OnData(wxCoord x
, wxCoord y
) = 0;
122 // may be called *only* from inside OnData() and will fill m_dataObject
123 // with the data from the drop source if it returns TRUE
124 virtual bool GetData() = 0;
127 wxDataObject
*m_dataObject
;
130 // ----------------------------------------------------------------------------
131 // the platform-specific headers also define standard wxDropTarget
132 // implementations wxTextDropTarget and wxFileDropTarget
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
136 // include platform dependent class declarations
137 // ----------------------------------------------------------------------------
139 #if defined(__WXMSW__)
140 #include "wx/msw/ole/dropsrc.h"
141 #include "wx/msw/ole/droptgt.h"
142 #elif defined(__WXMOTIF__)
143 #include "wx/motif/dnd.h"
144 #elif defined(__WXGTK__)
145 #include "wx/gtk/dnd.h"
146 #elif defined(__WXQT__)
147 #include "wx/qt/dnd.h"
148 #elif defined(__WXMAC__)
149 #include "wx/mac/dnd.h"
150 #elif defined(__WXPM__)
151 #include "wx/os2/dnd.h"
152 #elif defined(__WXSTUBS__)
153 #include "wx/stubs/dnd.h"
156 #endif // wxUSE_DRAG_AND_DROP
158 #endif // _WX_DND_H_BASE_