1 // This file is part of the utui library, a terminal UI framework.
3 // Copyright (C) 2006 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
12 //----------------------------------------------------------------------
17 cmd_Ok
= cmd_MsgBoxFirst
,
25 c_nMsgBoxCmds
= cmd_MsgBoxLast
- cmd_MsgBoxFirst
28 static const CMessageBox::SCmd s_MBCmds
[c_nMsgBoxCmds
] = {
29 { cmd_Ok
, cmd_MBBase
, 0, "&Ok" },
30 { cmd_Cancel
, cmd_MBBase
, 0, "&Cancel" },
31 { cmd_Yes
, cmd_MBBase
, 0, "&Yes" },
32 { cmd_No
, cmd_MBBase
, 0, "&No" },
33 { cmd_Abort
, cmd_MBBase
, 0, "&Abort" },
34 { cmd_Retry
, cmd_MBBase
, 0, "&Retry" },
35 { cmd_Ignore
, cmd_MBBase
, 0, "&Ignore" }
38 //----------------------------------------------------------------------
40 #define BEGIN_STD_MESSAGE_BOX(name, nButtons) \
41 BEGIN_DIALOG_DESC (name) \
43 LAYOUT_TILE (2, ld_Vertical, 1, 0, 0) \
44 LAYOUT_ALIGN (1, ld_Horizontal, la_Left, 1, 1) \
46 LAYOUT_ALIGN (1, ld_Horizontal, la_Center, 1, 1) \
47 LAYOUT_TILE (nButtons, ld_Horizontal, 1, 0, 0)
49 #define MB_BUTTON(name) BUTTON(s_MBCmds [cmd_##name - cmd_MsgBoxFirst])
51 BEGIN_STD_MESSAGE_BOX (c_OkDlgDesc
, 1)
55 BEGIN_STD_MESSAGE_BOX (c_OkCancelDlgDesc
, 2)
60 BEGIN_STD_MESSAGE_BOX (c_YesNoDlgDesc
, 2)
65 BEGIN_STD_MESSAGE_BOX (c_YesNoCancelDlgDesc
, 3)
71 BEGIN_STD_MESSAGE_BOX (c_AbortRetryIgnoreDlgDesc
, 3)
78 #undef BEGIN_STD_MESSAGE_BOX
80 //----------------------------------------------------------------------
82 /// Default constructor.
83 CMessageBox::CMessageBox (const string
& s
, EMBType t
)
88 static const SWidgetDesc
* const c_StdDlgs
[MB_Last
] = {
93 c_AbortRetryIgnoreDlgDesc
95 InitFromDesc (c_StdDlgs
[t
]);
96 TCW
<CLabel
>(0).SetText (s
);
99 void CMessageBox::OnCommand (cmd_t cmd
)
101 uoff_t cmdIdx
= cmd
- cmd_MsgBoxFirst
;
102 if (cmdIdx
>= c_nMsgBoxCmds
)
103 return (CDialog::OnCommand (cmd
));
104 static const uint8_t c_rvs
[c_nMsgBoxCmds
] = {
105 mbrv_Ok
, mbrv_Cancel
, mbrv_Yes
, mbrv_No
, mbrv_Abort
, mbrv_Retry
, mbrv_Ignore
107 Close (c_rvs
[cmdIdx
]);
110 /// Responds to \p key.
111 void CMessageBox::OnKey (wchar_t key
)
113 // Enter closes with current button, or the default action (first button)
115 case kv_Right
: SetFocus (GetNextFocus()); break;
116 case kv_Left
: SetFocus (GetNextFocus(-1)); break;
117 case kv_Esc
: Close (mbrv_Cancel
); break;
118 default: CDialog::OnKey (key
); break;
122 //----------------------------------------------------------------------
124 int MessageBox (const string
& s
, EMBType t
)
126 return (CRootWindow::Instance().RunModal (new CMessageBox (s
, t
)));
129 //----------------------------------------------------------------------