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