CCIMEDelegate.h 4.6 KB

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