Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / FGrpTextElement.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19 * @file                 FGrpTextElement.cpp
20 * @brief                This is the cpp file for TextElement class.
21 */
22
23 #include <new>
24
25 #include <FGrpTextElement.h>
26 #include <FBaseString.h>
27 #include <FGrpFont.h>
28
29 #include <FBaseSysLog.h>
30
31 #include "FGrp_TextElementImpl.h"
32 #include "FGrp_ResUtil.h"
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Base::Utility;
37
38 #define CHECK_NOT_CONSTRUCTED \
39         SysTryReturnResult(NID_GRP, this->__pImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Fails to allocate memory.") \
40         SysAssertf(!this->__pImpl->IsConstructed(), \
41                 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
42
43 #define CHECK_CONSTRUCTED \
44         SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
45                 "Not yet constructed! Construct() should be called before use.");
46
47 #define CHECK_CONSTRUCTED_EX(_result) \
48         SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
49                 "Not yet constructed! Construct() should be called before use.");
50
51 namespace Tizen { namespace Graphics
52 {
53
54 TextElement::TextElement()
55 {
56         __pImpl = new (std::nothrow) _TextElementImpl;
57 }
58
59 TextElement::~TextElement()
60 {
61         if (__pImpl)
62         {
63                 delete __pImpl;
64                 __pImpl = null;
65         }
66 }
67
68 result
69 TextElement::Construct(const Tizen::Base::String& text)
70 {
71         CHECK_NOT_CONSTRUCTED;
72
73         result r = __pImpl->Construct(text);
74         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
75
76         return E_SUCCESS;
77 }
78
79 result
80 TextElement::Construct(const Tizen::Base::String& text, const Tizen::Graphics::Canvas& canvas)
81 {
82         CHECK_NOT_CONSTRUCTED;
83
84         result r = __pImpl->Construct(text, canvas);
85         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
86
87         return E_SUCCESS;
88 }
89
90 result
91 TextElement::Construct(void)
92 {
93         CHECK_NOT_CONSTRUCTED;
94
95         result r = __pImpl->Construct();
96         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
97
98         return E_SUCCESS;
99 }
100
101 result
102 TextElement::Construct(const Tizen::Base::String& text, Tizen::Base::Utility::LinkType linkType, const Tizen::Base::String& link)
103 {
104         CHECK_NOT_CONSTRUCTED;
105
106         result r = __pImpl->Construct(text, linkType, link);
107         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
108
109         return E_SUCCESS;
110 }
111
112 result
113 TextElement::Construct(const Tizen::Base::String& text, unsigned long autoLink)
114 {
115         CHECK_NOT_CONSTRUCTED;
116
117         result r = __pImpl->Construct(text, autoLink);
118         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
119
120         return E_SUCCESS;
121 }
122
123 result
124 TextElement::Construct(const Tizen::Base::String& text, Tizen::Base::Utility::LinkType linkType, const Tizen::Base::String& link,
125                                            const Tizen::Graphics::Canvas& canvas)
126 {
127         CHECK_NOT_CONSTRUCTED;
128
129         result r = __pImpl->Construct(text, linkType, link, canvas);
130         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
131
132         return E_SUCCESS;
133 }
134
135 result
136 TextElement::Construct(const Tizen::Base::String& text, unsigned long autoLink, const Tizen::Graphics::Canvas& canvas)
137 {
138         CHECK_NOT_CONSTRUCTED;
139
140         result r = __pImpl->Construct(text, autoLink, canvas);
141         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
142
143         return E_SUCCESS;
144 }
145
146 Tizen::Base::String
147 TextElement::GetLink(void) const
148 {
149         CHECK_CONSTRUCTED_EX(String());
150
151         return __pImpl->GetLink();
152 }
153
154 Tizen::Base::Utility::LinkType
155 TextElement::GetLinkType(void) const
156 {
157         CHECK_CONSTRUCTED_EX(LINK_TYPE_NONE);
158
159         return __pImpl->GetLinkType();
160 }
161
162 result
163 TextElement::SetText(const Tizen::Base::String& text)
164 {
165         CHECK_CONSTRUCTED;
166
167         return __pImpl->SetText(text);
168 }
169
170 result
171 TextElement::SetFont(const Tizen::Graphics::Font& font)
172 {
173         CHECK_CONSTRUCTED;
174
175         result r = __pImpl->SetFont(font);
176         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
177
178         return r;
179 }
180
181 result
182 TextElement::SetTextColor(const Tizen::Graphics::Color& color)
183 {
184         CHECK_CONSTRUCTED;
185
186         return __pImpl->SetTextColor(color);
187 }
188
189 result
190 TextElement::SetBackgroundColor(const Tizen::Graphics::Color& color)
191 {
192         CHECK_CONSTRUCTED;
193
194         return __pImpl->SetBackgroundColor(color);
195 }
196
197 result
198 TextElement::SetOutlineColor(const Tizen::Graphics::Color& color)
199 {
200         CHECK_CONSTRUCTED;
201
202         return __pImpl->SetOutlineColor(color);
203 }
204
205 Tizen::Base::String
206 TextElement::GetText() const
207 {
208         CHECK_CONSTRUCTED_EX(String());
209
210         return __pImpl->GetText();
211 }
212
213 Tizen::Graphics::Color
214 TextElement::GetTextColor() const
215 {
216         CHECK_CONSTRUCTED_EX(Color::GetColor(COLOR_ID_BLACK));
217
218         return __pImpl->GetTextColor();
219 }
220
221 Tizen::Graphics::Color
222 TextElement::GetBackgroundColor() const
223 {
224         CHECK_CONSTRUCTED_EX(Color::GetColor(COLOR_ID_BLACK));
225
226         return __pImpl->GetBackgroundColor();
227 }
228
229 Tizen::Graphics::Color
230 TextElement::GetOutlineColor() const
231 {
232         CHECK_CONSTRUCTED_EX(Color::GetColor(COLOR_ID_BLACK));
233
234         return __pImpl->GetOutlineColor();
235 }
236
237 }} // Tizen::Graphics