Revert " modify license, permission and remove ^M char"
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_CustomItemImpl.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        FUiCtrl_CustomItemImpl.cpp
20  * @brief       This is the implementation file for _CustomItemImpl class.
21  *
22  * This file contains the implementation of _CustomItemImpl class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlCustomItem.h>
27 #include <FUiCtrlICustomElement.h>
28 #include <FUiCtrlICustomElementF.h>
29 #include <FGrp_TextElementImpl.h>
30 #include "FUi_CoordinateSystemUtils.h"
31 #include "FUi_ResourceManager.h"
32 #include "FUiCtrl_CustomElement.h"
33 #include "FUiCtrl_CustomItemImpl.h"
34 #include "FUiCtrl_ListViewItem.h"
35
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Utility;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Graphics::_Text;
40
41 namespace Tizen { namespace Ui { namespace Controls
42 {
43
44 _CustomItemImpl::_CustomItemImpl(CustomItem* pPublic)
45         : _ListItemBaseImpl(pPublic)
46 {
47
48 }
49
50 _CustomItemImpl::~_CustomItemImpl(void)
51 {
52
53 }
54
55 CustomItem&
56 _CustomItemImpl::GetPublic(void)
57 {
58         return static_cast <CustomItem&>(_ListItemBaseImpl::GetPublic());
59 }
60
61 const char*
62 _CustomItemImpl::GetPublicClassName(void) const
63 {
64         return "Tizen::Ui::Controls::CustomItem";
65 }
66
67 _CustomItemImpl*
68 _CustomItemImpl::CreateCustomItemImplN(CustomItem* pPublic, const FloatDimension& itemSize, ListAnnexStyle style)
69 {
70         result r = E_SUCCESS;
71
72         _CustomItemImpl* pImpl = new (std::nothrow) _CustomItemImpl(pPublic);
73         SysTryReturn(NID_UI_CTRL, (pImpl != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
74
75         r = pImpl->Construct(itemSize, style);
76         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[E_SYSTEM] Unable to construct _CustomItemImpl.");
77
78         return pImpl;
79
80 CATCH:
81         delete pImpl;
82         pImpl = null;
83
84         return null;
85 }
86
87 result
88 _CustomItemImpl::Construct(const FloatDimension& itemSize, ListAnnexStyle style)
89 {
90         result r = _ListItemBaseImpl::Construct(itemSize, style);
91         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
92
93         GetListViewItem()->SetListViewItemType(LISTVIEW_ITEM_TYPE_CUSTOM);
94
95         SetLastResultReturn(r);
96 }
97
98 result
99 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const EnrichedText& text)
100 {
101         _ListViewItem* pItem = GetListViewItem();
102
103         SysTryReturn(NID_UI_CTRL, (rect.width >= 0.0f) && (rect.height >= 0.0f), E_INVALID_ARG, E_INVALID_ARG,
104                         ("[E_INVALID_ARG] The width and height should be greater than 0.0f."));
105
106         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
107                         ("E_INVALID_ARG] The element ID should not be less than 0."));
108
109         FloatRectangle bounds = rect;
110         ListAnnexStyle style = GetListItemAnnexStyle();
111
112         if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
113         {
114                 float elementLeftMargin = 0.0f;
115                 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
116
117                 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
118         }
119
120         result r = pItem->AddElement(bounds, elementId, &text);
121         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
122
123         pItem->SetTextCutlinkViewMode(elementId, true, false);
124
125         return r;
126 }
127
128 result
129 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const String& text, bool textSliding)
130 {
131         _ListViewItem* pItem = GetListViewItem();
132
133         SysTryReturn(NID_UI_CTRL, (rect.width >= 0.0f) && (rect.height >= 0.0f), E_INVALID_ARG, E_INVALID_ARG,
134                         ("[E_INVALID_ARG] The width and height should be greater than 0."));
135
136         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
137                         ("E_INVALID_ARG] The element ID should not be less than 0."));
138
139         FloatRectangle bounds = rect;
140         ListAnnexStyle style = GetListItemAnnexStyle();
141
142         if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
143         {
144                 float elementLeftMargin = 0.0f;
145                 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
146
147                 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
148         }
149
150         result r = pItem->AddElement(bounds, elementId, text, textSliding);
151         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
152
153         if (textSliding)
154         {
155                 pItem->SetTextWrapType(elementId, TEXT_OBJECT_WRAP_TYPE_NONE);
156         }
157
158         return r;
159 }
160
161 result
162 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const String& text, float textSize,
163                 const Color& normalTextColor, const Color& pressedTextColor, const Color& highlightedTextColor, bool textSliding)
164 {
165         _ListViewItem* pItem = GetListViewItem();
166
167         SysTryReturn(NID_UI_CTRL, (rect.width >= 0.0f) && (rect.height >= 0.0f), E_INVALID_ARG, E_INVALID_ARG,
168                         ("[E_INVALID_ARG] The width and height should be greater than 0.0f."));
169
170         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
171                         ("E_INVALID_ARG] The element ID should not be less than 0."));
172
173         FloatRectangle bounds = rect;
174         ListAnnexStyle style = GetListItemAnnexStyle();
175         bool ret;
176         result r = E_SUCCESS;
177
178         if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
179         {
180                 float elementLeftMargin = 0.0f;
181                 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
182
183                 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
184         }
185
186         r = pItem->AddElement(bounds, elementId, text, textSliding);
187         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
188
189         ret = pItem->SetTextSize(elementId, textSize);
190         SysTryCatch(NID_UI_CTRL, (ret == true), (r = E_SYSTEM), E_SYSTEM, ("[E_SYSTEM] Unable to add element."));
191
192         ret = pItem->SetTextColor(elementId, normalTextColor, LISTVIEW_ITEM_STATUS_NORMAL);
193         SysTryCatch(NID_UI_CTRL, (ret == true), (r = E_SYSTEM), E_SYSTEM, ("[E_SYSTEM] Unable to add element."));
194
195         ret = pItem->SetTextColor(elementId, pressedTextColor, LISTVIEW_ITEM_STATUS_PRESSED);
196         SysTryCatch(NID_UI_CTRL, (ret == true), (r = E_SYSTEM), E_SYSTEM, ("[E_SYSTEM] Unable to add element."));
197
198         ret = pItem->SetTextColor(elementId, highlightedTextColor, LISTVIEW_ITEM_STATUS_HIGHLIGHTED);
199         SysTryCatch(NID_UI_CTRL, (ret == true), (r = E_SYSTEM), E_SYSTEM, ("[E_SYSTEM] Unable to add element."));
200
201         if (textSliding)
202         {
203                 pItem->SetTextWrapType(elementId, TEXT_OBJECT_WRAP_TYPE_NONE);
204         }
205
206         return E_SUCCESS;
207
208 CATCH:
209         if (!pItem->DeleteElement(elementId))
210         {
211                 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
212         }
213
214         return r;
215 }
216
217 result
218 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const Bitmap& normalBitmap, const Bitmap* pPressedBitmap,
219                 const Bitmap* pHighlightedBitmap)
220 {
221         _ListViewItem* pItem = GetListViewItem();
222
223         SysTryReturn(NID_UI_CTRL, (rect.width >= 0.0f) && (rect.height >= 0.0f), E_INVALID_ARG, E_INVALID_ARG,
224                         ("[E_INVALID_ARG] The width and height should be greater than 0.0f."));
225
226         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
227                         ("E_INVALID_ARG] The element ID should not be less than 0."));
228
229         FloatRectangle bounds = rect;
230         ListAnnexStyle style = GetListItemAnnexStyle();
231
232         if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
233         {
234                 float elementLeftMargin = 0.0f;
235                 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
236
237                 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
238         }
239
240         result r = pItem->AddElement(bounds, elementId, &normalBitmap, pPressedBitmap, pPressedBitmap);
241         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
242
243         return r;
244 }
245
246 result
247 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const ICustomElement& element)
248 {
249         _ListViewItem* pItem = GetListViewItem();
250
251         SysTryReturn(NID_UI_CTRL, (rect.width >= 0.0f) && (rect.height >= 0.0f), E_INVALID_ARG, E_INVALID_ARG,
252                         ("[E_INVALID_ARG] The width and height should be greater than 0.0f"));
253
254         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
255                         ("E_INVALID_ARG] The element ID should not be less than 0."));
256
257         _CustomElement* pCustomElement = null;
258         FloatRectangle bounds = rect;
259         ListAnnexStyle style = GetListItemAnnexStyle();
260
261         if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
262         {
263                 float elementLeftMargin = 0.0f;
264                 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
265
266                 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
267         }
268
269         pCustomElement = new (std::nothrow) _CustomElement(elementId);
270         SysTryReturn(NID_UI_CTRL, (pCustomElement != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
271         pCustomElement->SetElement(element);
272
273         result r = pItem->AddElement(bounds, elementId, pCustomElement);
274         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
275
276         return r;
277
278 CATCH:
279         delete pCustomElement;
280         pCustomElement = null;
281
282         return r;
283 }
284
285 result
286 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const ICustomElementF& element)
287 {
288         _ListViewItem* pItem = GetListViewItem();
289
290         SysTryReturn(NID_UI_CTRL, (rect.width >= 0.0f) && (rect.height >= 0.0f), E_INVALID_ARG, E_INVALID_ARG,
291                         ("[E_INVALID_ARG] The width and height should be greater than 0.0f"));
292
293         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
294                         ("E_INVALID_ARG] The element ID should not be less than 0."));
295
296         _CustomElement* pCustomElement = null;
297         FloatRectangle bounds = rect;
298         ListAnnexStyle style = GetListItemAnnexStyle();
299
300         if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
301         {
302                 float elementLeftMargin = 0.0f;
303                 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
304
305                 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
306         }
307
308         pCustomElement = new (std::nothrow) _CustomElement(elementId);
309         SysTryReturn(NID_UI_CTRL, (pCustomElement != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
310         pCustomElement->SetElement(element);
311
312         result r = pItem->AddElement(bounds, elementId, pCustomElement);
313         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
314
315         return r;
316
317 CATCH:
318         delete pCustomElement;
319         pCustomElement = null;
320
321         return r;
322 }
323
324 result
325 _CustomItemImpl::RemoveAllElements(void)
326 {
327         GetListViewItem()->DeleteAllElement();
328
329         return E_SUCCESS;
330 }
331
332 result
333 _CustomItemImpl::RemoveElement(int elementId)
334 {
335         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
336                         ("E_INVALID_ARG] The element ID should not be less than 0."));
337
338         SysTryReturn(NID_UI_CTRL, (GetListViewItem()->DeleteElement(elementId) == true), E_SYSTEM, E_SYSTEM,
339                         ("[E_SYSTEM] Unable to remove element."));
340
341         return E_SUCCESS;
342 }
343
344 result
345 _CustomItemImpl::SetElementSelectionEnabled(int elementId, bool enable)
346 {
347         _ListViewItem* pItem = GetListViewItem();
348
349         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
350                         ("E_INVALID_ARG] The element ID should not be less than 0."));
351
352         SysTryReturn(NID_UI_CTRL, (pItem->HasElement(elementId) == true), E_INVALID_ARG, E_INVALID_ARG,
353                         ("[E_INVALID_ARG] This elementId does not exist."));
354
355         SysTryReturn(NID_UI_CTRL, (pItem->SetElementSelectionEnabled(elementId, enable) == true), E_SYSTEM, E_SYSTEM,
356                         ("[E_SYSTEM] Unable to set selection type of element."));
357
358         return E_SUCCESS;
359 }
360
361 result
362 _CustomItemImpl::SetElementTextHorizontalAlignment(int elementId, HorizontalAlignment alignment)
363 {
364         _ListViewItem* pItem = GetListViewItem();
365
366         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
367                         ("E_INVALID_ARG] The element ID should not be less than 0."));
368
369         SysTryReturn(NID_UI_CTRL, (pItem->GetElementType(elementId) == LISTVIEW_ITEM_ELEMENT_TEXT), E_INVALID_OPERATION, E_INVALID_OPERATION,
370                         ("[E_INVALID_OPERATION] This element is not text."));
371
372         TextObjectAlignment align = 0x0000;
373         switch (alignment)
374         {
375         case ALIGNMENT_LEFT:
376                 align = TEXT_OBJECT_ALIGNMENT_LEFT;
377                 break;
378
379         case ALIGNMENT_RIGHT:
380                 align = TEXT_OBJECT_ALIGNMENT_RIGHT;
381                 break;
382
383         case ALIGNMENT_CENTER:
384                 align = TEXT_OBJECT_ALIGNMENT_CENTER;
385                 break;
386
387         default:
388                 SysTryReturn(NID_UI_CTRL, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to set TextAlignment.");
389         }
390
391         SysTryReturn(NID_UI_CTRL, (pItem->SetTextAlignment(elementId, align) == true), E_SYSTEM, E_SYSTEM,
392                         ("[E_SYSTEM] Unable to set TextAlignment."));
393
394         return E_SUCCESS;
395 }
396
397 result
398 _CustomItemImpl::SetElementTextVerticalAlignment(int elementId, VerticalAlignment alignment)
399 {
400         _ListViewItem* pItem = GetListViewItem();
401
402         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
403                         ("E_INVALID_ARG] The element ID should not be less than 0."));
404
405         SysTryReturn(NID_UI_CTRL, (pItem->GetElementType(elementId) == LISTVIEW_ITEM_ELEMENT_TEXT), E_INVALID_OPERATION, E_INVALID_OPERATION,
406                         ("[E_INVALID_OPERATION] This element is not text."));
407
408         TextObjectAlignment align = 0x0000;
409         switch (alignment)
410         {
411         case ALIGNMENT_TOP:
412                 align = TEXT_OBJECT_ALIGNMENT_TOP;
413                 break;
414
415         case ALIGNMENT_BOTTOM:
416                 align = TEXT_OBJECT_ALIGNMENT_BOTTOM;
417                 break;
418
419         case ALIGNMENT_MIDDLE:
420                 align = TEXT_OBJECT_ALIGNMENT_MIDDLE;
421                 break;
422
423         default:
424                 SysTryReturn(NID_UI_CTRL, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to set TextAlignment.");
425         }
426
427         SysTryReturn(NID_UI_CTRL, (pItem->SetTextAlignment(elementId, align) == true), E_SYSTEM, E_SYSTEM,
428                         ("[E_SYSTEM] Unable to set TextAlignment."));
429
430         return E_SUCCESS;
431 }
432
433 result
434 _CustomItemImpl::SetElementAutoLinkMask(int elementId, unsigned long mask)
435 {
436         _ListViewItem* pItem = GetListViewItem();
437
438         SysTryReturn(NID_UI_CTRL, (elementId >= 0) && (elementId <= Integer::VALUE_MAX), E_INVALID_ARG, E_INVALID_ARG,
439                         ("E_INVALID_ARG] The element ID should not be less than 0."));
440
441         SysTryReturn(NID_UI_CTRL, (pItem->GetElementType(elementId) == LISTVIEW_ITEM_ELEMENT_TEXT), E_INVALID_OPERATION, E_INVALID_OPERATION,
442                         ("[E_INVALID_OPERATION] This element is not text."));
443
444         SysTryReturn(NID_UI_CTRL, (pItem->SetTextCutlinkViewMode(elementId, true) == true), E_SYSTEM, E_SYSTEM,
445                         ("[E_SYSTEM] Unable to set auto link."));
446
447         unsigned long linktype = 0x0;
448
449         if (LINK_TYPE_URL & mask)
450         {
451                 linktype |= TEXT_CUTLINK_TYPE_URL;
452         }
453
454         if (LINK_TYPE_EMAIL & mask)
455         {
456                 linktype |= TEXT_CUTLINK_TYPE_EMAIL;
457         }
458
459         if (LINK_TYPE_TEL_NUM & mask)
460         {
461                 linktype |= TEXT_CUTLINK_TYPE_PHONE_NUMBER;
462         }
463
464         SysTryReturn(NID_UI_CTRL, (pItem->SetTextCutlinkMask(elementId, linktype) == true), E_SYSTEM, E_SYSTEM,
465                         "[E_SYSTEM] Unable to set auto link.");
466
467         return E_SUCCESS;
468 }
469
470 }}} // Tizen::Ui::Controls