1 #include <lib/gui/einputnumber.h>
2 #include <linux/input.h>
4 DEFINE_REF(eInputContentNumber);
6 eInputContentNumber::eInputContentNumber(int cur, int min, int max)
16 void eInputContentNumber::getDisplay(std::string &res, int &cursor)
22 for (int i = 1; i < m_len; ++i)
28 for (i = 0; i < m_len; ++i)
43 void eInputContentNumber::moveCursor(int dir)
45 eDebug("move cursor..");
46 int old_cursor = m_cursor;
69 if (m_cursor != old_cursor)
71 m_input->invalidate();
74 int eInputContentNumber::haveKey(int code, int overwrite)
78 /* we handle KEY_KPx, but not KEY_x. otherwise we would get stuff twice. */
79 #define ASCII(x) (x | 0x8000)
80 #define DIGIT(x) /* case KEY_##x: */ case KEY_KP##x: case ASCII(x|0x30): have_digit=x; break;
99 insertDigit(m_cursor, have_digit);
100 /* if overwrite and not end of line, erase char first. */
101 if (overwrite && m_cursor < m_len)
102 insertDigit(m_cursor + 1, -1);
108 assert(m_cursor <= m_len);
111 m_input->invalidate();
117 void eInputContentNumber::deleteChar(int dir)
119 if (dir == deleteForward)
122 if (m_cursor != m_len)
127 /* backward delete at begin */
134 insertDigit(m_cursor, -1);
140 m_input->invalidate();
143 int eInputContentNumber::isValid()
145 return m_value >= m_min && m_value <= m_max;
148 void eInputContentNumber::validate()
153 void eInputContentNumber::setValue(int val)
157 if (m_cursor > m_len)
160 m_input->invalidate();
163 int eInputContentNumber::getValue()
168 void eInputContentNumber::recalcLen()
178 if (!m_len) /* zero */
182 void eInputContentNumber::insertDigit(int pos, int dig)
184 /* get stuff left from cursor */
187 for (i = 0; i < (m_len - pos); ++i)
190 /* now it's 1...max */
191 int left = m_value / exp;
192 int right = m_value % exp;
198 } else if (dig == -1) /* delete */