]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/clipbrd.tex
Doc update.
[wxWidgets.git] / docs / latex / wx / clipbrd.tex
1 \section{\class{wxClipboard}}\label{wxclipboard}
2
3 A class for manipulating the clipboard. Note that this is not compatible with the
4 clipboard class from wxWidgets 1.xx, which has the same name but a different implementation.
5
6 To use the clipboard, you call member functions of the global {\bf wxTheClipboard} object.
7
8 See also the \helpref{wxDataObject overview}{wxdataobjectoverview} for further information.
9
10 Call \helpref{wxClipboard::Open}{wxclipboardopen} to get ownership of the clipboard. If this operation returns true, you
11 now own the clipboard. Call \helpref{wxClipboard::SetData}{wxclipboardsetdata} to put data
12 on the clipboard, or \helpref{wxClipboard::GetData}{wxclipboardgetdata} to
13 retrieve data from the clipboard. Call \helpref{wxClipboard::Close}{wxclipboardclose} to close
14 the clipboard and relinquish ownership. You should keep the clipboard open only momentarily.
15
16 For example:
17
18 \begin{verbatim}
19 // Write some text to the clipboard
20 if (wxTheClipboard->Open())
21 {
22 // This data objects are held by the clipboard,
23 // so do not delete them in the app.
24 wxTheClipboard->SetData( new wxTextDataObject("Some text") );
25 wxTheClipboard->Close();
26 }
27
28 // Read some text
29 if (wxTheClipboard->Open())
30 {
31 if (wxTheClipboard->IsSupported( wxDF_TEXT ))
32 {
33 wxTextDataObject data;
34 wxTheClipboard->GetData( data );
35 wxMessageBox( data.GetText() );
36 }
37 wxTheClipboard->Close();
38 }
39 \end{verbatim}
40
41 \wxheading{Derived from}
42
43 \helpref{wxObject}{wxobject}
44
45 \wxheading{Include files}
46
47 <wx/clipbrd.h>
48
49 \wxheading{See also}
50
51 \helpref{Drag and drop overview}{wxdndoverview}, \helpref{wxDataObject}{wxdataobject}
52
53 \latexignore{\rtfignore{\wxheading{Members}}}
54
55
56 \membersection{wxClipboard::wxClipboard}\label{wxclipboardctor}
57
58 \func{}{wxClipboard}{\void}
59
60 Constructor.
61
62
63 \membersection{wxClipboard::\destruct{wxClipboard}}\label{wxclipboarddtor}
64
65 \func{}{\destruct{wxClipboard}}{\void}
66
67 Destructor.
68
69
70 \membersection{wxClipboard::AddData}\label{wxclipboardadddata}
71
72 \func{bool}{AddData}{\param{wxDataObject*}{ data}}
73
74 Call this function to add the data object to the clipboard. You may call
75 this function repeatedly after having cleared the clipboard using \helpref{wxClipboard::Clear}{wxclipboardclear}.
76
77 After this function has been called, the clipboard owns the data, so do not delete
78 the data explicitly.
79
80 \wxheading{See also}
81
82 \helpref{wxClipboard::SetData}{wxclipboardsetdata}
83
84
85 \membersection{wxClipboard::Clear}\label{wxclipboardclear}
86
87 \func{void}{Clear}{\void}
88
89 Clears the global clipboard object and the system's clipboard if possible.
90
91
92 \membersection{wxClipboard::Close}\label{wxclipboardclose}
93
94 \func{void}{Close}{\void}
95
96 Call this function to close the clipboard, having opened it with \helpref{wxClipboard::Open}{wxclipboardopen}.
97
98
99 \membersection{wxClipboard::Flush}\label{wxclipboardflush}
100
101 \func{bool}{Flush}{\void}
102
103 Flushes the clipboard: this means that the data which is currently on
104 clipboard will stay available even after the application exits (possibly
105 eating memory), otherwise the clipboard will be emptied on exit.
106 Returns false if the operation is unsuccessful for any reason.
107
108
109 \membersection{wxClipboard::GetData}\label{wxclipboardgetdata}
110
111 \func{bool}{GetData}{\param{wxDataObject\&}{ data}}
112
113 Call this function to fill {\it data} with data on the clipboard, if available in the required
114 format. Returns true on success.
115
116
117 \membersection{wxClipboard::IsOpened}\label{wxclipboardisopened}
118
119 \constfunc{bool}{IsOpened}{\void}
120
121 Returns true if the clipboard has been opened.
122
123
124 \membersection{wxClipboard::IsSupported}\label{wxclipboardissupported}
125
126 \func{bool}{IsSupported}{\param{const wxDataFormat\&}{ format}}
127
128 Returns true if there is data which matches the data format of the given data object currently {\bf available} (IsSupported sounds like a misnomer, FIXME: better deprecate this name?) on the clipboard.
129
130
131 \membersection{wxClipboard::IsUsingPrimarySelection}\label{wxclipboardisusingprimaryselection}
132
133 \constfunc{bool}{IsUsingPrimarySelection}{\void}
134
135 Returns \true if we are using the primary selection, \false if clipboard one.
136 See \helpref{UsePrimarySelection}{wxclipboarduseprimary} for more information.
137
138
139 \membersection{wxClipboard::Open}\label{wxclipboardopen}
140
141 \func{bool}{Open}{\void}
142
143 Call this function to open the clipboard before calling \helpref{wxClipboard::SetData}{wxclipboardsetdata}
144 and \helpref{wxClipboard::GetData}{wxclipboardgetdata}.
145
146 Call \helpref{wxClipboard::Close}{wxclipboardclose} when you have finished with the clipboard. You
147 should keep the clipboard open for only a very short time.
148
149 Returns true on success. This should be tested (as in the sample shown above).
150
151
152 \membersection{wxClipboard::SetData}\label{wxclipboardsetdata}
153
154 \func{bool}{SetData}{\param{wxDataObject*}{ data}}
155
156 Call this function to set the data object to the clipboard. This function will
157 clear all previous contents in the clipboard, so calling it several times
158 does not make any sense.
159
160 After this function has been called, the clipboard owns the data, so do not delete
161 the data explicitly.
162
163 \wxheading{See also}
164
165 \helpref{wxClipboard::AddData}{wxclipboardadddata}
166
167
168 \membersection{wxClipboard::UsePrimarySelection}\label{wxclipboarduseprimary}
169
170 \func{void}{UsePrimarySelection}{\param{bool}{ primary = true}}
171
172 On platforms supporting it (all X11-based ports), wxClipboard uses the
173 CLIPBOARD X11 selection by default. When this function is called with \true
174 argument, all subsequent clipboard operations will use PRIMARY selection until
175 this function is called again with \false.
176
177 On the other platforms, there is no PRIMARY selection and so all clipboard
178 operations will fail. This allows to implement the standard X11 handling of the
179 clipboard which consists in copying data to the CLIPBOARD selection only when
180 the user explicitly requests it (i.e. by selection \texttt{"Copy"} menu
181 command) but putting the currently selected text into the PRIMARY selection
182 automatically, without overwriting the normal clipboard contents with the
183 currently selected text on the other platforms.
184