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.empty()?0:text.c_str(), 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));
97 if ((long)data == ASCII_ACTIONS)
99 if ((long)data2 == gotAsciiCode)
103 extern int getPrevAsciiCode(); // defined in enigma.cpp
104 return m_content->haveKey(getPrevAsciiCode(), m_mode);
108 else if ((long)data == INPUT_ACTIONS)
114 m_content->moveCursor(eInputContent::dirLeft);
118 m_content->moveCursor(eInputContent::dirRight);
122 m_content->moveCursor(eInputContent::dirHome);
126 m_content->moveCursor(eInputContent::dirEnd);
130 m_content->deleteChar(eInputContent::deleteForward);
134 m_content->deleteChar(eInputContent::deleteBackward);
136 case toggleOverwrite:
137 setOverwriteMode(!m_mode);
149 long key = (long)data;
150 long flags = (long)data2;
151 if (m_content && !(flags & 1)) // only make/repeat, no break
152 return m_content->haveKey(key, m_mode);
157 eDebug("focus got in %p", this);
158 ePtr<eActionMap> ptr;
159 eActionMap::getInstance(ptr);
160 ptr->bindAction("InputActions", 0, INPUT_ACTIONS, this);
161 ptr->bindAction("AsciiActions", 0, ASCII_ACTIONS, this);
163 eRCInput::getInstance()->setKeyboardMode(eRCInput::kmAscii);
164 // fixme. we should use a style for this.
165 setBackgroundColor(gRGB(64, 64, 128));
171 eDebug("focus lostin %p", this);
172 ePtr<eActionMap> ptr;
173 eActionMap::getInstance(ptr);
174 ptr->unbindAction(this, INPUT_ACTIONS);
175 ptr->unbindAction(this, ASCII_ACTIONS);
178 m_content->validate();
179 eRCInput::getInstance()->setKeyboardMode(eRCInput::kmNone);
180 clearBackgroundColor();
187 return eWidget::event(event, data, data2);
190 void eInput::setFont(gFont *fnt)
196 void eInputContent::setInput(eInput *widget)