remove APIs to apply [ACR][03/30][Remove] Remove APIs in Tizen::Ui namespace
[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 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_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                 __pListViewItem->Release();
74         }
75
76         delete __pEvent;
77         __pEvent = null;
78 }
79
80 const char*
81 _ListItemBaseImpl::GetPublicClassName(void) const
82 {
83         return "Tizen::Ui::Controls::ListItemBase";
84 }
85
86 const ListItemBase&
87 _ListItemBaseImpl::GetPublic(void) const
88 {
89         return static_cast <const ListItemBase&>(*__pPublic);
90 }
91
92 ListItemBase&
93 _ListItemBaseImpl::GetPublic(void)
94 {
95         return *__pPublic;
96 }
97
98 _ListItemBaseImpl*
99 _ListItemBaseImpl::CreateListItemBaseImplN(ListItemBase* pPublic, const FloatDimension& itemSize, ListAnnexStyle style)
100 {
101         _ListItemBaseImpl* pImpl = new (std::nothrow) _ListItemBaseImpl(pPublic);
102         SysTryReturn(NID_UI_CTRL, (pImpl != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
103
104         result r = pImpl->Construct(itemSize, style);
105         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
106
107         return pImpl;
108
109 CATCH:
110         delete pImpl;
111         pImpl = null;
112
113         return null;
114 }
115
116 result
117 _ListItemBaseImpl::Construct(const FloatDimension& itemSize, ListAnnexStyle style)
118 {
119         SysTryReturn(NID_UI_CTRL, (itemSize.width >= 0.0f) && (itemSize.height >= 0.0f), E_INVALID_ARG, E_INVALID_ARG,
120                         ("[E_INVALID_ARG] The item size should be greater than 0.0f"));
121
122         __pListViewItem = _ListViewItem::CreateListViewItemN(itemSize.height);
123         SysTryReturn(NID_UI_CTRL, (__pListViewItem != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
124
125         __pListViewItem->SetSize(itemSize);
126         __pListViewItem->SetBounds(FloatRectangle(0.0f, 0.0f, itemSize.width, itemSize.height));
127         __pListViewItem->SetBackgroundColor(Color(0, 0, 0, 0));
128         __pListViewItem->SetSelectionStyle(TABLE_VIEW_ITEM_SELECTION_STYLE_WHOLE);
129
130         __itemSize = itemSize;
131         __style = style;
132
133         return E_SUCCESS;
134 }
135
136 _ListViewItem*
137 _ListItemBaseImpl::GetListViewItem(void) const
138 {
139         return __pListViewItem;
140 }
141
142 FloatDimension
143 _ListItemBaseImpl::GetItemSize(void) const
144 {
145         return __itemSize;
146 }
147
148 result
149 _ListItemBaseImpl::SetBackgroundBitmap(ListItemDrawingStatus status, const Bitmap* pBitmap)
150 {
151         SysTryReturn(NID_UI_CTRL, (pBitmap != null), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] It is invalid argument.");
152
153         ListItemState itemState;
154
155         switch (status)
156         {
157         case LIST_ITEM_DRAWING_STATUS_NORMAL:
158                 itemState = LIST_ITEM_STATE_NORMAL;
159                 break;
160
161         case LIST_ITEM_DRAWING_STATUS_PRESSED:
162                 itemState = LIST_ITEM_STATE_PRESSED;
163                 break;
164
165         case LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED:
166                 itemState = LIST_ITEM_STATE_HIGHLIGHTED;
167                 break;
168
169         default:
170                 SysTryReturn(NID_UI_CTRL, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to set background image.");
171         }
172
173         bool ret = __pListViewItem->SetItemBackgroundBitmap(itemState, pBitmap);
174         __pListViewItem->SetItemChanged(ret);
175
176         return E_SUCCESS;
177 }
178
179 result
180 _ListItemBaseImpl::SetBackgroundColor(ListItemDrawingStatus status, const Color& color)
181 {
182         ListItemState itemState;
183
184         switch (status)
185         {
186         case LIST_ITEM_DRAWING_STATUS_NORMAL:
187                 itemState = LIST_ITEM_STATE_NORMAL;
188                 break;
189
190         case LIST_ITEM_DRAWING_STATUS_PRESSED:
191                 itemState = LIST_ITEM_STATE_PRESSED;
192                 break;
193
194         case LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED:
195                 itemState = LIST_ITEM_STATE_HIGHLIGHTED;
196                 break;
197
198         default:
199                 SysTryReturn(NID_UI_CTRL, false, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to set background color.");
200         }
201
202         __pListViewItem->SetItemBackgroundColor(itemState, color);
203         __pListViewItem->SetItemChanged(true);
204
205         return E_SUCCESS;
206 }
207
208 Color
209 _ListItemBaseImpl::GetBackgroundColor(ListItemDrawingStatus status) const
210 {
211         ListItemState itemState;
212
213         switch (status)
214         {
215         case LIST_ITEM_DRAWING_STATUS_NORMAL:
216                 itemState = LIST_ITEM_STATE_NORMAL;
217                 break;
218
219         case LIST_ITEM_DRAWING_STATUS_PRESSED:
220                 itemState = LIST_ITEM_STATE_PRESSED;
221                 break;
222
223         case LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED:
224                 itemState = LIST_ITEM_STATE_HIGHLIGHTED;
225                 break;
226
227         default:
228                 SysTryReturn(NID_UI_CTRL, false, Color(0), E_SYSTEM, "[E_SYSTEM] Unable to get background color.");
229         }
230
231         return __pListViewItem->GetItemBackgroundColor(itemState);
232 }
233
234 result
235 _ListItemBaseImpl::SetContextItem(const _ListContextItemImpl* pItem)
236 {
237         if (pItem == null)
238         {
239                 __pListViewItem->SetContextItem(null);
240                 return E_SUCCESS;
241         }
242
243         _ListViewContextItem* pContextItem = const_cast<_ListContextItemImpl*>(pItem)->GetContextItem();
244
245         if (pContextItem != null)
246         {
247                 __pListViewItem->SetItemWidth(__itemSize.width);
248                 __pListViewItem->SetContextItem(pContextItem);
249                 __pListViewItem->SetContextItemEventListener(*this);
250
251                 return E_SUCCESS;
252         }
253
254         return E_SYSTEM;
255 }
256
257 result
258 _ListItemBaseImpl::SetDescriptionText(const String& text)
259 {
260         SysTryReturn(NID_UI_CTRL, (__pListViewItem->SetDescriptionText(text) == true), E_SYSTEM, E_SYSTEM,
261                         ("[E_SYSTEM] Unable to set description text."));
262
263         return E_SUCCESS;
264 }
265
266 result
267 _ListItemBaseImpl::SetDescriptionTextColor(const Color& color)
268 {
269         __pListViewItem->SetDescriptionTextColor(color);
270
271         return E_SUCCESS;
272 }
273
274 float
275 _ListItemBaseImpl::GetAnnexWidth(ListAnnexStyle style)
276 {
277         float annexWidth = 0.0f;
278
279         switch (style)
280         {
281         case LIST_ANNEX_STYLE_NORMAL:
282                 annexWidth = 0.0f;
283                 break;
284
285         case LIST_ANNEX_STYLE_MARK:
286                 GET_SHAPE_CONFIG(TABLEVIEW::ITEM_ANNEX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, annexWidth);
287                 break;
288
289         case LIST_ANNEX_STYLE_ONOFF_SLIDING:
290                 GET_SHAPE_CONFIG(TABLEVIEW::ITEM_ANNEX_ONOFF_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, annexWidth);
291                 break;
292
293         case LIST_ANNEX_STYLE_DETAILED:
294                 GET_SHAPE_CONFIG(TABLEVIEW::ITEM_ANNEX_MORE_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, annexWidth);
295                 break;
296
297         case LIST_ANNEX_STYLE_RADIO:
298                 GET_SHAPE_CONFIG(TABLEVIEW::ITEM_ANNEX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, annexWidth);
299                 break;
300
301         case LIST_ANNEX_STYLE_ONOFF_SLIDING_WITH_DIVIDER:
302                 GET_SHAPE_CONFIG(TABLEVIEW::ITEM_ANNEX_ONOFF_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, annexWidth);
303                 break;
304
305         default:
306                 break;
307         }
308
309         return annexWidth;
310 }
311
312 ListAnnexStyle
313 _ListItemBaseImpl::GetListItemAnnexStyle(void)
314 {
315         return __style;
316 }
317
318 bool
319 _ListItemBaseImpl::SetTextColor(int elementId, Color textColor)
320 {
321         bool ret = __pListViewItem->SetTextColor(elementId, textColor);
322         __pListViewItem->SetItemChanged(ret);
323
324         return ret;
325 }
326
327 bool
328 _ListItemBaseImpl::GetTextColor(int elementId, Color& textColor) const
329 {
330         return __pListViewItem->GetTextColor(elementId, textColor);
331 }
332
333 void
334 _ListItemBaseImpl::AddListViewItemEventListener(_IUiListViewItemEventListener& listener)
335 {
336         if (__pEvent == null)
337         {
338                 __pEvent = new (std::nothrow) _UiListViewItemEvent();
339                 SysTryReturnVoidResult(NID_UI_CTRL, __pEvent != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
340         }
341
342         __pEvent->AddListener(listener);
343 }
344
345 void
346 _ListItemBaseImpl::RemoveListViewItemEventListener(_IUiListViewItemEventListener& listener)
347 {
348         if (__pEvent != null)
349         {
350                 __pEvent->RemoveListener(listener);
351         }
352 }
353
354 void
355 _ListItemBaseImpl::OnActionPerformed(const _Control& source, int actionId)
356 {
357         if (__pEvent != null)
358         {
359                 int groupIndex = -1;
360                 int itemIndex = -1;
361
362                 __pListViewItem->GetItemIndex(groupIndex, itemIndex);
363                 __pEvent->SetSource(__pListViewItem);
364
365                 _UiListViewItemEventArg* pArg = new (std::nothrow) _UiListViewItemEventArg(groupIndex, itemIndex, actionId, NOTIFY_TYPE_CONTEXTITEM_SELCTED);
366                 __pEvent->Fire(*pArg);
367         }
368 }
369
370 }}} // Tizen::Ui::Controls