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