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 <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"
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Utility;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Graphics::_Text;
41 namespace Tizen { namespace Ui { namespace Controls
44 _CustomItemImpl::_CustomItemImpl(CustomItem* pPublic)
45 : _ListItemBaseImpl(pPublic)
50 _CustomItemImpl::~_CustomItemImpl(void)
56 _CustomItemImpl::GetPublic(void)
58 return static_cast <CustomItem&>(_ListItemBaseImpl::GetPublic());
62 _CustomItemImpl::GetPublicClassName(void) const
64 return "Tizen::Ui::Controls::CustomItem";
68 _CustomItemImpl::CreateCustomItemImplN(CustomItem* pPublic, const FloatDimension& itemSize, ListAnnexStyle style)
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.");
75 r = pImpl->Construct(itemSize, style);
76 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[E_SYSTEM] Unable to construct _CustomItemImpl.");
88 _CustomItemImpl::Construct(const FloatDimension& itemSize, ListAnnexStyle style)
90 result r = _ListItemBaseImpl::Construct(itemSize, style);
91 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
93 GetListViewItem()->SetListViewItemType(LISTVIEW_ITEM_TYPE_CUSTOM);
95 SetLastResultReturn(r);
99 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const EnrichedText& text)
101 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
109 FloatRectangle bounds = rect;
110 ListAnnexStyle style = GetListItemAnnexStyle();
112 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
114 float elementLeftMargin = 0.0f;
115 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
117 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
120 result r = pItem->AddElement(bounds, elementId, &text);
121 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
123 pItem->SetTextCutlinkViewMode(elementId, true, false);
129 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const String& text, bool textSliding)
131 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
139 FloatRectangle bounds = rect;
140 ListAnnexStyle style = GetListItemAnnexStyle();
142 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
144 float elementLeftMargin = 0.0f;
145 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
147 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
150 result r = pItem->AddElement(bounds, elementId, text, textSliding);
151 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
155 pItem->SetTextWrapType(elementId, TEXT_OBJECT_WRAP_TYPE_NONE);
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)
165 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
173 FloatRectangle bounds = rect;
174 ListAnnexStyle style = GetListItemAnnexStyle();
176 result r = E_SUCCESS;
178 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
180 float elementLeftMargin = 0.0f;
181 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
183 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
186 r = pItem->AddElement(bounds, elementId, text, textSliding);
187 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
189 ret = pItem->SetTextSize(elementId, textSize);
190 SysTryCatch(NID_UI_CTRL, (ret == true), (r = E_SYSTEM), E_SYSTEM, ("[E_SYSTEM] Unable to add element."));
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."));
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."));
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."));
203 pItem->SetTextWrapType(elementId, TEXT_OBJECT_WRAP_TYPE_NONE);
209 if (!pItem->DeleteElement(elementId))
211 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
218 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const Bitmap& normalBitmap, const Bitmap* pPressedBitmap,
219 const Bitmap* pHighlightedBitmap)
221 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
229 FloatRectangle bounds = rect;
230 ListAnnexStyle style = GetListItemAnnexStyle();
232 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
234 float elementLeftMargin = 0.0f;
235 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
237 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
240 result r = pItem->AddElement(bounds, elementId, &normalBitmap, pPressedBitmap, pPressedBitmap);
241 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
247 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const ICustomElement& element)
249 _ListViewItem* pItem = GetListViewItem();
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"));
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."));
257 _CustomElement* pCustomElement = null;
258 FloatRectangle bounds = rect;
259 ListAnnexStyle style = GetListItemAnnexStyle();
261 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
263 float elementLeftMargin = 0.0f;
264 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
266 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
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);
273 result r = pItem->AddElement(bounds, elementId, pCustomElement);
274 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
279 delete pCustomElement;
280 pCustomElement = null;
286 _CustomItemImpl::AddElement(const FloatRectangle& rect, int elementId, const ICustomElementF& element)
288 _ListViewItem* pItem = GetListViewItem();
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"));
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."));
296 _CustomElement* pCustomElement = null;
297 FloatRectangle bounds = rect;
298 ListAnnexStyle style = GetListItemAnnexStyle();
300 if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
302 float elementLeftMargin = 0.0f;
303 GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, elementLeftMargin);
305 bounds.x += GetAnnexWidth(style) + elementLeftMargin;
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);
312 result r = pItem->AddElement(bounds, elementId, pCustomElement);
313 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
318 delete pCustomElement;
319 pCustomElement = null;
325 _CustomItemImpl::RemoveAllElements(void)
327 GetListViewItem()->DeleteAllElement();
333 _CustomItemImpl::RemoveElement(int elementId)
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."));
338 SysTryReturn(NID_UI_CTRL, (GetListViewItem()->DeleteElement(elementId) == true), E_SYSTEM, E_SYSTEM,
339 ("[E_SYSTEM] Unable to remove element."));
345 _CustomItemImpl::SetElementSelectionEnabled(int elementId, bool enable)
347 _ListViewItem* pItem = GetListViewItem();
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."));
352 SysTryReturn(NID_UI_CTRL, (pItem->HasElement(elementId) == true), E_INVALID_ARG, E_INVALID_ARG,
353 ("[E_INVALID_ARG] This elementId does not exist."));
355 SysTryReturn(NID_UI_CTRL, (pItem->SetElementSelectionEnabled(elementId, enable) == true), E_SYSTEM, E_SYSTEM,
356 ("[E_SYSTEM] Unable to set selection type of element."));
362 _CustomItemImpl::SetElementTextHorizontalAlignment(int elementId, HorizontalAlignment alignment)
364 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
372 TextObjectAlignment align = 0x0000;
376 align = TEXT_OBJECT_ALIGNMENT_LEFT;
379 case ALIGNMENT_RIGHT:
380 align = TEXT_OBJECT_ALIGNMENT_RIGHT;
383 case ALIGNMENT_CENTER:
384 align = TEXT_OBJECT_ALIGNMENT_CENTER;
388 SysTryReturn(NID_UI_CTRL, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to set TextAlignment.");
391 SysTryReturn(NID_UI_CTRL, (pItem->SetTextAlignment(elementId, align) == true), E_SYSTEM, E_SYSTEM,
392 ("[E_SYSTEM] Unable to set TextAlignment."));
398 _CustomItemImpl::SetElementTextVerticalAlignment(int elementId, VerticalAlignment alignment)
400 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
408 TextObjectAlignment align = 0x0000;
412 align = TEXT_OBJECT_ALIGNMENT_TOP;
415 case ALIGNMENT_BOTTOM:
416 align = TEXT_OBJECT_ALIGNMENT_BOTTOM;
419 case ALIGNMENT_MIDDLE:
420 align = TEXT_OBJECT_ALIGNMENT_MIDDLE;
424 SysTryReturn(NID_UI_CTRL, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to set TextAlignment.");
427 SysTryReturn(NID_UI_CTRL, (pItem->SetTextAlignment(elementId, align) == true), E_SYSTEM, E_SYSTEM,
428 ("[E_SYSTEM] Unable to set TextAlignment."));
434 _CustomItemImpl::SetElementAutoLinkMask(int elementId, unsigned long mask)
436 _ListViewItem* pItem = GetListViewItem();
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."));
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."));
444 SysTryReturn(NID_UI_CTRL, (pItem->SetTextCutlinkViewMode(elementId, true) == true), E_SYSTEM, E_SYSTEM,
445 ("[E_SYSTEM] Unable to set auto link."));
447 unsigned long linktype = 0x0;
449 if (LINK_TYPE_URL & mask)
451 linktype |= TEXT_CUTLINK_TYPE_URL;
454 if (LINK_TYPE_EMAIL & mask)
456 linktype |= TEXT_CUTLINK_TYPE_EMAIL;
459 if (LINK_TYPE_TEL_NUM & mask)
461 linktype |= TEXT_CUTLINK_TYPE_PHONE_NUMBER;
464 SysTryReturn(NID_UI_CTRL, (pItem->SetTextCutlinkMask(elementId, linktype) == true), E_SYSTEM, E_SYSTEM,
465 "[E_SYSTEM] Unable to set auto link.");
470 }}} // Tizen::Ui::Controls