[Tizen] Add parameter (bool immediate) to TextChanged signal in interface
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/autofill-item.h>
23 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
24 #include <dali/devel-api/adaptor-framework/input-method-context.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
28 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
29 #include <dali-toolkit/internal/text/text-control-interface.h>
30 #include <dali-toolkit/internal/text/text-controller.h>
31 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
32 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
33 #include <dali-toolkit/public-api/controls/control-impl.h>
34 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
35
36 namespace Dali
37 {
38 namespace Toolkit
39 {
40 namespace Internal
41 {
42 /**
43  * @brief A control which renders a short text string.
44  */
45 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
46 {
47 public:
48   /**
49    * @copydoc Dali::Toollkit::TextField::New()
50    */
51   static Toolkit::TextField New();
52
53   // Properties
54
55   /**
56    * @brief Called when a property of an object of this type is set.
57    *
58    * @param[in] object The object whose property is set.
59    * @param[in] index The property index.
60    * @param[in] value The new property value.
61    */
62   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
63
64   /**
65    * @brief Called to retrieve a property of an object of this type.
66    *
67    * @param[in] object The object whose property is to be retrieved.
68    * @param[in] index The property index.
69    * @return The current value of the property.
70    */
71   static Property::Value GetProperty(BaseObject* object, Property::Index index);
72
73   /**
74    * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
75    */
76   InputMethodContext GetInputMethodContext();
77
78   /**
79    * Connects a callback function with the object's signals.
80    * @param[in] object The object providing the signal.
81    * @param[in] tracker Used to disconnect the signal.
82    * @param[in] signalName The signal to connect to.
83    * @param[in] functor A newly allocated FunctorDelegate.
84    * @return True if the signal was connected.
85    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
86    */
87   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
88
89   /**
90    * @copydoc TextField::TextChangedSignal()
91    */
92   Toolkit::TextField::TextChangedSignalType& TextChangedSignal();
93
94   /**
95    * @copydoc TextField::MaxLengthReachedSignal()
96    */
97   Toolkit::TextField::MaxLengthReachedSignalType& MaxLengthReachedSignal();
98
99   /**
100    * @copydoc TextField::TextChangedSignal()
101    */
102   Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
103
104 private: // From Control
105   /**
106    * @copydoc Control::OnInitialize()
107    */
108   void OnInitialize() override;
109
110   /**
111    * @copydoc Control::OnStyleChange()
112    */
113   void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
114
115   /**
116    * @copydoc Control::GetNaturalSize()
117    */
118   Vector3 GetNaturalSize() override;
119
120   /**
121    * @copydoc Control::GetHeightForWidth()
122    */
123   float GetHeightForWidth(float width) override;
124
125   /**
126    * @copydoc Control::OnInitialize()
127    */
128   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
129
130   /**
131    * @copydoc Control::OnKeyInputFocusGained()
132    */
133   void OnKeyInputFocusGained() override;
134
135   /**
136    * @copydoc Control::OnKeyInputFocusLost()
137    */
138   void OnKeyInputFocusLost() override;
139
140   /**
141    * @copydoc Control::OnTap()
142    */
143   void OnTap(const TapGesture& tap) override;
144
145   /**
146    * @copydoc Control::OnPan()
147    */
148   void OnPan(const PanGesture& gesture) override;
149
150   /**
151    * @copydoc Control::OnLongPress()
152    */
153   void OnLongPress(const LongPressGesture& gesture) override;
154
155   /**
156    * @copydoc Control::OnSceneConnection()
157    */
158   void OnSceneConnection(int depth) override;
159
160   /**
161    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
162    */
163   bool OnKeyEvent(const KeyEvent& event) override;
164
165   // From ControlInterface
166
167   /**
168    * @copydoc Text::ControlInterface::RequestTextRelayout()
169    */
170   void RequestTextRelayout() override;
171
172   // From EditableControlInterface
173
174   /**
175    * @copydoc Text::EditableControlInterface::TextChanged()
176    */
177   void TextChanged(bool immediate) override;
178
179   /**
180    * @copydoc Text::EditableControlInterface::MaxLengthReached()
181    */
182   void MaxLengthReached() override;
183
184   /**
185    * @copydoc Text::EditableControlInterface::InputStyleChanged()
186    */
187   void InputStyleChanged(Text::InputStyle::Mask inputStyleMask) override;
188
189   /**
190    * @copydoc Text::EditableControlInterface::AddDecoration()
191    */
192   void AddDecoration(Actor& actor, bool needsClipping) override;
193
194   // From SelectableControlInterface
195 public:
196   /**
197    * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
198    */
199   void SetTextSelectionRange(const uint32_t* start, const uint32_t* end) override;
200
201   /**
202    * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
203    */
204   Uint32Pair GetTextSelectionRange() const override;
205
206   /**
207    * @copydoc Text::SelectableControlInterface::SelectWholeText()
208    */
209   void SelectWholeText() override;
210
211   /**
212    * @copydoc Text::SelectableControlInterface::SelectNone()
213    */
214   void SelectNone() override;
215
216   /**
217    * @copydoc Text::SelectableControlInterface::GetSelectedText()
218    */
219   string GetSelectedText() const override;
220
221   /**
222    * @copydoc Text::EditableControlInterface::IsEditable()
223    */
224   bool IsEditable() const override;
225
226   /**
227    * @copydoc Text::EditableControlInterface::SetEditable()
228    */
229   void SetEditable(bool editable) override;
230
231 private: // Implementation
232   /**
233    * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
234    */
235   InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
236
237   /**
238    * @brief Callback when Clipboard signals an item should be pasted
239    * @param[in] clipboard handle to Clipboard Event Notifier
240    */
241   void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
242
243   /**
244    * @brief Get a Property Map for the image used for the required Handle Image
245    * @param[out] value the returned image property
246    * @param[in] handleType the type of handle
247    * @param[in] handleImageType the type of image for the given handleType
248    */
249   void GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType);
250
251   /**
252    * @brief Enable or disable clipping.
253    */
254   void EnableClipping();
255
256   /**
257    * @brief Callback when keyboard is shown/hidden.
258    *
259    * @param[in] keyboardShown True if keyboard is shown.
260    */
261   void KeyboardStatusChanged(bool keyboardShown);
262
263   /**
264    * @brief Callback when TextField is touched
265    *
266    * @param[in] actor TextField touched
267    * @param[in] touch Touch information
268    */
269   bool OnTouched(Actor actor, const TouchEvent& touch);
270
271   /**
272    * @brief Callbacks called on idle.
273    *
274    * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
275    */
276   void OnIdleSignal();
277
278   /**
279    * @brief Emits TextChanged signal.
280    */
281   void EmitTextChangedSignal();
282
283   /**
284    * Construct a new TextField.
285    */
286   TextField();
287
288   /**
289    * A reference counted object may only be deleted by calling Unreference()
290    */
291   virtual ~TextField();
292
293   // Undefined copy constructor and assignment operators
294   TextField(const TextField&);
295   TextField& operator=(const TextField& rhs);
296
297   /**
298    * @brief Render view, create and attach actor(s) to this Text Field.
299    */
300   void RenderText(Text::Controller::UpdateTextType updateTextType);
301
302   // Connection needed to re-render text, when a Text Field returns to the scene.
303   void OnSceneConnect(Dali::Actor actor);
304
305 public: // For UTC only
306   Text::ControllerPtr GetTextController()
307   {
308     return mController;
309   }
310
311 private: // Data
312   // Signals
313   Toolkit::TextField::TextChangedSignalType       mTextChangedSignal;
314   Toolkit::TextField::MaxLengthReachedSignalType  mMaxLengthReachedSignal;
315   Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
316
317   InputMethodContext       mInputMethodContext;
318   Text::ControllerPtr      mController;
319   Text::RendererPtr        mRenderer;
320   Text::DecoratorPtr       mDecorator;
321   Toolkit::Control         mStencil;                  ///< For EXCEED_POLICY_CLIP
322   std::vector<Actor>       mClippingDecorationActors; ///< Decoration actors which need clipping.
323   Dali::InputMethodOptions mInputMethodOptions;
324   Dali::AutofillItem       mAutofillItem;
325
326   Actor         mRenderableActor;
327   Actor         mActiveLayer;
328   Actor         mBackgroundActor;
329   CallbackBase* mIdleCallback;
330
331   float mAlignmentOffset;
332   int   mRenderingBackend;
333   int   mExceedPolicy;
334   bool  mHasBeenStaged : 1;
335   bool  mTextChanged : 1; ///< If true, emits TextChangedSignal in next OnRelayout().
336 };
337
338 } // namespace Internal
339
340 // Helpers for public-api forwarding methods
341
342 inline Toolkit::Internal::TextField& GetImpl(Toolkit::TextField& textField)
343 {
344   DALI_ASSERT_ALWAYS(textField);
345
346   Dali::RefObject& handle = textField.GetImplementation();
347
348   return static_cast<Toolkit::Internal::TextField&>(handle);
349 }
350
351 inline const Toolkit::Internal::TextField& GetImpl(const Toolkit::TextField& textField)
352 {
353   DALI_ASSERT_ALWAYS(textField);
354
355   const Dali::RefObject& handle = textField.GetImplementation();
356
357   return static_cast<const Toolkit::Internal::TextField&>(handle);
358 }
359
360 } // namespace Toolkit
361
362 } // namespace Dali
363
364 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H