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