1 #include <lib/gui/einput.h>
2 #include <lib/gdi/font.h>
3 #include <lib/actions/action.h>
5 eInput::eInput(eWidget *parent): eLabel(parent)
7 /* default to center alignment */
8 m_valign = alignCenter;
9 m_halign = alignCenter;
12 eActionMap::getInstance(ptr);
13 ptr->bindAction("InputActions", 0, 0, this);
19 eActionMap::getInstance(ptr);
20 ptr->unbindAction(this, 0);
23 void eInput::setContent(eInputContent *content)
26 m_content->setInput(0);
29 m_content->setInput(this);
32 int eInput::event(int event, void *data, void *data2)
38 gPainter &painter = *(gPainter*)data2;
39 ePtr<eWindowStyle> style;
43 eWidget::event(event, data, data2);
45 ePtr<eTextPara> para = new eTextPara(eRect(0, 0, size().width(), size().height()));
51 m_content->getDisplay(text, cursor);
53 eDebug("cursor is %d", cursor);
54 para->setFont(m_font);
55 para->renderString(text, 0);
57 int glyphs = para->size();
61 bbox = para->getGlyphBBox(cursor);
62 bbox = eRect(bbox.left()-1, 0, 2, size().height());
65 bbox = para->getGlyphBBox(cursor - 1);
66 bbox = eRect(bbox.right(), 0, 2, size().height());
70 painter.renderPara(para, ePoint(0, 0));
80 m_content->moveCursor(eInputContent::dirLeft);
83 m_content->moveCursor(eInputContent::dirRight);
86 m_content->moveCursor(eInputContent::dirHome);
89 m_content->moveCursor(eInputContent::dirEnd);
101 return eLabel::event(event, data, data2);
104 int eInput::getNumber()
106 return atoi(m_text.c_str());
109 DEFINE_REF(eInputContentNumber);
111 void eInputContent::setInput(eInput *widget)
116 eInputContentNumber::eInputContentNumber(int cur, int min, int max)
126 void eInputContentNumber::getDisplay(std::string &res, int &cursor)
130 sprintf(r, "%d", m_value);
135 void eInputContentNumber::moveCursor(int dir)
137 eDebug("move cursor..");
138 int old_cursor = m_cursor;
158 if (m_cursor > m_len)
161 if (m_cursor != old_cursor)
163 m_input->invalidate();
166 int eInputContentNumber::haveKey(int code)
168 insertDigit(m_cursor, code);
173 int eInputContentNumber::isValid()
175 return m_value >= m_min && m_value <= m_max;
178 void eInputContentNumber::recalcLen()
188 if (!m_len) /* zero */
192 void eInputContentNumber::insertDigit(int pos, int dig)
194 /* get stuff left from cursor */
197 for (i = 0; i < (m_len - pos - 1); ++i)
200 /* now it's 1...max */
201 int left = m_value / exp;
202 int right = m_value % exp;