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.Drop;
26 
27 private import gdk.ContentFormats;
28 private import gdk.Device;
29 private import gdk.Display;
30 private import gdk.Drag;
31 private import gdk.Surface;
32 private import gdk.c.functions;
33 public  import gdk.c.types;
34 private import gio.AsyncResultIF;
35 private import gio.Cancellable;
36 private import gio.InputStream;
37 private import glib.ErrorG;
38 private import glib.GException;
39 private import glib.Str;
40 private import glib.c.functions;
41 private import gobject.ObjectG;
42 private import gobject.Value;
43 
44 
45 /**
46  * The `GdkDrop` object represents the target of an ongoing DND operation.
47  * 
48  * Possible drop sites get informed about the status of the ongoing drag
49  * operation with events of type %GDK_DRAG_ENTER, %GDK_DRAG_LEAVE,
50  * %GDK_DRAG_MOTION and %GDK_DROP_START. The `GdkDrop` object can be obtained
51  * from these [class@Gdk.Event] types using [method@Gdk.DNDEvent.get_drop].
52  * 
53  * The actual data transfer is initiated from the target side via an async
54  * read, using one of the `GdkDrop` methods for this purpose:
55  * [method@Gdk.Drop.read_async] or [method@Gdk.Drop.read_value_async].
56  * 
57  * GTK provides a higher level abstraction based on top of these functions,
58  * and so they are not normally needed in GTK applications. See the
59  * "Drag and Drop" section of the GTK documentation for more information.
60  */
61 public class Drop : ObjectG
62 {
63 	/** the main Gtk struct */
64 	protected GdkDrop* gdkDrop;
65 
66 	/** Get the main Gtk struct */
67 	public GdkDrop* getDropStruct(bool transferOwnership = false)
68 	{
69 		if (transferOwnership)
70 			ownedRef = false;
71 		return gdkDrop;
72 	}
73 
74 	/** the main Gtk struct as a void* */
75 	protected override void* getStruct()
76 	{
77 		return cast(void*)gdkDrop;
78 	}
79 
80 	/**
81 	 * Sets our main struct and passes it to the parent class.
82 	 */
83 	public this (GdkDrop* gdkDrop, bool ownedRef = false)
84 	{
85 		this.gdkDrop = gdkDrop;
86 		super(cast(GObject*)gdkDrop, ownedRef);
87 	}
88 
89 
90 	/** */
91 	public static GType getType()
92 	{
93 		return gdk_drop_get_type();
94 	}
95 
96 	/**
97 	 * Ends the drag operation after a drop.
98 	 *
99 	 * The @action must be a single action selected from the actions
100 	 * available via [method@Gdk.Drop.get_actions].
101 	 *
102 	 * Params:
103 	 *     action = the action performed by the destination or 0 if the drop failed
104 	 */
105 	public void finish(GdkDragAction action)
106 	{
107 		gdk_drop_finish(gdkDrop, action);
108 	}
109 
110 	/**
111 	 * Returns the possible actions for this `GdkDrop`.
112 	 *
113 	 * If this value contains multiple actions - i.e.
114 	 * [func@Gdk.DragAction.is_unique] returns %FALSE for the result -
115 	 * [method@Gdk.Drop.finish] must choose the action to use when
116 	 * accepting the drop. This will only happen if you passed
117 	 * %GDK_ACTION_ASK as one of the possible actions in
118 	 * [method@Gdk.Drop.status]. %GDK_ACTION_ASK itself will not
119 	 * be included in the actions returned by this function.
120 	 *
121 	 * This value may change over the lifetime of the [class@Gdk.Drop]
122 	 * both as a response to source side actions as well as to calls to
123 	 * [method@Gdk.Drop.status] or [method@Gdk.Drop.finish]. The source
124 	 * side will not change this value anymore once a drop has started.
125 	 *
126 	 * Returns: The possible `GdkDragActions`
127 	 */
128 	public GdkDragAction getActions()
129 	{
130 		return gdk_drop_get_actions(gdkDrop);
131 	}
132 
133 	/**
134 	 * Returns the `GdkDevice` performing the drop.
135 	 *
136 	 * Returns: The `GdkDevice` performing the drop.
137 	 */
138 	public Device getDevice()
139 	{
140 		auto __p = gdk_drop_get_device(gdkDrop);
141 
142 		if(__p is null)
143 		{
144 			return null;
145 		}
146 
147 		return ObjectG.getDObject!(Device)(cast(GdkDevice*) __p);
148 	}
149 
150 	/**
151 	 * Gets the `GdkDisplay` that @self was created for.
152 	 *
153 	 * Returns: a `GdkDisplay`
154 	 */
155 	public Display getDisplay()
156 	{
157 		auto __p = gdk_drop_get_display(gdkDrop);
158 
159 		if(__p is null)
160 		{
161 			return null;
162 		}
163 
164 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p);
165 	}
166 
167 	/**
168 	 * If this is an in-app drag-and-drop operation, returns the `GdkDrag`
169 	 * that corresponds to this drop.
170 	 *
171 	 * If it is not, %NULL is returned.
172 	 *
173 	 * Returns: the corresponding `GdkDrag`
174 	 */
175 	public Drag getDrag()
176 	{
177 		auto __p = gdk_drop_get_drag(gdkDrop);
178 
179 		if(__p is null)
180 		{
181 			return null;
182 		}
183 
184 		return ObjectG.getDObject!(Drag)(cast(GdkDrag*) __p);
185 	}
186 
187 	/**
188 	 * Returns the `GdkContentFormats` that the drop offers the data
189 	 * to be read in.
190 	 *
191 	 * Returns: The possible `GdkContentFormats`
192 	 */
193 	public ContentFormats getFormats()
194 	{
195 		auto __p = gdk_drop_get_formats(gdkDrop);
196 
197 		if(__p is null)
198 		{
199 			return null;
200 		}
201 
202 		return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p);
203 	}
204 
205 	/**
206 	 * Returns the `GdkSurface` performing the drop.
207 	 *
208 	 * Returns: The `GdkSurface` performing the drop.
209 	 */
210 	public Surface getSurface()
211 	{
212 		auto __p = gdk_drop_get_surface(gdkDrop);
213 
214 		if(__p is null)
215 		{
216 			return null;
217 		}
218 
219 		return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p);
220 	}
221 
222 	/**
223 	 * Asynchronously read the dropped data from a `GdkDrop`
224 	 * in a format that complies with one of the mime types.
225 	 *
226 	 * Params:
227 	 *     mimeTypes = pointer to an array of mime types
228 	 *     ioPriority = the I/O priority for the read operation
229 	 *     cancellable = optional `GCancellable` object,
230 	 *         %NULL to ignore
231 	 *     callback = a `GAsyncReadyCallback` to call when
232 	 *         the request is satisfied
233 	 *     userData = the data to pass to @callback
234 	 */
235 	public void readAsync(string[] mimeTypes, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
236 	{
237 		gdk_drop_read_async(gdkDrop, Str.toStringzArray(mimeTypes), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
238 	}
239 
240 	/**
241 	 * Finishes an async drop read operation.
242 	 *
243 	 * Note that you must not use blocking read calls on the returned stream
244 	 * in the GTK thread, since some platforms might require communication with
245 	 * GTK to complete the data transfer. You can use async APIs such as
246 	 * g_input_stream_read_bytes_async().
247 	 *
248 	 * See [method@Gdk.Drop.read_async].
249 	 *
250 	 * Params:
251 	 *     result = a `GAsyncResult`
252 	 *     outMimeType = return location for the used mime type
253 	 *
254 	 * Returns: the `GInputStream`, or %NULL
255 	 *
256 	 * Throws: GException on failure.
257 	 */
258 	public InputStream readFinish(AsyncResultIF result, out string outMimeType)
259 	{
260 		char* outoutMimeType = null;
261 		GError* err = null;
262 
263 		auto __p = gdk_drop_read_finish(gdkDrop, (result is null) ? null : result.getAsyncResultStruct(), &outoutMimeType, &err);
264 
265 		if (err !is null)
266 		{
267 			throw new GException( new ErrorG(err) );
268 		}
269 
270 		outMimeType = Str.toString(outoutMimeType);
271 
272 		if(__p is null)
273 		{
274 			return null;
275 		}
276 
277 		return ObjectG.getDObject!(InputStream)(cast(GInputStream*) __p, true);
278 	}
279 
280 	/**
281 	 * Asynchronously request the drag operation's contents converted
282 	 * to the given @type.
283 	 *
284 	 * When the operation is finished @callback will be called. You must
285 	 * then call [method@Gdk.Drop.read_value_finish] to get the resulting
286 	 * `GValue`.
287 	 *
288 	 * For local drag'n'drop operations that are available in the given
289 	 * `GType`, the value will be copied directly. Otherwise, GDK will
290 	 * try to use [func@Gdk.content_deserialize_async] to convert the data.
291 	 *
292 	 * Params:
293 	 *     type = a `GType` to read
294 	 *     ioPriority = the I/O priority of the request.
295 	 *     cancellable = optional `GCancellable` object, %NULL to ignore.
296 	 *     callback = callback to call when the request is satisfied
297 	 *     userData = the data to pass to callback function
298 	 */
299 	public void readValueAsync(GType type, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
300 	{
301 		gdk_drop_read_value_async(gdkDrop, type, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
302 	}
303 
304 	/**
305 	 * Finishes an async drop read.
306 	 *
307 	 * See [method@Gdk.Drop.read_value_async].
308 	 *
309 	 * Params:
310 	 *     result = a `GAsyncResult`
311 	 *
312 	 * Returns: a `GValue` containing the result.
313 	 *
314 	 * Throws: GException on failure.
315 	 */
316 	public Value readValueFinish(AsyncResultIF result)
317 	{
318 		GError* err = null;
319 
320 		auto __p = gdk_drop_read_value_finish(gdkDrop, (result is null) ? null : result.getAsyncResultStruct(), &err);
321 
322 		if (err !is null)
323 		{
324 			throw new GException( new ErrorG(err) );
325 		}
326 
327 		if(__p is null)
328 		{
329 			return null;
330 		}
331 
332 		return ObjectG.getDObject!(Value)(cast(GValue*) __p);
333 	}
334 
335 	/**
336 	 * Selects all actions that are potentially supported by the destination.
337 	 *
338 	 * When calling this function, do not restrict the passed in actions to
339 	 * the ones provided by [method@Gdk.Drop.get_actions]. Those actions may
340 	 * change in the future, even depending on the actions you provide here.
341 	 *
342 	 * The @preferred action is a hint to the drag'n'drop mechanism about which
343 	 * action to use when multiple actions are possible.
344 	 *
345 	 * This function should be called by drag destinations in response to
346 	 * %GDK_DRAG_ENTER or %GDK_DRAG_MOTION events. If the destination does
347 	 * not yet know the exact actions it supports, it should set any possible
348 	 * actions first and then later call this function again.
349 	 *
350 	 * Params:
351 	 *     actions = Supported actions of the destination, or 0 to indicate
352 	 *         that a drop will not be accepted
353 	 *     preferred = A unique action that's a member of @actions indicating the
354 	 *         preferred action
355 	 */
356 	public void status(GdkDragAction actions, GdkDragAction preferred)
357 	{
358 		gdk_drop_status(gdkDrop, actions, preferred);
359 	}
360 }