df140b3c1f453d8e079c6d22df95ba5d2fa8f98f
[platform/core/uifw/dali-toolkit.git] / capi / dali-toolkit / public-api / controls / text-input / text-input.h
1 #ifndef __DALI_TOOLKIT_TEXT_INPUT_H__
2 #define __DALI_TOOLKIT_TEXT_INPUT_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 /**
22  * @addtogroup CAPI_DALI_TOOLKIT_TEXT_INPUT_MODULE
23  * @{
24  */
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
28
29 namespace Dali DALI_IMPORT_API
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal DALI_INTERNAL
36 {
37 class TextInput;
38 }
39
40 /**
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
43  * can be set.
44  */
45 class TextInput : public Control
46 {
47
48 public:
49
50   /// @name Properties
51   /** @{ */
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
55
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
62   /** @} */
63
64   /// @name Signals
65   /** @{ */
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"
72   /** @} */
73
74 public:
75
76   /**
77    * @brief Create an uninitialized TextInput; this can be initialized with TextView::New().
78    *
79    * Calling member functions with an uninitialized Dali::Object is not allowed.
80    */
81   TextInput();
82
83   /**
84    * @brief Copy constructor.
85    *
86    * @param handle to be copied
87    */
88   TextInput( const TextInput& handle );
89
90   /**
91    * @brief Assignment operator.
92    *
93    * @param handle to object we want to point to
94    * @return handle to the TextInput
95    */
96   TextInput& operator=( const TextInput& handle );
97
98   /**
99    * @brief Create an initialised TextInput.
100    *
101    * @return A handle to a newly allocated Dali resource.
102    */
103   static TextInput New();
104
105   /**
106    * @brief Downcast an Object handle to TextInput.
107    *
108    * If handle points to a TextInput the downcast produces valid
109    * handle. If not the returned handle is left uninitialized.
110    *
111    * @param[in] handle Handle to an object
112    * @return handle to a TextInput or an uninitialized handle
113    */
114   static TextInput DownCast( BaseHandle handle );
115
116   /**
117    * @brief Virtual destructor.
118    *
119    * Dali::Object derived classes typically do not contain member data.
120    */
121   virtual ~TextInput();
122
123   /**
124    * @brief Get the inputed text currently being displayed.
125    *
126    * @return string, the currently displayed string.
127    */
128   std::string GetText() const;
129
130   /**
131    * @brief Get the inputed text currently being displayed together with mark-up tags.
132    *
133    * @return string, the currently displayed string with mark-up.
134    */
135   std::string GetMarkupText() const;
136
137   /**
138    * @brief Set the maximum number of characters for the Text Input.
139    *
140    * @param [in] maxChars the max number of characters
141    */
142   void SetMaxCharacterLength(std::size_t maxChars);
143
144   /**
145    * @brief Limits the number of lines of text Text Input will display.
146    *
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.
149    */
150   void SetNumberOfLinesLimit(std::size_t maxLines);
151
152   /**
153    * @brief Returns the limit of lines Text Input is allowed to display.
154    *
155    * @return max line number limit
156    */
157   std::size_t GetNumberOfLinesLimit() const;
158
159   /**
160    * @brief Returns the number of characters TextInput is displaying.
161    *
162    * @return number of characters
163    */
164   std::size_t GetNumberOfCharacters() const;
165
166   /**
167    *  @brief Sets a place holder text to be displayed when the text-input is empty.
168    *
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.
171    */
172   void SetPlaceholderText( const std::string& placeHolderText );
173
174   /**
175    * @return the current set place holder text, empty string returned if not set.
176    */
177   std::string GetPlaceholderText();
178
179   /**
180    *  @brief set initial text to be displayed in text-input.
181    *
182    *  Can be used to edit a pre-existing string.
183    *  @param [in] initialText text to be initially displayed
184    */
185   void SetInitialText(const std::string& initialText);
186
187   /**
188    *  @brief Manual method to set the focus on the TextInput so it starts or stops edit state.
189    *
190    *  @pre The text input actor has been initialised.
191    *  @param[in] editMode true or false to indicate editMode on or off
192    */
193    void SetEditable(bool editMode);
194
195    /**
196     * @see SetEditable(bool editMode).
197     *
198     * It sets the cursor in the closest character to the given touch point.
199     *
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.
202     */
203    void SetEditable(bool editMode, const Vector2& touchPoint);
204
205    /**
206     *  @brief Check if TextInput is in edit state.
207     *
208     *  @pre The text input actor has been initialised.
209     *  @return  True or False to indicate editMode on or off
210     */
211    bool IsEditable() const;
212
213    /**
214     * @brief Method to enable or disable edit on touch/tap.
215     *
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
220     */
221    void SetEditOnTouch(bool editOnTouch = true);
222
223    /**
224     *  @brief Check if TextInput starts edit mode on touch.
225     *
226     *  @pre The text input actor has been initialised.
227     *  @return  True or False to indicate editOnTouch on or off
228     */
229    bool IsEditOnTouch() const;
230
231    /**
232     *  @brief Check if Text Selection is enabled so required text can be highlighted.
233     *
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
237     */
238    void SetTextSelectable(bool textSelectable = true);
239
240    /**
241     *  @brief Check if Text can be selected.
242     *
243     *  @pre The text input actor has been initialised.
244     *  @return  True or False to indicate if text can be selected or not
245     */
246    bool IsTextSelectable() const;
247
248    /**
249     * @brief Check if any text is currently selected, can be used to determine if ApplyStyle or SetActiveStyle should be used.
250     *
251     * @pre The text input actor has been initialised.
252     * @return True if text selected else False
253     */
254    bool IsTextSelected() const;
255
256    /**
257     * @brief Selects text between the given positions.
258     *
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.
263     */
264    void SelectText(std::size_t start, std::size_t end);
265
266    /**
267     * @brief If any text is selected then de-select it and hide highlight.
268     *
269     * @pre The text input actor has been initialised.
270     */
271    void DeSelectText();
272
273    /**
274     * @brief Set the image to be used as the cursor grab hander.
275     *
276     * @pre The text input actor has been initialised.
277     * @param[in] image The image to be used.
278     */
279    void SetGrabHandleImage( Image image );
280
281    /**
282     * @brief Set the image to be used for the regular left to right cursor.
283     *
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.
287     */
288    void SetCursorImage(Dali::Image image, const Vector4& border );
289
290    /**
291     * @brief Retrieve the selection handle size.
292     *
293     * Both handles have same size.
294     * @return Vector3 the selection handle size.
295     */
296    Vector3 GetSelectionHandleSize();
297
298    /**
299     * @brief Set the image to be used for the Right to Left cursor.
300     *
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.
304     */
305     void SetRTLCursorImage(Dali::Image image, const Vector4& border );
306
307    /**
308     * @brief Toggle to enable the grab handle, used to position cursor when magnifier not being used.
309     *
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
312     */
313    void EnableGrabHandle(bool toggle);
314
315    /**
316     * @brief Method to check if grab handle is enabled, if false then the magnifier will be used to position cursor.
317     *
318     * @return bool returns true is grab handle enabled.
319     */
320    bool IsGrabHandleEnabled();
321
322   /**
323    * @brief Set the bounding rectangle which handles, popup and similar decorations will not exceed.
324    *
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    * ------------------------------------------
331    * |(x,y)                                   |
332    * |o---------------------------------------|
333    * ||                                      ||
334    * ||            Bounding Box              || boundary height
335    * ||                                      ||
336    * |----------------------------------------|
337    * ------------------------------------------
338    *               boundary width
339    */
340   void SetBoundingRectangle( const Rect<float>& boundingOriginAndSize );
341
342   /**
343    * @brief Retrieve the bounding box origin and dimensions.
344    *
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
347    */
348   const Rect<float> GetBoundingRectangle() const;
349
350    /**
351     * @brief Sets the style for new text being typed.
352     *
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.
357     */
358    void SetActiveStyle( const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
359
360    /**
361     * @brief Applies the given style to the selected text.
362     *
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.
367     */
368    void ApplyStyle( const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
369
370    /**
371      * @brief Applies the given style to all text, selected or not selected.
372      *
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.
376      */
377    void ApplyStyleToAll( const TextStyle& style, const TextStyle::Mask mask = TextStyle::ALL );
378
379    /**
380     * @brief Get the style of the Text character before the cursor.
381     *
382     * If no character before then return the InputStyle.
383     * @return TextStyle, the style of the character before the cursor
384     */
385    TextStyle GetStyleAtCursor() const;
386
387   /**
388    * @brief Set the current text alignment (overrides default setting).
389    *
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.
397    */
398   void SetTextAlignment( Toolkit::Alignment::Type align );
399
400   /**
401    * @brief Set the current line justification. (overrides default setting).
402    *
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.
410    */
411   void SetTextLineJustification( Toolkit::TextView::LineJustification justification );
412
413   /**
414    * @brief Sets a fade boundary.
415    *
416    * @see TextView::FadeBoundary.
417    *
418    * @param[in] fadeBoundary The given fade boundary.
419    */
420   void SetFadeBoundary( const Toolkit::TextView::FadeBoundary& fadeBoundary );
421
422   /**
423    * @brief Retrieves the fade boundary.
424    *
425    * @see TextView::FadeBoundary.
426    *
427    * @return The fade boundary.
428    */
429   const Toolkit::TextView::FadeBoundary& GetFadeBoundary() const;
430
431   /**
432    * @brief Get the current text alignment combined into a single value.
433    *
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
437    */
438   Toolkit::Alignment::Type GetTextAlignment() const;
439
440   /**
441    * @brief Sets how to split the text in lines policy.
442    *
443    * @param policy The multi-line policy.
444    */
445    void SetMultilinePolicy( Toolkit::TextView::MultilinePolicy policy );
446
447   /**
448    * @brief Gets the split in lines policy.
449    *
450    * @return The multi-line policy.
451    */
452   Toolkit::TextView::MultilinePolicy GetMultilinePolicy() const;
453
454   /**
455    * @brief Sets how to display the text inside the TextView when it exceeds the text-view's width.
456    *
457    * @param policy The exceed policy.
458    */
459   void SetWidthExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
460
461   /**
462    * @brief Gets the width exceed policy.
463    *
464    * @return The exceed policy.
465    */
466   TextView::ExceedPolicy GetWidthExceedPolicy() const;
467
468   /**
469    * @brief Sets how to display the text inside the TextView when it exceeds the text-view's height.
470    *
471    * @param policy The exceed policy.
472    */
473   void SetHeightExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
474
475   /**
476    * @brief Gets the height exceed policy.
477    *
478    * @return The exceed policy.
479    */
480   TextView::ExceedPolicy GetHeightExceedPolicy() const;
481
482   /**
483    * @brief Sets if the inputed text can exceed the text-input boundary.
484    *
485    * By default is enabled.
486    *
487    * @param[in] enable Whether the inputed text can exceed its boundary.
488    */
489   void SetExceedEnabled( bool enable );
490
491   /**
492    * @brief Retrieves whether inputed text can exceed the text-input boundary.
493    *
494    * @return \e true if text inputed can exceed the boundary, otherwise \e false.
495    */
496   bool GetExceedEnabled() const;
497
498   /**
499    * @brief Allows modification of text-actor's position in the depth sort algorithm.
500    *
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.
503    */
504   void SetSortModifier( float depthOffset );
505
506   /**
507    * @brief Sets whether text-view renders text using a previously generated snapshot.
508    *
509    * @see TextView::SetSnapshotModeEnabled()
510    *
511    * @param[in] enable Whether text-view is using or not a snapshot to render text.
512    */
513   void SetSnapshotModeEnabled( bool enable );
514
515   /**
516    * @brief Retrieves whether text-view is using a snapshot to render text.
517    *
518    * @see TextView::IsSnapshotModeEnabled()
519    *
520    * @return \e true if text-view is using a snapshot to render text, otherwhise it returns \e false.
521    */
522   bool IsSnapshotModeEnabled() const;
523
524   /**
525    * @copydoc TextView::SetScrollEnabled()
526    */
527   void SetScrollEnabled( bool enable );
528
529   /**
530    * @copydoc TextView::IsScrollEnabled()
531    */
532   bool IsScrollEnabled() const;
533
534   /**
535    * @copydoc TextView::SetScrollPosition()
536    */
537   void SetScrollPosition( const Vector2& position );
538
539   /**
540    * @copydoc TextView::GetScrollPosition()
541    */
542   Vector2 GetScrollPosition() const;
543
544   /**
545    * @brief Sets whether markup processing should be carried out.
546    *
547    * @param[in] enable whether markup processing is carried out or not.
548    */
549   void SetMarkupProcessingEnabled( bool enable );
550
551   /**
552    * @brief Returns whether markup processing is enabled or not
553    *
554    * @return true is markup processing is enabled
555    */
556   bool IsMarkupProcessingEnabled() const;
557
558
559 public: /* Signals */
560
561   /// @brief Input Signal.
562   typedef SignalV2< void ( TextInput textInput ) > InputSignalV2;
563
564   /// @brief Input style changed signal.
565   typedef SignalV2< void ( TextInput textInput, const TextStyle& style ) > StyleChangedSignalV2;
566
567   /// @brief Text modified signal.
568   typedef SignalV2< void ( TextInput textInput  ) > TextModifiedSignalType;
569
570   /// @brief Max input characters reached signal.
571   typedef SignalV2< void ( TextInput textInput ) > MaxInputCharactersReachedSignalV2;
572
573   /// @brief Input text exceeds boundaries signal.
574   typedef SignalV2< void ( TextInput textInput ) > InputTextExceedBoundariesSignalV2;
575
576   /**
577    * @brief Signal emitted when the Text-Input starts receiving input.
578    */
579   InputSignalV2& InputStartedSignal();
580
581   /**
582    * @brief Signal emitted when the Text-Input is finished receiving input.
583    *
584    * TextInput::GetText() can be called to get current text string.
585    * @return The signal to connect to
586    */
587   InputSignalV2& InputFinishedSignal();
588
589   /**
590    * @brief Signal emitted when the cut and paste toolbar is displayed.
591    *
592    * @return The signal to connect to
593    */
594   InputSignalV2& CutAndPasteToolBarDisplayedSignal();
595
596   /**
597    * @brief Signal emitted when style changes.
598    *
599    * @return The signal to connect to
600    */
601   StyleChangedSignalV2& StyleChangedSignal();
602
603   /**
604    * @brief Signal emitted when text changes.
605    *
606    * @return The signal to connect to.
607    */
608   TextModifiedSignalType& TextModifiedSignal();
609
610   /**
611    * @brief Signal emitted when max input characters are reached during text input.
612    *
613    * @return The signal to connect to
614    */
615   MaxInputCharactersReachedSignalV2& MaxInputCharactersReachedSignal();
616
617   /**
618    * @brief Signal emitted when input text exceeds the boundaries of the text-input.
619    *
620    * @return The signal to connect to
621    */
622   InputTextExceedBoundariesSignalV2& InputTextExceedBoundariesSignal();
623
624 public: // Not intended for application developers
625
626   /**
627    * @brief Creates a handle using the Toolkit::Internal implementation.
628    *
629    * @param[in]  implementation  The Control implementation.
630    */
631   TextInput(Internal::TextInput& implementation);
632
633   /**
634    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
635    *
636    * @param[in]  internal  A pointer to the internal CustomActor.
637    */
638   TextInput(Dali::Internal::CustomActor* internal );
639 };
640
641 } // namespace Toolkit
642
643 } // namespace Dali
644
645 /**
646  * @}
647  */
648 #endif // __DALI_TOOLKIT_TEXT_INPUT_H__