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
) { delete m_data
; m_data
= &data
; }
49 // start drag action, see enum wxDragResult for return value description
51 // if bAllowMove is TRUE, data can be moved, if not - only copied
52 virtual wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
54 // override to give feedback depending on the current operation result
56 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
),
57 bool WXUNUSED(bScrolling
) )
66 // ----------------------------------------------------------------------------
67 // wxDropTarget should be associated with a window if it wants to be able to
68 // receive data via drag and drop
69 // ----------------------------------------------------------------------------
71 class WXDLLEXPORT wxDropTargetBase
74 // ctor takes a pointer to heap-allocated wxDataObject which will be owned
75 // by wxDropTarget and deleted by it automatically. If you don't give it
76 // here, you can use SetDataObject() later.
77 wxDropTargetBase(wxDataObject
*dataObject
= NULL
)
78 { m_dataObject
= dataObject
; }
79 // dtor deletes our data object
80 virtual ~wxDropTargetBase()
81 { delete m_dataObject
; }
83 // get/set the associated wxDataObject
84 wxDataObject
*GetDataObject() const
85 { return m_dataObject
; }
86 void SetDataObject(wxDataObject
*dataObject
)
87 { delete m_dataObject
; m_dataObject
= dataObject
; }
89 // called when mouse enters/leaves the window: might be used to give
90 // some visual feedback to the user
91 virtual void OnEnter() { }
92 virtual void OnLeave() { }
94 // this function is called when data is dropped at position (x, y) - if it
95 // returns TRUE, OnData() will be called immediately afterwards which will
96 // allow to retrieve the data dropped.
97 virtual bool OnDrop(wxCoord x
, wxCoord y
) = 0;
99 // called after OnDrop() returns TRUE: you will usually just call
100 // GetData() from here and, probably, also refresh something to update the
102 virtual bool OnData() = 0;
104 // may be called *only* from inside OnData() and will fill m_dataObject
105 // with the data from the drop source if it returns TRUE
106 virtual bool GetData() = 0;
109 wxDataObject
*m_dataObject
;
112 // ----------------------------------------------------------------------------
113 // include platform dependent class declarations
114 // ----------------------------------------------------------------------------
116 #if defined(__WXMSW__)
117 #include "wx/dataobj.h"
118 #include "wx/msw/ole/dropsrc.h"
119 #include "wx/msw/ole/droptgt.h"
120 #elif defined(__WXMOTIF__)
121 #include "wx/motif/dnd.h"
122 #elif defined(__WXGTK__)
123 #include "wx/gtk/dnd.h"
124 #elif defined(__WXQT__)
125 #include "wx/qt/dnd.h"
126 #elif defined(__WXMAC__)
127 #include "wx/mac/dnd.h"
128 #elif defined(__WXPM__)
129 #include "wx/os2/dnd.h"
130 #elif defined(__WXSTUBS__)
131 #include "wx/stubs/dnd.h"
134 #endif // wxUSE_DRAG_AND_DROP
136 #endif // _WX_DND_H_BASE_