Added interface for queuing input events in TextController
[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 // The state information for grab handle events
63 enum GrabHandleState
64 {
65   GRAB_HANDLE_MOVING,
66   GRAB_HANDLE_RELEASED
67 };
68
69 /**
70  * @brief A Text Decorator is used to display cursors, handles, selection highlights and pop-ups.
71  *
72  * The decorator is responsible for clipping decorations which are positioned outside of the parent area.
73  * In some cases the decorations will be moved or flipped around, to maintain visibility on-screen.
74  *
75  * Decorator components forward input events to a controller class through an observer interface.
76  * The controller is responsible for selecting which components are active.
77  */
78 class Decorator : public RefObject
79 {
80 public:
81
82   class Observer
83   {
84   public:
85
86     /**
87      * @brief Constructor.
88      */
89     Observer() {};
90
91     /**
92      * @brief Virtual destructor.
93      */
94     virtual ~Observer() {};
95
96     /**
97      * @brief An input event from the grab handle.
98      *
99      * @param[in] state The grab handle state.
100      * @param[in] x The x position relative to the top-left of the parent control.
101      */
102     virtual void GrabHandleEvent( GrabHandleState state, float x ) = 0;
103   };
104
105   /**
106    * @brief Create a new instance of a Decorator.
107    *
108    * @param[in] parent Decorations will be added to this parent control.
109    * @param[in] observer A class which receives input events from Decorator components.
110    * @return A pointer to a new Decorator.
111    */
112   static DecoratorPtr New( Dali::Toolkit::Internal::Control& parent, Observer& observer );
113
114   /**
115    * @brief The decorator waits until a relayout before creating actors etc.
116    *
117    * @param[in] size The size of the parent control after size-negotiation.
118    */
119   void Relayout( const Dali::Vector2& size );
120
121   /**
122    * @brief Sets which of the cursors are active.
123    *
124    * @note Cursor will only be visible if within the parent area.
125    * @param[in] activeCursor Which of the cursors should be active (if any).
126    */
127   void SetActiveCursor( ActiveCursor activeCursor );
128
129   /**
130    * @brief Query which of the cursors are active.
131    *
132    * @return  Which of the cursors are active (if any).
133    */
134   unsigned int GetActiveCursor() const;
135
136   /**
137    * @brief Sets the position of a cursor.
138    *
139    * @param[in] cursor The cursor to set.
140    * @param[in] x The x position relative to the top-left of the parent control.
141    * @param[in] y The y position relative to the top-left of the parent control.
142    * @param[in] height The logical height of the cursor.
143    */
144   void SetPosition( Cursor cursor, float x, float y, float height );
145
146   /**
147    * @brief Retrieves the position of a cursor.
148    *
149    * @param[in] cursor The cursor to get.
150    * @param[out] x The x position relative to the top-left of the parent control.
151    * @param[out] y The y position relative to the top-left of the parent control.
152    * @param[out] height The logical height of the cursor.
153    */
154   void GetPosition( Cursor cursor, float& x, float& y, float& height ) const;
155
156   /**
157    * @brief Sets the image for a cursor.
158    *
159    * @param[in] image The image to use.
160    */
161   void SetCursorImage( Dali::Image image );
162
163   /**
164    * @brief Retrieves the image for a cursor.
165    *
166    * @return The cursor image.
167    */
168   Dali::Image GetCursorImage() const;
169
170   /**
171    * @brief Sets the color for a cursor.
172    *
173    * @param[in] cursor Whether this color is for the primary or secondary cursor.
174    * @param[in] color The color to use.
175    */
176   void SetColor( Cursor cursor, const Dali::Vector4& color );
177
178   /**
179    * @brief Retrieves the color for a cursor.
180    *
181    * @param[in] cursor Whether this color is for the primary or secondary cursor.
182    * @return The cursor color.
183    */
184   const Dali::Vector4& GetColor( Cursor cursor ) const;
185
186   /**
187    * @brief Start blinking the cursor; see also SetCursorBlinkDuration().
188    */
189   void StartCursorBlink();
190
191   /**
192    * @brief Stop blinking the cursor.
193    */
194   void StopCursorBlink();
195
196   /**
197    * @brief Set the interval between cursor blinks.
198    *
199    * @param[in] seconds The interval in seconds.
200    */
201   void SetCursorBlinkInterval( float seconds );
202
203   /**
204    * @brief Retrieves the blink-interval for a cursor.
205    *
206    * @return The cursor blink-interval.
207    */
208   float GetCursorBlinkInterval() const;
209
210   /**
211    * @brief The cursor will stop blinking after this duration.
212    *
213    * @param[in] seconds The duration in seconds.
214    */
215   void SetCursorBlinkDuration( float seconds );
216
217   /**
218    * @brief Retrieves the blink-duration for a cursor.
219    *
220    * @return The cursor blink-duration.
221    */
222   float GetCursorBlinkDuration() const;
223
224   /**
225    * @brief Sets whether the grab handle is active.
226    *
227    * @note The grab handle follows the cursor position set with SetPosition(Cursor, ...)
228    * @param[in] active True if the grab handle should be active.
229    */
230   void SetGrabHandleActive( bool active );
231
232   /**
233    * @brief Query whether the grab handle is active.
234    *
235    * @return True if the grab handle should be active.
236    */
237   bool IsGrabHandleActive() const;
238
239   /**
240    * @brief Sets the image for the grab handle.
241    *
242    * @param[in] image The image to use.
243    */
244   void SetGrabHandleImage( Dali::Image image );
245
246   /**
247    * @brief Retrieves the image for the grab handle.
248    *
249    * @return The grab handle image.
250    */
251   Dali::Image GetGrabHandleImage() const;
252
253 protected:
254
255   /**
256    * @brief A reference counted object may only be deleted by calling Unreference().
257    */
258   virtual ~Decorator();
259
260 private:
261
262   /**
263    * @brief Private constructor.
264    * @param[in] parent Decorations will be added to this parent control.
265    * @param[in] observer A class which receives input events from Decorator components.
266    */
267   Decorator(Dali::Toolkit::Internal::Control& parent, Observer& observer );
268
269   // Undefined
270   Decorator( const Decorator& handle );
271
272   // Undefined
273   Decorator& operator=( const Decorator& handle );
274
275 private:
276
277   struct Impl;
278   Impl* mImpl;
279 };
280 } // namespace Text
281
282 } // namespace Toolkit
283
284 } // namespace Dali
285
286 #endif // __DALI_TOOLKIT_TEXT_DECORATOR_H__