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
887 * Sets cursor visibility
888 * This sets visibility of the cursor. Which is comprised of 2
889 * cursors. The conventional cursor, and the alternate (RTL) cursor,
890 * which only appears when the cursor is at a character that can have
891 * a character appended to different visual positions depending on whether that
892 * character to be appended is RTL or LTR.
893 * @param[in] visible true - enable visibility for cursor, false - disable visiblity for cursor
895 void SetCursorVisibility( bool visible );
898 * Sets alternate cursor enable state
899 * @see SetCursorVisibility
900 * alternate cursor will only be visible if both SetCursorVisiblity
901 * and cursor enabled have been set to true.
903 void SetAltCursorEnabled( bool enabled );
906 * Create the grab handle that positions the cursor
907 * @param[in] image to be used for grab handle
910 void CreateGrabHandle(Image image=Image());
913 * Create Grab area to be used by Grab Handle
915 void CreateGrabArea( Actor& parent);
918 * Move grab handle to the required character position
920 * @param[in] displacement Displacement of the grab handle in actor coordinates.
922 * @return The new actual position the handle has been set to.
924 Vector3 MoveGrabHandle( const Vector2& displacement );
927 * Show or hide the grab handle without baking the visibility flag.
928 * Used when the Grab handle needs to be invisible due to text-view scrolling making it out of view
930 * @param[in] visible bool flag to set as true is grab handle should be shown, else false to hide.
932 void ShowGrabHandle( bool visible );
935 * Show or hide the grab handle and bake the visibility flag.
936 * 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.
937 * Calls ShowGrabHandle.
939 * @param[in] visible bool flag to set as true is grab handle should be shown, else false to hide.
941 void ShowGrabHandleAndSetVisibility( bool visible );
943 /* Boundary Property Notifications when handle exceed bounding box*/
946 * PropertyNotification Callback when left boundary exceeded so handle can be flipped.
947 * @param[in] source PropertyNotification
949 void OnLeftBoundaryExceeded( PropertyNotification& source );
951 * PropertyNotification Callback when within left boundary so handle can be flipped back.
952 * @param[in] source PropertyNotification
954 void OnReturnToLeftBoundary( PropertyNotification& source );
956 * PropertyNotification Callback when right boundary exceeded so handle can be flipped.
957 * @param[in] source PropertyNotification
959 void OnRightBoundaryExceeded( PropertyNotification& source );
961 * * PropertyNotification Callback when within right boundary so handle can be flipped back.
962 * @param[in] source PropertyNotification
964 void OnReturnToRightBoundary( PropertyNotification& source );
967 * PropertyNotification Callbacks for hiding handle one when it exceeds boundary.
968 * @param[in] source PropertyNotification
970 void OnHandleOneLeavesBoundary( PropertyNotification& source );
972 * PropertyNotification Callbacks for showing hidden handle one when returns within boundary
973 * @param[in] source PropertyNotification
975 void OnHandleOneWithinBoundary( PropertyNotification& source );
977 * PropertyNotification Callbacks for hiding handle two it when exceeds boundary.
978 * @param[in] source PropertyNotification
980 void OnHandleTwoLeavesBoundary( PropertyNotification& source );
982 * PropertyNotification Callbacks for showing hidden handle two when returns within boundary
983 * * @param[in] source PropertyNotification
985 void OnHandleTwoWithinBoundary( PropertyNotification& source );
988 * Set up property notifications on the position of the handles to facilitate flipping and hiding when at screen boundary.
990 void SetUpHandlePropertyNotifications();
993 * Create the selection handles that bound text to be selected for copy/cut.
994 * @param[in] start initial position of start selection handle.
995 * @param[in] end initial position of end selection handle.
996 * @param[in] handleOneImage (optional) to be used for selection handle
997 * @param[in] handleTwoImage (optional) to be used for selection handle
999 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() );
1002 * Move the selection handles to required positions in text.
1004 * @param[in] handleId the handle to position
1005 * @param[in] displacement Displacement of the selection handle in actor coordinates.
1007 * @return The new actual position the handle has been set to.
1009 Vector3 MoveSelectionHandle(SelectionHandleId handleId, const Vector2& displacement);
1012 * Calculate and position the specified selection handle the given index position
1014 * @param[in] handleId the handle to position
1016 void SetSelectionHandlePosition(SelectionHandleId handleId);
1019 * Gets a table of the visual text positions which has a flag
1020 * for each Character. The flag is either true (character selected)
1021 * or false (character deselected)
1022 * @note startSelection can be greater or less than endSelection
1024 * @param[in,out] selectedVisualText The vector to be resized and populated with the selected flags
1025 * @param[in] startSelection The start selection point for the text
1026 * @param[in] endSelection The end selection point for the text
1028 void GetVisualTextSelection(std::vector<bool>& selectedVisualText, std::size_t startSelection, std::size_t endSelection);
1031 * Iterates between selection handles and computes the info required to build the highlight mesh
1033 HighlightInfo CalculateHighlightInfo();
1036 * Calculates new Mesh data so highlight moves with selection handles.
1038 void UpdateHighlight();
1041 * Removes popup, and its options.
1046 * Adds Popup options which have been enabled.
1048 void AddPopupOptions();
1051 * Sets popup position
1052 * @param[in] position The actual position for this popup.
1053 * @param[in] alternativePosition Alternative popup position if no space in upper area.
1055 void SetPopupPosition(const Vector3& position, const Vector2& alternativePosition );
1059 * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
1060 * @param[in] signalFinished (optional) whether to perform an animation finish operation after the hide animation completes. Requires animate to be true.
1062 void HidePopup( bool animate = true, bool signalFinished = true );
1066 * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
1068 void ShowPopup(bool animate = true);
1071 * Shows the cut-copy-paste popup
1073 void ShowPopupCutCopyPaste();
1076 * Setup the selection popup and clipboard if relevant so the correct options are shown when ShowPopup is called.
1077 * @param[in] showCutButton Flag to show or hide cut button, in some cases like whitespace we do not want to cut just select.
1080 void SetUpPopupSelection( bool showCutButton = true );
1083 * Return the logical index containing the character position closest to the source.
1084 * Used for positioning the grab handle at characters when dragged along.
1085 * Two different behaviours are needed in case the source point doesn't actually touch a
1086 * character. @see TouchToIndex.
1087 * @param[in] source float to match against
1088 * @param[out] closestIndex index to the vector of character's size and position.
1089 * @return \e true if the source point is actually inside the geometry provided by TextView.
1091 bool ReturnClosestIndex(const Vector2& source, std::size_t& closestIndex );
1094 * Returns the X-position of the current line justification
1095 * (relative to left of text-view container)
1096 * @return X position for line justification
1098 float GetLineJustificationPosition() const;
1101 * Currently the cursor is positioned at the previous characters position plus it's width.
1102 * If the previous character is on a different line then this function returns the correct position.
1103 * @param[in] characterPosition the character position index that the cursor should be at
1104 * @return position of cursor/handle
1106 Vector3 PositionCursorAfterWordWrap( std::size_t characterPosition ) const;
1110 * Return a vector which is the actual position for the given character position
1111 * The character position is where a cursor would be position for that character.
1112 * @param[in] characterPosition the logical (input) position in the 'string' of characters.
1114 * @return Vector3 the actual x,y,z position
1116 Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition ) const;
1119 * Return a vector which is the actual position for the given character position
1120 * The character position is where a cursor would be positioned for that character to be inserted.
1121 * An additional alternatePosition is also set in circumstances where the possible writing
1122 * of characters would be in the opposite direction.
1123 * e.g. "HelloشقشلاهؤEnglish"
1126 * [*] - Primary actual position for cursor i.e. continuing writing LTR (English)
1127 * [+] - Alternate actual position for cursor i.e. writing RTL (Arabic)
1129 * @param[in] characterPosition the logical (input) position in the 'string' of characters.
1130 * @param[out] directionRTL Whether the actual x,y,z position is after LTR (false) or RTL (true) text.
1131 * @param[out] alternatePosition the actual x,y,z position of the cursor if user types
1132 * in alternate direction to current flow of text.
1133 * @param[out] alternatePositionValid whether this alternate position is valid.
1134 * @return Vector3 the actual x,y,z position
1136 Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition, bool& directionRTL, Vector3& alternatePosition, bool& alternatePositionValid ) const;
1139 * Retrieve the character position of the first character on the row of text
1140 * that this character resides on.
1141 * @param[in] logicalPosition the position in the 'string' of characters.
1142 * @return logical character position of start of row.
1144 std::size_t GetRowStartFromCharacterPosition(std::size_t logicalPosition) const;
1147 * Retrieves the first character of a group of characters with the same direction.
1149 * @param[in] logicalPosition Index to a character.
1151 * @return Index to the character.
1153 std::size_t GetFirstCharacterWithSameDirection( std::size_t logicalPosition ) const;
1156 * Retrieve the dimensions of this row of text that the character resides on.
1157 * @param[in] characterPosition the position in the 'string' of characters.
1158 * @return The size of the rectangle representing this row
1160 Size GetRowRectFromCharacterPosition(std::size_t characterPosition) const;
1163 * Retrieve the dimensions (and min-max) of this row of text that the character resides on.
1164 * @param[in] characterPosition the position in the 'string' of characters.
1165 * @param[out] min the top-left position of the rectangle representing this row
1166 * @param[out] max the bottom-right position of the rectangle representing this row
1167 * @return The size of the rectangle representing this row (max - min)
1169 Size GetRowRectFromCharacterPosition(std::size_t characterPosition, Vector2& min, Vector2& max) const;
1172 * Checks if the provided touchedActor was this text-input
1173 * @param[in] touchedActor the touched actor that will be checked against this text-input
1174 * @return true if the touchActor was the text-input or one of its children
1176 bool WasTouchedCheck( const Actor& touchedActor ) const;
1179 * Connect to the stage touch event
1181 void StartMonitoringStageForTouch();
1184 * Disconnect from the stage touch event
1186 void EndMonitoringStageForTouch();
1189 * Callback for when the screen is touched, this will be connected when selection starts and disconnected when it ends.
1190 * @param[in] event The touch event
1192 void OnStageTouched(const TouchEvent& event);
1196 * Select the text between the given values
1197 * @param[in] start position within array to start selection
1198 * @param[in] end position within array to end selection
1200 void SelectText(std::size_t start, std::size_t end);
1203 * Gets selected text and returns it as a StyleText vector
1204 * @return StyledText vector that is selected.
1206 MarkupProcessor::StyledTextArray GetSelectedText();
1209 * Applies the given style to all text, selected or not selected.
1210 * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
1212 void ApplyStyleToRange(const TextStyle& style, const TextStyle::Mask mask, const std::size_t begin, const std::size_t end);
1215 * Callback for when the keyboard status changes
1216 * @param[in] keyboardShown Whether the keyboard has just been shown or not.
1218 void KeyboardStatusChanged(bool keyboardShown);
1221 * Hide highlight shown between selection handles.
1222 * @param[in] hidePopup flag to hide the popup too, default is to hide popup.
1224 void RemoveHighlight( bool hidePopup = true );
1227 * Highlights text that has been selected
1229 void CreateHighlight();
1232 * Copies selected text to clipboard
1233 * @return bool true if copy was successful.
1235 bool CopySelectedTextToClipboard();
1238 * Pastes the given text to currently displayed string at the current cursor position
1239 * @param[in] text Text to be pasted
1241 void PasteText( const Text& text );
1244 * Sets the direction of the text if it is empty.
1246 void SetTextDirection();
1249 * Updates the line height accordingly with the current text input style.
1251 void UpdateLineHeight();
1254 * Finds a visible character.
1256 * The \e direction parameters specifies from where to start to look for a visible character. \e Left means start by characters in lower
1257 * positions than \e cursorPosition, \e Right means start by characters in greater positions than \e cursorPosition and \e ByEnd starts
1258 * by the last characters.
1260 * If \e Left or \e Right is provided and any character is found, then looks in the other direction.
1262 * @param[in] direction Direction used to find a visible character.
1263 * @param[in] cursorPosition Starting position.
1265 * @return The found visible character.
1267 std::size_t FindVisibleCharacter( const FindVisibleCharacterDirection direction , const std::size_t cursorPosition ) const;
1270 * @copydoc SetSortModifier()
1272 void SetSortModifier( float depthOffset );
1275 * @copydoc SetSnapshotModeEnabled()
1277 void SetSnapshotModeEnabled( bool enable );
1280 * @copydoc IsSnapshotModeEnabled()
1282 bool IsSnapshotModeEnabled() const;
1285 * @copydoc SetScrollEnabled()
1287 void SetScrollEnabled( bool enable );
1290 * @copydoc IsScrollEnabled()
1292 bool IsScrollEnabled() const;
1295 * @copydoc SetScrollPosition()
1297 void SetScrollPosition( const Vector2& position );
1300 * @copydoc GetScrollPosition()
1302 Vector2 GetScrollPosition() const;
1305 * @brief Sets whether markup processing should be carried out.
1307 * @param[in] enable whether markup processing is carried out or not.
1309 void SetMarkupProcessingEnabled( bool enable );
1312 * @brief Returns whether markup processing is enabled or not
1314 * @return true is markup processing is enabled
1316 bool IsMarkupProcessingEnabled() const;
1319 * Insert or replaces the given text in the given position. It checks if the text exceeds the maximum allowed number of characters
1320 * and if it fits in the text-input's boundaries.
1322 * @param[in] text Text to be inserted.
1323 * @param[in] position Position where the text is inserted.
1324 * @param[in] numberOfCharactersToReplace The number of characters to replace.
1325 * @param[out] textExceedsMaximunNumberOfCharacters The number of characters that have been inserted.
1326 * @param[out] textExceedsBoundary Whether the inserted text has exceeded the boundaries of the text-input.
1328 * @return The number of characters that have been inserted.
1330 std::size_t DoInsertAt( const Text& text, std::size_t position, std::size_t numberOfCharactersToReplace, bool& textExceedsMaximunNumberOfCharacters, bool& textExceedsBoundary );
1333 * Retrieve Text-view's layout info.
1335 void GetTextLayoutInfo();
1338 * Set the offset for positioning Popup from the TextInput
1339 * @param[in] offset in the order, left, top, right, bottom
1341 void SetOffsetFromText( const Vector4& offset );
1344 * Get the offset of the Popup from the TextInput
1345 * @return Vector4 with the offset in the order, left, top, right, bottom
1347 const Vector4& GetOffsetFromText() const;
1350 * Show the Placeholder text with an already created StyleTextArray
1351 * @param[in] stylePlaceHolderText Required placeholder text to be used
1353 void ShowPlaceholderText( const MarkupProcessor::StyledTextArray& stylePlaceHolderText );
1358 * Called when a property of an object of this type is set.
1359 * @param[in] object The object whose property is set.
1360 * @param[in] index The property index.
1361 * @param[in] value The new property value.
1363 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
1366 * Called to retrieve a property of an object of this type.
1367 * @param[in] object The object whose property is to be retrieved.
1368 * @param[in] index The property index.
1369 * @return The current value of the property.
1371 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
1374 * Emits the style changed signal.
1376 void EmitStyleChangedSignal();
1379 * Emit signal when text is modified.
1381 void EmitTextModified();
1384 * Emits max input characters reached signal.
1386 void EmitMaxInputCharactersReachedSignal();
1389 * Emits a signal when the input text exceeds the boundaries of the text-input.
1391 void EmitInputTextExceedsBoundariesSignal();
1395 State mState; ///< Current State of Text input.
1396 MarkupProcessor::StyledTextArray mStyledText; ///< String currently displayed by TextView with style info.
1397 TextStyle mInputStyle; ///< Stores the current input style.
1398 float mLineHeight; ///< Stores the current line height accordingly with the input style.
1399 Toolkit::TextView mDisplayedTextView; ///< Actor which actually display text
1401 MarkupProcessor::StyledTextArray mStyledPlaceHolderText; ///< Text used as place holder with style info.
1403 std::size_t mMaxStringLength; ///< Max number of characters for string
1404 std::size_t mNumberOflinesLimit; ///< Limit on the number of lines this TextInput will display.
1406 ImageActor mCursor; ///< Cursor overlayed on Text to show where new text will be inserted
1407 ImageActor mCursorRTL; ///< Right To Left Cursor overlayed on Text (where new RTL text would be inserted)
1408 Animation mCursorAnimation; ///< animator for cursor blinking.
1409 std::size_t mCursorPosition; ///< position along string cursor is at.
1410 Timer mCursorBlinkTimer; ///< Timer to signal cursor to blink
1412 Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else.
1414 Image mGrabHandleImage; ///< image to be used for grab handle
1415 ImageActor mGrabHandle; ///< Handle used to move cursor for editing
1417 Actor mGrabArea; ///< invisible actor that receives pans events for the grab handle.
1418 PanGestureDetector mPanGestureDetector; ///< Pan gesture for handles
1419 TapGestureDetector mTapDetector; ///< used to start editing
1420 TapGestureDetector mDoubleTapDetector; ///< double tap detector
1422 Vector3 mActualGrabHandlePosition; ///< actual position of grab handle, this might not be snapped to a character
1424 LongPressGestureDetector mLongPressDetector; ///< Gesture to start selection
1426 /*Selection handles*/
1427 Image mSelectionHandleOneImage; ///< image used for selection handle one
1428 Image mSelectionHandleOneImagePressed; ///< image used for selection handle one pressed state
1429 Image mSelectionHandleTwoImage; ///< image used for selection handle two
1430 Image mSelectionHandleTwoImagePressed; ///< image used for selection handle two pressed state
1432 bool mIsSelectionHandleOneFlipped:1; ///< Flag to know whether the handle one is flipped or not.
1433 bool mIsSelectionHandleTwoFlipped:1; ///< Flag to know whether the handle two is flipped or not.
1434 Vector3 mSelectionHandleOneOffset; ///< Handle One's Offset
1435 Vector3 mSelectionHandleTwoOffset; ///< Handle Two's Offset
1436 Vector3 mSelectionHandleOneActualPosition; ///< Actual x y position of handle
1437 Vector3 mSelectionHandleTwoActualPosition; ///< Actual x y position of handle
1438 std::size_t mSelectionHandleOnePosition; ///< Position of handle along the string of text
1439 std::size_t mSelectionHandleTwoPosition; ///< Position of handle along the string of text
1440 ImageActor mSelectionHandleOne; ///< First selection handle used for selecting text to cut&paste
1441 ImageActor mSelectionHandleTwo; ///< Second selection handle used for selecting text to cut&paste
1442 Actor mHandleOneGrabArea; ///< invisible actor that receives pans events for the selection handle.
1443 Actor mHandleTwoGrabArea; ///< invisible actor that receives pans events for the selection handle.
1445 Mesh mHighlightMesh; ///< Mesh Data for highlight
1446 MeshActor mHighlightMeshActor; ///< Mesh Actor to display highlight
1447 MeshData mMeshData; ///< Container to hold meshData for highlight
1448 Material mCustomMaterial; ///< Custom material used for highlight
1449 HighlightInfo mNewHighlightInfo; ///< Geometry info to create highlight.
1451 Text mPreEditString; ///< Holds current input string prior to it being committed.
1452 std::size_t mPreEditStartPosition; ///< Cursor position for start of pre-edit string
1453 std::size_t mPreEditLength; ///< Cursor position for length of current pre-edit string after purging characters that do not fit.
1454 std::size_t mNumberOfSurroundingCharactersDeleted; ///< Stores the number of surrounding characters deleted.
1455 unsigned long mTouchStartTime; ///< Touch Start time (time in ms when down press began)
1457 Toolkit::TextView::TextLayoutInfo mTextLayoutInfo; ///< It contains a table layout info per character sorted by the character's visual index (retrieved from TextView),
1458 ///< a reorder map that stores each character's visual (output) index according to its logical (input) index,
1459 ///< a reorder map that stores each character's logical (input) index according to its visual (output) index,
1460 ///< the text size after layout and the scroll offset.
1462 MarkupProcessor::StyledTextArray mCurrentCopySelecton; ///< Array to store copied text.
1463 TextInputPopup mPopupPanel; ///< Panel to house cut and paste, select all buttons.
1466 Vector2 mScrollDisplacement;
1467 Vector3 mCurrentHandlePosition;
1468 SelectionHandleId mCurrentSelectionId;
1469 Vector3 mCurrentSelectionHandlePosition;
1470 SelectionParameters mRequestedSelection;
1471 Vector4 mSelectionHandleFlipMargin;
1472 Vector4 mBoundingRectangleWorldCoordinates;
1474 Clipboard mClipboard; ///< Handle to clipboard
1477 Vector4 mMaterialColor; // Color of the highlight
1478 Vector4 mPopupOffsetFromText; // Offset of Popup from the TextInput.
1480 bool mOverrideAutomaticAlignment:1; ///< Whether to override the alignment automatically set by the text content (e.g. european LTR or arabic RTL)
1481 bool mCursorRTLEnabled:1; ///< Enable state of Alternate RTL Cursor (need to keep track of this as it's not always enabled)
1482 bool mClosestCursorPositionEOL:1; ///< closest cursor position is end of line.
1483 bool mCursorBlinkStatus:1; ///< \e true shows the cursor, \e false hiddes it.
1485 bool mCursorVisibility:1; ///< Visibility status of Cursor
1486 bool mGrabHandleVisibility:1; ///< Visibility status of the grab handle.
1488 bool mIsCursorInScrollArea:1; ///< Whether the cursor is inside the boundaries of the text-input.
1489 bool mIsGrabHandleInScrollArea:1; ///< Whether the grab handle is inside the boundaries of the text-input.
1491 bool mEditModeActive:1; ///< true to indicate TextInput is in edit mode.
1492 bool mEditOnTouch:1; ///< true indicates edit mode starts by touching/tapping the TextInput
1493 bool mTextSelection:1; ///< true indicates text selection is enabled.
1494 bool mExceedEnabled:1; ///< Whether text-input editing text beyond its boundary is enabled or not. By default is enabled.
1495 bool mGrabHandleEnabled:1; ///< Flag to enable the grab handle instead of the default magnifier.
1496 bool mIsSelectionHandleFlipEnabled:1; ///< Flag to enable the selection handle flip
1498 bool mPreEditFlag:1; ///< Flag to indicate if key string received is still in pre-edit mode (Ecore IMF keyboard)
1499 bool mIgnoreCommitFlag:1; ///< Flag to indicate if the commit string should be ignored, maybe due to a keyboard reset.
1500 bool mIgnoreFirstCommitFlag:1; ///< Whether to ignore the first commit.
1501 bool mSelectingText:1; ///< Ignore surrounding text as selecting text
1503 bool mPreserveCursorPosition:1; ///< Indicates that the commit message is from a reset and does not require the cursor to be moved
1505 bool mSelectTextOnCommit:1;
1507 bool mUnderlinedPriorToPreEdit:1; ///< As predictive text adds underline style this flag enables us to revert back or keep underline.
1509 bool mCommitByKeyInput:1; ///< Set if a commit is done by key input rather than automatically (usually when a space bar or enter is pressed).
1511 bool mPlaceHolderSet:1; ///< Whether the place holder text is set.
1512 bool mMarkUpEnabled:1; ///< enable to scan for mark-up
1514 Toolkit::TextInput::InputSignalV2 mInputStartedSignalV2; ///< Signal emitted when input starts
1515 Toolkit::TextInput::InputSignalV2 mInputFinishedSignalV2; ///< Signal emitted when input ends
1516 Toolkit::TextInput::StyleChangedSignalV2 mStyleChangedSignalV2; ///< Signal emitted when style changes.
1517 Toolkit::TextInput::TextModifiedSignalType mTextModifiedSignal; ///< Signal emitted when text modified.
1518 Toolkit::TextInput::MaxInputCharactersReachedSignalV2 mMaxInputCharactersReachedSignalV2; ///< Signal emitted when max input characters is reached.
1519 Toolkit::TextInput::InputSignalV2 mCutAndPasteToolBarDisplayedV2; ///< Signal emitted when toolbar displayed
1520 Toolkit::TextInput::InputTextExceedBoundariesSignalV2 mInputTextExceedBoundariesSignalV2; ///< Signal emitted when input text exceeds the boundaries of the text-input.
1523 } // namespace Internal
1525 // Helpers for public-api forwarding methods
1527 inline Toolkit::Internal::TextInput& GetImpl(Toolkit::TextInput& textInput)
1529 DALI_ASSERT_ALWAYS(textInput);
1531 Dali::RefObject& handle = textInput.GetImplementation();
1533 return static_cast<Toolkit::Internal::TextInput&>(handle);
1536 inline const Toolkit::Internal::TextInput& GetImpl(const Toolkit::TextInput& textInput)
1538 DALI_ASSERT_ALWAYS(textInput);
1540 const Dali::RefObject& handle = textInput.GetImplementation();
1542 return static_cast<const Toolkit::Internal::TextInput&>(handle);
1545 } // namespace Toolkit
1549 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_H__