]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkclipboard.sgml
2.9.0
[~andy/gtk] / docs / reference / gtk / tmpl / gtkclipboard.sgml
1 <!-- ##### SECTION Title ##### -->
2 Clipboards
3
4 <!-- ##### SECTION Short_Description ##### -->
5 Storing data on clipboards
6
7 <!-- ##### SECTION Long_Description ##### -->
8   <para>
9     The #GtkClipboard object represents a clipboard of data shared
10     between different processes or between different widgets in
11     the same process. Each clipboard is identified by a name encoded as a
12     #GdkAtom. (Conversion to and from strings can be done with
13     gdk_atom_intern() and gdk_atom_name().) The default clipboard
14     corresponds to the "CLIPBOARD" atom; another commonly used clipboard
15     is the "PRIMARY" clipboard, which, in X, traditionally contains
16     the currently selected text.
17   </para>
18   <para>
19     To support having a number of different formats on the clipboard
20     at the same time, the clipboard mechanism allows providing
21     callbacks instead of the actual data.  When you set the contents
22     of the clipboard, you can either supply the data directly (via
23     functions like gtk_clipboard_set_text()), or you can supply a
24     callback to be called at a later time when the data is needed (via
25     gtk_clipboard_set_with_data() or gtk_clipboard_set_with_owner().)
26     Providing a callback also avoids having to make copies of the data
27     when it is not needed.
28   </para>
29   <para>
30     gtk_clipboard_set_with_data() and gtk_clipboard_set_with_owner()
31     are quite similar; the choice between the two depends mostly on
32     which is more convenient in a particular situation.
33     The former is most useful when you want to have a blob of data
34     with callbacks to convert it into the various data types that you
35     advertise. When the @clear_func you provided is called, you
36     simply free the data blob. The latter is more useful when the
37     contents of clipboard reflect the internal state of a #GObject
38     (As an example, for the PRIMARY clipboard, when an entry widget
39     provides the clipboard's contents the contents are simply the
40     text within the selected region.) If the contents change, the
41     entry widget can call gtk_clipboard_set_with_owner() to update
42     the timestamp for clipboard ownership, without having to worry
43     about @clear_func being called.
44   </para>
45   <para>
46     Requesting the data from the clipboard is essentially
47     asynchronous. If the contents of the clipboard are provided within
48     the same process, then a direct function call will be made to
49     retrieve the data, but if they are provided by another process,
50     then the data needs to be retrieved from the other process, which
51     may take some time. To avoid blocking the user interface, the call
52     to request the selection, gtk_clipboard_request_contents() takes a
53     callback that will be called when the contents are received (or
54     when the request fails.) If you don't want to deal with providing
55     a separate callback, you can also use gtk_clipboard_wait_for_contents().
56     What this does is run the GLib main loop recursively waiting for
57     the contents. This can simplify the code flow, but you still have
58     to be aware that other callbacks in your program can be called
59     while this recursive mainloop is running.
60   </para>
61   <para>
62     Along with the functions to get the clipboard contents as an
63     arbitrary data chunk, there are also functions to retrieve
64     it as text, gtk_clipboard_request_text() and
65     gtk_clipboard_wait_for_text(). These functions take care of
66     determining which formats are advertised by the clipboard
67     provider, asking for the clipboard in the best available format
68     and converting the results into the UTF-8 encoding. (The standard
69     form for representing strings in GTK+.)
70   </para>
71
72 <!-- ##### SECTION See_Also ##### -->
73 <para>
74 <variablelist>
75
76 <varlistentry>
77 <term>#GtkSelection</term>
78 <listitem><para>#GtkClipboard provides a high-level wrapper around the
79             lower level routines that deal with X selections. It is
80             also possibly to directly manipulate the X selections,
81             though it is seldom necessary to do so.</para></listitem>
82 </varlistentry>
83
84 </variablelist>
85 </para>
86
87 <!-- ##### SECTION Stability_Level ##### -->
88
89
90 <!-- ##### STRUCT GtkClipboard ##### -->
91 <para>
92
93 </para>
94
95
96 <!-- ##### SIGNAL GtkClipboard::owner-change ##### -->
97 <para>
98
99 </para>
100
101 @clipboard: the object which received the signal.
102 @event: 
103
104 <!-- ##### USER_FUNCTION GtkClipboardReceivedFunc ##### -->
105 <para>
106     A function to be called when the results of gtk_clipboard_request_contents()
107     are received, or when the request fails.
108 </para>
109
110 @clipboard: the #GtkClipboard
111 @selection_data: a #GtkSelectionData containing the data was received.
112                  If retrieving the data failed, then then length field
113                  of @selection_data will be negative.
114 @data: the @user_data supplied to gtk_clipboard_request_contents().
115
116
117 <!-- ##### USER_FUNCTION GtkClipboardTextReceivedFunc ##### -->
118 <para>
119     A function to be called when the results of gtk_clipboard_request_text()
120     are received, or when the request fails.
121 </para>
122
123 @clipboard: the #GtkClipboard
124 @text: the text received, as a UTF-8 encoded string, or %NULL
125             if retrieving the data failed.
126 @data: the @user_data supplied to gtk_clipboard_request_text().
127
128
129 <!-- ##### USER_FUNCTION GtkClipboardImageReceivedFunc ##### -->
130 <para>
131     A function to be called when the results of gtk_clipboard_request_image()
132     are received, or when the request fails.
133 </para>
134
135 @clipboard: the #GtkClipboard
136 @pixbuf: the received image
137 @data: the @user_data supplied to gtk_clipboard_request_image().
138 @Since: 2.6
139
140
141 <!-- ##### USER_FUNCTION GtkClipboardTargetsReceivedFunc ##### -->
142 <para>
143     A function to be called when the results of gtk_clipboard_request_targets()
144     are received, or when the request fails.
145 </para>
146
147 @clipboard: the #GtkClipboard
148 @atoms: the supported targets, as array of #GdkAtom, or %NULL 
149             if retrieving the data failed.
150 @n_atoms: the length of the @atoms array.
151 @data: the @user_data supplied to gtk_clipboard_request_targets().
152 @Since: 2.4
153
154
155 <!-- ##### USER_FUNCTION GtkClipboardRichTextReceivedFunc ##### -->
156 <para>
157
158 </para>
159
160 @clipboard: 
161 @format: 
162 @text: 
163 @length: 
164 @data: 
165
166
167 <!-- ##### USER_FUNCTION GtkClipboardGetFunc ##### -->
168 <para>
169 A function that will be called to provide the contents of the selection.
170 If multiple types of data were advertised, the requested type can
171 be determined from the @info parameter or by checking the target field
172 of @selection_data. If the data could successfully be converted into
173 then it should be stored into the @selection_data object by
174 calling gtk_selection_data_set() (or related functions such
175 as gtk_selection_data_set_text()). If no data is set, the requestor
176 will be informed that the attempt to get the data failed.    
177 </para>
178
179 @clipboard: the #GtkClipboard
180 @selection_data: a #GtkSelectionData argument in which the requested
181                      data should be stored.
182 @info: the info field corresponding to the requested
183                      target from the #GtkTargetEntry array passed to
184                      gtk_clipboard_set_with_data() or gtk_clipboard_set_with_owner().
185 @user_data_or_owner: the @user_data argument passed to gtk_clipboard_set_with_data(), or
186                      the @owner argument passed to gtk_clipboard_set_with_owner()
187
188
189 <!-- ##### USER_FUNCTION GtkClipboardClearFunc ##### -->
190 <para>
191 A function that will be called when the contents of the clipboard are changed
192 or cleared. Once this has called, the @user_data_or_owner argument
193 will not be used again.
194 </para>
195
196 @clipboard: the #GtkClipboard
197 @user_data_or_owner: the @user_data argument passed to gtk_clipboard_set_with_data(), or
198                      the @owner argument passed to gtk_clipboard_set_with_owner()
199
200
201 <!-- ##### FUNCTION gtk_clipboard_get ##### -->
202 <para>
203
204 </para>
205
206 @selection: 
207 @Returns: 
208
209
210 <!-- ##### FUNCTION gtk_clipboard_get_for_display ##### -->
211 <para>
212
213 </para>
214
215 @display: 
216 @selection: 
217 @Returns: 
218
219
220 <!-- ##### FUNCTION gtk_clipboard_get_display ##### -->
221 <para>
222
223 </para>
224
225 @clipboard: 
226 @Returns: 
227
228
229 <!-- ##### FUNCTION gtk_clipboard_set_with_data ##### -->
230 <para>
231
232 </para>
233
234 @clipboard: 
235 @targets: 
236 @n_targets: 
237 @get_func: 
238 @clear_func: 
239 @user_data: 
240 @Returns: 
241
242
243 <!-- ##### FUNCTION gtk_clipboard_set_with_owner ##### -->
244 <para>
245
246 </para>
247
248 @clipboard: 
249 @targets: 
250 @n_targets: 
251 @get_func: 
252 @clear_func: 
253 @owner: 
254 @Returns: 
255
256
257 <!-- ##### FUNCTION gtk_clipboard_get_owner ##### -->
258 <para>
259
260 </para>
261
262 @clipboard: 
263 @Returns: 
264
265
266 <!-- ##### FUNCTION gtk_clipboard_clear ##### -->
267 <para>
268
269 </para>
270
271 @clipboard: 
272
273
274 <!-- ##### FUNCTION gtk_clipboard_set_text ##### -->
275 <para>
276
277 </para>
278
279 @clipboard: 
280 @text: 
281 @len: 
282
283
284 <!-- ##### FUNCTION gtk_clipboard_set_image ##### -->
285 <para>
286
287 </para>
288
289 @clipboard: 
290 @pixbuf: 
291
292
293 <!-- ##### FUNCTION gtk_clipboard_request_contents ##### -->
294 <para>
295
296 </para>
297
298 @clipboard: 
299 @target: 
300 @callback: 
301 @user_data: 
302
303
304 <!-- ##### FUNCTION gtk_clipboard_request_text ##### -->
305 <para>
306
307 </para>
308
309 @clipboard: 
310 @callback: 
311 @user_data: 
312
313
314 <!-- ##### FUNCTION gtk_clipboard_request_image ##### -->
315 <para>
316
317 </para>
318
319 @clipboard: 
320 @callback: 
321 @user_data: 
322
323
324 <!-- ##### FUNCTION gtk_clipboard_request_targets ##### -->
325 <para>
326
327 </para>
328
329 @clipboard: 
330 @callback: 
331 @user_data: 
332
333
334 <!-- ##### FUNCTION gtk_clipboard_request_rich_text ##### -->
335 <para>
336
337 </para>
338
339 @clipboard: 
340 @buffer: 
341 @callback: 
342 @user_data: 
343
344
345 <!-- ##### FUNCTION gtk_clipboard_wait_for_contents ##### -->
346 <para>
347
348 </para>
349
350 @clipboard: 
351 @target: 
352 @Returns: 
353
354
355 <!-- ##### FUNCTION gtk_clipboard_wait_for_text ##### -->
356 <para>
357
358 </para>
359
360 @clipboard: 
361 @Returns: 
362
363
364 <!-- ##### FUNCTION gtk_clipboard_wait_for_image ##### -->
365 <para>
366
367 </para>
368
369 @clipboard: 
370 @Returns: 
371
372
373 <!-- ##### FUNCTION gtk_clipboard_wait_for_rich_text ##### -->
374 <para>
375
376 </para>
377
378 @clipboard: 
379 @buffer: 
380 @format: 
381 @length: 
382 @Returns: 
383
384
385 <!-- ##### FUNCTION gtk_clipboard_wait_is_text_available ##### -->
386 <para>
387
388 </para>
389
390 @clipboard: 
391 @Returns: 
392
393
394 <!-- ##### FUNCTION gtk_clipboard_wait_is_image_available ##### -->
395 <para>
396
397 </para>
398
399 @clipboard: 
400 @Returns: 
401
402
403 <!-- ##### FUNCTION gtk_clipboard_wait_is_rich_text_available ##### -->
404 <para>
405
406 </para>
407
408 @clipboard: 
409 @buffer: 
410 @Returns: 
411
412
413 <!-- ##### FUNCTION gtk_clipboard_wait_for_targets ##### -->
414 <para>
415
416 </para>
417
418 @clipboard: 
419 @targets: 
420 @n_targets: 
421 @Returns: 
422
423 <!--
424 Local variables:
425 mode: sgml
426 sgml-parent-document: ("../gtk-docs.sgml" "book" "refsect2" "")
427 End:
428 -->
429
430
431 <!-- ##### FUNCTION gtk_clipboard_wait_is_target_available ##### -->
432 <para>
433
434 </para>
435
436 @clipboard: 
437 @target: 
438 @Returns: 
439
440
441 <!-- ##### FUNCTION gtk_clipboard_set_can_store ##### -->
442 <para>
443
444 </para>
445
446 @clipboard: 
447 @targets: 
448 @n_targets: 
449
450
451 <!-- ##### FUNCTION gtk_clipboard_store ##### -->
452 <para>
453
454 </para>
455
456 @clipboard: 
457
458