1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
5 * Copyright (c) 2020 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/devel-api/adaptor-framework/clipboard-event-notifier.h>
23 #include <dali/devel-api/adaptor-framework/input-method-context.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
28 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
29 #include <dali-toolkit/internal/text/text-control-interface.h>
30 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
31 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
32 #include <dali-toolkit/internal/text/text-controller.h>
33 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
44 * @brief A control which renders a short text string.
46 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
51 * @copydoc Dali::Toollkit::TextField::New()
53 static Toolkit::TextField New();
58 * @brief Called when a property of an object of this type is set.
60 * @param[in] object The object whose property is set.
61 * @param[in] index The property index.
62 * @param[in] value The new property value.
64 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
67 * @brief Called to retrieve a property of an object of this type.
69 * @param[in] object The object whose property is to be retrieved.
70 * @param[in] index The property index.
71 * @return The current value of the property.
73 static Property::Value GetProperty( BaseObject* object, Property::Index index );
76 * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
78 InputMethodContext GetInputMethodContext();
81 * Connects a callback function with the object's signals.
82 * @param[in] object The object providing the signal.
83 * @param[in] tracker Used to disconnect the signal.
84 * @param[in] signalName The signal to connect to.
85 * @param[in] functor A newly allocated FunctorDelegate.
86 * @return True if the signal was connected.
87 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
89 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
92 * @copydoc TextField::TextChangedSignal()
94 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
97 * @copydoc TextField::MaxLengthReachedSignal()
99 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
102 * @copydoc TextField::TextChangedSignal()
104 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
107 * @brief Called to select the whole texts.
109 void SelectWholeText();
112 * @brief Called to unselect the whole texts.
116 private: // From Control
119 * @copydoc Control::OnInitialize()
121 void OnInitialize() override;
124 * @copydoc Control::OnStyleChange()
126 void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
129 * @copydoc Control::GetNaturalSize()
131 Vector3 GetNaturalSize() override;
134 * @copydoc Control::GetHeightForWidth()
136 float GetHeightForWidth( float width ) override;
139 * @copydoc Control::OnInitialize()
141 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
144 * @copydoc Control::OnKeyInputFocusGained()
146 void OnKeyInputFocusGained() override;
149 * @copydoc Control::OnKeyInputFocusLost()
151 void OnKeyInputFocusLost() override;
154 * @copydoc Control::OnTap()
156 void OnTap( const TapGesture& tap ) override;
159 * @copydoc Control::OnPan()
161 void OnPan( const PanGesture& gesture ) override;
164 * @copydoc Control::OnLongPress()
166 void OnLongPress( const LongPressGesture& gesture ) override;
169 * @copydoc Control::OnSceneConnection()
171 void OnSceneConnection( int depth ) override;
174 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
176 bool OnKeyEvent(const KeyEvent& event) override;
178 // From ControlInterface
181 * @copydoc Text::ControlInterface::RequestTextRelayout()
183 void RequestTextRelayout() override;
185 // From EditableControlInterface
188 * @copydoc Text::EditableControlInterface::TextChanged()
190 void TextChanged() override;
193 * @copydoc Text::EditableControlInterface::MaxLengthReached()
195 void MaxLengthReached() override;
198 * @copydoc Text::EditableControlInterface::InputStyleChanged()
200 void InputStyleChanged( Text::InputStyle::Mask inputStyleMask ) override;
203 * @copydoc Text::EditableControlInterface::AddDecoration()
205 void AddDecoration( Actor& actor, bool needsClipping ) override;
207 // From SelectableControlInterface
210 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
212 void SetTextSelectionRange(const uint32_t *start, const uint32_t *end) override;
215 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
217 Uint32Pair GetTextSelectionRange() const override;
220 * @copydoc Text::EditableControlInterface::IsEditable()
222 bool IsEditable() const override;
225 * @copydoc Text::EditableControlInterface::SetEditable()
227 void SetEditable( bool editable ) override;
229 private: // Implementation
232 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
234 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
237 * @brief Callback when Clipboard signals an item should be pasted
238 * @param[in] clipboard handle to Clipboard Event Notifier
240 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
243 * @brief Get a Property Map for the image used for the required Handle Image
244 * @param[out] value the returned image property
245 * @param[in] handleType the type of handle
246 * @param[in] handleImageType the type of image for the given handleType
248 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
251 * @brief Enable or disable clipping.
253 void EnableClipping();
256 * @brief Callback when keyboard is shown/hidden.
258 * @param[in] keyboardShown True if keyboard is shown.
260 void KeyboardStatusChanged( bool keyboardShown );
263 * @brief Callback when TextField is touched
265 * @param[in] actor TextField touched
266 * @param[in] touch Touch information
268 bool OnTouched( Actor actor, const TouchEvent& touch );
271 * @brief Callbacks called on idle.
273 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
278 * Construct a new TextField.
283 * A reference counted object may only be deleted by calling Unreference()
285 virtual ~TextField();
287 // Undefined copy constructor and assignment operators
288 TextField(const TextField&);
289 TextField& operator=(const TextField& rhs);
292 * @brief Render view, create and attach actor(s) to this Text Field.
294 void RenderText( Text::Controller::UpdateTextType updateTextType );
296 // Connection needed to re-render text, when a Text Field returns to the scene.
297 void OnSceneConnect( Dali::Actor actor );
299 public: // For UTC only
301 Text::ControllerPtr GetTextController() { return mController; }
306 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
307 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
308 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
310 InputMethodContext mInputMethodContext;
311 Text::ControllerPtr mController;
312 Text::RendererPtr mRenderer;
313 Text::DecoratorPtr mDecorator;
314 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
315 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
316 Dali::InputMethodOptions mInputMethodOptions;
318 Actor mRenderableActor;
320 Actor mBackgroundActor;
321 CallbackBase* mIdleCallback;
323 float mAlignmentOffset;
324 int mRenderingBackend;
326 bool mHasBeenStaged:1;
329 } // namespace Internal
331 // Helpers for public-api forwarding methods
333 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
335 DALI_ASSERT_ALWAYS(textField);
337 Dali::RefObject& handle = textField.GetImplementation();
339 return static_cast<Toolkit::Internal::TextField&>(handle);
342 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
344 DALI_ASSERT_ALWAYS(textField);
346 const Dali::RefObject& handle = textField.GetImplementation();
348 return static_cast<const Toolkit::Internal::TextField&>(handle);
351 } // namespace Toolkit
355 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H