]>
Commit | Line | Data |
---|---|---|
e1ee679c VZ |
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$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets Team |
65571936 | 9 | // Licence: wxWindows licence |
e1ee679c VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_CLIPBRD_H_BASE_ |
13 | #define _WX_CLIPBRD_H_BASE_ | |
c801d85f | 14 | |
e1ee679c VZ |
15 | #include "wx/defs.h" |
16 | ||
17 | #if wxUSE_CLIPBOARD | |
18 | ||
b068c4e8 | 19 | |
e1ee679c | 20 | #include "wx/object.h" |
e3f6cbd9 | 21 | #include "wx/chartype.h" |
e1ee679c | 22 | |
b5dbe15d VS |
23 | class WXDLLIMPEXP_FWD_CORE wxDataFormat; |
24 | class WXDLLIMPEXP_FWD_CORE wxDataObject; | |
25 | class WXDLLIMPEXP_FWD_CORE wxClipboard; | |
e1ee679c VZ |
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 | ||
53a2db12 | 35 | class WXDLLIMPEXP_CORE wxClipboardBase : public wxObject |
e1ee679c VZ |
36 | { |
37 | public: | |
9005f2ed | 38 | wxClipboardBase() { m_usePrimary = false; } |
b068c4e8 | 39 | |
e1ee679c | 40 | // open the clipboard before Add/SetData() and GetData() |
b068c4e8 | 41 | virtual bool Open() = 0; |
e1ee679c VZ |
42 | |
43 | // close the clipboard after Add/SetData() and GetData() | |
b068c4e8 | 44 | virtual void Close() = 0; |
e1ee679c | 45 | |
f536e0f2 VZ |
46 | // query whether the clipboard is opened |
47 | virtual bool IsOpened() const = 0; | |
48 | ||
e1ee679c VZ |
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 | |
b068c4e8 | 53 | virtual bool AddData( wxDataObject *data ) = 0; |
e1ee679c VZ |
54 | |
55 | // set the clipboard data, this is the same as Clear() followed by | |
56 | // AddData() | |
b068c4e8 | 57 | virtual bool SetData( wxDataObject *data ) = 0; |
e1ee679c VZ |
58 | |
59 | // ask if data in correct format is available | |
b068c4e8 | 60 | virtual bool IsSupported( const wxDataFormat& format ) = 0; |
e1ee679c VZ |
61 | |
62 | // fill data with data on the clipboard (if available) | |
b068c4e8 | 63 | virtual bool GetData( wxDataObject& data ) = 0; |
68379eaf | 64 | |
e1ee679c | 65 | // clears wxTheClipboard and the system's clipboard if possible |
b068c4e8 | 66 | virtual void Clear() = 0; |
e1ee679c VZ |
67 | |
68 | // flushes the clipboard: this means that the data which is currently on | |
69 | // clipboard will stay available even after the application exits (possibly | |
70 | // eating memory), otherwise the clipboard will be emptied on exit | |
68379eaf | 71 | virtual bool Flush() { return false; } |
e1ee679c | 72 | |
9005f2ed VZ |
73 | // this allows to choose whether we work with CLIPBOARD (default) or |
74 | // PRIMARY selection on X11-based systems | |
75 | // | |
76 | // on the other ones, working with primary selection does nothing: this | |
77 | // allows to write code which sets the primary selection when something is | |
78 | // selected without any ill effects (i.e. without overwriting the | |
79 | // clipboard which would be wrong on the platforms without X11 PRIMARY) | |
80 | virtual void UsePrimarySelection(bool usePrimary = false) | |
81 | { | |
82 | m_usePrimary = usePrimary; | |
83 | } | |
84 | ||
85 | // return true if we're using primary selection | |
86 | bool IsUsingPrimarySelection() const { return m_usePrimary; } | |
e1ee679c | 87 | |
5dc43d1f VS |
88 | // Returns global instance (wxTheClipboard) of the object: |
89 | static wxClipboard *Get(); | |
9005f2ed VZ |
90 | |
91 | ||
92 | // don't use this directly, it is public for compatibility with some ports | |
93 | // (wxX11, wxMotif, ...) only | |
94 | bool m_usePrimary; | |
e1ee679c VZ |
95 | }; |
96 | ||
5dc43d1f VS |
97 | // ---------------------------------------------------------------------------- |
98 | // globals | |
99 | // ---------------------------------------------------------------------------- | |
100 | ||
101 | // The global clipboard object - backward compatible access macro: | |
102 | #define wxTheClipboard (wxClipboard::Get()) | |
103 | ||
e1ee679c VZ |
104 | // ---------------------------------------------------------------------------- |
105 | // include platform-specific class declaration | |
106 | // ---------------------------------------------------------------------------- | |
107 | ||
2049ba38 | 108 | #if defined(__WXMSW__) |
e1ee679c | 109 | #include "wx/msw/clipbrd.h" |
2049ba38 | 110 | #elif defined(__WXMOTIF__) |
e1ee679c | 111 | #include "wx/motif/clipbrd.h" |
1be7a35c | 112 | #elif defined(__WXGTK20__) |
e1ee679c | 113 | #include "wx/gtk/clipbrd.h" |
1be7a35c MR |
114 | #elif defined(__WXGTK__) |
115 | #include "wx/gtk1/clipbrd.h" | |
83df96d6 JS |
116 | #elif defined(__WXX11__) |
117 | #include "wx/x11/clipbrd.h" | |
1e6feb95 VZ |
118 | #elif defined(__WXMGL__) |
119 | #include "wx/mgl/clipbrd.h" | |
34138703 | 120 | #elif defined(__WXMAC__) |
e1ee679c | 121 | #include "wx/mac/clipbrd.h" |
aa3d0277 DE |
122 | #elif defined(__WXCOCOA__) |
123 | #include "wx/cocoa/clipbrd.h" | |
1777b9bb | 124 | #elif defined(__WXPM__) |
e1ee679c | 125 | #include "wx/os2/clipbrd.h" |
c801d85f KB |
126 | #endif |
127 | ||
f536e0f2 VZ |
128 | // ---------------------------------------------------------------------------- |
129 | // helpful class for opening the clipboard and automatically closing it | |
130 | // ---------------------------------------------------------------------------- | |
131 | ||
53a2db12 | 132 | class WXDLLIMPEXP_CORE wxClipboardLocker |
f536e0f2 VZ |
133 | { |
134 | public: | |
135 | wxClipboardLocker(wxClipboard *clipboard = (wxClipboard *)NULL) | |
136 | { | |
137 | m_clipboard = clipboard ? clipboard : wxTheClipboard; | |
138 | if ( m_clipboard ) | |
139 | { | |
140 | m_clipboard->Open(); | |
141 | } | |
142 | } | |
143 | ||
ffd56fbc | 144 | bool operator!() const { return !m_clipboard->IsOpened(); } |
f536e0f2 VZ |
145 | |
146 | ~wxClipboardLocker() | |
147 | { | |
148 | if ( m_clipboard ) | |
149 | { | |
150 | m_clipboard->Close(); | |
151 | } | |
152 | } | |
153 | ||
154 | private: | |
155 | wxClipboard *m_clipboard; | |
22f3361e VZ |
156 | |
157 | DECLARE_NO_COPY_CLASS(wxClipboardLocker) | |
f536e0f2 VZ |
158 | }; |
159 | ||
e1ee679c VZ |
160 | #endif // wxUSE_CLIPBOARD |
161 | ||
162 | #endif // _WX_CLIPBRD_H_BASE_ |