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