X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=7f50ed038fbdd6cc4a758adcc0973d84f550b726;hb=d7274749cb0e171e59d7dc9d7d1712906a351119;hp=9f7c761802f5de84af3e77a764788f929865cf7c;hpb=50bf1ef2e2c3c38de20f6996a6c5ed0066111177;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index 9f7c761..7f50ed0 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -8,6 +8,7 @@ Distributed under the LGPL #include #include #include +#include #include "entry.h" #include "graphic.h" #include "part.h" @@ -15,13 +16,15 @@ Distributed under the LGPL using namespace std; +#include + namespace Msp { namespace GLtk { Entry::Entry(const Resources &r, const string &t): Widget(r), text(t), - edit_pos(0) + edit_pos(text.size()) { update_style(); } @@ -29,30 +32,29 @@ Entry::Entry(const Resources &r, const string &t): void Entry::set_text(const string &t) { text=t; - if(edit_pos>text.size()) - edit_pos=text.size(); + edit_pos=text.size(); } void Entry::key_press(unsigned key, unsigned, wchar_t ch) { - if(key==100) + if(key==Input::KEY_LEFT) { if(edit_pos>0) --edit_pos; } - else if(key==102) + else if(key==Input::KEY_RIGHT) { if(edit_pos0) text.erase(--edit_pos, 1); } - else + else if(ch>=' ') { - text+=ch; + text.insert(edit_pos, Codecs::encode(Codecs::ustring(1, ch))); ++edit_pos; } }