5005d8ed1bd3aee413fdaaac895c95b885be7a3d
[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) 2017 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/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
27 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
28 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
29 #include <dali-toolkit/internal/text/text-model-interface.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Text
38 {
39
40 class Controller;
41 class ControlInterface;
42 class EditableControlInterface;
43 class View;
44 class RenderingController;
45
46 typedef IntrusivePtr<Controller> ControllerPtr;
47
48 /**
49  * @brief A Text Controller is used by UI Controls which display text.
50  *
51  * It manipulates the Logical & Visual text models on behalf of the UI Controls.
52  * It provides a view of the text that can be used by rendering back-ends.
53  *
54  * For selectable/editable UI controls, the controller handles input events from the UI control
55  * and decorations (grab handles etc) via the Decorator::ControllerInterface interface.
56  *
57  * The text selection popup button callbacks are as well handled via the TextSelectionPopupCallbackInterface interface.
58  */
59 class Controller : public RefObject, public Decorator::ControllerInterface, public TextSelectionPopupCallbackInterface
60 {
61 public: // Enumerated types.
62
63   /**
64    * @brief Text related operations to be done in the relayout process.
65    */
66   enum OperationsMask
67   {
68     NO_OPERATION       = 0x0000,
69     CONVERT_TO_UTF32   = 0x0001,
70     GET_SCRIPTS        = 0x0002,
71     VALIDATE_FONTS     = 0x0004,
72     GET_LINE_BREAKS    = 0x0008,
73     GET_WORD_BREAKS    = 0x0010,
74     BIDI_INFO          = 0x0020,
75     SHAPE_TEXT         = 0x0040,
76     GET_GLYPH_METRICS  = 0x0080,
77     LAYOUT             = 0x0100,
78     UPDATE_LAYOUT_SIZE = 0x0200,
79     REORDER            = 0x0400,
80     ALIGN              = 0x0800,
81     COLOR              = 0x1000,
82     UPDATE_DIRECTION   = 0x2000,
83     ALL_OPERATIONS     = 0xFFFF
84   };
85
86   /**
87    * @brief Used to distinguish between regular key events and IMF events
88    */
89   enum InsertType
90   {
91     COMMIT,
92     PRE_EDIT
93   };
94
95   /**
96    * @brief Used to specify whether to update the input style.
97    */
98   enum UpdateInputStyleType
99   {
100     UPDATE_INPUT_STYLE,
101     DONT_UPDATE_INPUT_STYLE
102   };
103
104   /**
105    * @brief Used to specify what has been updated after the Relayout() method has been called.
106    */
107   enum UpdateTextType
108   {
109     NONE_UPDATED      = 0x0, ///< Nothing has been updated.
110     MODEL_UPDATED     = 0x1, ///< The text's model has been updated.
111     DECORATOR_UPDATED = 0x2  ///< The decoration has been updated.
112   };
113
114   /**
115    * @brief Different placeholder-text can be shown when the control is active/inactive.
116    */
117   enum PlaceholderType
118   {
119     PLACEHOLDER_TYPE_ACTIVE,
120     PLACEHOLDER_TYPE_INACTIVE,
121   };
122
123   struct NoTextTap
124   {
125     enum Action
126     {
127       NO_ACTION,           ///< Does no action if there is a tap on top of an area with no text.
128       HIGHLIGHT,           ///< Highlights the nearest text (at the beginning or end of the text) and shows the text's selection popup.
129       SHOW_SELECTION_POPUP ///< Shows the text's selection popup.
130     };
131   };
132
133 public: // Constructor.
134
135   /**
136    * @brief Create a new instance of a Controller.
137    *
138    * @return A pointer to a new Controller.
139    */
140   static ControllerPtr New();
141
142   /**
143    * @brief Create a new instance of a Controller.
144    *
145    * @param[in] controlInterface The control's interface.
146    *
147    * @return A pointer to a new Controller.
148    */
149   static ControllerPtr New( ControlInterface* controlInterface );
150
151   /**
152    * @brief Create a new instance of a Controller.
153    *
154    * @param[in] controlInterface The control's interface.
155    * @param[in] editableControlInterface The editable control's interface.
156    *
157    * @return A pointer to a new Controller.
158    */
159   static ControllerPtr New( ControlInterface* controlInterface,
160                             EditableControlInterface* editableControlInterface );
161
162 public: // Configure the text controller.
163
164   /**
165    * @brief Called to enable text input.
166    *
167    * @note Selectable or editable controls should call this once after Controller::New().
168    * @param[in] decorator Used to create cursor, selection handle decorations etc.
169    */
170   void EnableTextInput( DecoratorPtr decorator );
171
172   /**
173    * @brief Used to switch between bitmap & vector based glyphs
174    *
175    * @param[in] glyphType The type of glyph; note that metrics for bitmap & vector based glyphs are different.
176    */
177   void SetGlyphType( TextAbstraction::GlyphType glyphType );
178
179   /**
180    * @brief Enables/disables the mark-up processor.
181    *
182    * By default is disabled.
183    *
184    * @param[in] enable Whether to enable the mark-up processor.
185    */
186   void SetMarkupProcessorEnabled( bool enable );
187
188   /**
189    * @brief Retrieves whether the mark-up processor is enabled.
190    *
191    * By default is disabled.
192    *
193    * @return @e true if the mark-up processor is enabled, otherwise returns @e false.
194    */
195   bool IsMarkupProcessorEnabled() const;
196
197   /**
198    * @brief Enables/disables the auto text scrolling
199    *
200    * By default is disabled.
201    *
202    * @param[in] enable Whether to enable the auto scrolling
203    */
204   void SetAutoScrollEnabled( bool enable );
205
206   /**
207    * @brief Retrieves whether auto text scrolling is enabled.
208    *
209    * By default is disabled.
210    *
211    * @return @e true if auto scrolling is enabled, otherwise returns @e false.
212    */
213   bool IsAutoScrollEnabled() const;
214
215   /**
216    * @brief Get direction of the text from the first line of text,
217    * @return bool rtl (right to left) is true
218    */
219   CharacterDirection GetAutoScrollDirection() const;
220
221   /**
222    * @brief Get the alignment offset of the first line of text.
223    *
224    * @return The alignment offset.
225    */
226   float GetAutoScrollLineAlignment() const;
227
228   /**
229    * @brief Enables the horizontal scrolling.
230    *
231    * @param[in] enable Whether to enable the horizontal scrolling.
232    */
233   void SetHorizontalScrollEnabled( bool enable );
234
235   /**
236    * @brief Retrieves whether the horizontal scrolling is enabled.
237    *
238    * @return @e true if the horizontal scrolling is enabled, otherwise it returns @e false.
239    */
240   bool IsHorizontalScrollEnabled() const;
241
242   /**
243    * @brief Enables the vertical scrolling.
244    *
245    * @param[in] enable Whether to enable the vertical scrolling.
246    */
247   void SetVerticalScrollEnabled( bool enable );
248
249   /**
250    * @brief Retrieves whether the verticall scrolling is enabled.
251    *
252    * @return @e true if the vertical scrolling is enabled, otherwise it returns @e false.
253    */
254   bool IsVerticalScrollEnabled() const;
255
256   /**
257    * @brief Enables the smooth handle panning.
258    *
259    * @param[in] enable Whether to enable the smooth handle panning.
260    */
261   void SetSmoothHandlePanEnabled( bool enable );
262
263   /**
264    * @brief Retrieves whether the smooth handle panning is enabled.
265    *
266    * @return @e true if the smooth handle panning is enabled.
267    */
268   bool IsSmoothHandlePanEnabled() const;
269
270   /**
271    * @brief Sets the maximum number of characters that can be inserted into the TextModel
272    *
273    * @param[in] maxCharacters maximum number of characters to be accepted
274    */
275   void SetMaximumNumberOfCharacters( Length maxCharacters );
276
277   /**
278    * @brief Sets the maximum number of characters that can be inserted into the TextModel
279    *
280    * @param[in] maxCharacters maximum number of characters to be accepted
281    */
282   int GetMaximumNumberOfCharacters();
283
284   /**
285    * @brief Called to enable/disable cursor blink.
286    *
287    * @note Only editable controls should calls this.
288    * @param[in] enabled Whether the cursor should blink or not.
289    */
290   void SetEnableCursorBlink( bool enable );
291
292   /**
293    * @brief Query whether cursor blink is enabled.
294    *
295    * @return Whether the cursor should blink or not.
296    */
297   bool GetEnableCursorBlink() const;
298
299   /**
300    * @brief Whether to enable the multi-line layout.
301    *
302    * @param[in] enable \e true enables the multi-line (by default)
303    */
304   void SetMultiLineEnabled( bool enable );
305
306   /**
307    * @return Whether the multi-line layout is enabled.
308    */
309   bool IsMultiLineEnabled() const;
310
311   /**
312    * @brief Sets the text's horizontal alignment.
313    *
314    * @param[in] alignment The horizontal alignment.
315    */
316   void SetHorizontalAlignment( Layout::HorizontalAlignment alignment );
317
318   /**
319    * @copydoc ModelInterface::GetHorizontalAlignment()
320    */
321   Layout::HorizontalAlignment GetHorizontalAlignment() const;
322
323   /**
324    * @brief Sets the text's vertical alignment.
325    *
326    * @param[in] alignment The vertical alignment.
327    */
328   void SetVerticalAlignment( Layout::VerticalAlignment alignment );
329
330   /**
331    * @copydoc ModelInterface::GetVerticalAlignment()
332    */
333   Layout::VerticalAlignment GetVerticalAlignment() const;
334
335   /**
336    * @brief Enable or disable the text elide.
337    *
338    * @param[in] enabled Whether to enable the text elide.
339    */
340   void SetTextElideEnabled( bool enabled );
341
342   /**
343    * @copydoc ModelInterface::IsTextElideEnabled()
344    */
345   bool IsTextElideEnabled() const;
346
347   /**
348    * @brief Sets input type to password
349    *
350    * @note The string is displayed continuous "*"
351    *
352    * @param[in] passwordInput True if password input is enabled.
353    */
354   void SetInputModePassword( bool passwordInput );
355
356   /**
357    * @brief Returns whether the input mode type is set as password.
358    *
359    * @return True if input mode type is password
360    */
361   bool IsInputModePassword();
362
363   /**
364    * @brief Sets the action when there is a double tap event on top of a text area with no text.
365    *
366    * @param[in] action The action to do.
367    */
368   void SetNoTextDoubleTapAction( NoTextTap::Action action );
369
370   /**
371    * @brief Retrieves the action when there is a double tap event on top of a text area with no text.
372    *
373    * @return The action to do.
374    */
375   NoTextTap::Action GetNoTextDoubleTapAction() const;
376
377   /**
378    * @briefSets the action when there is a long press event on top of a text area with no text.
379    *
380    * @param[in] action The action to do.
381    */
382   void SetNoTextLongPressAction( NoTextTap::Action action );
383
384   /**
385    * @brief Retrieves the action when there is a long press event on top of a text area with no text.
386    *
387    * @return The action to do.
388    */
389   NoTextTap::Action GetNoTextLongPressAction() const;
390
391 public: // Update.
392
393   /**
394    * @brief Replaces any text previously set.
395    *
396    * @note This will be converted into UTF-32 when stored in the text model.
397    * @param[in] text A string of UTF-8 characters.
398    */
399   void SetText( const std::string& text );
400
401   /**
402    * @brief Retrieve any text previously set.
403    *
404    * @param[out] text A string of UTF-8 characters.
405    */
406   void GetText( std::string& text ) const;
407
408   /**
409    * @brief Replaces any placeholder text previously set.
410    *
411    * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
412    * @param[in] text A string of UTF-8 characters.
413    */
414   void SetPlaceholderText( PlaceholderType type, const std::string& text );
415
416   /**
417    * @brief Retrieve any placeholder text previously set.
418    *
419    * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
420    * @param[out] A string of UTF-8 characters.
421    */
422   void GetPlaceholderText( PlaceholderType type, std::string& text ) const;
423
424   /**
425    * @ brief Update the text after a font change
426    * @param[in] newDefaultFont The new font to change to
427    */
428   void UpdateAfterFontChange( const std::string& newDefaultFont );
429
430 public: // Default style & Input style
431
432   /**
433    * @brief Set the default font family.
434    *
435    * @param[in] defaultFontFamily The default font family.
436    */
437   void SetDefaultFontFamily( const std::string& defaultFontFamily );
438
439   /**
440    * @brief Retrieve the default font family.
441    *
442    * @return The default font family.
443    */
444   const std::string& GetDefaultFontFamily() const;
445
446   /**
447    * @brief Sets the default font weight.
448    *
449    * @param[in] weight The font weight.
450    */
451   void SetDefaultFontWeight( FontWeight weight );
452
453   /**
454    * @brief Whether the font's weight has been defined.
455    */
456   bool IsDefaultFontWeightDefined() const;
457
458   /**
459    * @brief Retrieves the default font weight.
460    *
461    * @return The default font weight.
462    */
463   FontWeight GetDefaultFontWeight() const;
464
465   /**
466    * @brief Sets the default font width.
467    *
468    * @param[in] width The font width.
469    */
470   void SetDefaultFontWidth( FontWidth width );
471
472   /**
473    * @brief Whether the font's width has been defined.
474    */
475   bool IsDefaultFontWidthDefined() const;
476
477   /**
478    * @brief Retrieves the default font width.
479    *
480    * @return The default font width.
481    */
482   FontWidth GetDefaultFontWidth() const;
483
484   /**
485    * @brief Sets the default font slant.
486    *
487    * @param[in] slant The font slant.
488    */
489   void SetDefaultFontSlant( FontSlant slant );
490
491   /**
492    * @brief Whether the font's slant has been defined.
493    */
494   bool IsDefaultFontSlantDefined() const;
495
496   /**
497    * @brief Retrieves the default font slant.
498    *
499    * @return The default font slant.
500    */
501   FontSlant GetDefaultFontSlant() const;
502
503   /**
504    * @brief Set the default point size.
505    *
506    * @param[in] pointSize The default point size.
507    */
508   void SetDefaultPointSize( float pointSize );
509
510   /**
511    * @brief Retrieve the default point size.
512    *
513    * @return The default point size.
514    */
515   float GetDefaultPointSize() const;
516
517   /**
518    * @brief Sets the text's default color.
519    *
520    * @param color The default color.
521    */
522   void SetDefaultColor( const Vector4& color );
523
524   /**
525    * @brief Retrieves the text's default color.
526    *
527    * @return The default color.
528    */
529   const Vector4& GetDefaultColor() const;
530
531   /**
532    * @brief Set the text color
533    *
534    * @param textColor The text color
535    */
536   void SetPlaceholderTextColor( const Vector4& textColor );
537
538   /**
539    * @brief Retrieve the text color
540    *
541    * @return The text color
542    */
543   const Vector4& GetPlaceholderTextColor() const;
544
545   /**
546    * @brief Set the shadow offset.
547    *
548    * @param[in] shadowOffset The shadow offset, 0,0 indicates no shadow.
549    */
550   void SetShadowOffset( const Vector2& shadowOffset );
551
552   /**
553    * @brief Retrieve the shadow offset.
554    *
555    * @return The shadow offset.
556    */
557   const Vector2& GetShadowOffset() const;
558
559   /**
560    * @brief Set the shadow color.
561    *
562    * @param[in] shadowColor The shadow color.
563    */
564   void SetShadowColor( const Vector4& shadowColor );
565
566   /**
567    * @brief Retrieve the shadow color.
568    *
569    * @return The shadow color.
570    */
571   const Vector4& GetShadowColor() const;
572
573   /**
574    * @brief Set the underline color.
575    *
576    * @param[in] color color of underline.
577    */
578   void SetUnderlineColor( const Vector4& color );
579
580   /**
581    * @brief Retrieve the underline color.
582    *
583    * @return The underline color.
584    */
585   const Vector4& GetUnderlineColor() const;
586
587   /**
588    * @brief Set the underline enabled flag.
589    *
590    * @param[in] enabled The underline enabled flag.
591    */
592   void SetUnderlineEnabled( bool enabled );
593
594   /**
595    * @brief Returns whether the text is underlined or not.
596    *
597    * @return The underline state.
598    */
599   bool IsUnderlineEnabled() const;
600
601   /**
602    * @brief Set the override used for underline height, 0 indicates height will be supplied by font metrics
603    *
604    * @param[in] height The height in pixels of the underline
605    */
606   void SetUnderlineHeight( float height );
607
608   /**
609    * @brief Retrieves the override height of an underline, 0 indicates height is supplied by font metrics
610    *
611    * @return The height of the underline, or 0 if height is not overrided.
612    */
613   float GetUnderlineHeight() const;
614
615   /**
616    * @brief Sets the emboss's properties string.
617    *
618    * @note The string is stored to be recovered.
619    *
620    * @param[in] embossProperties The emboss's properties string.
621    */
622   void SetDefaultEmbossProperties( const std::string& embossProperties );
623
624   /**
625    * @brief Retrieves the emboss's properties string.
626    *
627    * @return The emboss's properties string.
628    */
629   const std::string& GetDefaultEmbossProperties() const;
630
631   /**
632    * @brief Sets the outline's properties string.
633    *
634    * @note The string is stored to be recovered.
635    *
636    * @param[in] outlineProperties The outline's properties string.
637    */
638   void SetDefaultOutlineProperties( const std::string& outlineProperties );
639
640   /**
641    * @brief Retrieves the outline's properties string.
642    *
643    * @return The outline's properties string.
644    */
645   const std::string& GetDefaultOutlineProperties() const;
646
647   /**
648    * @brief Sets the default line spacing.
649    *
650    * @param[in] lineSpacing The line spacing.
651    */
652   void SetDefaultLineSpacing( float lineSpacing );
653
654   /**
655    * @brief Retrieves the default line spacing.
656    *
657    * @return The line spacing.
658    */
659   float GetDefaultLineSpacing() const;
660
661   /**
662    * @brief Sets the input text's color.
663    *
664    * @param[in] color The input text's color.
665    */
666   void SetInputColor( const Vector4& color );
667
668   /**
669    * @brief Retrieves the input text's color.
670    *
671    * @return The input text's color.
672    */
673   const Vector4& GetInputColor() const;
674
675   /**
676    * @brief Sets the input text's font family name.
677    *
678    * @param[in] fontFamily The text's font family name.
679    */
680   void SetInputFontFamily( const std::string& fontFamily );
681
682   /**
683    * @brief Retrieves the input text's font family name.
684    *
685    * @return The input text's font family name.
686    */
687   const std::string& GetInputFontFamily() const;
688
689   /**
690    * @brief Sets the input font's weight.
691    *
692    * @param[in] weight The input font's weight.
693    */
694   void SetInputFontWeight( FontWeight weight );
695
696   /**
697    * @return Whether the font's weight has been defined.
698    */
699   bool IsInputFontWeightDefined() const;
700
701   /**
702    * @brief Retrieves the input font's weight.
703    *
704    * @return The input font's weight.
705    */
706   FontWeight GetInputFontWeight() const;
707
708   /**
709    * @brief Sets the input font's width.
710    *
711    * @param[in] width The input font's width.
712    */
713   void SetInputFontWidth( FontWidth width );
714
715   /**
716    * @return Whether the font's width has been defined.
717    */
718   bool IsInputFontWidthDefined() const;
719
720   /**
721    * @brief Retrieves the input font's width.
722    *
723    * @return The input font's width.
724    */
725   FontWidth GetInputFontWidth() const;
726
727   /**
728    * @brief Sets the input font's slant.
729    *
730    * @param[in] slant The input font's slant.
731    */
732   void SetInputFontSlant( FontSlant slant );
733
734   /**
735    * @return Whether the font's slant has been defined.
736    */
737   bool IsInputFontSlantDefined() const;
738
739   /**
740    * @brief Retrieves the input font's slant.
741    *
742    * @return The input font's slant.
743    */
744   FontSlant GetInputFontSlant() const;
745
746   /**
747    * @brief Sets the input font's point size.
748    *
749    * @param[in] size The input font's point size.
750    */
751   void SetInputFontPointSize( float size );
752
753   /**
754    * @brief Retrieves the input font's point size.
755    *
756    * @return The input font's point size.
757    */
758   float GetInputFontPointSize() const;
759
760   /**
761    * @brief Sets the input line spacing.
762    *
763    * @param[in] lineSpacing The line spacing.
764    */
765   void SetInputLineSpacing( float lineSpacing );
766
767   /**
768    * @brief Retrieves the input line spacing.
769    *
770    * @return The line spacing.
771    */
772   float GetInputLineSpacing() const;
773
774   /**
775    * @brief Sets the input shadow's properties string.
776    *
777    * @note The string is stored to be recovered.
778    *
779    * @param[in] shadowProperties The shadow's properties string.
780    */
781   void SetInputShadowProperties( const std::string& shadowProperties );
782
783   /**
784    * @brief Retrieves the input shadow's properties string.
785    *
786    * @return The shadow's properties string.
787    */
788   const std::string& GetInputShadowProperties() const;
789
790   /**
791    * @brief Sets the input underline's properties string.
792    *
793    * @note The string is stored to be recovered.
794    *
795    * @param[in] underlineProperties The underline's properties string.
796    */
797   void SetInputUnderlineProperties( const std::string& underlineProperties );
798
799   /**
800    * @brief Retrieves the input underline's properties string.
801    *
802    * @return The underline's properties string.
803    */
804   const std::string& GetInputUnderlineProperties() const;
805
806   /**
807    * @brief Sets the input emboss's properties string.
808    *
809    * @note The string is stored to be recovered.
810    *
811    * @param[in] embossProperties The emboss's properties string.
812    */
813   void SetInputEmbossProperties( const std::string& embossProperties );
814
815   /**
816    * @brief Retrieves the input emboss's properties string.
817    *
818    * @return The emboss's properties string.
819    */
820   const std::string& GetInputEmbossProperties() const;
821
822   /**
823    * @brief Sets input the outline's properties string.
824    *
825    * @note The string is stored to be recovered.
826    *
827    * @param[in] outlineProperties The outline's properties string.
828    */
829   void SetInputOutlineProperties( const std::string& outlineProperties );
830
831   /**
832    * @brief Retrieves the input outline's properties string.
833    *
834    * @return The outline's properties string.
835    */
836   const std::string& GetInputOutlineProperties() const;
837
838 public: // Queries & retrieves.
839
840   /**
841    * @brief Return the layout engine.
842    *
843    * @return A reference to the layout engine.
844    */
845   Layout::Engine& GetLayoutEngine();
846
847   /**
848    * @brief Return a view of the text.
849    *
850    * @return A reference to the view.
851    */
852   View& GetView();
853
854   /**
855    * @copydoc Control::GetNaturalSize()
856    */
857   Vector3 GetNaturalSize();
858
859   /**
860    * @copydoc Control::GetHeightForWidth()
861    */
862   float GetHeightForWidth( float width );
863
864   /**
865    * @brief Retrieves the text's model.
866    *
867    * @return A pointer to the text's model.
868    */
869   const ModelInterface* const GetTextModel() const;
870
871   /**
872    * @brief Used to get scrolled distance by user input
873    *
874    * @return Distance from last scroll offset to new scroll offset
875    */
876   float GetScrollAmountByUserInput();
877
878   /**
879    * @brief Get latest scroll amount, control size and layout size
880    *
881    * This method is used to get information of control's scroll
882    * @param[out] scrollPosition The current scrolled position
883    * @param[out] controlHeight The size of a UI control
884    * @param[out] layoutHeight The size of a bounding box to layout text within.
885    *
886    * @return Whether the text scroll position is changed or not after last update.
887    */
888   bool GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight );
889
890 public: // Relayout.
891
892   /**
893    * @brief Triggers a relayout which updates View (if necessary).
894    *
895    * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
896    * @param[in] size A the size of a bounding box to layout text within.
897    *
898    * @return Whether the text model or decorations were updated.
899    */
900   UpdateTextType Relayout( const Size& size );
901
902   /**
903    * @brief Request a relayout using the ControlInterface.
904    */
905   void RequestRelayout();
906
907 public: // Input style change signals.
908
909   /**
910    * @return Whether the queue of input style changed signals is empty.
911    */
912   bool IsInputStyleChangedSignalsQueueEmpty();
913
914   /**
915    * @brief Process all pending input style changed signals.
916    *
917    * Calls the Text::ControlInterface::InputStyleChanged() method which is overriden by the
918    * text controls. Text controls may send signals to state the input style has changed.
919    */
920   void ProcessInputStyleChangedSignals();
921
922 public: // Text-input Event Queuing.
923
924   /**
925    * @brief Called by editable UI controls when keyboard focus is gained.
926    */
927   void KeyboardFocusGainEvent();
928
929   /**
930    * @brief Called by editable UI controls when focus is lost.
931    */
932   void KeyboardFocusLostEvent();
933
934   /**
935    * @brief Called by editable UI controls when key events are received.
936    *
937    * @param[in] event The key event.
938    * @param[in] type Used to distinguish between regular key events and IMF events.
939    */
940   bool KeyEvent( const Dali::KeyEvent& event );
941
942   /**
943    * @brief Called by editable UI controls when a tap gesture occurs.
944    * @param[in] tapCount The number of taps.
945    * @param[in] x The x position relative to the top-left of the parent control.
946    * @param[in] y The y position relative to the top-left of the parent control.
947    */
948   void TapEvent( unsigned int tapCount, float x, float y );
949
950   /**
951    * @brief Called by editable UI controls when a pan gesture occurs.
952    *
953    * @param[in] state The state of the gesture.
954    * @param[in] displacement This distance panned since the last pan gesture.
955    */
956   void PanEvent( Gesture::State state, const Vector2& displacement );
957
958   /**
959    * @brief Called by editable UI controls when a long press gesture occurs.
960    *
961    * @param[in] state The state of the gesture.
962    * @param[in] x The x position relative to the top-left of the parent control.
963    * @param[in] y The y position relative to the top-left of the parent control.
964    */
965   void LongPressEvent( Gesture::State state, float x, float y );
966
967   /**
968    * @brief Event received from IMF manager
969    *
970    * @param[in] imfManager The IMF manager.
971    * @param[in] imfEvent The event received.
972    * @return A data struture indicating if update is needed, cursor position and current text.
973    */
974   ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
975
976   /**
977    * @brief Event from Clipboard notifying an Item has been selected for pasting
978    */
979   void PasteClipboardItemEvent();
980
981 protected: // Inherit from Text::Decorator::ControllerInterface.
982
983   /**
984    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize()
985    */
986   virtual void GetTargetSize( Vector2& targetSize );
987
988   /**
989    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::AddDecoration()
990    */
991   virtual void AddDecoration( Actor& actor, bool needsClipping );
992
993   /**
994    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::DecorationEvent()
995    */
996   virtual void DecorationEvent( HandleType handle, HandleState state, float x, float y );
997
998 protected: // Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
999
1000   /**
1001    * @copydoc Dali::Toolkit::TextSelectionPopup::TextPopupButtonCallbackInterface::TextPopupButtonTouched()
1002    */
1003   virtual void TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button );
1004
1005 private: // Update.
1006
1007   /**
1008    * @brief Called by editable UI controls when key events are received.
1009    *
1010    * @param[in] text The text to insert.
1011    * @param[in] type Used to distinguish between regular key events and IMF events.
1012    */
1013   void InsertText( const std::string& text, InsertType type );
1014
1015   /**
1016    * @brief Paste given string into Text model
1017    * @param[in] stringToPaste this string will be inserted into the text model
1018    */
1019   void PasteText( const std::string& stringToPaste );
1020
1021   /**
1022    * @brief Remove a given number of characters
1023    *
1024    * When predictve text is used the pre-edit text is removed and inserted again with the new characters.
1025    * The UpdateInputStyleType @type parameter if set to DONT_UPDATE_INPUT_STYLE avoids to update the input
1026    * style when pre-edit text is removed.
1027    *
1028    * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
1029    * @param[in] numberOfCharacters The number of characters to delete from the cursorOffset.
1030    * @param[in] type Whether to update the input style.
1031    * @return True if the remove was successful.
1032    */
1033   bool RemoveText( int cursorOffset,
1034                    int numberOfCharacters,
1035                    UpdateInputStyleType type  );
1036
1037   /**
1038    * @brief Checks if text is selected and if so removes it.
1039    * @return true if text was removed
1040    */
1041   bool RemoveSelectedText();
1042
1043 private: // Relayout.
1044
1045   /**
1046    * @brief Lays-out the text.
1047    *
1048    * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
1049    *
1050    * @param[in] size A the size of a bounding box to layout text within.
1051    * @param[in] operations The layout operations which need to be done.
1052    * @param[out] layoutSize The size of the laid-out text.
1053    */
1054   bool DoRelayout( const Size& size,
1055                    OperationsMask operations,
1056                    Size& layoutSize );
1057
1058   /**
1059    * @brief Calulates the vertical offset to align the text inside the bounding box.
1060    *
1061    * @param[in] size The size of the bounding box.
1062    */
1063   void CalculateVerticalOffset( const Size& size );
1064
1065 private: // Events.
1066
1067   /**
1068    * @brief Process queued events which modify the model.
1069    */
1070   void ProcessModifyEvents();
1071
1072   /**
1073    * @brief Used to process an event queued from SetText()
1074    */
1075   void TextReplacedEvent();
1076
1077   /**
1078    * @brief Used to process an event queued from key events etc.
1079    */
1080   void TextInsertedEvent();
1081
1082   /**
1083    * @brief Used to process an event queued from backspace key etc.
1084    */
1085   void TextDeletedEvent();
1086
1087   /**
1088    * @brief Creates a selection event.
1089    *
1090    * It could be called from the TapEvent (double tap) or when the text selection popup's sellect all button is pressed.
1091    *
1092    * @param[in] x The x position relative to the top-left of the parent control.
1093    * @param[in] y The y position relative to the top-left of the parent control.
1094    * @param[in] selectAll Whether the whole text is selected.
1095    */
1096   void SelectEvent( float x, float y, bool selectAll );
1097
1098   /**
1099    * @brief Helper to KeyEvent() to handle the backspace case.
1100    *
1101    * @return True if a character was deleted.
1102    */
1103   bool BackspaceKeyEvent();
1104
1105 private: // Helpers.
1106
1107   /**
1108    * @brief Used to remove the text included the placeholder text.
1109    */
1110   void ResetText();
1111
1112   /**
1113    * @brief Helper to show the place holder text..
1114    */
1115   void ShowPlaceholderText();
1116
1117   /**
1118    * @brief Helper to clear font-specific data (only).
1119    */
1120   void ClearFontData();
1121
1122   /**
1123    * @brief Helper to clear text's style data.
1124    */
1125   void ClearStyleData();
1126
1127   /**
1128    * @brief Used to reset the cursor position after setting a new text.
1129    *
1130    * @param[in] cursorIndex Where to place the cursor.
1131    */
1132   void ResetCursorPosition( CharacterIndex cursorIndex );
1133
1134   /**
1135    * @brief Used to reset the scroll position after setting a new text.
1136    */
1137   void ResetScrollPosition();
1138
1139 private: // Private contructors & copy operator.
1140
1141   /**
1142    * @brief Private constructor.
1143    */
1144   Controller();
1145
1146   /**
1147    * @brief Private constructor.
1148    */
1149   Controller( ControlInterface* controlInterface );
1150
1151   /**
1152    * @brief Private constructor.
1153    */
1154   Controller( ControlInterface* controlInterface,
1155               EditableControlInterface* editableControlInterface );
1156
1157   // Undefined
1158   Controller( const Controller& handle );
1159
1160   // Undefined
1161   Controller& operator=( const Controller& handle );
1162
1163 protected: // Destructor.
1164
1165   /**
1166    * @brief A reference counted object may only be deleted by calling Unreference().
1167    */
1168   virtual ~Controller();
1169
1170 private:
1171
1172   struct Impl;
1173   Impl* mImpl;
1174 };
1175
1176 } // namespace Text
1177
1178 } // namespace Toolkit
1179
1180 } // namespace Dali
1181
1182 #endif // DALI_TOOLKIT_TEXT_CONTROLLER_H