瀏覽代碼

Merge pull request #1467 from bgroves/next

Fixed TextBox to allow listeners to receive the TEXT_CHANGED event.
Sean Taylor 11 年之前
父節點
當前提交
d2f696a9af
共有 3 個文件被更改,包括 24 次插入22 次删除
  1. 0 2
      gameplay/src/Form.cpp
  2. 20 17
      gameplay/src/TextBox.cpp
  3. 4 3
      gameplay/src/TextBox.h

+ 0 - 2
gameplay/src/Form.cpp

@@ -738,8 +738,6 @@ bool Form::keyEventInternal(Keyboard::KeyEvent evt, int key)
             __shiftKeyDown = false;
         break;
     }
-    if (key == Keyboard::KEY_ESCAPE)
-        return false;
 
     // Handle focus changing
     if (__focusControl)

+ 20 - 17
gameplay/src/TextBox.cpp

@@ -4,11 +4,6 @@
 namespace gameplay
 {
 
-static bool space(char c)
-{
-    return isspace(c);
-}
-
 TextBox::TextBox() : _caretLocation(0), _lastKeypress(0), _fontSize(0), _caretImage(NULL), _passwordChar('*'), _inputMode(TEXT), _ctrlPressed(false)
 {
     _canFocus = true;
@@ -33,6 +28,16 @@ Control* TextBox::create(Theme::Style* style, Properties* properties)
     return textBox;
 }
 
+void TextBox::addListener(Control::Listener* listener, int eventFlags)
+{
+    if ((eventFlags & Control::Listener::VALUE_CHANGED) == Control::Listener::VALUE_CHANGED)
+    {
+        GP_ERROR("VALUE_CHANGED event is not applicable to this control.");
+    }
+
+    Control::addListener(listener, eventFlags);
+}
+
 void TextBox::initialize(const char* typeName, Theme::Style* style, Properties* properties)
 {
     Label::initialize(typeName, style, properties);
@@ -62,22 +67,18 @@ void TextBox::setCaretLocation(unsigned int index)
 
 bool TextBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
 {
-    State state = getState();
-
-    switch (evt)
-    {
-    case Touch::TOUCH_PRESS: 
-        if (state == ACTIVE)
+    if (getState() == ACTIVE) {
+        switch (evt)
         {
+        case Touch::TOUCH_PRESS:
             setCaretLocation(x, y);
-        }
-        break;
-    case Touch::TOUCH_MOVE:
-        if (state == ACTIVE)
-        {
+            break;
+        case Touch::TOUCH_MOVE:
             setCaretLocation(x, y);
+            break;
+        default:
+            break;
         }
-        break;
     }
 
     return Label::touchEvent(evt, x, y, contactIndex);
@@ -303,6 +304,8 @@ void TextBox::controlEvent(Control::Listener::EventType evt)
     case Control::Listener::FOCUS_LOST:
         Game::getInstance()->displayKeyboard(false);
         break;
+    default:
+        break;
     }
 }
 

+ 4 - 3
gameplay/src/TextBox.h

@@ -1,10 +1,9 @@
 #ifndef TEXTBOX_H_
 #define TEXTBOX_H_
 
-#include "Base.h"
+#include <string>
+
 #include "Label.h"
-#include "Theme.h"
-#include "Keyboard.h"
 
 namespace gameplay
 {
@@ -107,6 +106,8 @@ public:
      */
     InputMode getInputMode() const;
 
+    virtual void addListener(Control::Listener* listener, int eventFlags);
+
 protected:
 
     /**