]> git.saurik.com Git - wxWidgets.git/blob - include/wx/clipbrd.h
using Run of base class
[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 // Copyright: (c) wxWidgets Team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_CLIPBRD_H_BASE_
12 #define _WX_CLIPBRD_H_BASE_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_CLIPBOARD
17
18
19 #include "wx/event.h"
20 #include "wx/chartype.h"
21 #include "wx/dataobj.h" // for wxDataFormat
22 #include "wx/vector.h"
23
24 class WXDLLIMPEXP_FWD_CORE wxClipboard;
25
26 // ----------------------------------------------------------------------------
27 // wxClipboard represents the system clipboard. Normally, you should use
28 // wxTheClipboard which is a global pointer to the (unique) clipboard.
29 //
30 // Clipboard can be used to copy data to/paste data from. It works together
31 // with wxDataObject.
32 // ----------------------------------------------------------------------------
33
34 class WXDLLIMPEXP_CORE wxClipboardBase : public wxObject
35 {
36 public:
37 wxClipboardBase() { m_usePrimary = false; }
38
39 // open the clipboard before Add/SetData() and GetData()
40 virtual bool Open() = 0;
41
42 // close the clipboard after Add/SetData() and GetData()
43 virtual void Close() = 0;
44
45 // query whether the clipboard is opened
46 virtual bool IsOpened() const = 0;
47
48 // add to the clipboard data
49 //
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;
53
54 // set the clipboard data, this is the same as Clear() followed by
55 // AddData()
56 virtual bool SetData( wxDataObject *data ) = 0;
57
58 // ask if data in correct format is available
59 virtual bool IsSupported( const wxDataFormat& format ) = 0;
60
61 // ask if data in correct format is available
62 virtual bool IsSupportedAsync( wxEvtHandler *sink );
63
64 // fill data with data on the clipboard (if available)
65 virtual bool GetData( wxDataObject& data ) = 0;
66
67 // clears wxTheClipboard and the system's clipboard if possible
68 virtual void Clear() = 0;
69
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; }
74
75 // this allows to choose whether we work with CLIPBOARD (default) or
76 // PRIMARY selection on X11-based systems
77 //
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)
83 {
84 m_usePrimary = usePrimary;
85 }
86
87 // return true if we're using primary selection
88 bool IsUsingPrimarySelection() const { return m_usePrimary; }
89
90 // Returns global instance (wxTheClipboard) of the object:
91 static wxClipboard *Get();
92
93
94 // don't use this directly, it is public for compatibility with some ports
95 // (wxX11, wxMotif, ...) only
96 bool m_usePrimary;
97 };
98
99 // ----------------------------------------------------------------------------
100 // asynchronous clipboard event
101 // ----------------------------------------------------------------------------
102
103 class WXDLLIMPEXP_CORE wxClipboardEvent : public wxEvent
104 {
105 public:
106 wxClipboardEvent(wxEventType evtType = wxEVT_NULL)
107 : wxEvent(0, evtType)
108 {
109 }
110
111 wxClipboardEvent(const wxClipboardEvent& event)
112 : wxEvent(event),
113 m_formats(event.m_formats)
114 {
115 }
116
117 bool SupportsFormat(const wxDataFormat& format) const;
118 void AddFormat(const wxDataFormat& format);
119
120 virtual wxEvent *Clone() const
121 {
122 return new wxClipboardEvent(*this);
123 }
124
125
126 protected:
127 wxVector<wxDataFormat> m_formats;
128
129 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxClipboardEvent)
130 };
131
132 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_CLIPBOARD_CHANGED, wxClipboardEvent );
133
134 typedef void (wxEvtHandler::*wxClipboardEventFunction)(wxClipboardEvent&);
135
136 #define wxClipboardEventHandler(func) \
137 wxEVENT_HANDLER_CAST(wxClipboardEventFunction, func)
138
139 #define EVT_CLIPBOARD_CHANGED(func) wx__DECLARE_EVT0(wxEVT_CLIPBOARD_CHANGED, wxClipboardEventHandler(func))
140
141 // ----------------------------------------------------------------------------
142 // globals
143 // ----------------------------------------------------------------------------
144
145 // The global clipboard object - backward compatible access macro:
146 #define wxTheClipboard (wxClipboard::Get())
147
148 // ----------------------------------------------------------------------------
149 // include platform-specific class declaration
150 // ----------------------------------------------------------------------------
151
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"
168 #endif
169
170 // ----------------------------------------------------------------------------
171 // helpful class for opening the clipboard and automatically closing it
172 // ----------------------------------------------------------------------------
173
174 class WXDLLIMPEXP_CORE wxClipboardLocker
175 {
176 public:
177 wxClipboardLocker(wxClipboard *clipboard = NULL)
178 {
179 m_clipboard = clipboard ? clipboard : wxTheClipboard;
180 if ( m_clipboard )
181 {
182 m_clipboard->Open();
183 }
184 }
185
186 bool operator!() const { return !m_clipboard->IsOpened(); }
187
188 ~wxClipboardLocker()
189 {
190 if ( m_clipboard )
191 {
192 m_clipboard->Close();
193 }
194 }
195
196 private:
197 wxClipboard *m_clipboard;
198
199 wxDECLARE_NO_COPY_CLASS(wxClipboardLocker);
200 };
201
202 #endif // wxUSE_CLIPBOARD
203
204 #endif // _WX_CLIPBRD_H_BASE_