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,
84 LEFT_SELECTION_HANDLE_MARKER,
85 RIGHT_SELECTION_HANDLE_MARKER,
90 * @brief A Text Decorator is used to display cursors, handles, selection highlights and pop-ups.
92 * The decorator is responsible for clipping decorations which are positioned outside of the parent area.
94 * The Popup decoration will be positioned either above the Grab handle or above the selection handles but if doing so
95 * would cause the Popup to exceed the Decoration Bounding Box ( see SetBoundingBox API ) the the Popup will be repositioned below the handle(s).
97 * Selection handles will be flipped around to ensure they do not exceed the Decoration Bounding Box. ( Stay visible ).
99 * Decorator components forward input events to a controller class through an interface.
100 * The controller is responsible for selecting which components are active.
102 class Decorator : public RefObject
106 class ControllerInterface
111 * @brief Constructor.
113 ControllerInterface() {};
116 * @brief Virtual destructor.
118 virtual ~ControllerInterface() {};
121 * @brief Query the target size of the UI control.
123 * @param[out] targetSize The size of the UI control the decorator is adding it's decorations to.
125 virtual void GetTargetSize( Vector2& targetSize ) = 0;
128 * @brief Add a decoration to the parent UI control.
130 * @param[in] decoration The actor displaying a decoration.
132 virtual void AddDecoration( Actor& actor, bool needsClipping ) = 0;
135 * @brief An input event from one of the handles.
137 * @param[in] handleType The handle's type.
138 * @param[in] state The handle's state.
139 * @param[in] x The x position relative to the top-left of the parent control.
140 * @param[in] y The y position relative to the top-left of the parent control.
142 virtual void DecorationEvent( HandleType handleType, HandleState state, float x, float y ) = 0;
146 * @brief Create a new instance of a Decorator.
148 * @param[in] controller The controller which receives input events from Decorator components.
149 * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
151 * @return A pointer to a new Decorator.
153 static DecoratorPtr New( ControllerInterface& controller,
154 TextSelectionPopupCallbackInterface& callbackInterface );
157 * @brief Set the bounding box which handles, popup and similar decorations will not exceed.
159 * The default value is the width and height of the stage from the top left origin.
160 * If a title bar for example is on the top of the screen then the y should be the title's height and
161 * the boundary height the stage height minus the title's height.
162 * Restrictions - The boundary box should be set up with a fixed z position for the text-input and the default camera.
164 * ------------------------------------------
166 * |o---------------------------------------|
168 * || Bounding Box || boundary height
170 * |----------------------------------------|
171 * ------------------------------------------
174 * @param[in] boundingBox Vector( x coordinate, y coordinate, width, height )
176 void SetBoundingBox( const Rect<int>& boundingBox );
179 * @brief Retrieve the bounding box origin and dimensions.
181 * default is set once control is added to stage, before this the return vector will be Vector4:ZERO
182 * @param[out] boundingBox The bounding box origin, width and height.
184 void GetBoundingBox( Rect<int>& boundingBox ) const;
187 * @brief The decorator waits until a relayout before creating actors etc.
189 * @param[in] size The size of the parent control after size-negotiation.
191 void Relayout( const Dali::Vector2& size );
194 * @brief Updates the decorator's actor positions after scrolling.
196 * @param[in] scrollOffset The scroll offset.
198 void UpdatePositions( const Vector2& scrollOffset );
201 * @brief Sets which of the cursors are active.
203 * @note Cursor will only be visible if within the parent area.
204 * @param[in] activeCursor Which of the cursors should be active (if any).
206 void SetActiveCursor( ActiveCursor activeCursor );
209 * @brief Query which of the cursors are active.
211 * @return Which of the cursors are active (if any).
213 unsigned int GetActiveCursor() const;
216 * @brief Sets the position of a cursor.
218 * @param[in] cursor The cursor to set.
219 * @param[in] x The x position relative to the top-left of the parent control.
220 * @param[in] y The y position relative to the top-left of the parent control.
221 * @param[in] cursorHeight The logical height of the cursor.
222 * @param[in] lineHeight The logical height of the line.
224 void SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight );
227 * @brief Retrieves the position, height and lineHeight of a cursor.
229 * @param[in] cursor The cursor to get.
230 * @param[out] x The x position relative to the top-left of the parent control.
231 * @param[out] y The y position relative to the top-left of the parent control.
232 * @param[out] cursorHeight The logical height of the cursor.
233 * @param[out] lineHeight The logical height of the line.
235 void GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const;
238 * @brief Retrieves the position of a cursor.
240 * @param[in] cursor The cursor to get.
242 * @return The position.
244 const Vector2& GetPosition( Cursor cursor ) const;
247 * @brief Sets the color for a cursor.
249 * @param[in] cursor Whether this color is for the primary or secondary cursor.
250 * @param[in] color The color to use.
252 void SetCursorColor( Cursor cursor, const Dali::Vector4& color );
255 * @brief Retrieves the color for a cursor.
257 * @param[in] cursor Whether this color is for the primary or secondary cursor.
258 * @return The cursor color.
260 const Dali::Vector4& GetColor( Cursor cursor ) const;
263 * @brief Start blinking the cursor; see also SetCursorBlinkDuration().
265 void StartCursorBlink();
268 * @brief Stop blinking the cursor.
270 void StopCursorBlink();
273 * @brief Temporarily stops the cursor from blinking.
275 void DelayCursorBlink();
278 * @brief Set the interval between cursor blinks.
280 * @param[in] seconds The interval in seconds.
282 void SetCursorBlinkInterval( float seconds );
285 * @brief Retrieves the blink-interval for a cursor.
287 * @return The cursor blink-interval in seconds.
289 float GetCursorBlinkInterval() const;
292 * @brief The cursor will stop blinking after this duration.
294 * @param[in] seconds The duration in seconds.
296 void SetCursorBlinkDuration( float seconds );
299 * @brief Retrieves the blink-duration for a cursor.
301 * @return The cursor blink-duration in seconds.
303 float GetCursorBlinkDuration() const;
306 * @brief Sets the width of the cursors.
308 * @param[in] width The width of the cursor in pixels.
310 void SetCursorWidth( int width );
313 * @brief Retrieves the width of the cursors.
315 * @return The width of the cursors in pixels.
317 int GetCursorWidth() const;
320 * @brief Sets whether a handle is active.
322 * @param[in] handleType One of the handles.
323 * @param[in] active True if the handle should be active.
325 void SetHandleActive( HandleType handleType,
329 * @brief Query whether a handle is active.
331 * @param[in] handleType One of the handles.
333 * @return True if the handle is active.
335 bool IsHandleActive( HandleType handleType ) const;
338 * @brief Sets the image for one of the handles.
340 * @param[in] handleType One of the handles.
341 * @param[in] handleImageType A different image can be set for the pressed/released states.
342 * @param[in] image The image to use.
344 void SetHandleImage( HandleType handleType, HandleImageType handleImageType, Dali::Image image );
347 * @brief Retrieves the image for one of the handles.
349 * @param[in] handleType One of the handles.
350 * @param[in] handleImageType A different image can be set for the pressed/released states.
352 * @return The grab handle image.
354 Dali::Image GetHandleImage( HandleType handleType, HandleImageType handleImageType ) const;
357 * @brief Sets the color of the handles
359 * @param[in] color The color to use.
361 void SetHandleColor( const Vector4& color );
364 * @brief Retrieves the handles color.
366 * @return The color of the handles.
368 const Vector4& GetHandleColor() const;
371 * @brief Sets the position of a selection handle.
373 * @param[in] handleType The handle to set.
374 * @param[in] x The x position relative to the top-left of the parent control.
375 * @param[in] y The y position relative to the top-left of the parent control.
376 * @param[in] lineHeight The logical line height at this position.
378 void SetPosition( HandleType handleType, float x, float y, float lineHeight );
381 * @brief Retrieves the position of a selection handle.
383 * @param[in] handleType The handle to get.
384 * @param[out] x The x position relative to the top-left of the parent control.
385 * @param[out] y The y position relative to the top-left of the parent control.
386 * @param[out] lineHeight The logical line height at this position.
388 void GetPosition( HandleType handleType, float& x, float& y, float& lineHeight ) const;
391 * @brief Retrieves the position of a selection handle.
393 * @param[in] handleType The handle to get.
395 * @return The position of the selection handle relative to the top-left of the parent control.
397 const Vector2& GetPosition( HandleType handleType ) const;
400 * @brief Whether to flip vertically a handle.
402 * @param[in] handleType The handle to flip vertically.
403 * @param[in] flip Whether to flip vertically.
405 void FlipHandleVertically( HandleType handleType, bool flip );
408 * @brief Retrieves whether the handle is vertically flipped.
410 * @param[in] handleType The handle to query.
412 * @return @e ture if the handle is vertically flipped.
414 bool IsHandleVerticallyFlipped( HandleType handleType ) const;
417 * @brief Whether to flip the selection handles as soon as they are crossed.
419 * By default they flip when the handle is released.
421 * @param[in] enable If @e true the selection handles will flip as soon as they are crossed.
423 void FlipSelectionHandlesOnCrossEnabled( bool enable );
426 * @brief Sets info to calculate the handle flip state.
428 * Sets the character's direction where the handles are pointing.
429 * It resets the decorator internal flip state when there is a new selection.
431 * @param[in] indicesSwapped Whether the selection handle indices are swapped (start > end).
432 * @param[in] left The direction of the character pointed by the primary selection handle.
433 * @param[in] right The direction of the character pointed by the secondary selection handle.
435 void SetSelectionHandleFlipState( bool indicesSwapped, bool left, bool right );
438 * @brief Adds a quad to the existing selection highlights.
440 * @param[in] x1 The top-left x position.
441 * @param[in] y1 The top-left y position.
442 * @param[in] x2 The bottom-right x position.
443 * @param[in] y3 The bottom-right y position.
445 void AddHighlight( float x1, float y1, float x2, float y2 );
448 * @brief Removes all of the previously added highlights.
450 void ClearHighlights();
453 * @brief Sets the selection highlight color.
455 * @param[in] color The color to use.
457 void SetHighlightColor( const Vector4& color );
460 * @brief Retrieves the selection highlight color.
462 * @return The color of the highlight
464 const Vector4& GetHighlightColor() const;
467 * @brief Sets into the decorator the depth used to render the text.
469 * @param[in] depth The text's depth.
471 void SetTextDepth( int textDepth );
474 * @brief Set the Selection Popup to show or hide via the active flaf
475 * @param[in] active true to show, false to hide
477 void SetPopupActive( bool active );
480 * @brief Query whether the Selection Popup is active.
482 * @return True if the Selection Popup should be active.
484 bool IsPopupActive() const;
487 * @brief Set a bit mask of the buttons to be shown by Popup
488 * @param[in] enabledButtonsBitMask from TextSelectionPopup::Buttons enum
490 void SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButtonsBitMask );
493 * @brief Get the current bit mask of buttons to be shown by Popup
494 * @return bitmask of TextSelectionPopup::Buttons
496 TextSelectionPopup::Buttons& GetEnabledPopupButtons();
499 * @brief Sets the scroll threshold.
501 * It defines a square area inside the control, close to the edge.
502 * When the cursor enters this area, the decorator starts to send scroll events.
504 * @param[in] threshold The scroll threshold in pixels.
506 void SetScrollThreshold( float threshold );
509 * @brief Retrieves the scroll threshold.
511 * @retunr The scroll threshold in pixels.
513 float GetScrollThreshold() const;
516 * @brief Sets the scroll speed.
518 * Is the distance the text is going to be scrolled during a scroll interval.
520 * @param[in] speed The scroll speed in pixels/second.
522 void SetScrollSpeed( float speed );
525 * @brief Retrieves the scroll speed.
527 * @return The scroll speed in pixels/second.
529 float GetScrollSpeed() const;
532 * @brief Notifies the decorator the whole text has been scrolled.
534 void NotifyEndOfScroll();
537 * @copydoc Text::Controller::SetHorizontalScrollEnabled()
539 void SetHorizontalScrollEnabled( bool enable );
542 * @copydoc Text::Controller::IsHorizontalScrollEnabled()
544 bool IsHorizontalScrollEnabled() const;
547 * @copydoc Text::Controller::SetVerticalScrollEnabled()
549 void SetVerticalScrollEnabled( bool enable );
552 * @copydoc Text::Controller::IsVerticalScrollEnabled()
554 bool IsVerticalScrollEnabled() const;
557 * @copydoc Text::Controller::SetSmoothHandlePanEnabled()
559 void SetSmoothHandlePanEnabled( bool enable );
562 * @copydoc Text::Controller::IsSmoothHandlePanEnabled()
564 bool IsSmoothHandlePanEnabled() const;
569 * @brief A reference counted object may only be deleted by calling Unreference().
571 virtual ~Decorator();
576 * @brief Private constructor.
577 * @param[in] controller The controller which receives input events from Decorator components.
578 * @param[in] callbackInterface The text popup callback interface which receives the button click callbacks.
580 Decorator( ControllerInterface& controller,
581 TextSelectionPopupCallbackInterface& callbackInterface );
584 Decorator( const Decorator& handle );
587 Decorator& operator=( const Decorator& handle );
596 } // namespace Toolkit
600 #endif // __DALI_TOOLKIT_TEXT_DECORATOR_H__