]>
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 //-------------------------------------------------------------------------
24 // conditional compilation
25 //-------------------------------------------------------------------------
27 #if (GTK_MINOR_VERSION == 1)
28 #if (GTK_MICRO_VERSION >= 3)
29 #define NEW_GTK_DND_CODE
33 //-------------------------------------------------------------------------
35 //-------------------------------------------------------------------------
40 class wxTextDataObject
;
41 class wxFileDataObject
;
44 class wxTextDropTarget
;
45 class wxFileDropTarget
;
49 //-------------------------------------------------------------------------
51 //-------------------------------------------------------------------------
53 class wxDataObject
: public wxObject
60 virtual wxDataFormat
GetPreferredFormat() const = 0;
61 virtual bool IsSupportedFormat( wxDataFormat format
) const = 0;
62 virtual size_t GetDataSize() const = 0;
63 virtual void GetDataHere( void *data
) const = 0;
67 // ----------------------------------------------------------------------------
68 // wxTextDataObject is a specialization of wxDataObject for text data
69 // ----------------------------------------------------------------------------
71 class wxTextDataObject
: public wxDataObject
75 wxTextDataObject() { }
76 wxTextDataObject(const wxString
& strText
) : m_strText(strText
) { }
77 void Init(const wxString
& strText
) { m_strText
= strText
; }
79 virtual wxDataFormat
GetPreferredFormat() const
82 virtual bool IsSupportedFormat(wxDataFormat format
) const
83 { return format
== wxDF_TEXT
; }
85 virtual size_t GetDataSize() const
86 { return m_strText
.Len() + 1; } // +1 for trailing '\0'
88 virtual void GetDataHere( void *data
) const
89 { memcpy(data
, m_strText
.c_str(), GetDataSize()); }
96 // ----------------------------------------------------------------------------
97 // wxFileDataObject is a specialization of wxDataObject for file names
98 // ----------------------------------------------------------------------------
100 class wxFileDataObject
: public wxDataObject
104 wxFileDataObject(void) { }
105 void AddFile( const wxString
&file
)
106 { m_files
+= file
; m_files
+= '\0'; }
108 virtual wxDataFormat
GetPreferredFormat() const
109 { return wxDF_FILENAME
; }
111 virtual bool IsSupportedFormat( wxDataFormat format
) const
112 { return format
== wxDF_FILENAME
; }
114 virtual size_t GetDataSize() const
115 { return m_files
.Len(); } // no trailing '\0'
117 virtual void GetDataHere( void *data
) const
118 { memcpy(data
, m_files
.c_str(), GetDataSize()); }
124 //-------------------------------------------------------------------------
126 //-------------------------------------------------------------------------
128 class wxDropTarget
: public wxObject
135 virtual void OnEnter() { }
136 virtual void OnLeave() { }
137 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
) = 0;
139 // Override these to indicate what kind of data you support:
141 virtual size_t GetFormatCount() const = 0;
142 virtual wxDataFormat
GetFormat(size_t n
) const = 0;
146 void RegisterWidget( GtkWidget
*widget
);
147 void UnregisterWidget( GtkWidget
*widget
);
150 //-------------------------------------------------------------------------
152 //-------------------------------------------------------------------------
154 class wxTextDropTarget
: public wxDropTarget
158 wxTextDropTarget() {};
159 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
);
160 virtual bool OnDropText( long x
, long y
, const char *psz
);
164 virtual size_t GetFormatCount() const;
165 virtual wxDataFormat
GetFormat(size_t n
) const;
168 // ----------------------------------------------------------------------------
169 // A drop target which accepts files (dragged from File Manager or Explorer)
170 // ----------------------------------------------------------------------------
172 class wxFileDropTarget
: public wxDropTarget
176 wxFileDropTarget() {};
178 virtual bool OnDrop( long x
, long y
, const void *data
, size_t size
);
179 virtual bool OnDropFiles( long x
, long y
,
180 size_t nFiles
, const char * const aszFiles
[] );
184 virtual size_t GetFormatCount() const;
185 virtual wxDataFormat
GetFormat(size_t n
) const;
188 //-------------------------------------------------------------------------
190 //-------------------------------------------------------------------------
194 wxDragError
, // error prevented the d&d operation from completing
195 wxDragNone
, // drag target didn't accept the data
196 wxDragCopy
, // the data was successfully copied
197 wxDragMove
, // the data was successfully moved
198 wxDragCancel
// the operation was cancelled by user (not an error)
201 class wxDropSource
: public wxObject
205 wxDropSource( wxWindow
*win
);
206 wxDropSource( wxDataObject
&data
, wxWindow
*win
);
210 void SetData( wxDataObject
&data
);
211 wxDragResult
DoDragDrop( bool bAllowMove
= FALSE
);
213 virtual bool GiveFeedback( wxDragResult
WXUNUSED(effect
), bool WXUNUSED(bScrolling
) ) { return TRUE
; };
217 void RegisterWindow(void);
218 void UnregisterWindow(void);
222 wxDragResult m_retValue
;
223 wxDataObject
*m_data
;
225 wxCursor m_defaultCursor
;
226 wxCursor m_goaheadCursor
;