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>
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
27 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
28 #include <dali-toolkit/internal/text/text-control-interface.h>
29 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
30 #include <dali-toolkit/internal/text/text-controller.h>
31 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
43 * @brief A control which renders a short text string.
45 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface
50 * @copydoc Dali::Toollkit::TextField::New()
52 static Toolkit::TextField New();
57 * @brief Called when a property of an object of this type is set.
59 * @param[in] object The object whose property is set.
60 * @param[in] index The property index.
61 * @param[in] value The new property value.
63 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
66 * @brief Called to retrieve a property of an object of this type.
68 * @param[in] object The object whose property is to be retrieved.
69 * @param[in] index The property index.
70 * @return The current value of the property.
72 static Property::Value GetProperty( BaseObject* object, Property::Index index );
75 * Connects a callback function with the object's signals.
76 * @param[in] object The object providing the signal.
77 * @param[in] tracker Used to disconnect the signal.
78 * @param[in] signalName The signal to connect to.
79 * @param[in] functor A newly allocated FunctorDelegate.
80 * @return True if the signal was connected.
81 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
83 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
86 * @copydoc TextField::TextChangedSignal()
88 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
91 * @copydoc TextField::MaxLengthReachedSignal()
93 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
96 * @copydoc TextField::TextChangedSignal()
98 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
100 Text::ControllerPtr getController();
102 private: // From Control
105 * @copydoc Control::OnInitialize()
107 virtual void OnInitialize();
110 * @copydoc Control::OnStyleChange()
112 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
115 * @copydoc Control::GetNaturalSize()
117 virtual Vector3 GetNaturalSize();
120 * @copydoc Control::GetHeightForWidth()
122 virtual float GetHeightForWidth( float width );
125 * @copydoc Control::OnInitialize()
127 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
130 * @copydoc Control::OnKeyInputFocusGained()
132 virtual void OnKeyInputFocusGained();
135 * @copydoc Control::OnKeyInputFocusLost()
137 virtual void OnKeyInputFocusLost();
140 * @copydoc Control::OnTap()
142 virtual void OnTap( const TapGesture& tap );
145 * @copydoc Control::OnPan()
147 virtual void OnPan( const PanGesture& gesture );
150 * @copydoc Control::OnLongPress()
152 virtual void OnLongPress( const LongPressGesture& gesture );
155 * @copydoc Control::OnStageConnection()
157 virtual void OnStageConnection( int depth );
160 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
162 virtual bool OnKeyEvent(const KeyEvent& event);
164 // From ControlInterface
167 * @copydoc Text::ControlInterface::RequestTextRelayout()
169 virtual void RequestTextRelayout();
171 // From EditableControlInterface
174 * @copydoc Text::ControlInterface::TextChanged()
176 virtual void TextChanged();
179 * @copydoc Text::ControlInterface::MaxLengthReached()
181 virtual void MaxLengthReached();
184 * @copydoc Text::ControlInterface::InputStyleChanged()
186 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
189 * @copydoc Text::ControlInterface::AddDecoration()
191 virtual void AddDecoration( Actor& actor, bool needsClipping );
193 private: // Implementation
196 * @copydoc Dali::Toolkit::Text::Controller::(ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent)
198 ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
201 * @brief Callback when Clipboard signals an item should be pasted
202 * @param[in] clipboard handle to Clipboard Event Notifier
204 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
207 * @brief Get a Property Map for the image used for the required Handle Image
208 * @param[out] value the returned image property
209 * @param[in] handleType the type of handle
210 * @param[in] handleImageType the type of image for the given handleType
212 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
215 * @brief Enable or disable clipping.
217 void EnableClipping();
220 * @brief Callback when keyboard is shown/hidden.
222 * @param[in] keyboardShown True if keyboard is shown.
224 void KeyboardStatusChanged( bool keyboardShown );
227 * @brief Callback when TextField is touched
229 * @param[in] actor TextField touched
230 * @param[in] touch Touch information
232 bool OnTouched( Actor actor, const TouchData& touch );
235 * @brief Callbacks called on idle.
237 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
242 * Construct a new TextField.
247 * A reference counted object may only be deleted by calling Unreference()
249 virtual ~TextField();
251 // Undefined copy constructor and assignment operators
252 TextField(const TextField&);
253 TextField& operator=(const TextField& rhs);
256 * @brief Render view, create and attach actor(s) to this Text Field.
258 void RenderText( Text::Controller::UpdateTextType updateTextType );
260 // Connection needed to re-render text, when a Text Field returns to the stage.
261 void OnStageConnect( Dali::Actor actor );
266 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
267 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
268 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
270 ImfManager mImfManager;
271 Text::ControllerPtr mController;
272 Text::RendererPtr mRenderer;
273 Text::DecoratorPtr mDecorator;
274 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
275 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
276 Dali::InputMethodOptions mInputMethodOptions;
278 Actor mRenderableActor;
280 CallbackBase* mIdleCallback;
282 float mAlignmentOffset;
283 int mRenderingBackend;
285 bool mHasBeenStaged:1;
288 struct AccessibleImpl : public Control::AccessibleImpl,
289 public virtual Dali::Accessibility::Text,
290 public virtual Dali::Accessibility::EditableText
292 using Control::AccessibleImpl::AccessibleImpl;
294 std::string GetName() override;
295 std::string GetText( size_t startOffset, size_t endOffset ) override;
296 size_t GetCharacterCount() override;
297 Dali::Accessibility::Range
298 GetTextAtOffset( size_t offset,
299 Dali::Accessibility::TextBoundary boundary ) override;
300 Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
301 bool RemoveSelection( size_t selectionNum ) override;
302 bool SetSelection( size_t selectionNum, size_t startOffset,
303 size_t endOffset ) override;
304 bool CopyText( size_t startPosition, size_t endPosition ) override;
305 bool CutText( size_t startPosition, size_t endPosition ) override;
309 } // namespace Internal
311 // Helpers for public-api forwarding methods
313 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
315 DALI_ASSERT_ALWAYS(textField);
317 Dali::RefObject& handle = textField.GetImplementation();
319 return static_cast<Toolkit::Internal::TextField&>(handle);
322 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
324 DALI_ASSERT_ALWAYS(textField);
326 const Dali::RefObject& handle = textField.GetImplementation();
328 return static_cast<const Toolkit::Internal::TextField&>(handle);
331 } // namespace Toolkit
335 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H