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