]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/dnd.h
changed make_int, make_exp .. to wxmake_int..
[wxWidgets.git] / include / wx / gtk1 / dnd.h
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 void OnMouseMove( long WXUNUSED(x), long WXUNUSED(y) ) { }
64 virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0;
65
66 // Override these to indicate what kind of data you support:
67
68 virtual size_t GetFormatCount() const = 0;
69 virtual wxDataFormat &GetFormat(size_t n) const;
70
71 // implementation
72
73 void RegisterWidget( GtkWidget *widget );
74 void UnregisterWidget( GtkWidget *widget );
75
76 wxDataFormat *m_format;
77 };
78
79 //-------------------------------------------------------------------------
80 // wxTextDropTarget
81 //-------------------------------------------------------------------------
82
83 class wxTextDropTarget: public wxDropTarget
84 {
85 public:
86
87 wxTextDropTarget();
88 virtual bool OnDrop( long x, long y, const void *data, size_t size );
89 virtual bool OnDropText( long x, long y, const char *psz );
90
91 protected:
92
93 virtual size_t GetFormatCount() const;
94 };
95
96 //-------------------------------------------------------------------------
97 // wxPrivateDropTarget
98 //-------------------------------------------------------------------------
99
100 class wxPrivateDropTarget: public wxDropTarget
101 {
102 public:
103
104 wxPrivateDropTarget();
105
106 // you have to override OnDrop to get at the data
107
108 // the string ID identifies the format of clipboard or DnD data. a word
109 // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
110 // to the clipboard - the latter with the Id "application/wxword" or
111 // "image/png".
112
113 void SetId( const wxString& id );
114
115 wxString GetId()
116 { return m_id; }
117
118 private:
119
120 virtual size_t GetFormatCount() const;
121
122 wxString m_id;
123 };
124
125 //----------------------------------------------------------------------------
126 // A drop target which accepts files (dragged from File Manager or Explorer)
127 //----------------------------------------------------------------------------
128
129 class wxFileDropTarget: public wxDropTarget
130 {
131 public:
132
133 wxFileDropTarget();
134
135 virtual bool OnDrop( long x, long y, const void *data, size_t size );
136 virtual bool OnDropFiles( long x, long y,
137 size_t nFiles, const char * const aszFiles[] );
138
139 protected:
140
141 virtual size_t GetFormatCount() const;
142 };
143
144 //-------------------------------------------------------------------------
145 // wxDropSource
146 //-------------------------------------------------------------------------
147
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 (MSW only)
154 wxDragCancel // the operation was cancelled by user (not an error)
155 };
156
157 class wxDropSource: public wxObject
158 {
159 public:
160
161 /* constructor. set data later with SetData() */
162 wxDropSource( wxWindow *win );
163
164 /* constructor for setting one data object */
165 wxDropSource( wxDataObject *data, wxWindow *win );
166
167 /* constructor for setting several data objects via wxDataBroker */
168 wxDropSource( wxDataBroker *data, wxWindow *win );
169
170 ~wxDropSource(void);
171
172 /* set one dataobject */
173 void SetData( wxDataBroker *data );
174
175 /* set severa dataobjects via wxDataBroker */
176 void SetData( wxDataObject *data );
177
178 /* start drag action */
179 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
180
181 /* override to give feedback */
182 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
183
184 /* GTK implementation */
185
186 void RegisterWindow(void);
187 void UnregisterWindow(void);
188
189 GtkWidget *m_widget;
190 wxWindow *m_window;
191 wxDragResult m_retValue;
192 wxDataBroker *m_data;
193
194 wxCursor m_defaultCursor;
195 wxCursor m_goaheadCursor;
196 };
197
198 #endif
199
200 // wxUSE_DRAG_AND_DROP
201
202 #endif
203 //__GTKDNDH__
204