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.Drag;
26 
27 private import gdk.ContentFormats;
28 private import gdk.ContentProvider;
29 private import gdk.Device;
30 private import gdk.Display;
31 private import gdk.Surface;
32 private import gdk.c.functions;
33 public  import gdk.c.types;
34 private import gobject.ObjectG;
35 private import gobject.Signals;
36 private import std.algorithm;
37 
38 
39 /**
40  * The `GdkDrag` object represents the source of an ongoing DND operation.
41  * 
42  * A `GdkDrag` is created when a drag is started, and stays alive for duration of
43  * the DND operation. After a drag has been started with [func@Gdk.Drag.begin],
44  * the caller gets informed about the status of the ongoing drag operation
45  * with signals on the `GdkDrag` object.
46  * 
47  * GTK provides a higher level abstraction based on top of these functions,
48  * and so they are not normally needed in GTK applications. See the
49  * "Drag and Drop" section of the GTK documentation for more information.
50  */
51 public class Drag : ObjectG
52 {
53 	/** the main Gtk struct */
54 	protected GdkDrag* gdkDrag;
55 
56 	/** Get the main Gtk struct */
57 	public GdkDrag* getDragStruct(bool transferOwnership = false)
58 	{
59 		if (transferOwnership)
60 			ownedRef = false;
61 		return gdkDrag;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gdkDrag;
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GdkDrag* gdkDrag, bool ownedRef = false)
74 	{
75 		this.gdkDrag = gdkDrag;
76 		super(cast(GObject*)gdkDrag, ownedRef);
77 	}
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return gdk_drag_get_type();
84 	}
85 
86 	/**
87 	 * Starts a drag and creates a new drag context for it.
88 	 *
89 	 * This function is called by the drag source. After this call, you
90 	 * probably want to set up the drag icon using the surface returned
91 	 * by [method@Gdk.Drag.get_drag_surface].
92 	 *
93 	 * This function returns a reference to the [class@Gdk.Drag] object,
94 	 * but GTK keeps its own reference as well, as long as the DND operation
95 	 * is going on.
96 	 *
97 	 * Note: if @actions include %GDK_ACTION_MOVE, you need to listen for
98 	 * the [signal@Gdk.Drag::dnd-finished] signal and delete the data at
99 	 * the source if [method@Gdk.Drag.get_selected_action] returns
100 	 * %GDK_ACTION_MOVE.
101 	 *
102 	 * Params:
103 	 *     surface = the source surface for this drag
104 	 *     device = the device that controls this drag
105 	 *     content = the offered content
106 	 *     actions = the actions supported by this drag
107 	 *     dx = the x offset to @device's position where the drag nominally started
108 	 *     dy = the y offset to @device's position where the drag nominally started
109 	 *
110 	 * Returns: a newly created [class@Gdk.Drag]
111 	 *     or %NULL on error
112 	 */
113 	public static Drag begin(Surface surface, Device device, ContentProvider content, GdkDragAction actions, double dx, double dy)
114 	{
115 		auto __p = gdk_drag_begin((surface is null) ? null : surface.getSurfaceStruct(), (device is null) ? null : device.getDeviceStruct(), (content is null) ? null : content.getContentProviderStruct(), actions, dx, dy);
116 
117 		if(__p is null)
118 		{
119 			return null;
120 		}
121 
122 		return ObjectG.getDObject!(Drag)(cast(GdkDrag*) __p, true);
123 	}
124 
125 	/**
126 	 * Informs GDK that the drop ended.
127 	 *
128 	 * Passing %FALSE for @success may trigger a drag cancellation
129 	 * animation.
130 	 *
131 	 * This function is called by the drag source, and should be the
132 	 * last call before dropping the reference to the @drag.
133 	 *
134 	 * The `GdkDrag` will only take the first [method@Gdk.Drag.drop_done]
135 	 * call as effective, if this function is called multiple times,
136 	 * all subsequent calls will be ignored.
137 	 *
138 	 * Params:
139 	 *     success = whether the drag was ultimatively successful
140 	 */
141 	public void dropDone(bool success)
142 	{
143 		gdk_drag_drop_done(gdkDrag, success);
144 	}
145 
146 	/**
147 	 * Determines the bitmask of possible actions proposed by the source.
148 	 *
149 	 * Returns: the `GdkDragAction` flags
150 	 */
151 	public GdkDragAction getActions()
152 	{
153 		return gdk_drag_get_actions(gdkDrag);
154 	}
155 
156 	/**
157 	 * Returns the `GdkContentProvider` associated to the `GdkDrag` object.
158 	 *
159 	 * Returns: The `GdkContentProvider` associated to @drag.
160 	 */
161 	public ContentProvider getContent()
162 	{
163 		auto __p = gdk_drag_get_content(gdkDrag);
164 
165 		if(__p is null)
166 		{
167 			return null;
168 		}
169 
170 		return ObjectG.getDObject!(ContentProvider)(cast(GdkContentProvider*) __p);
171 	}
172 
173 	/**
174 	 * Returns the `GdkDevice` associated to the `GdkDrag` object.
175 	 *
176 	 * Returns: The `GdkDevice` associated to @drag.
177 	 */
178 	public Device getDevice()
179 	{
180 		auto __p = gdk_drag_get_device(gdkDrag);
181 
182 		if(__p is null)
183 		{
184 			return null;
185 		}
186 
187 		return ObjectG.getDObject!(Device)(cast(GdkDevice*) __p);
188 	}
189 
190 	/**
191 	 * Gets the `GdkDisplay` that the drag object was created for.
192 	 *
193 	 * Returns: a `GdkDisplay`
194 	 */
195 	public Display getDisplay()
196 	{
197 		auto __p = gdk_drag_get_display(gdkDrag);
198 
199 		if(__p is null)
200 		{
201 			return null;
202 		}
203 
204 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p);
205 	}
206 
207 	/**
208 	 * Returns the surface on which the drag icon should be rendered
209 	 * during the drag operation.
210 	 *
211 	 * Note that the surface may not be available until the drag operation
212 	 * has begun. GDK will move the surface in accordance with the ongoing
213 	 * drag operation. The surface is owned by @drag and will be destroyed
214 	 * when the drag operation is over.
215 	 *
216 	 * Returns: the drag surface, or %NULL
217 	 */
218 	public Surface getDragSurface()
219 	{
220 		auto __p = gdk_drag_get_drag_surface(gdkDrag);
221 
222 		if(__p is null)
223 		{
224 			return null;
225 		}
226 
227 		return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p);
228 	}
229 
230 	/**
231 	 * Retrieves the formats supported by this `GdkDrag` object.
232 	 *
233 	 * Returns: a `GdkContentFormats`
234 	 */
235 	public ContentFormats getFormats()
236 	{
237 		auto __p = gdk_drag_get_formats(gdkDrag);
238 
239 		if(__p is null)
240 		{
241 			return null;
242 		}
243 
244 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p);
245 	}
246 
247 	/**
248 	 * Determines the action chosen by the drag destination.
249 	 *
250 	 * Returns: a `GdkDragAction` value
251 	 */
252 	public GdkDragAction getSelectedAction()
253 	{
254 		return gdk_drag_get_selected_action(gdkDrag);
255 	}
256 
257 	/**
258 	 * Returns the `GdkSurface` where the drag originates.
259 	 *
260 	 * Returns: The `GdkSurface` where the drag originates
261 	 */
262 	public Surface getSurface()
263 	{
264 		auto __p = gdk_drag_get_surface(gdkDrag);
265 
266 		if(__p is null)
267 		{
268 			return null;
269 		}
270 
271 		return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p);
272 	}
273 
274 	/**
275 	 * Sets the position of the drag surface that will be kept
276 	 * under the cursor hotspot.
277 	 *
278 	 * Initially, the hotspot is at the top left corner of the drag surface.
279 	 *
280 	 * Params:
281 	 *     hotX = x coordinate of the drag surface hotspot
282 	 *     hotY = y coordinate of the drag surface hotspot
283 	 */
284 	public void setHotspot(int hotX, int hotY)
285 	{
286 		gdk_drag_set_hotspot(gdkDrag, hotX, hotY);
287 	}
288 
289 	/**
290 	 * Emitted when the drag operation is cancelled.
291 	 *
292 	 * Params:
293 	 *     reason = The reason the drag was cancelled
294 	 */
295 	gulong addOnCancel(void delegate(GdkDragCancelReason, Drag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
296 	{
297 		return Signals.connect(this, "cancel", dlg, connectFlags ^ ConnectFlags.SWAPPED);
298 	}
299 
300 	/**
301 	 * Emitted when the destination side has finished reading all data.
302 	 *
303 	 * The drag object can now free all miscellaneous data.
304 	 */
305 	gulong addOnDndFinished(void delegate(Drag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
306 	{
307 		return Signals.connect(this, "dnd-finished", dlg, connectFlags ^ ConnectFlags.SWAPPED);
308 	}
309 
310 	/**
311 	 * Emitted when the drop operation is performed on an accepting client.
312 	 */
313 	gulong addOnDropPerformed(void delegate(Drag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
314 	{
315 		return Signals.connect(this, "drop-performed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
316 	}
317 }