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 gtk.DropTargetAsync; 26 27 private import gdk.ContentFormats; 28 private import gdk.Drop; 29 private import glib.ConstructionException; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gtk.EventController; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 private import std.algorithm; 36 37 38 /** 39 * `GtkDropTargetAsync` is an event controller to receive Drag-and-Drop 40 * operations, asynchronously. 41 * 42 * It is the more complete but also more complex method of handling drop 43 * operations compared to [class@Gtk.DropTarget], and you should only use 44 * it if `GtkDropTarget` doesn't provide all the features you need. 45 * 46 * To use a `GtkDropTargetAsync` to receive drops on a widget, you create 47 * a `GtkDropTargetAsync` object, configure which data formats and actions 48 * you support, connect to its signals, and then attach it to the widget 49 * with [method@Gtk.Widget.add_controller]. 50 * 51 * During a drag operation, the first signal that a `GtkDropTargetAsync` 52 * emits is [signal@Gtk.DropTargetAsync::accept], which is meant to determine 53 * whether the target is a possible drop site for the ongoing drop. The 54 * default handler for the ::accept signal accepts the drop if it finds 55 * a compatible data format and an action that is supported on both sides. 56 * 57 * If it is, and the widget becomes a target, you will receive a 58 * [signal@Gtk.DropTargetAsync::drag-enter] signal, followed by 59 * [signal@Gtk.DropTargetAsync::drag-motion] signals as the pointer moves, 60 * optionally a [signal@Gtk.DropTargetAsync::drop] signal when a drop happens, 61 * and finally a [signal@Gtk.DropTargetAsync::drag-leave] signal when the 62 * pointer moves off the widget. 63 * 64 * The ::drag-enter and ::drag-motion handler return a `GdkDragAction` 65 * to update the status of the ongoing operation. The ::drop handler 66 * should decide if it ultimately accepts the drop and if it does, it 67 * should initiate the data transfer and finish the operation by calling 68 * [method@Gdk.Drop.finish]. 69 * 70 * Between the ::drag-enter and ::drag-leave signals the widget is a 71 * current drop target, and will receive the %GTK_STATE_FLAG_DROP_ACTIVE 72 * state, which can be used by themes to style the widget as a drop target. 73 */ 74 public class DropTargetAsync : EventController 75 { 76 /** the main Gtk struct */ 77 protected GtkDropTargetAsync* gtkDropTargetAsync; 78 79 /** Get the main Gtk struct */ 80 public GtkDropTargetAsync* getDropTargetAsyncStruct(bool transferOwnership = false) 81 { 82 if (transferOwnership) 83 ownedRef = false; 84 return gtkDropTargetAsync; 85 } 86 87 /** the main Gtk struct as a void* */ 88 protected override void* getStruct() 89 { 90 return cast(void*)gtkDropTargetAsync; 91 } 92 93 /** 94 * Sets our main struct and passes it to the parent class. 95 */ 96 public this (GtkDropTargetAsync* gtkDropTargetAsync, bool ownedRef = false) 97 { 98 this.gtkDropTargetAsync = gtkDropTargetAsync; 99 super(cast(GtkEventController*)gtkDropTargetAsync, ownedRef); 100 } 101 102 103 /** */ 104 public static GType getType() 105 { 106 return gtk_drop_target_async_get_type(); 107 } 108 109 /** 110 * Creates a new `GtkDropTargetAsync` object. 111 * 112 * Params: 113 * formats = the supported data formats 114 * actions = the supported actions 115 * 116 * Returns: the new `GtkDropTargetAsync` 117 * 118 * Throws: ConstructionException GTK+ fails to create the object. 119 */ 120 public this(ContentFormats formats, GdkDragAction actions) 121 { 122 auto __p = gtk_drop_target_async_new((formats is null) ? null : formats.getContentFormatsStruct(true), actions); 123 124 if(__p is null) 125 { 126 throw new ConstructionException("null returned by new"); 127 } 128 129 this(cast(GtkDropTargetAsync*) __p, true); 130 } 131 132 /** 133 * Gets the actions that this drop target supports. 134 * 135 * Returns: the actions that this drop target supports 136 */ 137 public GdkDragAction getActions() 138 { 139 return gtk_drop_target_async_get_actions(gtkDropTargetAsync); 140 } 141 142 /** 143 * Gets the data formats that this drop target accepts. 144 * 145 * If the result is %NULL, all formats are expected to be supported. 146 * 147 * Returns: the supported data formats 148 */ 149 public ContentFormats getFormats() 150 { 151 auto __p = gtk_drop_target_async_get_formats(gtkDropTargetAsync); 152 153 if(__p is null) 154 { 155 return null; 156 } 157 158 return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true); 159 } 160 161 /** 162 * Sets the @drop as not accepted on this drag site. 163 * 164 * This function should be used when delaying the decision 165 * on whether to accept a drag or not until after reading 166 * the data. 167 * 168 * Params: 169 * drop = the #GdkDrop of an ongoing drag operation 170 */ 171 public void rejectDrop(Drop drop) 172 { 173 gtk_drop_target_async_reject_drop(gtkDropTargetAsync, (drop is null) ? null : drop.getDropStruct()); 174 } 175 176 /** 177 * Sets the actions that this drop target supports. 178 * 179 * Params: 180 * actions = the supported actions 181 */ 182 public void setActions(GdkDragAction actions) 183 { 184 gtk_drop_target_async_set_actions(gtkDropTargetAsync, actions); 185 } 186 187 /** 188 * Sets the data formats that this drop target will accept. 189 * 190 * Params: 191 * formats = the supported data formats or %NULL for 192 * any format. 193 */ 194 public void setFormats(ContentFormats formats) 195 { 196 gtk_drop_target_async_set_formats(gtkDropTargetAsync, (formats is null) ? null : formats.getContentFormatsStruct()); 197 } 198 199 /** 200 * Emitted on the drop site when a drop operation is about to begin. 201 * 202 * If the drop is not accepted, %FALSE will be returned and the drop target 203 * will ignore the drop. If %TRUE is returned, the drop is accepted for now 204 * but may be rejected later via a call to [method@Gtk.DropTargetAsync.reject_drop] 205 * or ultimately by returning %FALSE from a [signal@Gtk.DropTargetAsync::drop] 206 * handler. 207 * 208 * The default handler for this signal decides whether to accept the drop 209 * based on the formats provided by the @drop. 210 * 211 * If the decision whether the drop will be accepted or rejected needs 212 * further processing, such as inspecting the data, this function should 213 * return %TRUE and proceed as is @drop was accepted and if it decides to 214 * reject the drop later, it should call [method@Gtk.DropTargetAsync.reject_drop]. 215 * 216 * Params: 217 * drop = the #GdkDrop 218 * 219 * Returns: %TRUE if @drop is accepted 220 */ 221 gulong addOnAccept(bool delegate(Drop, DropTargetAsync) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 222 { 223 return Signals.connect(this, "accept", dlg, connectFlags ^ ConnectFlags.SWAPPED); 224 } 225 226 /** 227 * Emitted on the drop site when the pointer enters the widget. 228 * 229 * It can be used to set up custom highlighting. 230 * 231 * Params: 232 * drop = the #GdkDrop 233 * x = the x coordinate of the current pointer position 234 * y = the y coordinate of the current pointer position 235 * 236 * Returns: Preferred action for this drag operation. 237 */ 238 gulong addOnDragEnter(GdkDragAction delegate(Drop, double, double, DropTargetAsync) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 239 { 240 return Signals.connect(this, "drag-enter", dlg, connectFlags ^ ConnectFlags.SWAPPED); 241 } 242 243 /** 244 * Emitted on the drop site when the pointer leaves the widget. 245 * 246 * Its main purpose it to undo things done in 247 * `GtkDropTargetAsync`::drag-enter. 248 * 249 * Params: 250 * drop = the #GdkDrop 251 */ 252 gulong addOnDragLeave(void delegate(Drop, DropTargetAsync) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 253 { 254 return Signals.connect(this, "drag-leave", dlg, connectFlags ^ ConnectFlags.SWAPPED); 255 } 256 257 /** 258 * Emitted while the pointer is moving over the drop target. 259 * 260 * Params: 261 * drop = the #GdkDrop 262 * x = the x coordinate of the current pointer position 263 * y = the y coordinate of the current pointer position 264 * 265 * Returns: Preferred action for this drag operation. 266 */ 267 gulong addOnDragMotion(GdkDragAction delegate(Drop, double, double, DropTargetAsync) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 268 { 269 return Signals.connect(this, "drag-motion", dlg, connectFlags ^ ConnectFlags.SWAPPED); 270 } 271 272 /** 273 * Emitted on the drop site when the user drops the data onto the widget. 274 * 275 * The signal handler must determine whether the pointer position is in a 276 * drop zone or not. If it is not in a drop zone, it returns %FALSE and no 277 * further processing is necessary. 278 * 279 * Otherwise, the handler returns %TRUE. In this case, this handler will 280 * accept the drop. The handler must ensure that [method@Gdk.Drop.finish] 281 * is called to let the source know that the drop is done. The call to 282 * [method@Gdk.Drop.finish] must only be done when all data has been received. 283 * 284 * To receive the data, use one of the read functions provided by 285 * [class@Gdk.Drop] such as [method@Gdk.Drop.read_async] or 286 * [method@Gdk.Drop.read_value_async]. 287 * 288 * Params: 289 * drop = the #GdkDrop 290 * x = the x coordinate of the current pointer position 291 * y = the y coordinate of the current pointer position 292 * 293 * Returns: whether the drop is accepted at the given pointer position 294 */ 295 gulong addOnDrop(bool delegate(Drop, double, double, DropTargetAsync) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 296 { 297 return Signals.connect(this, "drop", dlg, connectFlags ^ ConnectFlags.SWAPPED); 298 } 299 }