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 gdk.DragContext; 26 27 private import gdk.Device; 28 private import gdk.Screen; 29 private import gdk.Window; 30 private import gdk.c.functions; 31 public import gdk.c.types; 32 private import glib.ListG; 33 private import gobject.ObjectG; 34 private import gobject.Signals; 35 public import gtkc.gdktypes; 36 private import std.algorithm; 37 38 39 /** */ 40 public class DragContext : ObjectG 41 { 42 /** the main Gtk struct */ 43 protected GdkDragContext* gdkDragContext; 44 45 /** Get the main Gtk struct */ 46 public GdkDragContext* getDragContextStruct(bool transferOwnership = false) 47 { 48 if (transferOwnership) 49 ownedRef = false; 50 return gdkDragContext; 51 } 52 53 /** the main Gtk struct as a void* */ 54 protected override void* getStruct() 55 { 56 return cast(void*)gdkDragContext; 57 } 58 59 /** 60 * Sets our main struct and passes it to the parent class. 61 */ 62 public this (GdkDragContext* gdkDragContext, bool ownedRef = false) 63 { 64 this.gdkDragContext = gdkDragContext; 65 super(cast(GObject*)gdkDragContext, ownedRef); 66 } 67 68 69 /** */ 70 public static GType getType() 71 { 72 return gdk_drag_context_get_type(); 73 } 74 75 /** 76 * Determines the bitmask of actions proposed by the source if 77 * gdk_drag_context_get_suggested_action() returns %GDK_ACTION_ASK. 78 * 79 * Returns: the #GdkDragAction flags 80 * 81 * Since: 2.22 82 */ 83 public GdkDragAction getActions() 84 { 85 return gdk_drag_context_get_actions(gdkDragContext); 86 } 87 88 /** 89 * Returns the destination window for the DND operation. 90 * 91 * Returns: a #GdkWindow 92 * 93 * Since: 3.0 94 */ 95 public Window getDestWindow() 96 { 97 auto p = gdk_drag_context_get_dest_window(gdkDragContext); 98 99 if(p is null) 100 { 101 return null; 102 } 103 104 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 105 } 106 107 /** 108 * Returns the #GdkDevice associated to the drag context. 109 * 110 * Returns: The #GdkDevice associated to @context. 111 */ 112 public Device getDevice() 113 { 114 auto p = gdk_drag_context_get_device(gdkDragContext); 115 116 if(p is null) 117 { 118 return null; 119 } 120 121 return ObjectG.getDObject!(Device)(cast(GdkDevice*) p); 122 } 123 124 /** 125 * Returns the window on which the drag icon should be rendered 126 * during the drag operation. Note that the window may not be 127 * available until the drag operation has begun. GDK will move 128 * the window in accordance with the ongoing drag operation. 129 * The window is owned by @context and will be destroyed when 130 * the drag operation is over. 131 * 132 * Returns: the drag window, or %NULL 133 * 134 * Since: 3.20 135 */ 136 public Window getDragWindow() 137 { 138 auto p = gdk_drag_context_get_drag_window(gdkDragContext); 139 140 if(p is null) 141 { 142 return null; 143 } 144 145 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 146 } 147 148 /** 149 * Returns the drag protocol that is used by this context. 150 * 151 * Returns: the drag protocol 152 * 153 * Since: 3.0 154 */ 155 public GdkDragProtocol getProtocol() 156 { 157 return gdk_drag_context_get_protocol(gdkDragContext); 158 } 159 160 /** 161 * Determines the action chosen by the drag destination. 162 * 163 * Returns: a #GdkDragAction value 164 * 165 * Since: 2.22 166 */ 167 public GdkDragAction getSelectedAction() 168 { 169 return gdk_drag_context_get_selected_action(gdkDragContext); 170 } 171 172 /** 173 * Returns the #GdkWindow where the DND operation started. 174 * 175 * Returns: a #GdkWindow 176 * 177 * Since: 2.22 178 */ 179 public Window getSourceWindow() 180 { 181 auto p = gdk_drag_context_get_source_window(gdkDragContext); 182 183 if(p is null) 184 { 185 return null; 186 } 187 188 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 189 } 190 191 /** 192 * Determines the suggested drag action of the context. 193 * 194 * Returns: a #GdkDragAction value 195 * 196 * Since: 2.22 197 */ 198 public GdkDragAction getSuggestedAction() 199 { 200 return gdk_drag_context_get_suggested_action(gdkDragContext); 201 } 202 203 /** 204 * Retrieves the list of targets of the context. 205 * 206 * Returns: a #GList of targets 207 * 208 * Since: 2.22 209 */ 210 public ListG listTargets() 211 { 212 auto p = gdk_drag_context_list_targets(gdkDragContext); 213 214 if(p is null) 215 { 216 return null; 217 } 218 219 return new ListG(cast(GList*) p); 220 } 221 222 /** 223 * Requests the drag and drop operation to be managed by @context. 224 * When a drag and drop operation becomes managed, the #GdkDragContext 225 * will internally handle all input and source-side #GdkEventDND events 226 * as required by the windowing system. 227 * 228 * Once the drag and drop operation is managed, the drag context will 229 * emit the following signals: 230 * - The #GdkDragContext::action-changed signal whenever the final action 231 * to be performed by the drag and drop operation changes. 232 * - The #GdkDragContext::drop-performed signal after the user performs 233 * the drag and drop gesture (typically by releasing the mouse button). 234 * - The #GdkDragContext::dnd-finished signal after the drag and drop 235 * operation concludes (after all #GdkSelection transfers happen). 236 * - The #GdkDragContext::cancel signal if the drag and drop operation is 237 * finished but doesn't happen over an accepting destination, or is 238 * cancelled through other means. 239 * 240 * Params: 241 * ipcWindow = Window to use for IPC messaging/events 242 * actions = the actions supported by the drag source 243 * 244 * Returns: #TRUE if the drag and drop operation is managed. 245 * 246 * Since: 3.20 247 */ 248 public bool manageDnd(Window ipcWindow, GdkDragAction actions) 249 { 250 return gdk_drag_context_manage_dnd(gdkDragContext, (ipcWindow is null) ? null : ipcWindow.getWindowStruct(), actions) != 0; 251 } 252 253 /** 254 * Associates a #GdkDevice to @context, so all Drag and Drop events 255 * for @context are emitted as if they came from this device. 256 * 257 * Params: 258 * device = a #GdkDevice 259 */ 260 public void setDevice(Device device) 261 { 262 gdk_drag_context_set_device(gdkDragContext, (device is null) ? null : device.getDeviceStruct()); 263 } 264 265 /** 266 * Sets the position of the drag window that will be kept 267 * under the cursor hotspot. Initially, the hotspot is at the 268 * top left corner of the drag window. 269 * 270 * Params: 271 * hotX = x coordinate of the drag window hotspot 272 * hotY = y coordinate of the drag window hotspot 273 * 274 * Since: 3.20 275 */ 276 public void setHotspot(int hotX, int hotY) 277 { 278 gdk_drag_context_set_hotspot(gdkDragContext, hotX, hotY); 279 } 280 281 /** 282 * A new action is being chosen for the drag and drop operation. 283 * 284 * This signal will only be emitted if the #GdkDragContext manages 285 * the drag and drop operation. See gdk_drag_context_manage_dnd() 286 * for more information. 287 * 288 * Params: 289 * action = The action currently chosen 290 * 291 * Since: 3.20 292 */ 293 gulong addOnActionChanged(void delegate(GdkDragAction, DragContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 294 { 295 return Signals.connect(this, "action-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 296 } 297 298 /** 299 * The drag and drop operation was cancelled. 300 * 301 * This signal will only be emitted if the #GdkDragContext manages 302 * the drag and drop operation. See gdk_drag_context_manage_dnd() 303 * for more information. 304 * 305 * Params: 306 * reason = The reason the context was cancelled 307 * 308 * Since: 3.20 309 */ 310 gulong addOnCancel(void delegate(GdkDragCancelReason, DragContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 311 { 312 return Signals.connect(this, "cancel", dlg, connectFlags ^ ConnectFlags.SWAPPED); 313 } 314 315 /** 316 * The drag and drop operation was finished, the drag destination 317 * finished reading all data. The drag source can now free all 318 * miscellaneous data. 319 * 320 * This signal will only be emitted if the #GdkDragContext manages 321 * the drag and drop operation. See gdk_drag_context_manage_dnd() 322 * for more information. 323 * 324 * Since: 3.20 325 */ 326 gulong addOnDndFinished(void delegate(DragContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 327 { 328 return Signals.connect(this, "dnd-finished", dlg, connectFlags ^ ConnectFlags.SWAPPED); 329 } 330 331 /** 332 * The drag and drop operation was performed on an accepting client. 333 * 334 * This signal will only be emitted if the #GdkDragContext manages 335 * the drag and drop operation. See gdk_drag_context_manage_dnd() 336 * for more information. 337 * 338 * Params: 339 * time = the time at which the drop happened. 340 * 341 * Since: 3.20 342 */ 343 gulong addOnDropPerformed(void delegate(int, DragContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 344 { 345 return Signals.connect(this, "drop-performed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 346 } 347 348 /** 349 * Aborts a drag without dropping. 350 * 351 * This function is called by the drag source. 352 * 353 * This function does not need to be called in managed drag and drop 354 * operations. See gdk_drag_context_manage_dnd() for more information. 355 * 356 * Params: 357 * context = a #GdkDragContext 358 * time = the timestamp for this operation 359 */ 360 public static void dragAbort(DragContext context, uint time) 361 { 362 gdk_drag_abort((context is null) ? null : context.getDragContextStruct(), time); 363 } 364 365 /** 366 * Starts a drag and creates a new drag context for it. 367 * This function assumes that the drag is controlled by the 368 * client pointer device, use gdk_drag_begin_for_device() to 369 * begin a drag with a different device. 370 * 371 * This function is called by the drag source. 372 * 373 * Params: 374 * window = the source window for this drag. 375 * targets = the offered targets, 376 * as list of #GdkAtoms 377 * 378 * Returns: a newly created #GdkDragContext 379 */ 380 public static DragContext dragBegin(Window window, ListG targets) 381 { 382 auto p = gdk_drag_begin((window is null) ? null : window.getWindowStruct(), (targets is null) ? null : targets.getListGStruct()); 383 384 if(p is null) 385 { 386 return null; 387 } 388 389 return ObjectG.getDObject!(DragContext)(cast(GdkDragContext*) p, true); 390 } 391 392 /** 393 * Starts a drag and creates a new drag context for it. 394 * 395 * This function is called by the drag source. 396 * 397 * Params: 398 * window = the source window for this drag 399 * device = the device that controls this drag 400 * targets = the offered targets, 401 * as list of #GdkAtoms 402 * 403 * Returns: a newly created #GdkDragContext 404 */ 405 public static DragContext dragBeginForDevice(Window window, Device device, ListG targets) 406 { 407 auto p = gdk_drag_begin_for_device((window is null) ? null : window.getWindowStruct(), (device is null) ? null : device.getDeviceStruct(), (targets is null) ? null : targets.getListGStruct()); 408 409 if(p is null) 410 { 411 return null; 412 } 413 414 return ObjectG.getDObject!(DragContext)(cast(GdkDragContext*) p, true); 415 } 416 417 /** 418 * Starts a drag and creates a new drag context for it. 419 * 420 * This function is called by the drag source. 421 * 422 * Params: 423 * window = the source window for this drag 424 * device = the device that controls this drag 425 * targets = the offered targets, 426 * as list of #GdkAtoms 427 * xRoot = the x coordinate where the drag nominally started 428 * yRoot = the y coordinate where the drag nominally started 429 * 430 * Returns: a newly created #GdkDragContext 431 * 432 * Since: 3.20 433 */ 434 public static DragContext dragBeginFromPoint(Window window, Device device, ListG targets, int xRoot, int yRoot) 435 { 436 auto p = gdk_drag_begin_from_point((window is null) ? null : window.getWindowStruct(), (device is null) ? null : device.getDeviceStruct(), (targets is null) ? null : targets.getListGStruct(), xRoot, yRoot); 437 438 if(p is null) 439 { 440 return null; 441 } 442 443 return ObjectG.getDObject!(DragContext)(cast(GdkDragContext*) p, true); 444 } 445 446 /** 447 * Drops on the current destination. 448 * 449 * This function is called by the drag source. 450 * 451 * This function does not need to be called in managed drag and drop 452 * operations. See gdk_drag_context_manage_dnd() for more information. 453 * 454 * Params: 455 * context = a #GdkDragContext 456 * time = the timestamp for this operation 457 */ 458 public static void dragDrop(DragContext context, uint time) 459 { 460 gdk_drag_drop((context is null) ? null : context.getDragContextStruct(), time); 461 } 462 463 /** 464 * Inform GDK if the drop ended successfully. Passing %FALSE 465 * for @success may trigger a drag cancellation animation. 466 * 467 * This function is called by the drag source, and should 468 * be the last call before dropping the reference to the 469 * @context. 470 * 471 * The #GdkDragContext will only take the first gdk_drag_drop_done() 472 * call as effective, if this function is called multiple times, 473 * all subsequent calls will be ignored. 474 * 475 * Params: 476 * context = a #GdkDragContext 477 * success = whether the drag was ultimatively successful 478 * 479 * Since: 3.20 480 */ 481 public static void dragDropDone(DragContext context, bool success) 482 { 483 gdk_drag_drop_done((context is null) ? null : context.getDragContextStruct(), success); 484 } 485 486 /** 487 * Returns whether the dropped data has been successfully 488 * transferred. This function is intended to be used while 489 * handling a %GDK_DROP_FINISHED event, its return value is 490 * meaningless at other times. 491 * 492 * Params: 493 * context = a #GdkDragContext 494 * 495 * Returns: %TRUE if the drop was successful. 496 * 497 * Since: 2.6 498 */ 499 public static bool dragDropSucceeded(DragContext context) 500 { 501 return gdk_drag_drop_succeeded((context is null) ? null : context.getDragContextStruct()) != 0; 502 } 503 504 /** 505 * Finds the destination window and DND protocol to use at the 506 * given pointer position. 507 * 508 * This function is called by the drag source to obtain the 509 * @dest_window and @protocol parameters for gdk_drag_motion(). 510 * 511 * Params: 512 * context = a #GdkDragContext 513 * dragWindow = a window which may be at the pointer position, but 514 * should be ignored, since it is put up by the drag source as an icon 515 * screen = the screen where the destination window is sought 516 * xRoot = the x position of the pointer in root coordinates 517 * yRoot = the y position of the pointer in root coordinates 518 * destWindow = location to store the destination window in 519 * protocol = location to store the DND protocol in 520 * 521 * Since: 2.2 522 */ 523 public static void dragFindWindowForScreen(DragContext context, Window dragWindow, Screen screen, int xRoot, int yRoot, out Window destWindow, out GdkDragProtocol protocol) 524 { 525 GdkWindow* outdestWindow = null; 526 527 gdk_drag_find_window_for_screen((context is null) ? null : context.getDragContextStruct(), (dragWindow is null) ? null : dragWindow.getWindowStruct(), (screen is null) ? null : screen.getScreenStruct(), xRoot, yRoot, &outdestWindow, &protocol); 528 529 destWindow = ObjectG.getDObject!(Window)(outdestWindow); 530 } 531 532 /** 533 * Returns the selection atom for the current source window. 534 * 535 * Params: 536 * context = a #GdkDragContext. 537 * 538 * Returns: the selection atom, or %GDK_NONE 539 */ 540 public static GdkAtom dragGetSelection(DragContext context) 541 { 542 return gdk_drag_get_selection((context is null) ? null : context.getDragContextStruct()); 543 } 544 545 /** 546 * Updates the drag context when the pointer moves or the 547 * set of actions changes. 548 * 549 * This function is called by the drag source. 550 * 551 * This function does not need to be called in managed drag and drop 552 * operations. See gdk_drag_context_manage_dnd() for more information. 553 * 554 * Params: 555 * context = a #GdkDragContext 556 * destWindow = the new destination window, obtained by 557 * gdk_drag_find_window() 558 * protocol = the DND protocol in use, obtained by gdk_drag_find_window() 559 * xRoot = the x position of the pointer in root coordinates 560 * yRoot = the y position of the pointer in root coordinates 561 * suggestedAction = the suggested action 562 * possibleActions = the possible actions 563 * time = the timestamp for this operation 564 */ 565 public static bool dragMotion(DragContext context, Window destWindow, GdkDragProtocol protocol, int xRoot, int yRoot, GdkDragAction suggestedAction, GdkDragAction possibleActions, uint time) 566 { 567 return gdk_drag_motion((context is null) ? null : context.getDragContextStruct(), (destWindow is null) ? null : destWindow.getWindowStruct(), protocol, xRoot, yRoot, suggestedAction, possibleActions, time) != 0; 568 } 569 570 /** 571 * Selects one of the actions offered by the drag source. 572 * 573 * This function is called by the drag destination in response to 574 * gdk_drag_motion() called by the drag source. 575 * 576 * Params: 577 * context = a #GdkDragContext 578 * action = the selected action which will be taken when a drop happens, 579 * or 0 to indicate that a drop will not be accepted 580 * time = the timestamp for this operation 581 */ 582 public static void dragStatus(DragContext context, GdkDragAction action, uint time) 583 { 584 gdk_drag_status((context is null) ? null : context.getDragContextStruct(), action, time); 585 } 586 587 /** 588 * Ends the drag operation after a drop. 589 * 590 * This function is called by the drag destination. 591 * 592 * Params: 593 * context = a #GdkDragContext 594 * success = %TRUE if the data was successfully received 595 * time = the timestamp for this operation 596 */ 597 public static void dropFinish(DragContext context, bool success, uint time) 598 { 599 gdk_drop_finish((context is null) ? null : context.getDragContextStruct(), success, time); 600 } 601 602 /** 603 * Accepts or rejects a drop. 604 * 605 * This function is called by the drag destination in response 606 * to a drop initiated by the drag source. 607 * 608 * Params: 609 * context = a #GdkDragContext 610 * accepted = %TRUE if the drop is accepted 611 * time = the timestamp for this operation 612 */ 613 public static void dropReply(DragContext context, bool accepted, uint time) 614 { 615 gdk_drop_reply((context is null) ? null : context.getDragContextStruct(), accepted, time); 616 } 617 }