[Tizen](ATSPI) squashed implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
3
4 /*
5  * Copyright (c) 2017 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/object/property-map.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-label.h>
27 #include <dali-toolkit/internal/text/text-control-interface.h>
28 #include <dali-toolkit/internal/text/text-controller.h>
29 #include <dali-toolkit/internal/text/text-scroller-interface.h>
30 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
31 #include <dali-toolkit/internal/text/text-scroller.h>
32 #include <dali-toolkit/internal/visuals/text/text-visual.h>
33 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
34
35
36 namespace Dali
37 {
38
39 namespace Toolkit
40 {
41
42 namespace Internal
43 {
44
45 /**
46  * @brief A control which renders a short text string.
47  */
48 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface
49 {
50 public:
51
52   /**
53    * @copydoc Dali::Toollkit::TextLabel::New()
54    */
55   static Toolkit::TextLabel New();
56
57   // Properties
58
59   /**
60    * @brief Called when a property of an object of this type is set.
61    *
62    * @param[in] object The object whose property is set.
63    * @param[in] index The property index.
64    * @param[in] value The new property value.
65    */
66   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
67
68   /**
69    * @brief Called to retrieve a property of an object of this type.
70    *
71    * @param[in] object The object whose property is to be retrieved.
72    * @param[in] index The property index.
73    * @return The current value of the property.
74    */
75   static Property::Value GetProperty( BaseObject* object, Property::Index index );
76
77   Text::ControllerPtr getController();
78
79 private: // From Control
80
81   /**
82    * @copydoc Control::OnInitialize()
83    */
84   virtual void OnInitialize() override ;
85
86   /**
87    * @copydoc Control::OnStyleChange()
88    */
89   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override ;
90
91   /**
92    * @copydoc Control::OnRelayout()
93    */
94   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) override ;
95
96   /**
97    * @copydoc Control::GetNaturalSize()
98    */
99   virtual Vector3 GetNaturalSize() override ;
100
101   /**
102    * @copydoc Control::GetHeightForWidth()
103    */
104   virtual float GetHeightForWidth( float width ) override ;
105
106   /**
107    * @copydoc Control::OnPropertySet()
108    */
109   virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) override ;
110
111   // From ControlInterface
112
113   /**
114    * @copydoc Text::ControlInterface::RequestTextRelayout()
115    */
116   virtual void RequestTextRelayout() override ;
117
118 private: // from TextScroller
119
120   /**
121    * @copydoc Text::ScrollerInterface::ScrollingFinished()
122    */
123   virtual void ScrollingFinished();
124
125 private: // Implementation
126
127   /**
128    * Construct a new TextLabel.
129    */
130   TextLabel();
131
132   /**
133    * A reference counted object may only be deleted by calling Unreference()
134    */
135   virtual ~TextLabel();
136
137 private:
138
139   // Undefined copy constructor and assignment operators
140   TextLabel(const TextLabel&);
141   TextLabel& operator=(const TextLabel& rhs);
142
143   /**
144    * @brief Set up Autoscrolling
145    */
146   void SetUpAutoScrolling();
147
148 private: // Data
149
150   Text::ControllerPtr mController;
151   Text::TextScrollerPtr mTextScroller;
152
153   Toolkit::Visual::Base mVisual;
154
155   int mRenderingBackend;
156   bool mTextUpdateNeeded:1;
157
158 protected:
159   struct AccessibleImpl : public Control::Impl::AccessibleImpl,
160                           public virtual Dali::Accessibility::Text
161   {
162     using Control::Impl::AccessibleImpl::AccessibleImpl;
163
164     std::string GetText( size_t startOffset, size_t endOffset ) override;
165     size_t GetCharacterCount() override;
166     size_t GetCaretOffset() override;
167     bool SetCaretOffset(size_t offset) override;
168     Dali::Accessibility::Range
169     GetTextAtOffset( size_t offset,
170                      Dali::Accessibility::TextBoundary boundary ) override;
171     Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
172     bool RemoveSelection( size_t selectionNum ) override;
173     bool SetSelection( size_t selectionNum, size_t startOffset,
174                        size_t endOffset ) override;
175     std::string GetNameRaw() override;
176   };
177 };
178
179 } // namespace Internal
180
181 // Helpers for public-api forwarding methods
182
183 inline Toolkit::Internal::TextLabel& GetImpl( Toolkit::TextLabel& textLabel )
184 {
185   DALI_ASSERT_ALWAYS(textLabel);
186
187   Dali::RefObject& handle = textLabel.GetImplementation();
188
189   return static_cast<Toolkit::Internal::TextLabel&>(handle);
190 }
191
192 inline const Toolkit::Internal::TextLabel& GetImpl( const Toolkit::TextLabel& textLabel )
193 {
194   DALI_ASSERT_ALWAYS(textLabel);
195
196   const Dali::RefObject& handle = textLabel.GetImplementation();
197
198   return static_cast<const Toolkit::Internal::TextLabel&>(handle);
199 }
200
201 } // namespace Toolkit
202
203 } // namespace Dali
204
205 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H