1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/text-input/text-input.h>
24 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
25 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
26 #include <dali-toolkit/internal/controls/text-input/text-input-popup-impl.h>
28 #include <dali/public-api/common/dali-vector.h>
29 #include <dali/public-api/geometry/mesh.h>
43 typedef IntrusivePtr<TextInput> TextInputPtr;
45 class TextInput : public Control
52 TEXTINPUT_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
53 TEXTINPUT_PROPERTY_END_INDEX = TEXTINPUT_PROPERTY_START_INDEX + 512 ///< Reserving property indices
57 * Create a new TextInput
58 * @return instrusive ptr to a TextInput
60 static Dali::Toolkit::TextInput New();
63 * @copydoc Toolkit::TextInput::GetText
65 std::string GetText() const;
68 * @copydoc Toolkit::TextInput::GetMarkupText()
70 std::string GetMarkupText() const;
73 * @copydoc Toolkit::TextInput::SetPlaceholderText
75 void SetPlaceholderText( const std::string& placeHolderText );
78 * @copydoc Toolkit::TextInput::SetPlaceholderText
80 std::string GetPlaceholderText();
83 * @copydoc Toolkit::TextInput::SetInitialText
85 void SetInitialText(const std::string& initialText);
88 * set the text to be displayed in text-input, will overwrite any existing text.
89 * can be used to clear the text-input by passing an empty string.
90 * @param [in] initialText text to be initially displayed
92 void SetText(const std::string& initialText);
95 * @copydoc Toolkit::TextInput::SetMaxCharacterLength
97 void SetMaxCharacterLength(std::size_t maxChars);
100 * @copydoc Toolkit::TextInput::SetNumberOfLinesLimit
102 void SetNumberOfLinesLimit(std::size_t maxLines);
105 * @copydoc Toolkit::TextInput::GetNumberOfLinesLimit
107 std::size_t GetNumberOfLinesLimit() const;
110 * @copydoc Toolkit::TextInput::GetFont
112 Font GetFont() const;
115 * @copydoc Toolkit::TextInput::SetFont
117 void SetFont(Font font);
120 * @copydoc Toolkit::TextInput::InputStartedSignal()
122 Toolkit::TextInput::InputSignalV2& InputStartedSignal();
125 * @copydoc Toolkit::TextInput::InputFinishedSignal()
127 Toolkit::TextInput::InputSignalV2& InputFinishedSignal();
130 * @copydoc Toolkit::TextInput::CutAndPasteToolBarDisplayedSignal()
132 Toolkit::TextInput::InputSignalV2& CutAndPasteToolBarDisplayedSignal();
135 * @copydoc Toolkit::TextInput::StyleChangedSignal()
137 Toolkit::TextInput::StyleChangedSignalV2& StyleChangedSignal();
140 * @copydoc Toolkit::TextInput::TextModifiedSignal()
142 Toolkit::TextInput::TextModifiedSignalType& TextModifiedSignal();
145 * @copydoc Toolkit::TextInput::MaxInputCharactersReachedSignal()
147 Toolkit::TextInput::MaxInputCharactersReachedSignalV2& MaxInputCharactersReachedSignal();
150 * @copydoc Toolkit::TextInput::InputTextExceedBoundariesSignal()
152 Toolkit::TextInput::InputTextExceedBoundariesSignalV2& InputTextExceedBoundariesSignal();
155 * Connects a callback function with the object's signals.
156 * @param[in] object The object providing the signal.
157 * @param[in] tracker Used to disconnect the signal.
158 * @param[in] signalName The signal to connect to.
159 * @param[in] functor A newly allocated FunctorDelegate.
160 * @return True if the signal was connected.
161 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
163 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
166 * @see Toolkit::TextInput::SetEditMode(bool editMode)
167 * @see Toolkit::TextInput::SetEditMode(bool editMode, const Vector2& touchPoint)
169 * @param[in] editMode true or false to indicate editMode on or off.
170 * @param[in] setCursorOnTouchPoint Whether to use the touch point to set the cursor position.
171 * @param[in] touchPoint A position in actor coordinates within the text-input.
173 void SetEditable(bool editMode, bool setCursorOnTouchPoint, const Vector2& touchPoint = Vector2::ZERO);
176 * @copydoc Toolkit::TextInput::GetEditMode
178 bool IsEditable() const;
181 * @copydoc Toolkit::TextInput::SetTextSelectable
183 void SetTextSelectable(bool textSelectable = true);
186 * @copydoc Toolkit::TextInput::IsTextSelectable
188 bool IsTextSelectable() const;
191 * @copydoc Toolkit::TextInput::IsTextSelected
193 bool IsTextSelected() const;
196 * @copydoc Toolkit::TextInput::DeSelectText
201 * @copydoc Toolkit::TextInput::SetEditOnTouch
203 void SetEditOnTouch(bool editOnTouch);
206 * @copydoc Toolkit::TextInput::IsEditOnTouch
208 bool IsEditOnTouch() const;
211 * @copydoc Toolkit::TextInput::SetGrabHandleImage
213 void SetGrabHandleImage(Dali::Image image);
216 * @copydoc Toolkit::TextInput::SetCursorImage
218 void SetCursorImage(Dali::Image image, const Vector4& border );
221 * @copydoc Toolkit::TextInput::GetSelectionHandleSize
223 Vector3 GetSelectionHandleSize();
226 * @copydoc Toolkit::TextInput::SetRTLCursorImage
228 void SetRTLCursorImage(Dali::Image image, const Vector4& border );
231 * @copydoc Toolkit::TextInput::EnableGrabHandle
233 void EnableGrabHandle(bool toggle);
236 * @copydoc Toolkit::TextInput::IsGrabHandleEnabled
238 bool IsGrabHandleEnabled();
241 * @copydoc Toolkit::TextInput::EnableSelectionHandleFlip
243 void EnableSelectionHandleFlip( bool toggle );
246 * @copydoc Toolkit::TextInput::IsSelectionHandleFlipEnabled
248 bool IsSelectionHandleFlipEnabled();
251 * @copydoc Toolkit::TextInput::SetSelectionHandleFlipMargin
253 void SetSelectionHandleFlipMargin( const Vector4& margin );
256 * @copydoc Toolkit::TextInput::SetBoundingRectangle
258 void SetBoundingRectangle( const Rect<float>& boundingRectangle );
261 * @copydoc Toolkit::TextInput::GetBoundingRectangle
263 const Rect<float> GetBoundingRectangle() const;
266 * @copydoc Toolkit::TextInput::GetSelectionHandleFlipMargin
268 const Vector4& GetSelectionHandleFlipMargin();
271 * @copydoc Toolkit::TextInput::SetTextColor
273 void SetTextColor( const Vector4& color );
276 * @copydoc Toolkit::TextInput::SetActiveStyle
278 void SetActiveStyle( const TextStyle& style, const TextStyle::Mask mask );
281 * @copydoc Toolkit::TextInput::ApplyStyle
283 void ApplyStyle( const TextStyle& style, const TextStyle::Mask mask );
286 * @copydoc Toolkit::TextInput::ApplyStyleToAll
288 void ApplyStyleToAll( const TextStyle& style, const TextStyle::Mask mask );
291 * @copydoc Toolkit::TextInput::GetStyleAtCursor
293 TextStyle GetStyleAtCursor() const;
296 * Retrieves the character style for the given position.
297 * @param[in] position The character position which style is required.
298 * @return The style for the given position.
300 TextStyle GetStyleAt( std::size_t position ) const;
303 * @copydoc Toolkit::TextInput::SetTextAlignment()
305 void SetTextAlignment( Toolkit::Alignment::Type align );
308 * @copydoc Toolkit::TextInput::SetTextLineJustification()
310 void SetTextLineJustification( Toolkit::TextView::LineJustification justification );
313 * @copydoc Toolkit::TextInput::SetFadeBoundary()
315 void SetFadeBoundary( const Toolkit::TextView::FadeBoundary& fadeBoundary );
318 * @copydoc Toolkit::TextInput::GetFadeBoundary()
320 const Toolkit::TextView::FadeBoundary& GetFadeBoundary() const;
323 * @copydoc Toolkit::TextInput::GetTextAlignment()
325 Toolkit::Alignment::Type GetTextAlignment() const;
328 * @copydoc Toolkit::TextInput::SetMultilinePolicy()
330 void SetMultilinePolicy( Toolkit::TextView::MultilinePolicy policy );
333 * @copydoc Toolkit::TextInput::GetMultilinePolicy()
335 Toolkit::TextView::MultilinePolicy GetMultilinePolicy() const;
338 * @copydoc Toolkit::TextInput::SetWidthExceedPolicy()
340 void SetWidthExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
343 * @copydoc Toolkit::TextInput::GetWidthExceedPolicy()
345 Toolkit::TextView::ExceedPolicy GetWidthExceedPolicy() const;
348 * @copydoc Toolkit::TextInput::SetHeightExceedPolicy()
350 void SetHeightExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
353 * @copydoc Toolkit::TextInput::GetHeightExceedPolicy()
355 Toolkit::TextView::ExceedPolicy GetHeightExceedPolicy() const;
358 * @copydoc Toolkit::TextInput::SetExceedEnabled()
360 void SetExceedEnabled( bool enable );
363 * @copydoc Toolkit::TextInput::GetExceedEnabled()
365 bool GetExceedEnabled() const;
368 * @copydoc Toolkit::TextInput::SetBackground
370 void SetBackground(Dali::Image image );
373 * @copydoc Toolkit::TextInput::SetNumberOfLines
375 void SetNumberOfLines(std::size_t lines);
378 * @copydoc Toolkit::TextInput::GetNumberOfLines
380 std::size_t GetNumberOfLines();
383 * @copydoc Toolkit::TextInput::GetNumberOfCharacters
385 std::size_t GetNumberOfCharacters() const;
392 * Set the diffuse color for the highlight
393 * @param[in] color color to use
395 void SetMaterialDiffuseColor( const Vector4& color );
398 * Get the diffuse color used by the highlight
401 const Vector4& GetMaterialDiffuseColor() const;
406 * structure to hold each highlight box needed for text selection
410 Vector3 size; ///< size of the highlight box
411 Vector3 position; ///< position of highlight box
412 ImageActor highlightBoxActor; ///< as actor that is the highlight box
416 * structure to hold each character in displayed string and its position from the left
420 char character; ///< todo change to UTF to aid multi-language support
426 * structure to hold coordinates of each quad, which will make up the mesh.
428 struct QuadCoordinates
431 * Default constructor
439 * @param[in] x1 left co-ordinate
440 * @param[in] y1 top co-ordinate
441 * @param[in] x2 right co-ordinate
442 * @param[in] y2 bottom co-ordinate
444 QuadCoordinates(float x1, float y1, float x2, float y2)
450 Vector2 min; ///< top-left (minimum) position of quad
451 Vector2 max; ///< bottom-right (maximum) position of quad
454 typedef std::vector<QuadCoordinates> QuadContainer;
457 * structure for information required to build the highlight mesh
462 * Adds a Quad (2D rectangular sub-selection)
463 * @param[in] x1 left co-ordinate
464 * @param[in] y1 top co-ordinate
465 * @param[in] x2 right co-ordinate
466 * @param[in] y2 bottom co-ordinate
468 void AddQuad( float x1, float y1, float x2, float y2 );
471 * Clamps all quads to fit within a min -> max 2D boundary.
473 void Clamp2D(const Vector2& min, const Vector2& max);
475 QuadContainer mQuadList; ///< List of quads (sub-selections that form to create complete selection)
479 * Holds requested selection start and end points for highlighted text.
481 struct SelectionParameters
483 SelectionParameters( size_t start, size_t end )
484 : mStartOfSelection( start ), mEndOfSelection( end )
489 size_t mStartOfSelection;
490 size_t mEndOfSelection;
499 enum SelectionHandleId
501 HandleOne, ///< Selection handle one which is on the left
502 HandleTwo ///< Selection handle two which is on the right
506 * Two different behaviours are needed to convert a touch point into a character index.
507 * When a tap is received and the touch point doesn't hit any character, the final character selected might
508 * be different than the one selected if the event is a pan.
509 * i.e. If a tap is received and the touch point doesn't hit any character the expected position of the cursor
510 * would be the end or the beginning of a line. However, this behaviour would be weird while panning.
514 TapMode, ///< Touch point to character index conversion mode used for Tap events.
515 DragMode ///< Touch point to character index conversion mode used for Pan events.
519 * Used to set the direction when find the next visible character.
521 enum FindVisibleCharacterDirection
523 Left, ///< Find visible characters on the left.
524 Right, ///< Find visible characters on the right.
525 ByEnd ///< Start finding visible characters by the end.
531 virtual bool OnTouchEvent(const TouchEvent& event);
534 * From CustomActorImpl; called after the Text Input actor is touched
535 * @param[in] event The KeyEvent event.
536 * @return True if the event should be consumed.
538 virtual bool OnKeyEvent(const KeyEvent& event);
541 * From CustomActorImpl; called when this actor gains keyboard focus.
543 virtual void OnKeyInputFocusGained();
546 * From CustomActorImpl; called when this actor loses keyboard focus.
548 virtual void OnKeyInputFocusLost();
551 * From Control; called whenever the control is added to the stage.
553 virtual void OnControlStageConnection();
555 private: // From Control
558 * Creation of the layer that is used by top level active parts of the TextInput like handles
560 void CreateActiveLayer();
563 * @copydoc Control::OnInitialize()
565 virtual void OnInitialize();
568 * @copydoc Control::OnControlSizeSet()
570 virtual void OnControlSizeSet(const Vector3& targetSize);
573 * @copydoc Control::OnRelaidOut()
575 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
578 * Retrieves the text-input's natural size by calling TextView::GetNaturalSize().
580 * @return The natural size.
582 virtual Vector3 GetNaturalSize();
585 * Retrieves the text-input's \e height for a given \e width by calling TextView::GetHeightForWidth().
587 * @param[in] width The given \e width.
589 * @return The \e height for the given \e width.
591 virtual float GetHeightForWidth( float width );
596 * Construct a new TextInput.
601 * A reference counted object may only be deleted by calling Unreference()
603 virtual ~TextInput();
608 TextInput(const TextInput&);
611 TextInput& operator=(const TextInput& rhs);
614 * Callback when a handle is panned/moved, either selection handles or grab handle
615 * @param actor Handle of the selection or grab handle.
616 * @param gesture Data structure with the parameters of the gesture.
618 void OnHandlePan(Actor actor, PanGesture gesture);
621 * Callback for touch down on Grab handle
622 * @param[in] actor touched
623 * @param[in] touch touch event
625 bool OnPressDown(Dali::Actor actor, const TouchEvent& touch);
628 * Callback for touch down on Selection handle one
629 * @param[in] actor touched
630 * @param[in] touch touch event, used to determine if down or up event
632 bool OnHandleOneTouched(Dali::Actor actor, const TouchEvent& touch);
635 * Callback for touch down on Selection handle two
636 * @param[in] actor touched
637 * @param[in] touch touch event, used to determine if down or up event
639 bool OnHandleTwoTouched(Dali::Actor actor, const TouchEvent& touch);
642 * Callback for tap on TextInput
644 * @param[in] tap touch event
646 void OnTextTap(Dali::Actor actor, Dali::TapGesture tap);
649 * Callback for double tap on TextInput
651 * @param[in] tap touch event
653 void OnDoubleTap(Dali::Actor actor, Dali::TapGesture tap);
656 * Callback for long press on TextInput
658 * @param[in] longPress long press event
660 void OnLongPress(Dali::Actor actor, Dali::LongPressGesture longPress);
663 * Callback for the ClipboardEventNotifier when text is selected in the clipboard window.
664 * @param[in] notifier The Clipboard Event Notifier.
666 void OnClipboardTextSelected( ClipboardEventNotifier& notifier );
669 * Callback for when a button is pressed in popup panel
670 * @param[in] button handle to the button pressed.
672 bool OnPopupButtonPressed( Toolkit::Button button );
675 * Callback when handle timer ticks.
677 * Cursor should become visible/invisible to simulate blinking.
679 * @return True if the timer should be keep running.
681 bool OnCursorBlinkTimerTick();
684 * Invoked upon popup Hide animation completing.
685 * @note Only called for animating hide, not called for instantaneous (animate = false)
686 * @param[in] popup The popup which was hidden.
688 void OnPopupHideFinished(TextInputPopup& popup);
691 * Called in OnKeyEvent to handle key down events.
692 * @param[in] event The KeyEvent event.
693 * @return True if the event should be consumed.
695 bool OnKeyDownEvent(const KeyEvent& event);
698 * Called in OnKeyEvent to handle key up events.
699 * @param[in] event The KeyEvent event.
700 * @return True if the event should be consumed.
702 bool OnKeyUpEvent(const KeyEvent& event);
705 * Callback called when the text-view is scrolled.
707 * Updates the selection and grab handles, and the highlighted text.
709 * @param[in] textView Handle of the text-view.
710 * @param[in] scrollPosition The difference with the previous scroll position.
712 void OnTextViewScrolled( Toolkit::TextView textView, Vector2 scrollPosition );
715 * Scrolls the text-view to make the cursor visible.
717 * @param[in] cursorPosition The actual cursor position in actor coordinates.
719 void ScrollTextViewToMakeCursorVisible( const Vector3& cursorPosition );
722 * Creates and starts a timer to scroll the text when handles are close to the edges of the text-input.
724 * It only starts the timer if it's already created.
726 void StartScrollTimer();
729 * Stops the timer used to scroll the text.
731 void StopScrollTimer();
734 * Callback called by the timer used to scroll the text.
736 * It calculates and sets a new scroll position.
738 bool OnScrollTimerTick();
740 public: // Public to allow internal testing.
743 * Register for touch events
745 void SetUpTouchEvents();
748 * Sets up TextView Actor
750 void CreateTextViewActor();
753 * Set Styled Text for text input.
754 * @param[in] styleText The new styled text for the text input.
756 void SetText( const MarkupProcessor::StyledTextArray& styleText );
759 * Start a timer to signal cursor to blink.
761 void StartCursorBlinkTimer();
764 * Stop the timer signalling the cursor to blink.
766 void StopCursorBlinkTimer();
769 * Starts input, setting focus and showing keyboard..
771 void StartEditMode();
774 * Called when End of input and focus no longer required, keyboard is hidden.
779 * Applies a style to the current pre-edit / predicted word to show it is being edited.
780 * @param[in] preEditStartPosition position in text array that the predicted word starts at
781 * @param[in] preEditStringLength used to calculate how many characters need their style changed.
783 void ApplyPreEditStyle( std::size_t preEditStartPosition, std::size_t preEditStringLength );
786 * Restores style to value before applying Pre-Edit style.
788 void RemovePreEditStyle();
791 * Event received from IMF manager
792 * @return ImfCallbackData data struture undicating if update is needed, cursor position and current text
794 ImfManager::ImfCallbackData ImfEventReceived( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& test );
797 * Called when the OnKey event is a Pre-edit string
798 * @param[in] keyString String received in Pre-edit
799 * @param[in] cursorOffset the cursor offset from where the pre-edit word starts
800 * @return bool true if preedit reset is required.
802 bool PreEditReceived( const std::string& keyString, std::size_t cursorOffset );
805 * Called when the OnKey event is a Commit string
806 * @param[in] keyString String received in Comment
807 * @return update flag to trigger cursor update of TextInput only when needed.
809 bool CommitReceived( const std::string& keyString );
812 * Deletes Pre-edit string
813 * By default it doesn't update the character's size and position table, which is a costly
814 * operation. As in many cases deletion and insertion (InsertAt) of text
815 * occurs in the same action i.e. preedit/commit. It makes sense to
816 * delete without updating, and then insert with updating.
818 * @return The number of characters to be deleted.
820 std::size_t DeletePreEdit();
823 * Reset all pre-edit flag and signal IMF keyboard that the current pre-edit word has been comitted.
824 * This may be due to the cursor being moved by user or reached the max character limit.
825 * @param[in] preserveCursorPosition Set true to keep cursor in current position, eg. touch event caused cursor to move.
827 void PreEditReset( bool preserveCursorPosition );
830 * Called after cursor position needs updating.
831 * Redraws cursor and notifies VirtualKeyboard
836 * Delete highlighted characters
837 * @param[in] inheritStyle Whether style from previous character in the string should be inherited.
839 void DeleteHighlightedText( bool inheritStyle );
842 * Delete range of characters
843 * @param[in] start position of characters to delete
844 * @param[in] ncharacters number of characters to delete
846 void DeleteRange(std::size_t start, std::size_t ncharacters);
849 * Delete character at current cursor position and redisplay
850 * @param[in] positionToDelete position of character to delete
852 void DeleteCharacter( std::size_t positionToDelete );
855 * Add or replaces characters to currently displayed string at cursor position
856 * By default it doesn't update the character's size and position table, which is a costly
857 * operation. As in many cases deletion and insertion (InsertAt) of text
858 * occurs in the same action i.e. preedit/commit. It makes sense to
859 * delete without updating, and then insert with updating.
860 * @param[in] newText string to add to TextInput display string.
861 * @param[in] insertionPosition position to insert at.
862 * @param[in] numberOfCharactersToReplace The number of characters to replace.
863 * @return number of characters to offset the cursor by.
865 std::size_t InsertAt( const Text& newText, const std::size_t insertionPosition, const std::size_t numberOfCharactersToReplace );
869 * @param[in] color the cursor color.
870 * @return the image actor to be used as the cursor.
872 ImageActor CreateCursor( const Vector4 &color );
875 * Moves cursor to the right
876 * param[in] reverse if true then cursor moves in the reverse direction (to the left)
877 * param[in] places number of character cursor should move.
879 void AdvanceCursor(bool reverse = false, std::size_t places = 1);
882 * Draw a cursor / caret at position where new text should appear
883 * @param[in] nthChar the position along the text string in which new text should appear.
885 void DrawCursor(const std::size_t nthChar = 0);
888 * Sets cursor visibility
889 * This sets visibility of the cursor. Which is comprised of 2
890 * cursors. The conventional cursor, and the alternate (RTL) cursor,
891 * which only appears when the cursor is at a character that can have
892 * a character appended to different visual positions depending on whether that
893 * character to be appended is RTL or LTR.
894 * @param[in] visible true - enable visibility for cursor, false - disable visiblity for cursor
896 void SetCursorVisibility( bool visible );
899 * Sets alternate cursor enable state
900 * @see SetCursorVisibility
901 * alternate cursor will only be visible if both SetCursorVisiblity
902 * and cursor enabled have been set to true.
904 void SetAltCursorEnabled( bool enabled );
907 * Create the grab handle that positions the cursor
908 * @param[in] image to be used for grab handle
911 void CreateGrabHandle(Image image=Image());
914 * Create Grab area to be used by Grab Handle
916 void CreateGrabArea( Actor& parent);
919 * Move grab handle to the required character position
921 * @param[in] displacement Displacement of the grab handle in actor coordinates.
923 * @return The new actual position the handle has been set to.
925 Vector3 MoveGrabHandle( const Vector2& displacement );
928 * Show or hide the grab handle without baking the visibility flag.
929 * Used when the Grab handle needs to be invisible due to text-view scrolling making it out of view
931 * @param[in] visible bool flag to set as true is grab handle should be shown, else false to hide.
933 void ShowGrabHandle( bool visible );
936 * Show or hide the grab handle and bake the visibility flag.
937 * Used when the state of text-input changes to a state which the grabhandle is not required. E.g. Selection mode starts or edit mode ends.
938 * Calls ShowGrabHandle.
940 * @param[in] visible bool flag to set as true is grab handle should be shown, else false to hide.
942 void ShowGrabHandleAndSetVisibility( bool visible );
944 /* Boundary Property Notifications when handle exceed bounding box*/
947 * PropertyNotification Callback when left boundary exceeded so handle can be flipped.
948 * @param[in] source PropertyNotification
950 void OnLeftBoundaryExceeded( PropertyNotification& source );
952 * PropertyNotification Callback when within left boundary so handle can be flipped back.
953 * @param[in] source PropertyNotification
955 void OnReturnToLeftBoundary( PropertyNotification& source );
957 * PropertyNotification Callback when right boundary exceeded so handle can be flipped.
958 * @param[in] source PropertyNotification
960 void OnRightBoundaryExceeded( PropertyNotification& source );
962 * * PropertyNotification Callback when within right boundary so handle can be flipped back.
963 * @param[in] source PropertyNotification
965 void OnReturnToRightBoundary( PropertyNotification& source );
968 * PropertyNotification Callbacks for hiding handle one when it exceeds boundary.
969 * @param[in] source PropertyNotification
971 void OnHandleOneLeavesBoundary( PropertyNotification& source );
973 * PropertyNotification Callbacks for showing hidden handle one when returns within boundary
974 * @param[in] source PropertyNotification
976 void OnHandleOneWithinBoundary( PropertyNotification& source );
978 * PropertyNotification Callbacks for hiding handle two it when exceeds boundary.
979 * @param[in] source PropertyNotification
981 void OnHandleTwoLeavesBoundary( PropertyNotification& source );
983 * PropertyNotification Callbacks for showing hidden handle two when returns within boundary
984 * * @param[in] source PropertyNotification
986 void OnHandleTwoWithinBoundary( PropertyNotification& source );
989 * Set up property notifications on the position of the handles to facilitate flipping and hiding when at screen boundary.
991 void SetUpHandlePropertyNotifications();
994 * Create the selection handles that bound text to be selected for copy/cut.
995 * @param[in] start initial position of start selection handle.
996 * @param[in] end initial position of end selection handle.
997 * @param[in] handleOneImage (optional) to be used for selection handle
998 * @param[in] handleTwoImage (optional) to be used for selection handle
1000 void CreateSelectionHandles( std::size_t start = 0, std::size_t end = std::numeric_limits<std::size_t>::max(), Dali::Image handleOneImage = Dali::Image(), Dali::Image handleTwoImage = Dali::Image() );
1003 * Move the selection handles to required positions in text.
1005 * @param[in] handleId the handle to position
1006 * @param[in] displacement Displacement of the selection handle in actor coordinates.
1008 * @return The new actual position the handle has been set to.
1010 Vector3 MoveSelectionHandle(SelectionHandleId handleId, const Vector2& displacement);
1013 * Calculate and position the specified selection handle the given index position
1015 * @param[in] handleId the handle to position
1017 void SetSelectionHandlePosition(SelectionHandleId handleId);
1020 * Gets the visual position of a logical position.
1021 * @note This is preferred over directly accessing the Map, as it resolves visual
1022 * positions outside of the character map range.
1023 * @param[in] logicalPosition The logical position
1024 * @return Visual position is returned.
1026 std::size_t GetVisualPosition(std::size_t logicalPosition) const;
1029 * Gets a table of the visual text positions which has a flag
1030 * for each Character. The flag is either true (character selected)
1031 * or false (character deselected)
1032 * @note startSelection can be greater or less than endSelection
1034 * @param[in,out] selectedVisualText The vector to be resized and populated with the selected flags
1035 * @param[in] startSelection The start selection point for the text
1036 * @param[in] endSelection The end selection point for the text
1038 void GetVisualTextSelection(std::vector<bool>& selectedVisualText, std::size_t startSelection, std::size_t endSelection);
1041 * Iterates between selection handles and computes the info required to build the highlight mesh
1043 HighlightInfo CalculateHighlightInfo();
1046 * Calculates new Mesh data so highlight moves with selection handles.
1048 void UpdateHighlight();
1051 * Removes popup, and its options.
1056 * Adds Popup options which have been enabled.
1058 void AddPopupOptions();
1061 * Sets popup position
1062 * @param[in] position The actual position for this popup.
1063 * @param[in] alternativePosition Alternative popup position if no space in upper area.
1065 void SetPopupPosition(const Vector3& position, const Vector2& alternativePosition );
1069 * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
1070 * @param[in] signalFinished (optional) whether to perform an animation finish operation after the hide animation completes. Requires animate to be true.
1072 void HidePopup( bool animate = true, bool signalFinished = true );
1076 * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
1078 void ShowPopup(bool animate = true);
1081 * Shows the cut-copy-paste popup
1083 void ShowPopupCutCopyPaste();
1086 * Setup the selection popup and clipboard if relevant so the correct options are shown when ShowPopup is called.
1087 * @param[in] treatWhiteSpaceAsAnyOtherCharacter If whitespace should not be selected in the same manner as other characters set
1088 * this to false. default is true.
1090 void SetUpPopupSelection( bool treatWhiteSpaceAsAnyOtherCharacter = true );
1093 * Return the logical index containing the character position closest to the source.
1094 * Used for positioning the grab handle at characters when dragged along.
1095 * Two different behaviours are needed in case the source point doesn't actually touch a
1096 * character. @see TouchToIndex.
1097 * @param[in] source float to match against
1098 * @param[out] closestIndex index to the vector of character's size and position.
1099 * @return \e true if the source point is actually inside the geometry provided by TextView.
1101 bool ReturnClosestIndex(const Vector2& source, std::size_t& closestIndex );
1104 * Returns the X-position of the current line justification
1105 * (relative to left of text-view container)
1106 * @return X position for line justification
1108 float GetLineJustificationPosition() const;
1111 * Currently the cursor is positioned at the previous characters position plus it's width.
1112 * If the previous character is on a different line then this function returns the correct position.
1113 * @param[in] characterPosition the character position index that the cursor should be at
1114 * @return position of cursor/handle
1116 Vector3 PositionCursorAfterWordWrap( std::size_t characterPosition ) const;
1120 * Return a vector which is the actual position for the given character position
1121 * The character position is where a cursor would be position for that character.
1122 * @param[in] characterPosition the logical (input) position in the 'string' of characters.
1124 * @return Vector3 the actual x,y,z position
1126 Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition ) const;
1129 * Return a vector which is the actual position for the given character position
1130 * The character position is where a cursor would be positioned for that character to be inserted.
1131 * An additional alternatePosition is also set in circumstances where the possible writing
1132 * of characters would be in the opposite direction.
1133 * e.g. "HelloشقشلاهؤEnglish"
1136 * [*] - Primary actual position for cursor i.e. continuing writing LTR (English)
1137 * [+] - Alternate actual position for cursor i.e. writing RTL (Arabic)
1139 * @param[in] characterPosition the logical (input) position in the 'string' of characters.
1140 * @param[out] directionRTL Whether the actual x,y,z position is after LTR (false) or RTL (true) text.
1141 * @param[out] alternatePosition the actual x,y,z position of the cursor if user types
1142 * in alternate direction to current flow of text.
1143 * @param[out] alternatePositionValid whether this alternate position is valid.
1144 * @return Vector3 the actual x,y,z position
1146 Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition, bool& directionRTL, Vector3& alternatePosition, bool& alternatePositionValid ) const;
1149 * Retrieve the character position of the first character on the row of text
1150 * that this character resides on.
1151 * @param[in] logicalPosition the position in the 'string' of characters.
1152 * @return logical character position of start of row.
1154 std::size_t GetRowStartFromCharacterPosition(std::size_t logicalPosition) const;
1157 * Retrieve the dimensions of this row of text that the character resides on.
1158 * @param[in] characterPosition the position in the 'string' of characters.
1159 * @return The size of the rectangle representing this row
1161 Size GetRowRectFromCharacterPosition(std::size_t characterPosition) const;
1164 * Retrieve the dimensions (and min-max) of this row of text that the character resides on.
1165 * @param[in] characterPosition the position in the 'string' of characters.
1166 * @param[out] min the top-left position of the rectangle representing this row
1167 * @param[out] max the bottom-right position of the rectangle representing this row
1168 * @return The size of the rectangle representing this row (max - min)
1170 Size GetRowRectFromCharacterPosition(std::size_t characterPosition, Vector2& min, Vector2& max) const;
1173 * Checks if the provided touchedActor was this text-input
1174 * @param[in] touchedActor the touched actor that will be checked against this text-input
1175 * @return true if the touchActor was the text-input or one of its children
1177 bool WasTouchedCheck( const Actor& touchedActor ) const;
1180 * Connect to the stage touch event
1182 void StartMonitoringStageForTouch();
1185 * Disconnect from the stage touch event
1187 void EndMonitoringStageForTouch();
1190 * Callback for when the screen is touched, this will be connected when selection starts and disconnected when it ends.
1191 * @param[in] event The touch event
1193 void OnStageTouched(const TouchEvent& event);
1197 * Select the text between the given values
1198 * @param[in] start position within array to start selection
1199 * @param[in] end position within array to end selection
1201 void SelectText(std::size_t start, std::size_t end);
1204 * Gets selected text and returns it as a StyleText vector
1205 * @return StyledText vector that is selected.
1207 MarkupProcessor::StyledTextArray GetSelectedText();
1210 * Applies the given style to all text, selected or not selected.
1211 * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
1213 void ApplyStyleToRange(const TextStyle& style, const TextStyle::Mask mask, const std::size_t begin, const std::size_t end);
1216 * Callback for when the keyboard status changes
1217 * @param[in] keyboardShown Whether the keyboard has just been shown or not.
1219 void KeyboardStatusChanged(bool keyboardShown);
1222 * Hide highlight shown between selection handles.
1223 * @param[in] hidePopup flag to hide the popup too, default is to hide popup.
1225 void RemoveHighlight( bool hidePopup = true );
1228 * Highlights text that has been selected
1230 void CreateHighlight();
1233 * Copies selected text to clipboard
1234 * @return bool true if copy was successful.
1236 bool CopySelectedTextToClipboard();
1239 * Pastes the given text to currently displayed string at the current cursor position
1240 * @param[in] text Text to be pasted
1242 void PasteText( const Text& text );
1245 * Sets the direction of the text if it is empty.
1247 void SetTextDirection();
1250 * Updates the line height accordingly with the current text input style.
1252 void UpdateLineHeight();
1255 * Finds a visible character.
1257 * The \e direction parameters specifies from where to start to look for a visible character. \e Left means start by characters in lower
1258 * positions than \e cursorPosition, \e Right means start by characters in greater positions than \e cursorPosition and \e ByEnd starts
1259 * by the last characters.
1261 * If \e Left or \e Right is provided and any character is found, then looks in the other direction.
1263 * @param[in] direction Direction used to find a visible character.
1264 * @param[in] cursorPosition Starting position.
1266 * @return The found visible character.
1268 std::size_t FindVisibleCharacter( const FindVisibleCharacterDirection direction , const std::size_t cursorPosition ) const;
1271 * @copydoc SetSortModifier()
1273 void SetSortModifier( float depthOffset );
1276 * @copydoc SetSnapshotModeEnabled()
1278 void SetSnapshotModeEnabled( bool enable );
1281 * @copydoc IsSnapshotModeEnabled()
1283 bool IsSnapshotModeEnabled() const;
1286 * @copydoc SetScrollEnabled()
1288 void SetScrollEnabled( bool enable );
1291 * @copydoc IsScrollEnabled()
1293 bool IsScrollEnabled() const;
1296 * @copydoc SetScrollPosition()
1298 void SetScrollPosition( const Vector2& position );
1301 * @copydoc GetScrollPosition()
1303 Vector2 GetScrollPosition() const;
1306 * @brief Sets whether markup processing should be carried out.
1308 * @param[in] enable whether markup processing is carried out or not.
1310 void SetMarkupProcessingEnabled( bool enable );
1313 * @brief Returns whether markup processing is enabled or not
1315 * @return true is markup processing is enabled
1317 bool IsMarkupProcessingEnabled() const;
1320 * Insert or replaces the given text in the given position. It checks if the text exceeds the maximum allowed number of characters
1321 * and if it fits in the text-input's boundaries.
1323 * @param[in] text Text to be inserted.
1324 * @param[in] position Position where the text is inserted.
1325 * @param[in] numberOfCharactersToReplace The number of characters to replace.
1326 * @param[out] textExceedsMaximunNumberOfCharacters The number of characters that have been inserted.
1327 * @param[out] textExceedsBoundary Whether the inserted text has exceeded the boundaries of the text-input.
1329 * @return The number of characters that have been inserted.
1331 std::size_t DoInsertAt( const Text& text, std::size_t position, std::size_t numberOfCharactersToReplace, bool& textExceedsMaximunNumberOfCharacters, bool& textExceedsBoundary );
1334 * Retrieve Text-view's layout info.
1336 void GetTextLayoutInfo();
1339 * Set the offset for positioning Popup from the TextInput
1340 * @param[in] offset in the order, left, top, right, bottom
1342 void SetOffsetFromText( const Vector4& offset );
1345 * Get the offset of the Popup from the TextInput
1346 * @return Vector4 with the offset in the order, left, top, right, bottom
1348 const Vector4& GetOffsetFromText() const;
1353 * Called when a property of an object of this type is set.
1354 * @param[in] object The object whose property is set.
1355 * @param[in] index The property index.
1356 * @param[in] value The new property value.
1358 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
1361 * Called to retrieve a property of an object of this type.
1362 * @param[in] object The object whose property is to be retrieved.
1363 * @param[in] index The property index.
1364 * @return The current value of the property.
1366 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
1369 * Emits the style changed signal.
1371 void EmitStyleChangedSignal();
1374 * Emit signal when text is modified.
1376 void EmitTextModified();
1379 * Emits max input characters reached signal.
1381 void EmitMaxInputCharactersReachedSignal();
1384 * Emits a signal when the input text exceeds the boundaries of the text-input.
1386 void EmitInputTextExceedsBoundariesSignal();
1390 State mState; ///< Current State of Text input.
1391 MarkupProcessor::StyledTextArray mStyledText; ///< String currently displayed by TextView with style info.
1392 TextStyle mInputStyle; ///< Stores the current input style.
1393 float mLineHeight; ///< Stores the current line height accordingly with the input style.
1394 Toolkit::TextView mDisplayedTextView; ///< Actor which actually display text
1396 MarkupProcessor::StyledTextArray mStyledPlaceHolderText; ///< Text used as place holder with style info.
1398 std::size_t mMaxStringLength; ///< Max number of characters for string
1399 std::size_t mNumberOflinesLimit; ///< Limit on the number of lines this TextInput will display.
1401 ImageActor mCursor; ///< Cursor overlayed on Text to show where new text will be inserted
1402 ImageActor mCursorRTL; ///< Right To Left Cursor overlayed on Text (where new RTL text would be inserted)
1403 Animation mCursorAnimation; ///< animator for cursor blinking.
1404 std::size_t mCursorPosition; ///< position along string cursor is at.
1405 Timer mCursorBlinkTimer; ///< Timer to signal cursor to blink
1407 Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else.
1409 Image mGrabHandleImage; ///< image to be used for grab handle
1410 ImageActor mGrabHandle; ///< Handle used to move cursor for editing
1412 Actor mGrabArea; ///< invisible actor that receives pans events for the grab handle.
1413 PanGestureDetector mPanGestureDetector; ///< Pan gesture for handles
1414 TapGestureDetector mTapDetector; ///< used to start editing
1415 TapGestureDetector mDoubleTapDetector; ///< double tap detector
1417 Vector3 mActualGrabHandlePosition; ///< actual position of grab handle, this might not be snapped to a character
1419 LongPressGestureDetector mLongPressDetector; ///< Gesture to start selection
1421 /*Selection handles*/
1422 Image mSelectionHandleOneImage; ///< image used for selection handle one
1423 Image mSelectionHandleOneImagePressed; ///< image used for selection handle one pressed state
1424 Image mSelectionHandleTwoImage; ///< image used for selection handle two
1425 Image mSelectionHandleTwoImagePressed; ///< image used for selection handle two pressed state
1427 bool mIsSelectionHandleOneFlipped:1; ///< Flag to know whether the handle one is flipped or not.
1428 bool mIsSelectionHandleTwoFlipped:1; ///< Flag to know whether the handle two is flipped or not.
1429 Vector3 mSelectionHandleOneOffset; ///< Handle One's Offset
1430 Vector3 mSelectionHandleTwoOffset; ///< Handle Two's Offset
1431 Vector3 mSelectionHandleOneActualPosition; ///< Actual x y position of handle
1432 Vector3 mSelectionHandleTwoActualPosition; ///< Actual x y position of handle
1433 std::size_t mSelectionHandleOnePosition; ///< Position of handle along the string of text
1434 std::size_t mSelectionHandleTwoPosition; ///< Position of handle along the string of text
1435 ImageActor mSelectionHandleOne; ///< First selection handle used for selecting text to cut&paste
1436 ImageActor mSelectionHandleTwo; ///< Second selection handle used for selecting text to cut&paste
1437 Actor mHandleOneGrabArea; ///< invisible actor that receives pans events for the selection handle.
1438 Actor mHandleTwoGrabArea; ///< invisible actor that receives pans events for the selection handle.
1440 Mesh mHighlightMesh; ///< Mesh Data for highlight
1441 MeshActor mHighlightMeshActor; ///< Mesh Actor to display highlight
1442 MeshData mMeshData; ///< Container to hold meshData for highlight
1443 Material mCustomMaterial; ///< Custom material used for highlight
1444 HighlightInfo mNewHighlightInfo; ///< Geometry info to create highlight.
1446 Text mPreEditString; ///< Holds current input string prior to it being committed.
1447 std::size_t mPreEditStartPosition; ///< Cursor position for start of pre-edit string
1448 std::size_t mPreEditLength; ///< Cursor position for length of current pre-edit string after purging characters that do not fit.
1449 std::size_t mNumberOfSurroundingCharactersDeleted; ///< Stores the number of surrounding characters deleted.
1450 unsigned long mTouchStartTime; ///< Touch Start time (time in ms when down press began)
1452 Toolkit::TextView::TextLayoutInfo mTextLayoutInfo; ///< It contains a table layout info per character sorted by the character's visual index (retrieved from TextView),
1453 ///< a reorder map that stores each character's visual (output) index according to its logical (input) index,
1454 ///< a reorder map that stores each character's logical (input) index according to its visual (output) index,
1455 ///< the text size after layout and the scroll offset.
1457 MarkupProcessor::StyledTextArray mCurrentCopySelecton; ///< Array to store copied text.
1458 TextInputPopup mPopupPanel; ///< Panel to house cut and paste, select all buttons.
1461 Vector2 mScrollDisplacement;
1462 Vector3 mCurrentHandlePosition;
1463 SelectionHandleId mCurrentSelectionId;
1464 Vector3 mCurrentSelectionHandlePosition;
1465 SelectionParameters mRequestedSelection;
1466 Vector4 mSelectionHandleFlipMargin;
1467 Vector4 mBoundingRectangleWorldCoordinates;
1469 Clipboard mClipboard; ///< Handle to clipboard
1472 Vector4 mMaterialColor; // Color of the highlight
1473 Vector4 mPopupOffsetFromText; // Offset of Popup from the TextInput.
1475 bool mOverrideAutomaticAlignment:1; ///< Whether to override the alignment automatically set by the text content (e.g. european LTR or arabic RTL)
1476 bool mCursorRTLEnabled:1; ///< Enable state of Alternate RTL Cursor (need to keep track of this as it's not always enabled)
1477 bool mClosestCursorPositionEOL:1; ///< closest cursor position is end of line.
1478 bool mCursorBlinkStatus:1; ///< \e true shows the cursor, \e false hiddes it.
1480 bool mCursorVisibility:1; ///< Visibility status of Cursor
1481 bool mGrabHandleVisibility:1; ///< Visibility status of the grab handle.
1483 bool mIsCursorInScrollArea:1; ///< Whether the cursor is inside the boundaries of the text-input.
1484 bool mIsGrabHandleInScrollArea:1; ///< Whether the grab handle is inside the boundaries of the text-input.
1486 bool mEditModeActive:1; ///< true to indicate TextInput is in edit mode.
1487 bool mEditOnTouch:1; ///< true indicates edit mode starts by touching/tapping the TextInput
1488 bool mTextSelection:1; ///< true indicates text selection is enabled.
1489 bool mExceedEnabled:1; ///< Whether text-input editing text beyond its boundary is enabled or not. By default is enabled.
1490 bool mGrabHandleEnabled:1; ///< Flag to enable the grab handle instead of the default magnifier.
1491 bool mIsSelectionHandleFlipEnabled:1; ///< Flag to enable the selection handle flip
1493 bool mPreEditFlag:1; ///< Flag to indicate if key string received is still in pre-edit mode (Ecore IMF keyboard)
1494 bool mIgnoreCommitFlag:1; ///< Flag to indicate if the commit string should be ignored, maybe due to a keyboard reset.
1495 bool mIgnoreFirstCommitFlag:1; ///< Whether to ignore the first commit.
1496 bool mSelectingText:1; ///< Ignore surrounding text as selecting text
1498 bool mPreserveCursorPosition:1; ///< Indicates that the commit message is from a reset and does not require the cursor to be moved
1500 bool mSelectTextOnCommit:1;
1502 bool mUnderlinedPriorToPreEdit:1; ///< As predictive text adds underline style this flag enables us to revert back or keep underline.
1504 bool mCommitByKeyInput:1; ///< Set if a commit is done by key input rather than automatically (usually when a space bar or enter is pressed).
1506 bool mPlaceHolderSet:1; ///< Whether the place holder text is set.
1507 bool mMarkUpEnabled:1; ///< enable to scan for mark-up
1509 Toolkit::TextInput::InputSignalV2 mInputStartedSignalV2; ///< Signal emitted when input starts
1510 Toolkit::TextInput::InputSignalV2 mInputFinishedSignalV2; ///< Signal emitted when input ends
1511 Toolkit::TextInput::StyleChangedSignalV2 mStyleChangedSignalV2; ///< Signal emitted when style changes.
1512 Toolkit::TextInput::TextModifiedSignalType mTextModifiedSignal; ///< Signal emitted when text modified.
1513 Toolkit::TextInput::MaxInputCharactersReachedSignalV2 mMaxInputCharactersReachedSignalV2; ///< Signal emitted when max input characters is reached.
1514 Toolkit::TextInput::InputSignalV2 mCutAndPasteToolBarDisplayedV2; ///< Signal emitted when toolbar displayed
1515 Toolkit::TextInput::InputTextExceedBoundariesSignalV2 mInputTextExceedBoundariesSignalV2; ///< Signal emitted when input text exceeds the boundaries of the text-input.
1518 } // namespace Internal
1520 // Helpers for public-api forwarding methods
1522 inline Toolkit::Internal::TextInput& GetImpl(Toolkit::TextInput& textInput)
1524 DALI_ASSERT_ALWAYS(textInput);
1526 Dali::RefObject& handle = textInput.GetImplementation();
1528 return static_cast<Toolkit::Internal::TextInput&>(handle);
1531 inline const Toolkit::Internal::TextInput& GetImpl(const Toolkit::TextInput& textInput)
1533 DALI_ASSERT_ALWAYS(textInput);
1535 const Dali::RefObject& handle = textInput.GetImplementation();
1537 return static_cast<const Toolkit::Internal::TextInput&>(handle);
1540 } // namespace Toolkit
1544 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_H__