1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxClipboad class and clipboard functions
4 // Author: Vadim Zeitlin
7 // Copyright: (c) wxWidgets Team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_CLIPBRD_H_BASE_
12 #define _WX_CLIPBRD_H_BASE_
20 #include "wx/chartype.h"
21 #include "wx/dataobj.h" // for wxDataFormat
22 #include "wx/vector.h"
24 class WXDLLIMPEXP_FWD_CORE wxClipboard
;
26 // ----------------------------------------------------------------------------
27 // wxClipboard represents the system clipboard. Normally, you should use
28 // wxTheClipboard which is a global pointer to the (unique) clipboard.
30 // Clipboard can be used to copy data to/paste data from. It works together
32 // ----------------------------------------------------------------------------
34 class WXDLLIMPEXP_CORE wxClipboardBase
: public wxObject
37 wxClipboardBase() { m_usePrimary
= false; }
39 // open the clipboard before Add/SetData() and GetData()
40 virtual bool Open() = 0;
42 // close the clipboard after Add/SetData() and GetData()
43 virtual void Close() = 0;
45 // query whether the clipboard is opened
46 virtual bool IsOpened() const = 0;
48 // add to the clipboard data
50 // NB: the clipboard owns the pointer and will delete it, so data must be
51 // allocated on the heap
52 virtual bool AddData( wxDataObject
*data
) = 0;
54 // set the clipboard data, this is the same as Clear() followed by
56 virtual bool SetData( wxDataObject
*data
) = 0;
58 // ask if data in correct format is available
59 virtual bool IsSupported( const wxDataFormat
& format
) = 0;
61 // ask if data in correct format is available
62 virtual bool IsSupportedAsync( wxEvtHandler
*sink
);
64 // fill data with data on the clipboard (if available)
65 virtual bool GetData( wxDataObject
& data
) = 0;
67 // clears wxTheClipboard and the system's clipboard if possible
68 virtual void Clear() = 0;
70 // flushes the clipboard: this means that the data which is currently on
71 // clipboard will stay available even after the application exits (possibly
72 // eating memory), otherwise the clipboard will be emptied on exit
73 virtual bool Flush() { return false; }
75 // this allows to choose whether we work with CLIPBOARD (default) or
76 // PRIMARY selection on X11-based systems
78 // on the other ones, working with primary selection does nothing: this
79 // allows to write code which sets the primary selection when something is
80 // selected without any ill effects (i.e. without overwriting the
81 // clipboard which would be wrong on the platforms without X11 PRIMARY)
82 virtual void UsePrimarySelection(bool usePrimary
= false)
84 m_usePrimary
= usePrimary
;
87 // return true if we're using primary selection
88 bool IsUsingPrimarySelection() const { return m_usePrimary
; }
90 // Returns global instance (wxTheClipboard) of the object:
91 static wxClipboard
*Get();
94 // don't use this directly, it is public for compatibility with some ports
95 // (wxX11, wxMotif, ...) only
99 // ----------------------------------------------------------------------------
100 // asynchronous clipboard event
101 // ----------------------------------------------------------------------------
103 class WXDLLIMPEXP_CORE wxClipboardEvent
: public wxEvent
106 wxClipboardEvent(wxEventType evtType
= wxEVT_NULL
)
107 : wxEvent(0, evtType
)
111 wxClipboardEvent(const wxClipboardEvent
& event
)
113 m_formats(event
.m_formats
)
117 bool SupportsFormat(const wxDataFormat
& format
) const;
118 void AddFormat(const wxDataFormat
& format
);
120 virtual wxEvent
*Clone() const
122 return new wxClipboardEvent(*this);
127 wxVector
<wxDataFormat
> m_formats
;
129 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxClipboardEvent
)
132 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_CLIPBOARD_CHANGED
, wxClipboardEvent
);
134 typedef void (wxEvtHandler::*wxClipboardEventFunction
)(wxClipboardEvent
&);
136 #define wxClipboardEventHandler(func) \
137 wxEVENT_HANDLER_CAST(wxClipboardEventFunction, func)
139 #define EVT_CLIPBOARD_CHANGED(func) wx__DECLARE_EVT0(wxEVT_CLIPBOARD_CHANGED, wxClipboardEventHandler(func))
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 // The global clipboard object - backward compatible access macro:
146 #define wxTheClipboard (wxClipboard::Get())
148 // ----------------------------------------------------------------------------
149 // include platform-specific class declaration
150 // ----------------------------------------------------------------------------
152 #if defined(__WXMSW__)
153 #include "wx/msw/clipbrd.h"
154 #elif defined(__WXMOTIF__)
155 #include "wx/motif/clipbrd.h"
156 #elif defined(__WXGTK20__)
157 #include "wx/gtk/clipbrd.h"
158 #elif defined(__WXGTK__)
159 #include "wx/gtk1/clipbrd.h"
160 #elif defined(__WXX11__)
161 #include "wx/x11/clipbrd.h"
162 #elif defined(__WXMAC__)
163 #include "wx/osx/clipbrd.h"
164 #elif defined(__WXCOCOA__)
165 #include "wx/cocoa/clipbrd.h"
166 #elif defined(__WXPM__)
167 #include "wx/os2/clipbrd.h"
170 // ----------------------------------------------------------------------------
171 // helpful class for opening the clipboard and automatically closing it
172 // ----------------------------------------------------------------------------
174 class WXDLLIMPEXP_CORE wxClipboardLocker
177 wxClipboardLocker(wxClipboard
*clipboard
= NULL
)
179 m_clipboard
= clipboard
? clipboard
: wxTheClipboard
;
186 bool operator!() const { return !m_clipboard
->IsOpened(); }
192 m_clipboard
->Close();
197 wxClipboard
*m_clipboard
;
199 wxDECLARE_NO_COPY_CLASS(wxClipboardLocker
);
202 #endif // wxUSE_CLIPBOARD
204 #endif // _WX_CLIPBRD_H_BASE_