CCIMEDelegate.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_DELEGATE_H__
  23. #define __CC_IME_DELEGATE_H__
  24. #include <string>
  25. #include "math/CCGeometry.h"
  26. #include "base/CCEventKeyboard.h"
  27. /**
  28. * @addtogroup base
  29. * @{
  30. */
  31. NS_CC_BEGIN
  32. /**
  33. * A static global empty std::string install.
  34. */
  35. extern const std::string CC_DLL STD_STRING_EMPTY;
  36. /**
  37. * Keyboard notification event type.
  38. */
  39. typedef struct
  40. {
  41. Rect begin; // the soft keyboard rectangle when animation begins
  42. Rect end; // the soft keyboard rectangle when animation ends
  43. float duration; // the soft keyboard animation duration
  44. } IMEKeyboardNotificationInfo;
  45. /**
  46. *@brief Input method editor delegate.
  47. */
  48. class CC_DLL IMEDelegate
  49. {
  50. public:
  51. /**
  52. * Default constructor.
  53. * @js NA
  54. * @lua NA
  55. */
  56. virtual ~IMEDelegate();
  57. /**
  58. * Default destructor.
  59. * @js NA
  60. * @lua NA
  61. */
  62. virtual bool attachWithIME();
  63. /**
  64. * Determine whether the IME is detached or not.
  65. * @js NA
  66. * @lua NA
  67. */
  68. virtual bool detachWithIME();
  69. protected:
  70. friend class IMEDispatcher;
  71. /**
  72. @brief Decide if the delegate instance is ready to receive an IME message.
  73. Called by IMEDispatcher.
  74. * @js NA
  75. * @lua NA
  76. */
  77. virtual bool canAttachWithIME() { return false; }
  78. /**
  79. @brief When the delegate detaches from the IME, this method is called by IMEDispatcher.
  80. * @js NA
  81. * @lua NA
  82. */
  83. virtual void didAttachWithIME() {}
  84. /**
  85. @brief Decide if the delegate instance can stop receiving IME messages.
  86. * @js NA
  87. * @lua NA
  88. */
  89. virtual bool canDetachWithIME() { return false; }
  90. /**
  91. @brief When the delegate detaches from the IME, this method is called by IMEDispatcher.
  92. * @js NA
  93. * @lua NA
  94. */
  95. virtual void didDetachWithIME() {}
  96. /**
  97. @brief Called by IMEDispatcher when text input received from the IME.
  98. * @js NA
  99. * @lua NA
  100. */
  101. virtual void insertText(const char* /*text*/, size_t /*len*/) {}
  102. /**
  103. @brief Called by IMEDispatcher after the user clicks the backward key.
  104. * @js NA
  105. * @lua NA
  106. */
  107. virtual void deleteBackward() {}
  108. /**
  109. @brief Called by IMEDispatcher after the user press control key.
  110. * @js NA
  111. * @lua NA
  112. */
  113. virtual void controlKey(EventKeyboard::KeyCode /*keyCode*/) {}
  114. /**
  115. @brief Called by IMEDispatcher for text stored in delegate.
  116. * @js NA
  117. * @lua NA
  118. */
  119. virtual const std::string& getContentText() { return STD_STRING_EMPTY; }
  120. //////////////////////////////////////////////////////////////////////////
  121. // keyboard show/hide notification
  122. //////////////////////////////////////////////////////////////////////////
  123. /**
  124. * @js NA
  125. * @lua NA
  126. */
  127. virtual void keyboardWillShow(IMEKeyboardNotificationInfo& /*info*/) {}
  128. /**
  129. * @js NA
  130. * @lua NA
  131. */
  132. virtual void keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) {}
  133. /**
  134. * @js NA
  135. * @lua NA
  136. */
  137. virtual void keyboardWillHide(IMEKeyboardNotificationInfo& /*info*/) {}
  138. /**
  139. * @js NA
  140. * @lua NA
  141. */
  142. virtual void keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) {}
  143. protected:
  144. /**
  145. * @js NA
  146. * @lua NA
  147. */
  148. IMEDelegate();
  149. };
  150. NS_CC_END
  151. // end of base group
  152. /// @}
  153. #endif // __CC_IME_DELEGATE_H__