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