2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
19 * @file FUiCtrl_CustomItemImpl.cpp
20 * @brief This is the implementation file for _CustomItemImpl class.
22 * This file contains the implementation of _CustomItemImpl class.
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"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Graphics::_Text;
39 namespace Tizen { namespace Ui { namespace Controls
42 _CustomItemImpl::_CustomItemImpl(CustomItem* pPublic)
43 : _ListItemBaseImpl(pPublic)
48 _CustomItemImpl::~_CustomItemImpl(void)
54 _CustomItemImpl::GetPublic(void)
56 return static_cast <CustomItem&>(_ListItemBaseImpl::GetPublic());
60 _CustomItemImpl::GetPublicClassName(void) const
62 return "Tizen::Ui::Controls::CustomItem";
66 _CustomItemImpl::CreateCustomItemImplN(CustomItem* pPublic, const Dimension& itemSize, ListAnnexStyle style)
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.");
73 r = pImpl->Construct(itemSize, style);
74 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[E_SYSTEM] Unable to construct _CustomItemImpl.");
86 _CustomItemImpl::Construct(const Dimension& itemSize, ListAnnexStyle style)
88 result r = _ListItemBaseImpl::Construct(itemSize, style);
89 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
91 GetListViewItem()->SetListViewItemType(LISTVIEW_ITEM_TYPE_CUSTOM);
93 SetLastResultReturn(r);
97 _CustomItemImpl::AddElement(const Rectangle& rect, int elementId, const EnrichedText& text)
99 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
107 Rectangle bounds = rect;
108 ListAnnexStyle style = GetListItemAnnexStyle();
110 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
112 int elementLeftMargin = 0;
113 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
115 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
118 result r = pItem->AddElement(bounds, elementId, &text);
119 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
121 pItem->SetTextCutlinkViewMode(elementId, true, false);
127 _CustomItemImpl::AddElement(const Rectangle& rect, int elementId, const String& text, bool textSliding)
129 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
137 Rectangle bounds = rect;
138 ListAnnexStyle style = GetListItemAnnexStyle();
140 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
142 int elementLeftMargin = 0;
143 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
145 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
148 result r = pItem->AddElement(bounds, elementId, text, textSliding);
149 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
151 if (textSliding == true)
153 pItem->SetTextWrapType(elementId, TEXT_OBJECT_WRAP_TYPE_NONE);
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)
163 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
171 Rectangle bounds = rect;
172 ListAnnexStyle style = GetListItemAnnexStyle();
174 result r = E_SUCCESS;
176 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
178 int elementLeftMargin = 0;
179 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
181 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
184 r = pItem->AddElement(bounds, elementId, text, textSliding);
185 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
187 ret = pItem->SetTextSize(elementId, textSize);
188 SysTryCatch(NID_UI_CTRL, (ret == true), (r = E_SYSTEM), E_SYSTEM, ("[E_SYSTEM] Unable to add element."));
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."));
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."));
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."));
199 if (textSliding == true)
201 pItem->SetTextWrapType(elementId, TEXT_OBJECT_WRAP_TYPE_NONE);
207 if (pItem->DeleteElement(elementId) == false)
209 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
216 _CustomItemImpl::AddElement(const Rectangle& rect, int elementId, const Bitmap& normalBitmap, const Bitmap* pPressedBitmap,
217 const Bitmap* pHighlightedBitmap)
219 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
227 Rectangle bounds = rect;
228 ListAnnexStyle style = GetListItemAnnexStyle();
230 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
232 int elementLeftMargin = 0;
233 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
235 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
238 result r = pItem->AddElement(bounds, elementId, &normalBitmap, pPressedBitmap, pPressedBitmap);
239 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
245 _CustomItemImpl::AddElement(const Rectangle& rect, int elementId, const ICustomElement& element)
247 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
255 _CustomElement* pCustomElement = null;
256 Rectangle bounds = rect;
257 ListAnnexStyle style = GetListItemAnnexStyle();
259 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
261 int elementLeftMargin = 0;
262 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
264 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
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);
271 result r = pItem->AddElement(bounds, elementId, pCustomElement);
272 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
277 delete pCustomElement;
278 pCustomElement = null;
284 _CustomItemImpl::RemoveAllElements(void)
286 GetListViewItem()->DeleteAllElement();
292 _CustomItemImpl::RemoveElement(int elementId)
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."));
297 SysTryReturn(NID_UI_CTRL, (GetListViewItem()->DeleteElement(elementId) == true), E_SYSTEM, E_SYSTEM,
298 ("[E_SYSTEM] Unable to remove element."));
304 _CustomItemImpl::SetElementSelectionEnabled(int elementId, bool enable)
306 _ListViewItem* pItem = GetListViewItem();
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."));
311 SysTryReturn(NID_UI_CTRL, (pItem->HasElement(elementId) == true), E_INVALID_ARG, E_INVALID_ARG,
312 ("[E_INVALID_ARG] This elementId does not exist."));
314 SysTryReturn(NID_UI_CTRL, (pItem->SetElementSelectionEnabled(elementId, enable) == true), E_SYSTEM, E_SYSTEM,
315 ("[E_SYSTEM] Unable to set selection type of element."));
321 _CustomItemImpl::SetElementTextHorizontalAlignment(int elementId, HorizontalAlignment alignment)
323 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
331 TextObjectAlignment align = 0x0000;
335 align = TEXT_OBJECT_ALIGNMENT_LEFT;
338 case ALIGNMENT_RIGHT:
339 align = TEXT_OBJECT_ALIGNMENT_RIGHT;
342 case ALIGNMENT_CENTER:
343 align = TEXT_OBJECT_ALIGNMENT_CENTER;
347 SysTryReturn(NID_UI_CTRL, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to set TextAlignment.");
350 SysTryReturn(NID_UI_CTRL, (pItem->SetTextAlignment(elementId, align) == true), E_SYSTEM, E_SYSTEM,
351 ("[E_SYSTEM] Unable to set TextAlignment."));
357 _CustomItemImpl::SetElementTextVerticalAlignment(int elementId, VerticalAlignment alignment)
359 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
367 TextObjectAlignment align = 0x0000;
371 align = TEXT_OBJECT_ALIGNMENT_TOP;
374 case ALIGNMENT_BOTTOM:
375 align = TEXT_OBJECT_ALIGNMENT_BOTTOM;
378 case ALIGNMENT_MIDDLE:
379 align = TEXT_OBJECT_ALIGNMENT_MIDDLE;
383 SysTryReturn(NID_UI_CTRL, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to set TextAlignment.");
386 SysTryReturn(NID_UI_CTRL, (pItem->SetTextAlignment(elementId, align) == true), E_SYSTEM, E_SYSTEM,
387 ("[E_SYSTEM] Unable to set TextAlignment."));
393 _CustomItemImpl::SetElementAutoLinkMask(int elementId, unsigned long mask)
395 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
403 SysTryReturn(NID_UI_CTRL, (pItem->SetTextCutlinkViewMode(elementId, true) == true), E_SYSTEM, E_SYSTEM,
404 ("[E_SYSTEM] Unable to set auto link."));
406 unsigned long linktype = 0x0;
408 if (LINK_TYPE_URL & mask)
410 linktype |= TEXT_CUTLINK_TYPE_URL;
413 if (LINK_TYPE_EMAIL & mask)
415 linktype |= TEXT_CUTLINK_TYPE_EMAIL;
418 if (LINK_TYPE_TEL_NUM & mask)
420 linktype |= TEXT_CUTLINK_TYPE_PHONE_NUMBER;
423 SysTryReturn(NID_UI_CTRL, (pItem->SetTextCutlinkMask(elementId, linktype) == true), E_SYSTEM, E_SYSTEM,
424 "[E_SYSTEM] Unable to set auto link.");
429 }}} // Tizen::Ui::Controls