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.SelectionData; 26 27 private import gdk.Display; 28 private import gdkpixbuf.Pixbuf; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gtk.TargetEntry; 32 private import gtk.TextBuffer; 33 private import gtk.Widget; 34 private import gtkc.gtk; 35 public import gtkc.gtktypes; 36 37 38 public class SelectionData 39 { 40 /** the main Gtk struct */ 41 protected GtkSelectionData* gtkSelectionData; 42 43 /** Get the main Gtk struct */ 44 public GtkSelectionData* getSelectionDataStruct() 45 { 46 return gtkSelectionData; 47 } 48 49 /** the main Gtk struct as a void* */ 50 protected void* getStruct() 51 { 52 return cast(void*)gtkSelectionData; 53 } 54 55 /** 56 * Sets our main struct and passes it to the parent class. 57 */ 58 public this (GtkSelectionData* gtkSelectionData) 59 { 60 this.gtkSelectionData = gtkSelectionData; 61 } 62 63 /** 64 */ 65 66 public static GType getType() 67 { 68 return gtk_selection_data_get_type(); 69 } 70 71 /** 72 * Makes a copy of a #GtkSelectionData-struct and its data. 73 * 74 * Return: a pointer to a copy of @data. 75 */ 76 public SelectionData copy() 77 { 78 auto p = gtk_selection_data_copy(gtkSelectionData); 79 80 if(p is null) 81 { 82 return null; 83 } 84 85 return ObjectG.getDObject!(SelectionData)(cast(GtkSelectionData*) p); 86 } 87 88 /** 89 * Frees a #GtkSelectionData-struct returned from 90 * gtk_selection_data_copy(). 91 */ 92 public void free() 93 { 94 gtk_selection_data_free(gtkSelectionData); 95 } 96 97 /** 98 * Retrieves the raw data of the selection. 99 * 100 * Return: the raw data of the selection. 101 * 102 * Since: 2.14 103 */ 104 public string getData() 105 { 106 return Str.toString(gtk_selection_data_get_data(gtkSelectionData)); 107 } 108 109 /** 110 * Retrieves the data type of the selection. 111 * 112 * Return: the data type of the selection. 113 * 114 * Since: 2.14 115 */ 116 public GdkAtom getDataType() 117 { 118 return gtk_selection_data_get_data_type(gtkSelectionData); 119 } 120 121 /** 122 * Retrieves the raw data of the selection along with its length. 123 * 124 * Params: 125 * length = return location for length of the data segment 126 * 127 * Return: the raw data of the selection 128 * 129 * Since: 3.0 130 */ 131 public string getDataWithLength() 132 { 133 int length; 134 135 return Str.toString(gtk_selection_data_get_data_with_length(gtkSelectionData, &length)); 136 } 137 138 /** 139 * Retrieves the display of the selection. 140 * 141 * Return: the display of the selection. 142 * 143 * Since: 2.14 144 */ 145 public Display getDisplay() 146 { 147 auto p = gtk_selection_data_get_display(gtkSelectionData); 148 149 if(p is null) 150 { 151 return null; 152 } 153 154 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p); 155 } 156 157 /** 158 * Retrieves the format of the selection. 159 * 160 * Return: the format of the selection. 161 * 162 * Since: 2.14 163 */ 164 public int getFormat() 165 { 166 return gtk_selection_data_get_format(gtkSelectionData); 167 } 168 169 /** 170 * Retrieves the length of the raw data of the selection. 171 * 172 * Return: the length of the data of the selection. 173 * 174 * Since: 2.14 175 */ 176 public int getLength() 177 { 178 return gtk_selection_data_get_length(gtkSelectionData); 179 } 180 181 /** 182 * Gets the contents of the selection data as a #GdkPixbuf. 183 * 184 * Return: if the selection data 185 * contained a recognized image type and it could be converted to a 186 * #GdkPixbuf, a newly allocated pixbuf is returned, otherwise 187 * %NULL. If the result is non-%NULL it must be freed with 188 * g_object_unref(). 189 * 190 * Since: 2.6 191 */ 192 public Pixbuf getPixbuf() 193 { 194 auto p = gtk_selection_data_get_pixbuf(gtkSelectionData); 195 196 if(p is null) 197 { 198 return null; 199 } 200 201 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true); 202 } 203 204 /** 205 * Retrieves the selection #GdkAtom of the selection data. 206 * 207 * Return: the selection #GdkAtom of the selection data. 208 * 209 * Since: 2.16 210 */ 211 public GdkAtom getSelection() 212 { 213 return gtk_selection_data_get_selection(gtkSelectionData); 214 } 215 216 /** 217 * Retrieves the target of the selection. 218 * 219 * Return: the target of the selection. 220 * 221 * Since: 2.14 222 */ 223 public GdkAtom getTarget() 224 { 225 return gtk_selection_data_get_target(gtkSelectionData); 226 } 227 228 /** 229 * Gets the contents of @selection_data as an array of targets. 230 * This can be used to interpret the results of getting 231 * the standard TARGETS target that is always supplied for 232 * any selection. 233 * 234 * Params: 235 * targets = location to store an array of targets. The result stored 236 * here must be freed with g_free(). 237 * nAtoms = location to store number of items in @targets. 238 * 239 * Return: %TRUE if @selection_data contains a valid 240 * array of targets, otherwise %FALSE. 241 */ 242 public bool getTargets(out GdkAtom[] targets) 243 { 244 GdkAtom* outtargets = null; 245 int nAtoms; 246 247 auto p = gtk_selection_data_get_targets(gtkSelectionData, &outtargets, &nAtoms) != 0; 248 249 targets = outtargets[0 .. nAtoms]; 250 251 return p; 252 } 253 254 /** 255 * Gets the contents of the selection data as a UTF-8 string. 256 * 257 * Return: if the selection data contained a 258 * recognized text type and it could be converted to UTF-8, a newly 259 * allocated string containing the converted text, otherwise %NULL. 260 * If the result is non-%NULL it must be freed with g_free(). 261 */ 262 public string getText() 263 { 264 return Str.toString(gtk_selection_data_get_text(gtkSelectionData)); 265 } 266 267 /** 268 * Gets the contents of the selection data as array of URIs. 269 * 270 * Return: if 271 * the selection data contains a list of 272 * URIs, a newly allocated %NULL-terminated string array 273 * containing the URIs, otherwise %NULL. If the result is 274 * non-%NULL it must be freed with g_strfreev(). 275 * 276 * Since: 2.6 277 */ 278 public string[] getUris() 279 { 280 return Str.toStringArray(gtk_selection_data_get_uris(gtkSelectionData)); 281 } 282 283 /** 284 * Stores new data into a #GtkSelectionData object. Should 285 * only be called from a selection handler callback. 286 * Zero-terminates the stored data. 287 * 288 * Params: 289 * type = the type of selection data 290 * format = format (number of bits in a unit) 291 * data = pointer to the data (will be copied) 292 * length = length of the data 293 */ 294 public void set(GdkAtom type, int format, string data) 295 { 296 gtk_selection_data_set(gtkSelectionData, type, format, Str.toStringz(data), cast(int)data.length); 297 } 298 299 /** 300 * Sets the contents of the selection from a #GdkPixbuf 301 * The pixbuf is converted to the form determined by 302 * @selection_data->target. 303 * 304 * Params: 305 * pixbuf = a #GdkPixbuf 306 * 307 * Return: %TRUE if the selection was successfully set, 308 * otherwise %FALSE. 309 * 310 * Since: 2.6 311 */ 312 public bool setPixbuf(Pixbuf pixbuf) 313 { 314 return gtk_selection_data_set_pixbuf(gtkSelectionData, (pixbuf is null) ? null : pixbuf.getPixbufStruct()) != 0; 315 } 316 317 /** 318 * Sets the contents of the selection from a UTF-8 encoded string. 319 * The string is converted to the form determined by 320 * @selection_data->target. 321 * 322 * Params: 323 * str = a UTF-8 string 324 * len = the length of @str, or -1 if @str is nul-terminated. 325 * 326 * Return: %TRUE if the selection was successfully set, 327 * otherwise %FALSE. 328 */ 329 public bool setText(string str, int len) 330 { 331 return gtk_selection_data_set_text(gtkSelectionData, Str.toStringz(str), len) != 0; 332 } 333 334 /** 335 * Sets the contents of the selection from a list of URIs. 336 * The string is converted to the form determined by 337 * @selection_data->target. 338 * 339 * Params: 340 * uris = a %NULL-terminated array of 341 * strings holding URIs 342 * 343 * Return: %TRUE if the selection was successfully set, 344 * otherwise %FALSE. 345 * 346 * Since: 2.6 347 */ 348 public bool setUris(string[] uris) 349 { 350 return gtk_selection_data_set_uris(gtkSelectionData, Str.toStringzArray(uris)) != 0; 351 } 352 353 /** 354 * Given a #GtkSelectionData object holding a list of targets, 355 * determines if any of the targets in @targets can be used to 356 * provide a #GdkPixbuf. 357 * 358 * Params: 359 * writable = whether to accept only targets for which GTK+ knows 360 * how to convert a pixbuf into the format 361 * 362 * Return: %TRUE if @selection_data holds a list of targets, 363 * and a suitable target for images is included, otherwise %FALSE. 364 * 365 * Since: 2.6 366 */ 367 public bool targetsIncludeImage(bool writable) 368 { 369 return gtk_selection_data_targets_include_image(gtkSelectionData, writable) != 0; 370 } 371 372 /** 373 * Given a #GtkSelectionData object holding a list of targets, 374 * determines if any of the targets in @targets can be used to 375 * provide rich text. 376 * 377 * Params: 378 * buffer = a #GtkTextBuffer 379 * 380 * Return: %TRUE if @selection_data holds a list of targets, 381 * and a suitable target for rich text is included, 382 * otherwise %FALSE. 383 * 384 * Since: 2.10 385 */ 386 public bool targetsIncludeRichText(TextBuffer buffer) 387 { 388 return gtk_selection_data_targets_include_rich_text(gtkSelectionData, (buffer is null) ? null : buffer.getTextBufferStruct()) != 0; 389 } 390 391 /** 392 * Given a #GtkSelectionData object holding a list of targets, 393 * determines if any of the targets in @targets can be used to 394 * provide text. 395 * 396 * Return: %TRUE if @selection_data holds a list of targets, 397 * and a suitable target for text is included, otherwise %FALSE. 398 */ 399 public bool targetsIncludeText() 400 { 401 return gtk_selection_data_targets_include_text(gtkSelectionData) != 0; 402 } 403 404 /** 405 * Given a #GtkSelectionData object holding a list of targets, 406 * determines if any of the targets in @targets can be used to 407 * provide a list or URIs. 408 * 409 * Return: %TRUE if @selection_data holds a list of targets, 410 * and a suitable target for URI lists is included, otherwise %FALSE. 411 * 412 * Since: 2.10 413 */ 414 public bool targetsIncludeUri() 415 { 416 return gtk_selection_data_targets_include_uri(gtkSelectionData) != 0; 417 } 418 419 /** 420 * Appends a specified target to the list of supported targets for a 421 * given widget and selection. 422 * 423 * Params: 424 * widget = a #GtkWidget 425 * selection = the selection 426 * target = target to add. 427 * info = A unsigned integer which will be passed back to the application. 428 */ 429 public static void addTarget(Widget widget, GdkAtom selection, GdkAtom target, uint info) 430 { 431 gtk_selection_add_target((widget is null) ? null : widget.getWidgetStruct(), selection, target, info); 432 } 433 434 /** 435 * Prepends a table of targets to the list of supported targets 436 * for a given widget and selection. 437 * 438 * Params: 439 * widget = a #GtkWidget 440 * selection = the selection 441 * targets = a table of targets to add 442 * ntargets = number of entries in @targets 443 */ 444 public static void addTargets(Widget widget, GdkAtom selection, 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_selection_add_targets((widget is null) ? null : widget.getWidgetStruct(), selection, targetsArray.ptr, cast(uint)targets.length); 453 } 454 455 /** 456 * Remove all targets registered for the given selection for the 457 * widget. 458 * 459 * Params: 460 * widget = a #GtkWidget 461 * selection = an atom representing a selection 462 */ 463 public static void clearTargets(Widget widget, GdkAtom selection) 464 { 465 gtk_selection_clear_targets((widget is null) ? null : widget.getWidgetStruct(), selection); 466 } 467 468 /** 469 * Requests the contents of a selection. When received, 470 * a “selection-received” signal will be generated. 471 * 472 * Params: 473 * widget = The widget which acts as requestor 474 * selection = Which selection to get 475 * target = Form of information desired (e.g., STRING) 476 * time = Time of request (usually of triggering event) 477 * In emergency, you could use #GDK_CURRENT_TIME 478 * 479 * Return: %TRUE if requested succeeded. %FALSE if we could not process 480 * request. (e.g., there was already a request in process for 481 * this widget). 482 */ 483 public static bool convert(Widget widget, GdkAtom selection, GdkAtom target, uint time) 484 { 485 return gtk_selection_convert((widget is null) ? null : widget.getWidgetStruct(), selection, target, time) != 0; 486 } 487 488 /** 489 * Claims ownership of a given selection for a particular widget, 490 * or, if @widget is %NULL, release ownership of the selection. 491 * 492 * Params: 493 * widget = a #GtkWidget, or %NULL. 494 * selection = an interned atom representing the selection to claim 495 * time = timestamp with which to claim the selection 496 * 497 * Return: %TRUE if the operation succeeded 498 */ 499 public static bool ownerSet(Widget widget, GdkAtom selection, uint time) 500 { 501 return gtk_selection_owner_set((widget is null) ? null : widget.getWidgetStruct(), selection, time) != 0; 502 } 503 504 /** 505 * Claim ownership of a given selection for a particular widget, or, 506 * if @widget is %NULL, release ownership of the selection. 507 * 508 * Params: 509 * display = the #GdkDisplay where the selection is set 510 * widget = new selection owner (a #GtkWidget), or %NULL. 511 * selection = an interned atom representing the selection to claim. 512 * time = timestamp with which to claim the selection 513 * 514 * Return: TRUE if the operation succeeded 515 * 516 * Since: 2.2 517 */ 518 public static bool ownerSetForDisplay(Display display, Widget widget, GdkAtom selection, uint time) 519 { 520 return gtk_selection_owner_set_for_display((display is null) ? null : display.getDisplayStruct(), (widget is null) ? null : widget.getWidgetStruct(), selection, time) != 0; 521 } 522 523 /** 524 * Removes all handlers and unsets ownership of all 525 * selections for a widget. Called when widget is being 526 * destroyed. This function will not generally be 527 * called by applications. 528 * 529 * Params: 530 * widget = a #GtkWidget 531 */ 532 public static void removeAll(Widget widget) 533 { 534 gtk_selection_remove_all((widget is null) ? null : widget.getWidgetStruct()); 535 } 536 }