[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-anchor-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_ANCHOR_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_ANCHOR_H
3
4 /*
5  * Copyright (c) 2021 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/devel-api/atspi-interfaces/hyperlink.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/devel-api/controls/text-controls/text-anchor-devel.h>
26 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
27 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 namespace Internal
35 {
36 /**
37  * @brief A control which renders anchor (hyperlink) in hypertext.
38  */
39 class TextAnchor : public Control
40 {
41 public:
42   /**
43    * @copydoc Dali::Toollkit::TextAnchor::New()
44    */
45   static Toolkit::TextAnchor New();
46
47   // Properties
48
49   /**
50    * @brief Called when a property of an object of this type is set.
51    *
52    * @param[in] object The object whose property is set.
53    * @param[in] index The property index.
54    * @param[in] value The new property value.
55    */
56   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
57
58   /**
59    * @brief Called to retrieve a property of an object of this type.
60    *
61    * @param[in] object The object whose property is to be retrieved.
62    * @param[in] index The property index.
63    * @return The current value of the property.
64    */
65   static Property::Value GetProperty(BaseObject* object, Property::Index index);
66
67 private: // From Control
68   /**
69    * @copydoc Control::OnInitialize()
70    */
71   void OnInitialize() override;
72
73   /**
74    * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
75    */
76   DevelControl::ControlAccessible* CreateAccessibleObject() override;
77
78   /**
79    * @copydoc Control::OnPropertySet()
80    */
81   // void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
82
83   /**
84    * @copydoc Control::OnAccessibilityActivated()
85    */
86   bool OnAccessibilityActivated() override;
87
88 private: // Implementation
89   /**
90    * Construct a new TextAnchor.
91    */
92   TextAnchor();
93
94   /**
95    * A reference counted object may only be deleted by calling Unreference()
96    */
97   virtual ~TextAnchor();
98
99 private:
100   // Undefined copy constructor and assignment operators
101   TextAnchor(const TextAnchor&);
102   TextAnchor& operator=(const TextAnchor& rhs);
103
104   //Data
105   int         mStartCharacterIndex;
106   int         mEndCharacterIndex;
107   std::string mUri;
108
109 protected:
110   /**
111    * @brief This structure is to connect TextAnchor with Accessible functions.
112    */
113   class TextAnchorAccessible : public DevelControl::ControlAccessible,
114                                public virtual Dali::Accessibility::Hyperlink
115   {
116   public:
117     using DevelControl::ControlAccessible::ControlAccessible;
118
119     /**
120      * @copydoc Dali::Accessibility::Hyperlink::GetEndIndex()
121      */
122     int32_t GetEndIndex() const override;
123
124     /**
125      * @copydoc Dali::Accessibility::Hyperlink::GetStartIndex()
126      */
127     int32_t GetStartIndex() const override;
128
129     /**
130      * @copydoc Dali::Accessibility::Hyperlink::GetAnchorCount()
131      */
132     int32_t GetAnchorCount() const override;
133
134     /**
135      * @copydoc Dali::Accessibility::Hyperlink::GetAnchorAccessible()
136      */
137     Accessible* GetAnchorAccessible(int32_t anchorIndex) const override;
138
139     /**
140      * @copydoc Dali::Accessibility::Hyperlink::GetAnchorUri()
141      */
142     std::string GetAnchorUri(int32_t anchorIndex) const override;
143
144     /**
145      * @copydoc Dali::Accessibility::Hyperlink::IsValid()
146      */
147     bool IsValid() const override;
148   };
149 };
150
151 inline Toolkit::Internal::TextAnchor& GetImpl(Toolkit::TextAnchor& textAnchor)
152 {
153   DALI_ASSERT_ALWAYS(textAnchor);
154
155   Dali::RefObject& handle = textAnchor.GetImplementation();
156
157   return static_cast<Toolkit::Internal::TextAnchor&>(handle);
158 }
159
160 inline const Toolkit::Internal::TextAnchor& GetImpl(const Toolkit::TextAnchor& textAnchor)
161 {
162   DALI_ASSERT_ALWAYS(textAnchor);
163
164   const Dali::RefObject& handle = textAnchor.GetImplementation();
165
166   return static_cast<const Toolkit::Internal::TextAnchor&>(handle);
167 }
168
169 } // namespace Internal
170
171 } // namespace Toolkit
172
173 } // namespace Dali
174
175 #endif // DALI_TOOLKIT_INTERNAL_TEXT_ANCHOR_H