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>
28 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
50 typedef IntrusivePtr<Decorator> DecoratorPtr;
52 // Used to set the cursor positions etc.
55 PRIMARY_CURSOR, ///< The primary cursor for bidirectional text (or the regular cursor for single-direction text)
56 SECONDARY_CURSOR, ///< The secondary cursor for bidirectional text
60 // Determines which of the cursors are active (if any).
63 ACTIVE_CURSOR_NONE, ///< Neither primary nor secondary cursor are active
64 ACTIVE_CURSOR_PRIMARY, ///< Primary cursor is active (only)
65 ACTIVE_CURSOR_BOTH ///< Both primary and secondary cursor are active
68 // The state information for handle events.
78 // Used to set different handle images
82 HANDLE_IMAGE_RELEASED,
83 HANDLE_IMAGE_TYPE_COUNT
90 LEFT_SELECTION_HANDLE,
91 RIGHT_SELECTION_HANDLE,
96 * @brief A Text Decorator is used to display cursors, handles, selection highlights and pop-ups.
98 * The decorator is responsible for clipping decorations which are positioned outside of the parent area.
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).
103 * Selection handles will be flipped around to ensure they do not exceed the Decoration Bounding Box. ( Stay visible ).
105 * Decorator components forward input events to a controller class through an interface.
106 * The controller is responsible for selecting which components are active.
108 class Decorator : public RefObject
112 class ControllerInterface
117 * @brief Constructor.
119 ControllerInterface() {};
122 * @brief Virtual destructor.
124 virtual ~ControllerInterface() {};
127 * @brief An input event from one of the handles.
129 * @param[out] targetSize The Size of the UI control the decorator is adding it's decorations to.
131 virtual void GetTargetSize( Vector2& targetSize ) = 0;
134 * @brief Add a decoration to the parent UI control.
136 * @param[in] decoration The actor displaying a decoration.
138 virtual void AddDecoration( Actor& actor, bool needsClipping ) = 0;
141 * @brief An input event from one of the handles.
143 * @param[in] handleType The handle's type.
144 * @param[in] state The handle's state.
145 * @param[in] x The x position relative to the top-left of the parent control.
146 * @param[in] y The y position relative to the top-left of the parent control.
148 virtual void DecorationEvent( HandleType handleType, HandleState state, float x, float y ) = 0;
152 * @brief Create a new instance of a Decorator.
154 * @param[in] controller The controller which receives input events from Decorator components.
155 * @return A pointer to a new Decorator.
157 static DecoratorPtr New( ControllerInterface& controller );
160 * @brief Set the bounding box which handles, popup and similar decorations will not exceed.
162 * The default value is the width and height of the stage from the top left origin.
163 * If a title bar for example is on the top of the screen then the y should be the title's height and
164 * the boundary height the stage height minus the title's height.
165 * Restrictions - The boundary box should be set up with a fixed z position for the text-input and the default camera.
167 * ------------------------------------------
169 * |o---------------------------------------|
171 * || Bounding Box || boundary height
173 * |----------------------------------------|
174 * ------------------------------------------
177 * @param[in] boundingBox Vector( x coordinate, y coordinate, width, height )
179 void SetBoundingBox( const Rect<int>& boundingBox );
182 * @brief Retrieve the bounding box origin and dimensions.
184 * default is set once control is added to stage, before this the return vector will be Vector4:ZERO
185 * @return Rect<int> the bounding box origin, width and height
187 const Rect<int>& GetBoundingBox() const;
190 * @brief The decorator waits until a relayout before creating actors etc.
192 * @param[in] size The size of the parent control after size-negotiation.
194 void Relayout( const Dali::Vector2& size );
197 * @brief Updates the decorator's actor positions after scrolling.
199 * @param[in] scrollOffset The scroll offset.
201 void UpdatePositions( const Vector2& scrollOffset );
204 * @brief Sets which of the cursors are active.
206 * @note Cursor will only be visible if within the parent area.
207 * @param[in] activeCursor Which of the cursors should be active (if any).
209 void SetActiveCursor( ActiveCursor activeCursor );
212 * @brief Query which of the cursors are active.
214 * @return Which of the cursors are active (if any).
216 unsigned int GetActiveCursor() const;
219 * @brief Sets the position of a cursor.
221 * @param[in] cursor The cursor to set.
222 * @param[in] x The x position relative to the top-left of the parent control.
223 * @param[in] y The y position relative to the top-left of the parent control.
224 * @param[in] cursorHeight The logical height of the cursor.
225 * @param[in] lineHeight The logical height of the line.
227 void SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight );
230 * @brief Retrieves the position, height and lineHeight of a cursor.
232 * @param[in] cursor The cursor to get.
233 * @param[out] x The x position relative to the top-left of the parent control.
234 * @param[out] y The y position relative to the top-left of the parent control.
235 * @param[out] cursorHeight The logical height of the cursor.
236 * @param[out] lineHeight The logical height of the line.
238 void GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const;
241 * @brief Retrieves the position of a cursor.
243 * @param[in] cursor The cursor to get.
245 * @return The position.
247 const Vector2& GetPosition( Cursor cursor ) const;
250 * @brief Sets the color for a cursor.
252 * @param[in] cursor Whether this color is for the primary or secondary cursor.
253 * @param[in] color The color to use.
255 void SetColor( Cursor cursor, const Dali::Vector4& color );
258 * @brief Retrieves the color for a cursor.
260 * @param[in] cursor Whether this color is for the primary or secondary cursor.
261 * @return The cursor color.
263 const Dali::Vector4& GetColor( Cursor cursor ) const;
266 * @brief Start blinking the cursor; see also SetCursorBlinkDuration().
268 void StartCursorBlink();
271 * @brief Stop blinking the cursor.
273 void StopCursorBlink();
276 * @brief Set the interval between cursor blinks.
278 * @param[in] seconds The interval in seconds.
280 void SetCursorBlinkInterval( float seconds );
283 * @brief Retrieves the blink-interval for a cursor.
285 * @return The cursor blink-interval.
287 float GetCursorBlinkInterval() const;
290 * @brief The cursor will stop blinking after this duration.
292 * @param[in] seconds The duration in seconds.
294 void SetCursorBlinkDuration( float seconds );
297 * @brief Retrieves the blink-duration for a cursor.
299 * @return The cursor blink-duration.
301 float GetCursorBlinkDuration() const;
304 * @brief Sets whether a handle is active.
306 * @param[in] handleType One of the handles.
307 * @param[in] active True if the handle should be active.
309 void SetHandleActive( HandleType handleType,
313 * @brief Query whether a handle is active.
315 * @param[in] handleType One of the handles.
317 * @return True if the handle is active.
319 bool IsHandleActive( HandleType handleType ) const;
322 * @brief Sets the image for one of the handles.
324 * @param[in] handleType One of the handles.
325 * @param[in] handleImageType A different image can be set for the pressed/released states.
326 * @param[in] image The image to use.
328 void SetHandleImage( HandleType handleType, HandleImageType handleImageType, Dali::Image image );
331 * @brief Retrieves the image for one of the handles.
333 * @param[in] handleType One of the handles.
334 * @param[in] handleImageType A different image can be set for the pressed/released states.
336 * @return The grab handle image.
338 Dali::Image GetHandleImage( HandleType handleType, HandleImageType handleImageType ) const;
341 * @brief Sets the position of a selection handle.
343 * @param[in] handleType The handle to set.
344 * @param[in] x The x position relative to the top-left of the parent control.
345 * @param[in] y The y position relative to the top-left of the parent control.
346 * @param[in] lineHeight The logical line height at this position.
348 void SetPosition( HandleType handleType, float x, float y, float lineHeight );
351 * @brief Retrieves the position of a selection handle.
353 * @param[in] handleType The handle to get.
354 * @param[out] x The x position relative to the top-left of the parent control.
355 * @param[out] y The y position relative to the top-left of the parent control.
356 * @param[out] lineHeight The logical line height at this position.
358 void GetPosition( HandleType handleType, float& x, float& y, float& lineHeight ) const;
361 * @brief Retrieves the position of a selection handle.
363 * @param[in] handleType The handle to get.
365 * @return The position of the selection handle relative to the top-left of the parent control.
367 const Vector2& GetPosition( HandleType handleType ) const;
370 * @brief Swaps the selection handle's images.
372 * This method is called by the text controller to swap the handles
373 * when the start index is bigger than the end one.
375 void SwapSelectionHandlesEnabled( bool enable );
378 * @brief Adds a quad to the existing selection highlights.
380 * @param[in] x1 The top-left x position.
381 * @param[in] y1 The top-left y position.
382 * @param[in] x2 The bottom-right x position.
383 * @param[in] y3 The bottom-right y position.
385 void AddHighlight( float x1, float y1, float x2, float y2 );
388 * @brief Removes all of the previously added highlights.
390 void ClearHighlights();
393 * @brief Sets the selection highlight color.
395 * @param[in] image The image to use.
397 void SetHighlightColor( const Vector4& color );
400 * @brief Retrieves the selection highlight color.
404 const Vector4& GetHighlightColor() const;
407 * @brief Set the Selection Popup to show or hide via the active flaf
408 * @param[in] active true to show, false to hide
410 void SetPopupActive( bool active );
413 * @brief Query whether the Selection Popup is active.
415 * @return True if the Selection Popup should be active.
417 bool IsPopupActive() const;
420 * @brief Set a bit mask of the buttons to be shown by Popup
421 * @param[in] enabledButtonsBitMask from TextSelectionPopup::Buttons enum
423 void SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButtonsBitMask );
426 * @brief Get the current bit mask of buttons to be shown by Popup
427 * @return bitmask of TextSelectionPopup::Buttons
429 TextSelectionPopup::Buttons& GetEnabledPopupButtons();
432 * @brief Sets the scroll threshold.
434 * It defines a square area inside the control, close to the edge.
435 * When the cursor enters this area, the decorator starts to send scroll events.
437 * @param[in] threshold The scroll threshold.
439 void SetScrollThreshold( float threshold );
442 * @brief Retrieves the scroll threshold.
444 * @retunr The scroll threshold.
446 float GetScrollThreshold() const;
449 * @brief Sets the scroll speed.
451 * Is the distance the text is going to be scrolled during a scroll interval.
453 * @param[in] speed The scroll speed.
455 void SetScrollSpeed( float speed );
458 * @brief Retrieves the scroll speed.
460 * @return The scroll speed.
462 float GetScrollSpeed() const;
465 * @brief Sets the scroll interval.
467 * @param[in] seconds The scroll interval in seconds.
469 void SetScrollTickInterval( float seconds );
472 * @brief Retrieves the scroll interval.
474 * @return The scroll interval.
476 float GetScrollTickInterval() const;
481 * @brief A reference counted object may only be deleted by calling Unreference().
483 virtual ~Decorator();
488 * @brief Private constructor.
489 * @param[in] controller The controller which receives input events from Decorator components.
491 Decorator( ControllerInterface& controller );
494 Decorator( const Decorator& handle );
497 Decorator& operator=( const Decorator& handle );
506 } // namespace Toolkit
510 #endif // __DALI_TOOLKIT_TEXT_DECORATOR_H__