Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_SimpleItemImpl.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_SimpleItemImpl.cpp
20  * @brief       This is the implementation file for _SimpleItemImpl class.
21  *
22  * This file contains the implementation of _SimpleItemImpl class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlSimpleItem.h>
27 #include "FUi_ResourceManager.h"
28 #include "FUiCtrl_ListViewItem.h"
29 #include "FUiCtrl_SimpleItemImpl.h"
30
31 #ifdef MEMORY_LEAK_CHECK
32 #include "mem_leak_check.h"
33 #endif
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Graphics::_Text;
38
39 namespace Tizen { namespace Ui { namespace Controls
40 {
41
42 _SimpleItemImpl::_SimpleItemImpl(SimpleItem* pPublic)
43         : _ListItemBaseImpl(pPublic)
44 {
45
46 }
47
48 _SimpleItemImpl::~_SimpleItemImpl(void)
49 {
50
51 }
52
53 SimpleItem&
54 _SimpleItemImpl::GetPublic(void)
55 {
56         return static_cast <SimpleItem&>(_ListItemBaseImpl::GetPublic());
57 }
58
59 const SimpleItem&
60 _SimpleItemImpl::GetPublic(void) const
61 {
62         return static_cast <const SimpleItem&>(_ListItemBaseImpl::GetPublic());
63 }
64
65 const char*
66 _SimpleItemImpl::GetPublicClassName(void) const
67 {
68         return "Tizen::Ui::Controls::SimpleItem";
69 }
70
71 _SimpleItemImpl*
72 _SimpleItemImpl::CreateSimpleItemImplN(SimpleItem* pPublic, const Dimension& itemSize, ListAnnexStyle style)
73 {
74         result r = E_SUCCESS;
75
76         _SimpleItemImpl* pImpl = new (std::nothrow) _SimpleItemImpl(pPublic);
77         SysTryReturn(NID_UI_CTRL, pImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
78
79         r = pImpl->Construct(itemSize, style);
80         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] Unable to construct _SimpleItemImpl.");
81
82         return pImpl;
83
84 CATCH:
85         delete pImpl;
86         pImpl = null;
87
88         return null;
89 }
90
91 result
92 _SimpleItemImpl::Construct(const Dimension& itemSize, ListAnnexStyle style)
93 {
94         result r = _ListItemBaseImpl::Construct(itemSize, style);
95         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
96
97         GetListViewItem()->SetListViewItemType(LISTVIEW_ITEM_TYPE_SIMPLE);
98
99         SetLastResultReturn(r);
100 }
101
102 result
103 _SimpleItemImpl::SetElement(const String& text, const Bitmap* pBitmap)
104 {
105         bool ret = false;
106         _ListViewItem* pItem = GetListViewItem();
107
108         if (pItem->HasElement(LIST_ITEM_RESERVED_ID_2))
109         {
110                 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_2);
111                 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete bitmap element.");
112         }
113
114         if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
115         {
116                 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_3);
117                 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete text element.");
118         }
119
120         Rectangle bitmapRect = Rectangle(0, 0, 0, 0);
121         Rectangle textRect = Rectangle(0, 0, 0, 0);
122         ListAnnexStyle style = GetListItemAnnexStyle();
123         int leftMargin = 0;
124         int itemHeight = GetItemSize().height;
125         int annexWidth = GetAnnexWidth(style);
126         int elementSpacing = 0;
127         int textSize = 0;
128         result r = E_SUCCESS;
129
130         GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, leftMargin);
131         GET_SHAPE_CONFIG(LISTVIEW::ITEM_ELEMENT_SPACING, _CONTROL_ORIENTATION_PORTRAIT, elementSpacing);
132         GET_SHAPE_CONFIG(LISTVIEW::ITEM_DEFAULT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, textSize);
133
134         bitmapRect.x += leftMargin;
135
136         if (style == LIST_ANNEX_STYLE_MARK || style == LIST_ANNEX_STYLE_RADIO)
137         {
138                 bitmapRect.x += GetAnnexWidth(style) + elementSpacing;
139         }
140
141         // Add Bitmap element (optional)
142         if (pBitmap != null)
143         {
144                 int elementWidth = itemHeight * SIMPLE_ITEM_ELEMENT_BITMAP_SIZE_RATIO;
145                 int elementHeight = elementWidth;
146
147                 bitmapRect.y = (itemHeight - elementHeight) / 2;
148                 bitmapRect.width = elementWidth;
149                 bitmapRect.height = elementHeight;
150
151                 r = pItem->AddElement(bitmapRect, LIST_ITEM_RESERVED_ID_2, pBitmap);
152                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
153         }
154         else
155         {
156                 elementSpacing = 0;
157         }
158
159         // Add Text element
160         textRect.x = bitmapRect.x + bitmapRect.width + elementSpacing;
161         textRect.y = 0;
162         textRect.width = GetItemSize().width - textRect.x - ((annexWidth > 0) ? (annexWidth + leftMargin) : 0);
163         textRect.height = itemHeight;
164
165         r = pItem->AddElement(textRect, LIST_ITEM_RESERVED_ID_3, text);
166         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
167
168         pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, textSize);
169         pItem->SetTextAlignment(LIST_ITEM_RESERVED_ID_3, TEXT_OBJECT_ALIGNMENT_MIDDLE);
170
171         return E_SUCCESS;
172 }
173
174 }}} // Tizen::Ui::Controls