Merge "Spannable-Core: Add SpannableString and ForegroundColorSpan" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / spannable / span-ranges-container-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_SPANS_CONTAINER_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_SPANS_CONTAINER_IMPL_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/spans/base-span.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/math/vector4.h>
26 #include <memory>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/internal/text/spannable/spans/base-span-impl.h>
30 #include <dali-toolkit/internal/text/string-text/range-impl.h>
31
32 namespace Dali
33 {
34 namespace Toolkit
35 {
36 namespace Text
37 {
38 namespace Internal
39 {
40 class SpanRangesContainer;
41
42 /**
43  * @brief The container for style spans.
44  * This is to isolate the responsibility of container type from the logic of the spanned text.
45  */
46 class SpanRangesContainer
47 {
48 public:
49   /**
50    * @brief Default constructor.
51    */
52   SpanRangesContainer();
53
54   /**
55    * @brief Virtual destructor.
56    *
57    * A reference counted object may only be deleted by calling Unreference()
58    */
59   ~SpanRangesContainer();
60
61   //Methods
62 public:
63   /**
64    * @brief Add the span to the list of spans.
65    *
66    * @param[in] span The span of style.
67    * @param[in] range The range.
68    *
69    */
70   void AddSpan(const Dali::Toolkit::Text::BaseSpan& span, const Dali::Toolkit::Text::Range& range);
71
72   /**
73    * @brief Remove the span from the list.
74    *
75    * @param[in] span The span of style.
76    *
77    */
78   void RemoveSpan(const Dali::Toolkit::Text::BaseSpan& span);
79
80   /**
81    * @brief Check if a given @p span is in list
82    *
83    * @param[in] span The span of style.
84    *
85    * @return true if the @p span exists. Otherwise false.
86    */
87   bool Contains(const Dali::Toolkit::Text::BaseSpan& span) const;
88
89   /**
90    * @brief Retrieve all spans.
91    *
92    * @param[out] listOfSpans container to clone spans
93    */
94   void GetSpans(std::vector<Dali::Toolkit::Text::BaseSpan>& listOfSpans) const;
95
96   /**
97    * @brief Retrieve all spans and ranges.
98    *
99    * @param[out] spans container to clone spans
100    * @param[out] ranges container to clone ranges
101    */
102   void GetSpansAndRanges(std::vector<Dali::Toolkit::Text::BaseSpan>& spans, std::vector<Dali::Toolkit::Text::Range>& ranges) const;
103
104   // Removed constructors and assignment operators
105 public:                                                                // Constructors
106   SpanRangesContainer(const SpanRangesContainer&) = delete;            ///< Deleted copy constructor
107   SpanRangesContainer(SpanRangesContainer&&)      = delete;            ///< Deleted move constructor
108   SpanRangesContainer& operator=(const SpanRangesContainer&) = delete; ///< Deleted copy assignment operator
109   SpanRangesContainer& operator=(SpanRangesContainer&&) = delete;      ///< Deleted move assignment operator
110
111 private:
112   // Data
113   struct Impl;
114   std::unique_ptr<Impl> mImpl{nullptr};
115
116 }; // class SpanRangesContainer
117
118 } // namespace Internal
119
120 } // namespace Text
121
122 } // namespace Toolkit
123
124 // Allow SpanRangesContainer to be treated as a POD type
125 template<>
126 struct TypeTraits<Dali::Toolkit::Text::Internal::SpanRangesContainer> : public Dali::BasicTypes<Dali::Toolkit::Text::Internal::SpanRangesContainer>
127 {
128   enum
129   {
130     IS_TRIVIAL_TYPE = true
131   };
132 };
133
134 } // namespace Dali
135
136 #endif // DALI_TOOLKIT_INTERNAL_TEXT_SPANS_CONTAINER_IMPL_H