alternative to assert
[gtkD.git] / gtkD / src / gtk / Dialog.d
blobfe1e89d9252363d52441772b1448e7f02bcdbdab
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkDialog.html
26 * outPack = gtk
27 * outFile = Dialog
28 * strct = GtkDialog
29 * realStrct=
30 * ctorStrct=
31 * clss = Dialog
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_dialog_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * imports:
45 * - glib.Str
46 * - gtk.Window
47 * - gtk.Widget
48 * - gdk.Screen
49 * structWrap:
50 * - GdkScreen* -> Screen
51 * - GtkWidget* -> Widget
52 * - GtkWindow* -> Window
53 * module aliases:
54 * local aliases:
57 module gtk.Dialog;
59 version(noAssert)
61 version(Tango)
63 import tango.io.Stdout; // use the tango loging?
67 private import gtkc.gtktypes;
69 private import gtkc.gtk;
72 private import glib.Str;
73 private import gtk.Window;
74 private import gtk.Widget;
75 private import gdk.Screen;
80 /**
81 * Description
82 * Dialog boxes are a convenient way to prompt the user for a small amount of
83 * input, e.g. to display a message, ask a question, or anything else that does
84 * not require extensive effort on the user's part.
85 * GTK+ treats a dialog as a window split vertically. The top section is a
86 * GtkVBox, and is where widgets such as a GtkLabel or a GtkEntry should
87 * be packed. The bottom area is known as the
88 * action_area. This is generally used for
89 * packing buttons into the dialog which may perform functions such as
90 * cancel, ok, or apply. The two areas are separated by a GtkHSeparator.
91 * GtkDialog boxes are created with a call to gtk_dialog_new() or
92 * gtk_dialog_new_with_buttons(). gtk_dialog_new_with_buttons() is recommended; it
93 * allows you to set the dialog title, some convenient flags, and add simple
94 * buttons.
95 * If 'dialog' is a newly created dialog, the two primary areas of the window
96 * can be accessed as GTK_DIALOG(dialog)->vbox and
97 * GTK_DIALOG(dialog)->action_area,
98 * as can be seen from the example, below.
99 * A 'modal' dialog (that is, one which freezes the rest of the application from
100 * user input), can be created by calling gtk_window_set_modal() on the dialog. Use
101 * the GTK_WINDOW() macro to cast the widget returned from gtk_dialog_new() into a
102 * GtkWindow. When using gtk_dialog_new_with_buttons() you can also pass the
103 * GTK_DIALOG_MODAL flag to make a dialog modal.
104 * If you add buttons to GtkDialog using gtk_dialog_new_with_buttons(),
105 * gtk_dialog_add_button(), gtk_dialog_add_buttons(), or
106 * gtk_dialog_add_action_widget(), clicking the button will emit a signal called
107 * "response" with a response ID that you specified. GTK+ will never assign a
108 * meaning to positive response IDs; these are entirely user-defined. But for
109 * convenience, you can use the response IDs in the GtkResponseType enumeration
110 * (these all have values less than zero). If a dialog receives a delete event,
111 * the "response" signal will be emitted with a response ID of GTK_RESPONSE_DELETE_EVENT.
112 * If you want to block waiting for a dialog to return before returning control
113 * flow to your code, you can call gtk_dialog_run(). This function enters a
114 * recursive main loop and waits for the user to respond to the dialog, returning the
115 * response ID corresponding to the button the user clicked.
116 * For the simple dialog in the following example, in reality you'd probably use
117 * GtkMessageDialog to save yourself some effort. But you'd need to create the
118 * dialog contents manually if you had more than a simple message in the dialog.
119 * Example1.Simple GtkDialog usage.
120 * /+* Function to open a dialog box displaying the message provided. +/
121 * void quick_message (gchar *message) {
122 * GtkWidget *dialog, *label;
123 * /+* Create the widgets +/
124 * dialog = gtk_dialog_new_with_buttons ("Message",
125 * main_application_window,
126 * GTK_DIALOG_DESTROY_WITH_PARENT,
127 * GTK_STOCK_OK,
128 * GTK_RESPONSE_NONE,
129 * NULL);
130 * label = gtk_label_new (message);
131 * /+* Ensure that the dialog box is destroyed when the user responds. +/
132 * g_signal_connect_swapped (dialog,
133 * "response",
134 * G_CALLBACK (gtk_widget_destroy),
135 * dialog);
136 * /+* Add the label, and show everything we've added to the dialog. +/
137 * gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
138 * label);
139 * gtk_widget_show_all (dialog);
142 private import gtk.Window;
143 public class Dialog : Window
146 /** the main Gtk struct */
147 protected GtkDialog* gtkDialog;
150 public GtkDialog* getDialogStruct()
152 return gtkDialog;
156 /** the main Gtk struct as a void* */
157 protected void* getStruct()
159 return cast(void*)gtkDialog;
163 * Sets our main struct and passes it to the parent class
165 public this (GtkDialog* gtkDialog)
167 version(noAssert)
169 if ( gtkDialog is null )
171 int zero = 0;
172 version(Tango)
174 Stdout("struct gtkDialog is null on constructor").newline;
176 else
178 printf("struct gtkDialog is null on constructor");
180 zero = zero / zero;
183 else
185 assert(gtkDialog !is null, "struct gtkDialog is null on constructor");
187 super(cast(GtkWindow*)gtkDialog);
188 this.gtkDialog = gtkDialog;
191 public Widget addButton(StockID stockID, int responseId)
193 return addButton(StockDesc[stockID], responseId);
197 public void addButtons(char[][] buttonsText, ResponseType[] responses)
199 for ( int i=0 ; i<buttonsText.length && i<responses.length ; i++)
201 addButton(buttonsText[i], responses[i]);
205 public void addButtons(StockID[] stockIDs, ResponseType[] responses)
207 for ( int i=0 ; i<stockIDs.length && i<responses.length ; i++)
209 addButton(stockIDs[i], responses[i]);
217 // imports for the signal processing
218 private import gobject.Signals;
219 private import gtkc.gdktypes;
220 int[char[]] connectedSignals;
222 void delegate(Dialog)[] onCloseListeners;
223 void addOnClose(void delegate(Dialog) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
225 if ( !("close" in connectedSignals) )
227 Signals.connectData(
228 getStruct(),
229 "close",
230 cast(GCallback)&callBackClose,
231 cast(void*)this,
232 null,
233 connectFlags);
234 connectedSignals["close"] = 1;
236 onCloseListeners ~= dlg;
238 extern(C) static void callBackClose(GtkDialog* dialogStruct, Dialog dialog)
240 bool consumed = false;
242 foreach ( void delegate(Dialog) dlg ; dialog.onCloseListeners )
244 dlg(dialog);
247 return consumed;
250 void delegate(gint, Dialog)[] onResponseListeners;
251 void addOnResponse(void delegate(gint, Dialog) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
253 if ( !("response" in connectedSignals) )
255 Signals.connectData(
256 getStruct(),
257 "response",
258 cast(GCallback)&callBackResponse,
259 cast(void*)this,
260 null,
261 connectFlags);
262 connectedSignals["response"] = 1;
264 onResponseListeners ~= dlg;
266 extern(C) static void callBackResponse(GtkDialog* dialogStruct, gint arg1, Dialog dialog)
268 bool consumed = false;
270 foreach ( void delegate(gint, Dialog) dlg ; dialog.onResponseListeners )
272 dlg(arg1, dialog);
275 return consumed;
283 * Creates a new dialog box. Widgets should not be packed into this GtkWindow
284 * directly, but into the vbox and action_area, as described above.
285 * Returns:
286 * a new GtkDialog.
288 public this ()
290 // GtkWidget* gtk_dialog_new (void);
291 this(cast(GtkDialog*)gtk_dialog_new() );
295 * Creates a new GtkDialog with title title (or NULL for the default
296 * title; see gtk_window_set_title()) and transient parent parent (or
297 * NULL for none; see gtk_window_set_transient_for()). The flags
298 * argument can be used to make the dialog modal (GTK_DIALOG_MODAL)
299 * and/or to have it destroyed along with its transient parent
300 * (GTK_DIALOG_DESTROY_WITH_PARENT). After flags, button
301 * text/response ID pairs should be listed, with a NULL pointer ending
302 * the list. Button text can be either a stock ID such as
303 * GTK_STOCK_OK, or some arbitrary text. A response ID can be
304 * any positive number, or one of the values in the GtkResponseType
305 * enumeration. If the user clicks one of these dialog buttons,
306 * GtkDialog will emit the "response" signal with the corresponding
307 * response ID. If a GtkDialog receives the "delete_event" signal, it
308 * will emit "response" with a response ID of GTK_RESPONSE_DELETE_EVENT.
309 * However, destroying a dialog does not emit the "response" signal;
310 * so be careful relying on "response" when using
311 * the GTK_DIALOG_DESTROY_WITH_PARENT flag. Buttons are from left to right,
312 * so the first button in the list will be the leftmost button in the dialog.
313 * Here's a simple example:
314 * GtkWidget *dialog = gtk_dialog_new_with_buttons ("My dialog",
315 * main_app_window,
316 * GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
317 * GTK_STOCK_OK,
318 * GTK_RESPONSE_ACCEPT,
319 * GTK_STOCK_CANCEL,
320 * GTK_RESPONSE_REJECT,
321 * NULL);
322 * title:
323 * Title of the dialog, or NULL
324 * parent:
325 * Transient parent of the dialog, or NULL
326 * flags:
327 * from GtkDialogFlags
328 * first_button_text:
329 * stock ID or text to go in first button, or NULL
330 * ...:
331 * response ID for first button, then additional buttons, ending with NULL
332 * Returns:
333 * a new GtkDialog
335 public this (char[] title, Window parent, GtkDialogFlags flags, char[] firstButtonText, ... )
337 // GtkWidget* gtk_dialog_new_with_buttons (const gchar *title, GtkWindow *parent, GtkDialogFlags flags, const gchar *first_button_text, ...);
338 this(cast(GtkDialog*)gtk_dialog_new_with_buttons(Str.toStringz(title), (parent is null) ? null : parent.getWindowStruct(), flags, Str.toStringz(firstButtonText)) );
342 * Blocks in a recursive main loop until the dialog either emits the
343 * response signal, or is destroyed. If the dialog is destroyed during the call
344 * to gtk_dialog_run(), gtk_dialog_returns GTK_RESPONSE_NONE.
345 * Otherwise, it returns the response ID from the "response" signal emission.
346 * Before entering the recursive main loop, gtk_dialog_run() calls
347 * gtk_widget_show() on the dialog for you. Note that you still
348 * need to show any children of the dialog yourself.
349 * During gtk_dialog_run(), the default behavior of "delete_event" is
350 * disabled; if the dialog receives "delete_event", it will not be
351 * destroyed as windows usually are, and gtk_dialog_run() will return
352 * GTK_RESPONSE_DELETE_EVENT. Also, during gtk_dialog_run() the dialog will be
353 * modal. You can force gtk_dialog_run() to return at any time by
354 * calling gtk_dialog_response() to emit the "response"
355 * signal. Destroying the dialog during gtk_dialog_run() is a very bad
356 * idea, because your post-run code won't know whether the dialog was
357 * destroyed or not.
358 * After gtk_dialog_run() returns, you are responsible for hiding or
359 * destroying the dialog if you wish to do so.
360 * Typical usage of this function might be:
361 * gint result = gtk_dialog_run (GTK_DIALOG (dialog));
362 * switch (result)
364 * case GTK_RESPONSE_ACCEPT:
365 * do_application_specific_something ();
366 * break;
367 * default:
368 * do_nothing_since_dialog_was_cancelled ();
369 * break;
371 * gtk_widget_destroy (dialog);
372 * Note that even though the recursive main loop gives the effect of a
373 * modal dialog (it prevents the user from interacting with other
374 * windows in the same window group while the dialog is run), callbacks
375 * such as timeouts, IO channel watches, DND drops, etc, will
376 * be triggered during a gtk_dialog_run() call.
377 * dialog:
378 * a GtkDialog
379 * Returns:
380 * response ID
382 public int run()
384 // gint gtk_dialog_run (GtkDialog *dialog);
385 return gtk_dialog_run(gtkDialog);
389 * Emits the "response" signal with the given response ID. Used to
390 * indicate that the user has responded to the dialog in some way;
391 * typically either you or gtk_dialog_run() will be monitoring the
392 * "response" signal and take appropriate action.
393 * dialog:
394 * a GtkDialog
395 * response_id:
396 * response ID
398 public void response(int responseId)
400 // void gtk_dialog_response (GtkDialog *dialog, gint response_id);
401 gtk_dialog_response(gtkDialog, responseId);
405 * Adds a button with the given text (or a stock button, if button_text is a
406 * stock ID) and sets things up so that clicking the button will emit the
407 * "response" signal with the given response_id. The button is appended to the
408 * end of the dialog's action area. The button widget is returned, but usually
409 * you don't need it.
410 * dialog:
411 * a GtkDialog
412 * button_text:
413 * text of button, or stock ID
414 * response_id:
415 * response ID for the button
416 * Returns:
417 * the button widget that was added
419 public Widget addButton(char[] buttonText, int responseId)
421 // GtkWidget* gtk_dialog_add_button (GtkDialog *dialog, const gchar *button_text, gint response_id);
422 return new Widget( gtk_dialog_add_button(gtkDialog, Str.toStringz(buttonText), responseId) );
426 * Adds more buttons, same as calling gtk_dialog_add_button()
427 * repeatedly. The variable argument list should be NULL-terminated
428 * as with gtk_dialog_new_with_buttons(). Each button must have both
429 * text and response ID.
430 * dialog:
431 * a GtkDialog
432 * first_button_text:
433 * button text or stock ID
434 * ...:
435 * response ID for first button, then more text-response_id pairs
437 public void addButtons(char[] firstButtonText, ... )
439 // void gtk_dialog_add_buttons (GtkDialog *dialog, const gchar *first_button_text, ...);
440 gtk_dialog_add_buttons(gtkDialog, Str.toStringz(firstButtonText));
444 * Adds an activatable widget to the action area of a GtkDialog,
445 * connecting a signal handler that will emit the "response" signal on
446 * the dialog when the widget is activated. The widget is appended to
447 * the end of the dialog's action area. If you want to add a
448 * non-activatable widget, simply pack it into the
449 * action_area field of the GtkDialog struct.
450 * dialog:
451 * a GtkDialog
452 * child:
453 * an activatable widget
454 * response_id:
455 * response ID for child
457 public void addActionWidget(Widget child, int responseId)
459 // void gtk_dialog_add_action_widget (GtkDialog *dialog, GtkWidget *child, gint response_id);
460 gtk_dialog_add_action_widget(gtkDialog, (child is null) ? null : child.getWidgetStruct(), responseId);
464 * Accessor for whether the dialog has a separator.
465 * dialog:
466 * a GtkDialog
467 * Returns:
468 * TRUE if the dialog has a separator
470 public int getHasSeparator()
472 // gboolean gtk_dialog_get_has_separator (GtkDialog *dialog);
473 return gtk_dialog_get_has_separator(gtkDialog);
477 * Sets the last widget in the dialog's action area with the given response_id
478 * as the default widget for the dialog. Pressing "Enter" normally activates
479 * the default widget.
480 * dialog:
481 * a GtkDialog
482 * response_id:
483 * a response ID
485 public void setDefaultResponse(int responseId)
487 // void gtk_dialog_set_default_response (GtkDialog *dialog, gint response_id);
488 gtk_dialog_set_default_response(gtkDialog, responseId);
492 * Sets whether the dialog has a separator above the buttons.
493 * TRUE by default.
494 * dialog:
495 * a GtkDialog
496 * setting:
497 * TRUE to have a separator
499 public void setHasSeparator(int setting)
501 // void gtk_dialog_set_has_separator (GtkDialog *dialog, gboolean setting);
502 gtk_dialog_set_has_separator(gtkDialog, setting);
506 * Calls gtk_widget_set_sensitive (widget, setting)
507 * for each widget in the dialog's action area with the given response_id.
508 * A convenient way to sensitize/desensitize dialog buttons.
509 * dialog:
510 * a GtkDialog
511 * response_id:
512 * a response ID
513 * setting:
514 * TRUE for sensitive
516 public void setResponseSensitive(int responseId, int setting)
518 // void gtk_dialog_set_response_sensitive (GtkDialog *dialog, gint response_id, gboolean setting);
519 gtk_dialog_set_response_sensitive(gtkDialog, responseId, setting);
523 * Gets the response id of a widget in the action area
524 * of a dialog.
525 * dialog:
526 * a GtkDialog
527 * widget:
528 * a widget in the action area of dialog
529 * Returns:
530 * the response id of widget, or GTK_RESPONSE_NONE
531 * if widget doesn't have a response id set.
532 * Since 2.8
534 public int getResponseForWidget(Widget widget)
536 // gint gtk_dialog_get_response_for_widget (GtkDialog *dialog, GtkWidget *widget);
537 return gtk_dialog_get_response_for_widget(gtkDialog, (widget is null) ? null : widget.getWidgetStruct());
541 * Returns TRUE if dialogs are expected to use an alternative
542 * button order on the screen screen. See
543 * gtk_dialog_set_alternative_button_order() for more details
544 * about alternative button order.
545 * If you need to use this function, you should probably connect
546 * to the ::notify:gtk-alternative-button-order signal on the
547 * GtkSettings object associated to screen, in order to be
548 * notified if the button order setting changes.
549 * screen:
550 * a GdkScreen, or NULL to use the default screen
551 * Returns:
552 * Whether the alternative button order should be used
553 * Since 2.6
555 public static int alternativeDialogButtonOrder(Screen screen)
557 // gboolean gtk_alternative_dialog_button_order (GdkScreen *screen);
558 return gtk_alternative_dialog_button_order((screen is null) ? null : screen.getScreenStruct());
562 * Sets an alternative button order. If the gtk-alternative-button-order
563 * setting is set to TRUE, the dialog buttons are reordered according to
564 * the order of the response ids passed to this function.
565 * By default, GTK+ dialogs use the button order advocated by the Gnome
566 * Human
567 * Interface Guidelines with the affirmative button at the far
568 * right, and the cancel button left of it. But the builtin GTK+ dialogs
569 * and GtkMessageDialogs do provide an alternative button order,
570 * which is more suitable on some platforms, e.g. Windows.
571 * Use this function after adding all the buttons to your dialog, as the
572 * following example shows:
573 * cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
574 * GTK_STOCK_CANCEL,
575 * GTK_RESPONSE_CANCEL);
576 * ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
577 * GTK_STOCK_OK,
578 * GTK_RESPONSE_OK);
579 * gtk_widget_grab_default (ok_button);
580 * help_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
581 * GTK_STOCK_HELP,
582 * GTK_RESPONSE_HELP);
583 * gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
584 * GTK_RESPONSE_OK,
585 * GTK_RESPONSE_CANCEL,
586 * GTK_RESPONSE_HELP,
587 * -1);
588 * dialog:
589 * a GtkDialog
590 * first_response_id:
591 * a response id used by one dialog's buttons
592 * ...:
593 * a list of more response ids of dialog's buttons, terminated by -1
594 * Since 2.6
596 public void setAlternativeButtonOrder(int firstResponseId, ... )
598 // void gtk_dialog_set_alternative_button_order (GtkDialog *dialog, gint first_response_id, ...);
599 gtk_dialog_set_alternative_button_order(gtkDialog, firstResponseId);
603 * Sets an alternative button order. If the gtk-alternative-button-order
604 * setting is set to TRUE, the dialog buttons are reordered according to
605 * the order of the response ids in new_order.
606 * See gtk_dialog_set_alternative_button_order() for more information.
607 * This function is for use by language bindings.
608 * dialog:
609 * a GtkDialog
610 * n_params:
611 * the number of response ids in new_order
612 * new_order:
613 * an array of response ids of dialog's buttons
614 * Since 2.6
615 * Property Details
616 * The "has-separator" property
617 * "has-separator" gboolean : Read / Write
618 * The dialog has a separator bar above its buttons.
619 * Default value: TRUE
620 * Style Property Details
621 * The "action-area-border" style property
622 * "action-area-border" gint : Read
623 * Width of border around the button area at the bottom of the dialog.
624 * Allowed values: >= 0
625 * Default value: 5
627 public void setAlternativeButtonOrderFromArray(int nParams, int* newOrder)
629 // void gtk_dialog_set_alternative_button_order_from_array (GtkDialog *dialog, gint n_params, gint *new_order);
630 gtk_dialog_set_alternative_button_order_from_array(gtkDialog, nParams, newOrder);