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