]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/dnd.h
A fix for attribrute sorting, but it's still broken if there are
[wxWidgets.git] / include / wx / mac / dnd.h
CommitLineData
0dbd6262
SC
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
6e040042 28#ifndef __DARWIN__
0dbd6262
SC
29class WXDLLEXPORT wxDataObject;
30class WXDLLEXPORT wxTextDataObject;
31class WXDLLEXPORT wxFileDataObject;
03e11df5 32#endif
0dbd6262
SC
33
34class WXDLLEXPORT wxDropTarget;
35class WXDLLEXPORT wxTextDropTarget;
36class WXDLLEXPORT wxFileDropTarget;
37
38class WXDLLEXPORT wxDropSource;
39
6e040042 40#ifndef __DARWIN__
0dbd6262
SC
41//-------------------------------------------------------------------------
42// wxDataObject
43//-------------------------------------------------------------------------
44
03e11df5 45class WXDLLEXPORT wxDataObject : public wxObject
0dbd6262
SC
46{
47public:
48 // all data formats (values are the same as in windows.h, do not change!)
49 enum StdFormat
50 {
51 Invalid,
52 Text,
53 Bitmap,
54 MetafilePict,
55 Sylk,
56 Dif,
57 Tiff,
58 OemText,
59 Dib,
60 Palette,
61 Pendata,
62 Riff,
63 Wave,
64 UnicodeText,
65 EnhMetafile,
66 Hdrop,
67 Locale,
68 Max
69 };
70
71 // function to return symbolic name of clipboard format (debug messages)
72 static const char *GetFormatName(wxDataFormat format);
73
74 // ctor & dtor
75 wxDataObject() {};
76 ~wxDataObject() {};
77
78 // pure virtuals to override
79 // get the best suited format for our data
80 virtual wxDataFormat GetPreferredFormat() const = 0;
81 // decide if we support this format (should be one of values of
82 // StdFormat enumerations or a user-defined format)
83 virtual bool IsSupportedFormat(wxDataFormat format) const = 0;
84 // get the (total) size of data
85 virtual size_t GetDataSize() const = 0;
86 // copy raw data to provided pointer
87 virtual void GetDataHere(void *pBuf) const = 0;
88
89};
90
91// ----------------------------------------------------------------------------
92// wxTextDataObject is a specialization of wxDataObject for text data
93// ----------------------------------------------------------------------------
94
95class WXDLLEXPORT wxTextDataObject : public wxDataObject
96{
97public:
98 // ctors
99 wxTextDataObject() { }
100 wxTextDataObject(const wxString& strText) : m_strText(strText) { }
101 void Init(const wxString& strText) { m_strText = strText; }
102
103 // implement base class pure virtuals
104 virtual wxDataFormat GetPreferredFormat() const
105 { return wxDF_TEXT; }
106 virtual bool IsSupportedFormat(wxDataFormat format) const
107 { return format == wxDF_TEXT; }
108 virtual size_t GetDataSize() const
109 { return m_strText.Len() + 1; } // +1 for trailing '\0'of course
110 virtual void GetDataHere(void *pBuf) const
111 { memcpy(pBuf, m_strText.c_str(), GetDataSize()); }
112
113private:
114 wxString m_strText;
115
116};
117
118// ----------------------------------------------------------------------------
119// wxFileDataObject is a specialization of wxDataObject for file names
120// ----------------------------------------------------------------------------
121
122class WXDLLEXPORT wxFileDataObject : public wxDataObject
123{
124public:
125
126 wxFileDataObject(void) { }
127 void AddFile( const wxString &file )
128 { m_files += file; m_files += ";"; }
129
130 // implement base class pure virtuals
131 virtual wxDataFormat GetPreferredFormat() const
132 { return wxDF_FILENAME; }
133 virtual bool IsSupportedFormat(wxDataFormat format) const
134 { return format == wxDF_FILENAME; }
135 virtual size_t GetDataSize() const
136 { return m_files.Len() + 1; } // +1 for trailing '\0'of course
137 virtual void GetDataHere(void *pBuf) const
138 { memcpy(pBuf, m_files.c_str(), GetDataSize()); }
139
140private:
141 wxString m_files;
142
143};
03e11df5
GD
144#endif
145
0dbd6262
SC
146//-------------------------------------------------------------------------
147// wxDropTarget
148//-------------------------------------------------------------------------
149
150class WXDLLEXPORT wxDropTarget: public wxObject
151{
152 public:
153
154 wxDropTarget();
155 ~wxDropTarget();
156
157 virtual void OnEnter() { }
158 virtual void OnLeave() { }
5fde6fcc 159 virtual bool OnDrop( wxCoord x, wxCoord y, const void *pData ) = 0;
0dbd6262
SC
160
161// protected:
162
519cb848 163 friend class wxWindow;
0dbd6262
SC
164
165 // Override these to indicate what kind of data you support:
166
167 virtual size_t GetFormatCount() const = 0;
168 virtual wxDataFormat GetFormat(size_t n) const = 0;
169};
170
6e040042 171#ifndef __DARWIN__
0dbd6262
SC
172//-------------------------------------------------------------------------
173// wxTextDropTarget
174//-------------------------------------------------------------------------
175
176class WXDLLEXPORT wxTextDropTarget: public wxDropTarget
177{
178 public:
179
180 wxTextDropTarget() {};
5fde6fcc
GD
181 virtual bool OnDrop( wxCoord x, wxCoord y, const void *pData );
182 virtual bool OnDropText( wxCoord x, wxCoord y, const char *psz );
0dbd6262
SC
183
184 protected:
185
186 virtual size_t GetFormatCount() const;
187 virtual wxDataFormat GetFormat(size_t n) const;
188};
189
190// ----------------------------------------------------------------------------
191// A drop target which accepts files (dragged from File Manager or Explorer)
192// ----------------------------------------------------------------------------
193
194class WXDLLEXPORT wxFileDropTarget: public wxDropTarget
195{
196 public:
197
198 wxFileDropTarget() {};
199
5fde6fcc
GD
200 virtual bool OnDrop(wxCoord x, wxCoord y, const void *pData);
201 virtual bool OnDropFiles( wxCoord x, wxCoord y,
0dbd6262
SC
202 size_t nFiles, const char * const aszFiles[]);
203
204 protected:
205
206 virtual size_t GetFormatCount() const;
207 virtual wxDataFormat GetFormat(size_t n) const;
208};
03e11df5 209#endif
0dbd6262
SC
210
211//-------------------------------------------------------------------------
212// wxDropSource
213//-------------------------------------------------------------------------
214
0dbd6262
SC
215class WXDLLEXPORT wxDropSource: public wxObject
216{
217 public:
218
219 wxDropSource( wxWindow *win );
220 wxDropSource( wxDataObject &data, wxWindow *win );
221
222 ~wxDropSource(void);
223
224 void SetData( wxDataObject &data );
225 wxDragResult DoDragDrop( bool bAllowMove = FALSE );
226
227 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; };
228
229 protected:
230
231 wxDataObject *m_data;
232};
233
234#endif
235 //_WX_DND_H_
236