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>
34 #include <dali-toolkit/internal/controls/control/control-data-impl.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();
107 Text::ControllerPtr getController();
109 private: // From Control
112 * @copydoc Control::OnInitialize()
114 void OnInitialize() override;
117 * @copydoc Control::OnStyleChange()
119 void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
122 * @copydoc Control::GetNaturalSize()
124 Vector3 GetNaturalSize() override;
127 * @copydoc Control::GetHeightForWidth()
129 float GetHeightForWidth( float width ) override;
132 * @copydoc Control::OnInitialize()
134 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
137 * @copydoc Control::OnKeyInputFocusGained()
139 void OnKeyInputFocusGained() override;
142 * @copydoc Control::OnKeyInputFocusLost()
144 void OnKeyInputFocusLost() override;
147 * @copydoc Control::OnTap()
149 void OnTap( const TapGesture& tap ) override;
152 * @copydoc Control::OnPan()
154 void OnPan( const PanGesture& gesture ) override;
157 * @copydoc Control::OnLongPress()
159 void OnLongPress( const LongPressGesture& gesture ) override;
162 * @copydoc Control::OnSceneConnection()
164 void OnSceneConnection( int depth ) override;
167 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
169 bool OnKeyEvent(const KeyEvent& event) override;
171 // From ControlInterface
174 * @copydoc Text::ControlInterface::RequestTextRelayout()
176 void RequestTextRelayout() override;
178 // From EditableControlInterface
181 * @copydoc Text::EditableControlInterface::TextChanged()
183 void TextInserted( unsigned int position, unsigned int length, const std::string &content ) override;
186 * @copydoc Text::EditableControlInterface::TextDeleted()
188 void TextDeleted( unsigned int position, unsigned int length, const std::string &content ) override;
191 * @copydoc Text::EditableControlInterface::CaretMoved()
193 void CaretMoved( unsigned int position ) override;
196 * @copydoc Text::EditableControlInterface::TextChanged()
198 void TextChanged() override;
201 * @copydoc Text::EditableControlInterface::MaxLengthReached()
203 void MaxLengthReached() override;
206 * @copydoc Text::EditableControlInterface::InputStyleChanged()
208 void InputStyleChanged( Text::InputStyle::Mask inputStyleMask ) override;
211 * @copydoc Text::EditableControlInterface::AddDecoration()
213 void AddDecoration( Actor& actor, bool needsClipping ) override;
215 // From SelectableControlInterface
218 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
220 void SetTextSelectionRange(const uint32_t *start, const uint32_t *end) override;
223 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
225 Uint32Pair GetTextSelectionRange() const override;
228 * @copydoc Text::SelectableControlInterface::SelectWholeText()
230 void SelectWholeText() override;
233 * @copydoc Text::SelectableControlInterface::SelectNone()
235 void SelectNone() override;
238 * @copydoc Text::SelectableControlInterface::GetSelectedText()
240 string GetSelectedText() const override;
243 * @copydoc Text::EditableControlInterface::IsEditable()
245 bool IsEditable() const override;
248 * @copydoc Text::EditableControlInterface::SetEditable()
250 void SetEditable( bool editable ) override;
252 private: // Implementation
255 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
257 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
260 * @brief Callback when Clipboard signals an item should be pasted
261 * @param[in] clipboard handle to Clipboard Event Notifier
263 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
266 * @brief Get a Property Map for the image used for the required Handle Image
267 * @param[out] value the returned image property
268 * @param[in] handleType the type of handle
269 * @param[in] handleImageType the type of image for the given handleType
271 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
274 * @brief Enable or disable clipping.
276 void EnableClipping();
279 * @brief Callback when keyboard is shown/hidden.
281 * @param[in] keyboardShown True if keyboard is shown.
283 void KeyboardStatusChanged( bool keyboardShown );
286 * @brief Callback when TextField is touched
288 * @param[in] actor TextField touched
289 * @param[in] touch Touch information
291 bool OnTouched( Actor actor, const TouchEvent& touch );
294 * @brief Callbacks called on idle.
296 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
301 * Construct a new TextField.
306 * A reference counted object may only be deleted by calling Unreference()
308 virtual ~TextField();
310 // Undefined copy constructor and assignment operators
311 TextField(const TextField&);
312 TextField& operator=(const TextField& rhs);
315 * @brief Render view, create and attach actor(s) to this Text Field.
317 void RenderText( Text::Controller::UpdateTextType updateTextType );
319 // Connection needed to re-render text, when a Text Field returns to the scene.
320 void OnSceneConnect( Dali::Actor actor );
322 public: // For UTC only
324 Text::ControllerPtr GetTextController() { return mController; }
329 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
330 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
331 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
333 InputMethodContext mInputMethodContext;
334 Text::ControllerPtr mController;
335 Text::RendererPtr mRenderer;
336 Text::DecoratorPtr mDecorator;
337 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
338 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
339 Dali::InputMethodOptions mInputMethodOptions;
341 Actor mRenderableActor;
343 Actor mBackgroundActor;
344 CallbackBase* mIdleCallback;
346 float mAlignmentOffset;
347 int mRenderingBackend;
349 bool mHasBeenStaged:1;
352 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
353 public virtual Dali::Accessibility::Text,
354 public virtual Dali::Accessibility::EditableText
356 using Control::Impl::AccessibleImpl::AccessibleImpl;
358 std::string GetName() override;
359 std::string GetText( size_t startOffset, size_t endOffset ) override;
360 size_t GetCharacterCount() override;
361 size_t GetCaretOffset() override;
362 bool SetCaretOffset(size_t offset) override;
363 Dali::Accessibility::Range
364 GetTextAtOffset( size_t offset,
365 Dali::Accessibility::TextBoundary boundary ) override;
366 Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
367 bool RemoveSelection( size_t selectionNum ) override;
368 bool SetSelection( size_t selectionNum, size_t startOffset,
369 size_t endOffset ) override;
370 bool CopyText( size_t startPosition, size_t endPosition ) override;
371 bool CutText( size_t startPosition, size_t endPosition ) override;
372 Dali::Accessibility::States CalculateStates() override;
376 } // namespace Internal
378 // Helpers for public-api forwarding methods
380 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
382 DALI_ASSERT_ALWAYS(textField);
384 Dali::RefObject& handle = textField.GetImplementation();
386 return static_cast<Toolkit::Internal::TextField&>(handle);
389 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
391 DALI_ASSERT_ALWAYS(textField);
393 const Dali::RefObject& handle = textField.GetImplementation();
395 return static_cast<const Toolkit::Internal::TextField&>(handle);
398 } // namespace Toolkit
402 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H