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