Spannable-Core: Add SpannableString and ForegroundColorSpan
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / text / range.h
1 #ifndef DALI_TOOLKIT_TEXT_RANGE_H
2 #define DALI_TOOLKIT_TEXT_RANGE_H
3
4 /*
5  * Copyright (c) 2022 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-toolkit/public-api/dali-toolkit-common.h>
23 #include <dali/public-api/object/base-handle.h>
24
25 namespace Dali
26 {
27 namespace Toolkit
28 {
29 namespace Text
30 {
31 namespace Internal DALI_INTERNAL
32 {
33 class Range;
34 }
35
36 /**
37  * @brief Base structure for different text-spans.
38  * The application can attach and detach spans on range of text for text-controller.
39  * Used to modify text style dynamically at runtime on character level.
40  *
41  * A text-span contains set of attributes of specific style for text.
42  *
43  * To receive a particular text-span, the application has to create span through its builder.
44  *
45  * @note An instance of this class cannot be created.
46  *
47  */
48 class DALI_TOOLKIT_API Range : public BaseHandle
49 {
50 public:
51   /**
52    * @brief Create an initialized range.
53    *
54    * @param[in] startIndex the start index of range (included)
55    * @param[in] endIndex the end index of range (included)
56    *
57    * @return A handle to a newly allocated Dali resource
58    */
59   static Range New(u_int32_t startIndex, u_int32_t endIndex);
60
61   /**
62    * @brief Creates an uninitialized Range handle.
63    *
64    * Calling member functions with an uninitialized Range handle is not allowed.
65    */
66   Range();
67
68   /**
69    * @brief Copy constructor.
70    *
71    * @param[in] rhs A reference to the copied handle
72    */
73   Range(const Range& rhs);
74
75   /**
76    * @brief Move constructor.
77    *
78    * @param[in] rhs A reference to the handle to move
79    */
80   Range(Range&& rhs);
81
82   /**
83    * @brief Assignment operator.
84    *
85    * @param[in] handle A reference to the copied handle
86    * @return A reference to this
87    */
88   Range& operator=(const Range& handle);
89
90   /**
91    * @brief Move assignment operator.
92    *
93    * @param[in] rhs A reference to the handle to move
94    * @return A reference to this handle
95    */
96   Range& operator=(Range&& rhs);
97
98   /**
99    * @brief Non virtual destructor.
100    */
101   ~Range();
102
103 protected:
104   /**
105    * @brief Downcasts to a Range handle.
106    * If handle is not a Range, the returned handle is left uninitialized.
107    *
108    * @param[in] handle Handle to an object
109    * @return Range handle or an uninitialized handle
110    */
111   static Range DownCast(BaseHandle handle);
112
113 public: // Not intended for application developers
114   /// @cond internal
115   /**
116    * @brief Internal constructor.
117    *
118    * @param[in] range Pointer to internal Range
119    */
120   explicit DALI_INTERNAL Range(Internal::Range* range);
121   /// @endcond
122
123 public: //Methods
124         /**
125   * @brief Retrive the start index of range
126   * @return the 32-bit unsigned int.
127   */
128   u_int32_t GetStartIndex() const;
129
130   /**
131   * @brief Retrive the end index of range
132   * @return the 32-bit unsigned int.
133   */
134   u_int32_t GetEndIndex() const;
135
136   /**
137   * @brief Retrive the number of indices of range (endIndex - startIndex +1)
138   * @return the 32-bit unsigned int.
139   */
140   u_int32_t GetNumberOfIndices() const;
141 };
142
143 } // namespace Text
144
145 } // namespace Toolkit
146
147 // Allow Range to be treated as a POD type
148 template<>
149 struct TypeTraits<Dali::Toolkit::Text::Range> : public BasicTypes<Dali::Toolkit::Text::Range>
150 {
151   enum
152   {
153     IS_TRIVIAL_TYPE = true
154   };
155 };
156
157 } // namespace Dali
158
159 #endif // DALI_TOOLKIT_TEXT_RANGE_H