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 Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali-toolkit/public-api/controls/control-impl.h>
22 #include <dali-toolkit/public-api/controls/text-input/text-input.h>
23 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
24 #include <dali-toolkit/public-api/controls/tool-bar/tool-bar.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/adaptor-framework/common/imf-manager.h>
30 #include <dali/public-api/geometry/mesh.h>
44 typedef IntrusivePtr<TextInput> TextInputPtr;
46 class TextInput : public ControlImpl
51 * Create a new TextInput
52 * @return instrusive ptr to a TextInput
54 static Dali::Toolkit::TextInput New();
57 * @copydoc Toolkit::TextInput::GetText
59 std::string GetText() const;
62 * @copydoc Toolkit::TextInput::GetMarkupText()
64 std::string GetMarkupText() const;
67 * @copydoc Toolkit::TextInput::SetPlaceholderText
69 void SetPlaceholderText( const std::string& placeHolderText );
72 * @copydoc Toolkit::TextInput::SetPlaceholderText
74 std::string GetPlaceholderText();
77 * @copydoc Toolkit::TextInput::SetInitialText
79 void SetInitialText(const std::string& initialText);
82 * set the text to be displayed in text-input, will overwrite any existing text.
83 * can be used to clear the text-input by passing an empty string.
84 * @param [in] initialText text to be initially displayed
86 void SetText(const std::string& initialText);
89 * @copydoc Toolkit::TextInput::SetMaxCharacterLength
91 void SetMaxCharacterLength(std::size_t maxChars);
94 * @copydoc Toolkit::TextInput::SetNumberOfLinesLimit
96 void SetNumberOfLinesLimit(std::size_t maxLines);
99 * @copydoc Toolkit::TextInput::GetNumberOfLinesLimit
101 std::size_t GetNumberOfLinesLimit() const;
104 * @copydoc Toolkit::TextInput::GetFont
106 Font GetFont() const;
109 * @copydoc Toolkit::TextInput::SetFont
111 void SetFont(Font font);
114 * @copydoc Toolkit::TextInput::InputStartedSignal()
116 Toolkit::TextInput::InputSignalV2& InputStartedSignal();
119 * @copydoc Toolkit::TextInput::InputFinishedSignal()
121 Toolkit::TextInput::InputSignalV2& InputFinishedSignal();
124 * @copydoc Toolkit::TextInput::CutAndPasteToolBarDisplayedSignal()
126 Toolkit::TextInput::InputSignalV2& CutAndPasteToolBarDisplayedSignal();
129 * @copydoc Toolkit::TextInput::StyleChangedSignal()
131 Toolkit::TextInput::StyleChangedSignalV2& StyleChangedSignal();
134 * @copydoc Toolkit::TextInput::MaxInputCharactersReachedSignal()
136 Toolkit::TextInput::MaxInputCharactersReachedSignalV2& MaxInputCharactersReachedSignal();
139 * @copydoc Toolkit::TextInput::InputTextExceedBoundariesSignal()
141 Toolkit::TextInput::InputTextExceedBoundariesSignalV2& InputTextExceedBoundariesSignal();
144 * Connects a callback function with the object's signals.
145 * @param[in] object The object providing the signal.
146 * @param[in] tracker Used to disconnect the signal.
147 * @param[in] signalName The signal to connect to.
148 * @param[in] functor A newly allocated FunctorDelegate.
149 * @return True if the signal was connected.
150 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
152 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
155 * @see Toolkit::TextInput::SetEditMode(bool editMode)
156 * @see Toolkit::TextInput::SetEditMode(bool editMode, const Vector2& touchPoint)
158 * @param[in] editMode true or false to indicate editMode on or off.
159 * @param[in] setCursorOnTouchPoint Whether to use the touch point to set the cursor position.
160 * @param[in] touchPoint A position in actor coordinates within the text-input.
162 void SetEditable(bool editMode, bool setCursorOnTouchPoint, const Vector2& touchPoint = Vector2::ZERO);
165 * @copydoc Toolkit::TextInput::GetEditMode
167 bool IsEditable() const;
170 * @copydoc Toolkit::TextInput::SetTextSelectable
172 void SetTextSelectable(bool textSelectable = true);
175 * @copydoc Toolkit::TextInput::IsTextSelectable
177 bool IsTextSelectable() const;
180 * @copydoc Toolkit::TextInput::IsTextSelected
182 bool IsTextSelected() const;
185 * @copydoc Toolkit::TextInput::DeSelectText
190 * @copydoc Toolkit::TextInput::SetEditOnTouch
192 void SetEditOnTouch(bool editOnTouch);
195 * @copydoc Toolkit::TextInput::IsEditOnTouch
197 bool IsEditOnTouch() const;
200 * @copydoc Toolkit::TextInput::SetGrabHandleImage
202 void SetGrabHandleImage(Dali::Image image);
205 * @copydoc Toolkit::TextInput::SetCursorImage
207 void SetCursorImage(Dali::Image image, const Vector4& border );
210 * @copydoc Toolkit::TextInput::GetSelectionHandleSize
212 Vector3 GetSelectionHandleSize();
215 * @copydoc Toolkit::TextInput::SetRTLCursorImage
217 void SetRTLCursorImage(Dali::Image image, const Vector4& border );
220 * @copydoc Toolkit::TextInput::EnableGrabHandle
222 void EnableGrabHandle(bool toggle);
225 * @copydoc Toolkit::TextInput::IsGrabHandleEnabled
227 bool IsGrabHandleEnabled();
230 * @copydoc Toolkit::TextInput::EnableSelectionHandleFlip
232 void EnableSelectionHandleFlip( bool toggle );
235 * @copydoc Toolkit::TextInput::IsSelectionHandleFlipEnabled
237 bool IsSelectionHandleFlipEnabled();
240 * @copydoc Toolkit::TextInput::SetSelectionHandleFlipMargin
242 void SetSelectionHandleFlipMargin( const Vector4& margin );
245 * @copydoc Toolkit::TextInput::SetBoundingRectangle
247 void SetBoundingRectangle( const Rect<float>& boundingRectangle );
250 * @copydoc Toolkit::TextInput::GetBoundingRectangle
252 const Rect<float> GetBoundingRectangle() const;
255 * @copydoc Toolkit::TextInput::GetSelectionHandleFlipMargin
257 const Vector4& GetSelectionHandleFlipMargin();
260 * @copydoc Toolkit::TextInput::SetTextColor
262 void SetTextColor( const Vector4& color );
265 * @copydoc Toolkit::TextInput::SetActiveStyle
267 void SetActiveStyle( const TextStyle& style, const TextStyle::Mask mask );
270 * @copydoc Toolkit::TextInput::ApplyStyle
272 void ApplyStyle( const TextStyle& style, const TextStyle::Mask mask );
275 * @copydoc Toolkit::TextInput::ApplyStyleToAll
277 void ApplyStyleToAll( const TextStyle& style, const TextStyle::Mask mask );
280 * @copydoc Toolkit::TextInput::GetStyleAtCursor
282 TextStyle GetStyleAtCursor() const;
285 * Retrieves the character style for the given position.
286 * @param[in] position The character position which style is required.
287 * @return The style for the given position.
289 TextStyle GetStyleAt( std::size_t position ) const;
292 * @copydoc Toolkit::TextInput::SetTextAlignment()
294 void SetTextAlignment( Toolkit::Alignment::Type align );
297 * @copydoc Toolkit::TextInput::SetTextLineJustification()
299 void SetTextLineJustification( Toolkit::TextView::LineJustification justification );
302 * @copydoc Toolkit::TextInput::SetFadeBoundary()
304 void SetFadeBoundary( const Toolkit::TextView::FadeBoundary& fadeBoundary );
307 * @copydoc Toolkit::TextInput::GetFadeBoundary()
309 const Toolkit::TextView::FadeBoundary& GetFadeBoundary() const;
312 * @copydoc Toolkit::TextInput::GetTextAlignment()
314 Toolkit::Alignment::Type GetTextAlignment() const;
317 * @copydoc Toolkit::TextInput::SetMultilinePolicy()
319 void SetMultilinePolicy( Toolkit::TextView::MultilinePolicy policy );
322 * @copydoc Toolkit::TextInput::GetMultilinePolicy()
324 Toolkit::TextView::MultilinePolicy GetMultilinePolicy() const;
327 * @copydoc Toolkit::TextInput::SetWidthExceedPolicy()
329 void SetWidthExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
332 * @copydoc Toolkit::TextInput::GetWidthExceedPolicy()
334 Toolkit::TextView::ExceedPolicy GetWidthExceedPolicy() const;
337 * @copydoc Toolkit::TextInput::SetHeightExceedPolicy()
339 void SetHeightExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
342 * @copydoc Toolkit::TextInput::GetHeightExceedPolicy()
344 Toolkit::TextView::ExceedPolicy GetHeightExceedPolicy() const;
347 * @copydoc Toolkit::TextInput::SetExceedEnabled()
349 void SetExceedEnabled( bool enable );
352 * @copydoc Toolkit::TextInput::GetExceedEnabled()
354 bool GetExceedEnabled() const;
357 * @copydoc Toolkit::TextInput::SetBackground
359 void SetBackground(Dali::Image image );
362 * @copydoc Toolkit::TextInput::SetNumberOfLines
364 void SetNumberOfLines(std::size_t lines);
367 * @copydoc Toolkit::TextInput::GetNumberOfLines
369 std::size_t GetNumberOfLines();
372 * @copydoc Toolkit::TextInput::GetNumberOfCharacters
374 std::size_t GetNumberOfCharacters() const;
379 * structure to hold each highlight box needed for text selection
383 Vector3 size; ///< size of the highlight box
384 Vector3 position; ///< position of highlight box
385 ImageActor highlightBoxActor; ///< as actor that is the highlight box
389 * structure to hold each character in displayed string and its position from the left
393 char character; ///< todo change to UTF to aid multi-language support
399 * structure to hold coordinates of each quad, which will make up the mesh.
401 struct QuadCoordinates
404 * Default constructor
412 * @param[in] x1 left co-ordinate
413 * @param[in] y1 top co-ordinate
414 * @param[in] x2 right co-ordinate
415 * @param[in] y2 bottom co-ordinate
417 QuadCoordinates(float x1, float y1, float x2, float y2)
423 Vector2 min; ///< top-left (minimum) position of quad
424 Vector2 max; ///< bottom-right (maximum) position of quad
427 typedef std::vector<QuadCoordinates> QuadContainer;
430 * structure for information required to build the highlight mesh
435 * Adds a Quad (2D rectangular sub-selection)
436 * @param[in] x1 left co-ordinate
437 * @param[in] y1 top co-ordinate
438 * @param[in] x2 right co-ordinate
439 * @param[in] y2 bottom co-ordinate
441 void AddQuad( float x1, float y1, float x2, float y2 );
444 * Clamps all quads to fit within a min -> max 2D boundary.
446 void Clamp2D(const Vector2& min, const Vector2& max);
448 QuadContainer mQuadList; ///< List of quads (sub-selections that form to create complete selection)
452 * Holds requested selection start and end points for highlighted text.
454 struct SelectionParameters
456 SelectionParameters( size_t start, size_t end )
457 : mStartOfSelection( start ), mEndOfSelection( end )
462 size_t mStartOfSelection;
463 size_t mEndOfSelection;
472 enum SelectionHandleId
474 HandleOne, ///< Selection handle one which is on the left
475 HandleTwo ///< Selection handle two which is on the right
479 * Two different behaviours are needed to convert a touch point into a character index.
480 * When a tap is received and the touch point doesn't hit any character, the final character selected might
481 * be different than the one selected if the event is a pan.
482 * i.e. If a tap is received and the touch point doesn't hit any character the expected position of the cursor
483 * would be the end or the beginning of a line. However, this behaviour would be weird while panning.
487 TapMode, ///< Touch point to character index conversion mode used for Tap events.
488 DragMode ///< Touch point to character index conversion mode used for Pan events.
492 * Used to set the direction when find the next visible character.
494 enum FindVisibleCharacterDirection
496 Left, ///< Find visible characters on the left.
497 Right, ///< Find visible characters on the right.
498 ByEnd ///< Start finding visible characters by the end.
504 virtual bool OnTouchEvent(const TouchEvent& event);
507 * From CustomActorImpl; called after the Text Input actor is touched
508 * @param[in] event The KeyEvent event.
509 * @return True if the event should be consumed.
511 virtual bool OnKeyEvent(const KeyEvent& event);
514 * From CustomActorImpl; called when this actor gains keyboard focus.
516 virtual void OnKeyInputFocusGained();
519 * From CustomActorImpl; called when this actor loses keyboard focus.
521 virtual void OnKeyInputFocusLost();
524 * From ControlImpl; called whenever the control is added to the stage.
526 virtual void OnControlStageConnection();
528 private: // From ControlImpl
531 * Creation of the layer that is used by top level active parts of the TextInput like handles
533 void CreateActiveLayer();
536 * @copydoc Toolkit::ControlImpl::OnInitialize()
538 virtual void OnInitialize();
541 * @copydoc Toolkit::ControlImpl::OnControlSizeSet()
543 virtual void OnControlSizeSet(const Vector3& targetSize);
546 * @copydoc Toolkit::ControlImpl::OnRelaidOut()
548 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
551 * Retrieves the text-input's natural size by calling TextView::GetNaturalSize().
553 * @return The natural size.
555 virtual Vector3 GetNaturalSize();
558 * Retrieves the text-input's \e height for a given \e width by calling TextView::GetHeightForWidth().
560 * @param[in] width The given \e width.
562 * @return The \e height for the given \e width.
564 virtual float GetHeightForWidth( float width );
569 * Construct a new TextInput.
574 * A reference counted object may only be deleted by calling Unreference()
576 virtual ~TextInput();
581 TextInput(const TextInput&);
584 TextInput& operator=(const TextInput& rhs);
587 * Callback when a handle is panned/moved, either selection handles or grab handle
588 * @param actor Handle of the selection or grab handle.
589 * @param gesture Data structure with the parameters of the gesture.
591 void OnHandlePan(Actor actor, PanGesture gesture);
594 * Callback for touch down on Grab handle
595 * @param[in] actor touched
596 * @param[in] touch touch event
598 bool OnPressDown(Dali::Actor actor, const TouchEvent& touch);
601 * Callback for touch down on Selection handle one
602 * @param[in] actor touched
603 * @param[in] touch touch event, used to determine if down or up event
605 bool OnHandleOneTouched(Dali::Actor actor, const TouchEvent& touch);
608 * Callback for touch down on Selection handle two
609 * @param[in] actor touched
610 * @param[in] touch touch event, used to determine if down or up event
612 bool OnHandleTwoTouched(Dali::Actor actor, const TouchEvent& touch);
615 * Callback for tap on TextInput
617 * @param[in] tap touch event
619 void OnTextTap(Dali::Actor actor, Dali::TapGesture tap);
622 * Callback for double tap on TextInput
624 * @param[in] tap touch event
626 void OnDoubleTap(Dali::Actor actor, Dali::TapGesture tap);
629 * Callback for long press on TextInput
631 * @param[in] longPress long press event
633 void OnLongPress(Dali::Actor actor, Dali::LongPressGesture longPress);
636 * Callback for the ClipboardEventNotifier when text is selected in the clipboard window.
637 * @param[in] notifier The Clipboard Event Notifier.
639 void OnClipboardTextSelected( ClipboardEventNotifier& notifier );
642 * Callback for when a button is pressed in popup panel
643 * @param[in] button handle to the button pressed.
645 bool OnPopupButtonPressed( Toolkit::Button button );
648 * Callback when handle timer ticks.
650 * Cursor should become visible/invisible to simulate blinking.
652 * @return True if the timer should be keep running.
654 bool OnCursorBlinkTimerTick();
657 * Invoked upon popup Hide animation completing.
658 * @note Only called for animating hide, not called for instantaneous (animate = false)
659 * @param[in] popup The popup which was hidden.
661 void OnPopupHideFinished(TextInputPopup& popup);
664 * Called in OnKeyEvent to handle key down events.
665 * @param[in] event The KeyEvent event.
666 * @return True if the event should be consumed.
668 bool OnKeyDownEvent(const KeyEvent& event);
671 * Called in OnKeyEvent to handle key up events.
672 * @param[in] event The KeyEvent event.
673 * @return True if the event should be consumed.
675 bool OnKeyUpEvent(const KeyEvent& event);
678 * Callback called when the text-view is scrolled.
680 * Updates the selection and grab handles, and the highlighted text.
682 * @param[in] textView Handle of the text-view.
683 * @param[in] scrollPosition The difference with the previous scroll position.
685 void OnTextViewScrolled( Toolkit::TextView textView, Vector2 scrollPosition );
688 * Scrolls the text-view to make the cursor visible.
690 * @param[in] cursorPosition The actual cursor position in actor coordinates.
692 void ScrollTextViewToMakeCursorVisible( const Vector3& cursorPosition );
695 * Creates and starts a timer to scroll the text when handles are close to the edges of the text-input.
697 * It only starts the timer if it's already created.
699 void StartScrollTimer();
702 * Stops the timer used to scroll the text.
704 void StopScrollTimer();
707 * Callback called by the timer used to scroll the text.
709 * It calculates and sets a new scroll position.
711 bool OnScrollTimerTick();
713 public: // Public to allow internal testing.
716 * Register for touch events
718 void SetUpTouchEvents();
721 * Sets up TextView Actor
723 void CreateTextViewActor();
726 * Set Styled Text for text input.
727 * @param[in] styleText The new styled text for the text input.
729 void SetText( const MarkupProcessor::StyledTextArray& styleText );
732 * Start a timer to signal cursor to blink.
734 void StartCursorBlinkTimer();
737 * Stop the timer signalling the cursor to blink.
739 void StopCursorBlinkTimer();
742 * Starts input, setting focus and showing keyboard..
744 void StartEditMode();
747 * Called when End of input and focus no longer required, keyboard is hidden.
752 * Applies a style to the current pre-edit / predicted word to show it is being edited.
753 * @param[in] preEditStartPosition position in text array that the predicted word starts at
754 * @param[in] preEditStringLength used to calculate how many characters need their style changed.
756 void ApplyPreEditStyle( std::size_t preEditStartPosition, std::size_t preEditStringLength );
759 * Restores style to value before applying Pre-Edit style.
761 void RemovePreEditStyle();
764 * Event received from IMF manager
765 * @return ImfCallbackData data struture undicating if update is needed, cursor position and current text
767 ImfManager::ImfCallbackData ImfEventReceived( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& test );
770 * Called when the OnKey event is a Pre-edit string
771 * @param[in] keyString String received in Pre-edit
772 * @param[in] cursorOffset the cursor offset from where the pre-edit word starts
773 * @return bool true if preedit reset is required.
775 bool PreEditReceived( const std::string& keyString, std::size_t cursorOffset );
778 * Called when the OnKey event is a Commit string
779 * @param[in] keyString String received in Comment
780 * @return update flag to trigger cursor update of TextInput only when needed.
782 bool CommitReceived( const std::string& keyString );
785 * Deletes Pre-edit string
786 * By default it doesn't update the character's size and position table, which is a costly
787 * operation. As in many cases deletion and insertion (InsertAt) of text
788 * occurs in the same action i.e. preedit/commit. It makes sense to
789 * delete without updating, and then insert with updating.
791 * @return The number of characters to be deleted.
793 std::size_t DeletePreEdit();
796 * Reset all pre-edit flag and signal IMF keyboard that the current pre-edit word has been comitted.
797 * This may be due to the cursor being moved by user or reached the max character limit.
798 * @param[in] preserveCursorPosition Set true to keep cursor in current position, eg. touch event caused cursor to move.
800 void PreEditReset( bool preserveCursorPosition );
803 * Called after cursor position needs updating.
804 * Redraws cursor and notifies VirtualKeyboard
809 * Delete highlighted characters
810 * @param[in] inheritStyle Whether style from previous character in the string should be inherited.
812 void DeleteHighlightedText( bool inheritStyle );
815 * Delete range of characters
816 * @param[in] start position of characters to delete
817 * @param[in] ncharacters number of characters to delete
819 void DeleteRange(std::size_t start, std::size_t ncharacters);
822 * Delete character at current cursor position and redisplay
823 * @param[in] positionToDelete position of character to delete
825 void DeleteCharacter( std::size_t positionToDelete );
828 * Add or replaces characters to currently displayed string at cursor position
829 * By default it doesn't update the character's size and position table, which is a costly
830 * operation. As in many cases deletion and insertion (InsertAt) of text
831 * occurs in the same action i.e. preedit/commit. It makes sense to
832 * delete without updating, and then insert with updating.
833 * @param[in] newText string to add to TextInput display string.
834 * @param[in] insertionPosition position to insert at.
835 * @param[in] numberOfCharactersToReplace The number of characters to replace.
836 * @return number of characters to offset the cursor by.
838 std::size_t InsertAt( const Text& newText, const std::size_t insertionPosition, const std::size_t numberOfCharactersToReplace );
841 * Creates a cursor from the supplied image
842 * @param[in] cursorImage the image to be used for the cursor.
843 * @param[in] border the nine patch border corresponding to the supplied image.
844 * @return the image actor to be used as the cursor.
846 ImageActor CreateCursor( Image cursorImage, const Vector4& border );
849 * Moves cursor to the right
850 * param[in] reverse if true then cursor moves in the reverse direction (to the left)
851 * param[in] places number of character cursor should move.
853 void AdvanceCursor(bool reverse = false, std::size_t places = 1);
856 * Draw a cursor / caret at position where new text should appear
857 * @param[in] nthChar the position along the text string in which new text should appear.
859 void DrawCursor(const std::size_t nthChar = 0);
862 * Sets cursor visibility
863 * This sets visibility of the cursor. Which is comprised of 2
864 * cursors. The conventional cursor, and the alternate (RTL) cursor,
865 * which only appears when the cursor is at a character that can have
866 * a character appended to different visual positions depending on whether that
867 * character to be appended is RTL or LTR.
868 * @param[in] visible true - enable visibility for cursor, false - disable visiblity for cursor
870 void SetCursorVisibility( bool visible );
873 * Sets alternate cursor enable state
874 * @see SetCursorVisibility
875 * alternate cursor will only be visible if both SetCursorVisiblity
876 * and cursor enabled have been set to true.
878 void SetAltCursorEnabled( bool enabled );
881 * Create the grab handle that positions the cursor
882 * @param[in] image to be used for grab handle
885 void CreateGrabHandle(Image image=Image());
888 * Create Grab area to be used by Grab Handle
890 void CreateGrabArea( Actor& parent);
893 * Move grab handle to the required character position
895 * @param[in] displacement Displacement of the grab handle in actor coordinates.
897 * @return The new actual position the handle has been set to.
899 Vector3 MoveGrabHandle( const Vector2& displacement );
902 * Show or hide the grab handle without baking the visibility flag.
903 * Used when the Grab handle needs to be invisible due to text-view scrolling making it out of view
905 * @param[in] visible bool flag to set as true is grab handle should be shown, else false to hide.
907 void ShowGrabHandle( bool visible );
910 * Show or hide the grab handle and bake the visibility flag.
911 * 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.
912 * Calls ShowGrabHandle.
914 * @param[in] visible bool flag to set as true is grab handle should be shown, else false to hide.
916 void ShowGrabHandleAndSetVisibility( bool visible );
918 /* Boundary Property Notifications when handle exceed bounding box*/
921 * PropertyNotification Callback when left boundary exceeded so handle can be flipped.
922 * @param[in] source PropertyNotification
924 void OnLeftBoundaryExceeded( PropertyNotification& source );
926 * PropertyNotification Callback when within left boundary so handle can be flipped back.
927 * @param[in] source PropertyNotification
929 void OnReturnToLeftBoundary( PropertyNotification& source );
931 * PropertyNotification Callback when right boundary exceeded so handle can be flipped.
932 * @param[in] source PropertyNotification
934 void OnRightBoundaryExceeded( PropertyNotification& source );
936 * * PropertyNotification Callback when within right boundary so handle can be flipped back.
937 * @param[in] source PropertyNotification
939 void OnReturnToRightBoundary( PropertyNotification& source );
942 * PropertyNotification Callbacks for hiding handle one when it exceeds boundary.
943 * @param[in] source PropertyNotification
945 void OnHandleOneLeavesBoundary( PropertyNotification& source );
947 * PropertyNotification Callbacks for showing hidden handle one when returns within boundary
948 * @param[in] source PropertyNotification
950 void OnHandleOneWithinBoundary( PropertyNotification& source );
952 * PropertyNotification Callbacks for hiding handle two it when exceeds boundary.
953 * @param[in] source PropertyNotification
955 void OnHandleTwoLeavesBoundary( PropertyNotification& source );
957 * PropertyNotification Callbacks for showing hidden handle two when returns within boundary
958 * * @param[in] source PropertyNotification
960 void OnHandleTwoWithinBoundary( PropertyNotification& source );
963 * Set up property notifications on the position of the handles to facilitate flipping and hiding when at screen boundary.
965 void SetUpHandlePropertyNotifications();
968 * Create the selection handles that bound text to be selected for copy/cut.
969 * @param[in] start initial position of start selection handle.
970 * @param[in] end initial position of end selection handle.
971 * @param[in] handleOneImage (optional) to be used for selection handle
972 * @param[in] handleTwoImage (optional) to be used for selection handle
974 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() );
977 * Move the selection handles to required positions in text.
979 * @param[in] handleId the handle to position
980 * @param[in] displacement Displacement of the selection handle in actor coordinates.
982 * @return The new actual position the handle has been set to.
984 Vector3 MoveSelectionHandle(SelectionHandleId handleId, const Vector2& displacement);
987 * Calculate and position the specified selection handle the given index position
989 * @param[in] handleId the handle to position
991 void SetSelectionHandlePosition(SelectionHandleId handleId);
994 * Gets the visual position of a logical position.
995 * @note This is preferred over directly accessing the Map, as it resolves visual
996 * positions outside of the character map range.
997 * @param[in] logicalPosition The logical position
998 * @return Visual position is returned.
1000 std::size_t GetVisualPosition(std::size_t logicalPosition) const;
1003 * Gets a table of the visual text positions which has a flag
1004 * for each Character. The flag is either true (character selected)
1005 * or false (character deselected)
1006 * @note startSelection can be greater or less than endSelection
1008 * @param[in,out] selectedVisualText The vector to be resized and populated with the selected flags
1009 * @param[in] startSelection The start selection point for the text
1010 * @param[in] endSelection The end selection point for the text
1012 void GetVisualTextSelection(std::vector<bool>& selectedVisualText, std::size_t startSelection, std::size_t endSelection);
1015 * Iterates between selection handles and computes the info required to build the highlight mesh
1017 HighlightInfo CalculateHighlightInfo();
1020 * Calculates new Mesh data so highlight moves with selection handles.
1022 void UpdateHighlight();
1025 * Removes popup, and its options.
1030 * Adds a popup option.
1031 * @note Creates popup frame if not already created.
1032 * @param[in] name The unique name for this option.
1033 * @param[in] caption The caption (label) for this option
1034 * @param[in] icon the image icon to be displayed for this option
1035 * @param[in] finalOption Flag to indicate that this is the final option.
1036 * (set to true on the last option you add)
1038 void AddPopupOption(const std::string& name, const std::string& caption, const Image icon, bool finalOption = false);
1041 * Sets popup position
1042 * @param[in] position The actual position for this popup.
1044 void SetPopupPosition(const Vector3& position);
1048 * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
1049 * @param[in] signalFinished (optional) whether to perform an animation finish operation after the hide animation completes. Requires animate to be true.
1051 void HidePopup( bool animate = true, bool signalFinished = true );
1055 * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
1057 void ShowPopup(bool animate = true);
1060 * Shows the cut-copy-paste popup
1062 void ShowPopupCutCopyPaste();
1065 * Setup the selection popup and clipboard if relevant so the correct options are shown when ShowPopup is called.
1067 void SetUpPopUpSelection();
1070 * Return the logical index containing the character position closest to the source.
1071 * Used for positioning the grab handle at characters when dragged along.
1072 * Two different behaviours are needed in case the source point doesn't actually touch a
1073 * character. @see TouchToIndex.
1074 * @param[in] source float to match against
1075 * @param[out] closestIndex index to the vector of character's size and position.
1076 * @return \e true if the source point is actually inside the geometry provided by TextView.
1078 bool ReturnClosestIndex(const Vector2& source, std::size_t& closestIndex );
1081 * Returns the X-position of the current line justification
1082 * (relative to left of text-view container)
1083 * @return X position for line justification
1085 float GetLineJustificationPosition() const;
1088 * Currently the cursor is positioned at the previous characters position plus it's width.
1089 * If the previous character is on a different line then this function returns the correct position.
1090 * @param[in] characterPosition the character position index that the cursor should be at
1091 * @return position of cursor/handle
1093 Vector3 PositionCursorAfterWordWrap( std::size_t characterPosition ) const;
1097 * Return a vector which is the actual position for the given character position
1098 * The character position is where a cursor would be position for that character.
1099 * @param[in] characterPosition the logical (input) position in the 'string' of characters.
1101 * @return Vector3 the actual x,y,z position
1103 Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition ) const;
1106 * Return a vector which is the actual position for the given character position
1107 * The character position is where a cursor would be positioned for that character to be inserted.
1108 * An additional alternatePosition is also set in circumstances where the possible writing
1109 * of characters would be in the opposite direction.
1110 * e.g. "HelloشقشلاهؤEnglish"
1113 * [*] - Primary actual position for cursor i.e. continuing writing LTR (English)
1114 * [+] - Alternate actual position for cursor i.e. writing RTL (Arabic)
1116 * @param[in] characterPosition the logical (input) position in the 'string' of characters.
1117 * @param[out] directionRTL Whether the actual x,y,z position is after LTR (false) or RTL (true) text.
1118 * @param[out] alternatePosition the actual x,y,z position of the cursor if user types
1119 * in alternate direction to current flow of text.
1120 * @param[out] alternatePositionValid whether this alternate position is valid.
1121 * @return Vector3 the actual x,y,z position
1123 Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition, bool& directionRTL, Vector3& alternatePosition, bool& alternatePositionValid ) const;
1126 * Retrieve the character position of the first character on the row of text
1127 * that this character resides on.
1128 * @param[in] logicalPosition the position in the 'string' of characters.
1129 * @return logical character position of start of row.
1131 std::size_t GetRowStartFromCharacterPosition(std::size_t logicalPosition) const;
1134 * Retrieve the dimensions of this row of text that the character resides on.
1135 * @param[in] characterPosition the position in the 'string' of characters.
1136 * @return The size of the rectangle representing this row
1138 Size GetRowRectFromCharacterPosition(std::size_t characterPosition) const;
1141 * Retrieve the dimensions (and min-max) of this row of text that the character resides on.
1142 * @param[in] characterPosition the position in the 'string' of characters.
1143 * @param[out] min the top-left position of the rectangle representing this row
1144 * @param[out] max the bottom-right position of the rectangle representing this row
1145 * @return The size of the rectangle representing this row (max - min)
1147 Size GetRowRectFromCharacterPosition(std::size_t characterPosition, Vector2& min, Vector2& max) const;
1150 * Checks if the provided touchedActor was this text-input
1151 * @param[in] touchedActor the touched actor that will be checked against this text-input
1152 * @return true if the touchActor was the text-input or one of its children
1154 bool WasTouchedCheck( const Actor& touchedActor ) const;
1157 * Connect to the stage touch event
1159 void StartMonitoringStageForTouch();
1162 * Disconnect from the stage touch event
1164 void EndMonitoringStageForTouch();
1167 * Callback for when the screen is touched, this will be connected when selection starts and disconnected when it ends.
1168 * @param[in] event The touch event
1170 void OnStageTouched(const TouchEvent& event);
1174 * Select the text between the given values
1175 * @param[in] start position within array to start selection
1176 * @param[in] end position within array to end selection
1178 void SelectText(std::size_t start, std::size_t end);
1181 * Gets selected text and returns it as a StyleText vector
1182 * @return StyledText vector that is selected.
1184 MarkupProcessor::StyledTextArray GetSelectedText();
1187 * Applies the given style to all text, selected or not selected.
1188 * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
1190 void ApplyStyleToRange(const TextStyle& style, const TextStyle::Mask mask, const std::size_t begin, const std::size_t end);
1193 * Callback for when the keyboard status changes
1194 * @param[in] keyboardShown Whether the keyboard has just been shown or not.
1196 void KeyboardStatusChanged(bool keyboardShown);
1199 * Hide highlight shown between selection handles.
1201 void RemoveHighlight();
1204 * Highlights text that has been selected
1206 void CreateHighlight();
1209 * Copies selected text to clipboard
1210 * @return bool true if copy was successful.
1212 bool CopySelectedTextToClipboard();
1215 * Pastes the given text to currently displayed string at the current cursor position
1216 * @param[in] text Text to be pasted
1218 void PasteText( const Text& text );
1221 * Sets the direction of the text if it is empty.
1223 void SetTextDirection();
1226 * Updates the line height accordingly with the current text input style.
1228 void UpdateLineHeight();
1231 * Finds a visible character.
1233 * The \e direction parameters specifies from where to start to look for a visible character. \e Left means start by characters in lower
1234 * positions than \e cursorPosition, \e Right means start by characters in greater positions than \e cursorPosition and \e ByEnd starts
1235 * by the last characters.
1237 * If \e Left or \e Right is provided and any character is found, then looks in the other direction.
1239 * @param[in] direction Direction used to find a visible character.
1240 * @param[in] cursorPosition Starting position.
1242 * @return The found visible character.
1244 std::size_t FindVisibleCharacter( const FindVisibleCharacterDirection direction , const std::size_t cursorPosition ) const;
1247 * @copydoc SetSortModifier()
1249 void SetSortModifier( float depthOffset );
1252 * @copydoc SetSnapshotModeEnabled()
1254 void SetSnapshotModeEnabled( bool enable );
1257 * @copydoc IsSnapshotModeEnabled()
1259 bool IsSnapshotModeEnabled() const;
1262 * @copydoc SetScrollEnabled()
1264 void SetScrollEnabled( bool enable );
1267 * @copydoc IsScrollEnabled()
1269 bool IsScrollEnabled() const;
1272 * @copydoc SetScrollPosition()
1274 void SetScrollPosition( const Vector2& position );
1277 * @copydoc GetScrollPosition()
1279 Vector2 GetScrollPosition() const;
1282 * @brief Sets whether markup processing should be carried out.
1284 * @param[in] enable whether markup processing is carried out or not.
1286 void SetMarkupProcessingEnabled( bool enable );
1289 * @brief Returns whether markup processing is enabled or not
1291 * @return true is markup processing is enabled
1293 bool IsMarkupProcessingEnabled() const;
1296 * Insert or replaces the given text in the given position. It checks if the text exceeds the maximum allowed number of characters
1297 * and if it fits in the text-input's boundaries.
1299 * @param[in] text Text to be inserted.
1300 * @param[in] position Position where the text is inserted.
1301 * @param[in] numberOfCharactersToReplace The number of characters to replace.
1302 * @param[out] textExceedsMaximunNumberOfCharacters The number of characters that have been inserted.
1303 * @param[out] textExceedsBoundary Whether the inserted text has exceeded the boundaries of the text-input.
1305 * @return The number of characters that have been inserted.
1307 std::size_t DoInsertAt( const Text& text, std::size_t position, std::size_t numberOfCharactersToReplace, bool& textExceedsMaximunNumberOfCharacters, bool& textExceedsBoundary );
1310 * Retrieve Text-view's layout info.
1312 void GetTextLayoutInfo();
1315 * Emits the style changed signal.
1317 void EmitStyleChangedSignal();
1320 * Emits max input characters reached signal.
1322 void EmitMaxInputCharactersReachedSignal();
1325 * Emits a signal when the input text exceeds the boundaries of the text-input.
1327 void EmitInputTextExceedsBoundariesSignal();
1331 State mState; ///< Current State of Text input.
1332 MarkupProcessor::StyledTextArray mStyledText; ///< String currently displayed by TextView with style info.
1333 TextStyle mInputStyle; ///< Stores the current input style.
1334 float mLineHeight; ///< Stores the current line height accordingly with the input style.
1335 Toolkit::TextView mDisplayedTextView; ///< Actor which actually display text
1337 MarkupProcessor::StyledTextArray mStyledPlaceHolderText; ///< Text used as place holder with style info.
1339 std::size_t mMaxStringLength; ///< Max number of characters for string
1340 std::size_t mNumberOflinesLimit; ///< Limit on the number of lines this TextInput will display.
1342 ImageActor mCursor; ///< Cursor overlayed on Text to show where new text will be inserted
1343 ImageActor mCursorRTL; ///< Right To Left Cursor overlayed on Text (where new RTL text would be inserted)
1344 Animation mCursorAnimation; ///< animator for cursor blinking.
1345 std::size_t mCursorPosition; ///< position along string cursor is at.
1346 Timer mCursorBlinkTimer; ///< Timer to signal cursor to blink
1348 Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else.
1350 Image mGrabHandleImage; ///< image to be used for grab handle
1351 ImageActor mGrabHandle; ///< Handle used to move cursor for editing
1353 Actor mGrabArea; ///< invisible actor that receives pans events for the grab handle.
1354 PanGestureDetector mPanGestureDetector; ///< Pan gesture for handles
1355 TapGestureDetector mTapDetector; ///< used to start editing
1356 TapGestureDetector mDoubleTapDetector; ///< double tap detector
1358 Vector3 mActualGrabHandlePosition; ///< actual position of grab handle, this might not be snapped to a character
1360 LongPressGestureDetector mLongPressDetector; ///< Gesture to start selection
1362 /*Selection handles*/
1363 Image mSelectionHandleOneImage; ///< image used for selection handle one
1364 Image mSelectionHandleOneImagePressed; ///< image used for selection handle one pressed state
1365 Image mSelectionHandleTwoImage; ///< image used for selection handle two
1366 Image mSelectionHandleTwoImagePressed; ///< image used for selection handle two pressed state
1368 bool mIsSelectionHandleOneFlipped:1; ///< Flag to know whether the handle one is flipped or not.
1369 bool mIsSelectionHandleTwoFlipped:1; ///< Flag to know whether the handle two is flipped or not.
1370 Vector3 mSelectionHandleOneOffset; ///< Handle One's Offset
1371 Vector3 mSelectionHandleTwoOffset; ///< Handle Two's Offset
1372 Vector3 mSelectionHandleOneActualPosition; ///< Actual x y position of handle
1373 Vector3 mSelectionHandleTwoActualPosition; ///< Actual x y position of handle
1374 std::size_t mSelectionHandleOnePosition; ///< Position of handle along the string of text
1375 std::size_t mSelectionHandleTwoPosition; ///< Position of handle along the string of text
1376 ImageActor mSelectionHandleOne; ///< First selection handle used for selecting text to cut&paste
1377 ImageActor mSelectionHandleTwo; ///< Second selection handle used for selecting text to cut&paste
1378 Actor mHandleOneGrabArea; ///< invisible actor that receives pans events for the selection handle.
1379 Actor mHandleTwoGrabArea; ///< invisible actor that receives pans events for the selection handle.
1381 Mesh mHighlightMesh; ///< Mesh Data for highlight
1382 MeshActor mHighlightMeshActor; ///< Mesh Actor to display highlight
1383 MeshData mMeshData; ///< Container to hold meshData for highlight
1384 Material mCustomMaterial; ///< Custom material used for highlight
1385 HighlightInfo mNewHighlightInfo; ///< Geometry info to create highlight.
1387 Text mPreEditString; ///< Holds current input string prior to it being committed.
1388 std::size_t mPreEditStartPosition; ///< Cursor position for start of pre-edit string
1389 std::size_t mPreEditLength; ///< Cursor position for length of current pre-edit string after purging characters that do not fit.
1390 std::size_t mNumberOfSurroundingCharactersDeleted; ///< Stores the number of surrounding characters deleted.
1391 unsigned long mTouchStartTime; ///< Touch Start time (time in ms when down press began)
1393 Toolkit::TextView::TextLayoutInfo mTextLayoutInfo; ///< It contains a table layout info per character sorted by the character's visual index (retrieved from TextView),
1394 ///< a reorder map that stores each character's visual (output) index according to its logical (input) index,
1395 ///< a reorder map that stores each character's logical (input) index according to its visual (output) index,
1396 ///< the text size after layout and the scroll offset.
1398 MarkupProcessor::StyledTextArray mCurrentCopySelecton; ///< Array to store copied text.
1399 TextInputPopup mPopUpPanel; ///< Panel to house cut and paste, select all buttons.
1402 Vector2 mScrollDisplacement;
1403 Vector3 mCurrentHandlePosition;
1404 SelectionHandleId mCurrentSelectionId;
1405 Vector3 mCurrentSelectionHandlePosition;
1406 SelectionParameters mRequestedSelection;
1407 Vector4 mSelectionHandleFlipMargin;
1408 Vector4 mBoundingRectangleWorldCoordinates;
1410 Clipboard mClipboard; ///< Handle to clipboard
1412 bool mOverrideAutomaticAlignment:1; ///< Whether to override the alignment automatically set by the text content (e.g. european LTR or arabic RTL)
1413 bool mCursorRTLEnabled:1; ///< Enable state of Alternate RTL Cursor (need to keep track of this as it's not always enabled)
1414 bool mClosestCursorPositionEOL:1; ///< closest cursor position is end of line.
1415 bool mCursorBlinkStatus:1; ///< \e true shows the cursor, \e false hiddes it.
1417 bool mCursorVisibility:1; ///< Visibility status of Cursor
1418 bool mGrabHandleVisibility:1; ///< Visibility status of the grab handle.
1420 bool mIsCursorInScrollArea:1; ///< Whether the cursor is inside the boundaries of the text-input.
1421 bool mIsGrabHandleInScrollArea:1; ///< Whether the grab handle is inside the boundaries of the text-input.
1423 bool mEditModeActive:1; ///< true to indicate TextInput is in edit mode.
1424 bool mEditOnTouch:1; ///< true indicates edit mode starts by touching/tapping the TextInput
1425 bool mTextSelection:1; ///< true indicates text selection is enabled.
1426 bool mExceedEnabled:1; ///< Whether text-input editing text beyond its boundary is enabled or not. By default is enabled.
1427 bool mGrabHandleEnabled:1; ///< Flag to enable the grab handle instead of the default magnifier.
1428 bool mIsSelectionHandleFlipEnabled:1; ///< Flag to enable the selection handle flip
1430 bool mPreEditFlag:1; ///< Flag to indicate if key string received is still in pre-edit mode (Ecore IMF keyboard)
1431 bool mIgnoreCommitFlag:1; ///< Flag to indicate if the commit string should be ignored, maybe due to a keyboard reset.
1432 bool mIgnoreFirstCommitFlag:1; ///< Whether to ignore the first commit.
1433 bool mSelectingText:1; ///< Ignore surrounding text as selecting text
1435 bool mPreserveCursorPosition:1; ///< Indicates that the commit message is from a reset and does not require the cursor to be moved
1437 bool mSelectTextOnCommit:1;
1439 bool mUnderlinedPriorToPreEdit:1; ///< As predictive text adds underline style this flag enables us to revert back or keep underline.
1441 bool mCommitByKeyInput:1; ///< Set if a commit is done by key input rather than automatically (usually when a space bar or enter is pressed).
1443 bool mPlaceHolderSet:1; ///< Whether the place holder text is set.
1444 bool mMarkUpEnabled:1; ///< enable to scan for mark-up
1446 Toolkit::TextInput::InputSignalV2 mInputStartedSignalV2; ///< Signal emitted when input starts
1447 Toolkit::TextInput::InputSignalV2 mInputFinishedSignalV2; ///< Signal emitted when input ends
1448 Toolkit::TextInput::StyleChangedSignalV2 mStyleChangedSignalV2; ///< Signal emitted when style changes.
1449 Toolkit::TextInput::MaxInputCharactersReachedSignalV2 mMaxInputCharactersReachedSignalV2; ///< Signal emitted when max input characters is reached.
1450 Toolkit::TextInput::InputSignalV2 mCutAndPasteToolBarDisplayedV2; ///< Signal emitted when toolbar displayed
1451 Toolkit::TextInput::InputTextExceedBoundariesSignalV2 mInputTextExceedBoundariesSignalV2; ///< Signal emitted when input text exceeds the boundaries of the text-input.
1454 } // namespace Internal
1456 // Helpers for public-api forwarding methods
1458 inline Toolkit::Internal::TextInput& GetImpl(Toolkit::TextInput& textInput)
1460 DALI_ASSERT_ALWAYS(textInput);
1462 Dali::RefObject& handle = textInput.GetImplementation();
1464 return static_cast<Toolkit::Internal::TextInput&>(handle);
1467 inline const Toolkit::Internal::TextInput& GetImpl(const Toolkit::TextInput& textInput)
1469 DALI_ASSERT_ALWAYS(textInput);
1471 const Dali::RefObject& handle = textInput.GetImplementation();
1473 return static_cast<const Toolkit::Internal::TextInput&>(handle);
1476 } // namespace Toolkit
1480 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_H__