]> git.saurik.com Git - wxWidgets.git/blame - include/wx/stubs/dnd.h
fixed wxBITMAP for Motif
[wxWidgets.git] / include / wx / stubs / dnd.h
CommitLineData
34138703
JS
1///////////////////////////////////////////////////////////////////////////////
2// Name: dnd.h
3// Purpose: Declaration of the wxDropTarget, wxDropSource class etc.
4// Author: AUTHOR
5// RCS-ID: $Id$
6// Copyright: (c) 1998 AUTHOR
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_DND_H_
11#define _WX_DND_H_
12
13#ifdef __GNUG__
14#pragma interface "dnd.h"
15#endif
16
17#include "wx/defs.h"
18#include "wx/object.h"
19#include "wx/string.h"
20#include "wx/cursor.h"
21
22//-------------------------------------------------------------------------
23// classes
24//-------------------------------------------------------------------------
25
26class WXDLLEXPORT wxWindow;
27
28class WXDLLEXPORT wxDataObject;
29class WXDLLEXPORT wxTextDataObject;
30class WXDLLEXPORT wxFileDataObject;
31
32class WXDLLEXPORT wxDropTarget;
33class WXDLLEXPORT wxTextDropTarget;
34class WXDLLEXPORT wxFileDropTarget;
35
36class WXDLLEXPORT wxDropSource;
37
38//-------------------------------------------------------------------------
39// wxDataObject
40//-------------------------------------------------------------------------
41
42class WXDLLEXPORT wxDataObject: public wxObject
43{
44public:
45 // all data formats (values are the same as in windows.h, do not change!)
46 enum StdFormat
47 {
48 Invalid,
49 Text,
50 Bitmap,
51 MetafilePict,
52 Sylk,
53 Dif,
54 Tiff,
55 OemText,
56 Dib,
57 Palette,
58 Pendata,
59 Riff,
60 Wave,
61 UnicodeText,
62 EnhMetafile,
63 Hdrop,
64 Locale,
65 Max
66 };
67
68 // function to return symbolic name of clipboard format (debug messages)
69 static const char *GetFormatName(wxDataFormat format);
70
71 // ctor & dtor
72 wxDataObject() {};
73 ~wxDataObject() {};
74
75 // pure virtuals to override
76 // get the best suited format for our data
77 virtual wxDataFormat GetPreferredFormat() const = 0;
78 // decide if we support this format (should be one of values of
79 // StdFormat enumerations or a user-defined format)
80 virtual bool IsSupportedFormat(wxDataFormat format) const = 0;
81 // get the (total) size of data
c86f1403 82 virtual size_t GetDataSize() const = 0;
34138703
JS
83 // copy raw data to provided pointer
84 virtual void GetDataHere(void *pBuf) const = 0;
85
86};
87
88// ----------------------------------------------------------------------------
89// wxTextDataObject is a specialization of wxDataObject for text data
90// ----------------------------------------------------------------------------
91
92class WXDLLEXPORT wxTextDataObject : public wxDataObject
93{
94public:
95 // ctors
96 wxTextDataObject() { }
97 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
98 void Init(const wxString& strText) { m_strText = strText; }
99
100 // implement base class pure virtuals
101 virtual wxDataFormat GetPreferredFormat() const
102 { return wxDF_TEXT; }
103 virtual bool IsSupportedFormat(wxDataFormat format) const
104 { return format == wxDF_TEXT; }
c86f1403 105 virtual size_t GetDataSize() const
34138703
JS
106 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
107 virtual void GetDataHere(void *pBuf) const
108 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
109
110private:
111 wxString m_strText;
112
113};
114
115// ----------------------------------------------------------------------------
116// wxFileDataObject is a specialization of wxDataObject for file names
117// ----------------------------------------------------------------------------
118
119class WXDLLEXPORT wxFileDataObject : public wxDataObject
120{
121public:
122
123 wxFileDataObject(void) { }
124 void AddFile( const wxString &file )
125 { m_files += file; m_files += ";"; }
126
127 // implement base class pure virtuals
128 virtual wxDataFormat GetPreferredFormat() const
129 { return wxDF_FILENAME; }
130 virtual bool IsSupportedFormat(wxDataFormat format) const
131 { return format == wxDF_FILENAME; }
c86f1403 132 virtual size_t GetDataSize() const
34138703
JS
133 { return m_files.Len() + 1; } // +1 for trailing '\0'of course
134 virtual void GetDataHere(void *pBuf) const
135 { memcpy(pBuf, m_files.c_str(), GetDataSize()); }
136
137private:
138 wxString m_files;
139
140};
141//-------------------------------------------------------------------------
142// wxDropTarget
143//-------------------------------------------------------------------------
144
145class WXDLLEXPORT wxDropTarget: public wxObject
146{
147 public:
148
149 wxDropTarget();
150 ~wxDropTarget();
151
152 virtual void OnEnter() { }
153 virtual void OnLeave() { }
154 virtual bool OnDrop( long x, long y, const void *pData ) = 0;
155
156// protected:
157
158 friend wxWindow;
159
160 // Override these to indicate what kind of data you support:
161
162 virtual size_t GetFormatCount() const = 0;
163 virtual wxDataFormat GetFormat(size_t n) const = 0;
164};
165
166//-------------------------------------------------------------------------
167// wxTextDropTarget
168//-------------------------------------------------------------------------
169
170class WXDLLEXPORT wxTextDropTarget: public wxDropTarget
171{
172 public:
173
174 wxTextDropTarget() {};
175 virtual bool OnDrop( long x, long y, const void *pData );
176 virtual bool OnDropText( long x, long y, const char *psz );
177
178 protected:
179
180 virtual size_t GetFormatCount() const;
181 virtual wxDataFormat GetFormat(size_t n) const;
182};
183
184// ----------------------------------------------------------------------------
185// A drop target which accepts files (dragged from File Manager or Explorer)
186// ----------------------------------------------------------------------------
187
188class WXDLLEXPORT wxFileDropTarget: public wxDropTarget
189{
190 public:
191
192 wxFileDropTarget() {};
193
194 virtual bool OnDrop(long x, long y, const void *pData);
195 virtual bool OnDropFiles( long x, long y,
196 size_t nFiles, const char * const aszFiles[]);
197
198 protected:
199
200 virtual size_t GetFormatCount() const;
201 virtual wxDataFormat GetFormat(size_t n) const;
202};
203
204//-------------------------------------------------------------------------
205// wxDropSource
206//-------------------------------------------------------------------------
207
46ccb510
JS
208enum wxDragResult
209 {
210 wxDragError, // error prevented the d&d operation from completing
211 wxDragNone, // drag target didn't accept the data
212 wxDragCopy, // the data was successfully copied
213 wxDragMove, // the data was successfully moved
214 wxDragCancel // the operation was cancelled by user (not an error)
215 };
216
34138703
JS
217class WXDLLEXPORT wxDropSource: public wxObject
218{
219 public:
220
34138703
JS
221 wxDropSource( wxWindow *win );
222 wxDropSource( wxDataObject &data, wxWindow *win );
223
224 ~wxDropSource(void);
225
226 void SetData( wxDataObject &data );
46ccb510 227 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
34138703 228
46ccb510 229 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
34138703
JS
230
231 protected:
232
233 wxDataObject *m_data;
234};
235
236#endif
237 //_WX_DND_H_
238