]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dnd.h
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 uint
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 uint
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
+= ";"; }
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 uint
GetDataSize() const
134 { return m_files
.Len() + 1; } // +1 for trailing '\0'of course
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( GdkEvent
*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 //-------------------------------------------------------------------------
213 class wxDropSource
: public wxObject
219 Error
, // error prevented the d&d operation from completing
220 None
, // drag target didn't accept the data
221 Copy
, // the data was successfully copied
222 Move
, // the data was successfully moved
223 Cancel
// the operation was cancelled by user (not an error)
226 wxDropSource( wxWindow
*win
);
227 wxDropSource( wxDataObject
&data
, wxWindow
*win
);
231 void SetData( wxDataObject
&data
);
232 DragResult
DoDragDrop( bool bAllowMove
= FALSE
);
234 virtual bool GiveFeedback( DragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; };
238 void RegisterWindow(void);
239 void UnregisterWindow(void);
244 wxDataObject
*m_data
;
246 wxCursor m_defaultCursor
;
247 wxCursor m_goaheadCursor
;