1 #ifndef __DALI_TOOLKIT_TEXT_CONTROLLER_H__
2 #define __DALI_TOOLKIT_TEXT_CONTROLLER_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.
23 #include <dali/public-api/common/intrusive-ptr.h>
24 #include <dali/public-api/events/key-event.h>
25 #include <dali/public-api/math/vector3.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/object/ref-object.h>
30 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
31 #include <dali-toolkit/internal/text/text-control-interface.h>
32 #include <dali-toolkit/internal/text/text-view.h>
46 typedef IntrusivePtr<Controller> ControllerPtr;
47 typedef Dali::Toolkit::Text::ControlInterface ControlInterface;
50 * @brief A Text Controller is used by UI Controls which display text.
52 * It manipulates the Logical & Visual text models on behalf of the UI Controls.
53 * It provides a view of the text that can be used by rendering back-ends.
55 * For selectable/editable UI controls, the controller handles input events from the UI control
56 * and decorations (grab handles etc) via an observer interface.
58 class Controller : public RefObject, public Decorator::Observer
63 * @brief Text related operations to be done in the relayout process.
67 NO_OPERATION = 0x0000,
68 CONVERT_TO_UTF32 = 0x0001,
70 VALIDATE_FONTS = 0x0004,
71 GET_LINE_BREAKS = 0x0008,
72 GET_WORD_BREAKS = 0x0010,
75 GET_GLYPH_METRICS = 0x0080,
77 UPDATE_ACTUAL_SIZE = 0x0200,
78 UPDATE_POSITIONS = 0x0400,
79 UPDATE_LINES = 0x0800,
83 ALL_OPERATIONS = 0xFFFF
89 * @brief Create a new instance of a Controller.
91 * @param[in] controlInterface An interface used to request a text relayout.
92 * @return A pointer to a new Controller.
94 static ControllerPtr New( ControlInterface& controlInterface );
97 * @brief Replaces any text previously set.
99 * @note This will be converted into UTF-32 when stored in the text model.
100 * @param[in] text A string of UTF-8 characters.
102 void SetText( const std::string& text );
105 * @brief Retrieve any text previously set.
107 * @return A string of UTF-8 characters.
109 void GetText( std::string& text ) const;
112 * @brief Replaces any placeholder text previously set.
114 * @param[in] text A string of UTF-8 characters.
116 void SetPlaceholderText( const std::string& text );
119 * @brief Retrieve any placeholder text previously set.
121 * @return A string of UTF-8 characters.
123 void GetPlaceholderText( std::string& text ) const;
126 * @brief Set the default font family.
128 * @param[in] defaultFontFamily The default font family.
130 void SetDefaultFontFamily( const std::string& defaultFontFamily );
133 * @brief Retrieve the default font family.
135 * @return The default font family.
137 const std::string& GetDefaultFontFamily() const;
140 * @brief Set the default font style.
142 * @param[in] defaultFontStyle The default font style.
144 void SetDefaultFontStyle( const std::string& defaultFontStyle );
147 * @brief Retrieve the default font style.
149 * @return The default font style.
151 const std::string& GetDefaultFontStyle() const;
154 * @brief Set the default point size.
156 * @param[in] defaultFontStyle The default point size.
158 void SetDefaultPointSize( float pointSize );
161 * @brief Retrieve the default point size.
163 * @return The default point size.
165 float GetDefaultPointSize() const;
168 * @brief Called to enable text input.
170 * @note Only selectable or editable controls should calls this.
171 * @param[in] decorator Used to create cursor, selection handle decorations etc.
173 void EnableTextInput( DecoratorPtr decorator );
176 * @brief Triggers a relayout which updates View (if necessary).
178 * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
179 * @param[in] size A the size of a bounding box to layout text within.
180 * @return True if the text model or decorations were updated.
182 bool Relayout( const Vector2& size );
185 * @brief Lays-out the text.
187 * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
189 * @param[in] size A the size of a bounding box to layout text within.
190 * @param[in] operations The layout operations which need to be done.
191 * @param[out] layoutSize The size of the laid-out text.
193 bool DoRelayout( const Vector2& size,
194 OperationsMask operations,
198 * @copydoc Control::GetNaturalSize()
200 Vector3 GetNaturalSize();
203 * @copydoc Control::GetHeightForWidth()
205 float GetHeightForWidth( float width );
208 * @brief Return the layout engine.
210 * @return A reference to the layout engine.
212 LayoutEngine& GetLayoutEngine();
215 * @brief Return a view of the text.
217 * @return A reference to the view.
222 * @brief Caller by editable UI controls when keyboard focus is gained.
224 void KeyboardFocusGainEvent();
227 * @brief Caller by editable UI controls when focus is lost.
229 void KeyboardFocusLostEvent();
232 * @brief Caller by editable UI controls when key events are received.
234 * @param[in] event The key event.
236 bool KeyEvent( const Dali::KeyEvent& event );
239 * @brief Caller by editable UI controls when a tap gesture occurs.
240 * @param[in] tapCount The number of taps.
241 * @param[in] x The x position relative to the top-left of the parent control.
242 * @param[in] y The y position relative to the top-left of the parent control.
244 void TapEvent( unsigned int tapCount, float x, float y );
247 * @copydoc Dali::Toolkit::Text::Decorator::Observer::GrabHandleEvent()
249 virtual void GrabHandleEvent( GrabHandleState state, float x, float y );
254 * @brief A reference counted object may only be deleted by calling Unreference().
256 virtual ~Controller();
261 * @brief Request a relayout using the ControlInterface.
263 void RequestRelayout();
266 * @brief Private constructor.
268 Controller( ControlInterface& controlInterface );
271 Controller( const Controller& handle );
274 Controller& operator=( const Controller& handle );
281 // Avoid allocating this when the user does not specify a font
284 // Avoid allocating this for non-editable controls
290 } // namespace Toolkit
294 #endif // __DALI_TOOLKIT_TEXT_CONTROLLER_H__