/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2008, 2010 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
using namespace std;
using namespace Msp;
-::Input::Input(Designer &d, const string &title, const string &text):
- Panel(d.get_ui_resources()),
+InputDialog::InputDialog(Designer &d, const string &title, const string &text):
designer(d)
{
set_size(300, 100);
GLtk::Label *lbl;
- add(*(lbl=new GLtk::Label(res, title)));
+ add(*(lbl=new GLtk::Label(title)));
lbl->set_geometry(GLtk::Geometry(10, geom.h-30, geom.w-20, 20));
- add(*(entry=new GLtk::Entry(res, text)));
+ add(*(entry=new GLtk::Entry(text)));
entry->set_geometry(GLtk::Geometry(10, geom.h-60, geom.w-20, 20));
GLtk::Button *btn;
- add(*(btn=new GLtk::Button(res, "Cncl")));
+ add_button(*(btn=new GLtk::Button("Cncl")), 0);
btn->set_geometry(GLtk::Geometry(geom.w-90, 10, 40, 24));
btn->set_style("red");
- btn->signal_clicked.connect(signal_cancel);
- add(*(btn=new GLtk::Button(res, "OK")));
+ add_button(*(btn=new GLtk::Button("OK")), 1);
btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24));
btn->set_style("green");
- btn->signal_clicked.connect(signal_accept);
designer.get_root().add(*this);
const GLtk::Geometry &rgeom=designer.get_root().get_geometry();
entry->set_focus();
}
-const string &::Input::get_text() const
-{
- return entry->get_text();
-}
-
-void ::Input::key_press(unsigned key, unsigned mod, wchar_t ch)
+void InputDialog::key_press(unsigned key, unsigned mod, wchar_t ch)
{
if(key==Msp::Input::KEY_ENTER)
- signal_accept.emit();
+ response(1);
else if(key==Msp::Input::KEY_ESC)
- signal_cancel.emit();
+ response(0);
else
- Panel::key_press(key, mod, ch);
+ Dialog::key_press(key, mod, ch);
+}
+
+void InputDialog::on_response(int code)
+{
+ if(code)
+ signal_accept.emit(entry->get_text());
}