Merge "Convert the Underline and Shadow deprecated APIs to the new ones." into devel...
[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 Set the underline color.
503    *
504    * @param[in] color color of underline.
505    */
506   void SetUnderlineColor( const Vector4& color );
507
508   /**
509    * @brief Retrieve the underline color.
510    *
511    * @return The underline color.
512    */
513   const Vector4& GetUnderlineColor() const;
514
515   /**
516    * @brief Set the underline enabled flag.
517    *
518    * @param[in] enabled The underline enabled flag.
519    */
520   void SetUnderlineEnabled( bool enabled );
521
522   /**
523    * @brief Returns whether the text is underlined or not.
524    *
525    * @return The underline state.
526    */
527   bool IsUnderlineEnabled() const;
528
529   /**
530    * @brief Set the override used for underline height, 0 indicates height will be supplied by font metrics
531    *
532    * @param[in] height The height in pixels of the underline
533    */
534   void SetUnderlineHeight( float height );
535
536   /**
537    * @brief Retrieves the override height of an underline, 0 indicates height is supplied by font metrics
538    *
539    * @return The height of the underline, or 0 if height is not overrided.
540    */
541   float GetUnderlineHeight() const;
542
543   /**
544    * @brief Sets the emboss's properties string.
545    *
546    * @note The string is stored to be recovered.
547    *
548    * @param[in] embossProperties The emboss's properties string.
549    */
550   void SetDefaultEmbossProperties( const std::string& embossProperties );
551
552   /**
553    * @brief Retrieves the emboss's properties string.
554    *
555    * @return The emboss's properties string.
556    */
557   const std::string& GetDefaultEmbossProperties() const;
558
559   /**
560    * @brief Sets the outline's properties string.
561    *
562    * @note The string is stored to be recovered.
563    *
564    * @param[in] outlineProperties The outline's properties string.
565    */
566   void SetDefaultOutlineProperties( const std::string& outlineProperties );
567
568   /**
569    * @brief Retrieves the outline's properties string.
570    *
571    * @return The outline's properties string.
572    */
573   const std::string& GetDefaultOutlineProperties() const;
574
575   /**
576    * @brief Sets the default line spacing.
577    *
578    * @param[in] lineSpacing The line spacing.
579    */
580   void SetDefaultLineSpacing( float lineSpacing );
581
582   /**
583    * @brief Retrieves the default line spacing.
584    *
585    * @return The line spacing.
586    */
587   float GetDefaultLineSpacing() const;
588
589   /**
590    * @brief Sets the input text's color.
591    *
592    * @param[in] color The input text's color.
593    */
594   void SetInputColor( const Vector4& color );
595
596   /**
597    * @brief Retrieves the input text's color.
598    *
599    * @return The input text's color.
600    */
601   const Vector4& GetInputColor() const;
602
603   /**
604    * @brief Sets the input text's font family name.
605    *
606    * @param[in] fontFamily The text's font family name.
607    */
608   void SetInputFontFamily( const std::string& fontFamily );
609
610   /**
611    * @brief Retrieves the input text's font family name.
612    *
613    * @return The input text's font family name.
614    */
615   const std::string& GetInputFontFamily() const;
616
617   /**
618    * @brief Sets the input font's weight.
619    *
620    * @param[in] weight The input font's weight.
621    */
622   void SetInputFontWeight( FontWeight weight );
623
624   /**
625    * @return Whether the font's weight has been defined.
626    */
627   bool IsInputFontWeightDefined() const;
628
629   /**
630    * @brief Retrieves the input font's weight.
631    *
632    * @return The input font's weight.
633    */
634   FontWeight GetInputFontWeight() const;
635
636   /**
637    * @brief Sets the input font's width.
638    *
639    * @param[in] width The input font's width.
640    */
641   void SetInputFontWidth( FontWidth width );
642
643   /**
644    * @return Whether the font's width has been defined.
645    */
646   bool IsInputFontWidthDefined() const;
647
648   /**
649    * @brief Retrieves the input font's width.
650    *
651    * @return The input font's width.
652    */
653   FontWidth GetInputFontWidth() const;
654
655   /**
656    * @brief Sets the input font's slant.
657    *
658    * @param[in] slant The input font's slant.
659    */
660   void SetInputFontSlant( FontSlant slant );
661
662   /**
663    * @return Whether the font's slant has been defined.
664    */
665   bool IsInputFontSlantDefined() const;
666
667   /**
668    * @brief Retrieves the input font's slant.
669    *
670    * @return The input font's slant.
671    */
672   FontSlant GetInputFontSlant() const;
673
674   /**
675    * @brief Sets the input font's point size.
676    *
677    * @param[in] size The input font's point size.
678    */
679   void SetInputFontPointSize( float size );
680
681   /**
682    * @brief Retrieves the input font's point size.
683    *
684    * @return The input font's point size.
685    */
686   float GetInputFontPointSize() const;
687
688   /**
689    * @brief Sets the input line spacing.
690    *
691    * @param[in] lineSpacing The line spacing.
692    */
693   void SetInputLineSpacing( float lineSpacing );
694
695   /**
696    * @brief Retrieves the input line spacing.
697    *
698    * @return The line spacing.
699    */
700   float GetInputLineSpacing() const;
701
702   /**
703    * @brief Sets the input shadow's properties string.
704    *
705    * @note The string is stored to be recovered.
706    *
707    * @param[in] shadowProperties The shadow's properties string.
708    */
709   void SetInputShadowProperties( const std::string& shadowProperties );
710
711   /**
712    * @brief Retrieves the input shadow's properties string.
713    *
714    * @return The shadow's properties string.
715    */
716   const std::string& GetInputShadowProperties() const;
717
718   /**
719    * @brief Sets the input underline's properties string.
720    *
721    * @note The string is stored to be recovered.
722    *
723    * @param[in] underlineProperties The underline's properties string.
724    */
725   void SetInputUnderlineProperties( const std::string& underlineProperties );
726
727   /**
728    * @brief Retrieves the input underline's properties string.
729    *
730    * @return The underline's properties string.
731    */
732   const std::string& GetInputUnderlineProperties() const;
733
734   /**
735    * @brief Sets the input emboss's properties string.
736    *
737    * @note The string is stored to be recovered.
738    *
739    * @param[in] embossProperties The emboss's properties string.
740    */
741   void SetInputEmbossProperties( const std::string& embossProperties );
742
743   /**
744    * @brief Retrieves the input emboss's properties string.
745    *
746    * @return The emboss's properties string.
747    */
748   const std::string& GetInputEmbossProperties() const;
749
750   /**
751    * @brief Sets input the outline's properties string.
752    *
753    * @note The string is stored to be recovered.
754    *
755    * @param[in] outlineProperties The outline's properties string.
756    */
757   void SetInputOutlineProperties( const std::string& outlineProperties );
758
759   /**
760    * @brief Retrieves the input outline's properties string.
761    *
762    * @return The outline's properties string.
763    */
764   const std::string& GetInputOutlineProperties() const;
765
766 public: // Queries & retrieves.
767
768   /**
769    * @brief Return the layout engine.
770    *
771    * @return A reference to the layout engine.
772    */
773   LayoutEngine& GetLayoutEngine();
774
775   /**
776    * @brief Return a view of the text.
777    *
778    * @return A reference to the view.
779    */
780   View& GetView();
781
782   /**
783    * @brief Query the current scroll position; the UI control is responsible for moving actors to this position.
784    *
785    * @return The scroll position.
786    */
787   const Vector2& GetScrollPosition() const;
788
789   /**
790    * @copydoc Control::GetNaturalSize()
791    */
792   Vector3 GetNaturalSize();
793
794   /**
795    * @copydoc Control::GetHeightForWidth()
796    */
797   float GetHeightForWidth( float width );
798
799 public: // Relayout.
800
801   /**
802    * @brief Triggers a relayout which updates View (if necessary).
803    *
804    * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
805    * @param[in] size A the size of a bounding box to layout text within.
806    *
807    * @return Whether the text model or decorations were updated.
808    */
809   UpdateTextType Relayout( const Size& size );
810
811 public: // Input style change signals.
812
813   /**
814    * @return Whether the queue of input style changed signals is empty.
815    */
816   bool IsInputStyleChangedSignalsQueueEmpty();
817
818   /**
819    * @brief Process all pending input style changed signals.
820    *
821    * Calls the Text::ControlInterface::InputStyleChanged() method which is overriden by the
822    * text controls. Text controls may send signals to state the input style has changed.
823    */
824   void ProcessInputStyleChangedSignals();
825
826 public: // Text-input Event Queuing.
827
828   /**
829    * @brief Called by editable UI controls when keyboard focus is gained.
830    */
831   void KeyboardFocusGainEvent();
832
833   /**
834    * @brief Called by editable UI controls when focus is lost.
835    */
836   void KeyboardFocusLostEvent();
837
838   /**
839    * @brief Called by editable UI controls when key events are received.
840    *
841    * @param[in] event The key event.
842    * @param[in] type Used to distinguish between regular key events and IMF events.
843    */
844   bool KeyEvent( const Dali::KeyEvent& event );
845
846   /**
847    * @brief Called by editable UI controls when a tap gesture occurs.
848    * @param[in] tapCount The number of taps.
849    * @param[in] x The x position relative to the top-left of the parent control.
850    * @param[in] y The y position relative to the top-left of the parent control.
851    */
852   void TapEvent( unsigned int tapCount, float x, float y );
853
854   /**
855    * @brief Called by editable UI controls when a pan gesture occurs.
856    *
857    * @param[in] state The state of the gesture.
858    * @param[in] displacement This distance panned since the last pan gesture.
859    */
860   void PanEvent( Gesture::State state, const Vector2& displacement );
861
862   /**
863    * @brief Called by editable UI controls when a long press gesture occurs.
864    *
865    * @param[in] state The state of the gesture.
866    * @param[in] x The x position relative to the top-left of the parent control.
867    * @param[in] y The y position relative to the top-left of the parent control.
868    */
869   void LongPressEvent( Gesture::State state, float x, float y );
870
871   /**
872    * @brief Event received from IMF manager
873    *
874    * @param[in] imfManager The IMF manager.
875    * @param[in] imfEvent The event received.
876    * @return A data struture indicating if update is needed, cursor position and current text.
877    */
878   ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
879
880   /**
881    * @brief Event from Clipboard notifying an Item has been selected for pasting
882    */
883   void PasteClipboardItemEvent();
884
885 protected: // Inherit from Text::Decorator::ControllerInterface.
886
887   /**
888    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize()
889    */
890   virtual void GetTargetSize( Vector2& targetSize );
891
892   /**
893    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::AddDecoration()
894    */
895   virtual void AddDecoration( Actor& actor, bool needsClipping );
896
897   /**
898    * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::DecorationEvent()
899    */
900   virtual void DecorationEvent( HandleType handle, HandleState state, float x, float y );
901
902 protected: // Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
903
904   /**
905    * @copydoc Dali::Toolkit::TextSelectionPopup::TextPopupButtonCallbackInterface::TextPopupButtonTouched()
906    */
907   virtual void TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button );
908
909 private: // Update.
910
911   /**
912    * @brief Called by editable UI controls when key events are received.
913    *
914    * @param[in] text The text to insert.
915    * @param[in] type Used to distinguish between regular key events and IMF events.
916    */
917   void InsertText( const std::string& text, InsertType type );
918
919   /**
920    * @brief Paste given string into Text model
921    * @param[in] stringToPaste this string will be inserted into the text model
922    */
923   void PasteText( const std::string& stringToPaste );
924
925   /**
926    * @brief Remove a given number of characters
927    *
928    * When predictve text is used the pre-edit text is removed and inserted again with the new characters.
929    * The UpdateInputStyleType @type parameter if set to DONT_UPDATE_INPUT_STYLE avoids to update the input
930    * style when pre-edit text is removed.
931    *
932    * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
933    * @param[in] numberOfCharacters The number of characters to delete from the cursorOffset.
934    * @param[in] type Whether to update the input style.
935    * @return True if the remove was successful.
936    */
937   bool RemoveText( int cursorOffset,
938                    int numberOfCharacters,
939                    UpdateInputStyleType type  );
940
941   /**
942    * @brief Checks if text is selected and if so removes it.
943    * @return true if text was removed
944    */
945   bool RemoveSelectedText();
946
947 private: // Relayout.
948
949   /**
950    * @brief Lays-out the text.
951    *
952    * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
953    *
954    * @param[in] size A the size of a bounding box to layout text within.
955    * @param[in] operations The layout operations which need to be done.
956    * @param[out] layoutSize The size of the laid-out text.
957    */
958   bool DoRelayout( const Size& size,
959                    OperationsMask operations,
960                    Size& layoutSize );
961
962   /**
963    * @brief Calulates the vertical offset to align the text inside the bounding box.
964    *
965    * @param[in] size The size of the bounding box.
966    */
967   void CalculateVerticalOffset( const Size& size );
968
969 private: // Events.
970
971   /**
972    * @brief Process queued events which modify the model.
973    */
974   void ProcessModifyEvents();
975
976   /**
977    * @brief Used to process an event queued from SetText()
978    */
979   void TextReplacedEvent();
980
981   /**
982    * @brief Used to process an event queued from key events etc.
983    */
984   void TextInsertedEvent();
985
986   /**
987    * @brief Used to process an event queued from backspace key etc.
988    */
989   void TextDeletedEvent();
990
991   /**
992    * @brief Creates a selection event.
993    *
994    * It could be called from the TapEvent (double tap) or when the text selection popup's sellect all button is pressed.
995    *
996    * @param[in] x The x position relative to the top-left of the parent control.
997    * @param[in] y The y position relative to the top-left of the parent control.
998    * @param[in] selectAll Whether the whole text is selected.
999    */
1000   void SelectEvent( float x, float y, bool selectAll );
1001
1002   /**
1003    * @brief Helper to KeyEvent() to handle the backspace case.
1004    *
1005    * @return True if a character was deleted.
1006    */
1007   bool BackspaceKeyEvent();
1008
1009 private: // Helpers.
1010
1011   /**
1012    * @brief Used to remove the text included the placeholder text.
1013    */
1014   void ResetText();
1015
1016   /**
1017    * @brief Helper to show the place holder text..
1018    */
1019   void ShowPlaceholderText();
1020
1021   /**
1022    * @brief Helper to clear font-specific data (only).
1023    */
1024   void ClearFontData();
1025
1026   /**
1027    * @brief Helper to clear text's style data.
1028    */
1029   void ClearStyleData();
1030
1031   /**
1032    * @brief Used to reset the cursor position after setting a new text.
1033    *
1034    * @param[in] cursorIndex Where to place the cursor.
1035    */
1036   void ResetCursorPosition( CharacterIndex cursorIndex );
1037
1038   /**
1039    * @brief Used to reset the scroll position after setting a new text.
1040    */
1041   void ResetScrollPosition();
1042
1043 private: // Private contructors & copy operator.
1044
1045   /**
1046    * @brief Private constructor.
1047    */
1048   Controller();
1049
1050   /**
1051    * @brief Private constructor.
1052    */
1053   Controller( ControlInterface* controlInterface );
1054
1055   /**
1056    * @brief Private constructor.
1057    */
1058   Controller( ControlInterface* controlInterface,
1059               EditableControlInterface* editableControlInterface );
1060
1061   // Undefined
1062   Controller( const Controller& handle );
1063
1064   // Undefined
1065   Controller& operator=( const Controller& handle );
1066
1067 protected: // Destructor.
1068
1069   /**
1070    * @brief A reference counted object may only be deleted by calling Unreference().
1071    */
1072   virtual ~Controller();
1073
1074 private:
1075
1076   struct Impl;
1077   Impl* mImpl;
1078 };
1079
1080 } // namespace Text
1081
1082 } // namespace Toolkit
1083
1084 } // namespace Dali
1085
1086 #endif // DALI_TOOLKIT_TEXT_CONTROLLER_H