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>
24 #include <dali/devel-api/adaptor-framework/autofill-item.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
29 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
30 #include <dali-toolkit/internal/text/text-control-interface.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/internal/text/text-controller.h>
34 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
45 * @brief A control which renders a short text string.
47 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
52 * @copydoc Dali::Toollkit::TextField::New()
54 static Toolkit::TextField New();
59 * @brief Called when a property of an object of this type is set.
61 * @param[in] object The object whose property is set.
62 * @param[in] index The property index.
63 * @param[in] value The new property value.
65 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
68 * @brief Called to retrieve a property of an object of this type.
70 * @param[in] object The object whose property is to be retrieved.
71 * @param[in] index The property index.
72 * @return The current value of the property.
74 static Property::Value GetProperty( BaseObject* object, Property::Index index );
77 * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
79 InputMethodContext GetInputMethodContext();
82 * Connects a callback function with the object's signals.
83 * @param[in] object The object providing the signal.
84 * @param[in] tracker Used to disconnect the signal.
85 * @param[in] signalName The signal to connect to.
86 * @param[in] functor A newly allocated FunctorDelegate.
87 * @return True if the signal was connected.
88 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
90 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
93 * @copydoc TextField::TextChangedSignal()
95 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
98 * @copydoc TextField::MaxLengthReachedSignal()
100 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
103 * @copydoc TextField::TextChangedSignal()
105 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
108 * @brief Called to select the whole texts.
110 void SelectWholeText();
113 * @brief Called to unselect the whole texts.
117 private: // From Control
120 * @copydoc Control::OnInitialize()
122 void OnInitialize() override;
125 * @copydoc Control::OnStyleChange()
127 void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
130 * @copydoc Control::GetNaturalSize()
132 Vector3 GetNaturalSize() override;
135 * @copydoc Control::GetHeightForWidth()
137 float GetHeightForWidth( float width ) override;
140 * @copydoc Control::OnInitialize()
142 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
145 * @copydoc Control::OnKeyInputFocusGained()
147 void OnKeyInputFocusGained() override;
150 * @copydoc Control::OnKeyInputFocusLost()
152 void OnKeyInputFocusLost() override;
155 * @copydoc Control::OnTap()
157 void OnTap( const TapGesture& tap ) override;
160 * @copydoc Control::OnPan()
162 void OnPan( const PanGesture& gesture ) override;
165 * @copydoc Control::OnLongPress()
167 void OnLongPress( const LongPressGesture& gesture ) override;
170 * @copydoc Control::OnSceneConnection()
172 void OnSceneConnection( int depth ) override;
175 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
177 bool OnKeyEvent(const KeyEvent& event) override;
179 // From ControlInterface
182 * @copydoc Text::ControlInterface::RequestTextRelayout()
184 void RequestTextRelayout() override;
186 // From EditableControlInterface
189 * @copydoc Text::ControlInterface::TextChanged()
191 void TextChanged() override;
194 * @copydoc Text::ControlInterface::MaxLengthReached()
196 void MaxLengthReached() override;
199 * @copydoc Text::ControlInterface::InputStyleChanged()
201 void InputStyleChanged( Text::InputStyle::Mask inputStyleMask ) override;
204 * @copydoc Text::ControlInterface::AddDecoration()
206 void AddDecoration( Actor& actor, bool needsClipping ) override;
208 // From SelectableControlInterface
211 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
213 void SetTextSelectionRange(const uint32_t *start, const uint32_t *end) override;
216 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
218 Uint32Pair GetTextSelectionRange() const override;
221 * @copydoc Text::EditableControlInterface::IsEditable()
223 bool IsEditable() const override;
226 * @copydoc Text::EditableControlInterface::SetEditable()
228 void SetEditable( bool editable ) override;
230 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 * Construct a new TextField.
284 * A reference counted object may only be deleted by calling Unreference()
286 virtual ~TextField();
288 // Undefined copy constructor and assignment operators
289 TextField(const TextField&);
290 TextField& operator=(const TextField& rhs);
293 * @brief Render view, create and attach actor(s) to this Text Field.
295 void RenderText( Text::Controller::UpdateTextType updateTextType );
297 // Connection needed to re-render text, when a Text Field returns to the scene.
298 void OnSceneConnect( Dali::Actor actor );
300 public: // For UTC only
302 Text::ControllerPtr GetTextController() { return mController; }
307 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
308 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
309 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
311 InputMethodContext mInputMethodContext;
312 Text::ControllerPtr mController;
313 Text::RendererPtr mRenderer;
314 Text::DecoratorPtr mDecorator;
315 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
316 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
317 Dali::InputMethodOptions mInputMethodOptions;
318 Dali::AutofillItem mAutofillItem;
320 Actor mRenderableActor;
322 Actor mBackgroundActor;
323 CallbackBase* mIdleCallback;
325 float mAlignmentOffset;
326 int mRenderingBackend;
328 bool mHasBeenStaged:1;
331 } // namespace Internal
333 // Helpers for public-api forwarding methods
335 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
337 DALI_ASSERT_ALWAYS(textField);
339 Dali::RefObject& handle = textField.GetImplementation();
341 return static_cast<Toolkit::Internal::TextField&>(handle);
344 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
346 DALI_ASSERT_ALWAYS(textField);
348 const Dali::RefObject& handle = textField.GetImplementation();
350 return static_cast<const Toolkit::Internal::TextField&>(handle);
353 } // namespace Toolkit
357 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H