1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.Clipboard; 26 27 private import gdk.Display; 28 private import gdk.Event; 29 private import gdkpixbuf.Pixbuf; 30 private import glib.Str; 31 private import gobject.ObjectG; 32 private import gobject.Signals; 33 private import gtk.SelectionData; 34 private import gtk.TargetEntry; 35 private import gtk.TextBuffer; 36 private import gtkc.gtk; 37 public import gtkc.gtktypes; 38 private import std.algorithm; 39 40 41 /** 42 * The #GtkClipboard object represents a clipboard of data shared 43 * between different processes or between different widgets in 44 * the same process. Each clipboard is identified by a name encoded as a 45 * #GdkAtom. (Conversion to and from strings can be done with 46 * gdk_atom_intern() and gdk_atom_name().) The default clipboard 47 * corresponds to the “CLIPBOARD” atom; another commonly used clipboard 48 * is the “PRIMARY” clipboard, which, in X, traditionally contains 49 * the currently selected text. 50 * 51 * To support having a number of different formats on the clipboard 52 * at the same time, the clipboard mechanism allows providing 53 * callbacks instead of the actual data. When you set the contents 54 * of the clipboard, you can either supply the data directly (via 55 * functions like gtk_clipboard_set_text()), or you can supply a 56 * callback to be called at a later time when the data is needed (via 57 * gtk_clipboard_set_with_data() or gtk_clipboard_set_with_owner().) 58 * Providing a callback also avoids having to make copies of the data 59 * when it is not needed. 60 * 61 * gtk_clipboard_set_with_data() and gtk_clipboard_set_with_owner() 62 * are quite similar; the choice between the two depends mostly on 63 * which is more convenient in a particular situation. 64 * The former is most useful when you want to have a blob of data 65 * with callbacks to convert it into the various data types that you 66 * advertise. When the @clear_func you provided is called, you 67 * simply free the data blob. The latter is more useful when the 68 * contents of clipboard reflect the internal state of a #GObject 69 * (As an example, for the PRIMARY clipboard, when an entry widget 70 * provides the clipboard’s contents the contents are simply the 71 * text within the selected region.) If the contents change, the 72 * entry widget can call gtk_clipboard_set_with_owner() to update 73 * the timestamp for clipboard ownership, without having to worry 74 * about @clear_func being called. 75 * 76 * Requesting the data from the clipboard is essentially 77 * asynchronous. If the contents of the clipboard are provided within 78 * the same process, then a direct function call will be made to 79 * retrieve the data, but if they are provided by another process, 80 * then the data needs to be retrieved from the other process, which 81 * may take some time. To avoid blocking the user interface, the call 82 * to request the selection, gtk_clipboard_request_contents() takes a 83 * callback that will be called when the contents are received (or 84 * when the request fails.) If you don’t want to deal with providing 85 * a separate callback, you can also use gtk_clipboard_wait_for_contents(). 86 * What this does is run the GLib main loop recursively waiting for 87 * the contents. This can simplify the code flow, but you still have 88 * to be aware that other callbacks in your program can be called 89 * while this recursive mainloop is running. 90 * 91 * Along with the functions to get the clipboard contents as an 92 * arbitrary data chunk, there are also functions to retrieve 93 * it as text, gtk_clipboard_request_text() and 94 * gtk_clipboard_wait_for_text(). These functions take care of 95 * determining which formats are advertised by the clipboard 96 * provider, asking for the clipboard in the best available format 97 * and converting the results into the UTF-8 encoding. (The standard 98 * form for representing strings in GTK+.) 99 */ 100 public class Clipboard : ObjectG 101 { 102 /** the main Gtk struct */ 103 protected GtkClipboard* gtkClipboard; 104 105 /** Get the main Gtk struct */ 106 public GtkClipboard* getClipboardStruct(bool transferOwnership = false) 107 { 108 if (transferOwnership) 109 ownedRef = false; 110 return gtkClipboard; 111 } 112 113 /** the main Gtk struct as a void* */ 114 protected override void* getStruct() 115 { 116 return cast(void*)gtkClipboard; 117 } 118 119 protected override void setStruct(GObject* obj) 120 { 121 gtkClipboard = cast(GtkClipboard*)obj; 122 super.setStruct(obj); 123 } 124 125 /** 126 * Sets our main struct and passes it to the parent class. 127 */ 128 public this (GtkClipboard* gtkClipboard, bool ownedRef = false) 129 { 130 this.gtkClipboard = gtkClipboard; 131 super(cast(GObject*)gtkClipboard, ownedRef); 132 } 133 134 135 /** */ 136 public static GType getType() 137 { 138 return gtk_clipboard_get_type(); 139 } 140 141 /** 142 * Returns the clipboard object for the given selection. 143 * See gtk_clipboard_get_for_display() for complete details. 144 * 145 * Params: 146 * selection = a #GdkAtom which identifies the clipboard to use 147 * 148 * Returns: the appropriate clipboard object. If no clipboard 149 * already exists, a new one will be created. Once a clipboard 150 * object has been created, it is persistent and, since it is 151 * owned by GTK+, must not be freed or unreffed. 152 */ 153 public static Clipboard get(GdkAtom selection) 154 { 155 auto p = gtk_clipboard_get(selection); 156 157 if(p is null) 158 { 159 return null; 160 } 161 162 return ObjectG.getDObject!(Clipboard)(cast(GtkClipboard*) p); 163 } 164 165 /** 166 * Returns the default clipboard object for use with cut/copy/paste menu items 167 * and keyboard shortcuts. 168 * 169 * Params: 170 * display = the #GdkDisplay for which the clipboard is to be retrieved. 171 * 172 * Returns: the default clipboard object. 173 * 174 * Since: 3.16 175 */ 176 public static Clipboard getDefault(Display display) 177 { 178 auto p = gtk_clipboard_get_default((display is null) ? null : display.getDisplayStruct()); 179 180 if(p is null) 181 { 182 return null; 183 } 184 185 return ObjectG.getDObject!(Clipboard)(cast(GtkClipboard*) p); 186 } 187 188 /** 189 * Returns the clipboard object for the given selection. 190 * Cut/copy/paste menu items and keyboard shortcuts should use 191 * the default clipboard, returned by passing %GDK_SELECTION_CLIPBOARD for @selection. 192 * (%GDK_NONE is supported as a synonym for GDK_SELECTION_CLIPBOARD 193 * for backwards compatibility reasons.) 194 * The currently-selected object or text should be provided on the clipboard 195 * identified by #GDK_SELECTION_PRIMARY. Cut/copy/paste menu items 196 * conceptually copy the contents of the #GDK_SELECTION_PRIMARY clipboard 197 * to the default clipboard, i.e. they copy the selection to what the 198 * user sees as the clipboard. 199 * 200 * (Passing #GDK_NONE is the same as using `gdk_atom_intern 201 * ("CLIPBOARD", FALSE)`. 202 * 203 * See the 204 * [FreeDesktop Clipboard Specification](http://www.freedesktop.org/Standards/clipboards-spec) 205 * for a detailed discussion of the “CLIPBOARD” vs. “PRIMARY” 206 * selections under the X window system. On Win32 the 207 * #GDK_SELECTION_PRIMARY clipboard is essentially ignored.) 208 * 209 * It’s possible to have arbitrary named clipboards; if you do invent 210 * new clipboards, you should prefix the selection name with an 211 * underscore (because the ICCCM requires that nonstandard atoms are 212 * underscore-prefixed), and namespace it as well. For example, 213 * if your application called “Foo” has a special-purpose 214 * clipboard, you might call it “_FOO_SPECIAL_CLIPBOARD”. 215 * 216 * Params: 217 * display = the #GdkDisplay for which the clipboard is to be retrieved or created. 218 * selection = a #GdkAtom which identifies the clipboard to use. 219 * 220 * Returns: the appropriate clipboard object. If no 221 * clipboard already exists, a new one will be created. Once a clipboard 222 * object has been created, it is persistent and, since it is owned by 223 * GTK+, must not be freed or unrefd. 224 * 225 * Since: 2.2 226 */ 227 public static Clipboard getForDisplay(Display display, GdkAtom selection) 228 { 229 auto p = gtk_clipboard_get_for_display((display is null) ? null : display.getDisplayStruct(), selection); 230 231 if(p is null) 232 { 233 return null; 234 } 235 236 return ObjectG.getDObject!(Clipboard)(cast(GtkClipboard*) p); 237 } 238 239 /** 240 * Clears the contents of the clipboard. Generally this should only 241 * be called between the time you call gtk_clipboard_set_with_owner() 242 * or gtk_clipboard_set_with_data(), 243 * and when the @clear_func you supplied is called. Otherwise, the 244 * clipboard may be owned by someone else. 245 */ 246 public void clear() 247 { 248 gtk_clipboard_clear(gtkClipboard); 249 } 250 251 /** 252 * Gets the #GdkDisplay associated with @clipboard 253 * 254 * Returns: the #GdkDisplay associated with @clipboard 255 * 256 * Since: 2.2 257 */ 258 public Display getDisplay() 259 { 260 auto p = gtk_clipboard_get_display(gtkClipboard); 261 262 if(p is null) 263 { 264 return null; 265 } 266 267 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p); 268 } 269 270 /** 271 * If the clipboard contents callbacks were set with 272 * gtk_clipboard_set_with_owner(), and the gtk_clipboard_set_with_data() or 273 * gtk_clipboard_clear() has not subsequently called, returns the owner set 274 * by gtk_clipboard_set_with_owner(). 275 * 276 * Returns: the owner of the clipboard, if any; 277 * otherwise %NULL. 278 */ 279 public ObjectG getOwner() 280 { 281 auto p = gtk_clipboard_get_owner(gtkClipboard); 282 283 if(p is null) 284 { 285 return null; 286 } 287 288 return ObjectG.getDObject!(ObjectG)(cast(GObject*) p); 289 } 290 291 /** 292 * Gets the selection that this clipboard is for. 293 * 294 * Returns: the selection 295 * 296 * Since: 3.22 297 */ 298 public GdkAtom getSelection() 299 { 300 return gtk_clipboard_get_selection(gtkClipboard); 301 } 302 303 /** 304 * Requests the contents of clipboard as the given target. 305 * When the results of the result are later received the supplied callback 306 * will be called. 307 * 308 * Params: 309 * target = an atom representing the form into which the clipboard 310 * owner should convert the selection. 311 * callback = A function to call when the results are received 312 * (or the retrieval fails). If the retrieval fails the length field of 313 * @selection_data will be negative. 314 * userData = user data to pass to @callback 315 */ 316 public void requestContents(GdkAtom target, GtkClipboardReceivedFunc callback, void* userData) 317 { 318 gtk_clipboard_request_contents(gtkClipboard, target, callback, userData); 319 } 320 321 /** 322 * Requests the contents of the clipboard as image. When the image is 323 * later received, it will be converted to a #GdkPixbuf, and 324 * @callback will be called. 325 * 326 * The @pixbuf parameter to @callback will contain the resulting 327 * #GdkPixbuf if the request succeeded, or %NULL if it failed. This 328 * could happen for various reasons, in particular if the clipboard 329 * was empty or if the contents of the clipboard could not be 330 * converted into an image. 331 * 332 * Params: 333 * callback = a function to call when the image is received, 334 * or the retrieval fails. (It will always be called one way or the other.) 335 * userData = user data to pass to @callback. 336 * 337 * Since: 2.6 338 */ 339 public void requestImage(GtkClipboardImageReceivedFunc callback, void* userData) 340 { 341 gtk_clipboard_request_image(gtkClipboard, callback, userData); 342 } 343 344 /** 345 * Requests the contents of the clipboard as rich text. When the rich 346 * text is later received, @callback will be called. 347 * 348 * The @text parameter to @callback will contain the resulting rich 349 * text if the request succeeded, or %NULL if it failed. The @length 350 * parameter will contain @text’s length. This function can fail for 351 * various reasons, in particular if the clipboard was empty or if the 352 * contents of the clipboard could not be converted into rich text form. 353 * 354 * Params: 355 * buffer = a #GtkTextBuffer 356 * callback = a function to call when the text is received, 357 * or the retrieval fails. (It will always be called one way or the other.) 358 * userData = user data to pass to @callback. 359 * 360 * Since: 2.10 361 */ 362 public void requestRichText(TextBuffer buffer, GtkClipboardRichTextReceivedFunc callback, void* userData) 363 { 364 gtk_clipboard_request_rich_text(gtkClipboard, (buffer is null) ? null : buffer.getTextBufferStruct(), callback, userData); 365 } 366 367 /** 368 * Requests the contents of the clipboard as list of supported targets. 369 * When the list is later received, @callback will be called. 370 * 371 * The @targets parameter to @callback will contain the resulting targets if 372 * the request succeeded, or %NULL if it failed. 373 * 374 * Params: 375 * callback = a function to call when the targets are 376 * received, or the retrieval fails. (It will always be called 377 * one way or the other.) 378 * userData = user data to pass to @callback. 379 * 380 * Since: 2.4 381 */ 382 public void requestTargets(GtkClipboardTargetsReceivedFunc callback, void* userData) 383 { 384 gtk_clipboard_request_targets(gtkClipboard, callback, userData); 385 } 386 387 /** 388 * Requests the contents of the clipboard as text. When the text is 389 * later received, it will be converted to UTF-8 if necessary, and 390 * @callback will be called. 391 * 392 * The @text parameter to @callback will contain the resulting text if 393 * the request succeeded, or %NULL if it failed. This could happen for 394 * various reasons, in particular if the clipboard was empty or if the 395 * contents of the clipboard could not be converted into text form. 396 * 397 * Params: 398 * callback = a function to call when the text is received, 399 * or the retrieval fails. (It will always be called one way or the other.) 400 * userData = user data to pass to @callback. 401 */ 402 public void requestText(GtkClipboardTextReceivedFunc callback, void* userData) 403 { 404 gtk_clipboard_request_text(gtkClipboard, callback, userData); 405 } 406 407 /** 408 * Requests the contents of the clipboard as URIs. When the URIs are 409 * later received @callback will be called. 410 * 411 * The @uris parameter to @callback will contain the resulting array of 412 * URIs if the request succeeded, or %NULL if it failed. This could happen 413 * for various reasons, in particular if the clipboard was empty or if the 414 * contents of the clipboard could not be converted into URI form. 415 * 416 * Params: 417 * callback = a function to call when the URIs are received, 418 * or the retrieval fails. (It will always be called one way or the other.) 419 * userData = user data to pass to @callback. 420 * 421 * Since: 2.14 422 */ 423 public void requestUris(GtkClipboardURIReceivedFunc callback, void* userData) 424 { 425 gtk_clipboard_request_uris(gtkClipboard, callback, userData); 426 } 427 428 /** 429 * Hints that the clipboard data should be stored somewhere when the 430 * application exits or when gtk_clipboard_store () is called. 431 * 432 * This value is reset when the clipboard owner changes. 433 * Where the clipboard data is stored is platform dependent, 434 * see gdk_display_store_clipboard () for more information. 435 * 436 * Params: 437 * targets = array containing 438 * information about which forms should be stored or %NULL 439 * to indicate that all forms should be stored. 440 * nTargets = number of elements in @targets 441 * 442 * Since: 2.6 443 */ 444 public void setCanStore(TargetEntry[] targets) 445 { 446 GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length]; 447 for ( int i = 0; i < targets.length; i++ ) 448 { 449 targetsArray[i] = *(targets[i].getTargetEntryStruct()); 450 } 451 452 gtk_clipboard_set_can_store(gtkClipboard, targetsArray.ptr, cast(int)targets.length); 453 } 454 455 /** 456 * Sets the contents of the clipboard to the given #GdkPixbuf. 457 * GTK+ will take responsibility for responding for requests 458 * for the image, and for converting the image into the 459 * requested format. 460 * 461 * Params: 462 * pixbuf = a #GdkPixbuf 463 * 464 * Since: 2.6 465 */ 466 public void setImage(Pixbuf pixbuf) 467 { 468 gtk_clipboard_set_image(gtkClipboard, (pixbuf is null) ? null : pixbuf.getPixbufStruct()); 469 } 470 471 /** 472 * Sets the contents of the clipboard to the given UTF-8 string. GTK+ will 473 * make a copy of the text and take responsibility for responding 474 * for requests for the text, and for converting the text into 475 * the requested format. 476 * 477 * Params: 478 * text = a UTF-8 string. 479 * len = length of @text, in bytes, or -1, in which case 480 * the length will be determined with strlen(). 481 */ 482 public void setText(string text, int len) 483 { 484 gtk_clipboard_set_text(gtkClipboard, Str.toStringz(text), len); 485 } 486 487 /** 488 * Virtually sets the contents of the specified clipboard by providing 489 * a list of supported formats for the clipboard data and a function 490 * to call to get the actual data when it is requested. 491 * 492 * Params: 493 * targets = array containing information 494 * about the available forms for the clipboard data 495 * nTargets = number of elements in @targets 496 * getFunc = function to call to get the actual clipboard data 497 * clearFunc = when the clipboard contents are set again, 498 * this function will be called, and @get_func will not be subsequently 499 * called. 500 * userData = user data to pass to @get_func and @clear_func. 501 * 502 * Returns: %TRUE if setting the clipboard data succeeded. 503 * If setting the clipboard data failed the provided callback 504 * functions will be ignored. 505 */ 506 public bool setWithData(TargetEntry[] targets, GtkClipboardGetFunc getFunc, GtkClipboardClearFunc clearFunc, void* userData) 507 { 508 GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length]; 509 for ( int i = 0; i < targets.length; i++ ) 510 { 511 targetsArray[i] = *(targets[i].getTargetEntryStruct()); 512 } 513 514 return gtk_clipboard_set_with_data(gtkClipboard, targetsArray.ptr, cast(uint)targets.length, getFunc, clearFunc, userData) != 0; 515 } 516 517 /** 518 * Virtually sets the contents of the specified clipboard by providing 519 * a list of supported formats for the clipboard data and a function 520 * to call to get the actual data when it is requested. 521 * 522 * The difference between this function and gtk_clipboard_set_with_data() 523 * is that instead of an generic @user_data pointer, a #GObject is passed 524 * in. 525 * 526 * Params: 527 * targets = array containing information 528 * about the available forms for the clipboard data 529 * nTargets = number of elements in @targets 530 * getFunc = function to call to get the actual clipboard data 531 * clearFunc = when the clipboard contents are set again, 532 * this function will be called, and @get_func will not be subsequently 533 * called 534 * owner = an object that “owns” the data. This object will be passed 535 * to the callbacks when called 536 * 537 * Returns: %TRUE if setting the clipboard data succeeded. 538 * If setting the clipboard data failed the provided callback 539 * functions will be ignored. 540 */ 541 public bool setWithOwner(TargetEntry[] targets, GtkClipboardGetFunc getFunc, GtkClipboardClearFunc clearFunc, ObjectG owner) 542 { 543 GtkTargetEntry[] targetsArray = new GtkTargetEntry[targets.length]; 544 for ( int i = 0; i < targets.length; i++ ) 545 { 546 targetsArray[i] = *(targets[i].getTargetEntryStruct()); 547 } 548 549 return gtk_clipboard_set_with_owner(gtkClipboard, targetsArray.ptr, cast(uint)targets.length, getFunc, clearFunc, (owner is null) ? null : owner.getObjectGStruct()) != 0; 550 } 551 552 /** 553 * Stores the current clipboard data somewhere so that it will stay 554 * around after the application has quit. 555 * 556 * Since: 2.6 557 */ 558 public void store() 559 { 560 gtk_clipboard_store(gtkClipboard); 561 } 562 563 /** 564 * Requests the contents of the clipboard using the given target. 565 * This function waits for the data to be received using the main 566 * loop, so events, timeouts, etc, may be dispatched during the wait. 567 * 568 * Params: 569 * target = an atom representing the form into which the clipboard 570 * owner should convert the selection. 571 * 572 * Returns: a newly-allocated #GtkSelectionData object or %NULL 573 * if retrieving the given target failed. If non-%NULL, 574 * this value must be freed with gtk_selection_data_free() 575 * when you are finished with it. 576 */ 577 public SelectionData waitForContents(GdkAtom target) 578 { 579 auto p = gtk_clipboard_wait_for_contents(gtkClipboard, target); 580 581 if(p is null) 582 { 583 return null; 584 } 585 586 return ObjectG.getDObject!(SelectionData)(cast(GtkSelectionData*) p, true); 587 } 588 589 /** 590 * Requests the contents of the clipboard as image and converts 591 * the result to a #GdkPixbuf. This function waits for 592 * the data to be received using the main loop, so events, 593 * timeouts, etc, may be dispatched during the wait. 594 * 595 * Returns: a newly-allocated #GdkPixbuf 596 * object which must be disposed with g_object_unref(), or 597 * %NULL if retrieving the selection data failed. (This could 598 * happen for various reasons, in particular if the clipboard 599 * was empty or if the contents of the clipboard could not be 600 * converted into an image.) 601 * 602 * Since: 2.6 603 */ 604 public Pixbuf waitForImage() 605 { 606 auto p = gtk_clipboard_wait_for_image(gtkClipboard); 607 608 if(p is null) 609 { 610 return null; 611 } 612 613 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true); 614 } 615 616 /** 617 * Requests the contents of the clipboard as rich text. This function 618 * waits for the data to be received using the main loop, so events, 619 * timeouts, etc, may be dispatched during the wait. 620 * 621 * Params: 622 * buffer = a #GtkTextBuffer 623 * format = return location for the format of the returned data 624 * 625 * Returns: a 626 * newly-allocated binary block of data which must be 627 * freed with g_free(), or %NULL if retrieving the 628 * selection data failed. (This could happen for various 629 * reasons, in particular if the clipboard was empty or 630 * if the contents of the clipboard could not be 631 * converted into text form.) 632 * 633 * Since: 2.10 634 */ 635 public ubyte[] waitForRichText(TextBuffer buffer, out GdkAtom format) 636 { 637 size_t length; 638 639 auto p = gtk_clipboard_wait_for_rich_text(gtkClipboard, (buffer is null) ? null : buffer.getTextBufferStruct(), &format, &length); 640 641 return p[0 .. length]; 642 } 643 644 /** 645 * Returns a list of targets that are present on the clipboard, or %NULL 646 * if there aren’t any targets available. The returned list must be 647 * freed with g_free(). 648 * This function waits for the data to be received using the main 649 * loop, so events, timeouts, etc, may be dispatched during the wait. 650 * 651 * Params: 652 * targets = location 653 * to store an array of targets. The result stored here must 654 * be freed with g_free(). 655 * nTargets = location to store number of items in @targets. 656 * 657 * Returns: %TRUE if any targets are present on the clipboard, 658 * otherwise %FALSE. 659 * 660 * Since: 2.4 661 */ 662 public bool waitForTargets(out GdkAtom[] targets) 663 { 664 GdkAtom* outtargets = null; 665 int nTargets; 666 667 auto p = gtk_clipboard_wait_for_targets(gtkClipboard, &outtargets, &nTargets) != 0; 668 669 targets = outtargets[0 .. nTargets]; 670 671 return p; 672 } 673 674 /** 675 * Requests the contents of the clipboard as text and converts 676 * the result to UTF-8 if necessary. This function waits for 677 * the data to be received using the main loop, so events, 678 * timeouts, etc, may be dispatched during the wait. 679 * 680 * Returns: a newly-allocated UTF-8 string which must 681 * be freed with g_free(), or %NULL if retrieving 682 * the selection data failed. (This could happen 683 * for various reasons, in particular if the 684 * clipboard was empty or if the contents of the 685 * clipboard could not be converted into text form.) 686 */ 687 public string waitForText() 688 { 689 auto retStr = gtk_clipboard_wait_for_text(gtkClipboard); 690 691 scope(exit) Str.freeString(retStr); 692 return Str.toString(retStr); 693 } 694 695 /** 696 * Requests the contents of the clipboard as URIs. This function waits 697 * for the data to be received using the main loop, so events, 698 * timeouts, etc, may be dispatched during the wait. 699 * 700 * Returns: a newly-allocated %NULL-terminated array of strings which must 701 * be freed with g_strfreev(), or %NULL if retrieving the 702 * selection data failed. (This could happen for various reasons, 703 * in particular if the clipboard was empty or if the contents of 704 * the clipboard could not be converted into URI form.) 705 * 706 * Since: 2.14 707 */ 708 public string[] waitForUris() 709 { 710 auto retStr = gtk_clipboard_wait_for_uris(gtkClipboard); 711 712 scope(exit) Str.freeStringArray(retStr); 713 return Str.toStringArray(retStr); 714 } 715 716 /** 717 * Test to see if there is an image available to be pasted 718 * This is done by requesting the TARGETS atom and checking 719 * if it contains any of the supported image targets. This function 720 * waits for the data to be received using the main loop, so events, 721 * timeouts, etc, may be dispatched during the wait. 722 * 723 * This function is a little faster than calling 724 * gtk_clipboard_wait_for_image() since it doesn’t need to retrieve 725 * the actual image data. 726 * 727 * Returns: %TRUE is there is an image available, %FALSE otherwise. 728 * 729 * Since: 2.6 730 */ 731 public bool waitIsImageAvailable() 732 { 733 return gtk_clipboard_wait_is_image_available(gtkClipboard) != 0; 734 } 735 736 /** 737 * Test to see if there is rich text available to be pasted 738 * This is done by requesting the TARGETS atom and checking 739 * if it contains any of the supported rich text targets. This function 740 * waits for the data to be received using the main loop, so events, 741 * timeouts, etc, may be dispatched during the wait. 742 * 743 * This function is a little faster than calling 744 * gtk_clipboard_wait_for_rich_text() since it doesn’t need to retrieve 745 * the actual text. 746 * 747 * Params: 748 * buffer = a #GtkTextBuffer 749 * 750 * Returns: %TRUE is there is rich text available, %FALSE otherwise. 751 * 752 * Since: 2.10 753 */ 754 public bool waitIsRichTextAvailable(TextBuffer buffer) 755 { 756 return gtk_clipboard_wait_is_rich_text_available(gtkClipboard, (buffer is null) ? null : buffer.getTextBufferStruct()) != 0; 757 } 758 759 /** 760 * Checks if a clipboard supports pasting data of a given type. This 761 * function can be used to determine if a “Paste” menu item should be 762 * insensitive or not. 763 * 764 * If you want to see if there’s text available on the clipboard, use 765 * gtk_clipboard_wait_is_text_available () instead. 766 * 767 * Params: 768 * target = A #GdkAtom indicating which target to look for. 769 * 770 * Returns: %TRUE if the target is available, %FALSE otherwise. 771 * 772 * Since: 2.6 773 */ 774 public bool waitIsTargetAvailable(GdkAtom target) 775 { 776 return gtk_clipboard_wait_is_target_available(gtkClipboard, target) != 0; 777 } 778 779 /** 780 * Test to see if there is text available to be pasted 781 * This is done by requesting the TARGETS atom and checking 782 * if it contains any of the supported text targets. This function 783 * waits for the data to be received using the main loop, so events, 784 * timeouts, etc, may be dispatched during the wait. 785 * 786 * This function is a little faster than calling 787 * gtk_clipboard_wait_for_text() since it doesn’t need to retrieve 788 * the actual text. 789 * 790 * Returns: %TRUE is there is text available, %FALSE otherwise. 791 */ 792 public bool waitIsTextAvailable() 793 { 794 return gtk_clipboard_wait_is_text_available(gtkClipboard) != 0; 795 } 796 797 /** 798 * Test to see if there is a list of URIs available to be pasted 799 * This is done by requesting the TARGETS atom and checking 800 * if it contains the URI targets. This function 801 * waits for the data to be received using the main loop, so events, 802 * timeouts, etc, may be dispatched during the wait. 803 * 804 * This function is a little faster than calling 805 * gtk_clipboard_wait_for_uris() since it doesn’t need to retrieve 806 * the actual URI data. 807 * 808 * Returns: %TRUE is there is an URI list available, %FALSE otherwise. 809 * 810 * Since: 2.14 811 */ 812 public bool waitIsUrisAvailable() 813 { 814 return gtk_clipboard_wait_is_uris_available(gtkClipboard) != 0; 815 } 816 817 protected class OnOwnerChangeDelegateWrapper 818 { 819 void delegate(GdkEventOwnerChange*, Clipboard) dlg; 820 gulong handlerId; 821 822 this(void delegate(GdkEventOwnerChange*, Clipboard) dlg) 823 { 824 this.dlg = dlg; 825 onOwnerChangeListeners ~= this; 826 } 827 828 void remove(OnOwnerChangeDelegateWrapper source) 829 { 830 foreach(index, wrapper; onOwnerChangeListeners) 831 { 832 if (wrapper.handlerId == source.handlerId) 833 { 834 onOwnerChangeListeners[index] = null; 835 onOwnerChangeListeners = std.algorithm.remove(onOwnerChangeListeners, index); 836 break; 837 } 838 } 839 } 840 } 841 OnOwnerChangeDelegateWrapper[] onOwnerChangeListeners; 842 843 /** 844 * The ::owner-change signal is emitted when GTK+ receives an 845 * event that indicates that the ownership of the selection 846 * associated with @clipboard has changed. 847 * 848 * Params: 849 * event = the @GdkEventOwnerChange event 850 * 851 * Since: 2.6 852 */ 853 gulong addOnOwnerChange(void delegate(GdkEventOwnerChange*, Clipboard) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 854 { 855 auto wrapper = new OnOwnerChangeDelegateWrapper(dlg); 856 wrapper.handlerId = Signals.connectData( 857 this, 858 "owner-change", 859 cast(GCallback)&callBackOwnerChange, 860 cast(void*)wrapper, 861 cast(GClosureNotify)&callBackOwnerChangeDestroy, 862 connectFlags); 863 return wrapper.handlerId; 864 } 865 866 extern(C) static void callBackOwnerChange(GtkClipboard* clipboardStruct, GdkEventOwnerChange* event, OnOwnerChangeDelegateWrapper wrapper) 867 { 868 wrapper.dlg(event, wrapper.outer); 869 } 870 871 extern(C) static void callBackOwnerChangeDestroy(OnOwnerChangeDelegateWrapper wrapper, GClosure* closure) 872 { 873 wrapper.remove(wrapper); 874 } 875 876 protected class OnOwnerChangeGenericDelegateWrapper 877 { 878 void delegate(Event, Clipboard) dlg; 879 gulong handlerId; 880 881 this(void delegate(Event, Clipboard) dlg) 882 { 883 this.dlg = dlg; 884 onOwnerChangeGenericListeners ~= this; 885 } 886 887 void remove(OnOwnerChangeGenericDelegateWrapper source) 888 { 889 foreach(index, wrapper; onOwnerChangeGenericListeners) 890 { 891 if (wrapper.handlerId == source.handlerId) 892 { 893 onOwnerChangeGenericListeners[index] = null; 894 onOwnerChangeGenericListeners = std.algorithm.remove(onOwnerChangeGenericListeners, index); 895 break; 896 } 897 } 898 } 899 } 900 OnOwnerChangeGenericDelegateWrapper[] onOwnerChangeGenericListeners; 901 902 /** 903 * The ::owner-change signal is emitted when GTK+ receives an 904 * event that indicates that the ownership of the selection 905 * associated with @clipboard has changed. 906 * 907 * Params: 908 * event = the @GdkEventOwnerChange event 909 * 910 * Since: 2.6 911 */ 912 gulong addOnOwnerChange(void delegate(Event, Clipboard) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 913 { 914 auto wrapper = new OnOwnerChangeGenericDelegateWrapper(dlg); 915 wrapper.handlerId = Signals.connectData( 916 this, 917 "owner-change", 918 cast(GCallback)&callBackOwnerChangeGeneric, 919 cast(void*)wrapper, 920 cast(GClosureNotify)&callBackOwnerChangeGenericDestroy, 921 connectFlags); 922 return wrapper.handlerId; 923 } 924 925 extern(C) static void callBackOwnerChangeGeneric(GtkClipboard* clipboardStruct, GdkEvent* event, OnOwnerChangeGenericDelegateWrapper wrapper) 926 { 927 wrapper.dlg(ObjectG.getDObject!(Event)(event), wrapper.outer); 928 } 929 930 extern(C) static void callBackOwnerChangeGenericDestroy(OnOwnerChangeGenericDelegateWrapper wrapper, GClosure* closure) 931 { 932 wrapper.remove(wrapper); 933 } 934 }