Adding TextSelectionPopup control
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / 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 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/math/vector2.h>
26
27 namespace Dali
28 {
29
30 class Image;
31 class Vector2;
32 class Vector4;
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39 class Control;
40 }
41
42 namespace Text
43 {
44
45 class Decorator;
46 typedef IntrusivePtr<Decorator> DecoratorPtr;
47
48 // Used to set the cursor positions etc.
49 enum Cursor
50 {
51   PRIMARY_CURSOR,   ///< The primary cursor for bidirectional text (or the regular cursor for single-direction text)
52   SECONDARY_CURSOR, ///< The secondary cursor for bidirectional text
53   CURSOR_COUNT
54 };
55
56 // Determines which of the cursors are active (if any).
57 enum ActiveCursor
58 {
59   ACTIVE_CURSOR_NONE,    ///< Neither primary nor secondary cursor are active
60   ACTIVE_CURSOR_PRIMARY, ///< Primary cursor is active (only)
61   ACTIVE_CURSOR_BOTH     ///< Both primary and secondary cursor are active
62 };
63
64 // The state information for grab handle events
65 enum GrabHandleState
66 {
67   GRAB_HANDLE_TAPPED,
68   GRAB_HANDLE_PRESSED,
69   GRAB_HANDLE_RELEASED
70 };
71
72 // The set the selection-handle positions etc.
73 enum SelectionHandle
74 {
75   PRIMARY_SELECTION_HANDLE,
76   SECONDARY_SELECTION_HANDLE,
77   SELECTION_HANDLE_COUNT
78 };
79
80 enum SelectionHandleState
81 {
82   SELECTION_HANDLE_PRESSED,
83   SELECTION_HANDLE_RELEASED
84 };
85
86 /**
87  * @brief A Text Decorator is used to display cursors, handles, selection highlights and pop-ups.
88  *
89  * The decorator is responsible for clipping decorations which are positioned outside of the parent area.
90  *
91  * The Popup decoration will be positioned either above the Grab handle or above the selection handles but if doing so
92  * would cause the Popup to exceed the Decoration Bounding Box ( see SetBoundingBox API ) the the Popup will be repositioned below the handle(s).
93  *
94  * Selection handles will be flipped around to ensure they do not exceed the Decoration Bounding Box. ( Stay visible ).
95  *
96  * Decorator components forward input events to a controller class through an observer interface.
97  * The controller is responsible for selecting which components are active.
98  */
99 class Decorator : public RefObject
100 {
101 public:
102
103   class Observer
104   {
105   public:
106
107     /**
108      * @brief Constructor.
109      */
110     Observer() {};
111
112     /**
113      * @brief Virtual destructor.
114      */
115     virtual ~Observer() {};
116
117     /**
118      * @brief An input event from the grab handle.
119      *
120      * @param[in] state The grab handle state.
121      * @param[in] x The x position relative to the top-left of the parent control.
122      * @param[in] y The y position relative to the top-left of the parent control.
123      */
124     virtual void GrabHandleEvent( GrabHandleState state, float x, float y ) = 0;
125   };
126
127   /**
128    * @brief Create a new instance of a Decorator.
129    *
130    * @param[in] parent Decorations will be added to this parent control.
131    * @param[in] observer A class which receives input events from Decorator components.
132    * @return A pointer to a new Decorator.
133    */
134   static DecoratorPtr New( Dali::Toolkit::Internal::Control& parent, Observer& observer );
135
136   /**
137    * @brief Set the bounding box which handles, popup and similar decorations will not exceed.
138    *
139    * The default value is the width and height of the stage from the top left origin.
140    * If a title bar for example is on the top of the screen then the y should be the title's height and
141    * the boundary height the stage height minus the title's height.
142    * Restrictions - The boundary box should be set up with a fixed z position for the text-input and the default camera.
143    *
144    * ------------------------------------------
145    * |(x,y)                                   |
146    * |o---------------------------------------|
147    * ||                                      ||
148    * ||            Bounding Box              || boundary height
149    * ||                                      ||
150    * |----------------------------------------|
151    * ------------------------------------------
152    *               boundary width
153    *
154    * @param[in] boundingBox Vector( x coordinate, y coordinate, width, height )
155    */
156   void SetBoundingBox( const Rect<int>& boundingBox );
157
158   /**
159    * @brief Retrieve the bounding box origin and dimensions.
160    *
161    * default is set once control is added to stage, before this the return vector will be Vector4:ZERO
162    * @return Rect<int> the bounding box origin, width and height
163    */
164   const Rect<int>& GetBoundingBox() const;
165
166   /**
167    * @brief The decorator waits until a relayout before creating actors etc.
168    *
169    * @param[in] size The size of the parent control after size-negotiation.
170    * @param[in] scrollPosition The cursor, grab-handle positions etc. should be offset by this.
171    */
172   void Relayout( const Dali::Vector2& size, const Vector2& scrollPosition );
173
174   /**
175    * @brief Sets which of the cursors are active.
176    *
177    * @note Cursor will only be visible if within the parent area.
178    * @param[in] activeCursor Which of the cursors should be active (if any).
179    */
180   void SetActiveCursor( ActiveCursor activeCursor );
181
182   /**
183    * @brief Query which of the cursors are active.
184    *
185    * @return  Which of the cursors are active (if any).
186    */
187   unsigned int GetActiveCursor() const;
188
189   /**
190    * @brief Sets the position of a cursor.
191    *
192    * @param[in] cursor The cursor to set.
193    * @param[in] x The x position relative to the top-left of the parent control.
194    * @param[in] y The y position relative to the top-left of the parent control.
195    * @param[in] height The logical height of the cursor.
196    */
197   void SetPosition( Cursor cursor, float x, float y, float height );
198
199   /**
200    * @brief Retrieves the position of a cursor.
201    *
202    * @param[in] cursor The cursor to get.
203    * @param[out] x The x position relative to the top-left of the parent control.
204    * @param[out] y The y position relative to the top-left of the parent control.
205    * @param[out] height The logical height of the cursor.
206    */
207   void GetPosition( Cursor cursor, float& x, float& y, float& height ) const;
208
209   /**
210    * @brief Sets the color for a cursor.
211    *
212    * @param[in] cursor Whether this color is for the primary or secondary cursor.
213    * @param[in] color The color to use.
214    */
215   void SetColor( Cursor cursor, const Dali::Vector4& color );
216
217   /**
218    * @brief Retrieves the color for a cursor.
219    *
220    * @param[in] cursor Whether this color is for the primary or secondary cursor.
221    * @return The cursor color.
222    */
223   const Dali::Vector4& GetColor( Cursor cursor ) const;
224
225   /**
226    * @brief Start blinking the cursor; see also SetCursorBlinkDuration().
227    */
228   void StartCursorBlink();
229
230   /**
231    * @brief Stop blinking the cursor.
232    */
233   void StopCursorBlink();
234
235   /**
236    * @brief Set the interval between cursor blinks.
237    *
238    * @param[in] seconds The interval in seconds.
239    */
240   void SetCursorBlinkInterval( float seconds );
241
242   /**
243    * @brief Retrieves the blink-interval for a cursor.
244    *
245    * @return The cursor blink-interval.
246    */
247   float GetCursorBlinkInterval() const;
248
249   /**
250    * @brief The cursor will stop blinking after this duration.
251    *
252    * @param[in] seconds The duration in seconds.
253    */
254   void SetCursorBlinkDuration( float seconds );
255
256   /**
257    * @brief Retrieves the blink-duration for a cursor.
258    *
259    * @return The cursor blink-duration.
260    */
261   float GetCursorBlinkDuration() const;
262
263   /**
264    * @brief Sets whether the grab handle is active.
265    *
266    * @note The grab handle follows the cursor position set with SetPosition(Cursor, ...)
267    * @param[in] active True if the grab handle should be active.
268    */
269   void SetGrabHandleActive( bool active );
270
271   /**
272    * @brief Query whether the grab handle is active.
273    *
274    * @return True if the grab handle should be active.
275    */
276   bool IsGrabHandleActive() const;
277
278   /**
279    * @brief Sets the image for the grab handle.
280    *
281    * @param[in] image The image to use.
282    */
283   void SetGrabHandleImage( Dali::Image image );
284
285   /**
286    * @brief Retrieves the image for the grab handle.
287    *
288    * @return The grab handle image.
289    */
290   Dali::Image GetGrabHandleImage() const;
291
292   /**
293    * @brief Sets whether the selection handles and highlight are active.
294    *
295    * @param[in] active True if the selection handles and highlight are active.
296    */
297   void SetSelectionActive( bool active );
298
299   /**
300    * @brief Query whether the selection handles and highlight are active.
301    *
302    * @return True if the selection handles and highlight are active.
303    */
304   bool IsSelectionActive() const;
305
306   /**
307    * @brief Sets the position of a selection handle.
308    *
309    * @param[in] handle The handle to set.
310    * @param[in] x The x position relative to the top-left of the parent control.
311    * @param[in] y The y position relative to the top-left of the parent control.
312    * @param[in] cursorHeight The logical cursor height at this position.
313    */
314   void SetPosition( SelectionHandle handle, float x, float y, float cursorHeight );
315
316   /**
317    * @brief Retrieves the position of a selection handle.
318    *
319    * @param[in] handle The handle to get.
320    * @param[out] x The x position relative to the top-left of the parent control.
321    * @param[out] y The y position relative to the top-left of the parent control.
322    * @param[out] cursorHeight The logical cursor height at this position.
323    */
324   void GetPosition( SelectionHandle handle, float& x, float& y, float& cursorHeight ) const;
325
326   /**
327    * @brief Sets the image for one of the selection handles.
328    *
329    * @param[in] handle The selection handle.
330    * @param[in] state A different image can be set for the pressed/released states.
331    * @param[in] image The image to use.
332    */
333   void SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image );
334
335   /**
336    * @brief Retrieves the image for a selection handle.
337    *
338    * @param[in] handle The selection handle.
339    * @param[in] state A different image can be set for the pressed/released states.
340    * @return The image.
341    */
342   Dali::Image GetImage( SelectionHandle handle, SelectionHandleState state ) const;
343
344   /**
345    * @brief Set the Selection Popup to show or hide via the active flaf
346    * @param[in] active true to show, false to hide
347    */
348   void SetPopupActive( bool active );
349
350   /**
351    * @brief Query whether the Selection Popup is active.
352    *
353    * @return True if the Selection Popup should be active.
354    */
355   bool IsPopupActive() const;
356
357
358 protected:
359
360   /**
361    * @brief A reference counted object may only be deleted by calling Unreference().
362    */
363   virtual ~Decorator();
364
365 private:
366
367   /**
368    * @brief Private constructor.
369    * @param[in] parent Decorations will be added to this parent control.
370    * @param[in] observer A class which receives input events from Decorator components.
371    */
372   Decorator(Dali::Toolkit::Internal::Control& parent, Observer& observer );
373
374   // Undefined
375   Decorator( const Decorator& handle );
376
377   // Undefined
378   Decorator& operator=( const Decorator& handle );
379
380 private:
381
382   struct Impl;
383   Impl* mImpl;
384 };
385 } // namespace Text
386
387 } // namespace Toolkit
388
389 } // namespace Dali
390
391 #endif // __DALI_TOOLKIT_TEXT_DECORATOR_H__