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 	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 	int[string] connectedSignals;
282 
283 	void delegate(GdkDragAction, DragContext)[] onActionChangedListeners;
284 	/**
285 	 * A new action is being chosen for the drag and drop operation.
286 	 *
287 	 * This signal will only be emitted if the #GdkDragContext manages
288 	 * the drag and drop operation. See gdk_drag_context_manage_dnd()
289 	 * for more information.
290 	 *
291 	 * Params:
292 	 *     action = The action currently chosen
293 	 *
294 	 * Since: 3.20
295 	 */
296 	void addOnActionChanged(void delegate(GdkDragAction, DragContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
297 	{
298 		if ( "action-changed" !in connectedSignals )
299 		{
300 			Signals.connectData(
301 				this,
302 				"action-changed",
303 				cast(GCallback)&callBackActionChanged,
304 				cast(void*)this,
305 				null,
306 				connectFlags);
307 			connectedSignals["action-changed"] = 1;
308 		}
309 		onActionChangedListeners ~= dlg;
310 	}
311 	extern(C) static void callBackActionChanged(GdkDragContext* dragcontextStruct, GdkDragAction action, DragContext _dragcontext)
312 	{
313 		foreach ( void delegate(GdkDragAction, DragContext) dlg; _dragcontext.onActionChangedListeners )
314 		{
315 			dlg(action, _dragcontext);
316 		}
317 	}
318 
319 	void delegate(GdkDragCancelReason, DragContext)[] onCancelListeners;
320 	/**
321 	 * The drag and drop operation was cancelled.
322 	 *
323 	 * This signal will only be emitted if the #GdkDragContext manages
324 	 * the drag and drop operation. See gdk_drag_context_manage_dnd()
325 	 * for more information.
326 	 *
327 	 * Since: 3.20
328 	 */
329 	void addOnCancel(void delegate(GdkDragCancelReason, DragContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
330 	{
331 		if ( "cancel" !in connectedSignals )
332 		{
333 			Signals.connectData(
334 				this,
335 				"cancel",
336 				cast(GCallback)&callBackCancel,
337 				cast(void*)this,
338 				null,
339 				connectFlags);
340 			connectedSignals["cancel"] = 1;
341 		}
342 		onCancelListeners ~= dlg;
343 	}
344 	extern(C) static void callBackCancel(GdkDragContext* dragcontextStruct, GdkDragCancelReason object, DragContext _dragcontext)
345 	{
346 		foreach ( void delegate(GdkDragCancelReason, DragContext) dlg; _dragcontext.onCancelListeners )
347 		{
348 			dlg(object, _dragcontext);
349 		}
350 	}
351 
352 	void delegate(DragContext)[] onDndFinishedListeners;
353 	/**
354 	 * The drag and drop operation was finished, the drag destination
355 	 * finished reading all data. The drag source can now free all
356 	 * miscellaneous data.
357 	 *
358 	 * This signal will only be emitted if the #GdkDragContext manages
359 	 * the drag and drop operation. See gdk_drag_context_manage_dnd()
360 	 * for more information.
361 	 *
362 	 * Since: 3.20
363 	 */
364 	void addOnDndFinished(void delegate(DragContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
365 	{
366 		if ( "dnd-finished" !in connectedSignals )
367 		{
368 			Signals.connectData(
369 				this,
370 				"dnd-finished",
371 				cast(GCallback)&callBackDndFinished,
372 				cast(void*)this,
373 				null,
374 				connectFlags);
375 			connectedSignals["dnd-finished"] = 1;
376 		}
377 		onDndFinishedListeners ~= dlg;
378 	}
379 	extern(C) static void callBackDndFinished(GdkDragContext* dragcontextStruct, DragContext _dragcontext)
380 	{
381 		foreach ( void delegate(DragContext) dlg; _dragcontext.onDndFinishedListeners )
382 		{
383 			dlg(_dragcontext);
384 		}
385 	}
386 
387 	void delegate(int, DragContext)[] onDropPerformedListeners;
388 	/**
389 	 * The drag and drop operation was performed on an accepting client.
390 	 *
391 	 * This signal will only be emitted if the #GdkDragContext manages
392 	 * the drag and drop operation. See gdk_drag_context_manage_dnd()
393 	 * for more information.
394 	 *
395 	 * Params:
396 	 *     time = the time at which the drop happened.
397 	 *
398 	 * Since: 3.20
399 	 */
400 	void addOnDropPerformed(void delegate(int, DragContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
401 	{
402 		if ( "drop-performed" !in connectedSignals )
403 		{
404 			Signals.connectData(
405 				this,
406 				"drop-performed",
407 				cast(GCallback)&callBackDropPerformed,
408 				cast(void*)this,
409 				null,
410 				connectFlags);
411 			connectedSignals["drop-performed"] = 1;
412 		}
413 		onDropPerformedListeners ~= dlg;
414 	}
415 	extern(C) static void callBackDropPerformed(GdkDragContext* dragcontextStruct, int time, DragContext _dragcontext)
416 	{
417 		foreach ( void delegate(int, DragContext) dlg; _dragcontext.onDropPerformedListeners )
418 		{
419 			dlg(time, _dragcontext);
420 		}
421 	}
422 
423 	/**
424 	 * Aborts a drag without dropping.
425 	 *
426 	 * This function is called by the drag source.
427 	 *
428 	 * This function does not need to be called in managed drag and drop
429 	 * operations. See gdk_drag_context_manage_dnd() for more information.
430 	 *
431 	 * Params:
432 	 *     context = a #GdkDragContext
433 	 *     time = the timestamp for this operation
434 	 */
435 	public static void dragAbort(DragContext context, uint time)
436 	{
437 		gdk_drag_abort((context is null) ? null : context.getDragContextStruct(), time);
438 	}
439 
440 	/**
441 	 * Starts a drag and creates a new drag context for it.
442 	 * This function assumes that the drag is controlled by the
443 	 * client pointer device, use gdk_drag_begin_for_device() to
444 	 * begin a drag with a different device.
445 	 *
446 	 * This function is called by the drag source.
447 	 *
448 	 * Params:
449 	 *     window = the source window for this drag.
450 	 *     targets = the offered targets,
451 	 *         as list of #GdkAtoms
452 	 *
453 	 * Return: a newly created #GdkDragContext
454 	 */
455 	public static DragContext dragBegin(Window window, ListG targets)
456 	{
457 		auto p = gdk_drag_begin((window is null) ? null : window.getWindowStruct(), (targets is null) ? null : targets.getListGStruct());
458 		
459 		if(p is null)
460 		{
461 			return null;
462 		}
463 		
464 		return ObjectG.getDObject!(DragContext)(cast(GdkDragContext*) p, true);
465 	}
466 
467 	/**
468 	 * Starts a drag and creates a new drag context for it.
469 	 *
470 	 * This function is called by the drag source.
471 	 *
472 	 * Params:
473 	 *     window = the source window for this drag
474 	 *     device = the device that controls this drag
475 	 *     targets = the offered targets,
476 	 *         as list of #GdkAtoms
477 	 *
478 	 * Return: a newly created #GdkDragContext
479 	 */
480 	public static DragContext dragBeginForDevice(Window window, Device device, ListG targets)
481 	{
482 		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());
483 		
484 		if(p is null)
485 		{
486 			return null;
487 		}
488 		
489 		return ObjectG.getDObject!(DragContext)(cast(GdkDragContext*) p, true);
490 	}
491 
492 	/**
493 	 * Starts a drag and creates a new drag context for it.
494 	 *
495 	 * This function is called by the drag source.
496 	 *
497 	 * Params:
498 	 *     window = the source window for this drag
499 	 *     device = the device that controls this drag
500 	 *     targets = the offered targets,
501 	 *         as list of #GdkAtoms
502 	 *     xRoot = the x coordinate where the drag nominally started
503 	 *     yRoot = the y coordinate where the drag nominally started
504 	 *
505 	 * Return: a newly created #GdkDragContext
506 	 *
507 	 * Since: 3.20
508 	 */
509 	public static DragContext dragBeginFromPoint(Window window, Device device, ListG targets, int xRoot, int yRoot)
510 	{
511 		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);
512 		
513 		if(p is null)
514 		{
515 			return null;
516 		}
517 		
518 		return ObjectG.getDObject!(DragContext)(cast(GdkDragContext*) p, true);
519 	}
520 
521 	/**
522 	 * Drops on the current destination.
523 	 *
524 	 * This function is called by the drag source.
525 	 *
526 	 * This function does not need to be called in managed drag and drop
527 	 * operations. See gdk_drag_context_manage_dnd() for more information.
528 	 *
529 	 * Params:
530 	 *     context = a #GdkDragContext
531 	 *     time = the timestamp for this operation
532 	 */
533 	public static void dragDrop(DragContext context, uint time)
534 	{
535 		gdk_drag_drop((context is null) ? null : context.getDragContextStruct(), time);
536 	}
537 
538 	/**
539 	 * Inform GDK if the drop ended successfully. Passing %FALSE
540 	 * for @success may trigger a drag cancellation animation.
541 	 *
542 	 * This function is called by the drag source, and should
543 	 * be the last call before dropping the reference to the
544 	 * @context.
545 	 *
546 	 * The #GdkDragContext will only take the first gdk_drag_drop_done()
547 	 * call as effective, if this function is called multiple times,
548 	 * all subsequent calls will be ignored.
549 	 *
550 	 * Params:
551 	 *     context = a #GdkDragContext
552 	 *     success = whether the drag was ultimatively successful
553 	 *
554 	 * Since: 3.20
555 	 */
556 	public static void dragDropDone(DragContext context, bool success)
557 	{
558 		gdk_drag_drop_done((context is null) ? null : context.getDragContextStruct(), success);
559 	}
560 
561 	/**
562 	 * Returns whether the dropped data has been successfully
563 	 * transferred. This function is intended to be used while
564 	 * handling a %GDK_DROP_FINISHED event, its return value is
565 	 * meaningless at other times.
566 	 *
567 	 * Params:
568 	 *     context = a #GdkDragContext
569 	 *
570 	 * Return: %TRUE if the drop was successful.
571 	 *
572 	 * Since: 2.6
573 	 */
574 	public static bool dragDropSucceeded(DragContext context)
575 	{
576 		return gdk_drag_drop_succeeded((context is null) ? null : context.getDragContextStruct()) != 0;
577 	}
578 
579 	/**
580 	 * Finds the destination window and DND protocol to use at the
581 	 * given pointer position.
582 	 *
583 	 * This function is called by the drag source to obtain the
584 	 * @dest_window and @protocol parameters for gdk_drag_motion().
585 	 *
586 	 * Params:
587 	 *     context = a #GdkDragContext
588 	 *     dragWindow = a window which may be at the pointer position, but
589 	 *         should be ignored, since it is put up by the drag source as an icon
590 	 *     screen = the screen where the destination window is sought
591 	 *     xRoot = the x position of the pointer in root coordinates
592 	 *     yRoot = the y position of the pointer in root coordinates
593 	 *     destWindow = location to store the destination window in
594 	 *     protocol = location to store the DND protocol in
595 	 *
596 	 * Since: 2.2
597 	 */
598 	public static void dragFindWindowForScreen(DragContext context, Window dragWindow, Screen screen, int xRoot, int yRoot, out Window destWindow, out GdkDragProtocol protocol)
599 	{
600 		GdkWindow* outdestWindow = null;
601 		
602 		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);
603 		
604 		destWindow = ObjectG.getDObject!(Window)(outdestWindow);
605 	}
606 
607 	/**
608 	 * Returns the selection atom for the current source window.
609 	 *
610 	 * Params:
611 	 *     context = a #GdkDragContext.
612 	 *
613 	 * Return: the selection atom, or %GDK_NONE
614 	 */
615 	public static GdkAtom dragGetSelection(DragContext context)
616 	{
617 		return gdk_drag_get_selection((context is null) ? null : context.getDragContextStruct());
618 	}
619 
620 	/**
621 	 * Updates the drag context when the pointer moves or the
622 	 * set of actions changes.
623 	 *
624 	 * This function is called by the drag source.
625 	 *
626 	 * This function does not need to be called in managed drag and drop
627 	 * operations. See gdk_drag_context_manage_dnd() for more information.
628 	 *
629 	 * Params:
630 	 *     context = a #GdkDragContext
631 	 *     destWindow = the new destination window, obtained by
632 	 *         gdk_drag_find_window()
633 	 *     protocol = the DND protocol in use, obtained by gdk_drag_find_window()
634 	 *     xRoot = the x position of the pointer in root coordinates
635 	 *     yRoot = the y position of the pointer in root coordinates
636 	 *     suggestedAction = the suggested action
637 	 *     possibleActions = the possible actions
638 	 *     time = the timestamp for this operation
639 	 */
640 	public static bool dragMotion(DragContext context, Window destWindow, GdkDragProtocol protocol, int xRoot, int yRoot, GdkDragAction suggestedAction, GdkDragAction possibleActions, uint time)
641 	{
642 		return gdk_drag_motion((context is null) ? null : context.getDragContextStruct(), (destWindow is null) ? null : destWindow.getWindowStruct(), protocol, xRoot, yRoot, suggestedAction, possibleActions, time) != 0;
643 	}
644 
645 	/**
646 	 * Selects one of the actions offered by the drag source.
647 	 *
648 	 * This function is called by the drag destination in response to
649 	 * gdk_drag_motion() called by the drag source.
650 	 *
651 	 * Params:
652 	 *     context = a #GdkDragContext
653 	 *     action = the selected action which will be taken when a drop happens,
654 	 *         or 0 to indicate that a drop will not be accepted
655 	 *     time = the timestamp for this operation
656 	 */
657 	public static void dragStatus(DragContext context, GdkDragAction action, uint time)
658 	{
659 		gdk_drag_status((context is null) ? null : context.getDragContextStruct(), action, time);
660 	}
661 
662 	/**
663 	 * Ends the drag operation after a drop.
664 	 *
665 	 * This function is called by the drag destination.
666 	 *
667 	 * Params:
668 	 *     context = a #GdkDragContext
669 	 *     success = %TRUE if the data was successfully received
670 	 *     time = the timestamp for this operation
671 	 */
672 	public static void dropFinish(DragContext context, bool success, uint time)
673 	{
674 		gdk_drop_finish((context is null) ? null : context.getDragContextStruct(), success, time);
675 	}
676 
677 	/**
678 	 * Accepts or rejects a drop.
679 	 *
680 	 * This function is called by the drag destination in response
681 	 * to a drop initiated by the drag source.
682 	 *
683 	 * Params:
684 	 *     context = a #GdkDragContext
685 	 *     accepted = %TRUE if the drop is accepted
686 	 *     time = the timestamp for this operation
687 	 */
688 	public static void dropReply(DragContext context, bool accepted, uint time)
689 	{
690 		gdk_drop_reply((context is null) ? null : context.getDragContextStruct(), accepted, time);
691 	}
692 }