]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: dnd.h | |
3 | // Purpose: declaration of the wxDropTarget class | |
4 | // Author: Robert Roebling | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling | |
7 | // Licence: wxWindows license | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | ||
11 | #ifndef __GTKDNDH__ | |
12 | #define __GTKDNDH__ | |
13 | ||
14 | #ifdef __GNUG__ | |
15 | #pragma interface | |
16 | #endif | |
17 | ||
18 | #include "wx/defs.h" | |
19 | ||
20 | #if wxUSE_DRAG_AND_DROP | |
21 | ||
22 | #include "wx/object.h" | |
23 | #include "wx/string.h" | |
24 | #include "wx/dataobj.h" | |
25 | #include "wx/cursor.h" | |
26 | ||
27 | //------------------------------------------------------------------------- | |
28 | // conditional compilation | |
29 | //------------------------------------------------------------------------- | |
30 | ||
31 | #if (GTK_MINOR_VERSION == 1) | |
32 | #if (GTK_MICRO_VERSION >= 3) | |
33 | #define NEW_GTK_DND_CODE | |
34 | #endif | |
35 | #endif | |
36 | ||
37 | //------------------------------------------------------------------------- | |
38 | // classes | |
39 | //------------------------------------------------------------------------- | |
40 | ||
41 | class wxWindow; | |
42 | ||
43 | class wxDropTarget; | |
44 | class wxTextDropTarget; | |
45 | class wxFileDropTarget; | |
46 | class wxPrivateDropTarget; | |
47 | ||
48 | class wxDropSource; | |
49 | ||
50 | //------------------------------------------------------------------------- | |
51 | // wxDropTarget | |
52 | //------------------------------------------------------------------------- | |
53 | ||
54 | class wxDropTarget: public wxObject | |
55 | { | |
56 | public: | |
57 | ||
58 | wxDropTarget(); | |
59 | ~wxDropTarget(); | |
60 | ||
61 | virtual void OnEnter() { } | |
62 | virtual void OnLeave() { } | |
63 | virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0; | |
64 | ||
65 | // Override these to indicate what kind of data you support: | |
66 | ||
67 | virtual size_t GetFormatCount() const = 0; | |
68 | virtual wxDataFormat &GetFormat(size_t n) const; | |
69 | ||
70 | // implementation | |
71 | ||
72 | void RegisterWidget( GtkWidget *widget ); | |
73 | void UnregisterWidget( GtkWidget *widget ); | |
74 | ||
75 | wxDataFormat *m_format; | |
76 | }; | |
77 | ||
78 | //------------------------------------------------------------------------- | |
79 | // wxTextDropTarget | |
80 | //------------------------------------------------------------------------- | |
81 | ||
82 | class wxTextDropTarget: public wxDropTarget | |
83 | { | |
84 | public: | |
85 | ||
86 | wxTextDropTarget(); | |
87 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); | |
88 | virtual bool OnDropText( long x, long y, const char *psz ); | |
89 | ||
90 | protected: | |
91 | ||
92 | virtual size_t GetFormatCount() const; | |
93 | }; | |
94 | ||
95 | //------------------------------------------------------------------------- | |
96 | // wxPrivateDropTarget | |
97 | //------------------------------------------------------------------------- | |
98 | ||
99 | class wxPrivateDropTarget: public wxDropTarget | |
100 | { | |
101 | public: | |
102 | ||
103 | wxPrivateDropTarget(); | |
104 | ||
105 | // you have to override OnDrop to get at the data | |
106 | ||
107 | // the string ID identifies the format of clipboard or DnD data. a word | |
108 | // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject | |
109 | // to the clipboard - the latter with the Id "application/wxword" or | |
110 | // "image/png". | |
111 | ||
112 | void SetId( const wxString& id ); | |
113 | ||
114 | wxString GetId() | |
115 | { return m_id; } | |
116 | ||
117 | private: | |
118 | ||
119 | virtual size_t GetFormatCount() const; | |
120 | ||
121 | wxString m_id; | |
122 | }; | |
123 | ||
124 | //---------------------------------------------------------------------------- | |
125 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
126 | //---------------------------------------------------------------------------- | |
127 | ||
128 | class wxFileDropTarget: public wxDropTarget | |
129 | { | |
130 | public: | |
131 | ||
132 | wxFileDropTarget(); | |
133 | ||
134 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); | |
135 | virtual bool OnDropFiles( long x, long y, | |
136 | size_t nFiles, const char * const aszFiles[] ); | |
137 | ||
138 | protected: | |
139 | ||
140 | virtual size_t GetFormatCount() const; | |
141 | }; | |
142 | ||
143 | //------------------------------------------------------------------------- | |
144 | // wxDropSource | |
145 | //------------------------------------------------------------------------- | |
146 | ||
147 | enum wxDragResult | |
148 | { | |
149 | wxDragError, // error prevented the d&d operation from completing | |
150 | wxDragNone, // drag target didn't accept the data | |
151 | wxDragCopy, // the data was successfully copied | |
152 | wxDragMove, // the data was successfully moved (MSW only) | |
153 | wxDragCancel // the operation was cancelled by user (not an error) | |
154 | }; | |
155 | ||
156 | class wxDropSource: public wxObject | |
157 | { | |
158 | public: | |
159 | ||
160 | /* constructor. set data later with SetData() */ | |
161 | wxDropSource( wxWindow *win ); | |
162 | ||
163 | /* constructor for setting one data object */ | |
164 | wxDropSource( wxDataObject *data, wxWindow *win ); | |
165 | ||
166 | /* constructor for setting several data objects via wxDataBroker */ | |
167 | wxDropSource( wxDataBroker *data, wxWindow *win ); | |
168 | ||
169 | ~wxDropSource(void); | |
170 | ||
171 | /* set one dataobject */ | |
172 | void SetData( wxDataBroker *data ); | |
173 | ||
174 | /* set severa dataobjects via wxDataBroker */ | |
175 | void SetData( wxDataObject *data ); | |
176 | ||
177 | /* start drag action */ | |
178 | wxDragResult DoDragDrop( bool bAllowMove = FALSE ); | |
179 | ||
180 | /* override to give feedback */ | |
181 | virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; } | |
182 | ||
183 | /* GTK implementation */ | |
184 | ||
185 | void RegisterWindow(void); | |
186 | void UnregisterWindow(void); | |
187 | ||
188 | GtkWidget *m_widget; | |
189 | wxWindow *m_window; | |
190 | wxDragResult m_retValue; | |
191 | wxDataBroker *m_data; | |
192 | ||
193 | wxCursor m_defaultCursor; | |
194 | wxCursor m_goaheadCursor; | |
195 | }; | |
196 | ||
197 | #endif | |
198 | ||
199 | // wxUSE_DRAG_AND_DROP | |
200 | ||
201 | #endif | |
202 | //__GTKDNDH__ | |
203 |