]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dnd.h
DnD feedback
[wxWidgets.git] / include / wx / gtk / 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 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 = 0;
69
70 // implementation
71
72 void RegisterWidget( GtkWidget *widget );
73 void UnregisterWidget( GtkWidget *widget );
74 };
75
76 //-------------------------------------------------------------------------
77 // wxTextDropTarget
78 //-------------------------------------------------------------------------
79
80 class wxTextDropTarget: public wxDropTarget
81 {
82 public:
83
84 wxTextDropTarget() {};
85 virtual bool OnDrop( long x, long y, const void *data, size_t size );
86 virtual bool OnDropText( long x, long y, const char *psz );
87
88 protected:
89
90 virtual size_t GetFormatCount() const;
91 virtual wxDataFormat GetFormat(size_t n) const;
92 };
93
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
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 virtual wxDataFormat GetFormat(size_t n) 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
154 wxDragCancel // the operation was cancelled by user (not an error)
155 };
156
157 class wxDropSource: public wxObject
158 {
159 public:
160
161 wxDropSource( wxWindow *win );
162 wxDropSource( wxDataObject &data, wxWindow *win );
163
164 ~wxDropSource(void);
165
166 void SetData( wxDataObject &data );
167 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
168
169 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
170
171 // implementation
172
173 void RegisterWindow(void);
174 void UnregisterWindow(void);
175
176 GtkWidget *m_widget;
177 wxWindow *m_window;
178 wxDragResult m_retValue;
179 wxDataObject *m_data;
180
181 wxCursor m_defaultCursor;
182 wxCursor m_goaheadCursor;
183 };
184
185 #endif
186
187 // wxUSE_DRAG_AND_DROP
188
189 #endif
190 //__GTKDNDH__
191