1
0

CCIMEDispatcher.h 4.0 KB

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