]>
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
50 virtual wxDataFormat
GetPreferredFormat() const = 0;
51 virtual bool IsSupportedFormat( wxDataFormat format
) const = 0;
52 virtual size_t GetDataSize() const = 0;
53 virtual void GetDataHere( void *data
) const = 0;
57 // ----------------------------------------------------------------------------
58 // wxTextDataObject is a specialization of wxDataObject for text data
59 // ----------------------------------------------------------------------------
61 class wxTextDataObject
: public wxDataObject
65 wxTextDataObject() { }
66 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
67 void Init(const wxString
& strText
) { m_strText
= strText
; }
69 virtual wxDataFormat
GetPreferredFormat() const
72 virtual bool IsSupportedFormat(wxDataFormat format
) const
73 { return format
== wxDF_TEXT
; }
75 virtual size_t GetDataSize() const
76 { return m_strText
.Len() + 1; } // +1 for trailing '\0'
78 virtual void GetDataHere( void *data
) const
79 { memcpy(data
, m_strText
.c_str(), GetDataSize()); }
86 // ----------------------------------------------------------------------------
87 // wxFileDataObject is a specialization of wxDataObject for file names
88 // ----------------------------------------------------------------------------
90 class wxFileDataObject
: public wxDataObject
94 wxFileDataObject(void) { }
95 void AddFile( const wxString
&file
)
96 { m_files
+= file
; m_files
+= '\0'; }
98 virtual wxDataFormat
GetPreferredFormat() const
99 { return wxDF_FILENAME
; }
101 virtual bool IsSupportedFormat( wxDataFormat format
) const
102 { return format
== wxDF_FILENAME
; }
104 virtual size_t GetDataSize() const
105 { return m_files
.Len(); } // no trailing '\0'
107 virtual void GetDataHere( void *data
) const
108 { memcpy(data
, m_files
.c_str(), GetDataSize()); }
114 //-------------------------------------------------------------------------
116 //-------------------------------------------------------------------------
118 class wxDropTarget
: public wxObject
125 virtual void OnEnter() { }
126 virtual void OnLeave() { }
127 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
) = 0;
129 // Override these to indicate what kind of data you support:
131 virtual size_t GetFormatCount() const = 0;
132 virtual wxDataFormat
GetFormat(size_t n
) const = 0;
136 void RegisterWidget( GtkWidget
*widget
);
137 void UnregisterWidget( GtkWidget
*widget
);
140 //-------------------------------------------------------------------------
142 //-------------------------------------------------------------------------
144 class wxTextDropTarget
: public wxDropTarget
148 wxTextDropTarget() {};
149 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
);
150 virtual bool OnDropText( long x
, long y
, const char *psz
);
154 virtual size_t GetFormatCount() const;
155 virtual wxDataFormat
GetFormat(size_t n
) const;
158 // ----------------------------------------------------------------------------
159 // A drop target which accepts files (dragged from File Manager or Explorer)
160 // ----------------------------------------------------------------------------
162 class wxFileDropTarget
: public wxDropTarget
166 wxFileDropTarget() {};
168 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
);
169 virtual bool OnDropFiles( long x
, long y
,
170 size_t nFiles
, const char * const aszFiles
[] );
174 virtual size_t GetFormatCount() const;
175 virtual wxDataFormat
GetFormat(size_t n
) const;
178 //-------------------------------------------------------------------------
180 //-------------------------------------------------------------------------
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)
191 class wxDropSource
: public wxObject
195 wxDropSource( wxWindow
*win
);
196 wxDropSource( wxDataObject
&data
, wxWindow
*win
);
200 void SetData( wxDataObject
&data
);
201 wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
203 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; };
207 void RegisterWindow(void);
208 void UnregisterWindow(void);
212 wxDragResult m_retValue
;
213 wxDataObject
*m_data
;
215 wxCursor m_defaultCursor
;
216 wxCursor m_goaheadCursor
;