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>
27 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
42 typedef IntrusivePtr<Decorator> DecoratorPtr;
44 // Used to set the cursor positions etc.
47 PRIMARY_CURSOR, ///< The primary cursor for bidirectional text (or the regular cursor for single-direction text)
48 SECONDARY_CURSOR, ///< The secondary cursor for bidirectional text
52 // Determines which of the cursors are active (if any).
55 ACTIVE_CURSOR_NONE, ///< Neither primary nor secondary cursor are active
56 ACTIVE_CURSOR_PRIMARY, ///< Primary cursor is active (only)
57 ACTIVE_CURSOR_BOTH ///< Both primary and secondary cursor are active
60 // The state information for handle events.
70 // Used to set different handle images
74 HANDLE_IMAGE_RELEASED,
75 HANDLE_IMAGE_TYPE_COUNT
82 LEFT_SELECTION_HANDLE,
83 RIGHT_SELECTION_HANDLE,
88 * @brief A Text Decorator is used to display cursors, handles, selection highlights and pop-ups.
90 * The decorator is responsible for clipping decorations which are positioned outside of the parent area.
92 * The Popup decoration will be positioned either above the Grab handle or above the selection handles but if doing so
93 * would cause the Popup to exceed the Decoration Bounding Box ( see SetBoundingBox API ) the the Popup will be repositioned below the handle(s).
95 * Selection handles will be flipped around to ensure they do not exceed the Decoration Bounding Box. ( Stay visible ).
97 * Decorator components forward input events to a controller class through an interface.
98 * The controller is responsible for selecting which components are active.
100 class Decorator : public RefObject
104 class ControllerInterface
109 * @brief Constructor.
111 ControllerInterface() {};
114 * @brief Virtual destructor.
116 virtual ~ControllerInterface() {};
119 * @brief Query the target size of the UI control.
121 * @param[out] targetSize The size of the UI control the decorator is adding it's decorations to.
123 virtual void GetTargetSize( Vector2& targetSize ) = 0;
126 * @brief Add a decoration to the parent UI control.
128 * @param[in] decoration The actor displaying a decoration.
130 virtual void AddDecoration( Actor& actor, bool needsClipping ) = 0;
133 * @brief An input event from one of the handles.
135 * @param[in] handleType The handle's type.
136 * @param[in] state The handle's state.
137 * @param[in] x The x position relative to the top-left of the parent control.
138 * @param[in] y The y position relative to the top-left of the parent control.
140 virtual void DecorationEvent( HandleType handleType, HandleState state, float x, float y ) = 0;
144 * @brief Create a new instance of a Decorator.
146 * @param[in] controller The controller which receives input events from Decorator components.
147 * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
149 * @return A pointer to a new Decorator.
151 static DecoratorPtr New( ControllerInterface& controller,
152 TextSelectionPopupCallbackInterface& callbackInterface );
155 * @brief Set the bounding box which handles, popup and similar decorations will not exceed.
157 * The default value is the width and height of the stage from the top left origin.
158 * If a title bar for example is on the top of the screen then the y should be the title's height and
159 * the boundary height the stage height minus the title's height.
160 * Restrictions - The boundary box should be set up with a fixed z position for the text-input and the default camera.
162 * ------------------------------------------
164 * |o---------------------------------------|
166 * || Bounding Box || boundary height
168 * |----------------------------------------|
169 * ------------------------------------------
172 * @param[in] boundingBox Vector( x coordinate, y coordinate, width, height )
174 void SetBoundingBox( const Rect<int>& boundingBox );
177 * @brief Retrieve the bounding box origin and dimensions.
179 * default is set once control is added to stage, before this the return vector will be Vector4:ZERO
180 * @return Rect<int> the bounding box origin, width and height
182 const Rect<int>& GetBoundingBox() const;
185 * @brief The decorator waits until a relayout before creating actors etc.
187 * @param[in] size The size of the parent control after size-negotiation.
189 void Relayout( const Dali::Vector2& size );
192 * @brief Updates the decorator's actor positions after scrolling.
194 * @param[in] scrollOffset The scroll offset.
196 void UpdatePositions( const Vector2& scrollOffset );
199 * @brief Sets which of the cursors are active.
201 * @note Cursor will only be visible if within the parent area.
202 * @param[in] activeCursor Which of the cursors should be active (if any).
204 void SetActiveCursor( ActiveCursor activeCursor );
207 * @brief Query which of the cursors are active.
209 * @return Which of the cursors are active (if any).
211 unsigned int GetActiveCursor() const;
214 * @brief Sets the position of a cursor.
216 * @param[in] cursor The cursor to set.
217 * @param[in] x The x position relative to the top-left of the parent control.
218 * @param[in] y The y position relative to the top-left of the parent control.
219 * @param[in] cursorHeight The logical height of the cursor.
220 * @param[in] lineHeight The logical height of the line.
222 void SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight );
225 * @brief Retrieves the position, height and lineHeight of a cursor.
227 * @param[in] cursor The cursor to get.
228 * @param[out] x The x position relative to the top-left of the parent control.
229 * @param[out] y The y position relative to the top-left of the parent control.
230 * @param[out] cursorHeight The logical height of the cursor.
231 * @param[out] lineHeight The logical height of the line.
233 void GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const;
236 * @brief Retrieves the position of a cursor.
238 * @param[in] cursor The cursor to get.
240 * @return The position.
242 const Vector2& GetPosition( Cursor cursor ) const;
245 * @brief Sets the color for a cursor.
247 * @param[in] cursor Whether this color is for the primary or secondary cursor.
248 * @param[in] color The color to use.
250 void SetCursorColor( Cursor cursor, const Dali::Vector4& color );
253 * @brief Retrieves the color for a cursor.
255 * @param[in] cursor Whether this color is for the primary or secondary cursor.
256 * @return The cursor color.
258 const Dali::Vector4& GetColor( Cursor cursor ) const;
261 * @brief Start blinking the cursor; see also SetCursorBlinkDuration().
263 void StartCursorBlink();
266 * @brief Stop blinking the cursor.
268 void StopCursorBlink();
271 * @brief Set the interval between cursor blinks.
273 * @param[in] seconds The interval in seconds.
275 void SetCursorBlinkInterval( float seconds );
278 * @brief Retrieves the blink-interval for a cursor.
280 * @return The cursor blink-interval.
282 float GetCursorBlinkInterval() const;
285 * @brief The cursor will stop blinking after this duration.
287 * @param[in] seconds The duration in seconds.
289 void SetCursorBlinkDuration( float seconds );
292 * @brief Retrieves the blink-duration for a cursor.
294 * @return The cursor blink-duration.
296 float GetCursorBlinkDuration() const;
299 * @brief Sets whether a handle is active.
301 * @param[in] handleType One of the handles.
302 * @param[in] active True if the handle should be active.
304 void SetHandleActive( HandleType handleType,
308 * @brief Query whether a handle is active.
310 * @param[in] handleType One of the handles.
312 * @return True if the handle is active.
314 bool IsHandleActive( HandleType handleType ) const;
317 * @brief Sets the image for one of the handles.
319 * @param[in] handleType One of the handles.
320 * @param[in] handleImageType A different image can be set for the pressed/released states.
321 * @param[in] image The image to use.
323 void SetHandleImage( HandleType handleType, HandleImageType handleImageType, Dali::Image image );
326 * @brief Retrieves the image for one of the handles.
328 * @param[in] handleType One of the handles.
329 * @param[in] handleImageType A different image can be set for the pressed/released states.
331 * @return The grab handle image.
333 Dali::Image GetHandleImage( HandleType handleType, HandleImageType handleImageType ) const;
336 * @brief Sets the color of the handles
338 * @param[in] color The color to use.
340 void SetHandleColor( const Vector4& color );
343 * @brief Retrieves the handles color.
345 * @return The color of the handles.
347 const Vector4& GetHandleColor() const;
350 * @brief Sets the position of a selection handle.
352 * @param[in] handleType The handle to set.
353 * @param[in] x The x position relative to the top-left of the parent control.
354 * @param[in] y The y position relative to the top-left of the parent control.
355 * @param[in] lineHeight The logical line height at this position.
357 void SetPosition( HandleType handleType, float x, float y, float lineHeight );
360 * @brief Retrieves the position of a selection handle.
362 * @param[in] handleType The handle to get.
363 * @param[out] x The x position relative to the top-left of the parent control.
364 * @param[out] y The y position relative to the top-left of the parent control.
365 * @param[out] lineHeight The logical line height at this position.
367 void GetPosition( HandleType handleType, float& x, float& y, float& lineHeight ) const;
370 * @brief Retrieves the position of a selection handle.
372 * @param[in] handleType The handle to get.
374 * @return The position of the selection handle relative to the top-left of the parent control.
376 const Vector2& GetPosition( HandleType handleType ) const;
379 * @brief Swaps the selection handle's images.
381 * This method is called by the text controller to swap the handles
382 * when the start index is bigger than the end one.
384 void SwapSelectionHandlesEnabled( bool enable );
387 * @brief Adds a quad to the existing selection highlights.
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.
394 void AddHighlight( float x1, float y1, float x2, float y2 );
397 * @brief Removes all of the previously added highlights.
399 void ClearHighlights();
402 * @brief Sets the selection highlight color.
404 * @param[in] color The color to use.
406 void SetHighlightColor( const Vector4& color );
409 * @brief Retrieves the selection highlight color.
411 * @return The color of the highlight
413 const Vector4& GetHighlightColor() const;
416 * @brief Sets into the decorator the depth used to render the text.
418 * @param[in] depth The text's depth.
420 void SetTextDepth( int textDepth );
423 * @brief Set the Selection Popup to show or hide via the active flaf
424 * @param[in] active true to show, false to hide
426 void SetPopupActive( bool active );
429 * @brief Query whether the Selection Popup is active.
431 * @return True if the Selection Popup should be active.
433 bool IsPopupActive() const;
436 * @brief Set a bit mask of the buttons to be shown by Popup
437 * @param[in] enabledButtonsBitMask from TextSelectionPopup::Buttons enum
439 void SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButtonsBitMask );
442 * @brief Get the current bit mask of buttons to be shown by Popup
443 * @return bitmask of TextSelectionPopup::Buttons
445 TextSelectionPopup::Buttons& GetEnabledPopupButtons();
448 * @brief Sets the scroll threshold.
450 * It defines a square area inside the control, close to the edge.
451 * When the cursor enters this area, the decorator starts to send scroll events.
453 * @param[in] threshold The scroll threshold.
455 void SetScrollThreshold( float threshold );
458 * @brief Retrieves the scroll threshold.
460 * @retunr The scroll threshold.
462 float GetScrollThreshold() const;
465 * @brief Sets the scroll speed.
467 * Is the distance the text is going to be scrolled during a scroll interval.
469 * @param[in] speed The scroll speed.
471 void SetScrollSpeed( float speed );
474 * @brief Retrieves the scroll speed.
476 * @return The scroll speed.
478 float GetScrollSpeed() const;
481 * @brief Notifies the decorator the whole text has been scrolled.
483 void NotifyEndOfScroll();
488 * @brief A reference counted object may only be deleted by calling Unreference().
490 virtual ~Decorator();
495 * @brief Private constructor.
496 * @param[in] controller The controller which receives input events from Decorator components.
497 * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
499 Decorator( ControllerInterface& controller,
500 TextSelectionPopupCallbackInterface& callbackInterface );
503 Decorator( const Decorator& handle );
506 Decorator& operator=( const Decorator& handle );
515 } // namespace Toolkit
519 #endif // __DALI_TOOLKIT_TEXT_DECORATOR_H__