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