1 // Written in the D programming language.
2 
3 /**
4 This module contains common Dialog implementation.
5 
6 
7 Synopsis:
8 
9 ----
10 import dlangui.dialogs.msgbox;
11 
12 // show message box with single Ok button
13 window.showMessageBox(UIString("Dialog title"d), UIString("Some message"d));
14 
15 // show message box with OK and CANCEL buttons, cancel by default, and handle its result
16 window.showMessageBox(UIString("Dialog title"d), UIString("Some message"d), [ACTION_OK, ACTION_CANCEL], 1, delegate(const Action a) {
17     if (a.id == StandardAction.Ok)
18         Log.d("OK pressed");
19     else if (a.id == StandardAction.Cancel)
20         Log.d("CANCEL pressed");
21     return true;
22 });
23 
24 ----
25 
26 Copyright: Vadim Lopatin, 2014
27 License:   Boost License 1.0
28 Authors:   Vadim Lopatin, coolreader.org@gmail.com
29 */
30 module dlangui.dialogs.msgbox;
31 
32 import dlangui.core.i18n;
33 import dlangui.core.signals;
34 import dlangui.core.stdaction;
35 import dlangui.widgets.layouts;
36 import dlangui.widgets.controls;
37 import dlangui.platforms.common.platform;
38 import dlangui.dialogs.dialog;
39 
40 /// Message box
41 class MessageBox : Dialog {
42     protected UIString _message;
43     protected const(Action)[] _actions;
44     protected int _defaultButtonIndex;
45     this(UIString caption, UIString message, Window parentWindow = null, const(Action) [] buttons = [ACTION_OK], int defaultButtonIndex = 0, bool delegate(const Action result) handler = null) {
46         super(caption, parentWindow, DialogFlag.Modal | (Platform.instance.uiDialogDisplayMode & DialogDisplayMode.messageBoxInPopup ? DialogFlag.Popup : 0));
47         _message = message;
48         _actions = buttons;
49         _defaultButtonIndex = defaultButtonIndex;
50         if (handler) {
51             dialogResult = delegate (Dialog dlg, const Action action) {
52                 handler(action);
53             };
54         }
55     }
56     /// override to implement creation of dialog controls
57     override void initialize() {
58         TextWidget msg = new MultilineTextWidget("msg", _message);
59         padding(Rect(10, 10, 10, 10));
60         msg.padding(Rect(10, 10, 10, 10));
61         addChild(msg);
62         addChild(createButtonsPanel(_actions, _defaultButtonIndex, 0));
63     }
64 
65 }