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