[dali_1.9.30] Merge branch 'devel/master'
[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   /**
107    * @brief Called to select the whole texts.
108    */
109   void SelectWholeText();
110
111   /**
112    * @brief Called to unselect the whole texts.
113    */
114   void SelectNone();
115
116 private: // From Control
117
118   /**
119    * @copydoc Control::OnInitialize()
120    */
121   void OnInitialize() override;
122
123   /**
124    * @copydoc Control::OnStyleChange()
125    */
126   void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
127
128   /**
129    * @copydoc Control::GetNaturalSize()
130    */
131   Vector3 GetNaturalSize() override;
132
133   /**
134    * @copydoc Control::GetHeightForWidth()
135    */
136   float GetHeightForWidth( float width ) override;
137
138   /**
139    * @copydoc Control::OnInitialize()
140    */
141   void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
142
143   /**
144    * @copydoc Control::OnKeyInputFocusGained()
145    */
146   void OnKeyInputFocusGained() override;
147
148   /**
149    * @copydoc Control::OnKeyInputFocusLost()
150    */
151   void OnKeyInputFocusLost() override;
152
153   /**
154    * @copydoc Control::OnTap()
155    */
156   void OnTap( const TapGesture& tap ) override;
157
158   /**
159    * @copydoc Control::OnPan()
160    */
161   void OnPan( const PanGesture& gesture ) override;
162
163   /**
164    * @copydoc Control::OnLongPress()
165    */
166   void OnLongPress( const LongPressGesture& gesture ) override;
167
168   /**
169    * @copydoc Control::OnSceneConnection()
170    */
171   void OnSceneConnection( int depth ) override;
172
173   /**
174    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
175    */
176   bool OnKeyEvent(const KeyEvent& event) override;
177
178 // From ControlInterface
179
180   /**
181    * @copydoc Text::ControlInterface::RequestTextRelayout()
182    */
183   void RequestTextRelayout() override;
184
185 // From EditableControlInterface
186
187   /**
188    * @copydoc Text::ControlInterface::TextChanged()
189    */
190   void TextChanged() override;
191
192   /**
193    * @copydoc Text::ControlInterface::MaxLengthReached()
194    */
195   void MaxLengthReached() override;
196
197   /**
198    * @copydoc Text::ControlInterface::InputStyleChanged()
199    */
200   void InputStyleChanged( Text::InputStyle::Mask inputStyleMask ) override;
201
202   /**
203    * @copydoc Text::ControlInterface::AddDecoration()
204    */
205   void AddDecoration( Actor& actor, bool needsClipping ) override;
206
207
208 // From SelectableControlInterface
209 public:
210   /**
211    * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
212    */
213   void SetTextSelectionRange(const uint32_t *start, const uint32_t *end) override;
214
215   /**
216    * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
217    */
218   Uint32Pair GetTextSelectionRange() const override;
219
220 private: // Implementation
221
222   /**
223    * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
224    */
225   InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
226
227   /**
228    * @brief Callback when Clipboard signals an item should be pasted
229    * @param[in] clipboard handle to Clipboard Event Notifier
230    */
231   void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
232
233   /**
234    * @brief Get a Property Map for the image used for the required Handle Image
235    * @param[out] value the returned image property
236    * @param[in] handleType the type of handle
237    * @param[in] handleImageType the type of image for the given handleType
238    */
239   void GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
240
241   /**
242    * @brief Enable or disable clipping.
243    */
244   void EnableClipping();
245
246   /**
247    * @brief Callback when keyboard is shown/hidden.
248    *
249    * @param[in] keyboardShown True if keyboard is shown.
250    */
251   void KeyboardStatusChanged( bool keyboardShown );
252
253   /**
254    * @brief Callback when TextField is touched
255    *
256    * @param[in] actor TextField touched
257    * @param[in] touch Touch information
258    */
259   bool OnTouched( Actor actor, const TouchEvent& touch );
260
261   /**
262    * @brief Callbacks called on idle.
263    *
264    * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
265    */
266   void OnIdleSignal();
267
268   /**
269    * Construct a new TextField.
270    */
271   TextField();
272
273   /**
274    * A reference counted object may only be deleted by calling Unreference()
275    */
276   virtual ~TextField();
277
278   // Undefined copy constructor and assignment operators
279   TextField(const TextField&);
280   TextField& operator=(const TextField& rhs);
281
282   /**
283    * @brief Render view, create and attach actor(s) to this Text Field.
284    */
285   void RenderText( Text::Controller::UpdateTextType updateTextType );
286
287   // Connection needed to re-render text, when a Text Field returns to the scene.
288   void OnSceneConnect( Dali::Actor actor );
289
290 public: // For UTC only
291
292   Text::ControllerPtr GetTextController() { return mController; }
293
294 private: // Data
295
296   // Signals
297   Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
298   Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
299   Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
300
301   InputMethodContext mInputMethodContext;
302   Text::ControllerPtr mController;
303   Text::RendererPtr mRenderer;
304   Text::DecoratorPtr mDecorator;
305   Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
306   std::vector<Actor> mClippingDecorationActors;   ///< Decoration actors which need clipping.
307   Dali::InputMethodOptions mInputMethodOptions;
308
309   Actor mRenderableActor;
310   Actor mActiveLayer;
311   Actor mBackgroundActor;
312   CallbackBase* mIdleCallback;
313
314   float mAlignmentOffset;
315   int mRenderingBackend;
316   int mExceedPolicy;
317   bool mHasBeenStaged:1;
318 };
319
320 } // namespace Internal
321
322 // Helpers for public-api forwarding methods
323
324 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
325 {
326   DALI_ASSERT_ALWAYS(textField);
327
328   Dali::RefObject& handle = textField.GetImplementation();
329
330   return static_cast<Toolkit::Internal::TextField&>(handle);
331 }
332
333 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
334 {
335   DALI_ASSERT_ALWAYS(textField);
336
337   const Dali::RefObject& handle = textField.GetImplementation();
338
339   return static_cast<const Toolkit::Internal::TextField&>(handle);
340 }
341
342 } // namespace Toolkit
343
344 } // namespace Dali
345
346 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H