]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk1/dnd.h
Corrected wxCHECK calls in bitmap.cpp
[wxWidgets.git] / include / wx / gtk1 / dnd.h
CommitLineData
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"
19#include "wx/object.h"
20#include "wx/string.h"
21#include "wx/cursor.h"
22
23//-------------------------------------------------------------------------
24// classes
25//-------------------------------------------------------------------------
26
27class wxWindow;
28
e3e65dac
RR
29class wxDataObject;
30class wxTextDataObject;
31class wxFileDataObject;
32
c801d85f
KB
33class wxDropTarget;
34class wxTextDropTarget;
e3e65dac
RR
35class wxFileDropTarget;
36
37class wxDropSource;
38
39//-------------------------------------------------------------------------
40// wxDataObject
41//-------------------------------------------------------------------------
42
43class wxDataObject: public wxObject
44{
45public:
dc86cb34 46
e3e65dac
RR
47 wxDataObject() {};
48 ~wxDataObject() {};
49
e3e65dac 50 virtual wxDataFormat GetPreferredFormat() const = 0;
dc86cb34 51 virtual bool IsSupportedFormat( wxDataFormat format ) const = 0;
c86f1403 52 virtual size_t GetDataSize() const = 0;
dc86cb34 53 virtual void GetDataHere( void *data ) const = 0;
e3e65dac
RR
54
55};
56
57// ----------------------------------------------------------------------------
58// wxTextDataObject is a specialization of wxDataObject for text data
59// ----------------------------------------------------------------------------
60
61class wxTextDataObject : public wxDataObject
62{
63public:
dc86cb34 64
e3e65dac
RR
65 wxTextDataObject() { }
66 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
67 void Init(const wxString& strText) { m_strText = strText; }
68
e3e65dac
RR
69 virtual wxDataFormat GetPreferredFormat() const
70 { return wxDF_TEXT; }
dc86cb34 71
e3e65dac
RR
72 virtual bool IsSupportedFormat(wxDataFormat format) const
73 { return format == wxDF_TEXT; }
dc86cb34 74
c86f1403 75 virtual size_t GetDataSize() const
dc86cb34
RR
76 { return m_strText.Len() + 1; } // +1 for trailing '\0'
77
78 virtual void GetDataHere( void *data ) const
79 { memcpy(data, m_strText.c_str(), GetDataSize()); }
e3e65dac
RR
80
81private:
82 wxString m_strText;
83
84};
c801d85f 85
e3e65dac
RR
86// ----------------------------------------------------------------------------
87// wxFileDataObject is a specialization of wxDataObject for file names
88// ----------------------------------------------------------------------------
89
90class wxFileDataObject : public wxDataObject
91{
92public:
93
94 wxFileDataObject(void) { }
95 void AddFile( const wxString &file )
e5403d7c 96 { m_files += file; m_files += '\0'; }
e3e65dac 97
e3e65dac
RR
98 virtual wxDataFormat GetPreferredFormat() const
99 { return wxDF_FILENAME; }
dc86cb34
RR
100
101 virtual bool IsSupportedFormat( wxDataFormat format ) const
e3e65dac 102 { return format == wxDF_FILENAME; }
dc86cb34 103
c86f1403 104 virtual size_t GetDataSize() const
e5403d7c 105 { return m_files.Len(); } // no trailing '\0'
dc86cb34
RR
106
107 virtual void GetDataHere( void *data ) const
108 { memcpy(data, m_files.c_str(), GetDataSize()); }
e3e65dac
RR
109
110private:
111 wxString m_files;
112
113};
c801d85f
KB
114//-------------------------------------------------------------------------
115// wxDropTarget
116//-------------------------------------------------------------------------
117
46dc76ba 118class wxDropTarget: public wxObject
c801d85f
KB
119{
120 public:
121
122 wxDropTarget();
123 ~wxDropTarget();
e3e65dac 124
c801d85f
KB
125 virtual void OnEnter() { }
126 virtual void OnLeave() { }
dc86cb34 127 virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0;
c801d85f 128
e3e65dac
RR
129 // Override these to indicate what kind of data you support:
130
131 virtual size_t GetFormatCount() const = 0;
132 virtual wxDataFormat GetFormat(size_t n) const = 0;
133
dc86cb34
RR
134 // implementation
135
e3e65dac 136 void RegisterWidget( GtkWidget *widget );
c801d85f
KB
137 void UnregisterWidget( GtkWidget *widget );
138};
139
140//-------------------------------------------------------------------------
141// wxTextDropTarget
142//-------------------------------------------------------------------------
143
144class wxTextDropTarget: public wxDropTarget
145{
146 public:
147
148 wxTextDropTarget() {};
dc86cb34 149 virtual bool OnDrop( long x, long y, const void *data, size_t size );
c801d85f 150 virtual bool OnDropText( long x, long y, const char *psz );
e3e65dac
RR
151
152 protected:
153
154 virtual size_t GetFormatCount() const;
155 virtual wxDataFormat GetFormat(size_t n) const;
c801d85f
KB
156};
157
e3e65dac
RR
158// ----------------------------------------------------------------------------
159// A drop target which accepts files (dragged from File Manager or Explorer)
160// ----------------------------------------------------------------------------
c801d85f 161
e3e65dac 162class wxFileDropTarget: public wxDropTarget
c801d85f
KB
163{
164 public:
e3e65dac
RR
165
166 wxFileDropTarget() {};
167
dc86cb34 168 virtual bool OnDrop( long x, long y, const void *data, size_t size );
e3e65dac 169 virtual bool OnDropFiles( long x, long y,
dc86cb34 170 size_t nFiles, const char * const aszFiles[] );
c801d85f 171
e3e65dac 172 protected:
c801d85f 173
e3e65dac
RR
174 virtual size_t GetFormatCount() const;
175 virtual wxDataFormat GetFormat(size_t n) const;
c801d85f
KB
176};
177
178//-------------------------------------------------------------------------
e3e65dac 179// wxDropSource
c801d85f
KB
180//-------------------------------------------------------------------------
181
dc86cb34
RR
182enum wxDragResult
183{
184 wxDragError, // error prevented the d&d operation from completing
185 wxDragNone, // drag target didn't accept the data
186 wxDragCopy, // the data was successfully copied
187 wxDragMove, // the data was successfully moved
188 wxDragCancel // the operation was cancelled by user (not an error)
189};
46ccb510 190
e3e65dac 191class wxDropSource: public wxObject
c801d85f
KB
192{
193 public:
194
e3e65dac
RR
195 wxDropSource( wxWindow *win );
196 wxDropSource( wxDataObject &data, wxWindow *win );
197
198 ~wxDropSource(void);
c801d85f 199
e3e65dac 200 void SetData( wxDataObject &data );
46ccb510 201 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
e3e65dac 202
46ccb510 203 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
b6af8d80 204
dc86cb34
RR
205 // implementation
206
e3e65dac
RR
207 void RegisterWindow(void);
208 void UnregisterWindow(void);
209
210 GtkWidget *m_widget;
211 wxWindow *m_window;
46ccb510 212 wxDragResult m_retValue;
e3e65dac
RR
213 wxDataObject *m_data;
214
215 wxCursor m_defaultCursor;
216 wxCursor m_goaheadCursor;
c801d85f
KB
217};
218
219#endif
220 //__GTKDNDH__
221