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.
22 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
23 #include <dali-toolkit/internal/text/text-control-interface.h>
24 #include <dali-toolkit/internal/text/text-view.h>
27 #include <dali/public-api/common/intrusive-ptr.h>
28 #include <dali/public-api/math/vector3.h>
29 #include <dali/public-api/math/vector2.h>
30 #include <dali/public-api/object/ref-object.h>
45 typedef IntrusivePtr<Controller> ControllerPtr;
46 typedef Dali::Toolkit::Text::ControlInterface ControlInterface;
49 * @brief A Text Controller is used by UI Controls which display text.
51 * It manipulates the Logical & Visual text models on behalf of the UI Controls.
52 * It provides a view of the text that can be used by rendering back-ends.
54 * For selectable/editable UI controls, the controller handles input events from the UI control
55 * and decorations (grab handles etc) via an observer interface.
57 class Controller : public RefObject, public Decorator::Observer
62 * @brief Text related operations to be done in the relayout process.
66 NO_OPERATION = 0x0000,
67 CONVERT_TO_UTF32 = 0x0001,
69 VALIDATE_FONTS = 0x0004,
70 GET_LINE_BREAKS = 0x0008,
71 GET_WORD_BREAKS = 0x0010,
73 GET_GLYPH_METRICS = 0x0040,
75 UPDATE_ACTUAL_SIZE = 0x0100,
76 UPDATE_POSITIONS = 0x0200,
80 ALL_OPERATIONS = 0xFFFF
86 * @brief Create a new instance of a Controller.
88 * @param[in] controlInterface An interface used to request a text relayout.
89 * @return A pointer to a new Controller.
91 static ControllerPtr New( ControlInterface& controlInterface );
94 * @brief Replaces any text previously set.
96 * @note This will be converted into UTF-32 when stored in the text model.
97 * @param[in] text A string of UTF-8 characters.
99 void SetText( const std::string& text );
102 * @brief Retrieve any text previously set.
104 * @return A string of UTF-8 characters.
106 void GetText( std::string& text ) const;
109 * @brief Set the default font family.
111 * @param[in] defaultFontFamily The default font family.
113 void SetDefaultFontFamily( const std::string& defaultFontFamily );
116 * @brief Retrieve the default font family.
118 * @return The default font family.
120 const std::string& GetDefaultFontFamily() const;
123 * @brief Set the default font style.
125 * @param[in] defaultFontStyle The default font style.
127 void SetDefaultFontStyle( const std::string& defaultFontStyle );
130 * @brief Retrieve the default font style.
132 * @return The default font style.
134 const std::string& GetDefaultFontStyle() const;
137 * @brief Set the default point size.
139 * @param[in] defaultFontStyle The default point size.
141 void SetDefaultPointSize( float pointSize );
144 * @brief Retrieve the default point size.
146 * @return The default point size.
148 float GetDefaultPointSize() const;
151 * @brief Called to enable text input.
153 * @note Only selectable or editable controls should calls this.
154 * @param[in] decorator Used to create cursor, selection handle decorations etc.
156 void EnableTextInput( DecoratorPtr decorator );
159 * @brief Triggers a relayout which updates View (if necessary).
161 * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
162 * @param[in] size A the size of a bounding box to layout text within.
163 * @return True if the text model or decorations were updated.
165 bool Relayout( const Vector2& size );
168 * @brief Lays-out the text.
170 * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
172 * @param[in] size A the size of a bounding box to layout text within.
173 * @param[in] operations The layout operations which need to be done.
175 bool DoRelayout( const Vector2& size, OperationsMask operations );
178 * @copydoc Control::GetNaturalSize()
180 Vector3 GetNaturalSize();
183 * @copydoc Control::GetHeightForWidth()
185 float GetHeightForWidth( float width );
188 * @brief Return the layout engine.
190 * @return A reference to the layout engine.
192 LayoutEngine& GetLayoutEngine();
195 * @brief Return a view of the text.
197 * @return A reference to the view.
202 * @brief Caller by editable UI controls when keyboard focus is gained.
204 void KeyboardFocusGainEvent();
207 * @brief Caller by editable UI controls when focus is lost.
209 void KeyboardFocusLostEvent();
212 * @brief Caller by editable UI controls when a tap gesture occurs.
213 * @param[in] tapCount The number of taps.
214 * @param[in] x The x position relative to the top-left of the parent control.
215 * @param[in] y The y position relative to the top-left of the parent control.
217 void TapEvent( unsigned int tapCount, float x, float y );
220 * @copydoc Dali::Toolkit::Text::Decorator::Observer::GrabHandleEvent()
222 virtual void GrabHandleEvent( GrabHandleState state, float x, float y );
227 * @brief A reference counted object may only be deleted by calling Unreference().
229 virtual ~Controller();
234 * @brief Request a relayout using the ControlInterface.
236 void RequestRelayout();
239 * @brief Private constructor.
241 Controller( ControlInterface& controlInterface );
244 Controller( const Controller& handle );
247 Controller& operator=( const Controller& handle );
254 // Avoid allocating this when the user does not specify a font
257 // Avoid allocating this for non-editable controls
263 } // namespace Toolkit
267 #endif // __DALI_TOOLKIT_TEXT_CONTROLLER_H__