1 #include <lib/gui/einput.h>
2 #include <lib/gdi/font.h>
3 #include <lib/actions/action.h>
5 #include <lib/driver/rc.h>
7 eInput::eInput(eWidget *parent): eWidget(parent)
18 void eInput::setOverwriteMode(int m)
26 void eInput::setContent(eInputContent *content)
29 m_content->setInput(0);
32 m_content->setInput(this);
35 int eInput::event(int event, void *data, void *data2)
41 gPainter &painter = *(gPainter*)data2;
42 ePtr<eWindowStyle> style;
46 eWidget::event(event, data, data2);
48 ePtr<eTextPara> para = new eTextPara(eRect(0, 0, size().width(), size().height()));
54 m_content->getDisplay(text, cursor);
56 eDebug("cursor is %d", cursor);
57 para->setFont(m_font);
58 para->renderString(text, 0);
59 int glyphs = para->size();
63 if (m_mode && cursor < glyphs)
65 /* in overwrite mode, when not at end of line, invert the current cursor position. */
66 para->setGlyphFlag(cursor, GS_INVERT);
67 eRect bbox = para->getGlyphBBox(cursor);
68 bbox = eRect(bbox.left(), 0, bbox.width(), size().height());
72 /* otherwise, insert small cursor */
76 bbox = para->getGlyphBBox(cursor);
77 bbox = eRect(bbox.left()-1, 0, 2, size().height());
80 bbox = para->getGlyphBBox(cursor - 1);
81 bbox = eRect(bbox.right(), 0, 2, size().height());
84 bbox = eRect(0, 0, 2, size().height());
90 painter.renderPara(para, ePoint(0, 0));
100 m_content->moveCursor(eInputContent::dirLeft);
103 m_content->moveCursor(eInputContent::dirRight);
106 m_content->moveCursor(eInputContent::dirHome);
109 m_content->moveCursor(eInputContent::dirEnd);
112 m_content->deleteChar(eInputContent::deleteForward);
115 m_content->deleteChar(eInputContent::deleteBackward);
117 case toggleOverwrite:
118 setOverwriteMode(!m_mode);
130 int flags = (int)data2;
131 if (m_content && !(flags & 1)) // only make/repeat, no break
132 return m_content->haveKey(key, m_mode);
137 eDebug("focus got in %p", this);
138 ePtr<eActionMap> ptr;
139 eActionMap::getInstance(ptr);
140 ptr->bindAction("InputActions", 0, 0, this);
142 ptr->bindAction("", 0, 1, this);
144 eRCInput::getInstance()->setKeyboardMode(eRCInput::kmAscii);
145 // fixme. we should use a style for this.
146 setBackgroundColor(gRGB(64, 64, 128));
152 eDebug("focus lostin %p", this);
153 ePtr<eActionMap> ptr;
154 eActionMap::getInstance(ptr);
155 ptr->unbindAction(this, 0);
156 ptr->unbindAction(this, 1);
159 m_content->validate();
160 eRCInput::getInstance()->setKeyboardMode(eRCInput::kmNone);
161 clearBackgroundColor();
168 return eWidget::event(event, data, data2);
171 void eInput::setFont(gFont *fnt)
177 void eInputContent::setInput(eInput *widget)