cleanup
This commit is contained in:
parent
93ea4c4d2e
commit
6354e77144
2 changed files with 26 additions and 29 deletions
|
@ -15,17 +15,13 @@
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
DialogButton MessageDialog::_default_result("", false);
|
|
||||||
|
|
||||||
class DialogButtonWidget : public Button {
|
class DialogButtonWidget : public Button {
|
||||||
MessageDialog *_dia;
|
MessageDialog *_dia;
|
||||||
const DialogButton &_res;
|
|
||||||
public:
|
public:
|
||||||
DialogButtonWidget(Widget *parent, MessageDialog *dia,
|
DialogButtonWidget(Widget *parent, MessageDialog *dia,
|
||||||
const DialogButton &b)
|
const DialogButton &b)
|
||||||
: Button(parent),
|
: Button(parent),
|
||||||
_dia(dia),
|
_dia(dia)
|
||||||
_res(b)
|
|
||||||
{
|
{
|
||||||
assert(dia);
|
assert(dia);
|
||||||
setBevel(1);
|
setBevel(1);
|
||||||
|
@ -41,27 +37,30 @@ public:
|
||||||
Button::buttonPressHandler(e);
|
Button::buttonPressHandler(e);
|
||||||
}
|
}
|
||||||
virtual void clickHandler(unsigned int) {
|
virtual void clickHandler(unsigned int) {
|
||||||
_dia->setResult(_res);
|
_dia->setResult(DialogButton(text(), isHighlighted()));
|
||||||
_dia->hide();
|
_dia->hide();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MessageDialog::MessageDialog(int screen, EventDispatcher *ed, ustring title,
|
MessageDialog::MessageDialog(int screen, EventDispatcher *ed, ustring title,
|
||||||
ustring caption)
|
ustring caption)
|
||||||
: Widget(screen, ed, Widget::Vertical)
|
: Widget(screen, ed, Widget::Vertical),
|
||||||
|
_result("", false)
|
||||||
{
|
{
|
||||||
init(title, caption);
|
init(title, caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageDialog::MessageDialog(EventDispatcher *ed, ustring title,
|
MessageDialog::MessageDialog(EventDispatcher *ed, ustring title,
|
||||||
ustring caption)
|
ustring caption)
|
||||||
: Widget(DefaultScreen(**display), ed, Widget::Vertical)
|
: Widget(DefaultScreen(**display), ed, Widget::Vertical),
|
||||||
|
_result("", false)
|
||||||
{
|
{
|
||||||
init(title, caption);
|
init(title, caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageDialog::MessageDialog(Widget *parent, ustring title, ustring caption)
|
MessageDialog::MessageDialog(Widget *parent, ustring title, ustring caption)
|
||||||
: Widget(parent, Widget::Vertical)
|
: Widget(parent, Widget::Vertical),
|
||||||
|
_result("", false)
|
||||||
{
|
{
|
||||||
init(title, caption);
|
init(title, caption);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +74,6 @@ void MessageDialog::init(const ustring &title, const ustring &caption)
|
||||||
_button_holder->show();
|
_button_holder->show();
|
||||||
_return = XKeysymToKeycode(**display, XStringToKeysym("Return"));
|
_return = XKeysymToKeycode(**display, XStringToKeysym("Return"));
|
||||||
_escape = XKeysymToKeycode(**display, XStringToKeysym("Escape"));
|
_escape = XKeysymToKeycode(**display, XStringToKeysym("Escape"));
|
||||||
_result = &_default_result;
|
|
||||||
|
|
||||||
setEventMask(eventMask() | KeyPressMask);
|
setEventMask(eventMask() | KeyPressMask);
|
||||||
_label->setText(caption);
|
_label->setText(caption);
|
||||||
|
@ -109,7 +107,13 @@ const DialogButton& MessageDialog::run()
|
||||||
if (visible())
|
if (visible())
|
||||||
Timer::dispatchTimers(); // fire pending events
|
Timer::dispatchTimers(); // fire pending events
|
||||||
}
|
}
|
||||||
return *_result;
|
return _result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageDialog::addButton(const DialogButton &b)
|
||||||
|
{
|
||||||
|
_button_widgets.push_back(new DialogButtonWidget(_button_holder,
|
||||||
|
this, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageDialog::focus()
|
void MessageDialog::focus()
|
||||||
|
@ -120,11 +124,6 @@ void MessageDialog::focus()
|
||||||
|
|
||||||
void MessageDialog::show()
|
void MessageDialog::show()
|
||||||
{
|
{
|
||||||
std::vector<DialogButton>::const_iterator it, end = _buttons.end();
|
|
||||||
for (it = _buttons.begin(); it != end; ++it)
|
|
||||||
_button_widgets.push_back(new DialogButtonWidget(_button_holder,
|
|
||||||
this, *it));
|
|
||||||
|
|
||||||
Rect r;
|
Rect r;
|
||||||
|
|
||||||
if (parent())
|
if (parent())
|
||||||
|
@ -165,10 +164,10 @@ void MessageDialog::hide()
|
||||||
void MessageDialog::keyPressHandler(const XKeyEvent &e)
|
void MessageDialog::keyPressHandler(const XKeyEvent &e)
|
||||||
{
|
{
|
||||||
if (e.keycode == _return) {
|
if (e.keycode == _return) {
|
||||||
std::vector<DialogButton>::const_iterator it, end = _buttons.end();
|
std::vector<Button *>::const_iterator it, end = _button_widgets.end();
|
||||||
for (it = _buttons.begin(); it != end; ++it)
|
for (it = _button_widgets.begin(); it != end; ++it)
|
||||||
if (it->isDefault()) {
|
if ((*it)->isHighlighted()) {
|
||||||
_result = &(*it);
|
_result = DialogButton((*it)->text(), true);
|
||||||
hide();
|
hide();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@ class DialogButton {
|
||||||
ustring _label;
|
ustring _label;
|
||||||
bool _default;
|
bool _default;
|
||||||
public:
|
public:
|
||||||
DialogButton(char *label) : _label(label), _default(false)
|
DialogButton(ustring label) : _label(label), _default(false)
|
||||||
{}
|
{}
|
||||||
DialogButton(char *label, bool def) : _label(label), _default(def)
|
DialogButton(ustring label, bool def) : _label(label), _default(def)
|
||||||
{}
|
{}
|
||||||
inline const ustring& label() const { return _label; }
|
inline const ustring& label() const { return _label; }
|
||||||
inline const bool& isDefault() const { return _default; }
|
inline const bool& isDefault() const { return _default; }
|
||||||
|
@ -35,7 +35,7 @@ public:
|
||||||
MessageDialog(Widget *parent, ustring title, ustring caption);
|
MessageDialog(Widget *parent, ustring title, ustring caption);
|
||||||
virtual ~MessageDialog();
|
virtual ~MessageDialog();
|
||||||
|
|
||||||
virtual void addButton(const DialogButton &b) { _buttons.push_back(b); }
|
virtual void addButton(const DialogButton &b);
|
||||||
|
|
||||||
virtual const DialogButton& run();
|
virtual const DialogButton& run();
|
||||||
|
|
||||||
|
@ -43,24 +43,22 @@ public:
|
||||||
virtual void hide();
|
virtual void hide();
|
||||||
virtual void focus();
|
virtual void focus();
|
||||||
|
|
||||||
virtual const DialogButton& result() const { return *_result; }
|
virtual const DialogButton& result() const { return _result; }
|
||||||
virtual void setResult(const DialogButton &result) { _result = &result; }
|
virtual void setResult(const DialogButton &result) { _result = result; }
|
||||||
|
|
||||||
virtual void keyPressHandler(const XKeyEvent &e);
|
virtual void keyPressHandler(const XKeyEvent &e);
|
||||||
virtual void clientMessageHandler(const XClientMessageEvent &e);
|
virtual void clientMessageHandler(const XClientMessageEvent &e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static DialogButton _default_result;
|
|
||||||
|
|
||||||
void init(const ustring &title, const ustring &caption);
|
void init(const ustring &title, const ustring &caption);
|
||||||
|
|
||||||
std::vector<DialogButton> _buttons;
|
protected:
|
||||||
std::vector<Button *> _button_widgets;
|
std::vector<Button *> _button_widgets;
|
||||||
Label *_label;
|
Label *_label;
|
||||||
Widget *_button_holder;
|
Widget *_button_holder;
|
||||||
KeyCode _return;
|
KeyCode _return;
|
||||||
KeyCode _escape;
|
KeyCode _escape;
|
||||||
const DialogButton *_result;
|
DialogButton _result;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue