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