Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_ListItemBaseImpl.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_ListItemBaseImpl.cpp
20  * @brief       This is the implementation file for _ListItemBaseImpl class.
21  *
22  * This file contains the implementation of _ListItemBaseImpl class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlListItemBase.h>
27 #include <FGrp_BitmapImpl.h>
28 #include "FUi_CoordinateSystemUtils.h"
29 #include "FUi_ResourceManager.h"
30 #include "FUiCtrl_ListContextItemImpl.h"
31 #include "FUiCtrl_ListItemBaseImpl.h"
32 #include "FUiCtrl_ListViewContextItem.h"
33 #include "FUiCtrl_ListViewItem.h"
34 #include "FUiCtrl_UiListViewItemEvent.h"
35 #include "FUiCtrl_UiListViewItemEventArg.h"
36
37 #ifdef MEMORY_LEAK_CHECK
38 #include "mem_leak_check.h"
39 #endif
40
41 using namespace Tizen::Base;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Graphics::_Text;
44
45 namespace Tizen { namespace Ui { namespace Controls
46 {
47
48 _ListItemBaseImpl*
49 _ListItemBaseImpl::GetInstance(ListItemBase& listItemBase)
50 {
51         return listItemBase._pImpl;
52 }
53
54 const _ListItemBaseImpl*
55 _ListItemBaseImpl::GetInstance(const ListItemBase& listItemBase)
56 {
57         return listItemBase._pImpl;
58 }
59
60 _ListItemBaseImpl::_ListItemBaseImpl(ListItemBase* pPublic)
61         : __pPublic(pPublic)
62         , __pListViewItem(null)
63         , __style(LIST_ANNEX_STYLE_NORMAL)
64         , __pEvent(null)
65 {
66
67 }
68
69 _ListItemBaseImpl::~_ListItemBaseImpl(void)
70 {
71         if (__pListViewItem != null)
72         {
73                 _TableViewItem* pContextItem = __pListViewItem->GetContextItem();
74                 __pListViewItem->Release();
75
76                 if (pContextItem)
77                 {
78                         pContextItem->Release();
79                 }
80         }
81
82         delete __pEvent;
83         __pEvent = null;
84 }
85
86 const char*
87 _ListItemBaseImpl::GetPublicClassName(void) const
88 {
89         return "Tizen::Ui::Controls::ListItemBase";
90 }
91
92 const ListItemBase&
93 _ListItemBaseImpl::GetPublic(void) const
94 {
95         return static_cast <const ListItemBase&>(*__pPublic);
96 }
97
98 ListItemBase&
99 _ListItemBaseImpl::GetPublic(void)
100 {
101         return *__pPublic;
102 }
103
104 _ListItemBaseImpl*
105 _ListItemBaseImpl::CreateListItemBaseImplN(ListItemBase* pPublic, const FloatDimension& itemSize, ListAnnexStyle style)
106 {
107         _ListItemBaseImpl* pImpl = new (std::nothrow) _ListItemBaseImpl(pPublic);
108         SysTryReturn(NID_UI_CTRL, (pImpl != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
109
110         result r = pImpl->Construct(itemSize, style);
111         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
112
113         return pImpl;
114
115 CATCH:
116         delete pImpl;
117         pImpl = null;
118
119         return null;
120 }
121
122 result
123 _ListItemBaseImpl::Construct(const FloatDimension& itemSize, ListAnnexStyle style)
124 {
125         SysTryReturn(NID_UI_CTRL, (itemSize.width >= 0.0f) && (itemSize.height >= 0.0f), E_INVALID_ARG, E_INVALID_ARG,
126                         ("[E_INVALID_ARG] The item size should be greater than 0.0f"));
127
128         __pListViewItem = _ListViewItem::CreateListViewItemN(itemSize.height);
129         SysTryReturn(NID_UI_CTRL, (__pListViewItem != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
130
131         __pListViewItem->SetSize(itemSize);
132         __pListViewItem->SetBounds(FloatRectangle(0.0f, 0.0f, itemSize.width, itemSize.height));
133         __pListViewItem->SetBackgroundColor(Color(0, 0, 0, 0));
134         __pListViewItem->SetSelectionStyle(TABLE_VIEW_ITEM_SELECTION_STYLE_WHOLE);
135         __pListViewItem->GetAccessibilityContainer()->Activate(true);
136
137         __itemSize = itemSize;
138         __style = style;
139
140         return E_SUCCESS;
141 }
142
143 _ListViewItem*
144 _ListItemBaseImpl::GetListViewItem(void) const
145 {
146         return __pListViewItem;
147 }
148
149 FloatDimension
150 _ListItemBaseImpl::GetItemSize(void) const
151 {
152         return __itemSize;
153 }
154
155 result
156 _ListItemBaseImpl::SetBackgroundBitmap(ListItemDrawingStatus status, const Bitmap* pBitmap)
157 {
158         SysTryReturn(NID_UI_CTRL, (pBitmap != null), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] It is invalid argument.");
159
160         ListItemState itemState;
161
162         switch (status)
163         {
164         case LIST_ITEM_DRAWING_STATUS_NORMAL:
165                 itemState = LIST_ITEM_STATE_NORMAL;
166                 break;
167
168         case LIST_ITEM_DRAWING_STATUS_PRESSED:
169                 itemState = LIST_ITEM_STATE_PRESSED;
170                 break;
171
172         case LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED:
173                 itemState = LIST_ITEM_STATE_HIGHLIGHTED;
174                 break;
175
176         default:
177                 SysTryReturn(NID_UI_CTRL, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to set background image.");
178         }
179
180         bool ret = __pListViewItem->SetItemBackgroundBitmap(itemState, pBitmap);
181         __pListViewItem->SetItemChanged(ret);
182
183         return E_SUCCESS;
184 }
185
186 result
187 _ListItemBaseImpl::SetBackgroundColor(ListItemDrawingStatus status, const Color& color)
188 {
189         ListItemState itemState;
190
191         switch (status)
192         {
193         case LIST_ITEM_DRAWING_STATUS_NORMAL:
194                 itemState = LIST_ITEM_STATE_NORMAL;
195                 break;
196
197         case LIST_ITEM_DRAWING_STATUS_PRESSED:
198                 itemState = LIST_ITEM_STATE_PRESSED;
199                 break;
200
201         case LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED:
202                 itemState = LIST_ITEM_STATE_HIGHLIGHTED;
203                 break;
204
205         default:
206                 SysTryReturn(NID_UI_CTRL, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to set background color.");
207         }
208
209         __pListViewItem->SetItemBackgroundColor(itemState, color);
210         __pListViewItem->SetItemChanged(true);
211
212         return E_SUCCESS;
213 }
214
215 Color
216 _ListItemBaseImpl::GetBackgroundColor(ListItemDrawingStatus status) const
217 {
218         ListItemState itemState;
219
220         switch (status)
221         {
222         case LIST_ITEM_DRAWING_STATUS_NORMAL:
223                 itemState = LIST_ITEM_STATE_NORMAL;
224                 break;
225
226         case LIST_ITEM_DRAWING_STATUS_PRESSED:
227                 itemState = LIST_ITEM_STATE_PRESSED;
228                 break;
229
230         case LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED:
231                 itemState = LIST_ITEM_STATE_HIGHLIGHTED;
232                 break;
233
234         default:
235                 SysTryReturn(NID_UI_CTRL, false, Color(0), E_SYSTEM, "[E_SYSTEM] Unable to get background color.");
236         }
237
238         return __pListViewItem->GetItemBackgroundColor(itemState);
239 }
240
241 result
242 _ListItemBaseImpl::SetContextItem(const _ListContextItemImpl* pItem)
243 {
244         if (__pListViewItem->GetContextItem())
245         {
246                 __pListViewItem->GetContextItem()->Release();
247         }
248
249         if (pItem == null)
250         {
251                 __pListViewItem->SetContextItem(null);
252                 return E_SUCCESS;
253         }
254
255         _ListViewContextItem* pContextItem = const_cast<_ListContextItemImpl*>(pItem)->GetContextItem();
256
257         if (pContextItem != null)
258         {
259                 __pListViewItem->SetItemWidth(__itemSize.width);
260
261                 pContextItem->AddRef();
262
263                 __pListViewItem->SetContextItem(pContextItem);
264                 __pListViewItem->SetContextItemEventListener(*this);
265
266                 return E_SUCCESS;
267         }
268
269         return E_SYSTEM;
270 }
271
272 result
273 _ListItemBaseImpl::SetDescriptionText(const String& text)
274 {
275         SysTryReturn(NID_UI_CTRL, (__pListViewItem->SetDescriptionText(text) == true), E_SYSTEM, E_SYSTEM,
276                         ("[E_SYSTEM] Unable to set description text."));
277
278         return E_SUCCESS;
279 }
280
281 result
282 _ListItemBaseImpl::SetDescriptionTextColor(const Color& color)
283 {
284         __pListViewItem->SetDescriptionTextColor(color);
285
286         return E_SUCCESS;
287 }
288
289 float
290 _ListItemBaseImpl::GetAnnexWidth(ListAnnexStyle style)
291 {
292         TableViewAnnexStyle annexStyle = TABLE_VIEW_ANNEX_STYLE_NORMAL;
293
294         switch (style)
295         {
296         case LIST_ANNEX_STYLE_NORMAL:
297                 annexStyle = TABLE_VIEW_ANNEX_STYLE_NORMAL;
298                 break;
299
300         case LIST_ANNEX_STYLE_MARK:
301                 annexStyle = TABLE_VIEW_ANNEX_STYLE_MARK;
302                 break;
303
304         case LIST_ANNEX_STYLE_ONOFF_SLIDING:
305                 annexStyle = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
306                 break;
307
308         case LIST_ANNEX_STYLE_DETAILED:
309                 annexStyle = TABLE_VIEW_ANNEX_STYLE_DETAILED;
310                 break;
311
312         case LIST_ANNEX_STYLE_RADIO:
313                 annexStyle = TABLE_VIEW_ANNEX_STYLE_RADIO;
314                 break;
315
316         case LIST_ANNEX_STYLE_ONOFF_SLIDING_WITH_DIVIDER:
317                 annexStyle = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING_WITH_DIVIDER;
318                 break;
319
320         default:
321                 break;
322         }
323
324         return _TableViewItem::GetAnnexWidth(annexStyle);
325 }
326
327 ListAnnexStyle
328 _ListItemBaseImpl::GetListItemAnnexStyle(void)
329 {
330         return __style;
331 }
332
333 bool
334 _ListItemBaseImpl::SetTextColor(int elementId, Color textColor)
335 {
336         bool ret = __pListViewItem->SetTextColor(elementId, textColor);
337         __pListViewItem->SetItemChanged(ret);
338
339         return ret;
340 }
341
342 bool
343 _ListItemBaseImpl::GetTextColor(int elementId, Color& textColor) const
344 {
345         return __pListViewItem->GetTextColor(elementId, textColor);
346 }
347
348 void
349 _ListItemBaseImpl::AddListViewItemEventListener(_IUiListViewItemEventListener& listener)
350 {
351         if (__pEvent == null)
352         {
353                 __pEvent = new (std::nothrow) _UiListViewItemEvent();
354                 SysTryReturnVoidResult(NID_UI_CTRL, __pEvent != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
355         }
356
357         __pEvent->AddListener(listener);
358 }
359
360 void
361 _ListItemBaseImpl::RemoveListViewItemEventListener(_IUiListViewItemEventListener& listener)
362 {
363         if (__pEvent != null)
364         {
365                 __pEvent->RemoveListener(listener);
366         }
367 }
368
369 void
370 _ListItemBaseImpl::OnActionPerformed(const _Control& source, int actionId)
371 {
372         if (__pEvent != null)
373         {
374                 int groupIndex = -1;
375                 int itemIndex = -1;
376
377                 __pListViewItem->GetItemIndex(groupIndex, itemIndex);
378                 __pEvent->SetSource(__pListViewItem);
379
380                 _UiListViewItemEventArg* pArg = new (std::nothrow) _UiListViewItemEventArg(groupIndex, itemIndex, actionId, NOTIFY_TYPE_CONTEXTITEM_SELCTED);
381                 __pEvent->Fire(*pArg);
382         }
383 }
384
385 }}} // Tizen::Ui::Controls