1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of the wxDropTarget class
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling
7 // Licence: wxWindows license
8 ///////////////////////////////////////////////////////////////////////////////
19 #include "wx/object.h"
20 #include "wx/string.h"
21 #include "wx/cursor.h"
23 //-------------------------------------------------------------------------
25 //-------------------------------------------------------------------------
30 class wxTextDataObject
;
31 class wxFileDataObject
;
34 class wxTextDropTarget
;
35 class wxFileDropTarget
;
39 //-------------------------------------------------------------------------
41 //-------------------------------------------------------------------------
43 class wxDataObject
: public wxObject
46 // all data formats (values are the same as in windows.h, do not change!)
69 // function to return symbolic name of clipboard format (debug messages)
70 static const char *GetFormatName(wxDataFormat format
);
76 // pure virtuals to override
77 // get the best suited format for our data
78 virtual wxDataFormat
GetPreferredFormat() const = 0;
79 // decide if we support this format (should be one of values of
80 // StdFormat enumerations or a user-defined format)
81 virtual bool IsSupportedFormat(wxDataFormat format
) const = 0;
82 // get the (total) size of data
83 virtual size_t GetDataSize() const = 0;
84 // copy raw data to provided pointer
85 virtual void GetDataHere(void *pBuf
) const = 0;
89 // ----------------------------------------------------------------------------
90 // wxTextDataObject is a specialization of wxDataObject for text data
91 // ----------------------------------------------------------------------------
93 class wxTextDataObject
: public wxDataObject
97 wxTextDataObject() { }
98 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
99 void Init(const wxString
& strText
) { m_strText
= strText
; }
101 // implement base class pure virtuals
102 virtual wxDataFormat
GetPreferredFormat() const
103 { return wxDF_TEXT
; }
104 virtual bool IsSupportedFormat(wxDataFormat format
) const
105 { return format
== wxDF_TEXT
; }
106 virtual size_t GetDataSize() const
107 { return m_strText
.Len() + 1; } // +1 for trailing '\0'of course
108 virtual void GetDataHere(void *pBuf
) const
109 { memcpy(pBuf
, m_strText
.c_str(), GetDataSize()); }
116 // ----------------------------------------------------------------------------
117 // wxFileDataObject is a specialization of wxDataObject for file names
118 // ----------------------------------------------------------------------------
120 class wxFileDataObject
: public wxDataObject
124 wxFileDataObject(void) { }
125 void AddFile( const wxString
&file
)
126 { m_files
+= file
; m_files
+= '\0'; }
128 // implement base class pure virtuals
129 virtual wxDataFormat
GetPreferredFormat() const
130 { return wxDF_FILENAME
; }
131 virtual bool IsSupportedFormat(wxDataFormat format
) const
132 { return format
== wxDF_FILENAME
; }
133 virtual size_t GetDataSize() const
134 { return m_files
.Len(); } // no trailing '\0'
135 virtual void GetDataHere(void *pBuf
) const
136 { memcpy(pBuf
, m_files
.c_str(), GetDataSize()); }
142 //-------------------------------------------------------------------------
144 //-------------------------------------------------------------------------
146 class wxDropTarget
: public wxObject
153 virtual void OnEnter() { }
154 virtual void OnLeave() { }
155 virtual bool OnDrop( long x
, long y
, const void *pData
) = 0;
161 // Override these to indicate what kind of data you support:
163 virtual size_t GetFormatCount() const = 0;
164 virtual wxDataFormat
GetFormat(size_t n
) const = 0;
166 void Drop( GdkEventDropDataAvailable
*event
, int x
, int y
);
167 void RegisterWidget( GtkWidget
*widget
);
168 void UnregisterWidget( GtkWidget
*widget
);
171 //-------------------------------------------------------------------------
173 //-------------------------------------------------------------------------
175 class wxTextDropTarget
: public wxDropTarget
179 wxTextDropTarget() {};
180 virtual bool OnDrop( long x
, long y
, const void *pData
);
181 virtual bool OnDropText( long x
, long y
, const char *psz
);
185 virtual size_t GetFormatCount() const;
186 virtual wxDataFormat
GetFormat(size_t n
) const;
189 // ----------------------------------------------------------------------------
190 // A drop target which accepts files (dragged from File Manager or Explorer)
191 // ----------------------------------------------------------------------------
193 class wxFileDropTarget
: public wxDropTarget
197 wxFileDropTarget() {};
199 virtual bool OnDrop(long x
, long y
, const void *pData
);
200 virtual bool OnDropFiles( long x
, long y
,
201 size_t nFiles
, const char * const aszFiles
[]);
205 virtual size_t GetFormatCount() const;
206 virtual wxDataFormat
GetFormat(size_t n
) const;
209 //-------------------------------------------------------------------------
211 //-------------------------------------------------------------------------
215 wxDragError
, // error prevented the d&d operation from completing
216 wxDragNone
, // drag target didn't accept the data
217 wxDragCopy
, // the data was successfully copied
218 wxDragMove
, // the data was successfully moved
219 wxDragCancel
// the operation was cancelled by user (not an error)
222 class wxDropSource
: public wxObject
226 wxDropSource( wxWindow
*win
);
227 wxDropSource( wxDataObject
&data
, wxWindow
*win
);
231 void SetData( wxDataObject
&data
);
232 wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
234 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; };
238 friend void gtk_drag_callback( GtkWidget
*widget
, GdkEvent
*event
, wxDropSource
*source
);
240 void RegisterWindow(void);
241 void UnregisterWindow(void);
245 wxDragResult m_retValue
;
246 wxDataObject
*m_data
;
248 wxCursor m_defaultCursor
;
249 wxCursor m_goaheadCursor
;