]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/entry.cpp
Clear focus in Panel if focused child is removed
[libs/gltk.git] / source / entry.cpp
index 9f7c761802f5de84af3e77a764788f929865cf7c..efb4b45c57d354ca4f11b453ff567fe58d108421 100644 (file)
@@ -8,6 +8,7 @@ Distributed under the LGPL
 #include <msp/gl/matrix.h>
 #include <msp/gl/texture.h>
 #include <msp/gl/transform.h>
+#include <msp/input/keys.h>
 #include "entry.h"
 #include "graphic.h"
 #include "part.h"
@@ -15,13 +16,15 @@ Distributed under the LGPL
 
 using namespace std;
 
+#include <iostream>
+
 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_pos<text.size())
                        ++edit_pos;
        }
-       else if(key==22)
+       else if(key==Input::KEY_BACKSPACE)
        {
                if(edit_pos>0)
                        text.erase(--edit_pos, 1);
        }
        else
        {
-               text+=ch;
+               text.insert(edit_pos, Codecs::encode<Codecs::Utf8>(Codecs::ustring(1, ch)));
                ++edit_pos;
        }
 }