1 #ifndef __DALI_TOOLKIT_TEXT_INPUT_H__
2 #define __DALI_TOOLKIT_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/text-view/text-view.h>
30 namespace Internal DALI_INTERNAL
36 * @brief TextInput Actor takes input one character at a time and displays it as a string within an input box.
37 * Characters can be removed from the end of the string until it is empty. A maximum length of displayed string
40 class DALI_IMPORT_API TextInput : public Control
47 static const Dali::Property::Index HIGHLIGHT_COLOR_PROPERTY; // Property, name "highlight-color", type VECTOR4
48 static const Dali::Property::Index CUT_AND_PASTE_COLOR_PROPERTY; // Property, name "cut-and-paste-bg-color", type VECTOR4
49 static const Dali::Property::Index CUT_AND_PASTE_PRESSED_COLOR_PROPERTY; // Property, name "cut-and-paste-pressed-color", type VECTOR4
50 static const Dali::Property::Index CUT_AND_PASTE_BORDER_COLOR_PROPERTY; // Property, name "cut-and-paste-border-color", type VECTOR4
51 static const Dali::Property::Index CUT_AND_PASTE_ICON_COLOR_PROPERTY; // Property, name "cut-and-paste-icon-color", type VECTOR4
52 static const Dali::Property::Index CUT_AND_PASTE_ICON_PRESSED_COLOR_PROPERTY; // Property, name "cut-and-paste-icon-pressed-color", type VECTOR4
53 static const Dali::Property::Index CUT_AND_PASTE_TEXT_COLOR_PROPERTY; // Property, name "cut-and-paste-text-color", type VECTOR4
54 static const Dali::Property::Index CUT_AND_PASTE_TEXT_PRESSED_COLOR_PROPERTY; // Property, name "cut-and-paste-text-pressed-color", type VECTOR4
55 static const Dali::Property::Index CUT_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "cut-button-position-priority", type unsigned int
56 static const Dali::Property::Index COPY_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "copy-button-position-priority", type unsigned int
57 static const Dali::Property::Index PASTE_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "paste-button-position-priority", type unsigned int
58 static const Dali::Property::Index SELECT_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "select-button-position-priority", type unsigned int
59 static const Dali::Property::Index SELECT_ALL_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "select-all-button-position-priority", type unsigned int
60 static const Dali::Property::Index CLIPBOARD_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "clipboard-button-position-priority", type unsigned int
61 static const Dali::Property::Index POP_UP_OFFSET_FROM_TEXT_PROPERTY; // Property, name "popup-offset-from-text", type VECTOR4
62 static const Dali::Property::Index CURSOR_COLOR_PROPERTY; // Property, name "cursor-color", type VECTOR4
68 * @brief Create an uninitialized TextInput; this can be initialized with TextView::New().
70 * Calling member functions with an uninitialized Dali::Object is not allowed.
75 * @brief Copy constructor.
77 * @param handle to be copied
79 TextInput( const TextInput& handle );
82 * @brief Assignment operator.
84 * @param handle to object we want to point to
85 * @return handle to the TextInput
87 TextInput& operator=( const TextInput& handle );
90 * @brief Create an initialised TextInput.
92 * @return A handle to a newly allocated Dali resource.
94 static TextInput New();
97 * @brief Downcast an Object handle to TextInput.
99 * If handle points to a TextInput the downcast produces valid
100 * handle. If not the returned handle is left uninitialized.
102 * @param[in] handle Handle to an object
103 * @return handle to a TextInput or an uninitialized handle
105 static TextInput DownCast( BaseHandle handle );
110 * This is non-virtual since derived Handle types must not contain data or virtual methods.
115 * @brief Get the inputed text currently being displayed.
117 * @return string, the currently displayed string.
119 std::string GetText() const;
122 * @brief Get the inputed text currently being displayed together with mark-up tags.
124 * @return string, the currently displayed string with mark-up.
126 std::string GetMarkupText() const;
129 * @brief Set the maximum number of characters for the Text Input.
131 * @param [in] maxChars the max number of characters
133 void SetMaxCharacterLength(std::size_t maxChars);
136 * @brief Limits the number of lines of text Text Input will display.
138 * @param [in] maxLines the max number of lines to display, must be greater than 0.
139 * Currently the only valid limit is 1. Which turns TextInput into Single line mode. Any number higher than 1 results in no limit.
141 void SetNumberOfLinesLimit(std::size_t maxLines);
144 * @brief Returns the limit of lines Text Input is allowed to display.
146 * @return max line number limit
148 std::size_t GetNumberOfLinesLimit() const;
151 * @brief Returns the number of characters TextInput is displaying.
153 * @return number of characters
155 std::size_t GetNumberOfCharacters() const;
158 * @brief Sets a place holder text to be displayed when the text-input is empty.
160 * If not set or set to an empty string then no place holder will be shown.
161 * @param [in] placeHolderText text to be used as place holder.
163 void SetPlaceholderText( const std::string& placeHolderText );
166 * @return the current set place holder text, empty string returned if not set.
168 std::string GetPlaceholderText();
171 * @brief set initial text to be displayed in text-input.
173 * Can be used to edit a pre-existing string.
174 * @param [in] initialText text to be initially displayed
176 void SetInitialText(const std::string& initialText);
179 * @brief Manual method to set the focus on the TextInput so it starts or stops edit state.
181 * @pre The text input actor has been initialised.
182 * @param[in] editMode true or false to indicate editMode on or off
184 void SetEditable(bool editMode);
187 * @see SetEditable(bool editMode).
189 * It sets the cursor in the closest character to the given touch point.
191 * @param[in] editMode true or false to indicate editMode on or off
192 * @param[in] touchPoint A position in actor coordinates within the text-input.
194 void SetEditable(bool editMode, const Vector2& touchPoint);
197 * @brief Check if TextInput is in edit state.
199 * @pre The text input actor has been initialised.
200 * @return True or False to indicate editMode on or off
202 bool IsEditable() const;
205 * @brief Method to enable or disable edit on touch/tap.
207 * If not enabled (set to false) then SetEditable(true) will be used to start edit mode.
208 * @pre The text input actor has been initialised.
209 * @param[in] editOnTouch true or false to indicate if editing should start on touch
210 * default is for editing to start on touching textinput
212 void SetEditOnTouch(bool editOnTouch = true);
215 * @brief Check if TextInput starts edit mode on touch.
217 * @pre The text input actor has been initialised.
218 * @return True or False to indicate editOnTouch on or off
220 bool IsEditOnTouch() const;
223 * @brief Check if Text Selection is enabled so required text can be highlighted.
225 * @pre The text input actor has been initialised.
226 * @param[in] textSelectable true or false to indicate if text can be selected or not
227 * default is for text to be select-able when in edit mode
229 void SetTextSelectable(bool textSelectable = true);
232 * @brief Check if Text can be selected.
234 * @pre The text input actor has been initialised.
235 * @return True or False to indicate if text can be selected or not
237 bool IsTextSelectable() const;
240 * @brief Check if any text is currently selected, can be used to determine if ApplyStyle or SetActiveStyle should be used.
242 * @pre The text input actor has been initialised.
243 * @return True if text selected else False
245 bool IsTextSelected() const;
248 * @brief Selects text between the given positions.
250 * @pre TextInput should be in edit mode.
251 * @param start position to start selection
252 * @param end position to end selection, inclusive of this character.
253 * Providing 0 and result from GetNumberOfCharacters() will select all text.
255 void SelectText(std::size_t start, std::size_t end);
258 * @brief If any text is selected then de-select it and hide highlight.
260 * @pre The text input actor has been initialised.
265 * @brief Set the image to be used as the cursor grab hander.
267 * @pre The text input actor has been initialised.
268 * @param[in] image The image to be used.
270 void SetGrabHandleImage( Image image );
274 * @brief Set the image to be used for the regular left to right cursor.
276 * @pre The text input actor has been initialised.
277 * @param[in] image The image to be used.
278 * @param[in] border The nine patch border for the image.
280 void SetCursorImage(Dali::Image image, const Vector4& border );
283 * @brief Retrieve the selection handle size.
285 * Both handles have same size.
286 * @return Vector3 the selection handle size.
288 Vector3 GetSelectionHandleSize();
291 * @brief Set the image to be used for the Right to Left cursor.
293 * @pre The text input actor has been initialised.
294 * @param[in] image The image to be used.
295 * @param[in] border The nine patch border for the image.
297 void SetRTLCursorImage(Dali::Image image, const Vector4& border );
300 * @brief Toggle to enable the grab handle, used to position cursor when magnifier not being used.
302 * Default behaviour is to use the magnifier to position the cursor, enabling this prevents the magnifier from being shown.
303 * @param[in] toggle true to enable, false to disable grab handle
305 void EnableGrabHandle(bool toggle);
308 * @brief Method to check if grab handle is enabled, if false then the magnifier will be used to position cursor.
310 * @return bool returns true is grab handle enabled.
312 bool IsGrabHandleEnabled();
315 * @brief Set the bounding rectangle which handles, popup and similar decorations will not exceed.
317 * The default value is the width and height of the stage from the top left origin.
318 * If a title bar for example is on the top of the screen then the y should be the title's height and
319 * the boundary height the stage height minus the title's height.
320 * Restrictions - The boundary box should be set up with a fixed z position for the text-input and the default camera.
321 * @param[in] boundingOriginAndSize Rect( x coordinate, y coordinate, width, height )
323 * +----------------------------------------+
325 * |+--------------------------------------+|
327 * || Bounding Box || boundary height
329 * |+--------------------------------------+|
330 * +----------------------------------------+
334 void SetBoundingRectangle( const Rect<float>& boundingOriginAndSize );
337 * @brief Retrieve the bounding box origin and dimensions.
339 * default is set once control is added to stage, before this the return vector will be Vector4:ZERO
340 * @return Rect the bounding rectangle
342 const Rect<float> GetBoundingRectangle() const;
345 * @brief Sets the style for new text being typed.
347 * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
348 * @pre The text input actor has been initialised.
349 * @param[in] style The style for the new text.
350 * @param[in] mask The bit mask.
352 void SetActiveStyle( const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
355 * @brief Applies the given style to the selected text.
357 * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
358 * Introduced text after this call uses the new style.
359 * @param[in] style The given style.
360 * @param[in] mask The bit mask.
362 void ApplyStyle( const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
365 * @brief Applies the given style to all text, selected or not selected.
367 * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
368 * @param[in] style The given style.
369 * @param[in] mask The bit mask.
371 void ApplyStyleToAll( const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
374 * @brief Get the style of the Text character before the cursor.
376 * If no character before then return the InputStyle.
377 * @return TextStyle, the style of the character before the cursor
379 TextStyle GetStyleAtCursor() const;
382 * @brief Set the current text alignment (overrides default setting).
384 * The default alignment is dependent on the current text in the text field.
385 * If the text begins using LTR characters (e.g. European text) then the
386 * alignment is HorizontalLeft. If the text begins using RTL characters
387 * (e.g. Hebrew/Arabic text) then the alignment is HorizontalRight.
388 * If there is no text, then the alignment defaults to:
389 * (HorizontalLeft | VerticalCenter)
390 * @param[in] align The new alignment option.
392 void SetTextAlignment( Toolkit::Alignment::Type align );
395 * @brief Set the current line justification. (overrides default setting).
397 * The default justification is dependent on the current text in the text field.
398 * If the text begins using LTR characters (e.g. European text) then the
399 * justification is HorizontalLeft. If the text begins using RTL characters
400 * (e.g. Hebrew/Arabic text) then the justification is HorizontalRight.
401 * If there is no text, then the justification defaults to:
402 * (HorizontalLeft | VerticalCenter)
403 * @param[in] justification The new line justification.
405 void SetTextLineJustification( Toolkit::TextView::LineJustification justification );
408 * @brief Sets a fade boundary.
410 * @see TextView::FadeBoundary.
412 * @param[in] fadeBoundary The given fade boundary.
414 void SetFadeBoundary( const Toolkit::TextView::FadeBoundary& fadeBoundary );
417 * @brief Retrieves the fade boundary.
419 * @see TextView::FadeBoundary.
421 * @return The fade boundary.
423 const Toolkit::TextView::FadeBoundary& GetFadeBoundary() const;
426 * @brief Get the current text alignment combined into a single value.
428 * The values can be tested by using the & operator
429 * and the desired flag. e.g. if (GetTextAlignment() & HorizontalCentre) ...
430 * @return The combined text alignment
432 Toolkit::Alignment::Type GetTextAlignment() const;
435 * @brief Sets how to split the text in lines policy.
437 * @param policy The multi-line policy.
439 void SetMultilinePolicy( Toolkit::TextView::MultilinePolicy policy );
442 * @brief Gets the split in lines policy.
444 * @return The multi-line policy.
446 Toolkit::TextView::MultilinePolicy GetMultilinePolicy() const;
449 * @brief Sets how to display the text inside the TextView when it exceeds the text-view's width.
451 * @param policy The exceed policy.
453 void SetWidthExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
456 * @brief Gets the width exceed policy.
458 * @return The exceed policy.
460 TextView::ExceedPolicy GetWidthExceedPolicy() const;
463 * @brief Sets how to display the text inside the TextView when it exceeds the text-view's height.
465 * @param policy The exceed policy.
467 void SetHeightExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
470 * @brief Gets the height exceed policy.
472 * @return The exceed policy.
474 TextView::ExceedPolicy GetHeightExceedPolicy() const;
477 * @brief Sets if the inputed text can exceed the text-input boundary.
479 * By default is enabled.
481 * @param[in] enable Whether the inputed text can exceed its boundary.
483 void SetExceedEnabled( bool enable );
486 * @brief Retrieves whether inputed text can exceed the text-input boundary.
488 * @return \e true if text inputed can exceed the boundary, otherwise \e false.
490 bool GetExceedEnabled() const;
493 * @brief Allows modification of text-actor's position in the depth sort algorithm.
495 * @see Dali::RenderableActor::SetSortModifier()
496 * @param [in] depthOffset the offset to be given to the internal text-actors. Positive values pushing it further back.
498 void SetSortModifier( float depthOffset );
501 * @brief Sets whether text-view renders text using a previously generated snapshot.
503 * @see TextView::SetSnapshotModeEnabled()
505 * @param[in] enable Whether text-view is using or not a snapshot to render text.
507 void SetSnapshotModeEnabled( bool enable );
510 * @brief Retrieves whether text-view is using a snapshot to render text.
512 * @see TextView::IsSnapshotModeEnabled()
514 * @return \e true if text-view is using a snapshot to render text, otherwhise it returns \e false.
516 bool IsSnapshotModeEnabled() const;
519 * @copydoc TextView::SetScrollEnabled()
521 void SetScrollEnabled( bool enable );
524 * @copydoc TextView::IsScrollEnabled()
526 bool IsScrollEnabled() const;
529 * @copydoc TextView::SetScrollPosition()
531 void SetScrollPosition( const Vector2& position );
534 * @copydoc TextView::GetScrollPosition()
536 Vector2 GetScrollPosition() const;
539 * @brief Sets whether markup processing should be carried out.
541 * @param[in] enable whether markup processing is carried out or not.
543 void SetMarkupProcessingEnabled( bool enable );
546 * @brief Returns whether markup processing is enabled or not
548 * @return true is markup processing is enabled
550 bool IsMarkupProcessingEnabled() const;
553 public: /* Signals */
555 /// @brief Input Signal.
556 typedef Signal< void ( TextInput textInput ) > InputSignalType;
558 /// @brief Input style changed signal.
559 typedef Signal< void ( TextInput textInput, const TextStyle& style ) > StyleChangedSignalType;
561 /// @brief Text modified signal.
562 typedef Signal< void ( TextInput textInput ) > TextModifiedSignalType;
564 /// @brief Max input characters reached signal.
565 typedef Signal< void ( TextInput textInput ) > MaxInputCharactersReachedSignalType;
567 /// @brief Input text exceeds boundaries signal.
568 typedef Signal< void ( TextInput textInput ) > InputTextExceedBoundariesSignalType;
571 * @brief Signal emitted when the Text-Input starts receiving input.
573 InputSignalType& InputStartedSignal();
576 * @brief Signal emitted when the Text-Input is finished receiving input.
578 * TextInput::GetText() can be called to get current text string.
579 * @return The signal to connect to
581 InputSignalType& InputFinishedSignal();
584 * @brief Signal emitted when the cut and paste toolbar is displayed.
586 * @return The signal to connect to
588 InputSignalType& CutAndPasteToolBarDisplayedSignal();
591 * @brief Signal emitted when style changes.
593 * @return The signal to connect to
595 StyleChangedSignalType& StyleChangedSignal();
598 * @brief Signal emitted when text changes.
600 * @return The signal to connect to.
602 TextModifiedSignalType& TextModifiedSignal();
605 * @brief Signal emitted when max input characters are reached during text input.
607 * @return The signal to connect to
609 MaxInputCharactersReachedSignalType& MaxInputCharactersReachedSignal();
612 * @brief Signal emitted when input text exceeds the boundaries of the text-input.
614 * @return The signal to connect to
616 InputTextExceedBoundariesSignalType& InputTextExceedBoundariesSignal();
618 public: // Not intended for application developers
621 * @brief Creates a handle using the Toolkit::Internal implementation.
623 * @param[in] implementation The Control implementation.
625 DALI_INTERNAL TextInput(Internal::TextInput& implementation);
628 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
630 * @param[in] internal A pointer to the internal CustomActor.
632 explicit DALI_INTERNAL TextInput(Dali::Internal::CustomActor* internal );
635 } // namespace Toolkit
639 #endif // __DALI_TOOLKIT_TEXT_INPUT_H__