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  * Conversion parameters:
26  * inFile  = GtkDialog.html
27  * outPack = gtk
28  * outFile = Dialog
29  * strct   = GtkDialog
30  * realStrct=
31  * ctorStrct=
32  * clss    = Dialog
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_dialog_
41  * 	- gtk_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * 	- gtk_dialog_get_action_area
46  * 	- gtk_dialog_get_content_area
47  * omit signals:
48  * imports:
49  * 	- glib.Str
50  * 	- gdk.Screen
51  * 	- gtk.Button
52  * 	- gtk.Widget
53  * 	- gtk.Window
54  * 	- gtk.HButtonBox
55  * 	- gtk.VBox
56  * structWrap:
57  * 	- GdkScreen* -> Screen
58  * 	- GtkWidget* -> Widget
59  * 	- GtkWindow* -> Window
60  * module aliases:
61  * local aliases:
62  * 	- setAlternativeButtonOrderFromArray -> setAlternativeButtonOrder
63  * overrides:
64  */
65 
66 module gtk.Dialog;
67 
68 public  import gtkc.gtktypes;
69 
70 private import gtkc.gtk;
71 private import glib.ConstructionException;
72 private import gobject.ObjectG;
73 
74 private import gobject.Signals;
75 public  import gtkc.gdktypes;
76 private import glib.Str;
77 private import gdk.Screen;
78 private import gtk.Button;
79 private import gtk.Widget;
80 private import gtk.Window;
81 private import gtk.HButtonBox;
82 private import gtk.VBox;
83 
84 
85 private import gtk.Window;
86 
87 /**
88  * Dialog boxes are a convenient way to prompt the user for a small amount
89  * of input, e.g. to display a message, ask a question, or anything else
90  * that does not require extensive effort on the user's part.
91  *
92  * GTK+ treats a dialog as a window split vertically. The top section is a
93  * GtkVBox, and is where widgets such as a GtkLabel or a GtkEntry should
94  * be packed. The bottom area is known as the
95  * action_area. This is generally used for
96  * packing buttons into the dialog which may perform functions such as
97  * cancel, ok, or apply.
98  *
99  * GtkDialog boxes are created with a call to gtk_dialog_new() or
100  * gtk_dialog_new_with_buttons(). gtk_dialog_new_with_buttons() is
101  * recommended; it allows you to set the dialog title, some convenient flags,
102  * and add simple buttons.
103  *
104  * If 'dialog' is a newly created dialog, the two primary areas of the
105  * window can be accessed through gtk_dialog_get_content_area() and
106  * gtk_dialog_get_action_area(), as can be seen from the example below.
107  *
108  * A 'modal' dialog (that is, one which freezes the rest of the application
109  * from user input), can be created by calling gtk_window_set_modal() on the
110  * dialog. Use the GTK_WINDOW() macro to cast the widget returned from
111  * gtk_dialog_new() into a GtkWindow. When using gtk_dialog_new_with_buttons()
112  * you can also pass the GTK_DIALOG_MODAL flag to make a dialog modal.
113  *
114  * If you add buttons to GtkDialog using gtk_dialog_new_with_buttons(),
115  * gtk_dialog_add_button(), gtk_dialog_add_buttons(), or
116  * gtk_dialog_add_action_widget(), clicking the button will emit a signal
117  * called "response" with a response ID that you specified. GTK+
118  * will never assign a meaning to positive response IDs; these are entirely
119  * user-defined. But for convenience, you can use the response IDs in the
120  * GtkResponseType enumeration (these all have values less than zero). If
121  * a dialog receives a delete event, the "response" signal will
122  * be emitted with a response ID of GTK_RESPONSE_DELETE_EVENT.
123  *
124  * If you want to block waiting for a dialog to return before returning
125  * control flow to your code, you can call gtk_dialog_run(). This function
126  * enters a recursive main loop and waits for the user to respond to the
127  * dialog, returning the response ID corresponding to the button the user
128  * clicked.
129  *
130  * For the simple dialog in the following example, in reality you'd probably
131  * use GtkMessageDialog to save yourself some effort. But you'd need to
132  * create the dialog contents manually if you had more than a simple message
133  * in the dialog.
134  *
135  * $(DDOC_COMMENT example)
136  *
137  * GtkDialog as GtkBuildable
138  *
139  * The GtkDialog implementation of the GtkBuildable interface exposes the
140  * vbox and action_area as internal children with the names "vbox" and
141  * "action_area".
142  *
143  * GtkDialog supports a custom <action-widgets> element, which
144  * can contain multiple <action-widget> elements. The "response"
145  * attribute specifies a numeric response, and the content of the element
146  * is the id of widget (which should be a child of the dialogs action_area).
147  *
148  * $(DDOC_COMMENT example)
149  */
150 public class Dialog : Window
151 {
152 	
153 	/** the main Gtk struct */
154 	protected GtkDialog* gtkDialog;
155 	
156 	
157 	/** Get the main Gtk struct */
158 	public GtkDialog* getDialogStruct()
159 	{
160 		return gtkDialog;
161 	}
162 	
163 	
164 	/** the main Gtk struct as a void* */
165 	protected override void* getStruct()
166 	{
167 		return cast(void*)gtkDialog;
168 	}
169 	
170 	/**
171 	 * Sets our main struct and passes it to the parent class
172 	 */
173 	public this (GtkDialog* gtkDialog)
174 	{
175 		super(cast(GtkWindow*)gtkDialog);
176 		this.gtkDialog = gtkDialog;
177 	}
178 	
179 	protected override void setStruct(GObject* obj)
180 	{
181 		super.setStruct(obj);
182 		gtkDialog = cast(GtkDialog*)obj;
183 	}
184 	
185 	/**
186 	 * Both title and parent can be null.
187 	 */
188 	this(string title, Window parent, GtkDialogFlags flags, string[] buttonsText, ResponseType[] responses)
189 	{
190 		auto p = gtk_dialog_new_with_buttons(Str.toStringz(title), (parent is null) ? null : parent.getWindowStruct(), flags, Str.toStringz(buttonsText[0]), responses[0], null);
191 		if(p is null)
192 		{
193 			throw new ConstructionException("null returned by gtk_dialog_new_with_buttons");
194 		}
195 		
196 		this(cast(GtkDialog*)p);
197 		
198 		addButtons(buttonsText[1 .. $], responses[1 .. $]);
199 	}
200 	
201 	/** ditto */
202 	this(string title, Window parent, GtkDialogFlags flags, StockID[] stockIDs, ResponseType[] responses)
203 	{
204 		auto p = gtk_dialog_new_with_buttons(Str.toStringz(title), (parent is null) ? null : parent.getWindowStruct(), flags, Str.toStringz(StockDesc[stockIDs[0]]), responses[0], null);
205 		if(p is null)
206 		{
207 			throw new ConstructionException("null returned by gtk_dialog_new_with_buttons");
208 		}
209 		
210 		this(cast(GtkDialog*)p);
211 		
212 		addButtons(stockIDs[1 .. $], responses[1 .. $]);
213 	}
214 	
215 	/** */
216 	public Button addButton(StockID stockID, int responseId)
217 	{
218 		auto p = gtk_dialog_add_button(gtkDialog, Str.toStringz(StockDesc[stockID]), responseId);
219 		
220 		if ( p is null )
221 		{
222 			return null;
223 		}
224 		
225 		return new Button(cast(GtkButton*)p);
226 	}
227 	
228 	/** */
229 	public void addButtons(string[] buttonsText, ResponseType[] responses)
230 	{
231 		for ( int i=0 ; i<buttonsText.length && i<responses.length ; i++)
232 		{
233 			addButton(buttonsText[i], responses[i]);
234 		}
235 	}
236 	
237 	/** */
238 	public void addButtons(StockID[] stockIDs, ResponseType[] responses)
239 	{
240 		for ( int i=0 ; i<stockIDs.length && i<responses.length ; i++)
241 		{
242 			addButton(stockIDs[i], responses[i]);
243 		}
244 	}
245 	
246 	//Return the corect class instead of Widget
247 	/**
248 	 * Returns the action area of dialog.
249 	 * Since 2.14
250 	 * Returns: the action area.
251 	 */
252 	public HButtonBox getActionArea()
253 	{
254 		// GtkWidget* gtk_dialog_get_action_area (GtkDialog *dialog);
255 		auto p = gtk_dialog_get_action_area(gtkDialog);
256 		if(p is null)
257 		{
258 			return null;
259 		}
260 		return new HButtonBox(cast(GtkHButtonBox*) p);
261 	}
262 	
263 	//Return the corect class instead of Widget
264 	/**
265 	 * Returns the content area of dialog.
266 	 * Since 2.14
267 	 * Returns: the content area GtkVBox.
268 	 */
269 	public VBox getContentArea()
270 	{
271 		// GtkWidget* gtk_dialog_get_content_area (GtkDialog *dialog);
272 		auto p = gtk_dialog_get_content_area(gtkDialog);
273 		if(p is null)
274 		{
275 			return null;
276 		}
277 		return new VBox(cast(GtkVBox*) p);
278 	}
279 	
280 	/**
281 	 */
282 	int[string] connectedSignals;
283 	
284 	void delegate(Dialog)[] onCloseListeners;
285 	/**
286 	 * The ::close signal is a
287 	 * keybinding signal
288 	 * which gets emitted when the user uses a keybinding to close
289 	 * the dialog.
290 	 * The default binding for this signal is the Escape key.
291 	 */
292 	void addOnClose(void delegate(Dialog) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
293 	{
294 		if ( !("close" in connectedSignals) )
295 		{
296 			Signals.connectData(
297 			getStruct(),
298 			"close",
299 			cast(GCallback)&callBackClose,
300 			cast(void*)this,
301 			null,
302 			connectFlags);
303 			connectedSignals["close"] = 1;
304 		}
305 		onCloseListeners ~= dlg;
306 	}
307 	extern(C) static void callBackClose(GtkDialog* arg0Struct, Dialog _dialog)
308 	{
309 		foreach ( void delegate(Dialog) dlg ; _dialog.onCloseListeners )
310 		{
311 			dlg(_dialog);
312 		}
313 	}
314 	
315 	void delegate(gint, Dialog)[] onResponseListeners;
316 	/**
317 	 * Emitted when an action widget is clicked, the dialog receives a
318 	 * delete event, or the application programmer calls gtk_dialog_response().
319 	 * On a delete event, the response ID is GTK_RESPONSE_DELETE_EVENT.
320 	 * Otherwise, it depends on which action widget was clicked.
321 	 * See Also
322 	 * GtkVBox, GtkWindow, GtkButton
323 	 */
324 	void addOnResponse(void delegate(gint, Dialog) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
325 	{
326 		if ( !("response" in connectedSignals) )
327 		{
328 			Signals.connectData(
329 			getStruct(),
330 			"response",
331 			cast(GCallback)&callBackResponse,
332 			cast(void*)this,
333 			null,
334 			connectFlags);
335 			connectedSignals["response"] = 1;
336 		}
337 		onResponseListeners ~= dlg;
338 	}
339 	extern(C) static void callBackResponse(GtkDialog* dialogStruct, gint responseId, Dialog _dialog)
340 	{
341 		foreach ( void delegate(gint, Dialog) dlg ; _dialog.onResponseListeners )
342 		{
343 			dlg(responseId, _dialog);
344 		}
345 	}
346 	
347 	
348 	/**
349 	 * Creates a new dialog box.
350 	 * Widgets should not be packed into this GtkWindow
351 	 * directly, but into the vbox and action_area, as described above.
352 	 * Throws: ConstructionException GTK+ fails to create the object.
353 	 */
354 	public this ()
355 	{
356 		// GtkWidget * gtk_dialog_new (void);
357 		auto p = gtk_dialog_new();
358 		if(p is null)
359 		{
360 			throw new ConstructionException("null returned by gtk_dialog_new()");
361 		}
362 		this(cast(GtkDialog*) p);
363 	}
364 	
365 	/**
366 	 * Blocks in a recursive main loop until the dialog either emits the
367 	 * "response" signal, or is destroyed. If the dialog is
368 	 * destroyed during the call to gtk_dialog_run(), gtk_dialog_run() returns
369 	 * GTK_RESPONSE_NONE. Otherwise, it returns the response ID from the
370 	 * ::response signal emission.
371 	 * Before entering the recursive main loop, gtk_dialog_run() calls
372 	 * gtk_widget_show() on the dialog for you. Note that you still
373 	 * need to show any children of the dialog yourself.
374 	 * During gtk_dialog_run(), the default behavior of "delete-event"
375 	 * is disabled; if the dialog receives ::delete_event, it will not be
376 	 * destroyed as windows usually are, and gtk_dialog_run() will return
377 	 * GTK_RESPONSE_DELETE_EVENT. Also, during gtk_dialog_run() the dialog
378 	 * will be modal. You can force gtk_dialog_run() to return at any time by
379 	 * calling gtk_dialog_response() to emit the ::response signal. Destroying
380 	 * the dialog during gtk_dialog_run() is a very bad idea, because your
381 	 * post-run code won't know whether the dialog was destroyed or not.
382 	 * After gtk_dialog_run() returns, you are responsible for hiding or
383 	 * destroying the dialog if you wish to do so.
384 	 * Returns: response ID
385 	 */
386 	public int run()
387 	{
388 		// gint gtk_dialog_run (GtkDialog *dialog);
389 		return gtk_dialog_run(gtkDialog);
390 	}
391 	
392 	/**
393 	 * Emits the "response" signal with the given response ID.
394 	 * Used to indicate that the user has responded to the dialog in some way;
395 	 * typically either you or gtk_dialog_run() will be monitoring the
396 	 * ::response signal and take appropriate action.
397 	 * Params:
398 	 * responseId = response ID
399 	 */
400 	public void response(int responseId)
401 	{
402 		// void gtk_dialog_response (GtkDialog *dialog,  gint response_id);
403 		gtk_dialog_response(gtkDialog, responseId);
404 	}
405 	
406 	/**
407 	 * Adds a button with the given text and sets things up so that
408 	 * clicking the button will emit the "response" signal with
409 	 * the given response_id. The button is appended to the end of the
410 	 * dialog's action area. The button widget is returned, but usually
411 	 * you don't need it.
412 	 * Params:
413 	 * buttonText = text of button
414 	 * responseId = response ID for the button
415 	 * Returns: the GtkButton widget that was added. [transfer none]
416 	 */
417 	public Widget addButton(string buttonText, int responseId)
418 	{
419 		// GtkWidget * gtk_dialog_add_button (GtkDialog *dialog,  const gchar *button_text,  gint response_id);
420 		auto p = gtk_dialog_add_button(gtkDialog, Str.toStringz(buttonText), responseId);
421 		
422 		if(p is null)
423 		{
424 			return null;
425 		}
426 		
427 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
428 	}
429 	
430 	/**
431 	 * Adds an activatable widget to the action area of a GtkDialog,
432 	 * connecting a signal handler that will emit the "response"
433 	 * signal on the dialog when the widget is activated. The widget is
434 	 * appended to the end of the dialog's action area. If you want to add a
435 	 * non-activatable widget, simply pack it into the action_area field
436 	 * of the GtkDialog struct.
437 	 * Params:
438 	 * child = an activatable widget
439 	 * responseId = response ID for child
440 	 */
441 	public void addActionWidget(Widget child, int responseId)
442 	{
443 		// void gtk_dialog_add_action_widget (GtkDialog *dialog,  GtkWidget *child,  gint response_id);
444 		gtk_dialog_add_action_widget(gtkDialog, (child is null) ? null : child.getWidgetStruct(), responseId);
445 	}
446 	
447 	/**
448 	 * Sets the last widget in the dialog's action area with the given response_id
449 	 * as the default widget for the dialog. Pressing "Enter" normally activates
450 	 * the default widget.
451 	 * Params:
452 	 * responseId = a response ID
453 	 */
454 	public void setDefaultResponse(int responseId)
455 	{
456 		// void gtk_dialog_set_default_response (GtkDialog *dialog,  gint response_id);
457 		gtk_dialog_set_default_response(gtkDialog, responseId);
458 	}
459 	
460 	/**
461 	 * Calls gtk_widget_set_sensitive (widget, setting)
462 	 * for each widget in the dialog's action area with the given response_id.
463 	 * A convenient way to sensitize/desensitize dialog buttons.
464 	 * Params:
465 	 * responseId = a response ID
466 	 * setting = TRUE for sensitive
467 	 */
468 	public void setResponseSensitive(int responseId, int setting)
469 	{
470 		// void gtk_dialog_set_response_sensitive (GtkDialog *dialog,  gint response_id,  gboolean setting);
471 		gtk_dialog_set_response_sensitive(gtkDialog, responseId, setting);
472 	}
473 	
474 	/**
475 	 * Gets the response id of a widget in the action area
476 	 * of a dialog.
477 	 * Since 2.8
478 	 * Params:
479 	 * widget = a widget in the action area of dialog
480 	 * Returns: the response id of widget, or GTK_RESPONSE_NONE if widget doesn't have a response id set.
481 	 */
482 	public int getResponseForWidget(Widget widget)
483 	{
484 		// gint gtk_dialog_get_response_for_widget (GtkDialog *dialog,  GtkWidget *widget);
485 		return gtk_dialog_get_response_for_widget(gtkDialog, (widget is null) ? null : widget.getWidgetStruct());
486 	}
487 	
488 	/**
489 	 * Gets the widget button that uses the given response ID in the action area
490 	 * of a dialog.
491 	 * Since 2.20
492 	 * Params:
493 	 * responseId = the response ID used by the dialog widget
494 	 * Returns: the widget button that uses the given response_id, or NULL. [transfer none]
495 	 */
496 	public Widget getWidgetForResponse(int responseId)
497 	{
498 		// GtkWidget * gtk_dialog_get_widget_for_response (GtkDialog *dialog,  gint response_id);
499 		auto p = gtk_dialog_get_widget_for_response(gtkDialog, responseId);
500 		
501 		if(p is null)
502 		{
503 			return null;
504 		}
505 		
506 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
507 	}
508 	
509 	/**
510 	 * Returns TRUE if dialogs are expected to use an alternative
511 	 * button order on the screen screen. See
512 	 * gtk_dialog_set_alternative_button_order() for more details
513 	 * about alternative button order.
514 	 * If you need to use this function, you should probably connect
515 	 * to the ::notify:gtk-alternative-button-order signal on the
516 	 * GtkSettings object associated to screen, in order to be
517 	 * notified if the button order setting changes.
518 	 * Since 2.6
519 	 * Params:
520 	 * screen = a GdkScreen, or NULL to use the default screen. [allow-none]
521 	 * Returns: Whether the alternative button order should be used
522 	 */
523 	public static int alternativeDialogButtonOrder(Screen screen)
524 	{
525 		// gboolean gtk_alternative_dialog_button_order (GdkScreen *screen);
526 		return gtk_alternative_dialog_button_order((screen is null) ? null : screen.getScreenStruct());
527 	}
528 	
529 	/**
530 	 * Sets an alternative button order. If the
531 	 * "gtk-alternative-button-order" setting is set to TRUE,
532 	 * the dialog buttons are reordered according to the order of the
533 	 * response ids in new_order.
534 	 * See gtk_dialog_set_alternative_button_order() for more information.
535 	 * This function is for use by language bindings.
536 	 * Since 2.6
537 	 * Style Property Details
538 	 * The "action-area-border" style property
539 	 *  "action-area-border" gint : Read
540 	 * Width of border around the button area at the bottom of the dialog.
541 	 * Allowed values: &gt;= 0
542 	 * Default value: 5
543 	 * Params:
544 	 * newOrder = an array of response ids of
545 	 * dialog's buttons. [array length=n_params]
546 	 */
547 	public void setAlternativeButtonOrder(int[] newOrder)
548 	{
549 		// void gtk_dialog_set_alternative_button_order_from_array  (GtkDialog *dialog,  gint n_params,  gint *new_order);
550 		gtk_dialog_set_alternative_button_order_from_array(gtkDialog, cast(int) newOrder.length, newOrder.ptr);
551 	}
552 }