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