]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _clipbrd.i | |
3 | // Purpose: SWIG definitions for the Clipboard | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 31-October-1999 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | %newgroup | |
18 | ||
19 | %{ | |
20 | %} | |
21 | ||
fcafa8a9 | 22 | DocStr(wxClipboard, |
dce2bd22 RD |
23 | "wx.Clipboard represents the system clipboard and provides methods to |
24 | copy data to it or paste data from it. Normally, you should only use | |
25 | ``wx.TheClipboard`` which is a reference to a global wx.Clipboard | |
26 | instance. | |
27 | ||
28 | Call ``wx.TheClipboard``'s `Open` method to get ownership of the | |
29 | clipboard. If this operation returns True, you now own the | |
30 | clipboard. Call `SetData` to put data on the clipboard, or `GetData` | |
31 | to retrieve data from the clipboard. Call `Close` to close the | |
32 | clipboard and relinquish ownership. You should keep the clipboard open | |
33 | only momentarily. | |
34 | ||
35 | :see: `wx.DataObject` | |
d07d2bc9 | 36 | ", ""); |
fcafa8a9 | 37 | |
d14a1e28 RD |
38 | |
39 | ||
d14a1e28 RD |
40 | class wxClipboard : public wxObject { |
41 | public: | |
dce2bd22 RD |
42 | DocCtorStr( |
43 | wxClipboard(), | |
d07d2bc9 | 44 | "", ""); |
fcafa8a9 | 45 | |
d14a1e28 RD |
46 | ~wxClipboard(); |
47 | ||
d14a1e28 | 48 | |
fcafa8a9 RD |
49 | DocDeclStr( |
50 | virtual bool , Open(), | |
dce2bd22 RD |
51 | "Call this function to open the clipboard before calling SetData and |
52 | GetData. Call Close when you have finished with the clipboard. You | |
53 | should keep the clipboard open for only a very short time. Returns | |
d07d2bc9 | 54 | True on success.", ""); |
fcafa8a9 RD |
55 | |
56 | ||
57 | DocDeclStr( | |
58 | virtual void , Close(), | |
d07d2bc9 | 59 | "Closes the clipboard.", ""); |
fcafa8a9 | 60 | |
d14a1e28 | 61 | |
fcafa8a9 RD |
62 | DocDeclStr( |
63 | virtual bool , IsOpened() const, | |
d07d2bc9 | 64 | "Query whether the clipboard is opened", ""); |
fcafa8a9 | 65 | |
d14a1e28 | 66 | |
8668c242 | 67 | |
214c4fbe | 68 | %disownarg( wxDataObject *data ); |
8668c242 | 69 | |
fcafa8a9 RD |
70 | DocDeclStr( |
71 | virtual bool , AddData( wxDataObject *data ), | |
dce2bd22 RD |
72 | "Call this function to add the data object to the clipboard. You may |
73 | call this function repeatedly after having cleared the clipboard. | |
74 | After this function has been called, the clipboard owns the data, so | |
75 | do not delete the data explicitly. | |
76 | ||
d07d2bc9 | 77 | :see: `wx.DataObject`", ""); |
fcafa8a9 | 78 | |
d14a1e28 | 79 | |
fcafa8a9 RD |
80 | DocDeclStr( |
81 | virtual bool , SetData( wxDataObject *data ), | |
dce2bd22 RD |
82 | "Set the clipboard data, this is the same as `Clear` followed by |
83 | `AddData`. | |
84 | ||
d07d2bc9 | 85 | :see: `wx.DataObject`", ""); |
fcafa8a9 | 86 | |
214c4fbe RD |
87 | %cleardisown( wxDataObject *data ); |
88 | ||
8668c242 | 89 | |
fcafa8a9 RD |
90 | DocDeclStr( |
91 | virtual bool , IsSupported( const wxDataFormat& format ), | |
dce2bd22 | 92 | "Returns True if the given format is available in the data object(s) on |
d07d2bc9 | 93 | the clipboard.", ""); |
fcafa8a9 RD |
94 | |
95 | DocDeclStr( | |
96 | virtual bool , GetData( wxDataObject& data ), | |
dce2bd22 | 97 | "Call this function to fill data with data on the clipboard, if |
d07d2bc9 | 98 | available in the required format. Returns true on success.", ""); |
fcafa8a9 RD |
99 | |
100 | ||
101 | DocDeclStr( | |
102 | virtual void , Clear(), | |
dce2bd22 | 103 | "Clears data from the clipboard object and also the system's clipboard |
d07d2bc9 | 104 | if possible.", ""); |
d14a1e28 | 105 | |
d14a1e28 | 106 | |
fcafa8a9 RD |
107 | DocDeclStr( |
108 | virtual bool , Flush(), | |
dce2bd22 RD |
109 | "Flushes the clipboard: this means that the data which is currently on |
110 | clipboard will stay available even after the application exits, | |
111 | possibly eating memory, otherwise the clipboard will be emptied on | |
d07d2bc9 | 112 | exit. Returns False if the operation is unsuccesful for any reason.", ""); |
fcafa8a9 | 113 | |
d14a1e28 | 114 | |
fcafa8a9 | 115 | DocDeclStr( |
a72f4631 | 116 | virtual void , UsePrimarySelection( bool primary = true ), |
d029969f RD |
117 | "On platforms supporting it (the X11 based platforms), selects the so |
118 | called PRIMARY SELECTION as the clipboard as opposed to the normal | |
119 | clipboard, if primary is True. On other platforms all clipboard | |
120 | operations fail when using the primary selection. This allows code | |
121 | supporting the primary selection to be written without ill effects on | |
122 | the other platforms.", ""); | |
d14a1e28 | 123 | |
d029969f RD |
124 | |
125 | DocDeclStr( | |
126 | bool , IsUsingPrimarySelection() const, | |
127 | "Return true if we're using primary selection", ""); | |
128 | ||
d14a1e28 | 129 | |
fe5e444a RD |
130 | DocDeclStr( |
131 | static wxClipboard *, Get(), | |
132 | "Returns global instance (wxTheClipboard) of the object.", ""); | |
0eae5d09 | 133 | |
fe5e444a RD |
134 | }; |
135 | ||
d14a1e28 | 136 | |
fe5e444a RD |
137 | // Previously we just declared wxTheClipboard as a global, but in C++ |
138 | // is has been changed to be a macro for wxClipboard::Get, but the | |
139 | // swig generated code will try to evaluate it when it assigns to the | |
140 | // swig wrapper var so this causes Get to be called too early on | |
141 | // wxGTK. So instead we'll create a Python class that can delay the | |
142 | // Get until it is really needed, which is similar in effect to what | |
143 | // is really happening on the C++ side too. | |
144 | %pythoncode { | |
145 | class _wxPyDelayedInitWrapper(object): | |
146 | def __init__(self, initfunc, *args, **kwargs): | |
147 | self._initfunc = initfunc | |
148 | self._args = args | |
149 | self._kwargs = kwargs | |
150 | self._instance = None | |
151 | def _checkInstance(self): | |
152 | if self._instance is None: | |
02b800ce RD |
153 | if wx.GetApp(): |
154 | self._instance = self._initfunc(*self._args, **self._kwargs) | |
fe5e444a RD |
155 | def __getattr__(self, name): |
156 | self._checkInstance() | |
157 | return getattr(self._instance, name) | |
158 | def __repr__(self): | |
159 | self._checkInstance() | |
160 | return repr(self._instance) | |
161 | TheClipboard = _wxPyDelayedInitWrapper(Clipboard.Get) | |
162 | } | |
d14a1e28 RD |
163 | |
164 | ||
165 | //--------------------------------------------------------------------------- | |
166 | ||
167 | ||
fcafa8a9 | 168 | DocStr(wxClipboardLocker, |
dce2bd22 | 169 | "A helpful class for opening the clipboard and automatically |
d07d2bc9 | 170 | closing it when the locker is destroyed.", ""); |
fcafa8a9 | 171 | |
d14a1e28 RD |
172 | class wxClipboardLocker |
173 | { | |
174 | public: | |
175 | wxClipboardLocker(wxClipboard *clipboard = NULL); | |
176 | ~wxClipboardLocker(); | |
177 | ||
fcafa8a9 | 178 | DocStr(__nonzero__, |
dce2bd22 | 179 | "A ClipboardLocker instance evaluates to True if the clipboard was |
d07d2bc9 | 180 | successfully opened.", ""); |
d14a1e28 RD |
181 | %extend { |
182 | bool __nonzero__() { return !!(*self); } | |
183 | } | |
184 | }; | |
185 | ||
186 | ||
187 | //--------------------------------------------------------------------------- |