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