[dali_1.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.h
1 #ifndef DALI_TOOLKIT_TEXT_CONTROLLER_H
2 #define DALI_TOOLKIT_TEXT_CONTROLLER_H
3
4 /*
5  * Copyright (c) 2018 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 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/imf-manager.h>
23 #include <dali/public-api/events/gesture.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/text/text-enumerations.h>
27 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
28 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
29 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
30 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
31 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
32 #include <dali-toolkit/internal/text/hidden-text.h>
33 #include <dali-toolkit/internal/text/text-model-interface.h>
34
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Text
42 {
43
44 class Controller;
45 class ControlInterface;
46 class EditableControlInterface;
47 class View;
48 class RenderingController;
49
50 typedef IntrusivePtr<Controller> ControllerPtr;
51
52 /**
53  * @brief A Text Controller is used by UI Controls which display text.
54  *
55  * It manipulates the Logical & Visual text models on behalf of the UI Controls.
56  * It provides a view of the text that can be used by rendering back-ends.
57  *
58  * For selectable/editable UI controls, the controller handles input events from the UI control
59  * and decorations (grab handles etc) via the Decorator::ControllerInterface interface.
60  *
61  * The text selection popup button callbacks are as well handled via the TextSelectionPopupCallbackInterface interface.
62  */
63 class Controller : public RefObject, public Decorator::ControllerInterface, public TextSelectionPopupCallbackInterface, public HiddenText::Observer
64 {
65 public: // Enumerated types.
66
67   /**
68    * @brief Text related operations to be done in the relayout process.
69    */
70   enum OperationsMask
71   {
72     NO_OPERATION       = 0x0000,
73     CONVERT_TO_UTF32   = 0x0001,
74     GET_SCRIPTS        = 0x0002,
75     VALIDATE_FONTS     = 0x0004,
76     GET_LINE_BREAKS    = 0x0008,
77     GET_WORD_BREAKS    = 0x0010,
78     BIDI_INFO          = 0x0020,
79     SHAPE_TEXT         = 0x0040,
80     GET_GLYPH_METRICS  = 0x0080,
81     LAYOUT             = 0x0100,
82     UPDATE_LAYOUT_SIZE = 0x0200,
83     REORDER            = 0x0400,
84     ALIGN              = 0x0800,
85     COLOR              = 0x1000,
86     UPDATE_DIRECTION   = 0x2000,
87     ALL_OPERATIONS     = 0xFFFF
88   };
89
90   /**
91    * @brief Used to distinguish between regular key events and IMF events
92    */
93   enum InsertType
94   {
95     COMMIT,
96     PRE_EDIT
97   };
98
99   /**
100    * @brief Used to specify whether to update the input style.
101    */
102   enum UpdateInputStyleType
103   {
104     UPDATE_INPUT_STYLE,
105     DONT_UPDATE_INPUT_STYLE
106   };
107
108   /**
109    * @brief Used to specify what has been updated after the Relayout() method has been called.
110    */
111   enum UpdateTextType
112   {
113     NONE_UPDATED      = 0x0, ///< Nothing has been updated.
114     MODEL_UPDATED     = 0x1, ///< The text's model has been updated.
115     DECORATOR_UPDATED = 0x2  ///< The decoration has been updated.
116   };
117
118   /**
119    * @brief Different placeholder-text can be shown when the control is active/inactive.
120    */
121   enum PlaceholderType
122   {
123     PLACEHOLDER_TYPE_ACTIVE,
124     PLACEHOLDER_TYPE_INACTIVE,
125   };
126
127   /**
128    * @brief Enumeration for Font Size Type.
129    */
130   enum FontSizeType
131   {
132     POINT_SIZE,   // The size of font in points.
133     PIXEL_SIZE    // The size of font in pixels.
134   };
135
136   struct NoTextTap
137   {
138     enum Action
139     {
140       NO_ACTION,           ///< Does no action if there is a tap on top of an area with no text.
141       HIGHLIGHT,           ///< Highlights the nearest text (at the beginning or end of the text) and shows the text's selection popup.
142       SHOW_SELECTION_POPUP ///< Shows the text's selection popup.
143     };
144   };
145
146 public: // Constructor.
147
148   /**
149    * @brief Create a new instance of a Controller.
150    *
151    * @return A pointer to a new Controller.
152    */
153   static ControllerPtr New();
154
155   /**
156    * @brief Create a new instance of a Controller.
157    *
158    * @param[in] controlInterface The control's interface.
159    *
160    * @return A pointer to a new Controller.
161    */
162   static ControllerPtr New( ControlInterface* controlInterface );
163
164   /**
165    * @brief Create a new instance of a Controller.
166    *
167    * @param[in] controlInterface The control's interface.
168    * @param[in] editableControlInterface The editable control's interface.
169    *
170    * @return A pointer to a new Controller.
171    */
172   static ControllerPtr New( ControlInterface* controlInterface,
173                             EditableControlInterface* editableControlInterface );
174
175 public: // Configure the text controller.
176
177   /**
178    * @brief Called to enable text input.
179    *
180    * @note Selectable or editable controls should call this once after Controller::New().
181    * @param[in] decorator Used to create cursor, selection handle decorations etc.
182    */
183   void EnableTextInput( DecoratorPtr decorator );
184
185   /**
186    * @brief Used to switch between bitmap & vector based glyphs
187    *
188    * @param[in] glyphType The type of glyph; note that metrics for bitmap & vector based glyphs are different.
189    */
190   void SetGlyphType( TextAbstraction::GlyphType glyphType );
191
192   /**
193    * @brief Enables/disables the mark-up processor.
194    *
195    * By default is disabled.
196    *
197    * @param[in] enable Whether to enable the mark-up processor.
198    */
199   void SetMarkupProcessorEnabled( bool enable );
200
201   /**
202    * @brief Retrieves whether the mark-up processor is enabled.
203    *
204    * By default is disabled.
205    *
206    * @return @e true if the mark-up processor is enabled, otherwise returns @e false.
207    */
208   bool IsMarkupProcessorEnabled() const;
209
210   /**
211    * @brief Enables/disables the auto text scrolling
212    *
213    * By default is disabled.
214    *
215    * @param[in] enable Whether to enable the auto scrolling
216    */
217   void SetAutoScrollEnabled( bool enable );
218
219   /**
220    * @brief Retrieves whether auto text scrolling is enabled.
221    *
222    * By default is disabled.
223    *
224    * @return @e true if auto scrolling is enabled, otherwise returns @e false.
225    */
226   bool IsAutoScrollEnabled() const;
227
228   /**
229    * @brief Get direction of the text from the first line of text,
230    * @return bool rtl (right to left) is true
231    */
232   CharacterDirection GetAutoScrollDirection() const;
233
234   /**
235    * @brief Get the alignment offset of the first line of text.
236    *
237    * @return The alignment offset.
238    */
239   float GetAutoScrollLineAlignment() const;
240
241   /**
242    * @brief Enables the horizontal scrolling.
243    *
244    * @param[in] enable Whether to enable the horizontal scrolling.
245    */
246   void SetHorizontalScrollEnabled( bool enable );
247
248   /**
249    * @brief Retrieves whether the horizontal scrolling is enabled.
250    *
251    * @return @e true if the horizontal scrolling is enabled, otherwise it returns @e false.
252    */
253   bool IsHorizontalScrollEnabled() const;
254
255   /**
256    * @brief Enables the vertical scrolling.
257    *
258    * @param[in] enable Whether to enable the vertical scrolling.
259    */
260   void SetVerticalScrollEnabled( bool enable );
261
262   /**
263    * @brief Retrieves whether the verticall scrolling is enabled.
264    *
265    * @return @e true if the vertical scrolling is enabled, otherwise it returns @e false.
266    */
267   bool IsVerticalScrollEnabled() const;
268
269   /**
270    * @brief Enables the smooth handle panning.
271    *
272    * @param[in] enable Whether to enable the smooth handle panning.
273    */
274   void SetSmoothHandlePanEnabled( bool enable );
275
276   /**
277    * @brief Retrieves whether the smooth handle panning is enabled.
278    *
279    * @return @e true if the smooth handle panning is enabled.
280    */
281   bool IsSmoothHandlePanEnabled() const;
282
283   /**
284    * @brief Sets the maximum number of characters that can be inserted into the TextModel
285    *
286    * @param[in] maxCharacters maximum number of characters to be accepted
287    */
288   void SetMaximumNumberOfCharacters( Length maxCharacters );
289
290   /**
291    * @brief Sets the maximum number of characters that can be inserted into the TextModel
292    *
293    * @param[in] maxCharacters maximum number of characters to be accepted
294    */
295   int GetMaximumNumberOfCharacters();
296
297   /**
298    * @brief Called to enable/disable cursor blink.
299    *
300    * @note Only editable controls should calls this.
301    * @param[in] enabled Whether the cursor should blink or not.
302    */
303   void SetEnableCursorBlink( bool enable );
304
305   /**
306    * @brief Query whether cursor blink is enabled.
307    *
308    * @return Whether the cursor should blink or not.
309    */
310   bool GetEnableCursorBlink() const;
311
312   /**
313    * @brief Whether to enable the multi-line layout.
314    *
315    * @param[in] enable \e true enables the multi-line (by default)
316    */
317   void SetMultiLineEnabled( bool enable );
318
319   /**
320    * @return Whether the multi-line layout is enabled.
321    */
322   bool IsMultiLineEnabled() const;
323
324   /**
325    * @brief Sets the text's horizontal alignment.
326    *
327    * @param[in] alignment The horizontal alignment.
328    */
329   void SetHorizontalAlignment( HorizontalAlignment::Type alignment );
330
331   /**
332    * @copydoc ModelInterface::GetHorizontalAlignment()
333    */
334   HorizontalAlignment::Type GetHorizontalAlignment() const;
335
336   /**
337    * @brief Sets the text's vertical alignment.
338    *
339    * @param[in] alignment The vertical alignment.
340    */
341   void SetVerticalAlignment( VerticalAlignment::Type alignment );
342
343   /**
344    * @copydoc ModelInterface::GetVerticalAlignment()
345    */
346   VerticalAlignment::Type GetVerticalAlignment() const;
347
348   /**
349    * @brief Sets the text's wrap mode
350    * @param[in] text wrap mode The unit of wrapping
351    */
352   void SetLineWrapMode( Text::LineWrap::Mode textWarpMode );
353
354   /**
355    * @brief Retrieve text wrap mode previously set.
356    * @return text wrap mode
357    */
358   Text::LineWrap::Mode GetLineWrapMode() const;
359
360   /**
361    * @brief Enable or disable the text elide.
362    *
363    * @param[in] enabled Whether to enable the text elide.
364    */
365   void SetTextElideEnabled( bool enabled );
366
367   /**
368    * @copydoc ModelInterface::IsTextElideEnabled()
369    */
370   bool IsTextElideEnabled() const;
371
372   /**
373    * @brief Enable or disable the placeholder text elide.
374    * @param enabled Whether to enable the placeholder text elide.
375    */
376   void SetPlaceholderTextElideEnabled( bool enabled );
377
378   /**
379    * @brief Whether the placeholder text elide property is enabled.
380    * @return True if the placeholder text elide property is enabled, false otherwise.
381    */
382   bool IsPlaceholderTextElideEnabled() const;
383
384   /**
385    * @brief Enable or disable the text selection.
386    * @param[in] enabled Whether to enable the text selection.
387    */
388   void SetSelectionEnabled( bool enabled );
389
390   /**
391    * @brief Whether the text selection is enabled or not.
392    * @return True if the text selection is enabled
393    */
394   bool IsSelectionEnabled() const;
395
396   /**
397    * @brief Enable or disable the text selection using Shift key.
398    * @param enabled Whether to enable the text selection using Shift key
399    */
400   void SetShiftSelectionEnabled( bool enabled );
401
402   /**
403    * @brief Whether the text selection using Shift key is enabled or not.
404    * @return True if the text selection using Shift key is enabled
405    */
406   bool IsShiftSelectionEnabled() const;
407
408   /**
409    * @brief Enable or disable the grab handles for text selection.
410    *
411    * @param[in] enabled Whether to enable the grab handles
412    */
413   void SetGrabHandleEnabled( bool enabled );
414
415   /**
416    * @brief Returns whether the grab handles are enabled.
417    *
418    * @return True if the grab handles are enabled
419    */
420   bool IsGrabHandleEnabled() const;
421
422   /**
423    * @brief Sets input type to password
424    *
425    * @note The string is displayed hidden character
426    *
427    * @param[in] passwordInput True if password input is enabled.
428    */
429   void SetInputModePassword( bool passwordInput );
430
431   /**
432    * @brief Returns whether the input mode type is set as password.
433    *
434    * @return True if input mode type is password
435    */
436   bool IsInputModePassword();
437
438   /**
439    * @brief Sets the action when there is a double tap event on top of a text area with no text.
440    *
441    * @param[in] action The action to do.
442    */
443   void SetNoTextDoubleTapAction( NoTextTap::Action action );
444
445   /**
446    * @brief Retrieves the action when there is a double tap event on top of a text area with no text.
447    *
448    * @return The action to do.
449    */
450   NoTextTap::Action GetNoTextDoubleTapAction() const;
451
452   /**
453    * @briefSets the action when there is a long press event on top of a text area with no text.
454    *
455    * @param[in] action The action to do.
456    */
457   void SetNoTextLongPressAction( NoTextTap::Action action );
458
459   /**
460    * @brief Retrieves the action when there is a long press event on top of a text area with no text.
461    *
462    * @return The action to do.
463    */
464   NoTextTap::Action GetNoTextLongPressAction() const;
465
466   /**
467    * @brief Query if Underline settings were provided by string or map
468    * @return bool true if set by string
469    */
470   bool IsUnderlineSetByString();
471
472   /**
473    * Set method underline setting were set by
474    * @param[in] bool, true if set by string
475    */
476   void UnderlineSetByString( bool setByString );
477
478   /**
479    * @brief Query if shadow settings were provided by string or map
480    * @return bool true if set by string
481    */
482   bool IsShadowSetByString();
483
484   /**
485    * Set method shadow setting were set by
486    * @param[in] bool, true if set by string
487    */
488   void ShadowSetByString( bool setByString );
489
490   /**
491    * @brief Query if outline settings were provided by string or map
492    * @return bool true if set by string
493    */
494   bool IsOutlineSetByString();
495
496   /**
497    * Set method outline setting were set by
498    * @param[in] bool, true if set by string
499    */
500   void OutlineSetByString( bool setByString );
501
502   /**
503    * @brief Query if font style settings were provided by string or map
504    * @return bool true if set by string
505    */
506   bool IsFontStyleSetByString();
507
508   /**
509    * Set method font style setting were set by
510    * @param[in] bool, true if set by string
511    */
512   void FontStyleSetByString( bool setByString );
513
514 public: // Update.
515
516   /**
517    * @brief Replaces any text previously set.
518    *
519    * @note This will be converted into UTF-32 when stored in the text model.
520    * @param[in] text A string of UTF-8 characters.
521    */
522   void SetText( const std::string& text );
523
524   /**
525    * @brief Retrieve any text previously set.
526    *
527    * @param[out] text A string of UTF-8 characters.
528    */
529   void GetText( std::string& text ) const;
530
531   /**
532    * @brief Replaces any placeholder text previously set.
533    *
534    * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
535    * @param[in] text A string of UTF-8 characters.
536    */
537   void SetPlaceholderText( PlaceholderType type, const std::string& text );
538
539   /**
540    * @brief Retrieve any placeholder text previously set.
541    *
542    * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
543    * @param[out] A string of UTF-8 characters.
544    */
545   void GetPlaceholderText( PlaceholderType type, std::string& text ) const;
546
547   /**
548    * @ brief Update the text after a font change
549    * @param[in] newDefaultFont The new font to change to
550    */
551   void UpdateAfterFontChange( const std::string& newDefaultFont );
552
553 public: // Default style & Input style
554
555   /**
556    * @brief Set the default font family.
557    *
558    * @param[in] defaultFontFamily The default font family.
559    */
560   void SetDefaultFontFamily( const std::string& defaultFontFamily );
561
562   /**
563    * @brief Retrieve the default font family.
564    *
565    * @return The default font family.
566    */
567   const std::string& GetDefaultFontFamily() const;
568
569   /**
570    * @brief Sets the placeholder text font family.
571    * @param[in] placeholderTextFontFamily The placeholder text font family.
572    */
573   void SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily );
574
575   /**
576    * @brief Retrieves the placeholder text font family.
577    *
578    * @return The placeholder text font family
579    */
580   const std::string& GetPlaceholderFontFamily() const;
581
582   /**
583    * @brief Sets the default font weight.
584    *
585    * @param[in] weight The font weight.
586    */
587   void SetDefaultFontWeight( FontWeight weight );
588
589   /**
590    * @brief Whether the font's weight has been defined.
591    */
592   bool IsDefaultFontWeightDefined() const;
593
594   /**
595    * @brief Retrieves the default font weight.
596    *
597    * @return The default font weight.
598    */
599   FontWeight GetDefaultFontWeight() const;
600
601   /**
602    * @brief Sets the placeholder text font weight.
603    *
604    * @param[in] weight The font weight
605    */
606   void SetPlaceholderTextFontWeight( FontWeight weight );
607
608   /**
609    * @brief Whether the font's weight has been defined.
610    *
611    * @return True if the placeholder text font weight is defined
612    */
613   bool IsPlaceholderTextFontWeightDefined() const;
614
615   /**
616    * @brief Retrieves the placeholder text font weight.
617    *
618    * @return The placeholder text font weight
619    */
620   FontWeight GetPlaceholderTextFontWeight() const;
621
622   /**
623    * @brief Sets the default font width.
624    *
625    * @param[in] width The font width.
626    */
627   void SetDefaultFontWidth( FontWidth width );
628
629   /**
630    * @brief Whether the font's width has been defined.
631    */
632   bool IsDefaultFontWidthDefined() const;
633
634   /**
635    * @brief Retrieves the default font width.
636    *
637    * @return The default font width.
638    */
639   FontWidth GetDefaultFontWidth() const;
640
641   /**
642    * @brief Sets the placeholder text font width.
643    *
644    * @param[in] width The font width
645    */
646   void SetPlaceholderTextFontWidth( FontWidth width );
647
648   /**
649    * @brief Whether the font's width has been defined.
650    *
651    * @return True if the placeholder text font width is defined
652    */
653   bool IsPlaceholderTextFontWidthDefined() const;
654
655   /**
656    * @brief Retrieves the placeholder text font width.
657    *
658    * @return The placeholder text font width
659    */
660   FontWidth GetPlaceholderTextFontWidth() const;
661
662   /**
663    * @brief Sets the default font slant.
664    *
665    * @param[in] slant The font slant.
666    */
667   void SetDefaultFontSlant( FontSlant slant );
668
669   /**
670    * @brief Whether the font's slant has been defined.
671    */
672   bool IsDefaultFontSlantDefined() const;
673
674   /**
675    * @brief Retrieves the default font slant.
676    *
677    * @return The default font slant.
678    */
679   FontSlant GetDefaultFontSlant() const;
680
681   /**
682    * @brief Sets the placeholder text font slant.
683    *
684    * @param[in] slant The font slant
685    */
686   void SetPlaceholderTextFontSlant( FontSlant slant );
687
688   /**
689    * @brief Whether the font's slant has been defined.
690    *
691    * @return True if the placeholder text font slant is defined
692    */
693   bool IsPlaceholderTextFontSlantDefined() const;
694
695   /**
696    * @brief Retrieves the placeholder text font slant.
697    *
698    * @return The placeholder text font slant
699    */
700   FontSlant GetPlaceholderTextFontSlant() const;
701
702   /**
703    * @brief Set the default font size.
704    *
705    * @param[in] fontSize The default font size
706    * @param[in] type The font size type is point size or pixel size
707    */
708   void SetDefaultFontSize( float fontSize, FontSizeType type );
709
710   /**
711    * @brief Retrieve the default point size.
712    *
713    * @param[in] type The font size type
714    * @return The default point size.
715    */
716   float GetDefaultFontSize( FontSizeType type ) const;
717
718   /**
719    * @brief Sets the Placeholder text font size.
720    * @param[in] fontSize The placeholder text font size
721    * @param[in] type The font size type is point size or pixel size
722    */
723   void SetPlaceholderTextFontSize( float fontSize, FontSizeType type );
724
725   /**
726    * @brief Retrieves the Placeholder text font size.
727    * @param[in] type The font size type
728    * @return The placeholder font size
729    */
730   float GetPlaceholderTextFontSize( FontSizeType type ) const;
731
732   /**
733    * @brief Sets the text's default color.
734    *
735    * @param color The default color.
736    */
737   void SetDefaultColor( const Vector4& color );
738
739   /**
740    * @brief Retrieves the text's default color.
741    *
742    * @return The default color.
743    */
744   const Vector4& GetDefaultColor() const;
745
746   /**
747    * @brief Set the text color
748    *
749    * @param textColor The text color
750    */
751   void SetPlaceholderTextColor( const Vector4& textColor );
752
753   /**
754    * @brief Retrieve the text color
755    *
756    * @return The text color
757    */
758   const Vector4& GetPlaceholderTextColor() const;
759
760   /**
761    * @brief Set the shadow offset.
762    *
763    * @param[in] shadowOffset The shadow offset, 0,0 indicates no shadow.
764    */
765   void SetShadowOffset( const Vector2& shadowOffset );
766
767   /**
768    * @brief Retrieve the shadow offset.
769    *
770    * @return The shadow offset.
771    */
772   const Vector2& GetShadowOffset() const;
773
774   /**
775    * @brief Set the shadow color.
776    *
777    * @param[in] shadowColor The shadow color.
778    */
779   void SetShadowColor( const Vector4& shadowColor );
780
781   /**
782    * @brief Retrieve the shadow color.
783    *
784    * @return The shadow color.
785    */
786   const Vector4& GetShadowColor() const;
787
788   /**
789    * @brief Set the shadow blur radius.
790    *
791    * @param[in] shadowBlurRadius The shadow blur radius, 0,0 indicates no blur.
792    */
793   void SetShadowBlurRadius( const float& shadowBlurRadius );
794
795   /**
796    * @brief Retrieve the shadow blur radius.
797    *
798    * @return The shadow blur radius.
799    */
800   const float& GetShadowBlurRadius() const;
801
802   /**
803    * @brief Set the underline color.
804    *
805    * @param[in] color color of underline.
806    */
807   void SetUnderlineColor( const Vector4& color );
808
809   /**
810    * @brief Retrieve the underline color.
811    *
812    * @return The underline color.
813    */
814   const Vector4& GetUnderlineColor() const;
815
816   /**
817    * @brief Set the underline enabled flag.
818    *
819    * @param[in] enabled The underline enabled flag.
820    */
821   void SetUnderlineEnabled( bool enabled );
822
823   /**
824    * @brief Returns whether the text is underlined or not.
825    *
826    * @return The underline state.
827    */
828   bool IsUnderlineEnabled() const;
829
830   /**
831    * @brief Set the override used for underline height, 0 indicates height will be supplied by font metrics
832    *
833    * @param[in] height The height in pixels of the underline
834    */
835   void SetUnderlineHeight( float height );
836
837   /**
838    * @brief Retrieves the override height of an underline, 0 indicates height is supplied by font metrics
839    *
840    * @return The height of the underline, or 0 if height is not overrided.
841    */
842   float GetUnderlineHeight() const;
843
844   /**
845    * @brief Set the outline color.
846    *
847    * @param[in] color color of outline.
848    */
849   void SetOutlineColor( const Vector4& color );
850
851   /**
852    * @brief Retrieve the outline color.
853    *
854    * @return The outline color.
855    */
856   const Vector4& GetOutlineColor() const;
857
858   /**
859    * @brief Set the outline width
860    *
861    * @param[in] width The width in pixels of the outline, 0 indicates no outline
862    */
863   void SetOutlineWidth( unsigned int width );
864
865   /**
866    * @brief Retrieves the width of an outline
867    *
868    * @return The width of the outline.
869    */
870   unsigned int GetOutlineWidth() const;
871
872   /**
873    * @brief Set the background color.
874    *
875    * @param[in] color color of background.
876    */
877   void SetBackgroundColor( const Vector4& color );
878
879   /**
880    * @brief Retrieve the background color.
881    *
882    * @return The background color.
883    */
884   const Vector4& GetBackgroundColor() const;
885
886   /**
887    * @brief Set the background enabled flag.
888    *
889    * @param[in] enabled The background enabled flag.
890    */
891   void SetBackgroundEnabled( bool enabled );
892
893   /**
894    * @brief Returns whether to enable text background or not.
895    *
896    * @return Whether text background is enabled.
897    */
898   bool IsBackgroundEnabled() const;
899
900   /**
901    * @brief Sets the emboss's properties string.
902    *
903    * @note The string is stored to be recovered.
904    *
905    * @param[in] embossProperties The emboss's properties string.
906    */
907   void SetDefaultEmbossProperties( const std::string& embossProperties );
908
909   /**
910    * @brief Retrieves the emboss's properties string.
911    *
912    * @return The emboss's properties string.
913    */
914   const std::string& GetDefaultEmbossProperties() const;
915
916   /**
917    * @brief Sets the outline's properties string.
918    *
919    * @note The string is stored to be recovered.
920    *
921    * @param[in] outlineProperties The outline's properties string.
922    */
923   void SetDefaultOutlineProperties( const std::string& outlineProperties );
924
925   /**
926    * @brief Retrieves the outline's properties string.
927    *
928    * @return The outline's properties string.
929    */
930   const std::string& GetDefaultOutlineProperties() const;
931
932   /**
933    * @brief Sets the default line spacing.
934    *
935    * @param[in] lineSpacing The line spacing.
936    *
937    * @return True if lineSpacing has been updated, false otherwise
938    */
939   bool SetDefaultLineSpacing( float lineSpacing );
940
941   /**
942    * @brief Retrieves the default line spacing.
943    *
944    * @return The line spacing.
945    */
946   float GetDefaultLineSpacing() const;
947
948   /**
949    * @brief Sets the input text's color.
950    *
951    * @param[in] color The input text's color.
952    */
953   void SetInputColor( const Vector4& color );
954
955   /**
956    * @brief Retrieves the input text's color.
957    *
958    * @return The input text's color.
959    */
960   const Vector4& GetInputColor() const;
961
962   /**
963    * @brief Sets the input text's font family name.
964    *
965    * @param[in] fontFamily The text's font family name.
966    */
967   void SetInputFontFamily( const std::string& fontFamily );
968
969   /**
970    * @brief Retrieves the input text's font family name.
971    *
972    * @return The input text's font family name.
973    */
974   const std::string& GetInputFontFamily() const;
975
976   /**
977    * @brief Sets the input font's weight.
978    *
979    * @param[in] weight The input font's weight.
980    */
981   void SetInputFontWeight( FontWeight weight );
982
983   /**
984    * @return Whether the font's weight has been defined.
985    */
986   bool IsInputFontWeightDefined() const;
987
988   /**
989    * @brief Retrieves the input font's weight.
990    *
991    * @return The input font's weight.
992    */
993   FontWeight GetInputFontWeight() const;
994
995   /**
996    * @brief Sets the input font's width.
997    *
998    * @param[in] width The input font's width.
999    */
1000   void SetInputFontWidth( FontWidth width );
1001
1002   /**
1003    * @return Whether the font's width has been defined.
1004    */
1005   bool IsInputFontWidthDefined() const;
1006
1007   /**
1008    * @brief Retrieves the input font's width.
1009    *
1010    * @return The input font's width.
1011    */
1012   FontWidth GetInputFontWidth() const;
1013
1014   /**
1015    * @brief Sets the input font's slant.
1016    *
1017    * @param[in] slant The input font's slant.
1018    */
1019   void SetInputFontSlant( FontSlant slant );
1020
1021   /**
1022    * @return Whether the font's slant has been defined.
1023    */
1024   bool IsInputFontSlantDefined() const;
1025
1026   /**
1027    * @brief Retrieves the input font's slant.
1028    *
1029    * @return The input font's slant.
1030    */
1031   FontSlant GetInputFontSlant() const;
1032
1033   /**
1034    * @brief Sets the input font's point size.
1035    *
1036    * @param[in] size The input font's point size.
1037    */
1038   void SetInputFontPointSize( float size );
1039
1040   /**
1041    * @brief Retrieves the input font's point size.
1042    *
1043    * @return The input font's point size.
1044    */
1045   float GetInputFontPointSize() const;
1046
1047   /**
1048    * @brief Sets the input line spacing.
1049    *
1050    * @param[in] lineSpacing The line spacing.
1051    */
1052   void SetInputLineSpacing( float lineSpacing );
1053
1054   /**
1055    * @brief Retrieves the input line spacing.
1056    *
1057    * @return The line spacing.
1058    */
1059   float GetInputLineSpacing() const;
1060
1061   /**
1062    * @brief Sets the input shadow's properties string.
1063    *
1064    * @note The string is stored to be recovered.
1065    *
1066    * @param[in] shadowProperties The shadow's properties string.
1067    */
1068   void SetInputShadowProperties( const std::string& shadowProperties );
1069
1070   /**
1071    * @brief Retrieves the input shadow's properties string.
1072    *
1073    * @return The shadow's properties string.
1074    */
1075   const std::string& GetInputShadowProperties() const;
1076
1077   /**
1078    * @brief Sets the input underline's properties string.
1079    *
1080    * @note The string is stored to be recovered.
1081    *
1082    * @param[in] underlineProperties The underline's properties string.
1083    */
1084   void SetInputUnderlineProperties( const std::string& underlineProperties );
1085
1086   /**
1087    * @brief Retrieves the input underline's properties string.
1088    *
1089    * @return The underline's properties string.
1090    */
1091   const std::string& GetInputUnderlineProperties() const;
1092
1093   /**
1094    * @brief Sets the input emboss's properties string.
1095    *
1096    * @note The string is stored to be recovered.
1097    *
1098    * @param[in] embossProperties The emboss's properties string.
1099    */
1100   void SetInputEmbossProperties( const std::string& embossProperties );
1101
1102   /**
1103    * @brief Retrieves the input emboss's properties string.
1104    *
1105    * @return The emboss's properties string.
1106    */
1107   const std::string& GetInputEmbossProperties() const;
1108
1109   /**
1110    * @brief Sets input the outline's properties string.
1111    *
1112    * @note The string is stored to be recovered.
1113    *
1114    * @param[in] outlineProperties The outline's properties string.
1115    */
1116   void SetInputOutlineProperties( const std::string& outlineProperties );
1117
1118   /**
1119    * @brief Retrieves the input outline's properties string.
1120    *
1121    * @return The outline's properties string.
1122    */
1123   const std::string& GetInputOutlineProperties() const;
1124
1125   /**
1126    * @brief Set the control's interface.
1127    *
1128    * @param[in] controlInterface The control's interface.
1129    */
1130   void SetControlInterface( ControlInterface* controlInterface );
1131
1132 public: // Queries & retrieves.
1133
1134   /**
1135    * @brief Return the layout engine.
1136    *
1137    * @return A reference to the layout engine.
1138    */
1139   Layout::Engine& GetLayoutEngine();
1140
1141   /**
1142    * @brief Return a view of the text.
1143    *
1144    * @return A reference to the view.
1145    */
1146   View& GetView();
1147
1148   /**
1149    * @copydoc Control::GetNaturalSize()
1150    */
1151   Vector3 GetNaturalSize();
1152
1153   /**
1154    * @copydoc Control::GetHeightForWidth()
1155    */
1156   float GetHeightForWidth( float width );
1157
1158   /**
1159    * @brief Retrieves the text's number of lines for a given width.
1160    * @param[in] width The width of the text's area.
1161    * @ return The number of lines.
1162    */
1163   int GetLineCount( float width );
1164
1165   /**
1166    * @brief Retrieves the text's model.
1167    *
1168    * @return A pointer to the text's model.
1169    */
1170   const ModelInterface* const GetTextModel() const;
1171
1172   /**
1173    * @brief Used to get scrolled distance by user input
1174    *
1175    * @return Distance from last scroll offset to new scroll offset
1176    */
1177   float GetScrollAmountByUserInput();
1178
1179   /**
1180    * @brief Get latest scroll amount, control size and layout size
1181    *
1182    * This method is used to get information of control's scroll
1183    * @param[out] scrollPosition The current scrolled position
1184    * @param[out] controlHeight The size of a UI control
1185    * @param[out] layoutHeight The size of a bounding box to layout text within.
1186    *
1187    * @return Whether the text scroll position is changed or not after last update.
1188    */
1189   bool GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight );
1190
1191   /**
1192    * @brief Used to set the hidden input option
1193    */
1194   void SetHiddenInputOption( const Property::Map& options );
1195
1196   /**
1197    * @brief Used to get the hidden input option
1198    */
1199   void GetHiddenInputOption( Property::Map& options );
1200
1201   /**
1202    * @brief Sets the Placeholder Properties.
1203    *
1204    * @param[in] map The placeholder property map
1205    */
1206   void SetPlaceholderProperty( const Property::Map& map );
1207
1208   /**
1209    * @brief Retrieves the Placeholder Property map.
1210    *
1211    * @param[out] map The property map
1212    */
1213   void GetPlaceholderProperty( Property::Map& map );
1214
1215   /**
1216    * @brief Checks text direction.
1217    * @return The text direction.
1218    */
1219   Toolkit::DevelText::TextDirection::Type GetTextDirection();
1220
1221   /**
1222    * @brief Retrieves vertical line alignment
1223    * @return The vertical line alignment
1224    */
1225   Toolkit::DevelText::VerticalLineAlignment::Type GetVerticalLineAlignment() const;
1226
1227   /**
1228    * @brief Sets vertical line alignment
1229    * @param[in] alignment The vertical line alignment for the text
1230    */
1231   void SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment );
1232
1233 public: // Relayout.
1234
1235   /**
1236    * @brief Triggers a relayout which updates View (if necessary).
1237    *
1238    * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
1239    * @param[in] size A the size of a bounding box to layout text within.
1240    *
1241    * @return Whether the text model or decorations were updated.
1242    */
1243   UpdateTextType Relayout( const Size& size );
1244
1245   /**
1246    * @brief Request a relayout using the ControlInterface.
1247    */
1248   void RequestRelayout();
1249
1250 public: // Input style change signals.
1251
1252   /**
1253    * @return Whether the queue of input style changed signals is empty.
1254    */
1255   bool IsInputStyleChangedSignalsQueueEmpty();
1256
1257   /**
1258    * @brief Process all pending input style changed signals.
1259    *
1260    * Calls the Text::ControlInterface::InputStyleChanged() method which is overriden by the
1261    * text controls. Text controls may send signals to state the input style has changed.
1262    */
1263   void ProcessInputStyleChangedSignals();
1264
1265 public: // Text-input Event Queuing.
1266
1267   /**
1268    * @brief Called by editable UI controls when keyboard focus is gained.
1269    */
1270   void KeyboardFocusGainEvent();
1271
1272   /**
1273    * @brief Called by editable UI controls when focus is lost.
1274    */
1275   void KeyboardFocusLostEvent();
1276
1277   /**
1278    * @brief Called by editable UI controls when key events are received.
1279    *
1280    * @param[in] event The key event.
1281    * @param[in] type Used to distinguish between regular key events and IMF events.
1282    */
1283   bool KeyEvent( const Dali::KeyEvent& event );
1284
1285   /**
1286    * @brief Called by editable UI controls when a tap gesture occurs.
1287    * @param[in] tapCount The number of taps.
1288    * @param[in] x The x position relative to the top-left of the parent control.
1289    * @param[in] y The y position relative to the top-left of the parent control.
1290    */
1291   void TapEvent( unsigned int tapCount, float x, float y );
1292
1293   /**
1294    * @brief Called by editable UI controls when a pan gesture occurs.
1295    *
1296    * @param[in] state The state of the gesture.
1297    * @param[in] displacement This distance panned since the last pan gesture.
1298    */
1299   void PanEvent( Gesture::State state, const Vector2& displacement );
1300
1301   /**
1302    * @brief Called by editable UI controls when a long press gesture occurs.
1303    *
1304    * @param[in] state The state of the gesture.
1305    * @param[in] x The x position relative to the top-left of the parent control.
1306    * @param[in] y The y position relative to the top-left of the parent control.
1307    */
1308   void LongPressEvent( Gesture::State state, float x, float y );
1309
1310   /**
1311    * @brief Event received from IMF manager
1312    *
1313    * @param[in] imfManager The IMF manager.
1314    * @param[in] imfEvent The event received.
1315    * @return A data struture indicating if update is needed, cursor position and current text.
1316    */
1317   ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
1318
1319   /**
1320    * @brief Event from Clipboard notifying an Item has been selected for pasting
1321    */
1322   void PasteClipboardItemEvent();
1323
1324   /**
1325    * @brief Return true when text control should clear key input focus when escape key is pressed.
1326    *
1327    * @return Whether text control should clear key input focus or not when escape key is pressed.
1328    */
1329   bool ShouldClearFocusOnEscape() const;
1330
1331 protected: // Inherit from Text::Decorator::ControllerInterface.
1332
1333   /**
1334    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize()
1335    */
1336   virtual void GetTargetSize( Vector2& targetSize );
1337
1338   /**
1339    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::AddDecoration()
1340    */
1341   virtual void AddDecoration( Actor& actor, bool needsClipping );
1342
1343   /**
1344    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::DecorationEvent()
1345    */
1346   virtual void DecorationEvent( HandleType handle, HandleState state, float x, float y );
1347
1348 protected: // Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
1349
1350   /**
1351    * @copydoc Dali::Toolkit::TextSelectionPopup::TextPopupButtonCallbackInterface::TextPopupButtonTouched()
1352    */
1353   virtual void TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button );
1354
1355 protected: // Inherit from HiddenText.
1356
1357   /**
1358    * @brief Invoked from HiddenText when showing time of the last character was expired
1359    */
1360   virtual void DisplayTimeExpired();
1361
1362 private: // Update.
1363
1364   /**
1365    * @brief Called by editable UI controls when key events are received.
1366    *
1367    * @param[in] text The text to insert.
1368    * @param[in] type Used to distinguish between regular key events and IMF events.
1369    */
1370   void InsertText( const std::string& text, InsertType type );
1371
1372   /**
1373    * @brief Paste given string into Text model
1374    * @param[in] stringToPaste this string will be inserted into the text model
1375    */
1376   void PasteText( const std::string& stringToPaste );
1377
1378   /**
1379    * @brief Remove a given number of characters
1380    *
1381    * When predictve text is used the pre-edit text is removed and inserted again with the new characters.
1382    * The UpdateInputStyleType @type parameter if set to DONT_UPDATE_INPUT_STYLE avoids to update the input
1383    * style when pre-edit text is removed.
1384    *
1385    * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
1386    * @param[in] numberOfCharacters The number of characters to delete from the cursorOffset.
1387    * @param[in] type Whether to update the input style.
1388    * @return True if the remove was successful.
1389    */
1390   bool RemoveText( int cursorOffset,
1391                    int numberOfCharacters,
1392                    UpdateInputStyleType type  );
1393
1394   /**
1395    * @brief Checks if text is selected and if so removes it.
1396    * @return true if text was removed
1397    */
1398   bool RemoveSelectedText();
1399
1400 private: // Relayout.
1401
1402   /**
1403    * @brief Lays-out the text.
1404    *
1405    * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
1406    *
1407    * @param[in] size A the size of a bounding box to layout text within.
1408    * @param[in] operations The layout operations which need to be done.
1409    * @param[out] layoutSize The size of the laid-out text.
1410    */
1411   bool DoRelayout( const Size& size,
1412                    OperationsMask operations,
1413                    Size& layoutSize );
1414
1415   /**
1416    * @brief Calulates the vertical offset to align the text inside the bounding box.
1417    *
1418    * @param[in] size The size of the bounding box.
1419    */
1420   void CalculateVerticalOffset( const Size& size );
1421
1422 private: // Events.
1423
1424   /**
1425    * @brief Process queued events which modify the model.
1426    */
1427   void ProcessModifyEvents();
1428
1429   /**
1430    * @brief Used to process an event queued from SetText()
1431    */
1432   void TextReplacedEvent();
1433
1434   /**
1435    * @brief Used to process an event queued from key events etc.
1436    */
1437   void TextInsertedEvent();
1438
1439   /**
1440    * @brief Used to process an event queued from backspace key etc.
1441    */
1442   void TextDeletedEvent();
1443
1444   /**
1445    * @brief Creates a selection event.
1446    *
1447    * It could be called from the TapEvent (double tap) or when the text selection popup's sellect all button is pressed.
1448    *
1449    * @param[in] x The x position relative to the top-left of the parent control.
1450    * @param[in] y The y position relative to the top-left of the parent control.
1451    * @param[in] selectAll Whether the whole text is selected.
1452    */
1453   void SelectEvent( float x, float y, bool selectAll );
1454
1455   /**
1456    * @brief Helper to KeyEvent() to handle the backspace or delete key case.
1457    *
1458    * @param[in] keyCode The keycode for the key pressed
1459    * @return True if a character was deleted.
1460    */
1461   bool DeleteEvent( int keyCode );
1462
1463 private: // Helpers.
1464
1465   /**
1466    * @brief Used to remove the text included the placeholder text.
1467    */
1468   void ResetText();
1469
1470   /**
1471    * @brief Helper to show the place holder text..
1472    */
1473   void ShowPlaceholderText();
1474
1475   /**
1476    * @brief Helper to clear font-specific data (only).
1477    */
1478   void ClearFontData();
1479
1480   /**
1481    * @brief Helper to clear text's style data.
1482    */
1483   void ClearStyleData();
1484
1485   /**
1486    * @brief Used to reset the cursor position after setting a new text.
1487    *
1488    * @param[in] cursorIndex Where to place the cursor.
1489    */
1490   void ResetCursorPosition( CharacterIndex cursorIndex );
1491
1492   /**
1493    * @brief Used to reset the scroll position after setting a new text.
1494    */
1495   void ResetScrollPosition();
1496
1497 private: // Private contructors & copy operator.
1498
1499   /**
1500    * @brief Private constructor.
1501    */
1502   Controller();
1503
1504   /**
1505    * @brief Private constructor.
1506    */
1507   Controller( ControlInterface* controlInterface );
1508
1509   /**
1510    * @brief Private constructor.
1511    */
1512   Controller( ControlInterface* controlInterface,
1513               EditableControlInterface* editableControlInterface );
1514
1515   // Undefined
1516   Controller( const Controller& handle );
1517
1518   // Undefined
1519   Controller& operator=( const Controller& handle );
1520
1521 protected: // Destructor.
1522
1523   /**
1524    * @brief A reference counted object may only be deleted by calling Unreference().
1525    */
1526   virtual ~Controller();
1527
1528 public:
1529
1530   struct Impl; ///< Made public for testing purposes
1531
1532 private:
1533
1534   Impl* mImpl;
1535 };
1536
1537 } // namespace Text
1538
1539 } // namespace Toolkit
1540
1541 } // namespace Dali
1542
1543 #endif // DALI_TOOLKIT_TEXT_CONTROLLER_H