UIEditBoxImpl-win32.h 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013 Jozef Pridavok
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #ifndef __UIEditBoxIMPLWIN_H__
  23. #define __UIEditBoxIMPLWIN_H__
  24. #include "platform/CCPlatformConfig.h"
  25. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
  26. #include "ui/UIEditBox/UIEditBoxImpl-common.h"
  27. NS_CC_BEGIN
  28. namespace ui {
  29. class EditBox;
  30. class CC_GUI_DLL EditBoxImplWin : public EditBoxImplCommon
  31. {
  32. public:
  33. EditBoxImplWin(EditBox* pEditText);
  34. virtual ~EditBoxImplWin();
  35. virtual bool isEditing() override;
  36. virtual void createNativeControl(const Rect& frame) override;
  37. virtual void setNativeFont(const char* pFontName, int fontSize) override;
  38. virtual void setNativeFontColor(const Color4B& color) override;
  39. virtual void setNativePlaceholderFont(const char* pFontName, int fontSize) override;
  40. virtual void setNativePlaceholderFontColor(const Color4B& color) override;
  41. virtual void setNativeInputMode(EditBox::InputMode inputMode) override;
  42. virtual void setNativeInputFlag(EditBox::InputFlag inputFlag) override;
  43. virtual void setNativeReturnType(EditBox::KeyboardReturnType returnType) override;
  44. virtual void setNativeTextHorizontalAlignment(TextHAlignment alignment) override;
  45. virtual void setNativeText(const char* pText) override;
  46. virtual void setNativePlaceHolder(const char* pText) override;
  47. virtual void setNativeVisible(bool visible) override;
  48. virtual void updateNativeFrame(const Rect& rect) override;
  49. virtual const char* getNativeDefaultFontName() override;
  50. virtual void nativeOpenKeyboard() override;
  51. virtual void nativeCloseKeyboard() override;
  52. virtual void setNativeMaxLength(int maxLength) override;
  53. private:
  54. void createEditCtrl(bool singleLine);
  55. void cleanupEditCtrl();
  56. std::string getText() const;
  57. void _WindowProc(HWND, UINT, WPARAM, LPARAM);
  58. WNDPROC _prevWndProc;
  59. static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  60. static LRESULT CALLBACK hookGLFWWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  61. HWND _hwndEdit;
  62. bool _changedTextManually;
  63. bool _hasFocus;
  64. EditBoxDelegate::EditBoxEndAction _endAction;
  65. static WNDPROC s_prevCocosWndProc;
  66. static HINSTANCE s_hInstance;
  67. static HWND s_hwndCocos;
  68. static HWND s_previousFocusWnd;
  69. static bool s_isInitialized;
  70. static int s_editboxChildID;
  71. static void lazyInit();
  72. };
  73. }
  74. NS_CC_END
  75. #endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */
  76. #endif /* __UIEditBoxIMPLWIN_H__ */