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.NativeDialog; 26 27 private import glib.Str; 28 private import gobject.ObjectG; 29 private import gobject.Signals; 30 private import gtk.Window; 31 private import gtkc.gtk; 32 public import gtkc.gtktypes; 33 private import std.algorithm; 34 35 36 /** 37 * Native dialogs are platform dialogs that don't use #GtkDialog or 38 * #GtkWindow. They are used in order to integrate better with a 39 * platform, by looking the same as other native applications and 40 * supporting platform specific features. 41 * 42 * The #GtkDialog functions cannot be used on such objects, but we 43 * need a similar API in order to drive them. The #GtkNativeDialog 44 * object is an API that allows you to do this. It allows you to set 45 * various common properties on the dialog, as well as show and hide 46 * it and get a #GtkNativeDialog::response signal when the user finished 47 * with the dialog. 48 * 49 * There is also a gtk_native_dialog_run() helper that makes it easy 50 * to run any native dialog in a modal way with a recursive mainloop, 51 * similar to gtk_dialog_run(). 52 */ 53 public class NativeDialog : ObjectG 54 { 55 /** the main Gtk struct */ 56 protected GtkNativeDialog* gtkNativeDialog; 57 58 /** Get the main Gtk struct */ 59 public GtkNativeDialog* getNativeDialogStruct(bool transferOwnership = false) 60 { 61 if (transferOwnership) 62 ownedRef = false; 63 return gtkNativeDialog; 64 } 65 66 /** the main Gtk struct as a void* */ 67 protected override void* getStruct() 68 { 69 return cast(void*)gtkNativeDialog; 70 } 71 72 protected override void setStruct(GObject* obj) 73 { 74 gtkNativeDialog = cast(GtkNativeDialog*)obj; 75 super.setStruct(obj); 76 } 77 78 /** 79 * Sets our main struct and passes it to the parent class. 80 */ 81 public this (GtkNativeDialog* gtkNativeDialog, bool ownedRef = false) 82 { 83 this.gtkNativeDialog = gtkNativeDialog; 84 super(cast(GObject*)gtkNativeDialog, ownedRef); 85 } 86 87 88 /** */ 89 public static GType getType() 90 { 91 return gtk_native_dialog_get_type(); 92 } 93 94 /** 95 * Destroys a dialog. 96 * 97 * When a dialog is destroyed, it will break any references it holds 98 * to other objects. If it is visible it will be hidden and any underlying 99 * window system resources will be destroyed. 100 * 101 * Note that this does not release any reference to the object (as opposed to 102 * destroying a GtkWindow) because there is no reference from the windowing 103 * system to the #GtkNativeDialog. 104 * 105 * Since: 3.20 106 */ 107 public void destroy() 108 { 109 gtk_native_dialog_destroy(gtkNativeDialog); 110 } 111 112 /** 113 * Returns whether the dialog is modal. See gtk_native_dialog_set_modal(). 114 * 115 * Returns: %TRUE if the dialog is set to be modal 116 * 117 * Since: 3.20 118 */ 119 public bool getModal() 120 { 121 return gtk_native_dialog_get_modal(gtkNativeDialog) != 0; 122 } 123 124 /** 125 * Gets the title of the #GtkNativeDialog. 126 * 127 * Returns: the title of the dialog, or %NULL if none has 128 * been set explicitly. The returned string is owned by the widget 129 * and must not be modified or freed. 130 * 131 * Since: 3.20 132 */ 133 public string getTitle() 134 { 135 return Str.toString(gtk_native_dialog_get_title(gtkNativeDialog)); 136 } 137 138 /** 139 * Fetches the transient parent for this window. See 140 * gtk_native_dialog_set_transient_for(). 141 * 142 * Returns: the transient parent for this window, 143 * or %NULL if no transient parent has been set. 144 * 145 * Since: 3.20 146 */ 147 public Window getTransientFor() 148 { 149 auto p = gtk_native_dialog_get_transient_for(gtkNativeDialog); 150 151 if(p is null) 152 { 153 return null; 154 } 155 156 return ObjectG.getDObject!(Window)(cast(GtkWindow*) p); 157 } 158 159 /** 160 * Determines whether the dialog is visible. 161 * 162 * Returns: %TRUE if the dialog is visible 163 * 164 * Since: 3.20 165 */ 166 public bool getVisible() 167 { 168 return gtk_native_dialog_get_visible(gtkNativeDialog) != 0; 169 } 170 171 /** 172 * Hides the dialog if it is visilbe, aborting any interaction. Once this 173 * is called the #GtkNativeDialog::response signal will not be emitted 174 * until after the next call to gtk_native_dialog_show(). 175 * 176 * If the dialog is not visible this does nothing. 177 * 178 * Since: 3.20 179 */ 180 public void hide() 181 { 182 gtk_native_dialog_hide(gtkNativeDialog); 183 } 184 185 /** 186 * Blocks in a recursive main loop until @self emits the 187 * #GtkNativeDialog::response signal. It then returns the response ID 188 * from the ::response signal emission. 189 * 190 * Before entering the recursive main loop, gtk_native_dialog_run() 191 * calls gtk_native_dialog_show() on the dialog for you. 192 * 193 * After gtk_native_dialog_run() returns, then dialog will be hidden. 194 * 195 * Typical usage of this function might be: 196 * |[<!-- language="C" --> 197 * gint result = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog)); 198 * switch (result) 199 * { 200 * case GTK_RESPONSE_ACCEPT: 201 * do_application_specific_something (); 202 * break; 203 * default: 204 * do_nothing_since_dialog_was_cancelled (); 205 * break; 206 * } 207 * g_object_unref (dialog); 208 * ]| 209 * 210 * Note that even though the recursive main loop gives the effect of a 211 * modal dialog (it prevents the user from interacting with other 212 * windows in the same window group while the dialog is run), callbacks 213 * such as timeouts, IO channel watches, DND drops, etc, will 214 * be triggered during a gtk_nautilus_dialog_run() call. 215 * 216 * Returns: response ID 217 * 218 * Since: 3.20 219 */ 220 public int run() 221 { 222 return gtk_native_dialog_run(gtkNativeDialog); 223 } 224 225 /** 226 * Sets a dialog modal or non-modal. Modal dialogs prevent interaction 227 * with other windows in the same application. To keep modal dialogs 228 * on top of main application windows, use 229 * gtk_native_dialog_set_transient_for() to make the dialog transient for the 230 * parent; most [window managers][gtk-X11-arch] 231 * will then disallow lowering the dialog below the parent. 232 * 233 * Params: 234 * modal = whether the window is modal 235 * 236 * Since: 3.20 237 */ 238 public void setModal(bool modal) 239 { 240 gtk_native_dialog_set_modal(gtkNativeDialog, modal); 241 } 242 243 /** 244 * Sets the title of the #GtkNativeDialog. 245 * 246 * Params: 247 * title = title of the dialog 248 * 249 * Since: 3.20 250 */ 251 public void setTitle(string title) 252 { 253 gtk_native_dialog_set_title(gtkNativeDialog, Str.toStringz(title)); 254 } 255 256 /** 257 * Dialog windows should be set transient for the main application 258 * window they were spawned from. This allows 259 * [window managers][gtk-X11-arch] to e.g. keep the 260 * dialog on top of the main window, or center the dialog over the 261 * main window. 262 * 263 * Passing %NULL for @parent unsets the current transient window. 264 * 265 * Params: 266 * parent = parent window, or %NULL 267 * 268 * Since: 3.20 269 */ 270 public void setTransientFor(Window parent) 271 { 272 gtk_native_dialog_set_transient_for(gtkNativeDialog, (parent is null) ? null : parent.getWindowStruct()); 273 } 274 275 /** 276 * Shows the dialog on the display, allowing the user to interact with 277 * it. When the user accepts the state of the dialog the dialog will 278 * be automatically hidden and the #GtkNativeDialog::response signal 279 * will be emitted. 280 * 281 * Multiple calls while the dialog is visible will be ignored. 282 * 283 * Since: 3.20 284 */ 285 public void show() 286 { 287 gtk_native_dialog_show(gtkNativeDialog); 288 } 289 290 protected class OnResponseDelegateWrapper 291 { 292 static OnResponseDelegateWrapper[] listeners; 293 void delegate(int, NativeDialog) dlg; 294 gulong handlerId; 295 296 this(void delegate(int, NativeDialog) dlg) 297 { 298 this.dlg = dlg; 299 this.listeners ~= this; 300 } 301 302 void remove(OnResponseDelegateWrapper source) 303 { 304 foreach(index, wrapper; listeners) 305 { 306 if (wrapper.handlerId == source.handlerId) 307 { 308 listeners[index] = null; 309 listeners = std.algorithm.remove(listeners, index); 310 break; 311 } 312 } 313 } 314 } 315 316 /** 317 * Emitted when the user responds to the dialog. 318 * 319 * When this is called the dialog has been hidden. 320 * 321 * If you call gtk_native_dialog_hide() before the user responds to 322 * the dialog this signal will not be emitted. 323 * 324 * Params: 325 * responseId = the response ID 326 * 327 * Since: 3.20 328 */ 329 gulong addOnResponse(void delegate(int, NativeDialog) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 330 { 331 auto wrapper = new OnResponseDelegateWrapper(dlg); 332 wrapper.handlerId = Signals.connectData( 333 this, 334 "response", 335 cast(GCallback)&callBackResponse, 336 cast(void*)wrapper, 337 cast(GClosureNotify)&callBackResponseDestroy, 338 connectFlags); 339 return wrapper.handlerId; 340 } 341 342 extern(C) static void callBackResponse(GtkNativeDialog* nativedialogStruct, int responseId, OnResponseDelegateWrapper wrapper) 343 { 344 wrapper.dlg(responseId, wrapper.outer); 345 } 346 347 extern(C) static void callBackResponseDestroy(OnResponseDelegateWrapper wrapper, GClosure* closure) 348 { 349 wrapper.remove(wrapper); 350 } 351 }