axmol/extensions/GUI/CCEditBox/CCEditBox.h

453 lines
12 KiB
C
Raw Normal View History

2013-09-20 22:23:13 +08:00
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCEDITTEXT_H__
#define __CCEDITTEXT_H__
Squashed commit of the following: commit a794d107ad85667e3d754f0b6251fc864dfbf288 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 14:33:49 2014 -0700 Yeah... everything compiles on win32 and wp8 commit 4740be6e4a0d16f742c27996e7ab2c100adc76af Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:58:38 2014 -0700 CCIME moved to base and compiles on Android commit ff3e1bf1eb27a01019f4e1b56d1aebbe2d385f72 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:02:57 2014 -0700 compiles Ok for Windows Phone 8 commit 8160a4eb2ecdc61b5bd1cf56b90d2da6f11e3ebd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 12:25:31 2014 -0700 fixes for Windows Phone 8 commit 418197649efc93032aee0adc205e502101cdb53d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 11:15:13 2014 -0700 Compiles on Win32 commit 08813ed7cf8ac1079ffadeb1ce78ea9e833e1a33 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 10:08:31 2014 -0700 Compiles on linux! commit 118896521e5b335a5257090b6863f1fb2a2002fe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 09:30:42 2014 -0700 moves cocos/2d/platform -> cocos/platform commit 4fe9319d7717b0c1bccb2db0156eeb86255a89e0 Merge: bd68ec2 511295e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 08:24:41 2014 -0700 Merge remote-tracking branch 'cocos2d/v3' into files commit bd68ec2f0e3a826d8b2f4b60564ba65ce766bc56 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu May 15 19:36:23 2014 -0700 files in the correct directory
2014-05-17 05:36:00 +08:00
#include "base/CCIMEDelegate.h"
#include "extensions/ExtensionMacros.h"
2013-09-20 22:23:13 +08:00
#include "../CCControlExtension/CCControlExtensions.h"
#include "extensions/ExtensionExport.h"
2013-09-20 22:23:13 +08:00
NS_CC_EXT_BEGIN
class EditBox;
class EditBoxImpl;
class CC_EX_DLL EditBoxDelegate
2013-09-20 22:23:13 +08:00
{
public:
/**
* @js NA
* @lua NA
*/
virtual ~EditBoxDelegate() {};
/**
* This method is called when an edit box gains focus after keyboard is shown.
* @param editBox The edit box object that generated the event.
* @js NA
* @lua NA
*/
virtual void editBoxEditingDidBegin(EditBox* editBox) {};
/**
* This method is called when an edit box loses focus after keyboard is hidden.
* @param editBox The edit box object that generated the event.
* @js NA
* @lua NA
*/
virtual void editBoxEditingDidEnd(EditBox* editBox) {};
/**
* This method is called when the edit box text was changed.
* @param editBox The edit box object that generated the event.
* @param text The new text.
* @js NA
* @lua NA
*/
virtual void editBoxTextChanged(EditBox* editBox, const std::string& text) {};
/**
* This method is called when the return button was pressed or the outside area of keyboard was touched.
* @param editBox The edit box object that generated the event.
* @js NA
* @lua NA
*/
virtual void editBoxReturn(EditBox* editBox) = 0;
};
/**
* \brief Class for edit box.
*
* You can use this widget to gather small amounts of text from the user.
*
*/
class CC_EX_DLL EditBox
2013-09-20 22:23:13 +08:00
: public ControlButton
, public IMEDelegate
{
public:
enum class KeyboardReturnType
{
DEFAULT,
DONE,
SEND,
SEARCH,
GO
};
/**
* \brief The EditBox::InputMode defines the type of text that the user is allowed
* to enter.
*/
enum class InputMode
{
/**
* The user is allowed to enter any text, including line breaks.
*/
ANY,
/**
* The user is allowed to enter an e-mail address.
*/
EMAIL_ADDRESS,
/**
* The user is allowed to enter an integer value.
*/
NUMERIC,
/**
* The user is allowed to enter a phone number.
*/
PHONE_NUMBER,
/**
* The user is allowed to enter a URL.
*/
URL,
/**
* The user is allowed to enter a real number value.
* This extends kEditBoxInputModeNumeric by allowing a decimal point.
*/
DECIMAL,
/**
* The user is allowed to enter any text, except for line breaks.
*/
SINGLE_LINE,
};
/**
* \brief The EditBox::InputFlag defines how the input text is displayed/formatted.
*/
enum class InputFlag
{
/**
* Indicates that the text entered is confidential data that should be
* obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE.
*/
PASSWORD,
/**
* Indicates that the text entered is sensitive data that the
* implementation must never store into a dictionary or table for use
* in predictive, auto-completing, or other accelerated input schemes.
* A credit card number is an example of sensitive data.
*/
SENSITIVE,
/**
* This flag is a hint to the implementation that during text editing,
* the initial letter of each word should be capitalized.
*/
INITIAL_CAPS_WORD,
/**
* This flag is a hint to the implementation that during text editing,
* the initial letter of each sentence should be capitalized.
*/
INITIAL_CAPS_SENTENCE,
/**
* Capitalize all characters automatically.
*/
INTIAL_CAPS_ALL_CHARACTERS,
};
/**
* create a edit box with size.
* @return An autorelease pointer of EditBox, you don't need to release it only if you retain it again.
*/
static EditBox* create(const Size& size, Scale9Sprite* pNormal9SpriteBg, Scale9Sprite* pPressed9SpriteBg = NULL, Scale9Sprite* pDisabled9SpriteBg = NULL);
/**
* Constructor.
* @js ctor
*/
EditBox(void);
/**
* Destructor.
* @js NA
* @lua NA
*/
virtual ~EditBox(void);
/**
* Init edit box with specified size. This method should be invoked right after constructor.
* @param size The size of edit box.
*/
bool initWithSizeAndBackgroundSprite(const Size& size, Scale9Sprite* pNormal9SpriteBg);
/**
* Gets/Sets the delegate for edit box.
* @lua NA
*/
void setDelegate(EditBoxDelegate* pDelegate);
/**
* @js NA
* @lua NA
*/
EditBoxDelegate* getDelegate();
#if CC_ENABLE_SCRIPT_BINDING
2013-09-20 22:23:13 +08:00
/**
* Registers a script function that will be called for EditBox events.
*
* This handler will be removed automatically after onExit() called.
* @code
* -- lua sample
* local function editboxEventHandler(eventType)
* if eventType == "began" then
* -- triggered when an edit box gains focus after keyboard is shown
* elseif eventType == "ended" then
* -- triggered when an edit box loses focus after keyboard is hidden.
* elseif eventType == "changed" then
* -- triggered when the edit box text was changed.
* elseif eventType == "return" then
* -- triggered when the return button was pressed or the outside area of keyboard was touched.
* end
* end
*
* local editbox = EditBox:create(Size(...), Scale9Sprite:create(...))
* editbox = registerScriptEditBoxHandler(editboxEventHandler)
* @endcode
*
* @param handler A number that indicates a lua function.
* @js NA
* @lua NA
*/
void registerScriptEditBoxHandler(int handler);
/**
* Unregisters a script function that will be called for EditBox events.
* @js NA
* @lua NA
*/
void unregisterScriptEditBoxHandler(void);
/**
* get a script Handler
* @js NA
* @lua NA
*/
int getScriptEditBoxHandler(void){ return _scriptEditBoxHandler ;}
#endif // #if CC_ENABLE_SCRIPT_BINDING
2013-09-20 22:23:13 +08:00
/**
* Set the text entered in the edit box.
* @param pText The given text.
*/
void setText(const char* pText);
/**
* Get the text entered in the edit box.
* @return The text entered in the edit box.
*/
const char* getText(void);
/**
* Set the font.
* @param pFontName The font name.
* @param fontSize The font size.
*/
void setFont(const char* pFontName, int fontSize);
/**
* Set the font name.
* @param pFontName The font name.
*/
void setFontName(const char* pFontName);
/**
* Set the font size.
* @param fontSize The font size.
*/
void setFontSize(int fontSize);
/**
* Set the font color of the widget's text.
*/
void setFontColor(const Color3B& color);
/**
* Set the placeholder's font.
* @param pFontName The font name.
* @param fontSize The font size.
*/
void setPlaceholderFont(const char* pFontName, int fontSize);
/**
* Set the placeholder's font name.
* @param pFontName The font name.
*/
void setPlaceholderFontName(const char* pFontName);
/**
* Set the placeholder's font size.
* @param fontSize The font size.
*/
void setPlaceholderFontSize(int fontSize);
/**
* Set the font color of the placeholder text when the edit box is empty.
* Not supported on IOS.
*/
void setPlaceholderFontColor(const Color3B& color);
/**
* Set a text in the edit box that acts as a placeholder when an
* edit box is empty.
* @param pText The given text.
*/
void setPlaceHolder(const char* pText);
/**
* Get a text in the edit box that acts as a placeholder when an
* edit box is empty.
*/
const char* getPlaceHolder(void);
/**
* Set the input mode of the edit box.
* @param inputMode One of the EditBox::InputMode constants.
*/
void setInputMode(InputMode inputMode);
/**
* Sets the maximum input length of the edit box.
* Setting this value enables multiline input mode by default.
* Available on Android, iOS and Windows Phone.
*
* @param maxLength The maximum length.
*/
void setMaxLength(int maxLength);
/**
* Gets the maximum input length of the edit box.
*
* @return Maximum input length.
*/
int getMaxLength();
/**
* Set the input flags that are to be applied to the edit box.
* @param inputFlag One of the EditBox::InputFlag constants.
*/
void setInputFlag(InputFlag inputFlag);
/**
* Set the return type that are to be applied to the edit box.
* @param returnType One of the EditBox::KeyboardReturnType constants.
*/
void setReturnType(EditBox::KeyboardReturnType returnType);
/* override functions */
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
virtual void setPosition(const Vec2& pos) override;
virtual void setVisible(bool visible) override;
virtual void setContentSize(const Size& size) override;
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
virtual void setAnchorPoint(const Vec2& anchorPoint) override;
2013-09-20 22:23:13 +08:00
/**
* @js NA
* @lua NA
*/
virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
2013-09-20 22:23:13 +08:00
/**
* @js NA
* @lua NA
*/
virtual void onEnter(void) override;
2013-09-20 22:23:13 +08:00
/**
* @js NA
* @lua NA
*/
virtual void onExit(void) override;
2013-09-20 22:23:13 +08:00
/**
* @js NA
* @lua NA
*/
virtual void keyboardWillShow(IMEKeyboardNotificationInfo& info) override;
2013-09-20 22:23:13 +08:00
/**
* @js NA
* @lua NA
*/
virtual void keyboardDidShow(IMEKeyboardNotificationInfo& info) override;
2013-09-20 22:23:13 +08:00
/**
* @js NA
* @lua NA
*/
virtual void keyboardWillHide(IMEKeyboardNotificationInfo& info) override;
2013-09-20 22:23:13 +08:00
/**
* @js NA
* @lua NA
*/
virtual void keyboardDidHide(IMEKeyboardNotificationInfo& info) override;
2013-09-20 22:23:13 +08:00
/* callback funtions
* @js NA
* @lua NA
*/
void touchDownAction(Ref *sender, Control::EventType controlEvent);
2013-09-20 22:23:13 +08:00
protected:
void updatePosition(float dt);
2013-09-20 22:23:13 +08:00
EditBoxImpl* _editBoxImpl;
EditBoxDelegate* _delegate;
InputMode _editBoxInputMode;
InputFlag _editBoxInputFlag;
EditBox::KeyboardReturnType _keyboardReturnType;
std::string _text;
std::string _placeHolder;
std::string _fontName;
std::string _placeholderFontName;
int _fontSize;
int _placeholderFontSize;
Color3B _colText;
Color3B _colPlaceHolder;
int _maxLength;
float _adjustHeight;
#if CC_ENABLE_SCRIPT_BINDING
2013-09-20 22:23:13 +08:00
int _scriptEditBoxHandler;
#endif
2013-09-20 22:23:13 +08:00
};
NS_CC_EXT_END
#endif /* __CCEDITTEXT_H__ */