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 bool(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     this(UIString caption, UIString message, Window parentWindow = null, const(Action) [] buttons = [ACTION_OK], int defaultButtonIndex = 0, bool delegate(const Action result) handler = null) {
45         super(caption, parentWindow, DialogFlag.Modal | (Platform.instance.uiDialogDisplayMode & DialogDisplayMode.messageBoxInPopup ? DialogFlag.Popup : 0));
46         _message = message;
47         _actions = buttons;
48         _defaultButtonIndex = defaultButtonIndex;
49         if (handler) {
50             dialogResult = delegate (Dialog dlg, const Action action) {
51                 handler(action);
52             };
53         }
54     }
55     /// override to implement creation of dialog controls
56     override void initialize() {
57         TextWidget msg = new MultilineTextWidget("msg", _message);
58         padding(Rect(10, 10, 10, 10));
59         msg.padding(Rect(10, 10, 10, 10));
60         addChild(msg);
61         addChild(createButtonsPanel(_actions, _defaultButtonIndex, 0));
62     }
63 
64 }