Merge "Skeleton Decorator API" into new_text
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / text / decorator / text-decorator.h
1 #ifndef __DALI_TOOLKIT_TEXT_DECORATOR_H__
2 #define __DALI_TOOLKIT_TEXT_DECORATOR_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/object/ref-object.h>
24
25 namespace Dali
26 {
27
28 class Image;
29 class Vector2;
30 class Vector4;
31
32 namespace Toolkit
33 {
34
35 class ControlImpl;
36
37 namespace Text
38 {
39
40 class Decorator;
41 typedef IntrusivePtr<Decorator> DecoratorPtr;
42
43 // Used to set the cursor positions etc.
44 enum Cursor
45 {
46   PRIMARY_CURSOR,   ///< The primary cursor for bidirectional text (or the regular cursor for single-direction text)
47   SECONDARY_CURSOR, ///< The secondary cursor for bidirectional text
48   CURSOR_COUNT
49 };
50
51 // Determines which of the cursors are active (if any).
52 enum ActiveCursor
53 {
54   ACTIVE_CURSOR_NONE,    ///< Neither primary nor secondary cursor are active
55   ACTIVE_CURSOR_PRIMARY, ///< Primary cursor is active (only)
56   ACTIVE_CURSOR_BOTH     ///< Both primary and secondary cursor are active
57 };
58
59 /**
60  * @brief A Text Decorator is used to display cursors, handles, selection highlights and pop-ups.
61  *
62  * The decorator is responsible for clipping decorations which are positioned outside of the parent area.
63  * In some cases the decorations will be moved or flipped around, to maintain visibility on-screen.
64  */
65 class Decorator : public RefObject
66 {
67 public:
68
69   /**
70    * @brief Create a new instance of a Decorator.
71    *
72    * @param[in] parent Decorations will be added to this parent control.
73    * @return A pointer to a new Decorator.
74    */
75   static DecoratorPtr New( ControlImpl& parent );
76
77   /**
78    * @brief The decorator waits until a relayout before creating actors etc.
79    *
80    * @param[in] size The size of the parent control after size-negotiation.
81    */
82   void Relayout( const Dali::Vector2& size );
83
84   /**
85    * @brief Sets which of the cursors are active.
86    *
87    * @note Cursor will only be visible if within the parent area.
88    * @param[in] activeCursor Which of the cursors should be active (if any).
89    */
90   void SetActiveCursor( ActiveCursor activeCursor );
91
92   /**
93    * @brief Sets whether a cursor should be visible.
94    *
95    * @return  Which of the cursors are active (if any).
96    */
97   unsigned int GetActiveCursor() const;
98
99   /**
100    * @brief Sets the position of a cursor.
101    *
102    * @param[in] cursor The cursor to set.
103    * @param[in] x The x position relative to the top-left of the parent control.
104    * @param[in] y The y position relative to the top-left of the parent control.
105    * @param[in] height The logical height of the cursor.
106    */
107   void SetPosition( Cursor cursor, float x, float y, float height );
108
109   /**
110    * @brief Retrieves the position of a cursor.
111    *
112    * @param[in] cursor The cursor to get.
113    * @param[out] x The x position relative to the top-left of the parent control.
114    * @param[out] y The y position relative to the top-left of the parent control.
115    * @param[out] height The logical height of the cursor.
116    */
117   void GetPosition( Cursor cursor, float& x, float& y, float& height ) const;
118
119   /**
120    * @brief Sets the image for a cursor.
121    *
122    * @param[in] cursor The cursor to set.
123    * @param[in] image The image to use.
124    */
125   void SetImage( Cursor cursor, Dali::Image image );
126
127   /**
128    * @brief Retrieves the image for a cursor.
129    *
130    * @return The cursor image.
131    */
132   Dali::Image GetImage( Cursor cursor ) const;
133
134   /**
135    * @brief Sets the color for a cursor.
136    *
137    * @param[in] cursor The cursor to set.
138    * @param[in] color The color to use.
139    */
140   void SetColor( Cursor cursor, const Dali::Vector4& color );
141
142   /**
143    * @brief Retrieves the color for a cursor.
144    *
145    * @return The cursor color.
146    */
147   const Dali::Vector4& GetColor( Cursor cursor ) const;
148
149   /**
150    * @brief Start blinking the cursor; see also SetCursorBlinkDuration().
151    */
152   void StartCursorBlink();
153
154   /**
155    * @brief Stop blinking the cursor.
156    */
157   void StopCursorBlink();
158
159   /**
160    * @brief Set the interval between cursor blinks.
161    *
162    * @param[in] seconds The interval in seconds.
163    */
164   void SetCursorBlinkInterval( float seconds );
165
166   /**
167    * @brief Retrieves the blink-interval for a cursor.
168    *
169    * @return The cursor blink-interval.
170    */
171   float GetCursorBlinkInterval() const;
172
173   /**
174    * @brief The cursor will stop blinking after this duration.
175    *
176    * @param[in] seconds The duration in seconds.
177    */
178   void SetCursorBlinkDuration( float seconds );
179
180   /**
181    * @brief Retrieves the blink-duration for a cursor.
182    *
183    * @return The cursor blink-duration.
184    */
185   float GetCursorBlinkDuration() const;
186
187 protected:
188
189   /**
190    * @brief A reference counted object may only be deleted by calling Unreference().
191    */
192   virtual ~Decorator();
193
194 private:
195
196   /**
197    * @brief Private constructor.
198    * @param[in] parent Decorations will be added to this parent control.
199    */
200   Decorator(ControlImpl& parent);
201
202   // Undefined
203   Decorator( const Decorator& handle );
204
205   // Undefined
206   Decorator& operator=( const Decorator& handle );
207
208 private:
209
210   struct Impl;
211   Impl* mImpl;
212 };
213 } // namespace Text
214
215 } // namespace Toolkit
216
217 } // namespace Dali
218
219 #endif // __DALI_TOOLKIT_TEXT_DECORATOR_H__