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