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