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