Spannable-Core: Add SpannableString and ForegroundColorSpan
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / text / spannable.h
1 #ifndef DALI_TOOLKIT_TEXT_SPANNABLE_H
2 #define DALI_TOOLKIT_TEXT_SPANNABLE_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/range.h>
23 #include <dali-toolkit/devel-api/text/spanned.h>
24 #include <dali-toolkit/devel-api/text/spans/base-span.h>
25
26 namespace Dali
27 {
28 namespace Toolkit
29 {
30 namespace Text
31 {
32 namespace Internal DALI_INTERNAL
33 {
34 class Spannable;
35 }
36
37 /**
38  * @brief Interface for text to which spans objects can be attached and detached.
39  * It provides uniform APIs for mutable formatted character sequences.
40  *
41  * @note An instance of this class cannot be created.
42  *
43  */
44 class DALI_TOOLKIT_API Spannable : public Spanned
45 {
46 public:
47   /**
48    * @brief Creates an uninitialized Spannable handle.
49    *
50    * Calling member functions with an uninitialized Spannable handle is not allowed.
51    */
52   Spannable();
53
54   /**
55    * @brief Copy constructor.
56    *
57    * @param[in] rhs A reference to the copied handle
58    */
59   Spannable(const Spannable& rhs);
60
61   /**
62    * @brief Move constructor.
63    *
64    * @param[in] rhs A reference to the handle to move
65    */
66   Spannable(Spannable&& rhs);
67
68   /**
69    * @brief Assignment operator.
70    *
71    * @param[in] handle A reference to the copied handle
72    * @return A reference to this
73    */
74   Spannable& operator=(const Spannable& handle);
75
76   /**
77    * @brief Move assignment operator.
78    *
79    * @param[in] rhs A reference to the handle to move
80    * @return A reference to this handle
81    */
82   Spannable& operator=(Spannable&& rhs);
83
84   /**
85    * @brief Non virtual destructor.
86    */
87   ~Spannable();
88
89 public:
90   /**
91    * @brief Add the given style span on the given range of text.
92    *
93    * @param[in] styleSpan The span of style to apply it on range @p range
94    * @param[in] range The range.
95    *
96    * @return true if the @p range is valid on text. Otherwise false
97    */
98   bool AttachSpan(BaseSpan styleSpan, Range range);
99
100   /**
101    * @brief Remove the given style span on all ranges of text.
102    * checks if @p styleSpan exists, and if it does, it's to be removed.
103    *
104    * @param[in] styleSpan The span of style to remove with ranges.
105    *
106    * @return true if the @p styleSpan was exist and removed. Otherwise false
107    */
108   bool DetachSpan(const BaseSpan& styleSpan);
109
110 protected:
111   /**
112    * @brief Downcasts to a Spannable handle.
113    * If handle is not a Spannable, the returned handle is left uninitialized.
114    *
115    * @param[in] handle Handle to an object
116    * @return Spannable handle or an uninitialized handle
117    */
118   static Spannable DownCast(BaseHandle handle);
119
120 public: // Not intended for application developers
121   /// @cond internal
122   /**
123    * @brief Internal constructor.
124    *
125    * @param[in] spannable Pointer to internal Spannable
126    */
127   explicit DALI_INTERNAL Spannable(Internal::Spannable* spannable);
128   /// @endcond
129 };
130
131 } // namespace Text
132
133 } // namespace Toolkit
134
135 } // namespace Dali
136
137 #endif // DALI_TOOLKIT_TEXT_SPANNABLE_H