Fix doxygen comments
[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::EditableControlInterface::TextChanged()
189    */
190   void TextChanged() override;
191
192   /**
193    * @copydoc Text::EditableControlInterface::MaxLengthReached()
194    */
195   void MaxLengthReached() override;
196
197   /**
198    * @copydoc Text::EditableControlInterface::InputStyleChanged()
199    */
200   void InputStyleChanged( Text::InputStyle::Mask inputStyleMask ) override;
201
202   /**
203    * @copydoc Text::EditableControlInterface::AddDecoration()
204    */
205   void AddDecoration( Actor& actor, bool needsClipping ) override;
206
207 // From SelectableControlInterface
208 public:
209   /**
210    * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
211    */
212   void SetTextSelectionRange(const uint32_t *start, const uint32_t *end) override;
213
214   /**
215    * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
216    */
217   Uint32Pair GetTextSelectionRange() const override;
218
219   /**
220    * @copydoc Text::EditableControlInterface::IsEditable()
221    */
222   bool IsEditable() const override;
223
224   /**
225    * @copydoc Text::EditableControlInterface::SetEditable()
226    */
227   void SetEditable( bool editable ) override;
228
229 private: // Implementation
230
231   /**
232    * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
233    */
234   InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
235
236   /**
237    * @brief Callback when Clipboard signals an item should be pasted
238    * @param[in] clipboard handle to Clipboard Event Notifier
239    */
240   void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
241
242   /**
243    * @brief Get a Property Map for the image used for the required Handle Image
244    * @param[out] value the returned image property
245    * @param[in] handleType the type of handle
246    * @param[in] handleImageType the type of image for the given handleType
247    */
248   void GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
249
250   /**
251    * @brief Enable or disable clipping.
252    */
253   void EnableClipping();
254
255   /**
256    * @brief Callback when keyboard is shown/hidden.
257    *
258    * @param[in] keyboardShown True if keyboard is shown.
259    */
260   void KeyboardStatusChanged( bool keyboardShown );
261
262   /**
263    * @brief Callback when TextField is touched
264    *
265    * @param[in] actor TextField touched
266    * @param[in] touch Touch information
267    */
268   bool OnTouched( Actor actor, const TouchEvent& touch );
269
270   /**
271    * @brief Callbacks called on idle.
272    *
273    * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
274    */
275   void OnIdleSignal();
276
277   /**
278    * Construct a new TextField.
279    */
280   TextField();
281
282   /**
283    * A reference counted object may only be deleted by calling Unreference()
284    */
285   virtual ~TextField();
286
287   // Undefined copy constructor and assignment operators
288   TextField(const TextField&);
289   TextField& operator=(const TextField& rhs);
290
291   /**
292    * @brief Render view, create and attach actor(s) to this Text Field.
293    */
294   void RenderText( Text::Controller::UpdateTextType updateTextType );
295
296   // Connection needed to re-render text, when a Text Field returns to the scene.
297   void OnSceneConnect( Dali::Actor actor );
298
299 public: // For UTC only
300
301   Text::ControllerPtr GetTextController() { return mController; }
302
303 private: // Data
304
305   // Signals
306   Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
307   Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
308   Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
309
310   InputMethodContext mInputMethodContext;
311   Text::ControllerPtr mController;
312   Text::RendererPtr mRenderer;
313   Text::DecoratorPtr mDecorator;
314   Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
315   std::vector<Actor> mClippingDecorationActors;   ///< Decoration actors which need clipping.
316   Dali::InputMethodOptions mInputMethodOptions;
317
318   Actor mRenderableActor;
319   Actor mActiveLayer;
320   Actor mBackgroundActor;
321   CallbackBase* mIdleCallback;
322
323   float mAlignmentOffset;
324   int mRenderingBackend;
325   int mExceedPolicy;
326   bool mHasBeenStaged:1;
327 };
328
329 } // namespace Internal
330
331 // Helpers for public-api forwarding methods
332
333 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
334 {
335   DALI_ASSERT_ALWAYS(textField);
336
337   Dali::RefObject& handle = textField.GetImplementation();
338
339   return static_cast<Toolkit::Internal::TextField&>(handle);
340 }
341
342 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
343 {
344   DALI_ASSERT_ALWAYS(textField);
345
346   const Dali::RefObject& handle = textField.GetImplementation();
347
348   return static_cast<const Toolkit::Internal::TextField&>(handle);
349 }
350
351 } // namespace Toolkit
352
353 } // namespace Dali
354
355 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H