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>
44 * @brief A control which renders a short text string.
46 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface
51 * @copydoc Dali::Toollkit::TextField::New()
53 static Toolkit::TextField New();
58 * @brief Called when a property of an object of this type is set.
60 * @param[in] object The object whose property is set.
61 * @param[in] index The property index.
62 * @param[in] value The new property value.
64 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
67 * @brief Called to retrieve a property of an object of this type.
69 * @param[in] object The object whose property is to be retrieved.
70 * @param[in] index The property index.
71 * @return The current value of the property.
73 static Property::Value GetProperty( BaseObject* object, Property::Index index );
76 * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
78 InputMethodContext GetInputMethodContext();
81 * Connects a callback function with the object's signals.
82 * @param[in] object The object providing the signal.
83 * @param[in] tracker Used to disconnect the signal.
84 * @param[in] signalName The signal to connect to.
85 * @param[in] functor A newly allocated FunctorDelegate.
86 * @return True if the signal was connected.
87 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
89 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
92 * @copydoc TextField::TextChangedSignal()
94 Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
97 * @copydoc TextField::MaxLengthReachedSignal()
99 Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
102 * @copydoc TextField::TextChangedSignal()
104 Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
107 * @brief Called to select the whole texts.
109 void SelectWholeText();
111 private: // From Control
114 * @copydoc Control::OnInitialize()
116 virtual void OnInitialize();
119 * @copydoc Control::OnStyleChange()
121 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
124 * @copydoc Control::GetNaturalSize()
126 virtual Vector3 GetNaturalSize();
129 * @copydoc Control::GetHeightForWidth()
131 virtual float GetHeightForWidth( float width );
134 * @copydoc Control::OnInitialize()
136 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
139 * @copydoc Control::OnKeyInputFocusGained()
141 virtual void OnKeyInputFocusGained();
144 * @copydoc Control::OnKeyInputFocusLost()
146 virtual void OnKeyInputFocusLost();
149 * @copydoc Control::OnTap()
151 virtual void OnTap( const TapGesture& tap );
154 * @copydoc Control::OnPan()
156 virtual void OnPan( const PanGesture& gesture );
159 * @copydoc Control::OnLongPress()
161 virtual void OnLongPress( const LongPressGesture& gesture );
164 * @copydoc Control::OnStageConnection()
166 virtual void OnStageConnection( int depth );
169 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
171 virtual bool OnKeyEvent(const KeyEvent& event);
173 // From ControlInterface
176 * @copydoc Text::ControlInterface::RequestTextRelayout()
178 virtual void RequestTextRelayout();
180 // From EditableControlInterface
183 * @copydoc Text::ControlInterface::TextChanged()
185 virtual void TextChanged();
188 * @copydoc Text::ControlInterface::MaxLengthReached()
190 virtual void MaxLengthReached();
193 * @copydoc Text::ControlInterface::InputStyleChanged()
195 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
198 * @copydoc Text::ControlInterface::AddDecoration()
200 virtual void AddDecoration( Actor& actor, bool needsClipping );
202 private: // Implementation
205 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
207 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
210 * @brief Callback when Clipboard signals an item should be pasted
211 * @param[in] clipboard handle to Clipboard Event Notifier
213 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
216 * @brief Get a Property Map for the image used for the required Handle Image
217 * @param[out] value the returned image property
218 * @param[in] handleType the type of handle
219 * @param[in] handleImageType the type of image for the given handleType
221 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
224 * @brief Enable or disable clipping.
226 void EnableClipping();
229 * @brief Callback when keyboard is shown/hidden.
231 * @param[in] keyboardShown True if keyboard is shown.
233 void KeyboardStatusChanged( bool keyboardShown );
236 * @brief Callback when TextField is touched
238 * @param[in] actor TextField touched
239 * @param[in] touch Touch information
241 bool OnTouched( Actor actor, const TouchData& touch );
244 * @brief Callbacks called on idle.
246 * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
251 * Construct a new TextField.
256 * A reference counted object may only be deleted by calling Unreference()
258 virtual ~TextField();
260 // Undefined copy constructor and assignment operators
261 TextField(const TextField&);
262 TextField& operator=(const TextField& rhs);
265 * @brief Render view, create and attach actor(s) to this Text Field.
267 void RenderText( Text::Controller::UpdateTextType updateTextType );
269 // Connection needed to re-render text, when a Text Field returns to the stage.
270 void OnStageConnect( Dali::Actor actor );
272 public: // For UTC only
274 Text::ControllerPtr GetTextController() { return mController; }
279 Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
280 Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
281 Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
283 InputMethodContext mInputMethodContext;
284 Text::ControllerPtr mController;
285 Text::RendererPtr mRenderer;
286 Text::DecoratorPtr mDecorator;
287 Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
288 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
289 Dali::InputMethodOptions mInputMethodOptions;
290 Dali::AutofillItem mAutofillItem;
292 Actor mRenderableActor;
294 Actor mBackgroundActor;
295 CallbackBase* mIdleCallback;
297 float mAlignmentOffset;
298 int mRenderingBackend;
300 bool mHasBeenStaged:1;
303 } // namespace Internal
305 // Helpers for public-api forwarding methods
307 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
309 DALI_ASSERT_ALWAYS(textField);
311 Dali::RefObject& handle = textField.GetImplementation();
313 return static_cast<Toolkit::Internal::TextField&>(handle);
316 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
318 DALI_ASSERT_ALWAYS(textField);
320 const Dali::RefObject& handle = textField.GetImplementation();
322 return static_cast<const Toolkit::Internal::TextField&>(handle);
325 } // namespace Toolkit
329 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H