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