X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=lib%2Fgui%2Feinputstring.cpp;fp=lib%2Fgui%2Feinputstring.cpp;h=9ead4fa9b5b91d15c4ebea1f906991901e5eee28;hp=0000000000000000000000000000000000000000;hb=ee0a99a85f0e8c01e44422c4bc2c81fce7ee7e5e;hpb=34c3f1a742135c764ced560e8479e77129082301 diff --git a/lib/gui/einputstring.cpp b/lib/gui/einputstring.cpp new file mode 100644 index 0000000..9ead4fa --- /dev/null +++ b/lib/gui/einputstring.cpp @@ -0,0 +1,126 @@ +#include + +DEFINE_REF(eInputContentString); + +eInputContentString::eInputContentString() +{ + m_string = "bla"; + m_cursor = 0; + m_input = 0; + m_len = m_string.size(); +} + +void eInputContentString::getDisplay(std::string &res, int &cursor) +{ + res = m_string; + cursor = m_cursor; +} + +void eInputContentString::moveCursor(int dir) +{ + int old_cursor = m_cursor; + + switch (dir) + { + case dirLeft: + --m_cursor; + break; + case dirRight: + ++m_cursor; + break; + case dirHome: + m_cursor = 0; + break; + case dirEnd: + m_cursor = m_len; + break; + } + + if (m_cursor < 0) + m_cursor = 0; + if (m_cursor > m_len) + m_cursor = m_len; + + if (m_cursor != old_cursor) + if (m_input) + m_input->invalidate(); +} + +int eInputContentString::haveKey(int code, int overwrite) +{ + int have_char = -1; + + if (code >= 0x8020) + have_char = code &~ 0x8000; + + if (have_char != -1) + { + if (overwrite && m_cursor < m_len) + m_string[m_cursor] = have_char; + else + { + m_string.insert(m_cursor, 1, have_char); + ++m_len; + } + + m_cursor++; + + assert(m_cursor <= m_len); + + if (m_input) + m_input->invalidate(); + return 1; + } + return 0; +} + +void eInputContentString::deleteChar(int dir) +{ + if (dir == deleteForward) + { + eDebug("forward"); + if (m_cursor != m_len) + ++m_cursor; + else + return; + } + /* backward delete at begin */ + if (!m_cursor) + return; + + if (!m_len) + return; + + m_string.erase(m_cursor - 1, m_cursor); + + m_len--; + m_cursor--; + + if (m_input) + m_input->invalidate(); +} + +int eInputContentString::isValid() +{ + return 1; +} + +void eInputContentString::validate() +{ +} + +void eInputContentString::setText(const std::string &str) +{ + m_string = str; + m_len = m_string.size(); + if (m_cursor > m_len) + m_cursor = m_len; + + if (m_input) + m_input->invalidate(); +} + +std::string eInputContentString::getText() +{ + return m_string; +}