Merge "Changes for std::vector removal from api" into tizen
[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) 2015 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
24 #include <dali-toolkit/internal/text/clipping/text-clipper.h>
25 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
26 #include <dali-toolkit/internal/text/text-control-interface.h>
27 #include <dali-toolkit/internal/text/text-controller.h>
28 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 /**
40  * @brief A control which renders a short text string.
41  */
42 class TextField : public Control, public Text::ControlInterface
43 {
44 public:
45
46   /**
47    * @copydoc Dali::Toollkit::TextField::New()
48    */
49   static Toolkit::TextField New();
50
51   // Properties
52
53   /**
54    * @brief Called when a property of an object of this type is set.
55    *
56    * @param[in] object The object whose property is set.
57    * @param[in] index The property index.
58    * @param[in] value The new property value.
59    */
60   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
61
62   /**
63    * @brief Called to retrieve a property of an object of this type.
64    *
65    * @param[in] object The object whose property is to be retrieved.
66    * @param[in] index The property index.
67    * @return The current value of the property.
68    */
69   static Property::Value GetProperty( BaseObject* object, Property::Index index );
70
71   /**
72    * Connects a callback function with the object's signals.
73    * @param[in] object The object providing the signal.
74    * @param[in] tracker Used to disconnect the signal.
75    * @param[in] signalName The signal to connect to.
76    * @param[in] functor A newly allocated FunctorDelegate.
77    * @return True if the signal was connected.
78    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
79    */
80   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
81
82   /**
83    * @copydoc TextField::MaxLengthReachedSignal()
84    */
85   Toolkit::TextField::MaxLengthReachedSignalType&  MaxLengthReachedSignal();
86
87 private: // From Control
88
89   /**
90    * @copydoc Control::OnInitialize()
91    */
92   virtual void OnInitialize();
93
94   /**
95    * @copydoc Control::OnStyleChange()
96    */
97   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
98
99   /**
100    * @copydoc Control::GetNaturalSize()
101    */
102   virtual Vector3 GetNaturalSize();
103
104   /**
105    * @copydoc Control::GetHeightForWidth()
106    */
107   virtual float GetHeightForWidth( float width );
108
109   /**
110    * @copydoc Control::OnInitialize()
111    */
112   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
113
114   /**
115    * @copydoc Control::OnKeyInputFocusGained()
116    */
117   virtual void OnKeyInputFocusGained();
118
119   /**
120    * @copydoc Control::OnKeyInputFocusLost()
121    */
122   virtual void OnKeyInputFocusLost();
123
124   /**
125    * @copydoc Control::OnTap()
126    */
127   virtual void OnTap( const TapGesture& tap );
128
129   /**
130    * @copydoc Control::OnPan()
131    */
132   virtual void OnPan( const PanGesture& gesture );
133
134   /**
135    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
136    */
137   virtual bool OnKeyEvent(const KeyEvent& event);
138
139   /**
140    * @copydoc Dali::Toolkit::Text::Controller::(ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent)
141    */
142   ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
143
144   /**
145    * @copydoc Text::ControlInterface::RequestTextRelayout()
146    */
147   virtual void RequestTextRelayout();
148
149   /**
150    * @copydoc Text::ControlInterface::MaxLengthReached()
151    */
152   virtual void MaxLengthReached();
153
154 private: // Implementation
155
156   /**
157    * @brief Enable or disable clipping.
158    *
159    * @param[in] clipping True if clipping should be enabled.
160    * @param[in] size The area to clip within.
161    */
162   void EnableClipping( bool clipping, const Vector2& size );
163
164   /**
165    * @brief Callback when keyboard is shown/hidden.
166    *
167    * @param[in] keyboardShown True if keyboard is shown.
168    */
169   void KeyboardStatusChanged( bool keyboardShown );
170
171   /**
172    * @brief Callback when Textfield is touched
173    *
174    * @param[in] actor TextField touched
175    * @param[in] event TouchEvent information
176    */
177   bool OnTouched( Actor actor, const TouchEvent& event );
178
179   /**
180    * Construct a new TextField.
181    */
182   TextField();
183
184   /**
185    * A reference counted object may only be deleted by calling Unreference()
186    */
187   virtual ~TextField();
188
189   // Undefined copy constructor and assignment operators
190   TextField(const TextField&);
191   TextField& operator=(const TextField& rhs);
192
193 private: // Data
194
195   // Signals
196   Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
197
198   Text::ControllerPtr mController;
199   Text::RendererPtr mRenderer;
200   Text::DecoratorPtr mDecorator;
201   Text::ClipperPtr mClipper; ///< For EXCEED_POLICY_CLIP
202
203   RenderableActor mRenderableActor;
204
205   int mRenderingBackend;
206   int mExceedPolicy;
207 };
208
209 } // namespace Internal
210
211 // Helpers for public-api forwarding methods
212
213 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
214 {
215   DALI_ASSERT_ALWAYS(textField);
216
217   Dali::RefObject& handle = textField.GetImplementation();
218
219   return static_cast<Toolkit::Internal::TextField&>(handle);
220 }
221
222 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
223 {
224   DALI_ASSERT_ALWAYS(textField);
225
226   const Dali::RefObject& handle = textField.GetImplementation();
227
228   return static_cast<const Toolkit::Internal::TextField&>(handle);
229 }
230
231 } // namespace Toolkit
232
233 } // namespace Dali
234
235 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__