5428275dca1022e4a31c27472a2dcec547c61b1a
[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 // EXTERNAL INCLUDES
22 #include <dali/public-api/adaptor-framework/imf-manager.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/clipping/text-clipper.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-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
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 private: // From Control
75
76   /**
77    * @copydoc Control::OnInitialize()
78    */
79   virtual void OnInitialize();
80
81   /**
82    * @copydoc Control::OnStyleChange()
83    */
84   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change );
85
86   /**
87    * @copydoc Control::GetNaturalSize()
88    */
89   virtual Vector3 GetNaturalSize();
90
91   /**
92    * @copydoc Control::GetHeightForWidth()
93    */
94   virtual float GetHeightForWidth( float width );
95
96   /**
97    * @copydoc Control::OnInitialize()
98    */
99   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
100
101   /**
102    * @copydoc Control::OnKeyInputFocusGained()
103    */
104   virtual void OnKeyInputFocusGained();
105
106   /**
107    * @copydoc Control::OnKeyInputFocusLost()
108    */
109   virtual void OnKeyInputFocusLost();
110
111   /**
112    * @copydoc Control::OnTap()
113    */
114   virtual void OnTap( const TapGesture& tap );
115
116   /**
117    * @copydoc Control::OnPan()
118    */
119   virtual void OnPan( const PanGesture& gesture );
120
121   /**
122    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
123    */
124   virtual bool OnKeyEvent(const KeyEvent& event);
125
126   /**
127    * @brief Event received from IMF manager
128    *
129    * @param[in] imfManager The IMF manager.
130    * @param[in] imfEvent The event received.
131    * @return A data struture indicating if update is needed, cursor position and current text.
132    */
133   ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
134
135   /**
136    * @copydoc Text::ControlInterface::RequestTextRelayout()
137    */
138   virtual void RequestTextRelayout();
139
140 private: // Implementation
141
142   /**
143    * @brief Enable or disable clipping.
144    *
145    * @param[in] clipping True if clipping should be enabled.
146    * @param[in] size The area to clip within.
147    */
148   void EnableClipping( bool clipping, const Vector2& size );
149
150   /**
151    * @brief Callback when keyboard is shown/hidden.
152    *
153    * @param[in] keyboardShown True if keyboard is shown.
154    */
155   void KeyboardStatusChanged( bool keyboardShown );
156
157   /**
158    * Construct a new TextField.
159    */
160   TextField();
161
162   /**
163    * A reference counted object may only be deleted by calling Unreference()
164    */
165   virtual ~TextField();
166
167 private:
168
169   // Undefined copy constructor and assignment operators
170   TextField(const TextField&);
171   TextField& operator=(const TextField& rhs);
172
173 private: // Data
174
175   Text::ControllerPtr mController;
176   Text::RendererPtr mRenderer;
177   Text::DecoratorPtr mDecorator;
178   Text::ClipperPtr mClipper; ///< For EXCEED_POLICY_CLIP
179
180   RenderableActor mRenderableActor;
181
182   int mRenderingBackend;
183   int mExceedPolicy;
184 };
185
186 } // namespace Internal
187
188 // Helpers for public-api forwarding methods
189
190 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
191 {
192   DALI_ASSERT_ALWAYS(textField);
193
194   Dali::RefObject& handle = textField.GetImplementation();
195
196   return static_cast<Toolkit::Internal::TextField&>(handle);
197 }
198
199 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
200 {
201   DALI_ASSERT_ALWAYS(textField);
202
203   const Dali::RefObject& handle = textField.GetImplementation();
204
205   return static_cast<const Toolkit::Internal::TextField&>(handle);
206 }
207
208 } // namespace Toolkit
209
210 } // namespace Dali
211
212 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__