Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_GroupedListViewImpl.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_GroupedListViewImpl.cpp
20  * @brief   This is the implementation file for
21  *        _GroupedListViewImpl class.
22  *
23  * This file contains the implementation of _GroupedListViewImpl
24  * class.
25  */
26
27 #include <FUiCtrlGroupedListView.h>
28 #include <FBaseSysLog.h>
29 #include <FGrp_TextTextSimple.h>
30 #include "FApp_AppInfo.h"
31 #include "FUi_ResourceManager.h"
32 #include "FUi_TouchManager.h"
33 #include "FUi_UiBuilder.h"
34 #include "FUiCtrl_FastScrollEvent.h"
35 #include "FUiCtrl_FastScrollEventArg.h"
36 #include "FUiCtrl_Label.h"
37 #include "FUiCtrl_GroupedListViewImpl.h"
38 #include "FUiCtrl_GroupedListViewItemProviderAdaptor.h"
39 #include "FUiCtrl_ListItemEvent.h"
40 #include "FUiCtrl_ListItemEventArg.h"
41 #include "FUiCtrl_ListViewItem.h"
42 #include "FUiCtrl_PublicLinkEvent.h"
43 #include "FUiCtrl_ScrollEvent.h"
44 #include "FUiCtrl_ScrollEventArg.h"
45
46 #ifdef MEMORY_LEAK_CHECK
47 #include "mem_leak_check.h"
48 #endif
49
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::Base::Runtime;
53 using namespace Tizen::Graphics;
54 using namespace Tizen::Graphics::_Text;
55
56 namespace Tizen { namespace Ui { namespace Controls
57 {
58
59 _GroupedListViewImpl*
60 _GroupedListViewImpl::GetInstance(GroupedListView& groupedListView)
61 {
62         return static_cast <_GroupedListViewImpl*>(groupedListView._pControlImpl);
63 }
64
65 const _GroupedListViewImpl*
66 _GroupedListViewImpl::GetInstance(const GroupedListView& groupedListView)
67 {
68         return static_cast <const _GroupedListViewImpl*>(groupedListView._pControlImpl);
69 }
70
71 _GroupedListViewImpl::_GroupedListViewImpl(GroupedListView* pGroupedList, _TableView* pCore)
72         : _ControlImpl(pGroupedList, pCore)
73         , __pListItemEvent(null)
74         , __pLinkEvent(null)
75         , __pScrollEvent(null)
76         , __pFastScrollEvent(null)
77         , __pEmptyBitmap(null)
78         , __pEmptyText(null)
79         , __redrawListView(true)
80         , __pItemNeedsLazyDeletion(null)
81         , __pItemSwept(null)
82 {
83         GET_COLOR_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_NORMAL, __emptyTextColor);
84 }
85
86 _GroupedListViewImpl::~_GroupedListViewImpl()
87 {
88         if (__pListItemEvent != null)
89         {
90                 delete __pListItemEvent;
91                 __pListItemEvent = null;
92         }
93
94         if (__pLinkEvent != null)
95         {
96                 delete __pLinkEvent;
97                 __pLinkEvent = null;
98         }
99
100         if (__pScrollEvent != null)
101         {
102                 delete __pScrollEvent;
103                 __pScrollEvent = null;
104         }
105
106         if (__pFastScrollEvent != null)
107         {
108                 delete __pFastScrollEvent;
109                 __pFastScrollEvent = null;
110         }
111
112         if (__pEmptyBitmap != null)
113         {
114                 GetCore().DetachChild(*__pEmptyBitmap);
115
116                 delete __pEmptyBitmap;
117                 __pEmptyBitmap = null;
118         }
119
120         if (__pEmptyText != null)
121         {
122                 GetCore().DetachChild(*__pEmptyText);
123
124                 delete __pEmptyText;
125                 __pEmptyText = null;
126         }
127 }
128
129 const char*
130 _GroupedListViewImpl::GetPublicClassName(void) const
131 {
132         return "Tizen::Ui::Controls::GroupedListView";
133 }
134
135 const GroupedListView&
136 _GroupedListViewImpl::GetPublic(void) const
137 {
138         return static_cast <const GroupedListView&>(_ControlImpl::GetPublic());
139 }
140
141 GroupedListView&
142 _GroupedListViewImpl::GetPublic(void)
143 {
144         return static_cast <GroupedListView&>(_ControlImpl::GetPublic());
145 }
146
147 const _TableView&
148 _GroupedListViewImpl::GetCore(void) const
149 {
150         return static_cast <const _TableView&>(_ControlImpl::GetCore());
151 }
152
153 _TableView&
154 _GroupedListViewImpl::GetCore(void)
155 {
156         return static_cast <_TableView&>(_ControlImpl::GetCore());
157 }
158
159 _GroupedListViewImpl*
160 _GroupedListViewImpl::CreateGroupedListViewImplN(GroupedListView* pControl, GroupedListViewStyle style, bool itemDivider, ListScrollStyle scrollStyle)
161 {
162         result r = E_SUCCESS;
163         TableViewScrollBarStyle scrollBarStyle;
164
165         switch (scrollStyle)
166         {
167         case SCROLL_STYLE_FADE_OUT:
168                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT;
169                 break;
170         case SCROLL_STYLE_FIXED:
171                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FIXED;
172                 break;
173         case SCROLL_STYLE_FAST_SCROLL:
174                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL;
175                 break;
176         case SCROLL_STYLE_JUMP_TO_TOP:
177                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_JUMP_TO_TOP;
178                 break;
179         case SCROLL_STYLE_THUMB:
180                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_THUMB;
181                 break;
182         default:
183                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_NONE;
184                 break;
185         }
186
187         TableViewStyle tableViewStyle = ((style == GROUPED_LIST_VIEW_STYLE_SECTION) ? TABLE_VIEW_STYLE_SECTION : TABLE_VIEW_STYLE_GROUPED);
188
189         _TableView* pCore = _TableView::CreateTableViewN(tableViewStyle, itemDivider, scrollBarStyle);
190         SysTryReturn(NID_UI_CTRL, (pCore != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
191
192         _GroupedListViewImpl* pImpl = new (std::nothrow) _GroupedListViewImpl(pControl, pCore);
193
194         r = CheckConstruction(pCore, pImpl);
195         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
196
197         return pImpl;
198 }
199
200 result
201 _GroupedListViewImpl::SetItemProvider(IGroupedListViewItemProvider& provider)
202 {
203         result r = E_SUCCESS;
204         int itemWidth = GetCore().GetBounds().width;
205
206         if (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION)
207         {
208                 int margin = 0;
209                 GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, margin);
210
211                 itemWidth -= (margin * 2);
212         }
213
214         _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
215                         static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
216
217         if (pProviderAdaptor == null)
218         {
219                 pProviderAdaptor = new (std::nothrow) _GroupedListViewItemProviderAdaptor(provider);
220                 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
221                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
222
223                 pProviderAdaptor->SetListViewItemEventListener(*this);
224
225                 r = pProviderAdaptor->SetListWidth(itemWidth);
226                 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
227         }
228         else
229         {
230                 pProviderAdaptor->SetItemProvider(provider);
231                 r = pProviderAdaptor->SetListWidth(itemWidth);
232
233                 UpdateList();
234         }
235
236         __redrawListView = true;
237
238         SetLastResultReturn(r);
239 }
240
241 void
242 _GroupedListViewImpl::AddGroupedListViewItemEventListener(IGroupedListViewItemEventListener& listener)
243 {
244         result r = E_SUCCESS;
245
246         if (__pListItemEvent == null)
247         {
248                 __pListItemEvent = new (std::nothrow) _ListItemEvent();
249                 SysTryReturnVoidResult(NID_UI_CTRL, (__pListItemEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
250
251                 r = __pListItemEvent->Construct(GetPublic(), CLASSNAME_GROUPEDLISTVIEW);
252                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Item Event.");
253         }
254
255         __pListItemEvent->AddListener(listener);
256
257         r = GetCore().AddGroupedTableViewItemEventListener(*this);
258
259         SetLastResult(r);
260 }
261
262 void
263 _GroupedListViewImpl::RemoveGroupedListViewItemEventListener(IGroupedListViewItemEventListener& listener)
264 {
265         result r = E_SUCCESS;
266
267         if (__pListItemEvent != null)
268         {
269                 r = __pListItemEvent->RemoveListener(listener);
270         }
271
272         SetLastResult(r);
273 }
274
275 void
276 _GroupedListViewImpl::AddFastScrollListener(IFastScrollListener& listener)
277 {
278         result r = E_SUCCESS;
279
280         if (__pFastScrollEvent == null)
281         {
282                 __pFastScrollEvent = new (std::nothrow) _FastScrollEvent();
283                 SysTryReturnVoidResult(NID_UI_CTRL, (__pFastScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
284
285                 r = __pFastScrollEvent->Construct(GetPublic());
286                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct FastScroll Event.");
287         }
288
289         __pFastScrollEvent->AddListener(listener);
290
291         r = GetCore().AddFastScrollListener(*this);
292
293         SetLastResult(r);
294 }
295
296 void
297 _GroupedListViewImpl::RemoveFastScrollListener(IFastScrollListener& listener)
298 {
299         result r = E_SUCCESS;
300
301         if (__pFastScrollEvent != null)
302         {
303                 r = __pFastScrollEvent->RemoveListener(listener);
304         }
305
306         SetLastResult(r);
307 }
308
309 void
310 _GroupedListViewImpl::AddScrollEventListener(IScrollEventListener& listener)
311 {
312         result r = E_SUCCESS;
313
314         if (__pScrollEvent == null)
315         {
316                 __pScrollEvent = new (std::nothrow) _ScrollEvent();
317                 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
318
319                 r = __pScrollEvent->Construct(GetPublic());
320                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
321         }
322
323         __pScrollEvent->AddListener(listener);
324
325         GetCore().AddScrollEventListener(*this);
326
327         SetLastResult(r);
328 }
329
330 void
331 _GroupedListViewImpl::RemoveScrollEventListener(IScrollEventListener& listener)
332 {
333         result r = E_SUCCESS;
334
335         if (__pScrollEvent != null)
336         {
337                 r = __pScrollEvent->RemoveListener(listener);
338         }
339
340         SetLastResult(r);
341 }
342
343 void
344 _GroupedListViewImpl::AddUiLinkEventListener(const IUiLinkEventListener& listener)
345 {
346         result r = E_SUCCESS;
347
348         if (__pLinkEvent == null)
349         {
350                 __pLinkEvent = _PublicLinkEvent::CreateInstanceN(GetPublic());
351                 SysTryReturnVoidResult(NID_UI, (__pLinkEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
352         }
353
354         r = __pLinkEvent->AddListener(listener);
355
356         SetLastResult(r);
357 }
358
359 void
360 _GroupedListViewImpl::RemoveUiLinkEventListener(const IUiLinkEventListener& listener)
361 {
362         result r = E_SUCCESS;
363
364         if (__pLinkEvent != null)
365         {
366                 r = __pLinkEvent->RemoveListener(listener);
367         }
368
369         SetLastResult(r);
370 }
371
372 result
373 _GroupedListViewImpl::SetSweepEnabled(bool enable)
374 {
375         GetCore().SetSweepEnabled(enable);
376
377         SetLastResultReturn(E_SUCCESS);
378 }
379
380 result
381 _GroupedListViewImpl::SetFastScrollIndex(const String& text, bool useSearchIcon)
382 {
383         result r = GetCore().SetFastScrollIndex(text, useSearchIcon);
384         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS) || (r == E_SYSTEM), E_INVALID_STATE, E_INVALID_STATE,
385                         "[E_INVALID_STATE] This instance is in an invalid state.");
386
387         SetLastResultReturn(r);
388 }
389
390 result
391 _GroupedListViewImpl::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
392 {
393         return GetCore().GetTopDrawnItemIndex(groupIndex, itemIndex);
394 }
395
396 result
397 _GroupedListViewImpl::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
398 {
399         return GetCore().GetBottomDrawnItemIndex(groupIndex, itemIndex);
400 }
401
402 result
403 _GroupedListViewImpl::ScrollToItem(int groupIndex, int itemIndex, ListScrollItemAlignment itemAlignment)
404 {
405         result r = E_SUCCESS;
406
407         if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_TOP)
408         {
409                 r = GetCore().SetTopDrawnItemIndex(groupIndex, itemIndex);
410         }
411         else if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_BOTTOM)
412         {
413                 r = GetCore().SetBottomDrawnItemIndex(groupIndex, itemIndex);
414         }
415         else
416         {
417                 SysTryReturn(NID_UI_CTRL, false, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
418                                         "[E_OUT_OF_RANGE] The specified itemAlignment is out of range.");
419         }
420
421         SetLastResultReturn(r);
422 }
423
424 result
425 _GroupedListViewImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
426 {
427         return GetCore().SetItemChecked(groupIndex, itemIndex, check);
428 }
429
430 bool
431 _GroupedListViewImpl::IsItemChecked(int groupIndex, int itemIndex) const
432 {
433         return GetCore().IsItemChecked(groupIndex, itemIndex);
434 }
435
436 result
437 _GroupedListViewImpl::SetItemEnabled(int groupIndex, int itemIndex, bool enable)
438 {
439         return GetCore().SetItemEnabled(groupIndex, itemIndex, enable);
440 }
441
442 bool
443 _GroupedListViewImpl::IsItemEnabled(int groupIndex, int itemIndex) const
444 {
445         return GetCore().IsItemEnabled(groupIndex, itemIndex);
446 }
447
448 int
449 _GroupedListViewImpl::GetGroupCount(void) const
450 {
451         return GetCore().GetGroupCount();
452 }
453
454 int
455 _GroupedListViewImpl::GetItemCountAt(int groupIndex) const
456 {
457         return GetCore().GetItemCountAt(groupIndex);
458 }
459
460 result
461 _GroupedListViewImpl::ShowItemDescriptionText(int groupIndex, int itemIndex)
462 {
463         return SetItemDescriptionTextShowState(groupIndex, itemIndex, true);
464 }
465
466 result
467 _GroupedListViewImpl::HideItemDescriptionText(int groupIndex, int itemIndex)
468 {
469         return SetItemDescriptionTextShowState(groupIndex, itemIndex, false);
470 }
471
472 result
473 _GroupedListViewImpl::SetItemDescriptionTextShowState(int groupIndex, int itemIndex, bool show)
474 {
475         result r = E_SUCCESS;
476
477         SysTryReturn(NID_UI_CTRL, (groupIndex >= 0) && (groupIndex < GetGroupCount()), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
478                         "[E_OUT_OF_RANGE] The specified groupIndex is out of range.");
479
480         SysTryReturn(NID_UI_CTRL, (itemIndex >= 0) && (itemIndex < GetItemCountAt(groupIndex)), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
481                         "[E_OUT_OF_RANGE] The specified itemIndex is out of range.");
482
483         _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
484                         static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
485         SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] _GroupedListItemProviderAdaptor is not set.");
486
487         // Save description text show state to provider adaptor
488         pProviderAdaptor->SetDescriptionTextShowState(groupIndex, itemIndex, show);
489
490         if (GetCore().FindItem(groupIndex, itemIndex) != null)
491         {
492                 r = GetCore().RefreshTableView(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
493         }
494
495         SetLastResultReturn(r);
496 }
497
498 result
499 _GroupedListViewImpl::RefreshList(int groupIndex, int itemIndex, ListRefreshType type)
500 {
501         result r = E_SUCCESS;
502
503         int groupCount = GetCore().GetGroupCount();
504         int itemCount = GetCore().GetItemCountAt(groupIndex);
505
506         if ((groupIndex < 0) || (groupIndex > groupCount) ||
507                 (itemIndex < -1) || (itemIndex > itemCount) ||
508                 ((type != LIST_REFRESH_TYPE_ITEM_ADD) && (itemIndex == itemCount)))
509         {
510                 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
511                 return E_OUT_OF_RANGE;
512         }
513
514         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
515
516         // for lazy delete item
517         if ((__pItemNeedsLazyDeletion != null) && (type != LIST_REFRESH_TYPE_ITEM_ADD))
518         {
519                 if (__pItemNeedsLazyDeletion == pListViewItem)
520                 {
521                         _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
522                                         static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
523
524                         if (pProviderAdaptor != null)
525                         {
526                                 pProviderAdaptor->SetItemNeedsLazyDeletion(__pItemNeedsLazyDeletion);
527                         }
528                 }
529         }
530
531         if ((__pItemSwept != null) && (type != LIST_REFRESH_TYPE_ITEM_ADD))
532         {
533                 if (__pItemSwept == pListViewItem)
534                 {
535                         GetCore().ResetSweepItem();
536                 }
537         }
538
539         if (type == LIST_REFRESH_TYPE_ITEM_MODIFY)
540         {
541                 int topGroupIndex = -1;
542                 int topItemIndex = -1;
543                 int bottomGroupIndex = -1;
544                 int bottomItemIndex = -1;
545
546                 GetCore().GetFirstLoadedItemIndex(topGroupIndex, topItemIndex);
547                 GetCore().GetLastLoadedItemIndex(bottomGroupIndex, bottomItemIndex);
548
549                 if ((topGroupIndex > groupIndex) || (bottomGroupIndex < groupIndex)
550                         || ((topGroupIndex == groupIndex) && (topItemIndex > itemIndex))
551                         || ((bottomGroupIndex == groupIndex) && (bottomItemIndex < itemIndex)))
552                 {
553                         // not yet loaded item
554                         SetLastResultReturn(r);
555                 }
556                 else
557                 {
558                         TableViewItemDrawingStatus itemDrawingStatus = TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL;
559                         bool itemSelected = false;
560                         Point touchPosition(-1, -1);
561
562                         if (pListViewItem != null)
563                         {
564                                 itemDrawingStatus = pListViewItem->GetDrawingStatus();
565                                 itemSelected = pListViewItem->GetSelectionState();
566                                 touchPosition = pListViewItem->GetLastTouchPressedPosition();
567
568                                 pListViewItem = null;
569                         }
570
571                         GetCore().UnloadItem(groupIndex, itemIndex);
572                         GetCore().LoadItem(groupIndex, itemIndex);
573
574                         pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
575
576                         if ((pListViewItem != null) && (itemDrawingStatus != TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL))
577                         {
578                                 pListViewItem->SetDrawingStatus(itemDrawingStatus);
579                                 pListViewItem->SetSelectionState(itemSelected);
580                                 pListViewItem->SetLastTouchPressedPosition(touchPosition);
581
582                                 // for create Annex
583                                 pListViewItem->Draw();
584                                 pListViewItem->Show();
585
586                                 _Control* target = static_cast<_Control*>(pListViewItem);
587
588                                 for (int i = 0; i < pListViewItem->GetChildCount(); i++)
589                                 {
590                                         if (pListViewItem->GetChild(i)->GetBounds().Contains(touchPosition))
591                                         {
592                                                 target = pListViewItem->GetChild(i);
593                                         }
594                                 }
595
596                                 if (target != null)
597                                 {
598                                         target->SetChangingEventTarget(true);
599                                 }
600                                 else
601                                 {
602                                         pListViewItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
603                                         pListViewItem->SetSelectionState(false);
604                                 }
605                         }
606                 }
607         }
608         else
609         {
610                 r = GetCore().RefreshTableView(groupIndex, itemIndex, static_cast<TableViewRefreshType>(type));
611         }
612
613         CheckEmptyListShowState();
614
615         Draw();
616         Show();
617
618         SetLastResultReturn(r);
619 }
620
621 result
622 _GroupedListViewImpl::RefreshList(int groupIndex, int itemIndex, int elementId)
623 {
624         if ((groupIndex < 0) || (groupIndex >= GetCore().GetGroupCount()) || (itemIndex < 0) || (itemIndex >= GetCore().GetItemCountAt(groupIndex)))
625         {
626                 return E_OUT_OF_RANGE;
627         }
628
629         result r = E_SUCCESS;
630         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
631
632         if (pListViewItem != null)
633         {
634                 r = (pListViewItem->RefreshElement(elementId)) ? E_SUCCESS : E_OUT_OF_RANGE;
635         }
636
637         SetLastResultReturn(r);
638 }
639
640 result
641 _GroupedListViewImpl::UpdateList(void)
642 {
643         // for lazy delete item
644         if (__pItemNeedsLazyDeletion != null)
645         {
646                 _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
647                                 static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
648
649                 if (pProviderAdaptor != null)
650                 {
651                         pProviderAdaptor->SetItemNeedsLazyDeletion(__pItemNeedsLazyDeletion);
652                 }
653         }
654
655         result r = GetCore().UpdateTableView();
656
657         CheckEmptyListShowState();
658
659         Invalidate(true);
660
661         // API versioning for initial Show() operation
662         if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
663         {
664                 Show();
665         }
666
667         SetLastResultReturn(r);
668 }
669
670 result
671 _GroupedListViewImpl::GetItemIndexFromPosition(const Point& position, int& groupIndex, int& itemIndex) const
672 {
673         result r = GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
674         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] There is no item at the specified position.");
675
676         SetLastResultReturn(r);
677 }
678
679 result
680 _GroupedListViewImpl::GetItemIndexFromPosition(const Point& position, int& groupIndex, int& itemIndex, int& elementId) const
681 {
682         elementId = -1;
683
684         result r =  GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
685         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] There is no item at the specified position.");
686
687         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
688
689         if (pListViewItem != null)
690         {
691                 Point originPosition = pListViewItem->GetPosition();
692                 originPosition.y -= GetCore().GetScrollPosition();
693
694                 elementId = pListViewItem->GetElementIdFromPosition(Point(position.x - originPosition.x, position.y - originPosition.y));
695         }
696
697         SetLastResultReturn(r);
698 }
699
700 result
701 _GroupedListViewImpl::SetSectionColor(const Color& color)
702 {
703         return GetCore().SetSectionColor(color);
704 }
705
706 Color
707 _GroupedListViewImpl::GetSectionColor(void) const
708 {
709         return GetCore().GetSectionColor();
710 }
711
712 result
713 _GroupedListViewImpl::SetItemDividerColor(const Color& color)
714 {
715         return GetCore().SetItemDividerColor(color);
716 }
717
718 Color
719 _GroupedListViewImpl::GetItemDividerColor(void) const
720 {
721         return GetCore().GetItemDividerColor();
722 }
723
724 void
725 _GroupedListViewImpl::SetListBackgroundColor(const Color& color)
726 {
727         SetBackgroundColor(color);
728 }
729
730 result
731 _GroupedListViewImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
732 {
733         GetCore().SetBackgroundBitmap(const_cast<Bitmap*>(pBitmap));
734         GetCore().SetBackgroundBitmapStretch(true);
735
736         SetLastResultReturn(E_SUCCESS);
737 }
738
739 result
740 _GroupedListViewImpl::SetBitmapOfEmptyList(const Bitmap* pBitmap)
741 {
742         if (pBitmap == null)
743         {
744                 if (__pEmptyBitmap != null)
745                 {
746                         GetCore().DetachChild(*__pEmptyBitmap);
747
748                         delete __pEmptyBitmap;
749                         __pEmptyBitmap = null;
750                 }
751         }
752         else
753         {
754                 if (__pEmptyBitmap == null)
755                 {
756                         __pEmptyBitmap = _Label::CreateLabelN();
757                         SysTryReturn(NID_UI_CTRL, (__pEmptyBitmap != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
758
759                         __pEmptyBitmap->SetVisibleState(false);
760                         __pEmptyBitmap->SetMargin(0, 0);
761
762                         GetCore().AttachChild(*__pEmptyBitmap);
763                 }
764
765                 Dimension bitmapSize(pBitmap->GetWidth(), pBitmap->GetHeight());
766                 Dimension listDimension = GetCore().GetSize();
767                 Dimension labelDimension;
768
769                 labelDimension.width = ((listDimension.width < bitmapSize.width) ? listDimension.width : bitmapSize.width);
770                 labelDimension.height = ((listDimension.height < bitmapSize.height) ? listDimension.height : bitmapSize.height);
771
772                 __pEmptyBitmap->SetSize(labelDimension);
773                 __pEmptyBitmap->SetBackgroundColor(Color(0, 0, 0, 0));
774                 __pEmptyBitmap->SetBackgroundBitmap(*pBitmap);
775         }
776
777         AdjustLayoutOfEmptyList();
778
779         SetLastResultReturn(E_SUCCESS);
780 }
781
782 result
783 _GroupedListViewImpl::SetTextOfEmptyList(const String& text)
784 {
785         if (text.IsEmpty())
786         {
787                 if (__pEmptyText != null)
788                 {
789                         GetCore().DetachChild(*__pEmptyText);
790
791                         delete __pEmptyText;
792                         __pEmptyText = null;
793                 }
794         }
795         else
796         {
797                 if (__pEmptyText == null)
798                 {
799                         __pEmptyText = _Label::CreateLabelN();
800                         SysTryReturn(NID_UI_CTRL, (__pEmptyText != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
801
802                         __pEmptyText->SetVisibleState(false);
803                         __pEmptyText->SetMargin(0, 0);
804
805                         GetCore().AttachChild(*__pEmptyText);
806                 }
807
808                 TextObject* pText = new (std::nothrow) TextObject;
809                 SysTryReturn(NID_UI_CTRL, (pText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
810
811                 pText->Construct();
812
813                 TextSimple* pSimpleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(text.GetPointer()), text.GetLength());
814                 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
815                 pText->AppendElement(*pSimpleText);
816
817                 int fontSize = 0;
818                 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, fontSize);
819
820                 Font font;
821                 font.Construct(GetFont(), FONT_STYLE_PLAIN, fontSize);
822                 pText->SetFont(&font, 0, pText->GetTextLength());
823
824                 Dimension listDimension = GetCore().GetSize();
825
826                 pText->SetBounds(Rectangle(0, 0, listDimension.width, 1));
827                 pText->Compose();
828
829                 Dimension labelDimension = pText->GetTextExtent(0, pText->GetTextLength());
830                 labelDimension.height = pText->GetTotalHeight();
831
832                 if (labelDimension.width > listDimension.width)
833                 {
834                         pText->SetBounds(Rectangle(0, 0, listDimension.width, 1));
835                         pText->Compose();
836
837                         int labelHeight = pText->GetTotalHeight();
838
839                         labelDimension.width = listDimension.width;
840                         labelDimension.height = ((listDimension.height < labelHeight) ? listDimension.height : labelHeight);
841                 }
842
843                 delete pText;
844
845                 __pEmptyText->SetSize(labelDimension);
846                 __pEmptyText->SetBackgroundColor(Color(0, 0, 0, 0));
847                 __pEmptyText->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
848                 __pEmptyText->SetTextColor(__emptyTextColor);
849                 __pEmptyText->SetText(text);
850         }
851
852         AdjustLayoutOfEmptyList();
853
854         SetLastResultReturn(E_SUCCESS);
855 }
856
857 String
858 _GroupedListViewImpl::GetTextOfEmptyList(void) const
859 {
860         return ((__pEmptyText != null) ? __pEmptyText->GetText() : String());
861 }
862
863 result
864 _GroupedListViewImpl::SetTextColorOfEmptyList(const Color& color)
865 {
866         __emptyTextColor = color;
867
868         if (__pEmptyText != null)
869         {
870                 __pEmptyText->SetTextColor(color);
871         }
872
873         SetLastResultReturn(E_SUCCESS);
874 }
875
876 Color
877 _GroupedListViewImpl::GetTextColorOfEmptyList(void) const
878 {
879         return __emptyTextColor;
880 }
881
882 result
883 _GroupedListViewImpl::ExpandGroup(int groupIndex)
884 {
885         return GetCore().ExpandGroup(groupIndex);
886 }
887
888 result
889 _GroupedListViewImpl::CollapseGroup(int groupIndex)
890 {
891         return GetCore().CollapseGroup(groupIndex);
892 }
893
894 bool
895 _GroupedListViewImpl::IsGroupExpanded(int groupIndex) const
896 {
897         return GetCore().IsGroupExpanded(groupIndex);
898 }
899
900 void
901 _GroupedListViewImpl::CheckEmptyListShowState(void)
902 {
903         bool isEmpty = (GetGroupCount() == 0);
904
905         if (__pEmptyBitmap != null)
906         {
907                 __pEmptyBitmap->SetVisibleState(isEmpty);
908         }
909         if (__pEmptyText != null)
910         {
911                 __pEmptyText->SetVisibleState(isEmpty);
912         }
913 }
914
915
916 void
917 _GroupedListViewImpl::AdjustLayoutOfEmptyList(void)
918 {
919         Dimension listDimension = GetCore().GetSize();
920         Dimension emptyBitmap;
921         Dimension emptyText;
922         Point bitmapPos;
923         Point textPos;
924         int totalHeight = 0;
925
926         if (__pEmptyBitmap != null)
927         {
928                 emptyBitmap = __pEmptyBitmap->GetSize();
929         }
930         if (__pEmptyText != null)
931         {
932                 emptyText = __pEmptyText->GetSize();
933         }
934
935         totalHeight = emptyBitmap.height + emptyText.height;
936
937         if ((__pEmptyBitmap != null) && (__pEmptyText != null) && (totalHeight < listDimension.height))
938         {
939                 bitmapPos.x = ((listDimension.width == emptyBitmap.width) ? 0 : (listDimension.width - emptyBitmap.width) / 2);
940                 bitmapPos.y = (listDimension.height - totalHeight) / 2;
941
942                 textPos.x = ((listDimension.width == emptyText.width) ? 0 : (listDimension.width - emptyText.width) / 2);
943                 textPos.y = bitmapPos.y + emptyBitmap.height;
944         }
945         else
946         {
947                 if (__pEmptyBitmap != null)
948                 {
949                         bitmapPos.x = ((listDimension.width == emptyBitmap.width) ? 0 : (listDimension.width - emptyBitmap.width) / 2);
950                         bitmapPos.y = ((listDimension.height == emptyBitmap.height) ? 0 : (listDimension.height - emptyBitmap.height) / 2);
951                 }
952
953                 if (__pEmptyText != null)
954                 {
955                         textPos.x = ((listDimension.width == emptyText.width) ? 0 : (listDimension.width - emptyText.width) / 2);
956                         textPos.y = ((listDimension.height == emptyText.height) ? 0 : (listDimension.height - emptyText.height) / 2);
957                 }
958         }
959
960         if (__pEmptyBitmap != null)
961         {
962                 __pEmptyBitmap->SetPosition(bitmapPos);
963         }
964         if (__pEmptyText != null)
965         {
966                 __pEmptyText->SetPosition(textPos);
967         }
968
969         CheckEmptyListShowState();
970 }
971
972 result
973 _GroupedListViewImpl::BeginReorderingMode(void)
974 {
975         SysTryReturn(NID_UI_CTRL, (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED), E_INVALID_OPERATION, E_INVALID_OPERATION,
976                         "[E_INVALID_OPERATION] Reordering mode is supported only Indexed style.");
977
978         result r = GetCore().SetReorderModeEnabled(true);
979
980         SetLastResultReturn(r);
981 }
982
983 result
984 _GroupedListViewImpl::EndReorderingMode(void)
985 {
986         SysTryReturn(NID_UI_CTRL, (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED), E_INVALID_OPERATION, E_INVALID_OPERATION,
987                                 "[E_INVALID_OPERATION] Reordering mode is supported only Indexed style.");
988
989         result r = GetCore().SetReorderModeEnabled(false);
990
991         SetLastResultReturn(r);
992 }
993
994 bool
995 _GroupedListViewImpl::IsInReorderingMode(void) const
996 {
997         return GetCore().IsReorderModeEnabled();
998 }
999
1000 void
1001 _GroupedListViewImpl::OnListViewContextItemStateChanged(_Control& source, int groupIndex, int itemIndex, int elementId,
1002                 ListContextItemStatus status)
1003 {
1004         if (__pListItemEvent != null)
1005         {
1006                 GetCore().ResetSweepItem();
1007
1008                 __pItemNeedsLazyDeletion = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1009
1010                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(groupIndex, itemIndex, elementId, 0, NOTIFY_TYPE_SELCTED_CONTEXT_ITEM);
1011                 __pListItemEvent->Fire(*pArg);
1012
1013                 __pItemNeedsLazyDeletion = null;
1014         }
1015 }
1016
1017 void
1018 _GroupedListViewImpl::OnListViewItemLongPressed(_Control& source, int groupIndex, int itemIndex, int elementId)
1019 {
1020         if (__pListItemEvent != null)
1021         {
1022                 __pItemNeedsLazyDeletion = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1023
1024                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(groupIndex, itemIndex, elementId, 0, NOTIFY_TYPE_LONG_PRESSED_ITEM);
1025                 __pListItemEvent->Fire(*pArg);
1026
1027                 __pItemNeedsLazyDeletion = null;
1028         }
1029 }
1030
1031 void
1032 _GroupedListViewImpl::OnGroupedTableViewGroupItemStateChanged(_TableView& tableView, int groupIndex, _TableViewItem* pItem,
1033                 TableViewItemStatus status)
1034 {
1035         FireListViewItemEvent(groupIndex, -1, pItem, status);
1036 }
1037
1038 void
1039 _GroupedListViewImpl::OnGroupedTableViewItemStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pItem,
1040                 TableViewItemStatus status)
1041 {
1042         FireListViewItemEvent(groupIndex, itemIndex, pItem, status);
1043 }
1044
1045 void
1046 _GroupedListViewImpl::OnGroupedTableViewContextItemActivationStateChanged(_TableView& tableView, int groupIndex, int itemIndex,
1047                 _TableViewItem* pContextItem, bool activated)
1048 {
1049         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1050
1051         if (pListViewItem != null)
1052         {
1053                 __pItemSwept = (activated ? pListViewItem : null);
1054
1055                 pListViewItem->SetContextItemActivationState(activated);
1056         }
1057 }
1058
1059 void
1060 _GroupedListViewImpl::OnGroupedTableViewItemReordered(_TableView& tableView, int groupIndexFrom, int itemIndexFrom,
1061                 int groupIndexTo, int itemIndexTo)
1062 {
1063         if (__pListItemEvent != null)
1064         {
1065                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(groupIndexFrom, itemIndexFrom, groupIndexTo, itemIndexTo,
1066                                                                                                                                            NOTIFY_TYPE_REORDERED_ITEM);
1067                 __pListItemEvent->Fire(*pArg);
1068         }
1069 }
1070
1071 void
1072 _GroupedListViewImpl::OnSectionTableViewItemStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pItem,
1073                 TableViewItemStatus status)
1074 {
1075         FireListViewItemEvent(sectionIndex, itemIndex, pItem, status);
1076 }
1077
1078 void
1079 _GroupedListViewImpl::OnSectionTableViewContextItemActivationStateChanged(_TableView& tableView, int sectionIndex, int itemIndex,
1080                 _TableViewItem* pContextItem, bool activated)
1081 {
1082         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(sectionIndex, itemIndex));
1083
1084         if (pListViewItem != null)
1085         {
1086                 __pItemSwept = (activated ? pListViewItem : null);
1087
1088                 pListViewItem->SetContextItemActivationState(activated);
1089         }
1090 }
1091
1092 void
1093 _GroupedListViewImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1094 {
1095         if (__pListItemEvent != null)
1096         {
1097                 __pItemNeedsLazyDeletion = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1098
1099                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(groupIndex, itemIndex, direction, 0, NOTIFY_TYPE_SWEPT_ITEM);
1100                 __pListItemEvent->Fire(*pArg);
1101
1102                 __pItemNeedsLazyDeletion = null;
1103         }
1104 }
1105
1106 void
1107 _GroupedListViewImpl::FireListViewItemEvent(int groupIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1108 {
1109         if (__pListItemEvent != null)
1110         {
1111                 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(pItem);
1112
1113                 __pItemNeedsLazyDeletion = pListViewItem;
1114
1115                 if (pListViewItem != null)
1116                 {
1117                         _ListViewItemStateChangedInfo itemInfo;
1118                         pListViewItem->GetLastStateChangedInfo(itemInfo);
1119
1120                         if ((__pLinkEvent != null) && (itemInfo.pUiLinkInfo != null))
1121                         {
1122                                 IEventArg* pLinkEventArg = _PublicLinkEvent::CreateLinkEventArgN(itemInfo.pUiLinkInfo->textInfo,
1123                                                                                                                                                                  itemInfo.pUiLinkInfo->linkType,
1124                                                                                                                                                                  itemInfo.pUiLinkInfo->linkInfo);
1125                                 SysTryReturnVoidResult(NID_UI_CTRL, (pLinkEventArg != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _LinkEventArg.");
1126                                 __pLinkEvent->Fire(*pLinkEventArg);
1127
1128                         }
1129                         else
1130                         {
1131                                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(groupIndex, itemIndex, itemInfo.elementId, 0,
1132                                                                                                                                                            static_cast<NotifyType>(status));
1133                                 __pListItemEvent->Fire(*pArg);
1134                         }
1135
1136                         pListViewItem->ClearLastStateChangedInfo();
1137                 }
1138
1139                 __pItemNeedsLazyDeletion = null;
1140         }
1141 }
1142
1143 void
1144 _GroupedListViewImpl::OnScrollEndReached(_Control& source, ScrollEndEvent type)
1145 {
1146         if (__pScrollEvent != null)
1147         {
1148                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), type);
1149                 result r = GetLastResult();
1150                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1151
1152                 __pScrollEvent->Fire(*pEventArg);
1153         }
1154 }
1155
1156 void
1157 _GroupedListViewImpl::OnScrollPositionChanged(_Control& source, int scrollPos)
1158 {
1159         if (__pScrollEvent != null)
1160         {
1161                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), scrollPos);
1162                 result r = GetLastResult();
1163                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1164
1165                 __pScrollEvent->Fire(*pEventArg);
1166         }
1167 }
1168
1169 void
1170 _GroupedListViewImpl::OnScrollStopped(_Control& source)
1171 {
1172         if (__pScrollEvent != null)
1173         {
1174                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic());
1175                 result r = GetLastResult();
1176                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1177
1178                 __pScrollEvent->Fire(*pEventArg);
1179         }
1180 }
1181 void
1182 _GroupedListViewImpl::OnUiFastScrollIndexSelected(_Control& source, _FastScrollIndex& index)
1183 {
1184         if (__pFastScrollEvent != null)
1185         {
1186                 String* pIndexText = index.GetIndexText();
1187                 if (pIndexText != null)
1188                 {
1189                         _FastScrollEventArg* pEventArg = new (std::nothrow) _FastScrollEventArg(GetPublic(), *pIndexText);
1190                         __pFastScrollEvent->Fire(*pEventArg);
1191                 }
1192         }
1193 }
1194
1195 void
1196 _GroupedListViewImpl::OnDraw(void)
1197 {
1198         _ControlImpl::OnDraw();
1199
1200         if (__redrawListView)
1201         {
1202                 CheckEmptyListShowState();
1203                 __redrawListView = false;
1204         }
1205 }
1206
1207 void
1208 _GroupedListViewImpl::OnBoundsChanged(void)
1209 {
1210         _ControlImpl::OnBoundsChanged();
1211
1212         if (__pEmptyBitmap != null)
1213         {
1214                 SetBitmapOfEmptyList(__pEmptyBitmap->GetBackgroundBitmap());
1215         }
1216         if (__pEmptyText != null)
1217         {
1218                 SetTextOfEmptyList(__pEmptyText->GetText());
1219         }
1220
1221         _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
1222                         static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1223
1224         if (pProviderAdaptor != null)
1225         {
1226                 int itemWidth = GetCore().GetBounds().width;
1227
1228                 if (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION)
1229                 {
1230                         int margin = 0;
1231                         GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, margin);
1232
1233                         itemWidth -= (margin * 2);
1234                 }
1235
1236                 pProviderAdaptor->SetListWidth(itemWidth);
1237         }
1238 }
1239
1240 void
1241 _GroupedListViewImpl::OnFontChanged(Font* pFont)
1242 {
1243         String fontName = GetFont();
1244         _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
1245                         static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1246
1247         if (__pEmptyText != null)
1248         {
1249                 __pEmptyText->SetFont(fontName);
1250                 SetTextOfEmptyList(__pEmptyText->GetText());
1251         }
1252
1253         if (pProviderAdaptor != null)
1254         {
1255                 pProviderAdaptor->SetItemFont(fontName);
1256         }
1257
1258         int firstGroup = -1;
1259         int firstItem = -1;
1260         int lastGroup = -1;
1261         int lastItem = -1;
1262         int currentItem = -1;
1263         int lastItemInGroup = -1;
1264
1265         GetCore().GetFirstLoadedItemIndex(firstGroup, firstItem);
1266         GetCore().GetLastLoadedItemIndex(lastGroup, lastItem);
1267
1268         for (int i = firstGroup; i <= lastGroup; i++)
1269         {
1270                 currentItem = ((i == firstGroup) ? firstItem : -1);
1271                 lastItemInGroup = ((i == lastGroup) ? lastItem : GetCore().GetItemCountAt(i));
1272
1273                 for (; currentItem <= lastItemInGroup; currentItem++)
1274                 {
1275                         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(i, currentItem));
1276
1277                         if (pListViewItem != null)
1278                         {
1279                                 pListViewItem->SetFont(fontName);
1280                         }
1281                 }
1282         }
1283 }
1284
1285 void
1286 _GroupedListViewImpl::OnFontInfoRequested(unsigned long& style, int& size)
1287 {
1288         int textSize = 0;
1289         GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, textSize);
1290
1291         style = FONT_STYLE_PLAIN;
1292         size = textSize;
1293 }
1294
1295 bool
1296 _GroupedListViewImpl::OnTouchPressed(const _ControlImpl& source, const _TouchInfo& touchinfo)
1297 {
1298         FirePublicTouchEvent(touchinfo);
1299         return false;
1300 }
1301
1302 bool
1303 _GroupedListViewImpl::OnTouchReleased(const _ControlImpl& source, const _TouchInfo& touchinfo)
1304 {
1305         FirePublicTouchEvent(touchinfo);
1306         return false;
1307 }
1308
1309 bool
1310 _GroupedListViewImpl::OnTouchMoved(const _ControlImpl& source, const _TouchInfo& touchinfo)
1311 {
1312         FirePublicTouchEvent(touchinfo);
1313         return false;
1314 }
1315
1316 bool
1317 _GroupedListViewImpl::OnTouchCanceled(const _ControlImpl& source, const _TouchInfo& touchinfo)
1318 {
1319         FirePublicTouchEvent(touchinfo);
1320         return false;
1321 }
1322
1323 void
1324 _GroupedListViewImpl::FirePublicTouchEvent(const _TouchInfo& touchInfo)
1325 {
1326         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1327         SysTryReturnVoidResult(NID_UI, pTouchManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1328
1329         TouchEventInfo publicTouchInfo;
1330
1331         _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
1332         SysTryReturnVoidResult(NID_UI, pEventArg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1333
1334         publicTouchInfo.Construct(*pEventArg);
1335
1336         _Control* pDraggedControl = pTouchManager->GetTouchControlSource();
1337
1338         IEnumeratorT<IEventListener*>* pEnumerator = GetTouchEventListener()->GetEnumeratorN();
1339         if (pEnumerator)
1340         {
1341                 while (pEnumerator->MoveNext() == E_SUCCESS)
1342                 {
1343                         IEventListener* pListener = null;
1344                         pEnumerator->GetCurrent(pListener);
1345
1346                         ITouchEventListener* pTouchEventListener = dynamic_cast <ITouchEventListener*>(pListener);
1347                         if (pTouchEventListener)
1348                         {
1349                                 FirePublicListener(*pTouchEventListener, publicTouchInfo);
1350
1351                                 if (touchInfo.GetTouchStatus() == _TOUCH_RELEASED)
1352                                 {
1353                                         if (pDraggedControl == null)    //if exist dragged control, don't send focus event
1354                                         {
1355                                                 FireFocusListener(*pTouchEventListener, publicTouchInfo);
1356                                         }
1357                                 }
1358                                 else if (touchInfo.GetTouchStatus() == _TOUCH_MOVED)
1359                                 {
1360                                         FireFocusListener(*pTouchEventListener, publicTouchInfo);
1361                                 }
1362                         }
1363                 }
1364
1365                 delete pEnumerator;
1366         }
1367
1368         delete pEventArg;
1369 }
1370
1371 void
1372 _GroupedListViewImpl::FirePublicListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
1373 {
1374         switch (touchEventInfo.GetTouchStatus())
1375         {
1376         case TOUCH_PRESSED:
1377                 listener.OnTouchPressed(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1378                 break;
1379         case TOUCH_LONG_PRESSED:
1380                 listener.OnTouchLongPressed(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1381                 break;
1382         case TOUCH_RELEASED:
1383                 listener.OnTouchReleased(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1384                 break;
1385         case TOUCH_MOVED:
1386                 listener.OnTouchMoved(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1387                 break;
1388         case TOUCH_DOUBLE_PRESSED:
1389                 listener.OnTouchDoublePressed(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1390                 break;
1391         case TOUCH_FOCUS_IN:
1392                 listener.OnTouchFocusIn(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1393                 break;
1394         case TOUCH_FOCUS_OUT:
1395                 listener.OnTouchFocusOut(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1396                 break;
1397         case TOUCH_CANCELED:
1398                 listener.OnTouchCanceled(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1399                 break;
1400         default:
1401                 break;
1402         }
1403 }
1404
1405 void
1406 _GroupedListViewImpl::FireFocusListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
1407 {
1408         _ControlManager* pControlManager = _ControlManager::GetInstance();
1409         SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1410
1411         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1412         SysTryReturnVoidResult(NID_UI, pTouchManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1413
1414         Point screenPoint(pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).x,
1415                                           pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).y);
1416
1417         _Control* pTouchedControl = pControlManager->GetTopmostTouchedControl(screenPoint);
1418         SysTryReturnVoidResult(NID_UI, pTouchedControl, E_INVALID_CONDITION, "[E_INVALID_CONDITION] pTouchedControl is null.");
1419
1420         if (pTouchManager->GetFocusedControlSource() != pTouchedControl)
1421         {
1422                 if (&(GetCore()) != pTouchedControl)
1423                 {
1424                         if (pTouchManager->GetFocusedControlSource() == &(GetCore()))
1425                         {
1426                                 listener.OnTouchFocusOut(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1427                         }
1428                 }
1429                 else
1430                 {
1431                         listener.OnTouchFocusIn(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1432                 }
1433
1434                 pTouchManager->SetFocusedControlSource(*pTouchedControl);
1435         }
1436 }
1437
1438 _TouchEventArg*
1439 _GroupedListViewImpl::GetTouchEventArgN(const _TouchInfo& touchInfo)
1440 {
1441         Point startPoint;
1442
1443         _TouchEventArg* pEventArg = new (std::nothrow) _TouchEventArg(GetPublic(), touchInfo.GetTouchStatus());
1444         SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1445
1446         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1447         SysTryCatch(NID_UI, pTouchManager, , E_SYSTEM, "[E_SYSTEM] System error occurred.");
1448
1449         startPoint.SetPosition(pTouchManager->GetStartPoint(touchInfo.GetPointId()).x - GetCore().GetAbsoluteBounds().x,
1450                                                    pTouchManager->GetStartPoint(touchInfo.GetPointId()).y - GetCore().GetAbsoluteBounds().y);
1451
1452         pEventArg->SetTouchPosition(touchInfo.GetPointId(), startPoint.x, startPoint.y,
1453                         touchInfo.GetCurrentPosition().x, touchInfo.GetCurrentPosition().y);
1454
1455         // need to flick distance setting
1456
1457         return pEventArg;
1458
1459 CATCH:
1460         delete pEventArg;
1461         return null;
1462 }
1463
1464 class _GroupedListViewMaker
1465         : public _UiBuilderControlMaker
1466 {
1467 public:
1468         _GroupedListViewMaker(_UiBuilder* uibuilder)
1469                 : _UiBuilderControlMaker(uibuilder){};
1470
1471         virtual ~_GroupedListViewMaker(){};
1472
1473         static _UiBuilderControlMaker*
1474         GetInstance(_UiBuilder* uibuilder)
1475         {
1476                 _GroupedListViewMaker* pGroupedListViewMaker = new (std::nothrow) _GroupedListViewMaker(uibuilder);
1477                 return pGroupedListViewMaker;
1478         };
1479 protected:
1480         virtual Tizen::Ui::Control*
1481         Make(_UiBuilderControl* pControl)
1482         {
1483                 result r = E_SYSTEM;
1484                 _UiBuilderControlLayout* pControlProperty = null;
1485                 GroupedListView* pGroupedListView = null;
1486                 Rectangle rect;
1487
1488                 GroupedListViewStyle style = GROUPED_LIST_VIEW_STYLE_INDEXED;
1489                 String elementString;
1490                 bool itemDividerState = true;
1491                 bool fastScrollState = false;
1492                 int opacity = 100;
1493                 bool sweepEnabledState = false;
1494                 Color color;
1495
1496                 GetProperty(pControl, &pControlProperty);
1497                 if (pControlProperty == null)
1498                 {
1499                         return null;
1500                 }
1501
1502                 pGroupedListView = new (std::nothrow) GroupedListView();
1503                 if (pGroupedListView == null)
1504                 {
1505                         return null;
1506                 }
1507
1508                 rect = pControlProperty->GetRect();
1509
1510                 String styleString;
1511                 styleString = pControlProperty->GetStyle();
1512
1513                 if (styleString.Equals(L"GROUPED_LIST_VIEW_STYLE_SECTION", false))
1514                 {
1515                         style = GROUPED_LIST_VIEW_STYLE_SECTION;
1516                 }
1517                 else
1518                 {
1519                         style = GROUPED_LIST_VIEW_STYLE_INDEXED;
1520                 }
1521
1522                 //Construct
1523                 if (pControl->GetElement(L"itemDivider", elementString))
1524                 {
1525                         if (elementString.Equals(L"true", false))
1526                         {
1527                                 itemDividerState = true;
1528                         }
1529                         else
1530                         {
1531                                 itemDividerState = false;
1532                         }
1533                 }
1534
1535                 if (pControl->GetElement(L"fastScroll", elementString))
1536                 {
1537                         if (elementString.Equals(L"true", false))
1538                         {
1539                                 fastScrollState = true;
1540                         }
1541                         else
1542                         {
1543                                 fastScrollState = false;
1544                         }
1545                 }
1546
1547                 r = pGroupedListView->Construct(rect, style, itemDividerState, fastScrollState);
1548                 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1549
1550                 // Set BackgroundsBitmap
1551                 if (pControl->GetElement("backgroundBitmapPath", elementString))
1552                 {
1553                         Bitmap* pBackgroundBitmap = null;
1554                         pBackgroundBitmap = LoadBitmapN(elementString);
1555                         if (pBackgroundBitmap != null)
1556                         {
1557                                 r = pGroupedListView->SetBackgroundBitmap(pBackgroundBitmap);
1558                                 delete pBackgroundBitmap;
1559                                 pBackgroundBitmap = null;
1560
1561                                 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1562                         }
1563                 }
1564
1565                 // Set Empty List
1566                 if (pControl->GetElement(L"textOfEmptyList", elementString))
1567                 {
1568                         r = pGroupedListView->SetTextOfEmptyList(elementString);
1569                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1570                 }
1571
1572                 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
1573                 {
1574                         ConvertStringToColor(elementString, color);
1575                         r = pGroupedListView->SetTextColorOfEmptyList(color);
1576                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1577                 }
1578
1579                 if (pControl->GetElement(L"bitmapPathOfEmptyList", elementString))
1580                 {
1581                         Bitmap* pBackgroundBitmap = null;
1582                         pBackgroundBitmap = LoadBitmapN(elementString); //__image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
1583                         if (pBackgroundBitmap != null)
1584                         {
1585                                 r = pGroupedListView->SetBitmapOfEmptyList(pBackgroundBitmap);
1586                                 delete pBackgroundBitmap;
1587                                 pBackgroundBitmap = null;
1588
1589                                 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1590                         }
1591                 }
1592
1593                 if (pControl->GetElement(L"backgroundColorOpacity", elementString) || pControl->GetElement(L"BGColorOpacity", elementString))
1594                 {
1595                         Base::Integer::Parse(elementString, opacity);
1596                 }
1597
1598                 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
1599                 {
1600                         ConvertStringToColor32(elementString, opacity, color);
1601                         r = pGroupedListView->SetBackgroundColor(color);
1602                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1603                 }
1604
1605                 if (pControl->GetElement(L"itemDividerColor", elementString))
1606                 {
1607                         ConvertStringToColor(elementString, color);
1608                         r = pGroupedListView->SetItemDividerColor(color);
1609                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1610                 }
1611
1612                 if (pControl->GetElement(L"sectionColor", elementString))
1613                 {
1614                         ConvertStringToColor(elementString, color);
1615                         r = pGroupedListView->SetSectionColor(color);
1616                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1617                 }
1618
1619                 if (pControl->GetElement(L"sweepEnabled", elementString))
1620                 {
1621                         {
1622                                 if (elementString.Equals(L"true", false))
1623                                 {
1624                                         sweepEnabledState = true;
1625                                 }
1626                                 else
1627                                 {
1628                                         sweepEnabledState = false;
1629                                 }
1630                         }
1631                         r = pGroupedListView->SetSweepEnabled(sweepEnabledState);
1632                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1633                 }
1634
1635                 return pGroupedListView;
1636
1637         CATCH:
1638                 delete pGroupedListView;
1639                 pGroupedListView = null;
1640                 return null;
1641         }
1642
1643 private:
1644 }; // _GroupedListViewMaker
1645
1646 _GroupedListViewRegister::_GroupedListViewRegister()
1647 {
1648           _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1649           pUiBuilderControlTableManager->RegisterControl(L"GroupedListView", _GroupedListViewMaker::GetInstance);
1650 }
1651
1652 _GroupedListViewRegister::~_GroupedListViewRegister()
1653 {
1654           _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1655           pUiBuilderControlTableManager->UnregisterControl(L"GroupedListView");
1656 }
1657 static _GroupedListViewRegister GroupedListViewRegisterToUIbuilder;
1658 }}} // Tizen::Ui::Controls
1659