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>
45 typedef IntrusivePtr<Decorator> DecoratorPtr;
47 // Used to set the cursor positions etc.
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
55 // Determines which of the cursors are active (if any).
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
63 // The state information for grab handle events
71 // The set the selection-handle positions etc.
74 PRIMARY_SELECTION_HANDLE,
75 SECONDARY_SELECTION_HANDLE,
76 SELECTION_HANDLE_COUNT
79 enum SelectionHandleState
81 SELECTION_HANDLE_PRESSED,
82 SELECTION_HANDLE_RELEASED
86 * @brief A Text Decorator is used to display cursors, handles, selection highlights and pop-ups.
88 * The decorator is responsible for clipping decorations which are positioned outside of the parent area.
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).
93 * Selection handles will be flipped around to ensure they do not exceed the Decoration Bounding Box. ( Stay visible ).
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.
98 class Decorator : public RefObject
107 * @brief Constructor.
112 * @brief Virtual destructor.
114 virtual ~Observer() {};
117 * @brief An input event from the grab handle.
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.
123 virtual void GrabHandleEvent( GrabHandleState state, float x, float y ) = 0;
127 * @brief Create a new instance of a Decorator.
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.
133 static DecoratorPtr New( Dali::Toolkit::Internal::Control& parent, Observer& observer );
136 * @brief Set the bounding box which handles, popup and similar decorations will not exceed.
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.
143 * ------------------------------------------
145 * |o---------------------------------------|
147 * || Bounding Box || boundary height
149 * |----------------------------------------|
150 * ------------------------------------------
153 * @param[in] boundingBox Vector( x coordinate, y coordinate, width, height )
155 void SetBoundingBox( const Rect<int>& boundingBox );
158 * @brief Retrieve the bounding box origin and dimensions.
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
163 const Rect<int>& GetBoundingBox() const;
166 * @brief The decorator waits until a relayout before creating actors etc.
168 * @param[in] size The size of the parent control after size-negotiation.
169 * @param[in] scrollPosition The cursor, grab-handle positions etc. should be offset by this.
171 void Relayout( const Dali::Vector2& size, const Vector2& scrollPosition );
174 * @brief Sets which of the cursors are active.
176 * @note Cursor will only be visible if within the parent area.
177 * @param[in] activeCursor Which of the cursors should be active (if any).
179 void SetActiveCursor( ActiveCursor activeCursor );
182 * @brief Query which of the cursors are active.
184 * @return Which of the cursors are active (if any).
186 unsigned int GetActiveCursor() const;
189 * @brief Sets the position of a cursor.
191 * @param[in] cursor The cursor to set.
192 * @param[in] x The x position relative to the top-left of the parent control.
193 * @param[in] y The y position relative to the top-left of the parent control.
194 * @param[in] height The logical height of the cursor.
196 void SetPosition( Cursor cursor, float x, float y, float height );
199 * @brief Retrieves the position of a cursor.
201 * @param[in] cursor The cursor to get.
202 * @param[out] x The x position relative to the top-left of the parent control.
203 * @param[out] y The y position relative to the top-left of the parent control.
204 * @param[out] height The logical height of the cursor.
206 void GetPosition( Cursor cursor, float& x, float& y, float& height ) const;
209 * @brief Sets the color for a cursor.
211 * @param[in] cursor Whether this color is for the primary or secondary cursor.
212 * @param[in] color The color to use.
214 void SetColor( Cursor cursor, const Dali::Vector4& color );
217 * @brief Retrieves the color for a cursor.
219 * @param[in] cursor Whether this color is for the primary or secondary cursor.
220 * @return The cursor color.
222 const Dali::Vector4& GetColor( Cursor cursor ) const;
225 * @brief Start blinking the cursor; see also SetCursorBlinkDuration().
227 void StartCursorBlink();
230 * @brief Stop blinking the cursor.
232 void StopCursorBlink();
235 * @brief Set the interval between cursor blinks.
237 * @param[in] seconds The interval in seconds.
239 void SetCursorBlinkInterval( float seconds );
242 * @brief Retrieves the blink-interval for a cursor.
244 * @return The cursor blink-interval.
246 float GetCursorBlinkInterval() const;
249 * @brief The cursor will stop blinking after this duration.
251 * @param[in] seconds The duration in seconds.
253 void SetCursorBlinkDuration( float seconds );
256 * @brief Retrieves the blink-duration for a cursor.
258 * @return The cursor blink-duration.
260 float GetCursorBlinkDuration() const;
263 * @brief Sets whether the grab handle is active.
265 * @note The grab handle follows the cursor position set with SetPosition(Cursor, ...)
266 * @param[in] active True if the grab handle should be active.
268 void SetGrabHandleActive( bool active );
271 * @brief Query whether the grab handle is active.
273 * @return True if the grab handle should be active.
275 bool IsGrabHandleActive() const;
278 * @brief Sets the image for the grab handle.
280 * @param[in] image The image to use.
282 void SetGrabHandleImage( Dali::Image image );
285 * @brief Retrieves the image for the grab handle.
287 * @return The grab handle image.
289 Dali::Image GetGrabHandleImage() const;
292 * @brief Sets whether the selection handles and highlight are active.
294 * @param[in] active True if the selection handles and highlight are active.
296 void SetSelectionActive( bool active );
299 * @brief Query whether the selection handles and highlight are active.
301 * @return True if the selection handles and highlight are active.
303 bool IsSelectionActive() const;
306 * @brief Sets the position of a selection handle.
308 * @param[in] handle The handle to set.
309 * @param[in] x The x position relative to the top-left of the parent control.
310 * @param[in] y The y position relative to the top-left of the parent control.
311 * @param[in] cursorHeight The logical cursor height at this position.
313 void SetPosition( SelectionHandle handle, float x, float y, float cursorHeight );
316 * @brief Retrieves the position of a selection handle.
318 * @param[in] handle The handle to get.
319 * @param[out] x The x position relative to the top-left of the parent control.
320 * @param[out] y The y position relative to the top-left of the parent control.
321 * @param[out] cursorHeight The logical cursor height at this position.
323 void GetPosition( SelectionHandle handle, float& x, float& y, float& cursorHeight ) const;
326 * @brief Sets the image for one of the selection handles.
328 * @param[in] handle The selection handle.
329 * @param[in] state A different image can be set for the pressed/released states.
330 * @param[in] image The image to use.
332 void SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image );
335 * @brief Retrieves the image for a selection handle.
337 * @param[in] handle The selection handle.
338 * @param[in] state A different image can be set for the pressed/released states.
341 Dali::Image GetImage( SelectionHandle handle, SelectionHandleState state ) const;
344 * @brief Show the Copy and Paste Popup
349 * @brief Hide the Copy and Paste Popup
356 * @brief A reference counted object may only be deleted by calling Unreference().
358 virtual ~Decorator();
363 * @brief Private constructor.
364 * @param[in] parent Decorations will be added to this parent control.
365 * @param[in] observer A class which receives input events from Decorator components.
367 Decorator(Dali::Toolkit::Internal::Control& parent, Observer& observer );
370 Decorator( const Decorator& handle );
373 Decorator& operator=( const Decorator& handle );
382 } // namespace Toolkit
386 #endif // __DALI_TOOLKIT_TEXT_DECORATOR_H__