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