]>
Commit | Line | Data |
---|---|---|
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/vector.h" | |
23 | ||
24 | class WXDLLIMPEXP_FWD_CORE wxDataFormat; | |
25 | class WXDLLIMPEXP_FWD_CORE wxDataObject; | |
26 | class WXDLLIMPEXP_FWD_CORE wxClipboard; | |
27 | ||
28 | // ---------------------------------------------------------------------------- | |
29 | // wxClipboard represents the system clipboard. Normally, you should use | |
30 | // wxTheClipboard which is a global pointer to the (unique) clipboard. | |
31 | // | |
32 | // Clipboard can be used to copy data to/paste data from. It works together | |
33 | // with wxDataObject. | |
34 | // ---------------------------------------------------------------------------- | |
35 | ||
36 | class WXDLLIMPEXP_CORE wxClipboardBase : public wxObject | |
37 | { | |
38 | public: | |
39 | wxClipboardBase() { m_usePrimary = false; } | |
40 | ||
41 | // open the clipboard before Add/SetData() and GetData() | |
42 | virtual bool Open() = 0; | |
43 | ||
44 | // close the clipboard after Add/SetData() and GetData() | |
45 | virtual void Close() = 0; | |
46 | ||
47 | // query whether the clipboard is opened | |
48 | virtual bool IsOpened() const = 0; | |
49 | ||
50 | // add to the clipboard data | |
51 | // | |
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; | |
55 | ||
56 | // set the clipboard data, this is the same as Clear() followed by | |
57 | // AddData() | |
58 | virtual bool SetData( wxDataObject *data ) = 0; | |
59 | ||
60 | // ask if data in correct format is available | |
61 | virtual bool IsSupported( const wxDataFormat& format ) = 0; | |
62 | ||
63 | // ask if data in correct format is available | |
64 | virtual bool IsSupportedAsync( wxEvtHandler *sink ); | |
65 | ||
66 | // fill data with data on the clipboard (if available) | |
67 | virtual bool GetData( wxDataObject& data ) = 0; | |
68 | ||
69 | // clears wxTheClipboard and the system's clipboard if possible | |
70 | virtual void Clear() = 0; | |
71 | ||
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; } | |
76 | ||
77 | // this allows to choose whether we work with CLIPBOARD (default) or | |
78 | // PRIMARY selection on X11-based systems | |
79 | // | |
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) | |
85 | { | |
86 | m_usePrimary = usePrimary; | |
87 | } | |
88 | ||
89 | // return true if we're using primary selection | |
90 | bool IsUsingPrimarySelection() const { return m_usePrimary; } | |
91 | ||
92 | // Returns global instance (wxTheClipboard) of the object: | |
93 | static wxClipboard *Get(); | |
94 | ||
95 | ||
96 | // don't use this directly, it is public for compatibility with some ports | |
97 | // (wxX11, wxMotif, ...) only | |
98 | bool m_usePrimary; | |
99 | }; | |
100 | ||
101 | // ---------------------------------------------------------------------------- | |
102 | // asynchronous clipboard event | |
103 | // ---------------------------------------------------------------------------- | |
104 | ||
105 | class WXDLLIMPEXP_CORE wxClipboardEvent : public wxEvent | |
106 | { | |
107 | public: | |
108 | wxClipboardEvent(wxEventType commandType = wxEVT_NULL) | |
109 | : wxEvent(0,commandType) | |
110 | { } | |
111 | ||
112 | wxClipboardEvent(const wxClipboardEvent& event) | |
113 | : wxEvent(event), | |
114 | m_formats(event.m_formats) | |
115 | { } | |
116 | ||
117 | bool SupportsFormat( const wxDataFormat &format ) const; | |
118 | void AddFormat( const wxDataFormat &format ); | |
119 | ||
120 | virtual wxEvent *Clone() const { return new wxClipboardEvent(*this); } | |
121 | ||
122 | protected: | |
123 | wxVector<wxDataFormat> m_formats; | |
124 | ||
125 | private: | |
126 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxClipboardEvent) | |
127 | }; | |
128 | ||
129 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_CLIPBOARD_CHANGED; | |
130 | ||
131 | typedef void (wxEvtHandler::*wxClipboardEventFunction)(wxClipboardEvent&); | |
132 | ||
133 | #define wxClipboardEventHandler(func) \ | |
134 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxClipboardEventFunction, &func) | |
135 | ||
136 | #define EVT_CLIPBOARD_CHANGED(func) wx__DECLARE_EVT0(wxEVT_CLIPBOARD_CHANGED, wxClipboardEventHandler(func)) | |
137 | ||
138 | // ---------------------------------------------------------------------------- | |
139 | // globals | |
140 | // ---------------------------------------------------------------------------- | |
141 | ||
142 | // The global clipboard object - backward compatible access macro: | |
143 | #define wxTheClipboard (wxClipboard::Get()) | |
144 | ||
145 | // ---------------------------------------------------------------------------- | |
146 | // include platform-specific class declaration | |
147 | // ---------------------------------------------------------------------------- | |
148 | ||
149 | #if defined(__WXMSW__) | |
150 | #include "wx/msw/clipbrd.h" | |
151 | #elif defined(__WXMOTIF__) | |
152 | #include "wx/motif/clipbrd.h" | |
153 | #elif defined(__WXGTK20__) | |
154 | #include "wx/gtk/clipbrd.h" | |
155 | #elif defined(__WXGTK__) | |
156 | #include "wx/gtk1/clipbrd.h" | |
157 | #elif defined(__WXX11__) | |
158 | #include "wx/x11/clipbrd.h" | |
159 | #elif defined(__WXMGL__) | |
160 | #include "wx/mgl/clipbrd.h" | |
161 | #elif defined(__WXMAC__) | |
162 | #include "wx/osx/clipbrd.h" | |
163 | #elif defined(__WXCOCOA__) | |
164 | #include "wx/cocoa/clipbrd.h" | |
165 | #elif defined(__WXPM__) | |
166 | #include "wx/os2/clipbrd.h" | |
167 | #endif | |
168 | ||
169 | // ---------------------------------------------------------------------------- | |
170 | // helpful class for opening the clipboard and automatically closing it | |
171 | // ---------------------------------------------------------------------------- | |
172 | ||
173 | class WXDLLIMPEXP_CORE wxClipboardLocker | |
174 | { | |
175 | public: | |
176 | wxClipboardLocker(wxClipboard *clipboard = (wxClipboard *)NULL) | |
177 | { | |
178 | m_clipboard = clipboard ? clipboard : wxTheClipboard; | |
179 | if ( m_clipboard ) | |
180 | { | |
181 | m_clipboard->Open(); | |
182 | } | |
183 | } | |
184 | ||
185 | bool operator!() const { return !m_clipboard->IsOpened(); } | |
186 | ||
187 | ~wxClipboardLocker() | |
188 | { | |
189 | if ( m_clipboard ) | |
190 | { | |
191 | m_clipboard->Close(); | |
192 | } | |
193 | } | |
194 | ||
195 | private: | |
196 | wxClipboard *m_clipboard; | |
197 | ||
198 | DECLARE_NO_COPY_CLASS(wxClipboardLocker) | |
199 | }; | |
200 | ||
201 | #endif // wxUSE_CLIPBOARD | |
202 | ||
203 | #endif // _WX_CLIPBRD_H_BASE_ |