]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/input.cpp
Rename Input to InputDialog to avoid the conflict with the Msp::Input namespace
[r2c2.git] / source / designer / input.cpp
index b0e12515fa92d7d80dc129101e4119ab3570a2c7..e2b0ae0e06a175f8215b8299248fd07709ddfd49 100644 (file)
@@ -1,7 +1,7 @@
 /* $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
 */
 
@@ -15,9 +15,9 @@ Distributed under the GPL
 using namespace std;
 using namespace Msp;
 
-::Input::Input(Designer &d, const string &title, const string &text):
+InputDialog::InputDialog(Designer &d, const string &title, const string &text):
        GLtk::Widget(d.get_ui_resources()),
-       GLtk::Panel(d.get_ui_resources()),
+       GLtk::Dialog(d.get_ui_resources()),
        designer(d)
 {
        set_size(300, 100);
@@ -31,15 +31,13 @@ using namespace Msp;
 
        GLtk::Button *btn;
 
-       add(*(btn=new GLtk::Button(res, "Cncl")));
+       add_button(*(btn=new GLtk::Button(res, "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(res, "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();
@@ -47,17 +45,18 @@ using namespace Msp;
        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());
 }