]> Dogcows Code - chaz/openbox/blobdiff - otk/messagedialog.cc
make DialogButtons take char*'s meaning that the label will always be Utf-8
[chaz/openbox] / otk / messagedialog.cc
index df004347bdf3dd9b9826dd42c7d69d753e738e0b..b1f6c61af7abf580f11ee338b0efeb2c63ca46c5 100644 (file)
@@ -101,7 +101,8 @@ MessageDialog::~MessageDialog()
 
 const DialogButton& MessageDialog::run()
 {
-  show();
+  if (!visible())
+    show();
 
   while (visible()) {
     dispatcher()->dispatchEvents();
@@ -111,6 +112,12 @@ const DialogButton& MessageDialog::run()
   return *_result;
 }
 
+void MessageDialog::focus()
+{
+  if (visible())
+    XSetInputFocus(**display, window(), None, CurrentTime);
+}
+
 void MessageDialog::show()
 {
   std::vector<DialogButton>::const_iterator it, end = _buttons.end();
@@ -118,11 +125,17 @@ void MessageDialog::show()
     _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;
   size.min_width = minSize().width();
   size.min_height = minSize().height();
-  XSetWMNormalHints(**display, window(), &size);
 
   Size dest = area().size();
   if (dest.width() < 200 || dest.height() < 100) {
@@ -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();
 }
 
@@ -149,9 +168,9 @@ void MessageDialog::keyPressHandler(const XKeyEvent &e)
     for (it = _buttons.begin(); it != end; ++it)
       if (it->isDefault()) {
        _result = &(*it);
+       hide();
        break;
       }
-    hide();
   } else if (e.keycode == _escape) {
     hide();
   }
This page took 0.02246 seconds and 4 git commands to generate.