Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_GroupItemImpl.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_GroupItemImpl.cpp
20  * @brief       This is the implementation file for the GroupItemImpl class.
21  *
22  * This header file contains the declarations of the GroupItemImpl class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlGroupItem.h>
27 #include "FUi_ResourceManager.h"
28 #include "FUi_CoordinateSystemUtils.h"
29 #include "FUiCtrl_GroupItemImpl.h"
30 #include "FUiCtrl_ListViewItem.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 _GroupItemImpl*
44 _GroupItemImpl::GetInstance(GroupItem& groupItem)
45 {
46         return groupItem._pImpl;
47 }
48
49 const _GroupItemImpl*
50 _GroupItemImpl::GetInstance(const GroupItem& groupItem)
51 {
52         return groupItem._pImpl;
53 }
54
55 _GroupItemImpl::_GroupItemImpl(GroupItem* pPublic)
56         : _ListItemBaseImpl(null)
57 {
58         GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_DEFAULT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __textSize);
59         GET_COLOR_CONFIG(TABLEVIEW::GROUPITEM_TEXT_NORMAL, __textColor);
60 }
61
62 _GroupItemImpl::~_GroupItemImpl(void)
63 {
64
65 }
66
67 const char*
68 _GroupItemImpl::GetPublicClassName(void) const
69 {
70         return "Tizen::Ui::Controls::GroupItem";
71 }
72
73 _GroupItemImpl*
74 _GroupItemImpl::CreateGroupItemImpN(GroupItem* pPublic, const FloatDimension& itemSize)
75 {
76         result r = E_SUCCESS;
77
78         _GroupItemImpl* pImpl = new (std::nothrow) _GroupItemImpl(pPublic);
79         SysTryReturn(NID_UI_CTRL, pImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
80
81         r = pImpl->Construct(itemSize);
82         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
83
84         return pImpl;
85
86 CATCH:
87         delete pImpl;
88         pImpl = null;
89
90         return null;
91 }
92
93 result
94 _GroupItemImpl::Construct(const FloatDimension& itemSize)
95 {
96         result r = _ListItemBaseImpl::Construct(itemSize, LIST_ANNEX_STYLE_NORMAL);
97         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
98
99         _ListViewItem* pItem = GetListViewItem();
100
101         pItem->SetListViewItemType(LISTVIEW_ITEM_TYPE_GROUP);
102         pItem->SetItemDividerEnabled(false);
103         pItem->SetItemTapSoundEnabled(false);
104
105         r = SetBackgroundColor(GetBackgroundColor());
106
107         SetLastResultReturn(r);
108 }
109
110 result
111 _GroupItemImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
112 {
113         result r = E_SUCCESS;
114
115         r = _ListItemBaseImpl::SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_NORMAL, pBitmap);
116         r = _ListItemBaseImpl::SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_PRESSED, pBitmap);
117         r = _ListItemBaseImpl::SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, pBitmap);
118
119         return r;
120 }
121
122 result
123 _GroupItemImpl::SetBackgroundColor(const Color& color)
124 {
125         result r = E_SUCCESS;
126
127         r = _ListItemBaseImpl::SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, color);
128         r = _ListItemBaseImpl::SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, color);
129         r = _ListItemBaseImpl::SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, color);
130
131         return r;
132 }
133
134 Color
135 _GroupItemImpl::GetBackgroundColor(void) const
136 {
137         return _ListItemBaseImpl::GetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL);
138 }
139
140 result
141 _GroupItemImpl::SetTextColor(const Color& color)
142 {
143         _ListViewItem* pItem = GetListViewItem();
144
145         if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
146         {
147                 bool ret = false;
148
149                 ret = pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, color, LISTVIEW_ITEM_STATUS_NORMAL);
150                 SysTryReturn(NID_UI_CTRL, ret == true, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
151
152                 ret = pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, color, LISTVIEW_ITEM_STATUS_PRESSED);
153                 SysTryReturn(NID_UI_CTRL, ret == true, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
154
155                 ret = pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, color, LISTVIEW_ITEM_STATUS_HIGHLIGHTED);
156                 SysTryReturn(NID_UI_CTRL, ret == true, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
157         }
158
159         __textColor = color;
160
161         return E_SUCCESS;
162 }
163
164 Color
165 _GroupItemImpl::GetTextColor(void) const
166 {
167         return __textColor;
168 }
169
170 result
171 _GroupItemImpl::SetTextSize(float size)
172 {
173         __textSize = size;
174
175         _ListViewItem* pItem = GetListViewItem();
176         if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
177         {
178                 bool ret = pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, size);
179
180                 return (ret ? E_SUCCESS : E_SYSTEM);
181         }
182
183         return E_SUCCESS;
184 }
185
186 float
187 _GroupItemImpl::GetTextSize(void) const
188 {
189         return __textSize;
190 }
191
192 result
193 _GroupItemImpl::SetElement(const String& text, const Bitmap* pBitmap)
194 {
195         bool ret = false;
196         _ListViewItem* pItem = GetListViewItem();
197
198         if (pItem->HasElement(LIST_ITEM_RESERVED_ID_2))
199         {
200                 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_2);
201                 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete bitmap element.");
202         }
203
204         if (pItem->HasElement(LIST_ITEM_RESERVED_ID_3))
205         {
206                 ret = pItem->DeleteElement(LIST_ITEM_RESERVED_ID_3);
207                 SysTryReturn(NID_UI_CTRL, (ret == true), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to delete text element.");
208         }
209
210         FloatRectangle bitmapRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
211         FloatRectangle textRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
212         float leftMargin = 0.0f;
213         float itemHeight = GetItemSize().height;
214         float elementSpacing = 0.0f;
215         result r = E_SUCCESS;
216
217         GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_ELEMENT_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, leftMargin);
218
219         // Add Bitmap element (optional)
220         if (pBitmap != null)
221         {
222                 GET_SHAPE_CONFIG(LISTVIEW::GROUPITEM_ELEMENT_SPACING, _CONTROL_ORIENTATION_PORTRAIT, elementSpacing);
223
224                 float elementWidth = itemHeight * GROUP_ITEM_ELEMENT_BITMAP_SIZE_RATIO;
225                 float elementHeight = elementWidth;
226
227                 bitmapRect.x = leftMargin;
228                 bitmapRect.y = (itemHeight - elementHeight) / 2.0f;
229                 bitmapRect.width = elementWidth;
230                 bitmapRect.height = elementHeight;
231
232                 r = pItem->AddElement(bitmapRect, LIST_ITEM_RESERVED_ID_2, pBitmap);
233                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
234         }
235
236         // Add Text element
237         textRect.x = leftMargin + bitmapRect.width + elementSpacing;
238         textRect.y = 0;
239         textRect.width = GetItemSize().width - textRect.x;
240         textRect.height = itemHeight;
241
242         r = pItem->AddElement(textRect, LIST_ITEM_RESERVED_ID_3, text);
243         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
244
245         pItem->SetTextSize(LIST_ITEM_RESERVED_ID_3, __textSize);
246         pItem->SetTextAlignment(LIST_ITEM_RESERVED_ID_3, TEXT_OBJECT_ALIGNMENT_MIDDLE);
247
248         pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, __textColor, LISTVIEW_ITEM_STATUS_NORMAL);
249         pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, __textColor, LISTVIEW_ITEM_STATUS_PRESSED);
250         pItem->SetTextColor(LIST_ITEM_RESERVED_ID_3, __textColor, LISTVIEW_ITEM_STATUS_HIGHLIGHTED);
251
252         return E_SUCCESS;
253 }
254
255 }}} // Tizen::Ui::Controls