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 * @addtogroup CAPI_DALI_TOOLKIT_TEXT_INPUT_MODULE
27 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
29 namespace Dali DALI_IMPORT_API
35 namespace Internal DALI_INTERNAL
41 * @brief TextInput Actor takes input one character at a time and displays it as a string within an input box.
42 * Characters can be removed from the end of the string until it is empty. A maximum length of displayed string
45 class TextInput : public Control
52 static const Property::Index HIGHLIGHT_COLOR_PROPERTY; // Property, name "highlight-color", type VECTOR4
53 static const Property::Index CUT_AND_PASTE_COLOR_PROPERTY; // Property, name "cut-and-paste-bg-color", type VECTOR4
54 static const Property::Index CUT_AND_PASTE_PRESSED_COLOR_PROPERTY; // Property, name "cut-and-paste-pressed-color", type VECTOR4
56 static const Property::Index CUT_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "cut-button-position-priority", type unsigned int
57 static const Property::Index COPY_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "copy-button-position-priority", type unsigned int
58 static const Property::Index PASTE_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "paste-button-position-priority", type unsigned int
59 static const Property::Index SELECT_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "select-button-position-priority", type unsigned int
60 static const Property::Index SELECT_ALL_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "select-all-button-position-priority", type unsigned int
61 static const Property::Index CLIPBOARD_BUTTON_POSITION_PRIORITY_PROPERTY; // Property, name "clipboard-button-position-priority", type unsigned int
66 static const char* const SIGNAL_START_INPUT; ///< name "start-input"
67 static const char* const SIGNAL_END_INPUT; ///< name "end-input"
68 static const char* const SIGNAL_STYLE_CHANGED; ///< name "style-changed"
69 static const char* const SIGNAL_MAX_INPUT_CHARACTERS_REACHED; ///< name "max-input-characters-reached"
70 static const char* const SIGNAL_TOOLBAR_DISPLAYED; ///< name "toolbar-displayed"
71 static const char* const SIGNAL_TEXT_EXCEED_BOUNDARIES; ///< name "text-exceed-boundaries"
77 * @brief Create an uninitialized TextInput; this can be initialized with TextView::New().
79 * Calling member functions with an uninitialized Dali::Object is not allowed.
84 * @brief Copy constructor.
86 * @param handle to be copied
88 TextInput( const TextInput& handle );
91 * @brief Assignment operator.
93 * @param handle to object we want to point to
94 * @return handle to the TextInput
96 TextInput& operator=( const TextInput& handle );
99 * @brief Create an initialised TextInput.
101 * @return A handle to a newly allocated Dali resource.
103 static TextInput New();
106 * @brief Downcast an Object handle to TextInput.
108 * If handle points to a TextInput the downcast produces valid
109 * handle. If not the returned handle is left uninitialized.
111 * @param[in] handle Handle to an object
112 * @return handle to a TextInput or an uninitialized handle
114 static TextInput DownCast( BaseHandle handle );
117 * @brief Virtual destructor.
119 * Dali::Object derived classes typically do not contain member data.
121 virtual ~TextInput();
124 * @brief Get the inputed text currently being displayed.
126 * @return string, the currently displayed string.
128 std::string GetText() const;
131 * @brief Get the inputed text currently being displayed together with mark-up tags.
133 * @return string, the currently displayed string with mark-up.
135 std::string GetMarkupText() const;
138 * @brief Set the maximum number of characters for the Text Input.
140 * @param [in] maxChars the max number of characters
142 void SetMaxCharacterLength(std::size_t maxChars);
145 * @brief Limits the number of lines of text Text Input will display.
147 * @param [in] maxLines the max number of lines to display, must be greater than 0.
148 * Currently the only valid limit is 1. Which turns TextInput into Single line mode. Any number higher than 1 results in no limit.
150 void SetNumberOfLinesLimit(std::size_t maxLines);
153 * @brief Returns the limit of lines Text Input is allowed to display.
155 * @return max line number limit
157 std::size_t GetNumberOfLinesLimit() const;
160 * @brief Returns the number of characters TextInput is displaying.
162 * @return number of characters
164 std::size_t GetNumberOfCharacters() const;
167 * @brief Sets a place holder text to be displayed when the text-input is empty.
169 * If not set or set to an empty string then no place holder will be shown.
170 * @param [in] placeHolderText text to be used as place holder.
172 void SetPlaceholderText( const std::string& placeHolderText );
175 * @return the current set place holder text, empty string returned if not set.
177 std::string GetPlaceholderText();
180 * @brief set initial text to be displayed in text-input.
182 * Can be used to edit a pre-existing string.
183 * @param [in] initialText text to be initially displayed
185 void SetInitialText(const std::string& initialText);
188 * @brief Manual method to set the focus on the TextInput so it starts or stops edit state.
190 * @pre The text input actor has been initialised.
191 * @param[in] editMode true or false to indicate editMode on or off
193 void SetEditable(bool editMode);
196 * @see SetEditable(bool editMode).
198 * It sets the cursor in the closest character to the given touch point.
200 * @param[in] editMode true or false to indicate editMode on or off
201 * @param[in] touchPoint A position in actor coordinates within the text-input.
203 void SetEditable(bool editMode, const Vector2& touchPoint);
206 * @brief Check if TextInput is in edit state.
208 * @pre The text input actor has been initialised.
209 * @return True or False to indicate editMode on or off
211 bool IsEditable() const;
214 * @brief Method to enable or disable edit on touch/tap.
216 * If not enabled (set to false) then SetEditable(true) will be used to start edit mode.
217 * @pre The text input actor has been initialised.
218 * @param[in] editOnTouch true or false to indicate if editing should start on touch
219 * default is for editing to start on touching textinput
221 void SetEditOnTouch(bool editOnTouch = true);
224 * @brief Check if TextInput starts edit mode on touch.
226 * @pre The text input actor has been initialised.
227 * @return True or False to indicate editOnTouch on or off
229 bool IsEditOnTouch() const;
232 * @brief Check if Text Selection is enabled so required text can be highlighted.
234 * @pre The text input actor has been initialised.
235 * @param[in] textSelectable true or false to indicate if text can be selected or not
236 * default is for text to be select-able when in edit mode
238 void SetTextSelectable(bool textSelectable = true);
241 * @brief Check if Text can be selected.
243 * @pre The text input actor has been initialised.
244 * @return True or False to indicate if text can be selected or not
246 bool IsTextSelectable() const;
249 * @brief Check if any text is currently selected, can be used to determine if ApplyStyle or SetActiveStyle should be used.
251 * @pre The text input actor has been initialised.
252 * @return True if text selected else False
254 bool IsTextSelected() const;
257 * @brief Selects text between the given positions.
259 * @pre TextInput should be in edit mode.
260 * @param start position to start selection
261 * @param end position to end selection, inclusive of this character.
262 * Providing 0 and result from GetNumberOfCharacters() will select all text.
264 void SelectText(std::size_t start, std::size_t end);
267 * @brief If any text is selected then de-select it and hide highlight.
269 * @pre The text input actor has been initialised.
274 * @brief Set the image to be used as the cursor grab hander.
276 * @pre The text input actor has been initialised.
277 * @param[in] image The image to be used.
279 void SetGrabHandleImage( Image image );
282 * @brief Set the image to be used for the regular left to right cursor.
284 * @pre The text input actor has been initialised.
285 * @param[in] image The image to be used.
286 * @param[in] border The nine patch border for the image.
288 void SetCursorImage(Dali::Image image, const Vector4& border );
291 * @brief Retrieve the selection handle size.
293 * Both handles have same size.
294 * @return Vector3 the selection handle size.
296 Vector3 GetSelectionHandleSize();
299 * @brief Set the image to be used for the Right to Left cursor.
301 * @pre The text input actor has been initialised.
302 * @param[in] image The image to be used.
303 * @param[in] border The nine patch border for the image.
305 void SetRTLCursorImage(Dali::Image image, const Vector4& border );
308 * @brief Toggle to enable the grab handle, used to position cursor when magnifier not being used.
310 * Default behaviour is to use the magnifier to position the cursor, enabling this prevents the magnifier from being shown.
311 * @param[in] toggle true to enable, false to disable grab handle
313 void EnableGrabHandle(bool toggle);
316 * @brief Method to check if grab handle is enabled, if false then the magnifier will be used to position cursor.
318 * @return bool returns true is grab handle enabled.
320 bool IsGrabHandleEnabled();
323 * @brief Set the bounding rectangle which handles, popup and similar decorations will not exceed.
325 * The default value is the width and height of the stage from the top left origin.
326 * If a title bar for example is on the top of the screen then the y should be the title's height and
327 * the boundary height the stage height minus the title's height.
328 * Restrictions - The boundary box should be set up with a fixed z position for the text-input and the default camera.
329 * @param[in] boundingOriginAndSize Rect( x coordinate, y coordinate, width, height )
330 * ------------------------------------------
332 * |o---------------------------------------|
334 * || Bounding Box || boundary height
336 * |----------------------------------------|
337 * ------------------------------------------
340 void SetBoundingRectangle( const Rect<float>& boundingOriginAndSize );
343 * @brief Retrieve the bounding box origin and dimensions.
345 * default is set once control is added to stage, before this the return vector will be Vector4:ZERO
346 * @return Rect the bounding rectangle
348 const Rect<float> GetBoundingRectangle() const;
351 * @brief Sets the style for new text being typed.
353 * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
354 * @pre The text input actor has been initialised.
355 * @param[in] style The style for the new text.
356 * @param[in] mask The bit mask.
358 void SetActiveStyle( const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
361 * @brief Applies the given style to the selected text.
363 * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
364 * Introduced text after this call uses the new style.
365 * @param[in] style The given style.
366 * @param[in] mask The bit mask.
368 void ApplyStyle( const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
371 * @brief Applies the given style to all text, selected or not selected.
373 * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
374 * @param[in] style The given style.
375 * @param[in] mask The bit mask.
377 void ApplyStyleToAll( const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
380 * @brief Get the style of the Text character before the cursor.
382 * If no character before then return the InputStyle.
383 * @return TextStyle, the style of the character before the cursor
385 TextStyle GetStyleAtCursor() const;
388 * @brief Set the current text alignment (overrides default setting).
390 * The default alignment is dependent on the current text in the text field.
391 * If the text begins using LTR characters (e.g. European text) then the
392 * alignment is HorizontalLeft. If the text begins using RTL characters
393 * (e.g. Hebrew/Arabic text) then the alignment is HorizontalRight.
394 * If there is no text, then the alignment defaults to:
395 * (HorizontalLeft | VerticalCenter)
396 * @param[in] align The new alignment option.
398 void SetTextAlignment( Toolkit::Alignment::Type align );
401 * @brief Set the current line justification. (overrides default setting).
403 * The default justification is dependent on the current text in the text field.
404 * If the text begins using LTR characters (e.g. European text) then the
405 * justification is HorizontalLeft. If the text begins using RTL characters
406 * (e.g. Hebrew/Arabic text) then the justification is HorizontalRight.
407 * If there is no text, then the justification defaults to:
408 * (HorizontalLeft | VerticalCenter)
409 * @param[in] justification The new line justification.
411 void SetTextLineJustification( Toolkit::TextView::LineJustification justification );
414 * @brief Sets a fade boundary.
416 * @see TextView::FadeBoundary.
418 * @param[in] fadeBoundary The given fade boundary.
420 void SetFadeBoundary( const Toolkit::TextView::FadeBoundary& fadeBoundary );
423 * @brief Retrieves the fade boundary.
425 * @see TextView::FadeBoundary.
427 * @return The fade boundary.
429 const Toolkit::TextView::FadeBoundary& GetFadeBoundary() const;
432 * @brief Get the current text alignment combined into a single value.
434 * The values can be tested by using the & operator
435 * and the desired flag. e.g. if (GetTextAlignment() & HorizontalCentre) ...
436 * @return The combined text alignment
438 Toolkit::Alignment::Type GetTextAlignment() const;
441 * @brief Sets how to split the text in lines policy.
443 * @param policy The multi-line policy.
445 void SetMultilinePolicy( Toolkit::TextView::MultilinePolicy policy );
448 * @brief Gets the split in lines policy.
450 * @return The multi-line policy.
452 Toolkit::TextView::MultilinePolicy GetMultilinePolicy() const;
455 * @brief Sets how to display the text inside the TextView when it exceeds the text-view's width.
457 * @param policy The exceed policy.
459 void SetWidthExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
462 * @brief Gets the width exceed policy.
464 * @return The exceed policy.
466 TextView::ExceedPolicy GetWidthExceedPolicy() const;
469 * @brief Sets how to display the text inside the TextView when it exceeds the text-view's height.
471 * @param policy The exceed policy.
473 void SetHeightExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
476 * @brief Gets the height exceed policy.
478 * @return The exceed policy.
480 TextView::ExceedPolicy GetHeightExceedPolicy() const;
483 * @brief Sets if the inputed text can exceed the text-input boundary.
485 * By default is enabled.
487 * @param[in] enable Whether the inputed text can exceed its boundary.
489 void SetExceedEnabled( bool enable );
492 * @brief Retrieves whether inputed text can exceed the text-input boundary.
494 * @return \e true if text inputed can exceed the boundary, otherwise \e false.
496 bool GetExceedEnabled() const;
499 * @brief Allows modification of text-actor's position in the depth sort algorithm.
501 * @see Dali::RenderableActor::SetSortModifier()
502 * @param [in] depthOffset the offset to be given to the internal text-actors. Positive values pushing it further back.
504 void SetSortModifier( float depthOffset );
507 * @brief Sets whether text-view renders text using a previously generated snapshot.
509 * @see TextView::SetSnapshotModeEnabled()
511 * @param[in] enable Whether text-view is using or not a snapshot to render text.
513 void SetSnapshotModeEnabled( bool enable );
516 * @brief Retrieves whether text-view is using a snapshot to render text.
518 * @see TextView::IsSnapshotModeEnabled()
520 * @return \e true if text-view is using a snapshot to render text, otherwhise it returns \e false.
522 bool IsSnapshotModeEnabled() const;
525 * @copydoc TextView::SetScrollEnabled()
527 void SetScrollEnabled( bool enable );
530 * @copydoc TextView::IsScrollEnabled()
532 bool IsScrollEnabled() const;
535 * @copydoc TextView::SetScrollPosition()
537 void SetScrollPosition( const Vector2& position );
540 * @copydoc TextView::GetScrollPosition()
542 Vector2 GetScrollPosition() const;
545 * @brief Sets whether markup processing should be carried out.
547 * @param[in] enable whether markup processing is carried out or not.
549 void SetMarkupProcessingEnabled( bool enable );
552 * @brief Returns whether markup processing is enabled or not
554 * @return true is markup processing is enabled
556 bool IsMarkupProcessingEnabled() const;
559 public: /* Signals */
561 /// @brief Input Signal.
562 typedef SignalV2< void ( TextInput textInput ) > InputSignalV2;
564 /// @brief Input style changed signal.
565 typedef SignalV2< void ( TextInput textInput, const TextStyle& style ) > StyleChangedSignalV2;
567 /// @brief Text modified signal.
568 typedef SignalV2< void ( TextInput textInput ) > TextModifiedSignalType;
570 /// @brief Max input characters reached signal.
571 typedef SignalV2< void ( TextInput textInput ) > MaxInputCharactersReachedSignalV2;
573 /// @brief Input text exceeds boundaries signal.
574 typedef SignalV2< void ( TextInput textInput ) > InputTextExceedBoundariesSignalV2;
577 * @brief Signal emitted when the Text-Input starts receiving input.
579 InputSignalV2& InputStartedSignal();
582 * @brief Signal emitted when the Text-Input is finished receiving input.
584 * TextInput::GetText() can be called to get current text string.
585 * @return The signal to connect to
587 InputSignalV2& InputFinishedSignal();
590 * @brief Signal emitted when the cut and paste toolbar is displayed.
592 * @return The signal to connect to
594 InputSignalV2& CutAndPasteToolBarDisplayedSignal();
597 * @brief Signal emitted when style changes.
599 * @return The signal to connect to
601 StyleChangedSignalV2& StyleChangedSignal();
604 * @brief Signal emitted when text changes.
606 * @return The signal to connect to.
608 TextModifiedSignalType& TextModifiedSignal();
611 * @brief Signal emitted when max input characters are reached during text input.
613 * @return The signal to connect to
615 MaxInputCharactersReachedSignalV2& MaxInputCharactersReachedSignal();
618 * @brief Signal emitted when input text exceeds the boundaries of the text-input.
620 * @return The signal to connect to
622 InputTextExceedBoundariesSignalV2& InputTextExceedBoundariesSignal();
624 public: // Not intended for application developers
627 * @brief Creates a handle using the Toolkit::Internal implementation.
629 * @param[in] implementation The Control implementation.
631 TextInput(Internal::TextInput& implementation);
634 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
636 * @param[in] internal A pointer to the internal CustomActor.
638 TextInput(Dali::Internal::CustomActor* internal );
641 } // namespace Toolkit
648 #endif // __DALI_TOOLKIT_TEXT_INPUT_H__