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 );
109 * @brief Called to enable text input.
111 * @note Only selectable or editable controls should calls this.
112 * @param[in] decorator Used to create cursor, selection handle decorations etc.
114 void EnableTextInput( DecoratorPtr decorator );
117 * @brief Triggers a relayout which updates View (if necessary).
119 * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
120 * @param[in] size A the size of a bounding box to layout text within.
121 * @return True if the text model or decorations were updated.
123 bool Relayout( const Vector2& size );
126 * @brief Lays-out the text.
128 * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method.
130 * @param[in] size A the size of a bounding box to layout text within.
131 * @param[in] operations The layout operations which need to be done.
133 bool DoRelayout( const Vector2& size, OperationsMask operations );
136 * @copydoc Control::GetNaturalSize()
138 Vector3 GetNaturalSize();
141 * @copydoc Control::GetHeightForWidth()
143 float GetHeightForWidth( float width );
146 * @brief Return the layout engine.
148 * @return A reference to the layout engine.
150 LayoutEngine& GetLayoutEngine();
153 * @brief Return a view of the text.
155 * @return A reference to the view.
160 * @brief Caller by editable UI controls when keyboard focus is gained.
162 void KeyboardFocusGainEvent();
165 * @brief Caller by editable UI controls when focus is lost.
167 void KeyboardFocusLostEvent();
170 * @brief Caller by editable UI controls when a tap gesture occurs.
171 * @param[in] tapCount The number of taps.
172 * @param[in] x The x position relative to the top-left of the parent control.
173 * @param[in] y The y position relative to the top-left of the parent control.
175 void TapEvent( unsigned int tapCount, float x, float y );
178 * @copydoc Dali::Toolkit::Text::Decorator::Observer::GrabHandleEvent()
180 virtual void GrabHandleEvent( GrabHandleState state, float x, float y );
185 * @brief A reference counted object may only be deleted by calling Unreference().
187 virtual ~Controller();
192 * @brief Request a relayout using the ControlInterface.
194 void RequestRelayout();
197 * @brief Private constructor.
199 Controller( ControlInterface& controlInterface );
202 Controller( const Controller& handle );
205 Controller& operator=( const Controller& handle );
212 // Avoid allocating this for non-editable controls
218 } // namespace Toolkit
222 #endif // __DALI_TOOLKIT_TEXT_CONTROLLER_H__