From 25d2663dc4008127dad965cca5712a4faac66a10 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Wed, 15 May 2013 19:22:04 +0200 Subject: fix. --- plugingui/lineedit.cc | 18 +++++++++++++++++- plugingui/lineedit.h | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/plugingui/lineedit.cc b/plugingui/lineedit.cc index 3e1f24b..9308902 100644 --- a/plugingui/lineedit.cc +++ b/plugingui/lineedit.cc @@ -30,6 +30,8 @@ #include "window.h" +#include + #define BORDER 10 GUI::LineEdit::LineEdit(Widget *parent) @@ -47,6 +49,14 @@ GUI::LineEdit::LineEdit(Widget *parent) box.bottom = new Image(":widget_b.png"); box.bottomRight = new Image(":widget_br.png"); box.center = new Image(":widget_c.png"); + + handler = NULL; +} + +void GUI::LineEdit::registerEnterPressedHandler(void (*handler)(void *), void *ptr) +{ + this->handler = handler; + this->ptr = ptr; } void GUI::LineEdit::setReadOnly(bool ro) @@ -62,6 +72,8 @@ bool GUI::LineEdit::readOnly() void GUI::LineEdit::setText(std::string text) { _text = text; + if(_text.size() < pos) pos = text.size(); + repaintEvent(NULL); textChanged(); } @@ -90,6 +102,8 @@ void GUI::LineEdit::keyEvent(GUI::KeyEvent *e) { if(readOnly()) return; + DEBUG(lineedit, "Handling keyevent with text '%s'\n", _text.c_str()); + bool change = false; if(e->direction == -1) { @@ -108,6 +122,7 @@ void GUI::LineEdit::keyEvent(GUI::KeyEvent *e) } else if(e->keycode == GUI::KeyEvent::KEY_DELETE) { if(pos < _text.length()) { + printf("AAA: %d\n", pos); std::string t = _text.substr(0, pos); t += _text.substr(pos + 1, std::string::npos); _text = t; @@ -129,8 +144,9 @@ void GUI::LineEdit::keyEvent(GUI::KeyEvent *e) _text = pre + e->text + post; change = true; pos++; + } else if(e->keycode == GUI::KeyEvent::KEY_ENTER) { + if(handler) handler(ptr); } - repaintEvent(NULL); } diff --git a/plugingui/lineedit.h b/plugingui/lineedit.h index a159d75..2c37522 100644 --- a/plugingui/lineedit.h +++ b/plugingui/lineedit.h @@ -48,6 +48,8 @@ public: void setReadOnly(bool readonly); bool readOnly(); + void registerEnterPressedHandler(void (*handler)(void *), void *ptr); + //protected: virtual void keyEvent(KeyEvent *e); virtual void repaintEvent(RepaintEvent *e); @@ -65,6 +67,9 @@ private: size_t pos; bool readonly; + + void (*handler)(void *); + void *ptr; }; }; -- cgit v1.2.3