Spannable-Core: Add SpannableString and ForegroundColorSpan
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / text / spannable-string.h
1 #ifndef DALI_TOOLKIT_TEXT_SPANNABLE_STRING_H
2 #define DALI_TOOLKIT_TEXT_SPANNABLE_STRING_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/devel-api/text/spannable.h>
23 #include <string>
24
25 namespace Dali
26 {
27 namespace Toolkit
28 {
29 namespace Text
30 {
31 namespace Internal DALI_INTERNAL
32 {
33 class SpannableString;
34 }
35
36 /**
37  * @brief Interface for text that has spans objects attached to ranges of it.
38  * It provides uniform APIs for read-only access to many different kinds of formatted character sequences.
39  *
40  * @note An instance of this class cannot be created.
41  *
42  */
43 class DALI_TOOLKIT_API SpannableString : public Spannable
44 {
45 public:
46   /**
47    * @brief Create an initialized SpannableString.
48    *
49    * @param[in] text the text to be formatted
50    *
51    * @return A handle to a newly allocated Dali resource
52    */
53   static SpannableString New(const std::string& text);
54
55   /**
56    * @brief Creates an uninitialized SpannableString handle.
57    *
58    * Calling member functions with an uninitialized SpannableString handle is not allowed.
59    */
60   SpannableString();
61
62   /**
63    * @brief Copy constructor.
64    *
65    * @param[in] rhs A reference to the copied handle
66    */
67   SpannableString(const SpannableString& rhs);
68
69   /**
70    * @brief Move constructor.
71    *
72    * @param[in] rhs A reference to the handle to move
73    */
74   SpannableString(SpannableString&& rhs);
75
76   /**
77    * @brief Assignment operator.
78    *
79    * @param[in] handle A reference to the copied handle
80    * @return A reference to this
81    */
82   SpannableString& operator=(const SpannableString& handle);
83
84   /**
85    * @brief Move assignment operator.
86    *
87    * @param[in] rhs A reference to the handle to move
88    * @return A reference to this handle
89    */
90   SpannableString& operator=(SpannableString&& rhs);
91
92   /**
93    * @brief Non virtual destructor.
94    */
95   ~SpannableString();
96
97 protected:
98   /**
99    * @brief Downcasts to a SpannableString handle.
100    * If handle is not a SpannableString, the returned handle is left uninitialized.
101    *
102    * @param[in] handle Handle to an object
103    * @return SpannableString handle or an uninitialized handle
104    */
105   static SpannableString DownCast(BaseHandle handle);
106
107 public: // Not intended for application developers
108   /// @cond internal
109   /**
110    * @brief Internal constructor.
111    *
112    * @param[in] spannableString Pointer to internal SpannableString
113    */
114   explicit DALI_INTERNAL SpannableString(Internal::SpannableString* spannableString);
115   /// @endcond
116 };
117
118 } // namespace Text
119
120 } // namespace Toolkit
121
122 } // namespace Dali
123
124 #endif // DALI_TOOLKIT_TEXT_SPANNABLE_STRING_H