1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
5 * Copyright (c) 2017 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-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
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();
112 Text::ControllerPtr getController();
114 private: // From Control
117 * @copydoc Control::OnInitialize()
119 virtual void OnInitialize();
122 * @copydoc Control::OnStyleChange()
124 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
127 * @copydoc Control::GetNaturalSize()
129 virtual Vector3 GetNaturalSize();
132 * @copydoc Control::GetHeightForWidth()
134 virtual float GetHeightForWidth( float width );
137 * @copydoc Control::OnInitialize()
139 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
142 * @copydoc Control::OnKeyInputFocusGained()
144 virtual void OnKeyInputFocusGained();
147 * @copydoc Control::OnKeyInputFocusLost()
149 virtual void OnKeyInputFocusLost();
152 * @copydoc Control::OnTap()
154 virtual void OnTap( const TapGesture& tap );
157 * @copydoc Control::OnPan()
159 virtual void OnPan( const PanGesture& gesture );
162 * @copydoc Control::OnLongPress()
164 virtual void OnLongPress( const LongPressGesture& gesture );
167 * @copydoc Control::OnStageConnection()
169 virtual void OnStageConnection( int depth );
172 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
174 virtual bool OnKeyEvent(const KeyEvent& event);
176 // From ControlInterface
179 * @copydoc Text::ControlInterface::RequestTextRelayout()
181 virtual void RequestTextRelayout();
183 // From EditableControlInterface
186 * @copydoc Text::ControlInterface::TextInserted()
188 virtual void TextInserted( unsigned int position, unsigned int length, const std::string &content );
191 * @copydoc Text::ControlInterface::TextDeleted()
193 virtual void TextDeleted( unsigned int position, unsigned int length, const std::string &content );
196 * @copydoc Text::ControlInterface::CaretMoved()
198 virtual void CaretMoved( unsigned int position );
201 * @copydoc Text::ControlInterface::TextChanged()
203 virtual void TextChanged();
206 * @copydoc Text::ControlInterface::MaxLengthReached()
208 virtual void MaxLengthReached();
211 * @copydoc Text::ControlInterface::InputStyleChanged()
213 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
216 * @copydoc Text::ControlInterface::AddDecoration()
218 virtual void AddDecoration( Actor& actor, bool needsClipping );
220 private: // Implementation
223 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
225 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
228 * @brief Callback when Clipboard signals an item should be pasted
229 * @param[in] clipboard handle to Clipboard Event Notifier
231 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
234 * @brief Get a Property Map for the image used for the required Handle Image
235 * @param[out] value the returned image property
236 * @param[in] handleType the type of handle
237 * @param[in] handleImageType the type of image for the given handleType
239 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
242 * @brief Enable or disable clipping.
244 void EnableClipping();
247 * @brief Callback when keyboard is shown/hidden.
249 * @param[in] keyboardShown True if keyboard is shown.
251 void KeyboardStatusChanged( bool keyboardShown );
254 * @brief Callback when TextField is touched
256 * @param[in] actor TextField touched
257 * @param[in] touch Touch information
259 bool OnTouched( Actor actor, const TouchData& touch );
262 * @brief Callbacks called on idle.
264 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
269 * Construct a new TextField.
274 * A reference counted object may only be deleted by calling Unreference()
276 virtual ~TextField();
278 // Undefined copy constructor and assignment operators
279 TextField(const TextField&);
280 TextField& operator=(const TextField& rhs);
283 * @brief Render view, create and attach actor(s) to this Text Field.
285 void RenderText( Text::Controller::UpdateTextType updateTextType );
287 // Connection needed to re-render text, when a Text Field returns to the stage.
288 void OnStageConnect( Dali::Actor actor );
293 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
294 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
295 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
297 InputMethodContext mInputMethodContext;
298 Text::ControllerPtr mController;
299 Text::RendererPtr mRenderer;
300 Text::DecoratorPtr mDecorator;
301 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
302 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
303 Dali::InputMethodOptions mInputMethodOptions;
304 Dali::AutofillItem mAutofillItem;
306 Actor mRenderableActor;
308 CallbackBase* mIdleCallback;
310 float mAlignmentOffset;
311 int mRenderingBackend;
313 bool mHasBeenStaged:1;
316 struct AccessibleImpl : public Control::Impl::AccessibleImpl,
317 public virtual Dali::Accessibility::Text,
318 public virtual Dali::Accessibility::EditableText
320 using Control::Impl::AccessibleImpl::AccessibleImpl;
322 std::string GetName() override;
323 std::string GetText( size_t startOffset, size_t endOffset ) override;
324 size_t GetCharacterCount() override;
325 size_t GetCaretOffset() override;
326 bool SetCaretOffset(size_t offset) override;
327 Dali::Accessibility::Range
328 GetTextAtOffset( size_t offset,
329 Dali::Accessibility::TextBoundary boundary ) override;
330 Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
331 bool RemoveSelection( size_t selectionNum ) override;
332 bool SetSelection( size_t selectionNum, size_t startOffset,
333 size_t endOffset ) override;
334 bool CopyText( size_t startPosition, size_t endPosition ) override;
335 bool CutText( size_t startPosition, size_t endPosition ) override;
336 Dali::Accessibility::States CalculateStates() override;
340 } // namespace Internal
342 // Helpers for public-api forwarding methods
344 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
346 DALI_ASSERT_ALWAYS(textField);
348 Dali::RefObject& handle = textField.GetImplementation();
350 return static_cast<Toolkit::Internal::TextField&>(handle);
353 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
355 DALI_ASSERT_ALWAYS(textField);
357 const Dali::RefObject& handle = textField.GetImplementation();
359 return static_cast<const Toolkit::Internal::TextField&>(handle);
362 } // namespace Toolkit
366 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H