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