X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Fmessagedialog.cc;h=ac468cb3768b3450fc2186225aca1a52567c47bb;hb=bfea000a7407e51b5659590415e410a47f6f046b;hp=df004347bdf3dd9b9826dd42c7d69d753e738e0b;hpb=7a41f7730dfa7e5733720f98f89c5a5906f1e786;p=chaz%2Fopenbox diff --git a/otk/messagedialog.cc b/otk/messagedialog.cc index df004347..ac468cb3 100644 --- a/otk/messagedialog.cc +++ b/otk/messagedialog.cc @@ -15,17 +15,13 @@ namespace otk { -DialogButton MessageDialog::_default_result("", false); - class DialogButtonWidget : public Button { MessageDialog *_dia; - const DialogButton &_res; public: DialogButtonWidget(Widget *parent, MessageDialog *dia, const DialogButton &b) : Button(parent), - _dia(dia), - _res(b) + _dia(dia) { assert(dia); setBevel(1); @@ -41,27 +37,30 @@ public: Button::buttonPressHandler(e); } virtual void clickHandler(unsigned int) { - _dia->setResult(_res); + _dia->setResult(DialogButton(text(), isHighlighted())); _dia->hide(); } }; MessageDialog::MessageDialog(int screen, EventDispatcher *ed, ustring title, ustring caption) - : Widget(screen, ed, Widget::Vertical) + : Widget(screen, ed, Widget::Vertical), + _result("", false) { init(title, caption); } MessageDialog::MessageDialog(EventDispatcher *ed, ustring title, ustring caption) - : Widget(DefaultScreen(**display), ed, Widget::Vertical) + : Widget(DefaultScreen(**display), ed, Widget::Vertical), + _result("", false) { init(title, caption); } MessageDialog::MessageDialog(Widget *parent, ustring title, ustring caption) - : Widget(parent, Widget::Vertical) + : Widget(parent, Widget::Vertical), + _result("", false) { init(title, caption); } @@ -75,7 +74,6 @@ void MessageDialog::init(const ustring &title, const ustring &caption) _button_holder->show(); _return = XKeysymToKeycode(**display, XStringToKeysym("Return")); _escape = XKeysymToKeycode(**display, XStringToKeysym("Escape")); - _result = &_default_result; setEventMask(eventMask() | KeyPressMask); _label->setText(caption); @@ -101,30 +99,45 @@ MessageDialog::~MessageDialog() const DialogButton& MessageDialog::run() { - show(); + if (!visible()) + show(); while (visible()) { dispatcher()->dispatchEvents(); if (visible()) 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() +{ + if (visible()) + XSetInputFocus(**display, window(), None, CurrentTime); } void MessageDialog::show() { - std::vector::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; + if (parent()) + r = parent()->area(); + else + r = Rect(Point(0, 0), display->screenInfo(screen())->size()); + XSizeHints size; - size.flags = PMinSize; + size.flags = PMinSize | PPosition | PWinGravity; size.min_width = minSize().width(); size.min_height = minSize().height(); - XSetWMNormalHints(**display, window(), &size); + size.win_gravity = CenterGravity; - Size dest = area().size(); + Size dest = minSize(); if (dest.width() < 200 || dest.height() < 100) { if (dest.width() < 200 && dest.height() < 100) dest = Size(200, 100); else if (dest.width() < 200) dest = Size(200, dest.height()); @@ -132,6 +145,12 @@ void MessageDialog::show() resize(dest); } + // center it above its parent + move(Point(r.x() + (r.width() - dest.width()) / 2, + r.y() + (r.height() - dest.height()) / 2)); + + XSetWMNormalHints(**display, window(), &size); + Widget::show(); } @@ -145,13 +164,13 @@ void MessageDialog::hide() void MessageDialog::keyPressHandler(const XKeyEvent &e) { if (e.keycode == _return) { - std::vector::const_iterator it, end = _buttons.end(); - for (it = _buttons.begin(); it != end; ++it) - if (it->isDefault()) { - _result = &(*it); + std::vector