25ad18996219f99167e9d271284c2b7647e89b9d
[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/text-view.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/public-api/common/intrusive-ptr.h>
26 #include <dali/public-api/math/vector3.h>
27 #include <dali/public-api/math/vector2.h>
28 #include <dali/public-api/object/ref-object.h>
29 #include <string>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Text
38 {
39
40 class Controller;
41 class LayoutEngine;
42
43 typedef IntrusivePtr<Controller> ControllerPtr;
44
45 /**
46  * @brief A Text Controller is used by UI Controls which display text.
47  *
48  * It manipulates the Logical & Visual text models on behalf of the UI Controls.
49  * It provides a view of the text that can be used by rendering back-ends.
50  */
51 class Controller : public RefObject
52 {
53 private:
54
55   /**
56    * @brief Text related operations to be done in the relayout process.
57    */
58   enum OperationsMask
59   {
60     NO_OPERATION      = 0x0,
61     CONVERT_TO_UTF32  = 0x1,
62     GET_SCRIPTS       = 0x2,
63     VALIDATE_FONTS    = 0x4,
64     GET_LINE_BREAKS   = 0x8,
65     GET_WORD_BREAKS   = 0x10,
66     SHAPE_TEXT        = 0x20,
67     GET_GLYPH_METRICS = 0x40,
68     LAYOUT            = 0x80,
69     REORDER           = 0x100,
70     ALIGNEMENT        = 0x200,
71     RENDER            = 0x400,
72     ALL_OPERATIONS    = 0xFFF
73   };
74
75 public:
76
77   /**
78    * @brief Create a new instance of a Controller.
79    *
80    * @return A pointer to a new Controller.
81    */
82   static ControllerPtr New();
83
84   /**
85    * @brief Replaces any text previously set.
86    *
87    * @note This will be converted into UTF-32 when stored in the text model.
88    * @param[in] text A string of UTF-8 characters.
89    */
90   void SetText( const std::string& text );
91
92   /**
93    * @brief Triggers a relayout which updates View (if necessary).
94    *
95    * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
96    * @param[in] size A the size of a bounding box to layout text within.
97    * @return True if the View was updated.
98    */
99   bool Relayout( const Vector2& size );
100
101   /**
102    *
103    */
104   bool DoRelayout( const Vector2& size, OperationsMask operations );
105
106   /**
107    * @copydoc Control::GetNaturalSize()
108    */
109   Vector3 GetNaturalSize();
110
111   /**
112    * @copydoc Control::GetHeightForWidth()
113    */
114   float GetHeightForWidth( float width );
115
116   /**
117    * @brief Return the layout engine.
118    *
119    * @return A reference to the layout engine.
120    */
121   LayoutEngine& GetLayoutEngine();
122
123   /**
124    * @brief Return a view of the text.
125    *
126    * @return A reference to the view.
127    */
128   View& GetView();
129
130 protected:
131
132   /**
133    * @brief A reference counted object may only be deleted by calling Unreference().
134    */
135   virtual ~Controller();
136
137 private:
138
139   /**
140    * @brief Private constructor.
141    */
142   Controller();
143
144   /**
145    * @brief Populates the visual model.
146    */
147   void UpdateVisualModel();
148
149   // Undefined
150   Controller( const Controller& handle );
151
152   // Undefined
153   Controller& operator=( const Controller& handle );
154
155 private:
156
157   struct Impl;
158   Impl* mImpl;
159
160   Size mControlSize;
161 };
162
163 } // namespace Text
164
165 } // namespace Toolkit
166
167 } // namespace Dali
168
169 #endif // __DALI_TOOLKIT_TEXT_CONTROLLER_H__