Allow OK/Cancel buttons to be variably focused in MessageBox.

This commit is contained in:
Stephen Anthony 2017-10-05 20:30:36 -02:30
parent e2844f566f
commit 55a281bf34
5 changed files with 46 additions and 67 deletions

View File

@ -652,60 +652,40 @@ Widget* Dialog::findWidget(int x, int y) const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::addOKCancelBGroup(WidgetArray& wid, const GUI::Font& font,
const string& okText, const string& cancelText)
const string& okText, const string& cancelText,
bool focusOKButton)
{
int buttonWidth = std::max(font.getStringWidth("Cancel"),
std::max(font.getStringWidth(okText),
font.getStringWidth(okText))) + 15;
int buttonHeight = font.getLineHeight() + 4;
ButtonWidget* b;
#ifndef BSPF_MAC_OSX
b = new ButtonWidget(this, font, _w - 2 * (buttonWidth + 7), _h - buttonHeight - 10,
buttonWidth, buttonHeight,
okText == "" ? "OK" : okText, GuiObject::kOKCmd);
wid.push_back(b);
addOKWidget(b);
b = new ButtonWidget(this, font, _w - (buttonWidth + 10), _h - buttonHeight - 10,
buttonWidth, buttonHeight,
cancelText == "" ? "Cancel" : cancelText, GuiObject::kCloseCmd);
wid.push_back(b);
addCancelWidget(b);
addOKWidget(new ButtonWidget(this, font, _w - 2 * (buttonWidth + 7),
_h - buttonHeight - 10, buttonWidth, buttonHeight, okText, GuiObject::kOKCmd));
addCancelWidget(new ButtonWidget(this, font, _w - (buttonWidth + 10),
_h - buttonHeight - 10, buttonWidth, buttonHeight, cancelText, GuiObject::kCloseCmd));
#else
b = new ButtonWidget(this, font, _w - 2 * (buttonWidth + 7), _h - buttonHeight - 10,
buttonWidth, buttonHeight,
cancelText == "" ? "Cancel" : cancelText, GuiObject::kCloseCmd);
wid.push_back(b);
addCancelWidget(b);
b = new ButtonWidget(this, font, _w - (buttonWidth + 10), _h - buttonHeight - 10,
buttonWidth, buttonHeight,
okText == "" ? "OK" : okText, GuiObject::kOKCmd);
wid.push_back(b);
addOKWidget(b);
addCancelWidget(new ButtonWidget(this, font, _w - 2 * (buttonWidth + 7),
_h - buttonHeight - 10, buttonWidth, buttonHeight, cancelText, GuiObject::kCloseCmd));
addOKWidget(new ButtonWidget(this, font, _w - (buttonWidth + 10),
_h - buttonHeight - 10, buttonWidth, buttonHeight, okText, GuiObject::kOKCmd));
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog::Focus::Focus(Widget* w)
: widget(w)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog::Focus::~Focus()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog::TabFocus::TabFocus(TabWidget* w)
: widget(w),
currentTab(0)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog::TabFocus::~TabFocus()
{
// Note that 'focusOKButton' only takes effect when there are no other UI
// elements in the dialog; otherwise, the first widget of the dialog is always
// automatically focused first
// Changing this behaviour would require a fairly major refactoring of the UI code
if(focusOKButton)
{
wid.push_back(_okWidget);
wid.push_back(_cancelWidget);
}
else
{
wid.push_back(_cancelWidget);
wid.push_back(_okWidget);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -100,8 +100,9 @@ class Dialog : public GuiObject
Widget* findWidget(int x, int y) const; // Find the widget at pos x,y if any
void addOKCancelBGroup(WidgetArray& wid, const GUI::Font& font,
const string& okText = "",
const string& cancelText = "");
const string& okText = "OK",
const string& cancelText = "Cancel",
bool focusOKButton = true);
void processCancelWithoutWidget(bool state) { _processCancel = state; }
@ -132,8 +133,8 @@ class Dialog : public GuiObject
Widget* widget;
WidgetArray list;
Focus(Widget* w = nullptr);
virtual ~Focus();
Focus(Widget* w = nullptr) : widget(w) { }
virtual ~Focus() = default;
Focus(const Focus&) = default;
Focus& operator=(const Focus&) = default;
@ -145,8 +146,8 @@ class Dialog : public GuiObject
FocusList focus;
uInt32 currentTab;
TabFocus(TabWidget* w = nullptr);
virtual ~TabFocus();
TabFocus(TabWidget* w = nullptr) : widget(w), currentTab(0) { }
virtual ~TabFocus() = default;
TabFocus(const TabFocus&) = default;
TabFocus& operator=(const TabFocus&) = default;

View File

@ -223,7 +223,7 @@ void InputDialog::addDevicePortTab(const GUI::Font& font)
ypos += vGap*4;
fwidth = font.getStringWidth("AtariVox/SaveKey");
lwidth = font.getStringWidth("AtariVox/SaveKey");
new StaticTextWidget(myTab, font, _w - 14 - (fwidth + lwidth) / 2, ypos+2,
new StaticTextWidget(myTab, font, _w - 14 - (fwidth + lwidth) / 2, ypos,
"AtariVox/SaveKey");
// Show joystick database
@ -535,7 +535,8 @@ void InputDialog::handleCommand(CommandSender* sender, int cmd,
msg.push_back("click 'Cancel'.");
myConfirmMsg = make_unique<GUI::MessageBox>
(this, instance().frameBuffer().font(), msg,
myMaxWidth, myMaxHeight, kConfirmEEEraseCmd);
myMaxWidth, myMaxHeight, kConfirmEEEraseCmd,
"OK", "Cancel", false);
}
myConfirmMsg->show();
break;

View File

@ -28,7 +28,8 @@ namespace GUI {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font,
const StringList& text, int max_w, int max_h, int cmd,
const string& okText, const string& cancelText)
const string& okText, const string& cancelText,
bool focusOKButton)
: Dialog(boss->instance(), boss->parent(), 0, 0, max_w, max_h),
CommandSender(boss),
myCmd(cmd)
@ -36,24 +37,18 @@ MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font,
addText(font, text);
WidgetArray wid;
addOKCancelBGroup(wid, font, okText, cancelText);
addOKCancelBGroup(wid, font, okText, cancelText, focusOKButton);
addToFocusList(wid);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font,
const string& text, int max_w, int max_h, int cmd,
const string& okText, const string& cancelText)
: Dialog(boss->instance(), boss->parent(), 0, 0, max_w, max_h),
CommandSender(boss),
myCmd(cmd)
const string& okText, const string& cancelText,
bool focusOKButton)
: MessageBox(boss, font, StringParser(text).stringList(), max_w, max_h,
cmd, okText, cancelText, focusOKButton)
{
StringParser p(text);
addText(font, p.stringList());
WidgetArray wid;
addOKCancelBGroup(wid, font, okText, cancelText);
addToFocusList(wid);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -37,10 +37,12 @@ class MessageBox : public Dialog, public CommandSender
public:
MessageBox(GuiObject* boss, const GUI::Font& font, const StringList& text,
int max_w, int max_h, int cmd = 0,
const string& okText = "", const string& cancelText = "");
const string& okText = "OK", const string& cancelText = "Cancel",
bool focusOKButton = true);
MessageBox(GuiObject* boss, const GUI::Font& font, const string& text,
int max_w, int max_h, int cmd = 0,
const string& okText = "", const string& cancelText = "");
const string& okText = "OK", const string& cancelText = "Cancel",
bool focusOKButton = true);
virtual ~MessageBox() = default;
/** Place the input dialog onscreen and center it */