]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dnd.h
Further DnD changes. Untested.
[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 #include "wx/icon.h"
27 #include "wx/gdicmn.h"
28
29 //-------------------------------------------------------------------------
30 // classes
31 //-------------------------------------------------------------------------
32
33 class wxWindow;
34
35 class wxDropTarget;
36 class wxTextDropTarget;
37 class wxFileDropTarget;
38 class wxPrivateDropTarget;
39
40 class wxDropSource;
41
42 //-------------------------------------------------------------------------
43 // wxDropTarget
44 //-------------------------------------------------------------------------
45
46 class wxDropTarget: public wxObject
47 {
48 public:
49 wxDropTarget( wxDataObject *data );
50 ~wxDropTarget();
51
52 /* may be overridden to react to events */
53 virtual bool OnEnter( int x, int y );
54
55 virtual void OnLeave();
56
57 /* may be overridden to reject certain formats or drops
58 on certain areas. always returns TRUE by default
59 indicating that you'd accept the data from the drag. */
60 virtual bool OnMove( int x, int y );
61
62 /* has to be overridden to accept a drop event. call
63 IsSupported() to ask which formats are available
64 and then call RequestData() to indicate the format
65 you request. */
66 virtual bool OnDrop( int x, int y );
67
68 /* this gets called once the data has actually arrived.
69 it will call GetData() to fill up its wxDataObject */
70 virtual bool OnData( int x, int y );
71
72 /* fill data with data from the dragging source */
73 bool GetData();
74
75 // implementation
76
77 GdkAtom GetMatchingPair();
78
79 void RegisterWidget( GtkWidget *widget );
80 void UnregisterWidget( GtkWidget *widget );
81
82 wxDataObject *m_data;
83 GdkDragContext *m_dragContext;
84 GtkWidget *m_dragWidget;
85 GtkSelectionData *m_dragData;
86 guint m_dragTime;
87 bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */
88
89 void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
90 void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
91 void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
92 void SetDragTime( guint time ) { m_dragTime = time; }
93 };
94
95 //-------------------------------------------------------------------------
96 // wxDropSource
97 //-------------------------------------------------------------------------
98
99 enum wxDragResult
100 {
101 wxDragError, // error prevented the d&d operation from completing
102 wxDragNone, // drag target didn't accept the data
103 wxDragCopy, // the data was successfully copied
104 wxDragMove, // the data was successfully moved (MSW only)
105 wxDragCancel // the operation was cancelled by user (not an error)
106 };
107
108 class wxDropSource: public wxObject
109 {
110 public:
111
112 /* constructor. set data later with SetData() */
113 wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
114
115 wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
116 ~wxDropSource();
117
118 void SetData( wxDataObject& data );
119
120 /* start drag action */
121 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
122
123 /* override to give feedback */
124 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; }
125
126 /* GTK implementation */
127
128 void RegisterWindow();
129 void UnregisterWindow();
130
131 GtkWidget *m_widget;
132 wxWindow *m_window;
133 wxDragResult m_retValue;
134 wxDataObject *m_data;
135
136 wxCursor m_defaultCursor;
137 wxCursor m_goaheadCursor;
138
139 wxIcon m_goIcon;
140 wxIcon m_stopIcon;
141
142 bool m_waiting;
143 };
144
145 #endif
146
147 // wxUSE_DRAG_AND_DROP
148
149 #endif
150 //__GTKDNDH__
151