Bidirectional support interface
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / text / text-controller.h
1 #ifndef __DALI_TOOLKIT_TEXT_CONTROLLER_H__
2 #define __DALI_TOOLKIT_TEXT_CONTROLLER_H__
3
4 /*
5  * Copyright (c) 2015 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/text/decorator/text-decorator.h>
23 #include <dali-toolkit/public-api/text/text-control-interface.h>
24 #include <dali-toolkit/public-api/text/text-view.h>
25
26 // EXTERNAL INCLUDES
27 #include <dali/public-api/common/intrusive-ptr.h>
28 #include <dali/public-api/math/vector3.h>
29 #include <dali/public-api/math/vector2.h>
30 #include <dali/public-api/object/ref-object.h>
31 #include <string>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Text
40 {
41
42 class Controller;
43 class LayoutEngine;
44
45 typedef IntrusivePtr<Controller> ControllerPtr;
46 typedef Dali::Toolkit::Text::ControlInterface ControlInterface;
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 an observer interface.
56  */
57 class Controller : public RefObject, public Decorator::Observer
58 {
59 private:
60
61   /**
62    * @brief Text related operations to be done in the relayout process.
63    */
64   enum OperationsMask
65   {
66     NO_OPERATION      = 0x0,
67     CONVERT_TO_UTF32  = 0x1,
68     GET_SCRIPTS       = 0x2,
69     VALIDATE_FONTS    = 0x4,
70     GET_LINE_BREAKS   = 0x8,
71     GET_WORD_BREAKS   = 0x10,
72     SHAPE_TEXT        = 0x20,
73     GET_GLYPH_METRICS = 0x40,
74     LAYOUT            = 0x80,
75     REORDER           = 0x100,
76     ALIGNMENT         = 0x200,
77     RENDER            = 0x400,
78     ALL_OPERATIONS    = 0xFFF
79   };
80
81 public:
82
83   /**
84    * @brief Create a new instance of a Controller.
85    *
86    * @param[in] controlInterface An interface used to request a text relayout.
87    * @return A pointer to a new Controller.
88    */
89   static ControllerPtr New( ControlInterface& controlInterface );
90
91   /**
92    * @brief Replaces any text previously set.
93    *
94    * @note This will be converted into UTF-32 when stored in the text model.
95    * @param[in] text A string of UTF-8 characters.
96    */
97   void SetText( const std::string& text );
98
99   /**
100    * @brief Called to enable text input.
101    *
102    * @note Only selectable or editable controls should calls this.
103    * @param[in] decorator Used to create cursor, selection handle decorations etc.
104    */
105   void EnableTextInput( DecoratorPtr decorator );
106
107   /**
108    * @brief Triggers a relayout which updates View (if necessary).
109    *
110    * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
111    * @param[in] size A the size of a bounding box to layout text within.
112    * @return True if the text model or decorations were updated.
113    */
114   bool Relayout( const Vector2& size );
115
116   /**
117    *
118    */
119   bool DoRelayout( const Vector2& size, OperationsMask operations );
120
121   /**
122    * @copydoc Control::GetNaturalSize()
123    */
124   Vector3 GetNaturalSize();
125
126   /**
127    * @copydoc Control::GetHeightForWidth()
128    */
129   float GetHeightForWidth( float width );
130
131   /**
132    * @brief Return the layout engine.
133    *
134    * @return A reference to the layout engine.
135    */
136   LayoutEngine& GetLayoutEngine();
137
138   /**
139    * @brief Return a view of the text.
140    *
141    * @return A reference to the view.
142    */
143   View& GetView();
144
145   /**
146    * @brief Caller by editable UI controls when keyboard focus is gained.
147    */
148   void KeyboardFocusGainEvent();
149
150   /**
151    * @brief Caller by editable UI controls when focus is lost.
152    */
153   void KeyboardFocusLostEvent();
154
155   /**
156    * @brief Caller by editable UI controls when a tap gesture occurs.
157    * @param[in] tapCount The number of taps.
158    * @param[in] x The x position relative to the top-left of the parent control.
159    * @param[in] y The y position relative to the top-left of the parent control.
160    */
161   void TapEvent( unsigned int tapCount, float x, float y );
162
163   /**
164    * @copydoc Dali::Toolkit::Text::Decorator::Observer::GrabHandleEvent()
165    */
166   virtual void GrabHandleEvent( GrabHandleState state, float x, float y );
167
168 protected:
169
170   /**
171    * @brief A reference counted object may only be deleted by calling Unreference().
172    */
173   virtual ~Controller();
174
175 private:
176
177   /**
178    * @brief Request a relayout using the ControlInterface.
179    */
180   void RequestRelayout();
181
182   /**
183    * @brief Private constructor.
184    */
185   Controller( ControlInterface& controlInterface );
186
187   // Undefined
188   Controller( const Controller& handle );
189
190   // Undefined
191   Controller& operator=( const Controller& handle );
192
193 private:
194
195   struct Impl;
196   Impl* mImpl;
197
198   // Avoid allocating this for non-editable controls
199   struct TextInput;
200 };
201
202 } // namespace Text
203
204 } // namespace Toolkit
205
206 } // namespace Dali
207
208 #endif // __DALI_TOOLKIT_TEXT_CONTROLLER_H__