Spannable-Core: Add SpannableString and ForegroundColorSpan
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / spannable / spannable-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_SPANNABLE_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_SPANNABLE_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/spannable.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/spannable/spanned-impl.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 namespace Text
32 {
33 namespace Internal
34 {
35 class Spannable;
36
37 typedef IntrusivePtr<Spannable> SpannablePtr;
38 typedef const Spannable*        SpannableConstPtr;
39
40 /**
41  * @copydoc Dali::Toolkit::Text::Spannable
42  */
43 class Spannable : public Spanned
44 {
45 public:
46   /**
47    * This constructor is only used by derived classes.
48    */
49   Spannable();
50
51   /**
52    * @brief Virtual destructor.
53    *
54    * A reference counted object may only be deleted by calling Unreference()
55    */
56   virtual ~Spannable() = 0;
57
58   // Removed constructors and assignment operators
59 public:
60   Spannable(const Spannable&) = delete;            ///< Deleted copy constructor
61   Spannable(Spannable&&)      = delete;            ///< Deleted move constructor
62   Spannable& operator=(const Spannable&) = delete; ///< Deleted copy assignment operator
63   Spannable& operator=(Spannable&&) = delete;      ///< Deleted move assignment operator
64
65 public: //Methods
66   /**
67    * @copydoc Dali::Toolkit::Text::Spannable::AttachSpan()
68    */
69   virtual bool AttachSpan(const Dali::Toolkit::Text::BaseSpan& styleSpan, const Dali::Toolkit::Text::Range& range) = 0;
70
71   /**
72    * @copydoc Dali::Toolkit::Text::Spannable::DetachSpan()
73    */
74   virtual bool DetachSpan(const Dali::Toolkit::Text::BaseSpan& styleSpan) = 0;
75
76 }; // class Spannable
77
78 } // namespace Internal
79
80 /**
81  * Helper methods for public API.
82  */
83 inline Internal::Spannable& GetImplementation(Dali::Toolkit::Text::Spannable& spannable)
84 {
85   DALI_ASSERT_ALWAYS(spannable && "spannable handle is empty");
86
87   BaseObject& handle = spannable.GetBaseObject();
88
89   return static_cast<Internal::Spannable&>(handle);
90 }
91
92 inline const Internal::Spannable& GetImplementation(const Dali::Toolkit::Text::Spannable& spannable)
93 {
94   DALI_ASSERT_ALWAYS(spannable && "spannable handle is empty");
95
96   const BaseObject& handle = spannable.GetBaseObject();
97
98   return static_cast<const Internal::Spannable&>(handle);
99 }
100
101 } // namespace Text
102
103 } // namespace Toolkit
104
105 // Allow Spannable to be treated as a POD type
106 template<>
107 struct TypeTraits<Dali::Toolkit::Text::Internal::Spannable> : public Dali::BasicTypes<Dali::Toolkit::Text::Internal::Spannable>
108 {
109   enum
110   {
111     IS_TRIVIAL_TYPE = true
112   };
113 };
114
115 } // namespace Dali
116
117 #endif // DALI_TOOLKIT_INTERNAL_TEXT_SPANNABLE_IMPL_H