Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / FGrpEnrichedText.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                 FGrpEnrichedText.cpp
20 * @brief                This is the cpp file for EnrichedText class.
21 */
22
23 #include <new>
24
25 #include <FGrpEnrichedText.h>
26 #include <FBaseString.h>
27 #include <FGrpFont.h>
28 #include <FBaseUtilTypes.h>
29
30 #include <FBaseSysLog.h>
31
32 #include "FGrp_EnrichedTextImpl.h"
33 #include "FGrp_ResUtil.h"
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Base::Utility;
39
40 #define CHECK_NOT_CONSTRUCTED \
41         SysTryReturnResult(NID_GRP, this->__pImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Fails to allocate memory.") \
42         SysAssertf(!this->__pImpl->IsConstructed(), \
43                 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
44
45 #define CHECK_CONSTRUCTED \
46         ClearLastResult(); \
47         SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
48                 "Not yet constructed. Construct() should be called before use.");
49
50 #define CHECK_CONSTRUCTED_EX(_result) \
51         ClearLastResult(); \
52         SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
53                 "Not yet constructed. Construct() should be called before use.");
54
55 #define CHECK_CONSTRUCTED_VOID \
56         ClearLastResult(); \
57         SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
58                 "Not yet constructed. Construct() should be called before use.");
59
60 namespace Tizen { namespace Graphics
61 {
62
63 EnrichedText::EnrichedText()
64 {
65         __pImpl = new (std::nothrow) _EnrichedTextImpl;
66 }
67
68 EnrichedText::~EnrichedText()
69 {
70         if (__pImpl)
71         {
72                 delete __pImpl;
73                 __pImpl = null;
74         }
75 }
76
77 result
78 EnrichedText::Construct(const Tizen::Graphics::Dimension& dim)
79 {
80         CHECK_NOT_CONSTRUCTED;
81
82         result r = __pImpl->Construct(dim);
83         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating", GetErrorMessage(r));
84
85         return E_SUCCESS;
86 }
87
88 result
89 EnrichedText::InsertAt(int elementIndex, Tizen::Graphics::TextElement& element)
90 {
91         CHECK_CONSTRUCTED;
92
93         return __pImpl->InsertAt(elementIndex, element);
94 }
95
96 result
97 EnrichedText::RemoveAt(int elementIndex, bool deallocate)
98 {
99         CHECK_CONSTRUCTED;
100
101         return __pImpl->RemoveAt(elementIndex, deallocate);
102 }
103
104 result
105 EnrichedText::Remove(Tizen::Graphics::TextElement& element, bool deallocate)
106 {
107         CHECK_CONSTRUCTED;
108
109         return __pImpl->Remove(element, deallocate);
110 }
111
112 result
113 EnrichedText::Add(Tizen::Graphics::TextElement& element)
114 {
115         CHECK_CONSTRUCTED;
116
117         return __pImpl->Add(element);
118 }
119
120 result
121 EnrichedText::RemoveAllTextElements(bool deallocate)
122 {
123         CHECK_CONSTRUCTED;
124
125         return __pImpl->RemoveAllTextElements(deallocate);
126 }
127
128 result
129 EnrichedText::RemoveAll(bool deallocate)
130 {
131         CHECK_CONSTRUCTED;
132
133         return __pImpl->RemoveAll(deallocate);
134 }
135
136 TextElement*
137 EnrichedText::GetTextElementAt(int elementIndex) const
138 {
139         CHECK_CONSTRUCTED_EX(null);
140
141         return __pImpl->GetTextElementAt(elementIndex);
142 }
143
144 int
145 EnrichedText::GetTextElementCount(void) const
146 {
147         CHECK_CONSTRUCTED_EX(0);
148
149         return __pImpl->GetTextElementCount();
150 }
151
152 result
153 EnrichedText::SetSize(const Tizen::Graphics::Dimension& size)
154 {
155         CHECK_CONSTRUCTED;
156
157         return __pImpl->SetSize(size);
158 }
159
160 result
161 EnrichedText::SetSize(int width, int height)
162 {
163         CHECK_CONSTRUCTED;
164
165         return __pImpl->SetSize(width, height);
166 }
167
168 Tizen::Graphics::Dimension
169 EnrichedText::GetSize(void) const
170 {
171         CHECK_CONSTRUCTED_EX(Dimension(0, 0));
172
173         return __pImpl->GetSize();
174 }
175
176 void
177 EnrichedText::GetSize(int& width, int& height) const
178 {
179         CHECK_CONSTRUCTED_VOID;
180
181         return __pImpl->GetSize(width, height);
182 }
183
184 int
185 EnrichedText::GetWidth(void) const
186 {
187         CHECK_CONSTRUCTED_EX(0);
188
189         return __pImpl->GetWidth();
190 }
191
192 int
193 EnrichedText::GetHeight(void) const
194 {
195         CHECK_CONSTRUCTED_EX(0);
196
197         return __pImpl->GetHeight();
198 }
199
200 result
201 EnrichedText::SetVerticalAlignment(TextVerticalAlignment alignment)
202 {
203         CHECK_CONSTRUCTED;
204
205         return __pImpl->SetVerticalAlignment(alignment);
206 }
207
208 result
209 EnrichedText::SetHorizontalAlignment(TextHorizontalAlignment alignment)
210 {
211         CHECK_CONSTRUCTED;
212
213         return __pImpl->SetHorizontalAlignment(alignment);
214 }
215
216 TextVerticalAlignment
217 EnrichedText::GetVerticalAlignment(void) const
218 {
219         CHECK_CONSTRUCTED_EX(TEXT_ALIGNMENT_VERTICAL_MIN);
220
221         return __pImpl->GetVerticalAlignment();
222 }
223
224 TextHorizontalAlignment
225 EnrichedText::GetHorizontalAlignment(void) const
226 {
227         CHECK_CONSTRUCTED_EX(TEXT_ALIGNMENT_HORIZONTAL_MIN);
228
229         return __pImpl->GetHorizontalAlignment();
230 }
231
232 result
233 EnrichedText::SetTextWrapStyle(TextWrap wrap)
234 {
235         CHECK_CONSTRUCTED;
236
237         return __pImpl->SetTextWrapStyle(wrap);
238 }
239
240 TextWrap
241 EnrichedText::GetTextWrapStyle(void) const
242 {
243         CHECK_CONSTRUCTED_EX(TEXT_WRAP_MIN);
244
245         return __pImpl->GetTextWrapStyle();
246 }
247
248 result
249 EnrichedText::SetTextAbbreviationEnabled(bool enable)
250 {
251         CHECK_CONSTRUCTED;
252
253         return __pImpl->SetTextAbbreviationEnabled(enable);
254 }
255
256 bool
257 EnrichedText::IsTextAbbreviationEnabled(void) const
258 {
259         CHECK_CONSTRUCTED_EX(false);
260
261         return __pImpl->IsTextAbbreviationEnabled();
262 }
263
264 result
265 EnrichedText::SetLineSpace(int lineSpace)
266 {
267         CHECK_CONSTRUCTED;
268
269         return __pImpl->SetLineSpace(lineSpace);
270 }
271
272 int
273 EnrichedText::GetLineSpace(void) const
274 {
275         CHECK_CONSTRUCTED_EX(0);
276
277         return __pImpl->GetLineSpace();
278 }
279
280 void
281 EnrichedText::Refresh(void)
282 {
283         CHECK_CONSTRUCTED_VOID;
284
285         return __pImpl->Refresh();
286 }
287
288 int
289 EnrichedText::GetTotalLineCount(void) const
290 {
291         CHECK_CONSTRUCTED_EX(0);
292
293         return __pImpl->GetTotalLineCount();
294 }
295
296 int
297 EnrichedText::GetTotalLineHeight(void) const
298 {
299         CHECK_CONSTRUCTED_EX(0);
300
301         return __pImpl->GetTotalLineHeight();
302 }
303
304 int
305 EnrichedText::GetDisplayLineCount(void) const
306 {
307         CHECK_CONSTRUCTED_EX(0);
308
309         return __pImpl->GetDisplayLineCount();
310 }
311
312 int
313 EnrichedText::GetLineLength(int lineIndex) const
314 {
315         CHECK_CONSTRUCTED_EX(0);
316
317         return __pImpl->GetLineLength(lineIndex);
318 }
319
320 int
321 EnrichedText::GetFirstTextIndex(int lineIndex) const
322 {
323         CHECK_CONSTRUCTED_EX(0);
324
325         return __pImpl->GetFirstTextIndex(lineIndex);
326 }
327
328 int
329 EnrichedText::GetLineIndex(int textIndex) const
330 {
331         CHECK_CONSTRUCTED_EX(0);
332
333         return __pImpl->GetLineIndex(textIndex);
334 }
335
336 int
337 EnrichedText::GetLineHeight(int lineIndex) const
338 {
339         CHECK_CONSTRUCTED_EX(0);
340
341         return __pImpl->GetLineHeight(lineIndex);
342 }
343
344 int
345 EnrichedText::GetTextLength(void) const
346 {
347         CHECK_CONSTRUCTED_EX(0);
348
349         return __pImpl->GetTextLength();
350 }
351
352 result
353 EnrichedText::GetTextExtent(int startTextIndex, int textLength, int& width, int& height, int& actualLength) const
354 {
355         CHECK_CONSTRUCTED;
356
357         return __pImpl->GetTextExtent(startTextIndex, textLength, width, height, actualLength);
358 }
359
360 result
361 EnrichedText::GetTextExtent(int startTextIndex, int textLength, Tizen::Graphics::Dimension& size, int& actualLength) const
362 {
363         CHECK_CONSTRUCTED;
364
365         return __pImpl->GetTextExtent(startTextIndex, textLength, size, actualLength);
366 }
367
368 Tizen::Graphics::Dimension
369 EnrichedText::GetTextExtent(void) const
370 {
371         CHECK_CONSTRUCTED_EX(Dimension(-1, -1));
372
373         return __pImpl->GetTextExtent();
374 }
375
376 result
377 EnrichedText::Add(const Tizen::Graphics::Bitmap& bitmap)
378 {
379         CHECK_CONSTRUCTED;
380
381         return __pImpl->Add(bitmap);
382 }
383
384 result
385 EnrichedText::InsertAt(int elementIndex, const Tizen::Graphics::Bitmap& bitmap)
386 {
387         CHECK_CONSTRUCTED;
388
389         return __pImpl->InsertAt(elementIndex, bitmap);
390 }
391
392 result
393 EnrichedText::GetLinkInfoFromPosition(const Point& point, Tizen::Base::Utility::LinkInfo& linkInfo) const
394 {
395         CHECK_CONSTRUCTED;
396
397         return __pImpl->GetLinkInfoFromPosition(point, linkInfo);
398 }
399
400 result
401 EnrichedText::GetLinkInfoFromPosition(int x, int y, Tizen::Base::Utility::LinkInfo& linkInfo) const
402 {
403         CHECK_CONSTRUCTED;
404
405         return __pImpl->GetLinkInfoFromPosition(x, y, linkInfo);
406 }
407
408 TextVerticalAlignment
409 EnrichedText::GetElementVerticalAlignment(void) const
410 {
411         CHECK_CONSTRUCTED_EX(TEXT_ALIGNMENT_VERTICAL_MIN);
412
413         return __pImpl->GetElementVerticalAlignment();
414 }
415
416 result
417 EnrichedText::SetElementVerticalAlignment(TextVerticalAlignment alignment)
418 {
419         CHECK_CONSTRUCTED;
420
421         return __pImpl->SetElementVerticalAlignment(alignment);
422 }
423
424 }} // Tizen::Graphics