]> git.saurik.com Git - wxWidgets.git/blob - include/wx/clipbrd.h
Add wxUSE_RIBBON to wx/setup_inc.h and wx/chkconf.h.
[wxWidgets.git] / include / wx / clipbrd.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/clipbrd.h
3 // Purpose: wxClipboad class and clipboard functions
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 19.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets Team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CLIPBRD_H_BASE_
13 #define _WX_CLIPBRD_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_CLIPBOARD
18
19
20 #include "wx/event.h"
21 #include "wx/chartype.h"
22 #include "wx/dataobj.h" // for wxDataFormat
23 #include "wx/vector.h"
24
25 class WXDLLIMPEXP_FWD_CORE wxClipboard;
26
27 // ----------------------------------------------------------------------------
28 // wxClipboard represents the system clipboard. Normally, you should use
29 // wxTheClipboard which is a global pointer to the (unique) clipboard.
30 //
31 // Clipboard can be used to copy data to/paste data from. It works together
32 // with wxDataObject.
33 // ----------------------------------------------------------------------------
34
35 class WXDLLIMPEXP_CORE wxClipboardBase : public wxObject
36 {
37 public:
38 wxClipboardBase() { m_usePrimary = false; }
39
40 // open the clipboard before Add/SetData() and GetData()
41 virtual bool Open() = 0;
42
43 // close the clipboard after Add/SetData() and GetData()
44 virtual void Close() = 0;
45
46 // query whether the clipboard is opened
47 virtual bool IsOpened() const = 0;
48
49 // add to the clipboard data
50 //
51 // NB: the clipboard owns the pointer and will delete it, so data must be
52 // allocated on the heap
53 virtual bool AddData( wxDataObject *data ) = 0;
54
55 // set the clipboard data, this is the same as Clear() followed by
56 // AddData()
57 virtual bool SetData( wxDataObject *data ) = 0;
58
59 // ask if data in correct format is available
60 virtual bool IsSupported( const wxDataFormat& format ) = 0;
61
62 // ask if data in correct format is available
63 virtual bool IsSupportedAsync( wxEvtHandler *sink );
64
65 // fill data with data on the clipboard (if available)
66 virtual bool GetData( wxDataObject& data ) = 0;
67
68 // clears wxTheClipboard and the system's clipboard if possible
69 virtual void Clear() = 0;
70
71 // flushes the clipboard: this means that the data which is currently on
72 // clipboard will stay available even after the application exits (possibly
73 // eating memory), otherwise the clipboard will be emptied on exit
74 virtual bool Flush() { return false; }
75
76 // this allows to choose whether we work with CLIPBOARD (default) or
77 // PRIMARY selection on X11-based systems
78 //
79 // on the other ones, working with primary selection does nothing: this
80 // allows to write code which sets the primary selection when something is
81 // selected without any ill effects (i.e. without overwriting the
82 // clipboard which would be wrong on the platforms without X11 PRIMARY)
83 virtual void UsePrimarySelection(bool usePrimary = false)
84 {
85 m_usePrimary = usePrimary;
86 }
87
88 // return true if we're using primary selection
89 bool IsUsingPrimarySelection() const { return m_usePrimary; }
90
91 // Returns global instance (wxTheClipboard) of the object:
92 static wxClipboard *Get();
93
94
95 // don't use this directly, it is public for compatibility with some ports
96 // (wxX11, wxMotif, ...) only
97 bool m_usePrimary;
98 };
99
100 // ----------------------------------------------------------------------------
101 // asynchronous clipboard event
102 // ----------------------------------------------------------------------------
103
104 class WXDLLIMPEXP_CORE wxClipboardEvent : public wxEvent
105 {
106 public:
107 wxClipboardEvent(wxEventType evtType = wxEVT_NULL)
108 : wxEvent(0, evtType)
109 {
110 }
111
112 wxClipboardEvent(const wxClipboardEvent& event)
113 : wxEvent(event),
114 m_formats(event.m_formats)
115 {
116 }
117
118 bool SupportsFormat(const wxDataFormat& format) const;
119 void AddFormat(const wxDataFormat& format);
120
121 virtual wxEvent *Clone() const
122 {
123 return new wxClipboardEvent(*this);
124 }
125
126
127 protected:
128 wxVector<wxDataFormat> m_formats;
129
130 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxClipboardEvent)
131 };
132
133 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_CLIPBOARD_CHANGED, wxClipboardEvent );
134
135 typedef void (wxEvtHandler::*wxClipboardEventFunction)(wxClipboardEvent&);
136
137 #define wxClipboardEventHandler(func) \
138 wxEVENT_HANDLER_CAST(wxClipboardEventFunction, func)
139
140 #define EVT_CLIPBOARD_CHANGED(func) wx__DECLARE_EVT0(wxEVT_CLIPBOARD_CHANGED, wxClipboardEventHandler(func))
141
142 // ----------------------------------------------------------------------------
143 // globals
144 // ----------------------------------------------------------------------------
145
146 // The global clipboard object - backward compatible access macro:
147 #define wxTheClipboard (wxClipboard::Get())
148
149 // ----------------------------------------------------------------------------
150 // include platform-specific class declaration
151 // ----------------------------------------------------------------------------
152
153 #if defined(__WXMSW__)
154 #include "wx/msw/clipbrd.h"
155 #elif defined(__WXMOTIF__)
156 #include "wx/motif/clipbrd.h"
157 #elif defined(__WXGTK20__)
158 #include "wx/gtk/clipbrd.h"
159 #elif defined(__WXGTK__)
160 #include "wx/gtk1/clipbrd.h"
161 #elif defined(__WXX11__)
162 #include "wx/x11/clipbrd.h"
163 #elif defined(__WXMGL__)
164 #include "wx/mgl/clipbrd.h"
165 #elif defined(__WXMAC__)
166 #include "wx/osx/clipbrd.h"
167 #elif defined(__WXCOCOA__)
168 #include "wx/cocoa/clipbrd.h"
169 #elif defined(__WXPM__)
170 #include "wx/os2/clipbrd.h"
171 #endif
172
173 // ----------------------------------------------------------------------------
174 // helpful class for opening the clipboard and automatically closing it
175 // ----------------------------------------------------------------------------
176
177 class WXDLLIMPEXP_CORE wxClipboardLocker
178 {
179 public:
180 wxClipboardLocker(wxClipboard *clipboard = NULL)
181 {
182 m_clipboard = clipboard ? clipboard : wxTheClipboard;
183 if ( m_clipboard )
184 {
185 m_clipboard->Open();
186 }
187 }
188
189 bool operator!() const { return !m_clipboard->IsOpened(); }
190
191 ~wxClipboardLocker()
192 {
193 if ( m_clipboard )
194 {
195 m_clipboard->Close();
196 }
197 }
198
199 private:
200 wxClipboard *m_clipboard;
201
202 wxDECLARE_NO_COPY_CLASS(wxClipboardLocker);
203 };
204
205 #endif // wxUSE_CLIPBOARD
206
207 #endif // _WX_CLIPBRD_H_BASE_