1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
5 * Copyright (c) 2021 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/autofill-item.h>
23 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
24 #include <dali/devel-api/adaptor-framework/input-method-context.h>
27 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
28 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
29 #include <dali-toolkit/internal/text/text-control-interface.h>
30 #include <dali-toolkit/internal/text/text-controller.h>
31 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
32 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
33 #include <dali-toolkit/public-api/controls/control-impl.h>
34 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
43 * @brief A control which renders a short text string.
45 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
49 * @copydoc Dali::Toollkit::TextField::New()
51 static Toolkit::TextField New();
56 * @brief Called when a property of an object of this type is set.
58 * @param[in] object The object whose property is set.
59 * @param[in] index The property index.
60 * @param[in] value The new property value.
62 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
65 * @brief Called to retrieve a property of an object of this type.
67 * @param[in] object The object whose property is to be retrieved.
68 * @param[in] index The property index.
69 * @return The current value of the property.
71 static Property::Value GetProperty(BaseObject* object, Property::Index index);
74 * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
76 InputMethodContext GetInputMethodContext();
79 * Connects a callback function with the object's signals.
80 * @param[in] object The object providing the signal.
81 * @param[in] tracker Used to disconnect the signal.
82 * @param[in] signalName The signal to connect to.
83 * @param[in] functor A newly allocated FunctorDelegate.
84 * @return True if the signal was connected.
85 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
87 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
90 * @copydoc TextField::TextChangedSignal()
92 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
95 * @copydoc TextField::MaxLengthReachedSignal()
97 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
100 * @copydoc TextField::TextChangedSignal()
102 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
104 private: // From Control
106 * @copydoc Control::OnInitialize()
108 void OnInitialize() override;
111 * @copydoc Control::OnStyleChange()
113 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
116 * @copydoc Control::GetNaturalSize()
118 Vector3 GetNaturalSize() override;
121 * @copydoc Control::GetHeightForWidth()
123 float GetHeightForWidth(float width) override;
126 * @copydoc Control::OnInitialize()
128 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
131 * @copydoc Control::OnKeyInputFocusGained()
133 void OnKeyInputFocusGained() override;
136 * @copydoc Control::OnKeyInputFocusLost()
138 void OnKeyInputFocusLost() override;
141 * @copydoc Control::OnTap()
143 void OnTap(const TapGesture& tap) override;
146 * @copydoc Control::OnPan()
148 void OnPan(const PanGesture& gesture) override;
151 * @copydoc Control::OnLongPress()
153 void OnLongPress(const LongPressGesture& gesture) override;
156 * @copydoc Control::OnSceneConnection()
158 void OnSceneConnection(int depth) override;
161 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
163 bool OnKeyEvent(const KeyEvent& event) override;
165 // From ControlInterface
168 * @copydoc Text::ControlInterface::RequestTextRelayout()
170 void RequestTextRelayout() override;
172 // From EditableControlInterface
175 * @copydoc Text::EditableControlInterface::TextChanged()
177 void TextChanged(bool immediate) override;
180 * @copydoc Text::EditableControlInterface::MaxLengthReached()
182 void MaxLengthReached() override;
185 * @copydoc Text::EditableControlInterface::InputStyleChanged()
187 void InputStyleChanged(Text::InputStyle::Mask inputStyleMask) override;
190 * @copydoc Text::EditableControlInterface::AddDecoration()
192 void AddDecoration(Actor& actor, bool needsClipping) override;
194 // From SelectableControlInterface
197 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
199 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end) override;
202 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
204 Uint32Pair GetTextSelectionRange() const override;
207 * @copydoc Text::SelectableControlInterface::SelectWholeText()
209 void SelectWholeText() override;
212 * @copydoc Text::SelectableControlInterface::SelectNone()
214 void SelectNone() override;
217 * @copydoc Text::SelectableControlInterface::GetSelectedText()
219 string GetSelectedText() const override;
222 * @copydoc Text::EditableControlInterface::IsEditable()
224 bool IsEditable() const override;
227 * @copydoc Text::EditableControlInterface::SetEditable()
229 void SetEditable(bool editable) override;
231 private: // Implementation
233 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
235 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
238 * @brief Callback when Clipboard signals an item should be pasted
239 * @param[in] clipboard handle to Clipboard Event Notifier
241 void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
244 * @brief Get a Property Map for the image used for the required Handle Image
245 * @param[out] value the returned image property
246 * @param[in] handleType the type of handle
247 * @param[in] handleImageType the type of image for the given handleType
249 void GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType);
252 * @brief Enable or disable clipping.
254 void EnableClipping();
257 * @brief Callback when keyboard is shown/hidden.
259 * @param[in] keyboardShown True if keyboard is shown.
261 void KeyboardStatusChanged(bool keyboardShown);
264 * @brief Callback when TextField is touched
266 * @param[in] actor TextField touched
267 * @param[in] touch Touch information
269 bool OnTouched(Actor actor, const TouchEvent& touch);
272 * @brief Callbacks called on idle.
274 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
279 * @brief Emits TextChanged signal.
281 void EmitTextChangedSignal();
284 * Construct a new TextField.
289 * A reference counted object may only be deleted by calling Unreference()
291 virtual ~TextField();
293 // Undefined copy constructor and assignment operators
294 TextField(const TextField&);
295 TextField& operator=(const TextField& rhs);
298 * @brief Render view, create and attach actor(s) to this Text Field.
300 void RenderText(Text::Controller::UpdateTextType updateTextType);
302 // Connection needed to re-render text, when a Text Field returns to the scene.
303 void OnSceneConnect(Dali::Actor actor);
305 public: // For UTC only
306 Text::ControllerPtr GetTextController()
313 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
314 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
315 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
317 InputMethodContext mInputMethodContext;
318 Text::ControllerPtr mController;
319 Text::RendererPtr mRenderer;
320 Text::DecoratorPtr mDecorator;
321 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
322 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
323 Dali::InputMethodOptions mInputMethodOptions;
324 Dali::AutofillItem mAutofillItem;
326 Actor mRenderableActor;
328 Actor mBackgroundActor;
329 CallbackBase* mIdleCallback;
331 float mAlignmentOffset;
332 int mRenderingBackend;
334 bool mHasBeenStaged : 1;
335 bool mTextChanged : 1; ///< If true, emits TextChangedSignal in next OnRelayout().
338 } // namespace Internal
340 // Helpers for public-api forwarding methods
342 inline Toolkit::Internal::TextField& GetImpl(Toolkit::TextField& textField)
344 DALI_ASSERT_ALWAYS(textField);
346 Dali::RefObject& handle = textField.GetImplementation();
348 return static_cast<Toolkit::Internal::TextField&>(handle);
351 inline const Toolkit::Internal::TextField& GetImpl(const Toolkit::TextField& textField)
353 DALI_ASSERT_ALWAYS(textField);
355 const Dali::RefObject& handle = textField.GetImplementation();
357 return static_cast<const Toolkit::Internal::TextField&>(handle);
360 } // namespace Toolkit
364 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H