wxDataObject changes - ok for MSW, still not for GTK/Motif/...
[wxWidgets.git] / include / wx / dnd.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dnd.h
3 // Purpose: Drag and drop classes declarations
4 // Author: Vadim Zeitlin, Robert Roebling
5 // Modified by:
6 // Created: 26.05.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows Team
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DND_H_BASE_
13 #define _WX_DND_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_DRAG_AND_DROP
18
19 #include "wx/dataobj.h"
20
21 // ----------------------------------------------------------------------------
22 // constants
23 // ----------------------------------------------------------------------------
24
25 // result of wxDropSource::DoDragDrop() call
26 enum wxDragResult
27 {
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)
33 };
34
35 // ----------------------------------------------------------------------------
36 // wxDropSource is the object you need to create (and call DoDragDrop on it)
37 // to initiate a drag-and-drop operation
38 // ----------------------------------------------------------------------------
39
40 class WXDLLEXPORT wxDropSourceBase
41 {
42 public:
43 wxDropSourceBase() { m_data = (wxDataObject *)NULL; }
44 virtual ~wxDropSourceBase() { }
45
46 // set the data which is transfered by drag and drop
47 void SetData(wxDataObject& data) { delete m_data; m_data = &data; }
48
49 // start drag action, see enum wxDragResult for return value description
50 //
51 // if bAllowMove is TRUE, data can be moved, if not - only copied
52 virtual wxDragResult DoDragDrop(bool bAllowMove = FALSE) = 0;
53
54 // override to give feedback depending on the current operation result
55 // "effect"
56 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect),
57 bool WXUNUSED(bScrolling) )
58 {
59 return TRUE;
60 }
61
62 protected:
63 wxDataObject *m_data;
64 };
65
66 // ----------------------------------------------------------------------------
67 // wxDropTarget should be associated with a window if it wants to be able to
68 // receive data via drag and drop.
69 //
70 // To use this class, you should derive from wxDropTarget and implement
71 // OnData() pure virtual method. You may also wish to override OnDrop() if you
72 // want to accept the data only inside some region of the window (this may
73 // avoid having to copy the data to this application which happens only when
74 // OnData() is called)
75 // ----------------------------------------------------------------------------
76
77 class WXDLLEXPORT wxDropTargetBase
78 {
79 public:
80 // ctor takes a pointer to heap-allocated wxDataObject which will be owned
81 // by wxDropTarget and deleted by it automatically. If you don't give it
82 // here, you can use SetDataObject() later.
83 wxDropTargetBase(wxDataObject *dataObject = NULL)
84 { m_dataObject = dataObject; }
85 // dtor deletes our data object
86 virtual ~wxDropTargetBase()
87 { delete m_dataObject; }
88
89 // get/set the associated wxDataObject
90 wxDataObject *GetDataObject() const
91 { return m_dataObject; }
92 void SetDataObject(wxDataObject *dataObject)
93 { delete m_dataObject; m_dataObject = dataObject; }
94
95 // called when mouse enters/leaves the window: might be used to give
96 // some visual feedback to the user
97 virtual void OnEnter() { }
98 virtual void OnLeave() { }
99
100 // this function is called when data is dropped at position (x, y) - if it
101 // returns TRUE, OnData() will be called immediately afterwards which will
102 // allow to retrieve the data dropped.
103 virtual bool OnDrop(wxCoord x, wxCoord y) = 0;
104
105 // called after OnDrop() returns TRUE: you will usually just call
106 // GetData() from here and, probably, also refresh something to update the
107 // new data
108 virtual bool OnData(wxCoord x, wxCoord y) = 0;
109
110 // may be called *only* from inside OnData() and will fill m_dataObject
111 // with the data from the drop source if it returns TRUE
112 virtual bool GetData() = 0;
113
114 protected:
115 wxDataObject *m_dataObject;
116 };
117
118 // ----------------------------------------------------------------------------
119 // the platform-specific headers also define standard wxDropTarget
120 // implementations wxTextDropTarget and wxFileDropTarget
121 // ----------------------------------------------------------------------------
122
123 // ----------------------------------------------------------------------------
124 // include platform dependent class declarations
125 // ----------------------------------------------------------------------------
126
127 #if defined(__WXMSW__)
128 #include "wx/msw/ole/dropsrc.h"
129 #include "wx/msw/ole/droptgt.h"
130 #elif defined(__WXMOTIF__)
131 #include "wx/motif/dnd.h"
132 #elif defined(__WXGTK__)
133 #include "wx/gtk/dnd.h"
134 #elif defined(__WXQT__)
135 #include "wx/qt/dnd.h"
136 #elif defined(__WXMAC__)
137 #include "wx/mac/dnd.h"
138 #elif defined(__WXPM__)
139 #include "wx/os2/dnd.h"
140 #elif defined(__WXSTUBS__)
141 #include "wx/stubs/dnd.h"
142 #endif
143
144 #endif // wxUSE_DRAG_AND_DROP
145
146 #endif // _WX_DND_H_BASE_