CCIMEDispatcher.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /****************************************************************************
  2. Copyright (c) 2010 cocos2d-x.org
  3. Copyright (c) 2013-2016 Chukong Technologies Inc.
  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 __CC_IME_DISPATCHER_H__
  23. #define __CC_IME_DISPATCHER_H__
  24. #include "base/CCIMEDelegate.h"
  25. /**
  26. * @addtogroup base
  27. * @{
  28. */
  29. NS_CC_BEGIN
  30. /**
  31. @brief Input Method Edit Message Dispatcher.
  32. */
  33. class CC_DLL IMEDispatcher
  34. {
  35. public:
  36. /**
  37. * @js NA
  38. * @lua NA
  39. */
  40. ~IMEDispatcher();
  41. /**
  42. * @brief Returns the shared IMEDispatcher object for the system.
  43. * @js NA
  44. * @lua NA
  45. */
  46. static IMEDispatcher* sharedDispatcher();
  47. /**
  48. * @brief Dispatches the input text from IME.
  49. * @lua NA
  50. */
  51. void dispatchInsertText(const char * text, size_t len);
  52. /**
  53. * @brief Dispatches the delete-backward operation.
  54. * @lua NA
  55. */
  56. void dispatchDeleteBackward();
  57. /**
  58. * @brief Dispatches the press control key operation.
  59. * @lua NA
  60. */
  61. void dispatchControlKey(EventKeyboard::KeyCode keyCode);
  62. /**
  63. * @brief Get the content text from IMEDelegate, retrieved previously from IME.
  64. * @lua NA
  65. */
  66. const std::string& getContentText();
  67. //////////////////////////////////////////////////////////////////////////
  68. // dispatch keyboard notification
  69. //////////////////////////////////////////////////////////////////////////
  70. /**
  71. * @lua NA
  72. */
  73. void dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info);
  74. /**
  75. * @lua NA
  76. */
  77. void dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info);
  78. /**
  79. * @lua NA
  80. */
  81. void dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info);
  82. /**
  83. * @lua NA
  84. */
  85. void dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info);
  86. protected:
  87. friend class IMEDelegate;
  88. /**
  89. *@brief Add delegate to receive IME messages.
  90. *@param delegate A instance implements IMEDelegate delegate.
  91. */
  92. void addDelegate(IMEDelegate * delegate);
  93. /**
  94. *@brief Attach the Delegate to the IME.
  95. *@param delegate A instance implements IMEDelegate delegate.
  96. *@return If the old delegate can detach from the IME, and the new delegate
  97. * can attach to the IME, return true, otherwise false.
  98. */
  99. bool attachDelegateWithIME(IMEDelegate * delegate);
  100. /**
  101. * Detach the delegate to the IME
  102. *@see `attachDelegateWithIME(IMEDelegate*)`
  103. *@param delegate A instance implements IMEDelegate delegate.
  104. *@return Whether the IME is detached or not.
  105. */
  106. bool detachDelegateWithIME(IMEDelegate * delegate);
  107. /**
  108. *@brief Remove the delegate from the delegates which receive IME messages.
  109. *@param delegate A instance implements the IMEDelegate delegate.
  110. */
  111. void removeDelegate(IMEDelegate * delegate);
  112. private:
  113. IMEDispatcher();
  114. class Impl;
  115. Impl * _impl;
  116. };
  117. NS_CC_END
  118. // end of base group
  119. /// @}
  120. #endif // __CC_IME_DISPATCHER_H__