TextField property updates
[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   GRAB_HANDLE_SCROLLING,
71   GRAB_HANDLE_STOP_SCROLLING
72 };
73
74 // Used to set different grab handle images
75 enum GrabHandleImageType
76 {
77   GRAB_HANDLE_IMAGE_PRESSED,
78   GRAB_HANDLE_IMAGE_RELEASED
79 };
80
81 // The set the selection-handle positions etc.
82 enum SelectionHandle
83 {
84   PRIMARY_SELECTION_HANDLE,
85   SECONDARY_SELECTION_HANDLE,
86   SELECTION_HANDLE_COUNT
87 };
88
89 enum SelectionHandleState
90 {
91   SELECTION_HANDLE_PRESSED,
92   SELECTION_HANDLE_RELEASED
93 };
94
95 /**
96  * @brief A Text Decorator is used to display cursors, handles, selection highlights and pop-ups.
97  *
98  * The decorator is responsible for clipping decorations which are positioned outside of the parent area.
99  *
100  * The Popup decoration will be positioned either above the Grab handle or above the selection handles but if doing so
101  * would cause the Popup to exceed the Decoration Bounding Box ( see SetBoundingBox API ) the the Popup will be repositioned below the handle(s).
102  *
103  * Selection handles will be flipped around to ensure they do not exceed the Decoration Bounding Box. ( Stay visible ).
104  *
105  * Decorator components forward input events to a controller class through an observer interface.
106  * The controller is responsible for selecting which components are active.
107  */
108 class Decorator : public RefObject
109 {
110 public:
111
112   class Observer
113   {
114   public:
115
116     /**
117      * @brief Constructor.
118      */
119     Observer() {};
120
121     /**
122      * @brief Virtual destructor.
123      */
124     virtual ~Observer() {};
125
126     /**
127      * @brief An input event from the grab handle.
128      *
129      * @param[in] state The grab handle state.
130      * @param[in] x The x position relative to the top-left of the parent control.
131      * @param[in] y The y position relative to the top-left of the parent control.
132      */
133     virtual void GrabHandleEvent( GrabHandleState state, float x, float y ) = 0;
134   };
135
136   /**
137    * @brief Create a new instance of a Decorator.
138    *
139    * @param[in] parent Decorations will be added to this parent control.
140    * @param[in] observer A class which receives input events from Decorator components.
141    * @return A pointer to a new Decorator.
142    */
143   static DecoratorPtr New( Dali::Toolkit::Internal::Control& parent, Observer& observer );
144
145   /**
146    * @brief Set the bounding box which handles, popup and similar decorations will not exceed.
147    *
148    * The default value is the width and height of the stage from the top left origin.
149    * If a title bar for example is on the top of the screen then the y should be the title's height and
150    * the boundary height the stage height minus the title's height.
151    * Restrictions - The boundary box should be set up with a fixed z position for the text-input and the default camera.
152    *
153    * ------------------------------------------
154    * |(x,y)                                   |
155    * |o---------------------------------------|
156    * ||                                      ||
157    * ||            Bounding Box              || boundary height
158    * ||                                      ||
159    * |----------------------------------------|
160    * ------------------------------------------
161    *               boundary width
162    *
163    * @param[in] boundingBox Vector( x coordinate, y coordinate, width, height )
164    */
165   void SetBoundingBox( const Rect<int>& boundingBox );
166
167   /**
168    * @brief Retrieve the bounding box origin and dimensions.
169    *
170    * default is set once control is added to stage, before this the return vector will be Vector4:ZERO
171    * @return Rect<int> the bounding box origin, width and height
172    */
173   const Rect<int>& GetBoundingBox() const;
174
175   /**
176    * @brief The decorator waits until a relayout before creating actors etc.
177    *
178    * @param[in] size The size of the parent control after size-negotiation.
179    */
180   void Relayout( const Dali::Vector2& size );
181
182   /**
183    * @brief Updates the decorator's actor positions after scrolling.
184    *
185    * @param[in] scrollOffset The scroll offset.
186    */
187   void UpdatePositions( const Vector2& scrollOffset );
188
189   /**
190    * @brief Sets which of the cursors are active.
191    *
192    * @note Cursor will only be visible if within the parent area.
193    * @param[in] activeCursor Which of the cursors should be active (if any).
194    */
195   void SetActiveCursor( ActiveCursor activeCursor );
196
197   /**
198    * @brief Query which of the cursors are active.
199    *
200    * @return  Which of the cursors are active (if any).
201    */
202   unsigned int GetActiveCursor() const;
203
204   /**
205    * @brief Sets the position of a cursor.
206    *
207    * @param[in] cursor The cursor to set.
208    * @param[in] x The x position relative to the top-left of the parent control.
209    * @param[in] y The y position relative to the top-left of the parent control.
210    * @param[in] cursorHeight The logical height of the cursor.
211    * @param[in] lineHeight The logical height of the line.
212    */
213   void SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight );
214
215   /**
216    * @brief Retrieves the position, height and lineHeight of a cursor.
217    *
218    * @param[in] cursor The cursor to get.
219    * @param[out] x The x position relative to the top-left of the parent control.
220    * @param[out] y The y position relative to the top-left of the parent control.
221    * @param[out] cursorHeight The logical height of the cursor.
222    * @param[out] lineHeight The logical height of the line.
223    */
224   void GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const;
225
226   /**
227    * @brief Retrieves the position of a cursor.
228    *
229    * @param[in] cursor The cursor to get.
230    *
231    * @return The position.
232    */
233   const Vector2& GetPosition( Cursor cursor ) const;
234
235   /**
236    * @brief Sets the color for a cursor.
237    *
238    * @param[in] cursor Whether this color is for the primary or secondary cursor.
239    * @param[in] color The color to use.
240    */
241   void SetColor( Cursor cursor, const Dali::Vector4& color );
242
243   /**
244    * @brief Retrieves the color for a cursor.
245    *
246    * @param[in] cursor Whether this color is for the primary or secondary cursor.
247    * @return The cursor color.
248    */
249   const Dali::Vector4& GetColor( Cursor cursor ) const;
250
251   /**
252    * @brief Start blinking the cursor; see also SetCursorBlinkDuration().
253    */
254   void StartCursorBlink();
255
256   /**
257    * @brief Stop blinking the cursor.
258    */
259   void StopCursorBlink();
260
261   /**
262    * @brief Set the interval between cursor blinks.
263    *
264    * @param[in] seconds The interval in seconds.
265    */
266   void SetCursorBlinkInterval( float seconds );
267
268   /**
269    * @brief Retrieves the blink-interval for a cursor.
270    *
271    * @return The cursor blink-interval.
272    */
273   float GetCursorBlinkInterval() const;
274
275   /**
276    * @brief The cursor will stop blinking after this duration.
277    *
278    * @param[in] seconds The duration in seconds.
279    */
280   void SetCursorBlinkDuration( float seconds );
281
282   /**
283    * @brief Retrieves the blink-duration for a cursor.
284    *
285    * @return The cursor blink-duration.
286    */
287   float GetCursorBlinkDuration() const;
288
289   /**
290    * @brief Sets whether the grab handle is active.
291    *
292    * @note The grab handle follows the cursor position set with SetPosition(Cursor, ...)
293    * @param[in] active True if the grab handle should be active.
294    */
295   void SetGrabHandleActive( bool active );
296
297   /**
298    * @brief Query whether the grab handle is active.
299    *
300    * @return True if the grab handle should be active.
301    */
302   bool IsGrabHandleActive() const;
303
304   /**
305    * @brief Sets the image for the grab handle.
306    *
307    * @param[in] type A different image can be set for the pressed/released states.
308    * @param[in] image The image to use.
309    */
310   void SetGrabHandleImage( GrabHandleImageType type, Dali::Image image );
311
312   /**
313    * @brief Retrieves the image for the grab handle.
314    *
315    * @param[in] type A different image can be set for the pressed/released states.
316    * @return The grab handle image.
317    */
318   Dali::Image GetGrabHandleImage( GrabHandleImageType type ) const;
319
320   /**
321    * @brief Sets whether the selection handles and highlight are active.
322    *
323    * @param[in] active True if the selection handles and highlight are active.
324    */
325   void SetSelectionActive( bool active );
326
327   /**
328    * @brief Query whether the selection handles and highlight are active.
329    *
330    * @return True if the selection handles and highlight are active.
331    */
332   bool IsSelectionActive() const;
333
334   /**
335    * @brief Sets the position of a selection handle.
336    *
337    * @param[in] handle The handle to set.
338    * @param[in] x The x position relative to the top-left of the parent control.
339    * @param[in] y The y position relative to the top-left of the parent control.
340    * @param[in] lineHeight The logical line height at this position.
341    */
342   void SetPosition( SelectionHandle handle, float x, float y, float lineHeight );
343
344   /**
345    * @brief Retrieves the position of a selection handle.
346    *
347    * @param[in] handle The handle to get.
348    * @param[out] x The x position relative to the top-left of the parent control.
349    * @param[out] y The y position relative to the top-left of the parent control.
350    * @param[out] cursorHeight The logical cursor height at this position.
351    */
352   void GetPosition( SelectionHandle handle, float& x, float& y, float& cursorHeight ) const;
353
354   /**
355    * @brief Sets the image for one of the selection handles.
356    *
357    * @param[in] state A different image can be set for the pressed/released states.
358    * @param[in] image The image to use.
359    */
360   void SetLeftSelectionImage( SelectionHandleState state, Dali::Image image );
361
362   /**
363    * @brief Retrieves the image for a selection handle.
364    *
365    * @param[in] state A different image can be set for the pressed/released states.
366    * @return The image.
367    */
368   Dali::Image GetLeftSelectionImage( SelectionHandleState state ) const;
369
370   /**
371    * @brief Sets the image for one of the selection handles.
372    *
373    * @param[in] state A different image can be set for the pressed/released states.
374    * @param[in] image The image to use.
375    */
376   void SetRightSelectionImage( SelectionHandleState state, Dali::Image image );
377
378   /**
379    * @brief Retrieves the image for a selection handle.
380    *
381    * @param[in] state A different image can be set for the pressed/released states.
382    * @return The image.
383    */
384   Dali::Image GetRightSelectionImage( SelectionHandleState state ) const;
385
386   /**
387    * @brief Adds a quad to the existing selection highlights.
388    *
389    * @param[in] x1 The top-left x position.
390    * @param[in] y1 The top-left y position.
391    * @param[in] x2 The bottom-right x position.
392    * @param[in] y3 The bottom-right y position.
393    */
394   void AddHighlight( float x1, float y1, float x2, float y2 );
395
396   /**
397    * @brief Removes all of the previously added highlights.
398    */
399   void ClearHighlights();
400
401   /**
402    * @brief Sets the selection highlight color.
403    *
404    * @param[in] image The image to use.
405    */
406   void SetHighlightColor( const Vector4& color );
407
408   /**
409    * @brief Retrieves the selection highlight color.
410    *
411    * @return The image.
412    */
413   const Vector4& GetHighlightColor() const;
414
415   /**
416    * @brief Set the Selection Popup to show or hide via the active flaf
417    * @param[in] active true to show, false to hide
418    */
419   void SetPopupActive( bool active );
420
421   /**
422    * @brief Query whether the Selection Popup is active.
423    *
424    * @return True if the Selection Popup should be active.
425    */
426   bool IsPopupActive() const;
427
428   /**
429    * @brief Sets the scroll threshold.
430    *
431    * It defines a square area inside the control, close to the edge.
432    * When the cursor enters this area, the decorator starts to send scroll events.
433    *
434    * @param[in] threshold The scroll threshold.
435    */
436   void SetScrollThreshold( float threshold );
437
438   /**
439    * @brief Retrieves the scroll threshold.
440    *
441    * @retunr The scroll threshold.
442    */
443   float GetScrollThreshold() const;
444
445   /**
446    * @brief Sets the scroll speed.
447    *
448    * Is the distance the text is going to be scrolled during a scroll interval.
449    *
450    * @param[in] speed The scroll speed.
451    */
452   void SetScrollSpeed( float speed );
453
454   /**
455    * @brief Retrieves the scroll speed.
456    *
457    * @return The scroll speed.
458    */
459   float GetScrollSpeed() const;
460
461   /**
462    * @brief Sets the scroll interval.
463    *
464    * @param[in] seconds The scroll interval in seconds.
465    */
466   void SetScrollTickInterval( float seconds );
467
468   /**
469    * @brief Retrieves the scroll interval.
470    *
471    * @return The scroll interval.
472    */
473   float GetScrollTickInterval() const;
474
475 protected:
476
477   /**
478    * @brief A reference counted object may only be deleted by calling Unreference().
479    */
480   virtual ~Decorator();
481
482 private:
483
484   /**
485    * @brief Private constructor.
486    * @param[in] parent Decorations will be added to this parent control.
487    * @param[in] observer A class which receives input events from Decorator components.
488    */
489   Decorator(Dali::Toolkit::Internal::Control& parent, Observer& observer );
490
491   // Undefined
492   Decorator( const Decorator& handle );
493
494   // Undefined
495   Decorator& operator=( const Decorator& handle );
496
497 private:
498
499   struct Impl;
500   Impl* mImpl;
501 };
502 } // namespace Text
503
504 } // namespace Toolkit
505
506 } // namespace Dali
507
508 #endif // __DALI_TOOLKIT_TEXT_DECORATOR_H__