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/adaptor-framework/common/imf-manager.h>
30 #include <dali/public-api/geometry/mesh.h>
44 typedef IntrusivePtr<TextInput> TextInputPtr;
46 class TextInput : public Control
53 TEXTINPUT_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
54 TEXTINPUT_PROPERTY_END_INDEX = TEXTINPUT_PROPERTY_START_INDEX + 512 ///< Reserving property indices
58 * Create a new TextInput
59 * @return instrusive ptr to a TextInput
61 static Dali::Toolkit::TextInput New();
64 * @copydoc Toolkit::TextInput::GetText
66 std::string GetText() const;
69 * @copydoc Toolkit::TextInput::GetMarkupText()
71 std::string GetMarkupText() const;
74 * @copydoc Toolkit::TextInput::SetPlaceholderText
76 void SetPlaceholderText( const std::string& placeHolderText );
79 * @copydoc Toolkit::TextInput::SetPlaceholderText
81 std::string GetPlaceholderText();
84 * @copydoc Toolkit::TextInput::SetInitialText
86 void SetInitialText(const std::string& initialText);
89 * set the text to be displayed in text-input, will overwrite any existing text.
90 * can be used to clear the text-input by passing an empty string.
91 * @param [in] initialText text to be initially displayed
93 void SetText(const std::string& initialText);
96 * @copydoc Toolkit::TextInput::SetMaxCharacterLength
98 void SetMaxCharacterLength(std::size_t maxChars);
101 * @copydoc Toolkit::TextInput::SetNumberOfLinesLimit
103 void SetNumberOfLinesLimit(std::size_t maxLines);
106 * @copydoc Toolkit::TextInput::GetNumberOfLinesLimit
108 std::size_t GetNumberOfLinesLimit() const;
111 * @copydoc Toolkit::TextInput::GetFont
113 Font GetFont() const;
116 * @copydoc Toolkit::TextInput::SetFont
118 void SetFont(Font font);
121 * @copydoc Toolkit::TextInput::InputStartedSignal()
123 Toolkit::TextInput::InputSignalV2& InputStartedSignal();
126 * @copydoc Toolkit::TextInput::InputFinishedSignal()
128 Toolkit::TextInput::InputSignalV2& InputFinishedSignal();
131 * @copydoc Toolkit::TextInput::CutAndPasteToolBarDisplayedSignal()
133 Toolkit::TextInput::InputSignalV2& CutAndPasteToolBarDisplayedSignal();
136 * @copydoc Toolkit::TextInput::StyleChangedSignal()
138 Toolkit::TextInput::StyleChangedSignalV2& StyleChangedSignal();
141 * @copydoc Toolkit::TextInput::TextModifiedSignal()
143 Toolkit::TextInput::TextModifiedSignalType& TextModifiedSignal();
146 * @copydoc Toolkit::TextInput::MaxInputCharactersReachedSignal()
148 Toolkit::TextInput::MaxInputCharactersReachedSignalV2& MaxInputCharactersReachedSignal();
151 * @copydoc Toolkit::TextInput::InputTextExceedBoundariesSignal()
153 Toolkit::TextInput::InputTextExceedBoundariesSignalV2& InputTextExceedBoundariesSignal();
156 * Connects a callback function with the object's signals.
157 * @param[in] object The object providing the signal.
158 * @param[in] tracker Used to disconnect the signal.
159 * @param[in] signalName The signal to connect to.
160 * @param[in] functor A newly allocated FunctorDelegate.
161 * @return True if the signal was connected.
162 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
164 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
167 * @see Toolkit::TextInput::SetEditMode(bool editMode)
168 * @see Toolkit::TextInput::SetEditMode(bool editMode, const Vector2& touchPoint)
170 * @param[in] editMode true or false to indicate editMode on or off.
171 * @param[in] setCursorOnTouchPoint Whether to use the touch point to set the cursor position.
172 * @param[in] touchPoint A position in actor coordinates within the text-input.
174 void SetEditable(bool editMode, bool setCursorOnTouchPoint, const Vector2& touchPoint = Vector2::ZERO);
177 * @copydoc Toolkit::TextInput::GetEditMode
179 bool IsEditable() const;
182 * @copydoc Toolkit::TextInput::SetTextSelectable
184 void SetTextSelectable(bool textSelectable = true);
187 * @copydoc Toolkit::TextInput::IsTextSelectable
189 bool IsTextSelectable() const;
192 * @copydoc Toolkit::TextInput::IsTextSelected
194 bool IsTextSelected() const;
197 * @copydoc Toolkit::TextInput::DeSelectText
202 * @copydoc Toolkit::TextInput::SetEditOnTouch
204 void SetEditOnTouch(bool editOnTouch);
207 * @copydoc Toolkit::TextInput::IsEditOnTouch
209 bool IsEditOnTouch() const;
212 * @copydoc Toolkit::TextInput::SetGrabHandleImage
214 void SetGrabHandleImage(Dali::Image image);
217 * @copydoc Toolkit::TextInput::SetCursorImage
219 void SetCursorImage(Dali::Image image, const Vector4& border );
222 * @copydoc Toolkit::TextInput::GetSelectionHandleSize
224 Vector3 GetSelectionHandleSize();
227 * @copydoc Toolkit::TextInput::SetRTLCursorImage
229 void SetRTLCursorImage(Dali::Image image, const Vector4& border );
232 * @copydoc Toolkit::TextInput::EnableGrabHandle
234 void EnableGrabHandle(bool toggle);
237 * @copydoc Toolkit::TextInput::IsGrabHandleEnabled
239 bool IsGrabHandleEnabled();
242 * @copydoc Toolkit::TextInput::EnableSelectionHandleFlip
244 void EnableSelectionHandleFlip( bool toggle );
247 * @copydoc Toolkit::TextInput::IsSelectionHandleFlipEnabled
249 bool IsSelectionHandleFlipEnabled();
252 * @copydoc Toolkit::TextInput::SetSelectionHandleFlipMargin
254 void SetSelectionHandleFlipMargin( const Vector4& margin );
257 * @copydoc Toolkit::TextInput::SetBoundingRectangle
259 void SetBoundingRectangle( const Rect<float>& boundingRectangle );
262 * @copydoc Toolkit::TextInput::GetBoundingRectangle
264 const Rect<float> GetBoundingRectangle() const;
267 * @copydoc Toolkit::TextInput::GetSelectionHandleFlipMargin
269 const Vector4& GetSelectionHandleFlipMargin();
272 * @copydoc Toolkit::TextInput::SetTextColor
274 void SetTextColor( const Vector4& color );
277 * @copydoc Toolkit::TextInput::SetActiveStyle
279 void SetActiveStyle( const TextStyle& style, const TextStyle::Mask mask );
282 * @copydoc Toolkit::TextInput::ApplyStyle
284 void ApplyStyle( const TextStyle& style, const TextStyle::Mask mask );
287 * @copydoc Toolkit::TextInput::ApplyStyleToAll
289 void ApplyStyleToAll( const TextStyle& style, const TextStyle::Mask mask );
292 * @copydoc Toolkit::TextInput::GetStyleAtCursor
294 TextStyle GetStyleAtCursor() const;
297 * Retrieves the character style for the given position.
298 * @param[in] position The character position which style is required.
299 * @return The style for the given position.
301 TextStyle GetStyleAt( std::size_t position ) const;
304 * @copydoc Toolkit::TextInput::SetTextAlignment()
306 void SetTextAlignment( Toolkit::Alignment::Type align );
309 * @copydoc Toolkit::TextInput::SetTextLineJustification()
311 void SetTextLineJustification( Toolkit::TextView::LineJustification justification );
314 * @copydoc Toolkit::TextInput::SetFadeBoundary()
316 void SetFadeBoundary( const Toolkit::TextView::FadeBoundary& fadeBoundary );
319 * @copydoc Toolkit::TextInput::GetFadeBoundary()
321 const Toolkit::TextView::FadeBoundary& GetFadeBoundary() const;
324 * @copydoc Toolkit::TextInput::GetTextAlignment()
326 Toolkit::Alignment::Type GetTextAlignment() const;
329 * @copydoc Toolkit::TextInput::SetMultilinePolicy()
331 void SetMultilinePolicy( Toolkit::TextView::MultilinePolicy policy );
334 * @copydoc Toolkit::TextInput::GetMultilinePolicy()
336 Toolkit::TextView::MultilinePolicy GetMultilinePolicy() const;
339 * @copydoc Toolkit::TextInput::SetWidthExceedPolicy()
341 void SetWidthExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
344 * @copydoc Toolkit::TextInput::GetWidthExceedPolicy()
346 Toolkit::TextView::ExceedPolicy GetWidthExceedPolicy() const;
349 * @copydoc Toolkit::TextInput::SetHeightExceedPolicy()
351 void SetHeightExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
354 * @copydoc Toolkit::TextInput::GetHeightExceedPolicy()
356 Toolkit::TextView::ExceedPolicy GetHeightExceedPolicy() const;
359 * @copydoc Toolkit::TextInput::SetExceedEnabled()
361 void SetExceedEnabled( bool enable );
364 * @copydoc Toolkit::TextInput::GetExceedEnabled()
366 bool GetExceedEnabled() const;
369 * @copydoc Toolkit::TextInput::SetBackground
371 void SetBackground(Dali::Image image );
374 * @copydoc Toolkit::TextInput::SetNumberOfLines
376 void SetNumberOfLines(std::size_t lines);
379 * @copydoc Toolkit::TextInput::GetNumberOfLines
381 std::size_t GetNumberOfLines();
384 * @copydoc Toolkit::TextInput::GetNumberOfCharacters
386 std::size_t GetNumberOfCharacters() const;
393 * Set the diffuse color for the highlight
394 * @param[in] color color to use
396 void SetMaterialDiffuseColor( const Vector4& color );
399 * Get the diffuse color used by the highlight
402 const Vector4& GetMaterialDiffuseColor() const;
407 * structure to hold each highlight box needed for text selection
411 Vector3 size; ///< size of the highlight box
412 Vector3 position; ///< position of highlight box
413 ImageActor highlightBoxActor; ///< as actor that is the highlight box
417 * structure to hold each character in displayed string and its position from the left
421 char character; ///< todo change to UTF to aid multi-language support
427 * structure to hold coordinates of each quad, which will make up the mesh.
429 struct QuadCoordinates
432 * Default constructor
440 * @param[in] x1 left co-ordinate
441 * @param[in] y1 top co-ordinate
442 * @param[in] x2 right co-ordinate
443 * @param[in] y2 bottom co-ordinate
445 QuadCoordinates(float x1, float y1, float x2, float y2)
451 Vector2 min; ///< top-left (minimum) position of quad
452 Vector2 max; ///< bottom-right (maximum) position of quad
455 typedef std::vector<QuadCoordinates> QuadContainer;
458 * structure for information required to build the highlight mesh
463 * Adds a Quad (2D rectangular sub-selection)
464 * @param[in] x1 left co-ordinate
465 * @param[in] y1 top co-ordinate
466 * @param[in] x2 right co-ordinate
467 * @param[in] y2 bottom co-ordinate
469 void AddQuad( float x1, float y1, float x2, float y2 );
472 * Clamps all quads to fit within a min -> max 2D boundary.
474 void Clamp2D(const Vector2& min, const Vector2& max);
476 QuadContainer mQuadList; ///< List of quads (sub-selections that form to create complete selection)
480 * Holds requested selection start and end points for highlighted text.
482 struct SelectionParameters
484 SelectionParameters( size_t start, size_t end )
485 : mStartOfSelection( start ), mEndOfSelection( end )
490 size_t mStartOfSelection;
491 size_t mEndOfSelection;
500 enum SelectionHandleId
502 HandleOne, ///< Selection handle one which is on the left
503 HandleTwo ///< Selection handle two which is on the right
507 * Two different behaviours are needed to convert a touch point into a character index.
508 * When a tap is received and the touch point doesn't hit any character, the final character selected might
509 * be different than the one selected if the event is a pan.
510 * i.e. If a tap is received and the touch point doesn't hit any character the expected position of the cursor
511 * would be the end or the beginning of a line. However, this behaviour would be weird while panning.
515 TapMode, ///< Touch point to character index conversion mode used for Tap events.
516 DragMode ///< Touch point to character index conversion mode used for Pan events.
520 * Used to set the direction when find the next visible character.
522 enum FindVisibleCharacterDirection
524 Left, ///< Find visible characters on the left.
525 Right, ///< Find visible characters on the right.
526 ByEnd ///< Start finding visible characters by the end.
532 virtual bool OnTouchEvent(const TouchEvent& event);
535 * From CustomActorImpl; called after the Text Input actor is touched
536 * @param[in] event The KeyEvent event.
537 * @return True if the event should be consumed.
539 virtual bool OnKeyEvent(const KeyEvent& event);
542 * From CustomActorImpl; called when this actor gains keyboard focus.
544 virtual void OnKeyInputFocusGained();
547 * From CustomActorImpl; called when this actor loses keyboard focus.
549 virtual void OnKeyInputFocusLost();
552 * From Control; called whenever the control is added to the stage.
554 virtual void OnControlStageConnection();
556 private: // From Control
559 * Creation of the layer that is used by top level active parts of the TextInput like handles
561 void CreateActiveLayer();
564 * @copydoc Control::OnInitialize()
566 virtual void OnInitialize();
569 * @copydoc Control::OnControlSizeSet()
571 virtual void OnControlSizeSet(const Vector3& targetSize);
574 * @copydoc Control::OnRelaidOut()
576 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
579 * Retrieves the text-input's natural size by calling TextView::GetNaturalSize().
581 * @return The natural size.
583 virtual Vector3 GetNaturalSize();
586 * Retrieves the text-input's \e height for a given \e width by calling TextView::GetHeightForWidth().
588 * @param[in] width The given \e width.
590 * @return The \e height for the given \e width.
592 virtual float GetHeightForWidth( float width );
597 * Construct a new TextInput.
602 * A reference counted object may only be deleted by calling Unreference()
604 virtual ~TextInput();
609 TextInput(const TextInput&);
612 TextInput& operator=(const TextInput& rhs);
615 * Callback when a handle is panned/moved, either selection handles or grab handle
616 * @param actor Handle of the selection or grab handle.
617 * @param gesture Data structure with the parameters of the gesture.
619 void OnHandlePan(Actor actor, PanGesture gesture);
622 * Callback for touch down on Grab handle
623 * @param[in] actor touched
624 * @param[in] touch touch event
626 bool OnPressDown(Dali::Actor actor, const TouchEvent& touch);
629 * Callback for touch down on Selection handle one
630 * @param[in] actor touched
631 * @param[in] touch touch event, used to determine if down or up event
633 bool OnHandleOneTouched(Dali::Actor actor, const TouchEvent& touch);
636 * Callback for touch down on Selection handle two
637 * @param[in] actor touched
638 * @param[in] touch touch event, used to determine if down or up event
640 bool OnHandleTwoTouched(Dali::Actor actor, const TouchEvent& touch);
643 * Callback for tap on TextInput
645 * @param[in] tap touch event
647 void OnTextTap(Dali::Actor actor, Dali::TapGesture tap);
650 * Callback for double tap on TextInput
652 * @param[in] tap touch event
654 void OnDoubleTap(Dali::Actor actor, Dali::TapGesture tap);
657 * Callback for long press on TextInput
659 * @param[in] longPress long press event
661 void OnLongPress(Dali::Actor actor, Dali::LongPressGesture longPress);
664 * Callback for the ClipboardEventNotifier when text is selected in the clipboard window.
665 * @param[in] notifier The Clipboard Event Notifier.
667 void OnClipboardTextSelected( ClipboardEventNotifier& notifier );
670 * Callback for when a button is pressed in popup panel
671 * @param[in] button handle to the button pressed.
673 bool OnPopupButtonPressed( Toolkit::Button button );
676 * Callback when handle timer ticks.
678 * Cursor should become visible/invisible to simulate blinking.
680 * @return True if the timer should be keep running.
682 bool OnCursorBlinkTimerTick();
685 * Invoked upon popup Hide animation completing.
686 * @note Only called for animating hide, not called for instantaneous (animate = false)
687 * @param[in] popup The popup which was hidden.
689 void OnPopupHideFinished(TextInputPopup& popup);
692 * Called in OnKeyEvent to handle key down events.
693 * @param[in] event The KeyEvent event.
694 * @return True if the event should be consumed.
696 bool OnKeyDownEvent(const KeyEvent& event);
699 * Called in OnKeyEvent to handle key up events.
700 * @param[in] event The KeyEvent event.
701 * @return True if the event should be consumed.
703 bool OnKeyUpEvent(const KeyEvent& event);
706 * Callback called when the text-view is scrolled.
708 * Updates the selection and grab handles, and the highlighted text.
710 * @param[in] textView Handle of the text-view.
711 * @param[in] scrollPosition The difference with the previous scroll position.
713 void OnTextViewScrolled( Toolkit::TextView textView, Vector2 scrollPosition );
716 * Scrolls the text-view to make the cursor visible.
718 * @param[in] cursorPosition The actual cursor position in actor coordinates.
720 void ScrollTextViewToMakeCursorVisible( const Vector3& cursorPosition );
723 * Creates and starts a timer to scroll the text when handles are close to the edges of the text-input.
725 * It only starts the timer if it's already created.
727 void StartScrollTimer();
730 * Stops the timer used to scroll the text.
732 void StopScrollTimer();
735 * Callback called by the timer used to scroll the text.
737 * It calculates and sets a new scroll position.
739 bool OnScrollTimerTick();
741 public: // Public to allow internal testing.
744 * Register for touch events
746 void SetUpTouchEvents();
749 * Sets up TextView Actor
751 void CreateTextViewActor();
754 * Set Styled Text for text input.
755 * @param[in] styleText The new styled text for the text input.
757 void SetText( const MarkupProcessor::StyledTextArray& styleText );
760 * Start a timer to signal cursor to blink.
762 void StartCursorBlinkTimer();
765 * Stop the timer signalling the cursor to blink.
767 void StopCursorBlinkTimer();
770 * Starts input, setting focus and showing keyboard..
772 void StartEditMode();
775 * Called when End of input and focus no longer required, keyboard is hidden.
780 * Applies a style to the current pre-edit / predicted word to show it is being edited.
781 * @param[in] preEditStartPosition position in text array that the predicted word starts at
782 * @param[in] preEditStringLength used to calculate how many characters need their style changed.
784 void ApplyPreEditStyle( std::size_t preEditStartPosition, std::size_t preEditStringLength );
787 * Restores style to value before applying Pre-Edit style.
789 void RemovePreEditStyle();
792 * Event received from IMF manager
793 * @return ImfCallbackData data struture undicating if update is needed, cursor position and current text
795 ImfManager::ImfCallbackData ImfEventReceived( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& test );
798 * Called when the OnKey event is a Pre-edit string
799 * @param[in] keyString String received in Pre-edit
800 * @param[in] cursorOffset the cursor offset from where the pre-edit word starts
801 * @return bool true if preedit reset is required.
803 bool PreEditReceived( const std::string& keyString, std::size_t cursorOffset );
806 * Called when the OnKey event is a Commit string
807 * @param[in] keyString String received in Comment
808 * @return update flag to trigger cursor update of TextInput only when needed.
810 bool CommitReceived( const std::string& keyString );
813 * Deletes Pre-edit string
814 * By default it doesn't update the character's size and position table, which is a costly
815 * operation. As in many cases deletion and insertion (InsertAt) of text
816 * occurs in the same action i.e. preedit/commit. It makes sense to
817 * delete without updating, and then insert with updating.
819 * @return The number of characters to be deleted.
821 std::size_t DeletePreEdit();
824 * Reset all pre-edit flag and signal IMF keyboard that the current pre-edit word has been comitted.
825 * This may be due to the cursor being moved by user or reached the max character limit.
826 * @param[in] preserveCursorPosition Set true to keep cursor in current position, eg. touch event caused cursor to move.
828 void PreEditReset( bool preserveCursorPosition );
831 * Called after cursor position needs updating.
832 * Redraws cursor and notifies VirtualKeyboard
837 * Delete highlighted characters
838 * @param[in] inheritStyle Whether style from previous character in the string should be inherited.
840 void DeleteHighlightedText( bool inheritStyle );
843 * Delete range of characters
844 * @param[in] start position of characters to delete
845 * @param[in] ncharacters number of characters to delete
847 void DeleteRange(std::size_t start, std::size_t ncharacters);
850 * Delete character at current cursor position and redisplay
851 * @param[in] positionToDelete position of character to delete
853 void DeleteCharacter( std::size_t positionToDelete );
856 * Add or replaces characters to currently displayed string at cursor position
857 * By default it doesn't update the character's size and position table, which is a costly
858 * operation. As in many cases deletion and insertion (InsertAt) of text
859 * occurs in the same action i.e. preedit/commit. It makes sense to
860 * delete without updating, and then insert with updating.
861 * @param[in] newText string to add to TextInput display string.
862 * @param[in] insertionPosition position to insert at.
863 * @param[in] numberOfCharactersToReplace The number of characters to replace.
864 * @return number of characters to offset the cursor by.
866 std::size_t InsertAt( const Text& newText, const std::size_t insertionPosition, const std::size_t numberOfCharactersToReplace );
869 * Creates a cursor from the supplied image
870 * @param[in] cursorImage the image to be used for the cursor.
871 * @param[in] border the nine patch border corresponding to the supplied image.
872 * @return the image actor to be used as the cursor.
874 ImageActor CreateCursor( Image cursorImage, const Vector4& border );
877 * Moves cursor to the right
878 * param[in] reverse if true then cursor moves in the reverse direction (to the left)
879 * param[in] places number of character cursor should move.
881 void AdvanceCursor(bool reverse = false, std::size_t places = 1);
884 * Draw a cursor / caret at position where new text should appear
885 * @param[in] nthChar the position along the text string in which new text should appear.
887 void DrawCursor(const std::size_t nthChar = 0);
890 * Sets cursor visibility
891 * This sets visibility of the cursor. Which is comprised of 2
892 * cursors. The conventional cursor, and the alternate (RTL) cursor,
893 * which only appears when the cursor is at a character that can have
894 * a character appended to different visual positions depending on whether that
895 * character to be appended is RTL or LTR.
896 * @param[in] visible true - enable visibility for cursor, false - disable visiblity for cursor
898 void SetCursorVisibility( bool visible );
901 * Sets alternate cursor enable state
902 * @see SetCursorVisibility
903 * alternate cursor will only be visible if both SetCursorVisiblity
904 * and cursor enabled have been set to true.
906 void SetAltCursorEnabled( bool enabled );
909 * Create the grab handle that positions the cursor
910 * @param[in] image to be used for grab handle
913 void CreateGrabHandle(Image image=Image());
916 * Create Grab area to be used by Grab Handle
918 void CreateGrabArea( Actor& parent);
921 * Move grab handle to the required character position
923 * @param[in] displacement Displacement of the grab handle in actor coordinates.
925 * @return The new actual position the handle has been set to.
927 Vector3 MoveGrabHandle( const Vector2& displacement );
930 * Show or hide the grab handle without baking the visibility flag.
931 * Used when the Grab handle needs to be invisible due to text-view scrolling making it out of view
933 * @param[in] visible bool flag to set as true is grab handle should be shown, else false to hide.
935 void ShowGrabHandle( bool visible );
938 * Show or hide the grab handle and bake the visibility flag.
939 * 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.
940 * Calls ShowGrabHandle.
942 * @param[in] visible bool flag to set as true is grab handle should be shown, else false to hide.
944 void ShowGrabHandleAndSetVisibility( bool visible );
946 /* Boundary Property Notifications when handle exceed bounding box*/
949 * PropertyNotification Callback when left boundary exceeded so handle can be flipped.
950 * @param[in] source PropertyNotification
952 void OnLeftBoundaryExceeded( PropertyNotification& source );
954 * PropertyNotification Callback when within left boundary so handle can be flipped back.
955 * @param[in] source PropertyNotification
957 void OnReturnToLeftBoundary( PropertyNotification& source );
959 * PropertyNotification Callback when right boundary exceeded so handle can be flipped.
960 * @param[in] source PropertyNotification
962 void OnRightBoundaryExceeded( PropertyNotification& source );
964 * * PropertyNotification Callback when within right boundary so handle can be flipped back.
965 * @param[in] source PropertyNotification
967 void OnReturnToRightBoundary( PropertyNotification& source );
970 * PropertyNotification Callbacks for hiding handle one when it exceeds boundary.
971 * @param[in] source PropertyNotification
973 void OnHandleOneLeavesBoundary( PropertyNotification& source );
975 * PropertyNotification Callbacks for showing hidden handle one when returns within boundary
976 * @param[in] source PropertyNotification
978 void OnHandleOneWithinBoundary( PropertyNotification& source );
980 * PropertyNotification Callbacks for hiding handle two it when exceeds boundary.
981 * @param[in] source PropertyNotification
983 void OnHandleTwoLeavesBoundary( PropertyNotification& source );
985 * PropertyNotification Callbacks for showing hidden handle two when returns within boundary
986 * * @param[in] source PropertyNotification
988 void OnHandleTwoWithinBoundary( PropertyNotification& source );
991 * Set up property notifications on the position of the handles to facilitate flipping and hiding when at screen boundary.
993 void SetUpHandlePropertyNotifications();
996 * Create the selection handles that bound text to be selected for copy/cut.
997 * @param[in] start initial position of start selection handle.
998 * @param[in] end initial position of end selection handle.
999 * @param[in] handleOneImage (optional) to be used for selection handle
1000 * @param[in] handleTwoImage (optional) to be used for selection handle
1002 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() );
1005 * Move the selection handles to required positions in text.
1007 * @param[in] handleId the handle to position
1008 * @param[in] displacement Displacement of the selection handle in actor coordinates.
1010 * @return The new actual position the handle has been set to.
1012 Vector3 MoveSelectionHandle(SelectionHandleId handleId, const Vector2& displacement);
1015 * Calculate and position the specified selection handle the given index position
1017 * @param[in] handleId the handle to position
1019 void SetSelectionHandlePosition(SelectionHandleId handleId);
1022 * Gets the visual position of a logical position.
1023 * @note This is preferred over directly accessing the Map, as it resolves visual
1024 * positions outside of the character map range.
1025 * @param[in] logicalPosition The logical position
1026 * @return Visual position is returned.
1028 std::size_t GetVisualPosition(std::size_t logicalPosition) const;
1031 * Gets a table of the visual text positions which has a flag
1032 * for each Character. The flag is either true (character selected)
1033 * or false (character deselected)
1034 * @note startSelection can be greater or less than endSelection
1036 * @param[in,out] selectedVisualText The vector to be resized and populated with the selected flags
1037 * @param[in] startSelection The start selection point for the text
1038 * @param[in] endSelection The end selection point for the text
1040 void GetVisualTextSelection(std::vector<bool>& selectedVisualText, std::size_t startSelection, std::size_t endSelection);
1043 * Iterates between selection handles and computes the info required to build the highlight mesh
1045 HighlightInfo CalculateHighlightInfo();
1048 * Calculates new Mesh data so highlight moves with selection handles.
1050 void UpdateHighlight();
1053 * Removes popup, and its options.
1058 * Adds Popup options which have been enabled.
1060 void AddPopupOptions();
1063 * Sets popup position
1064 * @param[in] position The actual position for this popup.
1066 void SetPopupPosition(const Vector3& position);
1070 * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
1071 * @param[in] signalFinished (optional) whether to perform an animation finish operation after the hide animation completes. Requires animate to be true.
1073 void HidePopup( bool animate = true, bool signalFinished = true );
1077 * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
1079 void ShowPopup(bool animate = true);
1082 * Shows the cut-copy-paste popup
1084 void ShowPopupCutCopyPaste();
1087 * Setup the selection popup and clipboard if relevant so the correct options are shown when ShowPopup is called.
1089 void SetUpPopupSelection();
1092 * Return the logical index containing the character position closest to the source.
1093 * Used for positioning the grab handle at characters when dragged along.
1094 * Two different behaviours are needed in case the source point doesn't actually touch a
1095 * character. @see TouchToIndex.
1096 * @param[in] source float to match against
1097 * @param[out] closestIndex index to the vector of character's size and position.
1098 * @return \e true if the source point is actually inside the geometry provided by TextView.
1100 bool ReturnClosestIndex(const Vector2& source, std::size_t& closestIndex );
1103 * Returns the X-position of the current line justification
1104 * (relative to left of text-view container)
1105 * @return X position for line justification
1107 float GetLineJustificationPosition() const;
1110 * Currently the cursor is positioned at the previous characters position plus it's width.
1111 * If the previous character is on a different line then this function returns the correct position.
1112 * @param[in] characterPosition the character position index that the cursor should be at
1113 * @return position of cursor/handle
1115 Vector3 PositionCursorAfterWordWrap( 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 position for that character.
1121 * @param[in] characterPosition the logical (input) position in the 'string' of characters.
1123 * @return Vector3 the actual x,y,z position
1125 Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition ) const;
1128 * Return a vector which is the actual position for the given character position
1129 * The character position is where a cursor would be positioned for that character to be inserted.
1130 * An additional alternatePosition is also set in circumstances where the possible writing
1131 * of characters would be in the opposite direction.
1132 * e.g. "HelloشقشلاهؤEnglish"
1135 * [*] - Primary actual position for cursor i.e. continuing writing LTR (English)
1136 * [+] - Alternate actual position for cursor i.e. writing RTL (Arabic)
1138 * @param[in] characterPosition the logical (input) position in the 'string' of characters.
1139 * @param[out] directionRTL Whether the actual x,y,z position is after LTR (false) or RTL (true) text.
1140 * @param[out] alternatePosition the actual x,y,z position of the cursor if user types
1141 * in alternate direction to current flow of text.
1142 * @param[out] alternatePositionValid whether this alternate position is valid.
1143 * @return Vector3 the actual x,y,z position
1145 Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition, bool& directionRTL, Vector3& alternatePosition, bool& alternatePositionValid ) const;
1148 * Retrieve the character position of the first character on the row of text
1149 * that this character resides on.
1150 * @param[in] logicalPosition the position in the 'string' of characters.
1151 * @return logical character position of start of row.
1153 std::size_t GetRowStartFromCharacterPosition(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.
1223 void RemoveHighlight();
1226 * Highlights text that has been selected
1228 void CreateHighlight();
1231 * Copies selected text to clipboard
1232 * @return bool true if copy was successful.
1234 bool CopySelectedTextToClipboard();
1237 * Pastes the given text to currently displayed string at the current cursor position
1238 * @param[in] text Text to be pasted
1240 void PasteText( const Text& text );
1243 * Sets the direction of the text if it is empty.
1245 void SetTextDirection();
1248 * Updates the line height accordingly with the current text input style.
1250 void UpdateLineHeight();
1253 * Finds a visible character.
1255 * The \e direction parameters specifies from where to start to look for a visible character. \e Left means start by characters in lower
1256 * positions than \e cursorPosition, \e Right means start by characters in greater positions than \e cursorPosition and \e ByEnd starts
1257 * by the last characters.
1259 * If \e Left or \e Right is provided and any character is found, then looks in the other direction.
1261 * @param[in] direction Direction used to find a visible character.
1262 * @param[in] cursorPosition Starting position.
1264 * @return The found visible character.
1266 std::size_t FindVisibleCharacter( const FindVisibleCharacterDirection direction , const std::size_t cursorPosition ) const;
1269 * @copydoc SetSortModifier()
1271 void SetSortModifier( float depthOffset );
1274 * @copydoc SetSnapshotModeEnabled()
1276 void SetSnapshotModeEnabled( bool enable );
1279 * @copydoc IsSnapshotModeEnabled()
1281 bool IsSnapshotModeEnabled() const;
1284 * @copydoc SetScrollEnabled()
1286 void SetScrollEnabled( bool enable );
1289 * @copydoc IsScrollEnabled()
1291 bool IsScrollEnabled() const;
1294 * @copydoc SetScrollPosition()
1296 void SetScrollPosition( const Vector2& position );
1299 * @copydoc GetScrollPosition()
1301 Vector2 GetScrollPosition() const;
1304 * @brief Sets whether markup processing should be carried out.
1306 * @param[in] enable whether markup processing is carried out or not.
1308 void SetMarkupProcessingEnabled( bool enable );
1311 * @brief Returns whether markup processing is enabled or not
1313 * @return true is markup processing is enabled
1315 bool IsMarkupProcessingEnabled() const;
1318 * Insert or replaces the given text in the given position. It checks if the text exceeds the maximum allowed number of characters
1319 * and if it fits in the text-input's boundaries.
1321 * @param[in] text Text to be inserted.
1322 * @param[in] position Position where the text is inserted.
1323 * @param[in] numberOfCharactersToReplace The number of characters to replace.
1324 * @param[out] textExceedsMaximunNumberOfCharacters The number of characters that have been inserted.
1325 * @param[out] textExceedsBoundary Whether the inserted text has exceeded the boundaries of the text-input.
1327 * @return The number of characters that have been inserted.
1329 std::size_t DoInsertAt( const Text& text, std::size_t position, std::size_t numberOfCharactersToReplace, bool& textExceedsMaximunNumberOfCharacters, bool& textExceedsBoundary );
1332 * Retrieve Text-view's layout info.
1334 void GetTextLayoutInfo();
1337 * Set the offset for positioning Popup from the TextInput
1338 * @param[in] offset in the order, left, top, right, bottom
1340 void SetOffsetFromText( const Vector4& offset );
1343 * Get the offset of the Popup from the TextInput
1344 * @return Vector4 with the offset in the order, left, top, right, bottom
1346 const Vector4& GetOffsetFromText() const;
1351 * Called when a property of an object of this type is set.
1352 * @param[in] object The object whose property is set.
1353 * @param[in] index The property index.
1354 * @param[in] value The new property value.
1356 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
1359 * Called to retrieve a property of an object of this type.
1360 * @param[in] object The object whose property is to be retrieved.
1361 * @param[in] index The property index.
1362 * @return The current value of the property.
1364 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
1367 * Emits the style changed signal.
1369 void EmitStyleChangedSignal();
1372 * Emit signal when text is modified.
1374 void EmitTextModified();
1377 * Emits max input characters reached signal.
1379 void EmitMaxInputCharactersReachedSignal();
1382 * Emits a signal when the input text exceeds the boundaries of the text-input.
1384 void EmitInputTextExceedsBoundariesSignal();
1388 State mState; ///< Current State of Text input.
1389 MarkupProcessor::StyledTextArray mStyledText; ///< String currently displayed by TextView with style info.
1390 TextStyle mInputStyle; ///< Stores the current input style.
1391 float mLineHeight; ///< Stores the current line height accordingly with the input style.
1392 Toolkit::TextView mDisplayedTextView; ///< Actor which actually display text
1394 MarkupProcessor::StyledTextArray mStyledPlaceHolderText; ///< Text used as place holder with style info.
1396 std::size_t mMaxStringLength; ///< Max number of characters for string
1397 std::size_t mNumberOflinesLimit; ///< Limit on the number of lines this TextInput will display.
1399 ImageActor mCursor; ///< Cursor overlayed on Text to show where new text will be inserted
1400 ImageActor mCursorRTL; ///< Right To Left Cursor overlayed on Text (where new RTL text would be inserted)
1401 Animation mCursorAnimation; ///< animator for cursor blinking.
1402 std::size_t mCursorPosition; ///< position along string cursor is at.
1403 Timer mCursorBlinkTimer; ///< Timer to signal cursor to blink
1405 Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else.
1407 Image mGrabHandleImage; ///< image to be used for grab handle
1408 ImageActor mGrabHandle; ///< Handle used to move cursor for editing
1410 Actor mGrabArea; ///< invisible actor that receives pans events for the grab handle.
1411 PanGestureDetector mPanGestureDetector; ///< Pan gesture for handles
1412 TapGestureDetector mTapDetector; ///< used to start editing
1413 TapGestureDetector mDoubleTapDetector; ///< double tap detector
1415 Vector3 mActualGrabHandlePosition; ///< actual position of grab handle, this might not be snapped to a character
1417 LongPressGestureDetector mLongPressDetector; ///< Gesture to start selection
1419 /*Selection handles*/
1420 Image mSelectionHandleOneImage; ///< image used for selection handle one
1421 Image mSelectionHandleOneImagePressed; ///< image used for selection handle one pressed state
1422 Image mSelectionHandleTwoImage; ///< image used for selection handle two
1423 Image mSelectionHandleTwoImagePressed; ///< image used for selection handle two pressed state
1425 bool mIsSelectionHandleOneFlipped:1; ///< Flag to know whether the handle one is flipped or not.
1426 bool mIsSelectionHandleTwoFlipped:1; ///< Flag to know whether the handle two is flipped or not.
1427 Vector3 mSelectionHandleOneOffset; ///< Handle One's Offset
1428 Vector3 mSelectionHandleTwoOffset; ///< Handle Two's Offset
1429 Vector3 mSelectionHandleOneActualPosition; ///< Actual x y position of handle
1430 Vector3 mSelectionHandleTwoActualPosition; ///< Actual x y position of handle
1431 std::size_t mSelectionHandleOnePosition; ///< Position of handle along the string of text
1432 std::size_t mSelectionHandleTwoPosition; ///< Position of handle along the string of text
1433 ImageActor mSelectionHandleOne; ///< First selection handle used for selecting text to cut&paste
1434 ImageActor mSelectionHandleTwo; ///< Second selection handle used for selecting text to cut&paste
1435 Actor mHandleOneGrabArea; ///< invisible actor that receives pans events for the selection handle.
1436 Actor mHandleTwoGrabArea; ///< invisible actor that receives pans events for the selection handle.
1438 Mesh mHighlightMesh; ///< Mesh Data for highlight
1439 MeshActor mHighlightMeshActor; ///< Mesh Actor to display highlight
1440 MeshData mMeshData; ///< Container to hold meshData for highlight
1441 Material mCustomMaterial; ///< Custom material used for highlight
1442 HighlightInfo mNewHighlightInfo; ///< Geometry info to create highlight.
1444 Text mPreEditString; ///< Holds current input string prior to it being committed.
1445 std::size_t mPreEditStartPosition; ///< Cursor position for start of pre-edit string
1446 std::size_t mPreEditLength; ///< Cursor position for length of current pre-edit string after purging characters that do not fit.
1447 std::size_t mNumberOfSurroundingCharactersDeleted; ///< Stores the number of surrounding characters deleted.
1448 unsigned long mTouchStartTime; ///< Touch Start time (time in ms when down press began)
1450 Toolkit::TextView::TextLayoutInfo mTextLayoutInfo; ///< It contains a table layout info per character sorted by the character's visual index (retrieved from TextView),
1451 ///< a reorder map that stores each character's visual (output) index according to its logical (input) index,
1452 ///< a reorder map that stores each character's logical (input) index according to its visual (output) index,
1453 ///< the text size after layout and the scroll offset.
1455 MarkupProcessor::StyledTextArray mCurrentCopySelecton; ///< Array to store copied text.
1456 TextInputPopup mPopupPanel; ///< Panel to house cut and paste, select all buttons.
1459 Vector2 mScrollDisplacement;
1460 Vector3 mCurrentHandlePosition;
1461 SelectionHandleId mCurrentSelectionId;
1462 Vector3 mCurrentSelectionHandlePosition;
1463 SelectionParameters mRequestedSelection;
1464 Vector4 mSelectionHandleFlipMargin;
1465 Vector4 mBoundingRectangleWorldCoordinates;
1467 Clipboard mClipboard; ///< Handle to clipboard
1470 Vector4 mMaterialColor; // Color of the highlight
1471 Vector4 mPopupOffsetFromText; // Offset of Popup from the TextInput.
1473 bool mOverrideAutomaticAlignment:1; ///< Whether to override the alignment automatically set by the text content (e.g. european LTR or arabic RTL)
1474 bool mCursorRTLEnabled:1; ///< Enable state of Alternate RTL Cursor (need to keep track of this as it's not always enabled)
1475 bool mClosestCursorPositionEOL:1; ///< closest cursor position is end of line.
1476 bool mCursorBlinkStatus:1; ///< \e true shows the cursor, \e false hiddes it.
1478 bool mCursorVisibility:1; ///< Visibility status of Cursor
1479 bool mGrabHandleVisibility:1; ///< Visibility status of the grab handle.
1481 bool mIsCursorInScrollArea:1; ///< Whether the cursor is inside the boundaries of the text-input.
1482 bool mIsGrabHandleInScrollArea:1; ///< Whether the grab handle is inside the boundaries of the text-input.
1484 bool mEditModeActive:1; ///< true to indicate TextInput is in edit mode.
1485 bool mEditOnTouch:1; ///< true indicates edit mode starts by touching/tapping the TextInput
1486 bool mTextSelection:1; ///< true indicates text selection is enabled.
1487 bool mExceedEnabled:1; ///< Whether text-input editing text beyond its boundary is enabled or not. By default is enabled.
1488 bool mGrabHandleEnabled:1; ///< Flag to enable the grab handle instead of the default magnifier.
1489 bool mIsSelectionHandleFlipEnabled:1; ///< Flag to enable the selection handle flip
1491 bool mPreEditFlag:1; ///< Flag to indicate if key string received is still in pre-edit mode (Ecore IMF keyboard)
1492 bool mIgnoreCommitFlag:1; ///< Flag to indicate if the commit string should be ignored, maybe due to a keyboard reset.
1493 bool mIgnoreFirstCommitFlag:1; ///< Whether to ignore the first commit.
1494 bool mSelectingText:1; ///< Ignore surrounding text as selecting text
1496 bool mPreserveCursorPosition:1; ///< Indicates that the commit message is from a reset and does not require the cursor to be moved
1498 bool mSelectTextOnCommit:1;
1500 bool mUnderlinedPriorToPreEdit:1; ///< As predictive text adds underline style this flag enables us to revert back or keep underline.
1502 bool mCommitByKeyInput:1; ///< Set if a commit is done by key input rather than automatically (usually when a space bar or enter is pressed).
1504 bool mPlaceHolderSet:1; ///< Whether the place holder text is set.
1505 bool mMarkUpEnabled:1; ///< enable to scan for mark-up
1507 Toolkit::TextInput::InputSignalV2 mInputStartedSignalV2; ///< Signal emitted when input starts
1508 Toolkit::TextInput::InputSignalV2 mInputFinishedSignalV2; ///< Signal emitted when input ends
1509 Toolkit::TextInput::StyleChangedSignalV2 mStyleChangedSignalV2; ///< Signal emitted when style changes.
1510 Toolkit::TextInput::TextModifiedSignalType mTextModifiedSignal; ///< Signal emitted when text modified.
1511 Toolkit::TextInput::MaxInputCharactersReachedSignalV2 mMaxInputCharactersReachedSignalV2; ///< Signal emitted when max input characters is reached.
1512 Toolkit::TextInput::InputSignalV2 mCutAndPasteToolBarDisplayedV2; ///< Signal emitted when toolbar displayed
1513 Toolkit::TextInput::InputTextExceedBoundariesSignalV2 mInputTextExceedBoundariesSignalV2; ///< Signal emitted when input text exceeds the boundaries of the text-input.
1516 } // namespace Internal
1518 // Helpers for public-api forwarding methods
1520 inline Toolkit::Internal::TextInput& GetImpl(Toolkit::TextInput& textInput)
1522 DALI_ASSERT_ALWAYS(textInput);
1524 Dali::RefObject& handle = textInput.GetImplementation();
1526 return static_cast<Toolkit::Internal::TextInput&>(handle);
1529 inline const Toolkit::Internal::TextInput& GetImpl(const Toolkit::TextInput& textInput)
1531 DALI_ASSERT_ALWAYS(textInput);
1533 const Dali::RefObject& handle = textInput.GetImplementation();
1535 return static_cast<const Toolkit::Internal::TextInput&>(handle);
1538 } // namespace Toolkit
1542 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_H__