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