]>
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 | #include "wx/object.h" | |
20 | #include "wx/string.h" | |
21 | #include "wx/dataobj.h" | |
22 | #include "wx/cursor.h" | |
23 | ||
24 | //------------------------------------------------------------------------- | |
25 | // conditional compilation | |
26 | //------------------------------------------------------------------------- | |
27 | ||
28 | #if (GTK_MINOR_VERSION == 1) | |
29 | #if (GTK_MICRO_VERSION >= 3) | |
30 | #define NEW_GTK_DND_CODE | |
31 | #endif | |
32 | #endif | |
33 | ||
34 | //------------------------------------------------------------------------- | |
35 | // classes | |
36 | //------------------------------------------------------------------------- | |
37 | ||
38 | class wxWindow; | |
39 | ||
40 | class wxDropTarget; | |
41 | class wxTextDropTarget; | |
42 | class wxFileDropTarget; | |
43 | ||
44 | class wxDropSource; | |
45 | ||
46 | //------------------------------------------------------------------------- | |
47 | // wxDropTarget | |
48 | //------------------------------------------------------------------------- | |
49 | ||
50 | class wxDropTarget: public wxObject | |
51 | { | |
52 | public: | |
53 | ||
54 | wxDropTarget(); | |
55 | ~wxDropTarget(); | |
56 | ||
57 | virtual void OnEnter() { } | |
58 | virtual void OnLeave() { } | |
59 | virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0; | |
60 | ||
61 | // Override these to indicate what kind of data you support: | |
62 | ||
63 | virtual size_t GetFormatCount() const = 0; | |
64 | virtual wxDataFormat GetFormat(size_t n) const = 0; | |
65 | ||
66 | // implementation | |
67 | ||
68 | void RegisterWidget( GtkWidget *widget ); | |
69 | void UnregisterWidget( GtkWidget *widget ); | |
70 | }; | |
71 | ||
72 | //------------------------------------------------------------------------- | |
73 | // wxTextDropTarget | |
74 | //------------------------------------------------------------------------- | |
75 | ||
76 | class wxTextDropTarget: public wxDropTarget | |
77 | { | |
78 | public: | |
79 | ||
80 | wxTextDropTarget() {}; | |
81 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); | |
82 | virtual bool OnDropText( long x, long y, const char *psz ); | |
83 | ||
84 | protected: | |
85 | ||
86 | virtual size_t GetFormatCount() const; | |
87 | virtual wxDataFormat GetFormat(size_t n) const; | |
88 | }; | |
89 | ||
90 | // ---------------------------------------------------------------------------- | |
91 | // A drop target which accepts files (dragged from File Manager or Explorer) | |
92 | // ---------------------------------------------------------------------------- | |
93 | ||
94 | class wxFileDropTarget: public wxDropTarget | |
95 | { | |
96 | public: | |
97 | ||
98 | wxFileDropTarget() {}; | |
99 | ||
100 | virtual bool OnDrop( long x, long y, const void *data, size_t size ); | |
101 | virtual bool OnDropFiles( long x, long y, | |
102 | size_t nFiles, const char * const aszFiles[] ); | |
103 | ||
104 | protected: | |
105 | ||
106 | virtual size_t GetFormatCount() const; | |
107 | virtual wxDataFormat GetFormat(size_t n) const; | |
108 | }; | |
109 | ||
110 | //------------------------------------------------------------------------- | |
111 | // wxDropSource | |
112 | //------------------------------------------------------------------------- | |
113 | ||
114 | enum wxDragResult | |
115 | { | |
116 | wxDragError, // error prevented the d&d operation from completing | |
117 | wxDragNone, // drag target didn't accept the data | |
118 | wxDragCopy, // the data was successfully copied | |
119 | wxDragMove, // the data was successfully moved | |
120 | wxDragCancel // the operation was cancelled by user (not an error) | |
121 | }; | |
122 | ||
123 | class wxDropSource: public wxObject | |
124 | { | |
125 | public: | |
126 | ||
127 | wxDropSource( wxWindow *win ); | |
128 | wxDropSource( wxDataObject &data, wxWindow *win ); | |
129 | ||
130 | ~wxDropSource(void); | |
131 | ||
132 | void SetData( wxDataObject &data ); | |
133 | wxDragResult DoDragDrop( bool bAllowMove = FALSE ); | |
134 | ||
135 | virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }; | |
136 | ||
137 | // implementation | |
138 | ||
139 | void RegisterWindow(void); | |
140 | void UnregisterWindow(void); | |
141 | ||
142 | GtkWidget *m_widget; | |
143 | wxWindow *m_window; | |
144 | wxDragResult m_retValue; | |
145 | wxDataObject *m_data; | |
146 | ||
147 | wxCursor m_defaultCursor; | |
148 | wxCursor m_goaheadCursor; | |
149 | }; | |
150 | ||
151 | #endif | |
152 | //__GTKDNDH__ | |
153 |