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