]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: dnd.h | |
3 | // Purpose: declaration of the wxDropTarget class | |
4 | // Author: Robert Roebling | |
58614078 | 5 | // RCS-ID: $Id$ |
c801d85f KB |
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" | |
ac57418f | 19 | |
06cfab17 | 20 | #if wxUSE_DRAG_AND_DROP |
ac57418f | 21 | |
c801d85f KB |
22 | #include "wx/object.h" |
23 | #include "wx/string.h" | |
8b53e5a2 | 24 | #include "wx/dataobj.h" |
c801d85f KB |
25 | #include "wx/cursor.h" |
26 | ||
fed46e72 RR |
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 | ||
c801d85f KB |
37 | //------------------------------------------------------------------------- |
38 | // classes | |
39 | //------------------------------------------------------------------------- | |
40 | ||
41 | class wxWindow; | |
42 | ||
43 | class wxDropTarget; | |
44 | class wxTextDropTarget; | |
e3e65dac | 45 | class wxFileDropTarget; |
ab8884ac | 46 | class wxPrivateDropTarget; |
e3e65dac RR |
47 | |
48 | class wxDropSource; | |
49 | ||
c801d85f KB |
50 | //------------------------------------------------------------------------- |
51 | // wxDropTarget | |
52 | //------------------------------------------------------------------------- | |
53 | ||
46dc76ba | 54 | class wxDropTarget: public wxObject |
c801d85f KB |
55 | { |
56 | public: | |
57 | ||
58 | wxDropTarget(); | |
59 | ~wxDropTarget(); | |
e3e65dac | 60 | |
c801d85f KB |
61 | virtual void OnEnter() { } |
62 | virtual void OnLeave() { } | |
dc86cb34 | 63 | virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0; |
c801d85f | 64 | |
e3e65dac RR |
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 = 0; | |
69 | ||
dc86cb34 RR |
70 | // implementation |
71 | ||
e3e65dac | 72 | void RegisterWidget( GtkWidget *widget ); |
c801d85f KB |
73 | void UnregisterWidget( GtkWidget *widget ); |
74 | }; | |
75 | ||
76 | //------------------------------------------------------------------------- | |
77 | // wxTextDropTarget | |
78 | //------------------------------------------------------------------------- | |
79 | ||
80 | class wxTextDropTarget: public wxDropTarget | |
81 | { | |
82 | public: | |
83 | ||
84 | wxTextDropTarget() {}; | |
dc86cb34 | 85 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); |
c801d85f | 86 | virtual bool OnDropText( long x, long y, const char *psz ); |
e3e65dac RR |
87 | |
88 | protected: | |
89 | ||
90 | virtual size_t GetFormatCount() const; | |
91 | virtual wxDataFormat GetFormat(size_t n) const; | |
c801d85f KB |
92 | }; |
93 | ||
ab8884ac RR |
94 | //------------------------------------------------------------------------- |
95 | // wxPrivateDropTarget | |
96 | //------------------------------------------------------------------------- | |
97 | ||
98 | class wxPrivateDropTarget: public wxDropTarget | |
99 | { | |
100 | public: | |
101 | ||
102 | wxPrivateDropTarget(); | |
103 | ||
104 | // you have to override OnDrop to get at the data | |
105 | ||
106 | // the string ID identifies the format of clipboard or DnD data. a word | |
107 | // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject | |
108 | // to the clipboard - the latter with the Id "WXWORD_FORMAT". | |
109 | ||
110 | void SetId( const wxString& id ) | |
111 | { m_id = id; } | |
112 | ||
113 | wxString GetId() | |
114 | { return m_id; } | |
115 | ||
116 | private: | |
117 | ||
118 | virtual size_t GetFormatCount() const; | |
119 | virtual wxDataFormat GetFormat(size_t n) const; | |
120 | ||
121 | wxString m_id; | |
122 | }; | |
123 | ||
e3e65dac RR |
124 | // ---------------------------------------------------------------------------- |
125 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
126 | // ---------------------------------------------------------------------------- | |
c801d85f | 127 | |
e3e65dac | 128 | class wxFileDropTarget: public wxDropTarget |
c801d85f KB |
129 | { |
130 | public: | |
e3e65dac RR |
131 | |
132 | wxFileDropTarget() {}; | |
133 | ||
dc86cb34 | 134 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); |
e3e65dac | 135 | virtual bool OnDropFiles( long x, long y, |
dc86cb34 | 136 | size_t nFiles, const char * const aszFiles[] ); |
c801d85f | 137 | |
e3e65dac | 138 | protected: |
c801d85f | 139 | |
e3e65dac RR |
140 | virtual size_t GetFormatCount() const; |
141 | virtual wxDataFormat GetFormat(size_t n) const; | |
c801d85f KB |
142 | }; |
143 | ||
144 | //------------------------------------------------------------------------- | |
e3e65dac | 145 | // wxDropSource |
c801d85f KB |
146 | //------------------------------------------------------------------------- |
147 | ||
dc86cb34 RR |
148 | enum wxDragResult |
149 | { | |
150 | wxDragError, // error prevented the d&d operation from completing | |
151 | wxDragNone, // drag target didn't accept the data | |
152 | wxDragCopy, // the data was successfully copied | |
153 | wxDragMove, // the data was successfully moved | |
154 | wxDragCancel // the operation was cancelled by user (not an error) | |
155 | }; | |
46ccb510 | 156 | |
e3e65dac | 157 | class wxDropSource: public wxObject |
c801d85f KB |
158 | { |
159 | public: | |
160 | ||
e3e65dac RR |
161 | wxDropSource( wxWindow *win ); |
162 | wxDropSource( wxDataObject &data, wxWindow *win ); | |
163 | ||
164 | ~wxDropSource(void); | |
c801d85f | 165 | |
e3e65dac | 166 | void SetData( wxDataObject &data ); |
46ccb510 | 167 | wxDragResult DoDragDrop( bool bAllowMove = FALSE ); |
e3e65dac | 168 | |
46ccb510 | 169 | virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }; |
b6af8d80 | 170 | |
dc86cb34 RR |
171 | // implementation |
172 | ||
e3e65dac RR |
173 | void RegisterWindow(void); |
174 | void UnregisterWindow(void); | |
175 | ||
176 | GtkWidget *m_widget; | |
177 | wxWindow *m_window; | |
46ccb510 | 178 | wxDragResult m_retValue; |
e3e65dac RR |
179 | wxDataObject *m_data; |
180 | ||
181 | wxCursor m_defaultCursor; | |
182 | wxCursor m_goaheadCursor; | |
c801d85f KB |
183 | }; |
184 | ||
ac57418f RR |
185 | #endif |
186 | ||
187 | // wxUSE_DRAG_AND_DROP | |
188 | ||
c801d85f KB |
189 | #endif |
190 | //__GTKDNDH__ | |
191 |