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.
67 CONVERT_TO_UTF32 = 0x1,
70 GET_LINE_BREAKS = 0x8,
71 GET_WORD_BREAKS = 0x10,
73 GET_GLYPH_METRICS = 0x40,
78 ALL_OPERATIONS = 0xFFF
84 * @brief Create a new instance of a Controller.
86 * @param[in] controlInterface An interface used to request a text relayout.
87 * @return A pointer to a new Controller.
89 static ControllerPtr New( ControlInterface& controlInterface );
92 * @brief Replaces any text previously set.
94 * @note This will be converted into UTF-32 when stored in the text model.
95 * @param[in] text A string of UTF-8 characters.
97 void SetText( const std::string& text );
100 * @brief Retrieve any text previously set.
102 * @return A string of UTF-8 characters.
104 void GetText( std::string& text );
107 * @brief Called to enable text input.
109 * @note Only selectable or editable controls should calls this.
110 * @param[in] decorator Used to create cursor, selection handle decorations etc.
112 void EnableTextInput( DecoratorPtr decorator );
115 * @brief Triggers a relayout which updates View (if necessary).
117 * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.
118 * @param[in] size A the size of a bounding box to layout text within.
119 * @return True if the text model or decorations were updated.
121 bool Relayout( const Vector2& size );
126 bool DoRelayout( const Vector2& size, OperationsMask operations );
129 * @copydoc Control::GetNaturalSize()
131 Vector3 GetNaturalSize();
134 * @copydoc Control::GetHeightForWidth()
136 float GetHeightForWidth( float width );
139 * @brief Return the layout engine.
141 * @return A reference to the layout engine.
143 LayoutEngine& GetLayoutEngine();
146 * @brief Return a view of the text.
148 * @return A reference to the view.
153 * @brief Caller by editable UI controls when keyboard focus is gained.
155 void KeyboardFocusGainEvent();
158 * @brief Caller by editable UI controls when focus is lost.
160 void KeyboardFocusLostEvent();
163 * @brief Caller by editable UI controls when a tap gesture occurs.
164 * @param[in] tapCount The number of taps.
165 * @param[in] x The x position relative to the top-left of the parent control.
166 * @param[in] y The y position relative to the top-left of the parent control.
168 void TapEvent( unsigned int tapCount, float x, float y );
171 * @copydoc Dali::Toolkit::Text::Decorator::Observer::GrabHandleEvent()
173 virtual void GrabHandleEvent( GrabHandleState state, float x, float y );
178 * @brief A reference counted object may only be deleted by calling Unreference().
180 virtual ~Controller();
185 * @brief Request a relayout using the ControlInterface.
187 void RequestRelayout();
190 * @brief Private constructor.
192 Controller( ControlInterface& controlInterface );
195 Controller( const Controller& handle );
198 Controller& operator=( const Controller& handle );
205 // Avoid allocating this for non-editable controls
211 } // namespace Toolkit
215 #endif // __DALI_TOOLKIT_TEXT_CONTROLLER_H__