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