Added some TextField boilerplate code
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_LABEL_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/public-api/text/decorator/text-decorator.h>
25 #include <dali-toolkit/public-api/text/text-controller.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 /**
37  * @brief A control which renders a short text string.
38  */
39 class TextField : public Control
40 {
41 public:
42
43   // Properties
44   enum
45   {
46     TEXTFIELD_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
47     TEXTFIELD_PROPERTY_END_INDEX = TEXTFIELD_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
48   };
49
50   /**
51    * @copydoc Dali::Toollkit::TextField::New()
52    */
53   static Toolkit::TextField New();
54
55   /**
56    * @copydoc Dali::Toollkit::TextField::SetRenderer()
57    */
58   void SetRenderer( Text::RendererPtr renderer );
59
60   // Properties
61
62   /**
63    * Called when a property of an object of this type is set.
64    * @param[in] object The object whose property is set.
65    * @param[in] index The property index.
66    * @param[in] value The new property value.
67    */
68   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
69
70   /**
71    * Called to retrieve a property of an object of this type.
72    * @param[in] object The object whose property is to be retrieved.
73    * @param[in] index The property index.
74    * @return The current value of the property.
75    */
76   static Property::Value GetProperty( BaseObject* object, Property::Index index );
77
78 private: // From Control
79
80   /**
81    * @copydoc Control::OnInitialize()
82    */
83   virtual void OnInitialize();
84
85   /**
86    * @copydoc Control::OnInitialize()
87    */
88   virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container );
89
90 private: // Implementation
91
92   /**
93    * Helper for SetProperty.
94    * @param[in] text The new "text" property value.
95    */
96   void SetText( const std::string& text );
97
98   /**
99    * Construct a new TextField.
100    */
101   TextField();
102
103   /**
104    * A reference counted object may only be deleted by calling Unreference()
105    */
106   virtual ~TextField();
107
108 private:
109
110   // Undefined copy constructor and assignment operators
111   TextField(const TextField&);
112   TextField& operator=(const TextField& rhs);
113
114 private: // Data
115
116   Text::ControllerPtr mController;
117   Text::RendererPtr mRenderer;
118   Text::DecoratorPtr mDecorator;
119 };
120
121 } // namespace Internal
122
123 // Helpers for public-api forwarding methods
124
125 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textLabel )
126 {
127   DALI_ASSERT_ALWAYS(textLabel);
128
129   Dali::RefObject& handle = textLabel.GetImplementation();
130
131   return static_cast<Toolkit::Internal::TextField&>(handle);
132 }
133
134 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textLabel )
135 {
136   DALI_ASSERT_ALWAYS(textLabel);
137
138   const Dali::RefObject& handle = textLabel.GetImplementation();
139
140   return static_cast<const Toolkit::Internal::TextField&>(handle);
141 }
142
143 } // namespace Toolkit
144
145 } // namespace Dali
146
147 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H__