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>
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-controller.h>
32 #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 * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
77 InputMethodContext GetInputMethodContext();
80 * Connects a callback function with the object's signals.
81 * @param[in] object The object providing the signal.
82 * @param[in] tracker Used to disconnect the signal.
83 * @param[in] signalName The signal to connect to.
84 * @param[in] functor A newly allocated FunctorDelegate.
85 * @return True if the signal was connected.
86 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
88 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
91 * @copydoc TextField::TextChangedSignal()
93 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
96 * @copydoc TextField::MaxLengthReachedSignal()
98 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
101 * @copydoc TextField::TextChangedSignal()
103 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
106 * @brief Called to select the whole texts.
108 void SelectWholeText();
111 * @brief Called to unselect the whole texts.
115 private: // From Control
118 * @copydoc Control::OnInitialize()
120 virtual void OnInitialize();
123 * @copydoc Control::OnStyleChange()
125 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
128 * @copydoc Control::GetNaturalSize()
130 virtual Vector3 GetNaturalSize();
133 * @copydoc Control::GetHeightForWidth()
135 virtual float GetHeightForWidth( float width );
138 * @copydoc Control::OnInitialize()
140 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
143 * @copydoc Control::OnKeyInputFocusGained()
145 virtual void OnKeyInputFocusGained();
148 * @copydoc Control::OnKeyInputFocusLost()
150 virtual void OnKeyInputFocusLost();
153 * @copydoc Control::OnTap()
155 virtual void OnTap( const TapGesture& tap );
158 * @copydoc Control::OnPan()
160 virtual void OnPan( const PanGesture& gesture );
163 * @copydoc Control::OnLongPress()
165 virtual void OnLongPress( const LongPressGesture& gesture );
168 * @copydoc Control::OnSceneConnection()
170 virtual void OnSceneConnection( int depth );
173 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
175 virtual bool OnKeyEvent(const KeyEvent& event);
177 // From ControlInterface
180 * @copydoc Text::ControlInterface::RequestTextRelayout()
182 virtual void RequestTextRelayout();
184 // From EditableControlInterface
187 * @copydoc Text::ControlInterface::TextChanged()
189 virtual void TextChanged();
192 * @copydoc Text::ControlInterface::MaxLengthReached()
194 virtual void MaxLengthReached();
197 * @copydoc Text::ControlInterface::InputStyleChanged()
199 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
202 * @copydoc Text::ControlInterface::AddDecoration()
204 virtual void AddDecoration( Actor& actor, bool needsClipping );
206 private: // Implementation
209 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
211 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
214 * @brief Callback when Clipboard signals an item should be pasted
215 * @param[in] clipboard handle to Clipboard Event Notifier
217 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
220 * @brief Get a Property Map for the image used for the required Handle Image
221 * @param[out] value the returned image property
222 * @param[in] handleType the type of handle
223 * @param[in] handleImageType the type of image for the given handleType
225 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
228 * @brief Enable or disable clipping.
230 void EnableClipping();
233 * @brief Callback when keyboard is shown/hidden.
235 * @param[in] keyboardShown True if keyboard is shown.
237 void KeyboardStatusChanged( bool keyboardShown );
240 * @brief Callback when TextField is touched
242 * @param[in] actor TextField touched
243 * @param[in] touch Touch information
245 bool OnTouched( Actor actor, const TouchData& touch );
248 * @brief Callbacks called on idle.
250 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
255 * Construct a new TextField.
260 * A reference counted object may only be deleted by calling Unreference()
262 virtual ~TextField();
264 // Undefined copy constructor and assignment operators
265 TextField(const TextField&);
266 TextField& operator=(const TextField& rhs);
269 * @brief Render view, create and attach actor(s) to this Text Field.
271 void RenderText( Text::Controller::UpdateTextType updateTextType );
273 // Connection needed to re-render text, when a Text Field returns to the scene.
274 void OnSceneConnect( Dali::Actor actor );
276 public: // For UTC only
278 Text::ControllerPtr GetTextController() { return mController; }
283 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
284 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
285 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
287 InputMethodContext mInputMethodContext;
288 Text::ControllerPtr mController;
289 Text::RendererPtr mRenderer;
290 Text::DecoratorPtr mDecorator;
291 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
292 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
293 Dali::InputMethodOptions mInputMethodOptions;
295 Actor mRenderableActor;
297 Actor mBackgroundActor;
298 CallbackBase* mIdleCallback;
300 float mAlignmentOffset;
301 int mRenderingBackend;
303 bool mHasBeenStaged:1;
306 } // namespace Internal
308 // Helpers for public-api forwarding methods
310 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
312 DALI_ASSERT_ALWAYS(textField);
314 Dali::RefObject& handle = textField.GetImplementation();
316 return static_cast<Toolkit::Internal::TextField&>(handle);
319 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
321 DALI_ASSERT_ALWAYS(textField);
323 const Dali::RefObject& handle = textField.GetImplementation();
325 return static_cast<const Toolkit::Internal::TextField&>(handle);
328 } // namespace Toolkit
332 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H