1 #ifndef __DALI_TOOLKIT_TEXT_DECORATOR_H__
2 #define __DALI_TOOLKIT_TEXT_DECORATOR_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
46 typedef IntrusivePtr<Decorator> DecoratorPtr;
48 // Used to set the cursor positions etc.
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
56 // Determines which of the cursors are active (if any).
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
64 // The state information for grab handle events
72 // The set the selection-handle positions etc.
75 PRIMARY_SELECTION_HANDLE,
76 SECONDARY_SELECTION_HANDLE,
77 SELECTION_HANDLE_COUNT
80 enum SelectionHandleState
82 SELECTION_HANDLE_PRESSED,
83 SELECTION_HANDLE_RELEASED
87 * @brief A Text Decorator is used to display cursors, handles, selection highlights and pop-ups.
89 * The decorator is responsible for clipping decorations which are positioned outside of the parent area.
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).
94 * Selection handles will be flipped around to ensure they do not exceed the Decoration Bounding Box. ( Stay visible ).
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.
99 class Decorator : public RefObject
108 * @brief Constructor.
113 * @brief Virtual destructor.
115 virtual ~Observer() {};
118 * @brief An input event from the grab handle.
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.
124 virtual void GrabHandleEvent( GrabHandleState state, float x, float y ) = 0;
128 * @brief Create a new instance of a Decorator.
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.
134 static DecoratorPtr New( Dali::Toolkit::Internal::Control& parent, Observer& observer );
137 * @brief Set the bounding box which handles, popup and similar decorations will not exceed.
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.
144 * ------------------------------------------
146 * |o---------------------------------------|
148 * || Bounding Box || boundary height
150 * |----------------------------------------|
151 * ------------------------------------------
154 * @param[in] boundingBox Vector( x coordinate, y coordinate, width, height )
156 void SetBoundingBox( const Rect<int>& boundingBox );
159 * @brief Retrieve the bounding box origin and dimensions.
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
164 const Rect<int>& GetBoundingBox() const;
167 * @brief The decorator waits until a relayout before creating actors etc.
169 * @param[in] size The size of the parent control after size-negotiation.
171 void Relayout( const Dali::Vector2& size );
174 * @brief Updates the decorator's actor positions after scrolling.
176 * @param[in] scrollOffset The scroll offset.
178 void UpdatePositions( const Vector2& scrollOffset );
181 * @brief Sets which of the cursors are active.
183 * @note Cursor will only be visible if within the parent area.
184 * @param[in] activeCursor Which of the cursors should be active (if any).
186 void SetActiveCursor( ActiveCursor activeCursor );
189 * @brief Query which of the cursors are active.
191 * @return Which of the cursors are active (if any).
193 unsigned int GetActiveCursor() const;
196 * @brief Sets the position of a cursor.
198 * @param[in] cursor The cursor to set.
199 * @param[in] x The x position relative to the top-left of the parent control.
200 * @param[in] y The y position relative to the top-left of the parent control.
201 * @param[in] cursorHeight The logical height of the cursor.
202 * @param[in] lineHeight The logical height of the line.
204 void SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight );
207 * @brief Retrieves the position, height and lineHeight of a cursor.
209 * @param[in] cursor The cursor to get.
210 * @param[out] x The x position relative to the top-left of the parent control.
211 * @param[out] y The y position relative to the top-left of the parent control.
212 * @param[out] cursorHeight The logical height of the cursor.
213 * @param[out] lineHeight The logical height of the line.
215 void GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const;
218 * @brief Retrieves the position of a cursor.
220 * @param[in] cursor The cursor to get.
222 * @return The position.
224 const Vector2& GetPosition( Cursor cursor ) const;
227 * @brief Sets the color for a cursor.
229 * @param[in] cursor Whether this color is for the primary or secondary cursor.
230 * @param[in] color The color to use.
232 void SetColor( Cursor cursor, const Dali::Vector4& color );
235 * @brief Retrieves the color for a cursor.
237 * @param[in] cursor Whether this color is for the primary or secondary cursor.
238 * @return The cursor color.
240 const Dali::Vector4& GetColor( Cursor cursor ) const;
243 * @brief Start blinking the cursor; see also SetCursorBlinkDuration().
245 void StartCursorBlink();
248 * @brief Stop blinking the cursor.
250 void StopCursorBlink();
253 * @brief Set the interval between cursor blinks.
255 * @param[in] seconds The interval in seconds.
257 void SetCursorBlinkInterval( float seconds );
260 * @brief Retrieves the blink-interval for a cursor.
262 * @return The cursor blink-interval.
264 float GetCursorBlinkInterval() const;
267 * @brief The cursor will stop blinking after this duration.
269 * @param[in] seconds The duration in seconds.
271 void SetCursorBlinkDuration( float seconds );
274 * @brief Retrieves the blink-duration for a cursor.
276 * @return The cursor blink-duration.
278 float GetCursorBlinkDuration() const;
281 * @brief Sets whether the grab handle is active.
283 * @note The grab handle follows the cursor position set with SetPosition(Cursor, ...)
284 * @param[in] active True if the grab handle should be active.
286 void SetGrabHandleActive( bool active );
289 * @brief Query whether the grab handle is active.
291 * @return True if the grab handle should be active.
293 bool IsGrabHandleActive() const;
296 * @brief Sets the image for the grab handle.
298 * @param[in] image The image to use.
300 void SetGrabHandleImage( Dali::Image image );
303 * @brief Retrieves the image for the grab handle.
305 * @return The grab handle image.
307 Dali::Image GetGrabHandleImage() const;
310 * @brief Sets whether the selection handles and highlight are active.
312 * @param[in] active True if the selection handles and highlight are active.
314 void SetSelectionActive( bool active );
317 * @brief Query whether the selection handles and highlight are active.
319 * @return True if the selection handles and highlight are active.
321 bool IsSelectionActive() const;
324 * @brief Sets the position of a selection handle.
326 * @param[in] handle The handle to set.
327 * @param[in] x The x position relative to the top-left of the parent control.
328 * @param[in] y The y position relative to the top-left of the parent control.
329 * @param[in] lineHeight The logical line height at this position.
331 void SetPosition( SelectionHandle handle, float x, float y, float lineHeight );
334 * @brief Retrieves the position of a selection handle.
336 * @param[in] handle The handle to get.
337 * @param[out] x The x position relative to the top-left of the parent control.
338 * @param[out] y The y position relative to the top-left of the parent control.
339 * @param[out] cursorHeight The logical cursor height at this position.
341 void GetPosition( SelectionHandle handle, float& x, float& y, float& cursorHeight ) const;
344 * @brief Sets the image for one of the selection handles.
346 * @param[in] handle The selection handle.
347 * @param[in] state A different image can be set for the pressed/released states.
348 * @param[in] image The image to use.
350 void SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image );
353 * @brief Retrieves the image for a selection handle.
355 * @param[in] handle The selection handle.
356 * @param[in] state A different image can be set for the pressed/released states.
359 Dali::Image GetImage( SelectionHandle handle, SelectionHandleState state ) const;
362 * @brief Adds a quad to the existing selection highlights.
364 * @param[in] x1 The top-left x position.
365 * @param[in] y1 The top-left y position.
366 * @param[in] x2 The bottom-right x position.
367 * @param[in] y3 The bottom-right y position.
369 void AddHighlight( float x1, float y1, float x2, float y2 );
372 * @brief Removes all of the previously added highlights.
374 void ClearHighlights();
377 * @brief Set the Selection Popup to show or hide via the active flaf
378 * @param[in] active true to show, false to hide
380 void SetPopupActive( bool active );
383 * @brief Query whether the Selection Popup is active.
385 * @return True if the Selection Popup should be active.
387 bool IsPopupActive() const;
392 * @brief A reference counted object may only be deleted by calling Unreference().
394 virtual ~Decorator();
399 * @brief Private constructor.
400 * @param[in] parent Decorations will be added to this parent control.
401 * @param[in] observer A class which receives input events from Decorator components.
403 Decorator(Dali::Toolkit::Internal::Control& parent, Observer& observer );
406 Decorator( const Decorator& handle );
409 Decorator& operator=( const Decorator& handle );
418 } // namespace Toolkit
422 #endif // __DALI_TOOLKIT_TEXT_DECORATOR_H__