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