UIEditBoxImpl-win32.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013 Jozef Pridavok
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __UIEditBoxIMPLWIN_H__
  22. #define __UIEditBoxIMPLWIN_H__
  23. #include "platform/CCPlatformConfig.h"
  24. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
  25. #include "ui/UIEditBox/UIEditBoxImpl.h"
  26. NS_CC_BEGIN
  27. namespace ui {
  28. class EditBox;
  29. class CC_GUI_DLL EditBoxImplWin : public EditBoxImpl
  30. {
  31. public:
  32. /**
  33. * @js NA
  34. */
  35. EditBoxImplWin(EditBox* pEditText);
  36. /**
  37. * @js NA
  38. * @lua NA
  39. */
  40. virtual ~EditBoxImplWin();
  41. virtual bool initWithSize(const Size& size);
  42. virtual void setFont(const char* pFontName, int fontSize);
  43. virtual void setFontColor(const Color4B& color);
  44. virtual void setPlaceholderFont(const char* pFontName, int fontSize);
  45. virtual void setPlaceholderFontColor(const Color4B& color);
  46. virtual void setInputMode(EditBox::InputMode inputMode);
  47. virtual void setInputFlag(EditBox::InputFlag inputFlag);
  48. virtual void setMaxLength(int maxLength);
  49. virtual int getMaxLength();
  50. virtual void setTextHorizontalAlignment(TextHAlignment alignment) { _alignment = alignment; }
  51. virtual void setReturnType(EditBox::KeyboardReturnType returnType);
  52. virtual bool isEditing();
  53. virtual const char* getFontName() override { return _fontName.c_str(); }
  54. virtual int getFontSize() override { return _fontSize; }
  55. virtual const Color4B& getFontColor() override { return _colText; }
  56. virtual const char* getPlaceholderFontName() override { return _placeholderFontName.c_str(); }
  57. virtual int getPlaceholderFontSize() override { return _placeholderFontSize; }
  58. virtual const Color4B& getPlaceholderFontColor() override { return _colPlaceHolder; }
  59. virtual EditBox::InputMode getInputMode() override { return _editBoxInputMode; }
  60. virtual EditBox::InputFlag getInputFlag() override { return _editBoxInputFlag; }
  61. virtual EditBox::KeyboardReturnType getReturnType() override { return _keyboardReturnType; }
  62. virtual TextHAlignment getTextHorizontalAlignment() { return _alignment; }
  63. virtual void setText(const char* pText);
  64. virtual const char* getText(void);
  65. virtual void setPlaceHolder(const char* pText);
  66. virtual const char* getPlaceHolder(void);
  67. virtual void setPosition(const Vec2& pos);
  68. virtual void setVisible(bool visible);
  69. virtual void setContentSize(const Size& size);
  70. virtual void setAnchorPoint(const Vec2& anchorPoint);
  71. /**
  72. * @js NA
  73. * @lua NA
  74. */
  75. virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)override;
  76. virtual void doAnimationWhenKeyboardMove(float duration, float distance);
  77. virtual void openKeyboard();
  78. virtual void closeKeyboard();
  79. /**
  80. * @js NA
  81. * @lua NA
  82. */
  83. virtual void onEnter(void);
  84. private:
  85. Label* _label;
  86. Label* _labelPlaceHolder;
  87. EditBox::InputMode _editBoxInputMode;
  88. EditBox::InputFlag _editBoxInputFlag;
  89. EditBox::KeyboardReturnType _keyboardReturnType;
  90. TextHAlignment _alignment;
  91. std::string _text;
  92. std::string _placeHolder;
  93. std::string _fontName;
  94. std::string _placeholderFontName;
  95. int _fontSize;
  96. int _placeholderFontSize;
  97. Color4B _colText;
  98. Color4B _colPlaceHolder;
  99. int _maxLength;
  100. Size _editSize;
  101. /*
  102. Size _contentSize;
  103. HWND _sysEdit;
  104. int _maxTextLength;
  105. */
  106. std::string _editingText;
  107. std::string _originalText;
  108. bool _isEditing;
  109. void onWin32InputBoxTextChange(const char *pText);
  110. void onWin32InputBoxClose(INT_PTR buttonId);
  111. };
  112. }
  113. NS_CC_END
  114. #endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */
  115. #endif /* __UIEditBoxIMPLWIN_H__ */