rework key input handling, add more script events for UI and implement console history

This commit is contained in:
Eduardo Bart
2011-08-28 18:32:24 -03:00
parent 7242dfc9ee
commit 8aadea2a96
12 changed files with 494 additions and 314 deletions

View File

@@ -235,10 +235,8 @@ void UILineEdit::setText(const std::string& text)
{
if(m_text != text) {
m_text = text;
if(m_cursorPos >= 0) {
m_cursorPos = 0;
blinkCursor();
}
m_cursorPos = text.length();
blinkCursor();
update();
}
}
@@ -391,24 +389,24 @@ void UILineEdit::onFocusChange(bool focused, Fw::FocusReason reason)
bool UILineEdit::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
{
if(keyCode == KC_DELETE) // erase right character
if(keyCode == Fw::KeyDelete) // erase right character
removeCharacter(true);
else if(keyCode == KC_BACK) // erase left character {
else if(keyCode == Fw::KeyBackspace) // erase left character {
removeCharacter(false);
else if(keyCode == KC_RIGHT) // move cursor right
else if(keyCode == Fw::KeyRight) // move cursor right
moveCursor(true);
else if(keyCode == KC_LEFT) // move cursor left
else if(keyCode == Fw::KeyLeft) // move cursor left
moveCursor(false);
else if(keyCode == KC_HOME) // move cursor to first character
else if(keyCode == Fw::KeyHome) // move cursor to first character
setCursorPos(0);
else if(keyCode == KC_END) // move cursor to last character
else if(keyCode == Fw::KeyEnd) // move cursor to last character
setCursorPos(m_text.length());
else if(keyCode == KC_V && keyboardModifiers == Fw::KeyboardCtrlModifier)
else if(keyCode == Fw::KeyV && keyboardModifiers == Fw::KeyboardCtrlModifier)
appendText(g_platform.getClipboardText());
else if(keyCode == KC_TAB) {
else if(keyCode == Fw::KeyTab) {
if(UIWidgetPtr parent = getParent())
parent->focusNextChild(Fw::TabFocusReason);
} else if(keyCode == KC_RETURN) {
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
if(m_onAction)
m_onAction();
} else if(keyChar != 0)

View File

@@ -750,21 +750,24 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
void UIWidget::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
{
callLuaField("onGeometryUpdate", oldRect, newRect);
}
void UIWidget::onFocusChange(bool focused, Fw::FocusReason reason)
{
callLuaField("onHoverChange", focused, reason);
}
void UIWidget::onHoverChange(bool hovered)
{
callLuaField("onHoverChange", hovered);
}
bool UIWidget::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
{
if(callLuaField<bool>("onKeyPress", keyCode, keyChar, keyboardModifiers))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {
@@ -787,6 +790,9 @@ bool UIWidget::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
bool UIWidget::onKeyRelease(uchar keyCode, char keyChar, int keyboardModifiers)
{
if(callLuaField<bool>("onKeyRelease", keyCode, keyChar, keyboardModifiers))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {
@@ -809,6 +815,9 @@ bool UIWidget::onKeyRelease(uchar keyCode, char keyChar, int keyboardModifiers)
bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
{
if(callLuaField<bool>("onMousePress", mousePos, button))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {
@@ -840,6 +849,9 @@ bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
{
if(callLuaField<bool>("onMouseRelease", mousePos, button))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {
@@ -866,6 +878,9 @@ bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved)
{
if(callLuaField<bool>("onMouseMove", mousePos, mouseMoved))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {
@@ -887,6 +902,9 @@ bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved)
bool UIWidget::onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction)
{
if(callLuaField<bool>("onMouseWheel", mousePos, direction))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {