Changed indicator bg color.
[platform/framework/native/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 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_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 <FBaseSysLog.h>
28 #include <FApp_AppInfo.h>
29 #include <FGrp_TextTextSimple.h>
30 #include "FUi_AccessibilityContainer.h"
31 #include "FUi_AccessibilityElement.h"
32 #include "FUi_AccessibilityManager.h"
33 #include "FUi_CoordinateSystemUtils.h"
34 #include "FUi_ITouchLongPressGestureEventListener.h"
35 #include "FUi_Math.h"
36 #include "FUi_ResourceManager.h"
37 #include "FUi_TouchEventArg.h"
38 #include "FUi_TouchLongPressGestureDetector.h"
39 #include "FUi_TouchManager.h"
40 #include "FUi_UiBuilder.h"
41 #include "FUiCtrl_FastScrollEvent.h"
42 #include "FUiCtrl_FastScrollEventArg.h"
43 #include "FUiCtrl_GroupedListViewImpl.h"
44 #include "FUiCtrl_GroupedListViewItemProviderAdaptor.h"
45 #include "FUiCtrl_Label.h"
46 #include "FUiCtrl_ListItemEvent.h"
47 #include "FUiCtrl_ListItemEventArg.h"
48 #include "FUiCtrl_ListViewItem.h"
49 #include "FUiCtrl_PublicLinkEvent.h"
50 #include "FUiCtrl_ScrollEvent.h"
51 #include "FUiCtrl_ScrollEventArg.h"
52
53 using namespace Tizen::Base;
54 using namespace Tizen::Base::Collection;
55 using namespace Tizen::Base::Runtime;
56 using namespace Tizen::Base::Utility;
57 using namespace Tizen::Graphics;
58 using namespace Tizen::Graphics::_Text;
59
60 namespace Tizen { namespace Ui { namespace Controls
61 {
62
63 class _GroupedListViewImpl::_GroupedListViewPropagatedTouchEventListener
64         : public Tizen::Ui::_IPropagatedTouchEventListener
65         , public Tizen::Ui::_ITouchLongPressGestureEventListener
66 {
67 public:
68
69         _GroupedListViewPropagatedTouchEventListener(_GroupedListViewImpl& impl)
70                 : __impl(impl)
71                 , __core(impl.GetCore())
72                 , __public(impl.GetPublic())
73                 , __oldPreviousPressedTime(0)
74                 , __previousPressedTime(0)
75                 , __currentPressedTime(0)
76                 , __previousPressedPoint(0.0f, 0.0f)
77                 , __currentPressedPoint(0.0f, 0.0f)
78                 , __pLongPressedGesture(null)
79         {
80                 __pTouchManager = _TouchManager::GetInstance();
81                 SysTryReturnVoidResult(NID_UI_CTRL, (__pTouchManager != null), E_SYSTEM, "[E_SYSTEM] System error occurred.");
82
83                 // Add _TouchLongPressGestureDetector
84                 __pLongPressedGesture = new (std::nothrow) _TouchLongPressGestureDetector();
85                 SysTryReturnVoidResult(NID_UI_CTRL, (__pLongPressedGesture != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
86
87                 __core.AddGestureDetector(*__pLongPressedGesture);
88                 result r = __pLongPressedGesture->AddGestureListener(*this);
89                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] propagating.", GetErrorMessage(r));
90         }
91
92         virtual ~_GroupedListViewPropagatedTouchEventListener(void)
93         {
94                 if (__pLongPressedGesture != null)
95                 {
96                         __pLongPressedGesture->RemoveGestureListener(*this);
97                         __core.RemoveGestureDetector(*__pLongPressedGesture);
98
99                         delete __pLongPressedGesture;
100                         __pLongPressedGesture = null;
101                 }
102         }
103
104         virtual bool OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
105         {
106                 return __impl.CallOnTouchPressed(source, touchInfo);
107         }
108
109         virtual bool OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
110         {
111                 return __impl.CallOnTouchReleased(source, touchInfo);
112         }
113
114         virtual bool OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
115         {
116                 return __impl.CallOnTouchMoved(source, touchInfo);
117         }
118
119         virtual bool OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
120         {
121                 return __impl.CallOnTouchCanceled(source, touchInfo);
122         }
123
124         virtual _UiTouchEventDelivery OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
125         {
126                 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
127                 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
128
129                 if (pListener != null)
130                 {
131                         Control& control = __impl.GetPublic();
132
133                         TouchEventInfo publicTouchInfo;
134
135                         _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
136                         SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
137
138                         publicTouchInfo.Construct(*pEventArg);
139
140                         if (pEventArg)
141                         {
142                                 delete pEventArg;
143                                 pEventArg = null;
144                         }
145
146                         if (pListener->OnTouchPressed(control, publicTouchInfo) == true)
147                         {
148                                 return _UI_TOUCH_EVENT_DELIVERY_NO;
149                         }
150                 }
151
152                 // public TouchEventListener
153                 if (ProcessTouchEventListener(touchInfo) == true)
154                 {
155                         return _UI_TOUCH_EVENT_DELIVERY_NO;
156                 }
157
158                 if (__core.Equals(source))
159                 {
160                         return _UI_TOUCH_EVENT_DELIVERY_NO;
161                 }
162
163                 isFiltered = __impl.OnPreviewTouchPressed(__impl, touchInfo);
164                 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
165                 {
166                         return _UI_TOUCH_EVENT_DELIVERY_NO;
167                 }
168
169                 isFiltered = __core.OnPreviewTouchPressed(source, touchInfo);
170
171                 return isFiltered;
172         }
173
174         virtual _UiTouchEventDelivery OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
175         {
176                 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
177                 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
178
179                 if (pListener != null)
180                 {
181                         Control& control = __impl.GetPublic();
182
183                         TouchEventInfo publicTouchInfo;
184
185                         _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
186                         SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
187
188                         publicTouchInfo.Construct(*pEventArg);
189
190                         if (pEventArg)
191                         {
192                                 delete pEventArg;
193                                 pEventArg = null;
194                         }
195
196                         if (pListener->OnTouchReleased(control, publicTouchInfo) == true)
197                         {
198                                 return _UI_TOUCH_EVENT_DELIVERY_NO;
199                         }
200                 }
201
202                 // public TouchEventListener
203                 if (ProcessTouchEventListener(touchInfo) == true)
204                 {
205                         return _UI_TOUCH_EVENT_DELIVERY_NO;
206                 }
207
208                 if (__core.Equals(source))
209                 {
210                         return _UI_TOUCH_EVENT_DELIVERY_NO;
211                 }
212
213                 isFiltered = __impl.OnPreviewTouchReleased(__impl, touchInfo);
214                 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
215                 {
216                         return _UI_TOUCH_EVENT_DELIVERY_NO;
217                 }
218
219                 isFiltered = __core.OnPreviewTouchReleased(source, touchInfo);
220
221                 return isFiltered;
222         }
223
224         virtual _UiTouchEventDelivery OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
225         {
226                 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
227                 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
228
229                 if (pListener != null)
230                 {
231                         Control& control = __impl.GetPublic();
232
233                         TouchEventInfo publicTouchInfo;
234
235                         _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
236                         SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
237
238                         publicTouchInfo.Construct(*pEventArg);
239
240                         if (pEventArg)
241                         {
242                                 delete pEventArg;
243                                 pEventArg = null;
244                         }
245
246                         if (pListener->OnTouchMoved(control, publicTouchInfo) == true)
247                         {
248                                 return _UI_TOUCH_EVENT_DELIVERY_NO;
249                         }
250                 }
251
252                 // public TouchEventListener
253                 if (ProcessTouchEventListener(touchInfo) == true)
254                 {
255                         return _UI_TOUCH_EVENT_DELIVERY_NO;
256                 }
257
258                 if (__core.Equals(source))
259                 {
260                         return _UI_TOUCH_EVENT_DELIVERY_NO;
261                 }
262
263                 isFiltered = __impl.OnPreviewTouchMoved(__impl, touchInfo);
264                 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
265                 {
266                         return _UI_TOUCH_EVENT_DELIVERY_NO;
267                 }
268
269                 isFiltered = __core.OnPreviewTouchMoved(source, touchInfo);
270
271                 return isFiltered;
272         }
273
274         virtual _UiTouchEventDelivery OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
275         {
276                 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
277
278                 if (pListener != null)
279                 {
280                         Control& control = __impl.GetPublic();
281
282                         TouchEventInfo publicTouchInfo;
283
284                         _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
285                         SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
286
287                         publicTouchInfo.Construct(*pEventArg);
288
289                         if (pEventArg)
290                         {
291                                 delete pEventArg;
292                                 pEventArg = null;
293                         }
294
295                         if (pListener->OnTouchCanceled(control, publicTouchInfo) == true)
296                         {
297                                 return _UI_TOUCH_EVENT_DELIVERY_NO;
298                         }
299                 }
300
301                 // public TouchEventListener
302                 if (ProcessTouchEventListener(touchInfo) == true)
303                 {
304                         return _UI_TOUCH_EVENT_DELIVERY_NO;
305                 }
306
307                 return _UI_TOUCH_EVENT_DELIVERY_YES;
308         }
309
310         virtual void OnTouchPressHandled(const _Control& source)
311         {
312                 __impl.OnTouchPressHandled(source);
313         }
314
315         virtual void OnTouchReleaseHandled(const _Control& source)
316         {
317                 __impl.OnTouchReleaseHandled(source);
318         }
319
320         virtual void OnTouchMoveHandled(const _Control& source)
321         {
322                 __impl.OnTouchMoveHandled(source);
323         }
324
325         virtual void OnTouchCancelHandled(const _Control& source)
326         {
327                 __impl.OnTouchCancelHandled(source);
328         }
329
330         bool OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
331         {
332                 bool filtered = ProcessTouchEventListener();
333
334                 if (!filtered)
335                 {
336                         __impl.FireListViewItemLongPressedEvent();
337                 }
338
339                 return filtered;
340         }
341
342         bool OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
343         {
344                 return false;
345         }
346
347 private:
348
349         bool ProcessTouchEventListener(const _TouchInfo& touchInfo)
350         {
351                 bool filtered = false;
352
353                 if (touchInfo.GetTouchStatus() == _TOUCH_PRESSED)
354                 {
355                         filtered = ProcessTouchDoublePressed(touchInfo);
356                 }
357
358                 if (!filtered)
359                 {
360                         ProcessTouchEvent(touchInfo);
361                 }
362
363                 filtered = __impl.IsInputEventConsumed();
364
365                 if (filtered)
366                 {
367                         __impl.ResetInputEventConsumed();
368                 }
369
370                 return filtered;
371         }
372
373         bool ProcessTouchEventListener(void)
374         {
375                 // for TouchLongPressed
376                 _TouchInfo touchInfo(0, _TOUCH_LONG_PRESSED, __currentPressedPoint, false, 0);
377
378                 return ProcessTouchEventListener(touchInfo);
379         }
380
381         void ProcessTouchEvent(const _TouchInfo& touchInfo)
382         {
383                 TouchEventInfo publicTouchInfo;
384
385                 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
386                 SysTryReturnVoidResult(NID_UI, pEventArg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
387
388                 publicTouchInfo.Construct(*pEventArg);
389
390                 _Control* pDraggedControl = __pTouchManager->GetTouchControlSource();
391
392                 IEnumeratorT<IEventListener*>* pEnumerator = __impl.GetTouchEventListener()->GetEnumeratorN();
393                 if (pEnumerator)
394                 {
395                         while (pEnumerator->MoveNext() == E_SUCCESS)
396                         {
397                                 IEventListener* pListener = null;
398                                 pEnumerator->GetCurrent(pListener);
399
400                                 ITouchEventListener* pTouchEventListener = dynamic_cast <ITouchEventListener*>(pListener);
401                                 if (pTouchEventListener != null)
402                                 {
403                                         FirePublicListener(*pTouchEventListener, publicTouchInfo);
404
405                                         if (touchInfo.GetTouchStatus() == _TOUCH_RELEASED)
406                                         {
407                                                 if (pDraggedControl == null)    //if exist dragged control, don't send focus event
408                                                 {
409                                                         FireFocusListener(*pTouchEventListener, publicTouchInfo);
410                                                 }
411                                         }
412                                         else if (touchInfo.GetTouchStatus() == _TOUCH_MOVED)
413                                         {
414                                                 FireFocusListener(*pTouchEventListener, publicTouchInfo);
415                                         }
416                                 }
417                         }
418
419                         delete pEnumerator;
420                 }
421
422                 delete pEventArg;
423         }
424
425         bool ProcessTouchDoublePressed(const _TouchInfo& touchinfo)
426         {
427                 if (__pTouchManager->GetPointCount() == 1)
428                 {
429                         __oldPreviousPressedTime = __previousPressedTime;
430                         __previousPressedTime = __currentPressedTime;
431                         __currentPressedTime = touchinfo.GetTimeStamp();
432                         __previousPressedPoint.x = __currentPressedPoint.x;
433                         __previousPressedPoint.y = __currentPressedPoint.y;
434                         __currentPressedPoint.x = touchinfo.GetCurrentPosition().x;
435                         __currentPressedPoint.y = touchinfo.GetCurrentPosition().y;
436
437                         if (Math::Abs(__previousPressedTime - __currentPressedTime) < DOUBLE_PRESS_TIME)
438                         {
439                                 if (Math::Abs(__previousPressedTime - __oldPreviousPressedTime) > DOUBLE_PRESS_TIME)
440                                 {
441                                         if ((Math::Abs(__previousPressedPoint.x - __currentPressedPoint.x) < DOUBLE_PRESS_MOVE_ALLOWANCE)
442                                                 && (Math::Abs(__previousPressedPoint.y - __currentPressedPoint.y) < DOUBLE_PRESS_MOVE_ALLOWANCE))
443                                         {
444                                                 _TouchInfo touchInfo(0, _TOUCH_DOUBLE_PRESSED, __currentPressedPoint, false, 0);
445                                                 ProcessTouchEvent(touchInfo);
446
447                                                 return true;
448                                         }
449                                 }
450                         }
451                 }
452
453                 return false;
454         }
455
456         void FirePublicListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
457         {
458                 switch (touchEventInfo.GetTouchStatus())
459                 {
460                 case TOUCH_PRESSED:
461                         listener.OnTouchPressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
462                         break;
463                 case TOUCH_LONG_PRESSED:
464                         listener.OnTouchLongPressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
465                         break;
466                 case TOUCH_RELEASED:
467                         listener.OnTouchReleased(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
468                         break;
469                 case TOUCH_MOVED:
470                         listener.OnTouchMoved(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
471                         break;
472                 case TOUCH_DOUBLE_PRESSED:
473                         listener.OnTouchDoublePressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
474                         break;
475                 case TOUCH_FOCUS_IN:
476                         listener.OnTouchFocusIn(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
477                         break;
478                 case TOUCH_FOCUS_OUT:
479                         listener.OnTouchFocusOut(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
480                         break;
481                 case TOUCH_CANCELED:
482                         listener.OnTouchCanceled(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
483                         break;
484                 default:
485                         break;
486                 }
487         }
488
489         void FireFocusListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
490         {
491                 _ControlManager* pControlManager = _ControlManager::GetInstance();
492                 SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
493
494                 Point screenPoint(__pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).x,
495                                                   __pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).y);
496
497                 _Control* pTouchedControl = pControlManager->GetTopmostTouchedControl(screenPoint);
498                 SysTryReturnVoidResult(NID_UI, pTouchedControl, E_INVALID_CONDITION, "[E_INVALID_CONDITION] pTouchedControl is null.");
499
500                 if (__pTouchManager->GetFocusedControlSource() != pTouchedControl)
501                 {
502                         if (&(__core) != pTouchedControl)
503                         {
504                                 if (__pTouchManager->GetFocusedControlSource() == &(__core))
505                                 {
506                                         listener.OnTouchFocusOut(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
507                                 }
508                         }
509                         else
510                         {
511                                 listener.OnTouchFocusIn(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
512                         }
513
514                         __pTouchManager->SetFocusedControlSource(*pTouchedControl);
515                 }
516         }
517
518         _TouchEventArg* GetTouchEventArgN(const _TouchInfo& touchInfo)
519         {
520                 FloatPoint startPoint;
521
522                 _TouchEventArg* pEventArg = new (std::nothrow) _TouchEventArg(__public, touchInfo.GetTouchStatus());
523                 SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
524
525                 startPoint.SetPosition(__pTouchManager->GetStartPoint(touchInfo.GetPointId()).x - __core.GetAbsoluteBoundsF().x,
526                                                            __pTouchManager->GetStartPoint(touchInfo.GetPointId()).y - __core.GetAbsoluteBoundsF().y);
527
528                 pEventArg->SetTouchPosition(touchInfo.GetPointId(), startPoint.x, startPoint.y,
529                                                                         touchInfo.GetCurrentPosition().x, touchInfo.GetCurrentPosition().y);
530
531                 // need to flick distance setting
532
533                 return pEventArg;
534         }
535
536 private:
537         static const int DOUBLE_PRESS_TIME = 500;
538         static const int DOUBLE_PRESS_MOVE_ALLOWANCE = 10;
539
540         _GroupedListViewImpl& __impl;
541         _Control& __core;
542         Control& __public;
543         _TouchManager* __pTouchManager;
544
545         unsigned int __oldPreviousPressedTime;
546         unsigned int __previousPressedTime;
547         unsigned int __currentPressedTime;
548         Tizen::Graphics::FloatPoint __previousPressedPoint;
549         Tizen::Graphics::FloatPoint __currentPressedPoint;
550         _TouchLongPressGestureDetector* __pLongPressedGesture;
551 };
552
553 _GroupedListViewImpl*
554 _GroupedListViewImpl::GetInstance(GroupedListView& groupedListView)
555 {
556         return static_cast <_GroupedListViewImpl*>(groupedListView._pControlImpl);
557 }
558
559 const _GroupedListViewImpl*
560 _GroupedListViewImpl::GetInstance(const GroupedListView& groupedListView)
561 {
562         return static_cast <const _GroupedListViewImpl*>(groupedListView._pControlImpl);
563 }
564
565 _GroupedListViewImpl::_GroupedListViewImpl(GroupedListView* pGroupedList, _TableView* pCore)
566         : _ControlImpl(pGroupedList, pCore)
567         , __pListItemEvent(null)
568         , __pLinkEvent(null)
569         , __pScrollEvent(null)
570         , __pFastScrollEvent(null)
571         , __pEmptyBitmap(null)
572         , __pEmptyText(null)
573         , __pAccessibilityElement(null)
574         , __redrawListView(true)
575         , __isOrientationChanged(false)
576         , __needReloadItems(false)
577         , __pPropagatedTouchEventListener(null)
578 {
579         GET_COLOR_CONFIG(TABLEVIEW::EMPTY_CONTENTS_TEXT_NORMAL, __emptyTextColor);
580 }
581
582 _GroupedListViewImpl::~_GroupedListViewImpl()
583 {
584         delete __pListItemEvent;
585         __pListItemEvent = null;
586
587         delete __pLinkEvent;
588         __pLinkEvent = null;
589
590         delete __pScrollEvent;
591         __pScrollEvent = null;
592
593         delete __pFastScrollEvent;
594         __pFastScrollEvent = null;
595
596         if (__pEmptyBitmap != null)
597         {
598                 GetCore().DetachChild(*__pEmptyBitmap);
599
600                 delete __pEmptyBitmap;
601                 __pEmptyBitmap = null;
602         }
603
604         if (__pEmptyText != null)
605         {
606                 GetCore().DetachChild(*__pEmptyText);
607
608                 delete __pEmptyText;
609                 __pEmptyText = null;
610         }
611
612         _AccessibilityContainer* pContainer = GetCore().GetAccessibilityContainer();
613
614         if ((__pAccessibilityElement != null) && (pContainer != null))
615         {
616                 pContainer->RemoveElement(__pAccessibilityElement);
617         }
618
619         delete __pPropagatedTouchEventListener;
620         __pPropagatedTouchEventListener = null;
621 }
622
623 const char*
624 _GroupedListViewImpl::GetPublicClassName(void) const
625 {
626         return "Tizen::Ui::Controls::GroupedListView";
627 }
628
629 const GroupedListView&
630 _GroupedListViewImpl::GetPublic(void) const
631 {
632         return static_cast <const GroupedListView&>(_ControlImpl::GetPublic());
633 }
634
635 GroupedListView&
636 _GroupedListViewImpl::GetPublic(void)
637 {
638         return static_cast <GroupedListView&>(_ControlImpl::GetPublic());
639 }
640
641 const _TableView&
642 _GroupedListViewImpl::GetCore(void) const
643 {
644         return static_cast <const _TableView&>(_ControlImpl::GetCore());
645 }
646
647 _TableView&
648 _GroupedListViewImpl::GetCore(void)
649 {
650         return static_cast <_TableView&>(_ControlImpl::GetCore());
651 }
652
653 _GroupedListViewImpl*
654 _GroupedListViewImpl::CreateGroupedListViewImplN(GroupedListView* pControl, GroupedListViewStyle style, bool itemDivider, ListScrollStyle scrollStyle)
655 {
656         result r = E_SUCCESS;
657         TableViewScrollBarStyle scrollBarStyle;
658
659         switch (scrollStyle)
660         {
661         case SCROLL_STYLE_FADE_OUT:
662                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT;
663                 break;
664
665         case SCROLL_STYLE_FIXED:
666                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FIXED;
667                 break;
668
669         case SCROLL_STYLE_FAST_SCROLL:
670                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL;
671                 break;
672
673         case SCROLL_STYLE_JUMP_TO_TOP:
674                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_JUMP_TO_TOP;
675                 break;
676
677         case SCROLL_STYLE_THUMB:
678                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_THUMB;
679                 break;
680
681         case SCROLL_STYLE_FAST_SCROLL_FIXED:
682                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED;
683                 break;
684
685         default:
686                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_NONE;
687                 break;
688         }
689
690         TableViewStyle tableViewStyle = ((style == GROUPED_LIST_VIEW_STYLE_SECTION) ? TABLE_VIEW_STYLE_SECTION : TABLE_VIEW_STYLE_GROUPED);
691
692         _TableView* pCore = _TableView::CreateTableViewN(tableViewStyle, itemDivider, scrollBarStyle);
693         SysTryReturn(NID_UI_CTRL, (pCore != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
694
695         _GroupedListViewImpl* pImpl = new (std::nothrow) _GroupedListViewImpl(pControl, pCore);
696
697         r = CheckConstruction(pCore, pImpl);
698         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
699
700         pImpl->__pPropagatedTouchEventListener = new (std::nothrow) _GroupedListViewPropagatedTouchEventListener(*pImpl);
701
702         if (pImpl->__pPropagatedTouchEventListener != null)
703         {
704                 pCore->SetPropagatedTouchEventListener(pImpl->__pPropagatedTouchEventListener);
705         }
706
707         return pImpl;
708 }
709
710 result
711 _GroupedListViewImpl::SetItemProvider(IGroupedListViewItemProvider& provider)
712 {
713         result r = E_SUCCESS;
714
715         _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
716                         static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
717
718         if (pProviderAdaptor != null)
719         {
720                 IGroupedListViewItemProvider* pProvider = pProviderAdaptor->GetItemProvider();
721                 if (&provider == pProvider)
722                 {
723                         return r;
724                 }
725         }
726
727         float itemWidth = GetBoundsF().width;
728
729         if (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION)
730         {
731                 float margin = 0.0f;
732                 GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, margin);
733
734                 itemWidth -= (margin * 2.0f);
735         }
736
737         if (pProviderAdaptor == null)
738         {
739                 pProviderAdaptor = new (std::nothrow) _GroupedListViewItemProviderAdaptor(provider);
740                 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
741                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
742
743                 pProviderAdaptor->SetListViewItemEventListener(*this);
744
745                 r = pProviderAdaptor->SetListWidth(itemWidth);
746                 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
747         }
748         else
749         {
750                 pProviderAdaptor->SetItemProvider(provider);
751                 r = pProviderAdaptor->SetListWidth(itemWidth);
752
753                 UpdateList();
754         }
755
756         __redrawListView = true;
757
758         SetLastResultReturn(r);
759 }
760
761 result
762 _GroupedListViewImpl::SetItemProvider(IGroupedListViewItemProviderF& provider)
763 {
764         result r = E_SUCCESS;
765
766         _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
767                         static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
768
769         if (pProviderAdaptor != null)
770         {
771                 IGroupedListViewItemProviderF* pProvider = pProviderAdaptor->GetItemProviderF();
772                 if (&provider == pProvider)
773                 {
774                         return r;
775                 }
776         }
777
778         float itemWidth = GetBoundsF().width;
779
780         if (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_SECTION)
781         {
782                 float margin = 0.0f;
783                 GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, margin);
784
785                 itemWidth -= (margin * 2.0f);
786         }
787
788         if (pProviderAdaptor == null)
789         {
790                 pProviderAdaptor = new (std::nothrow) _GroupedListViewItemProviderAdaptor(provider);
791                 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
792                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
793
794                 pProviderAdaptor->SetListViewItemEventListener(*this);
795
796                 r = pProviderAdaptor->SetListWidth(itemWidth);
797                 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
798         }
799         else
800         {
801                 pProviderAdaptor->SetItemProvider(provider);
802                 r = pProviderAdaptor->SetListWidth(itemWidth);
803
804                 UpdateList();
805         }
806
807         __redrawListView = true;
808
809         SetLastResultReturn(r);
810
811         return E_SUCCESS;
812 }
813
814 void
815 _GroupedListViewImpl::AddGroupedListViewItemEventListener(IGroupedListViewItemEventListener& listener)
816 {
817         result r = E_SUCCESS;
818
819         if (__pListItemEvent == null)
820         {
821                 __pListItemEvent = new (std::nothrow) _ListItemEvent();
822                 SysTryReturnVoidResult(NID_UI_CTRL, (__pListItemEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
823
824                 r = __pListItemEvent->Construct(GetPublic(), CLASSNAME_GROUPEDLISTVIEW);
825                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Item Event.");
826         }
827
828         __pListItemEvent->AddListener(listener);
829
830         r = GetCore().AddGroupedTableViewItemEventListener(*this);
831
832         SetLastResult(r);
833 }
834
835 void
836 _GroupedListViewImpl::RemoveGroupedListViewItemEventListener(IGroupedListViewItemEventListener& listener)
837 {
838         result r = E_SUCCESS;
839
840         if (__pListItemEvent != null)
841         {
842                 r = __pListItemEvent->RemoveListener(listener);
843         }
844
845         SetLastResult(r);
846 }
847
848 void
849 _GroupedListViewImpl::AddFastScrollListener(IFastScrollListener& listener)
850 {
851         result r = E_SUCCESS;
852
853         if (__pFastScrollEvent == null)
854         {
855                 __pFastScrollEvent = new (std::nothrow) _FastScrollEvent();
856                 SysTryReturnVoidResult(NID_UI_CTRL, (__pFastScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
857
858                 r = __pFastScrollEvent->Construct(GetPublic());
859                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct FastScroll Event.");
860         }
861
862         __pFastScrollEvent->AddListener(listener);
863
864         r = GetCore().AddFastScrollListener(*this);
865
866         SetLastResult(r);
867 }
868
869 void
870 _GroupedListViewImpl::RemoveFastScrollListener(IFastScrollListener& listener)
871 {
872         result r = E_SUCCESS;
873
874         if (__pFastScrollEvent != null)
875         {
876                 r = __pFastScrollEvent->RemoveListener(listener);
877         }
878
879         SetLastResult(r);
880 }
881
882 void
883 _GroupedListViewImpl::AddScrollEventListener(IScrollEventListener& listener)
884 {
885         result r = E_SUCCESS;
886
887         if (__pScrollEvent == null)
888         {
889                 __pScrollEvent = new (std::nothrow) _ScrollEvent();
890                 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
891
892                 r = __pScrollEvent->Construct(GetPublic());
893                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
894         }
895
896         __pScrollEvent->AddListener(listener);
897
898         GetCore().AddScrollEventListener(*this);
899
900         SetLastResult(r);
901 }
902
903 void
904 _GroupedListViewImpl::AddScrollEventListener(IScrollEventListenerF& listener)
905 {
906         result r = E_SUCCESS;
907
908         if (__pScrollEvent == null)
909         {
910                 __pScrollEvent = new (std::nothrow) _ScrollEvent();
911                 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
912
913                 r = __pScrollEvent->Construct(GetPublic());
914                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
915         }
916
917         __pScrollEvent->AddListener(listener);
918
919         GetCore().AddScrollEventListener(*this);
920
921         SetLastResult(r);
922 }
923
924 void
925 _GroupedListViewImpl::RemoveScrollEventListener(IScrollEventListener& listener)
926 {
927         result r = E_SUCCESS;
928
929         if (__pScrollEvent != null)
930         {
931                 r = __pScrollEvent->RemoveListener(listener);
932         }
933
934         SetLastResult(r);
935 }
936
937 void
938 _GroupedListViewImpl::RemoveScrollEventListener(IScrollEventListenerF& listener)
939 {
940         result r = E_SUCCESS;
941
942         if (__pScrollEvent != null)
943         {
944                 r = __pScrollEvent->RemoveListener(listener);
945         }
946
947         SetLastResult(r);
948 }
949
950 void
951 _GroupedListViewImpl::AddUiLinkEventListener(const IUiLinkEventListener& listener)
952 {
953         result r = E_SUCCESS;
954
955         if (__pLinkEvent == null)
956         {
957                 __pLinkEvent = _PublicLinkEvent::CreateInstanceN(GetPublic());
958                 SysTryReturnVoidResult(NID_UI, (__pLinkEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
959         }
960
961         r = __pLinkEvent->AddListener(listener);
962
963         SetLastResult(r);
964 }
965
966 void
967 _GroupedListViewImpl::RemoveUiLinkEventListener(const IUiLinkEventListener& listener)
968 {
969         result r = E_SUCCESS;
970
971         if (__pLinkEvent != null)
972         {
973                 r = __pLinkEvent->RemoveListener(listener);
974         }
975
976         SetLastResult(r);
977 }
978
979 result
980 _GroupedListViewImpl::SetSweepEnabled(bool enable)
981 {
982         GetCore().SetSweepEnabled(enable);
983
984         SetLastResultReturn(E_SUCCESS);
985 }
986
987 result
988 _GroupedListViewImpl::SetFastScrollIndex(const String& text, bool useSearchIcon)
989 {
990         result r = GetCore().SetFastScrollIndex(text, useSearchIcon);
991         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS) || (r == E_SYSTEM), E_INVALID_STATE, E_INVALID_STATE,
992                         "[E_INVALID_STATE] This instance is in an invalid state.");
993
994         SetLastResultReturn(r);
995 }
996
997 result
998 _GroupedListViewImpl::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
999 {
1000         return GetCore().GetTopDrawnItemIndex(groupIndex, itemIndex);
1001 }
1002
1003 result
1004 _GroupedListViewImpl::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
1005 {
1006         return GetCore().GetBottomDrawnItemIndex(groupIndex, itemIndex);
1007 }
1008
1009 result
1010 _GroupedListViewImpl::ScrollToItem(int groupIndex, int itemIndex, ListScrollItemAlignment itemAlignment)
1011 {
1012         result r = E_SUCCESS;
1013
1014         if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_TOP)
1015         {
1016                 r = GetCore().SetTopDrawnItemIndex(groupIndex, itemIndex);
1017         }
1018         else if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_BOTTOM)
1019         {
1020                 r = GetCore().SetBottomDrawnItemIndex(groupIndex, itemIndex);
1021         }
1022         else
1023         {
1024                 SysTryReturn(NID_UI_CTRL, false, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1025                                 "[E_OUT_OF_RANGE] The specified itemAlignment is out of range.");
1026         }
1027
1028         SetLastResultReturn(r);
1029 }
1030
1031 result
1032 _GroupedListViewImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
1033 {
1034         return GetCore().SetItemChecked(groupIndex, itemIndex, check);
1035 }
1036
1037 bool
1038 _GroupedListViewImpl::IsItemChecked(int groupIndex, int itemIndex) const
1039 {
1040         return GetCore().IsItemChecked(groupIndex, itemIndex);
1041 }
1042
1043 result
1044 _GroupedListViewImpl::SetItemEnabled(int groupIndex, int itemIndex, bool enable)
1045 {
1046         return GetCore().SetItemEnabled(groupIndex, itemIndex, enable);
1047 }
1048
1049 bool
1050 _GroupedListViewImpl::IsItemEnabled(int groupIndex, int itemIndex) const
1051 {
1052         return GetCore().IsItemEnabled(groupIndex, itemIndex);
1053 }
1054
1055 int
1056 _GroupedListViewImpl::GetGroupCount(void) const
1057 {
1058         return GetCore().GetGroupCount();
1059 }
1060
1061 int
1062 _GroupedListViewImpl::GetItemCountAt(int groupIndex) const
1063 {
1064         return GetCore().GetItemCountAt(groupIndex);
1065 }
1066
1067 result
1068 _GroupedListViewImpl::ShowItemDescriptionText(int groupIndex, int itemIndex)
1069 {
1070         return SetItemDescriptionTextShowState(groupIndex, itemIndex, true);
1071 }
1072
1073 result
1074 _GroupedListViewImpl::HideItemDescriptionText(int groupIndex, int itemIndex)
1075 {
1076         return SetItemDescriptionTextShowState(groupIndex, itemIndex, false);
1077 }
1078
1079 result
1080 _GroupedListViewImpl::SetItemDescriptionTextShowState(int groupIndex, int itemIndex, bool show)
1081 {
1082         result r = E_SUCCESS;
1083
1084         SysTryReturn(NID_UI_CTRL, (groupIndex >= 0) && (groupIndex < GetGroupCount()), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1085                         "[E_OUT_OF_RANGE] The specified groupIndex is out of range.");
1086
1087         SysTryReturn(NID_UI_CTRL, (itemIndex >= 0) && (itemIndex < GetItemCountAt(groupIndex)), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1088                         "[E_OUT_OF_RANGE] The specified itemIndex is out of range.");
1089
1090         _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
1091                         static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1092         SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] _GroupedListItemProviderAdaptor is not set.");
1093
1094         // Save description text show state to provider adaptor
1095         pProviderAdaptor->SetDescriptionTextShowState(groupIndex, itemIndex, show);
1096
1097         if (GetCore().FindItem(groupIndex, itemIndex) != null)
1098         {
1099                 r = GetCore().RefreshTableView(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1100         }
1101
1102         SetLastResultReturn(r);
1103 }
1104
1105 result
1106 _GroupedListViewImpl::RefreshList(int groupIndex, int itemIndex, ListRefreshType type)
1107 {
1108         result r = E_SUCCESS;
1109
1110         if (__needReloadItems)
1111         {
1112                 return r;
1113         }
1114
1115         int groupCount = GetCore().GetGroupCount();
1116         int itemCount = GetCore().GetItemCountAt(groupIndex);
1117
1118         if ((groupIndex < 0) || (groupIndex > groupCount) || (itemIndex < -1) || (itemIndex > itemCount) ||
1119                         ((type != LIST_REFRESH_TYPE_ITEM_ADD) && (itemIndex == itemCount)))
1120         {
1121                 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
1122                 return E_OUT_OF_RANGE;
1123         }
1124
1125         if (type == LIST_REFRESH_TYPE_ITEM_MODIFY)
1126         {
1127                 if (IsContextItemOpened(groupIndex, itemIndex))
1128                 {
1129                         CloseContextItem(groupIndex, itemIndex);
1130                 }
1131
1132                 int topGroupIndex = -1;
1133                 int topItemIndex = -1;
1134                 int bottomGroupIndex = -1;
1135                 int bottomItemIndex = -1;
1136
1137                 GetCore().GetFirstLoadedItemIndex(topGroupIndex, topItemIndex);
1138                 GetCore().GetLastLoadedItemIndex(bottomGroupIndex, bottomItemIndex);
1139
1140                 if ((topGroupIndex > groupIndex) || (bottomGroupIndex < groupIndex) ||
1141                                 ((topGroupIndex == groupIndex) && (topItemIndex > itemIndex)) ||
1142                                 ((bottomGroupIndex == groupIndex) && (bottomItemIndex < itemIndex)))
1143                 {
1144                         // not yet loaded item
1145                         SetLastResultReturn(r);
1146                 }
1147                 else
1148                 {
1149                         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1150                         _ListViewItemStatus itemStatus;
1151                         memset(&itemStatus, 0, sizeof(_ListViewItemStatus));
1152                         bool needChangeEventTarget = false;
1153
1154                         if (pListViewItem != null && pListViewItem->IsItemSelected())
1155                         {
1156                                 needChangeEventTarget = true;
1157                         }
1158
1159                         if (needChangeEventTarget && (pListViewItem != null))
1160                         {
1161                                 pListViewItem->GetCurrentStatus(itemStatus);
1162                                 pListViewItem = null;
1163                         }
1164
1165                         // item unload
1166                         GetCore().UnloadItem(groupIndex, itemIndex);
1167                         // item load
1168                         pListViewItem = static_cast<_ListViewItem*>(GetCore().LoadItem(groupIndex, itemIndex));
1169
1170                         if (needChangeEventTarget && (pListViewItem != null))
1171                         {
1172                                 pListViewItem->SetCurrentStatus(itemStatus);
1173
1174                                 _Control* pTarget = static_cast<_Control*>(pListViewItem);
1175
1176                                 for (int i = 0; i < pListViewItem->GetChildCount(); i++)
1177                                 {
1178                                         if (pListViewItem->GetChild(i)->GetBoundsF().Contains(itemStatus.currentTouchPosition))
1179                                         {
1180                                                 pTarget = pListViewItem->GetChild(i);
1181                                         }
1182                                 }
1183
1184                                 // change touch event target
1185                                 pTarget->SetChangingEventTarget(true);
1186                                 _TouchManager::GetInstance()->SetChangedTouchableTarget(pTarget);
1187                         }
1188                 }
1189         }
1190         else
1191         {
1192                 r = GetCore().RefreshTableView(groupIndex, itemIndex, static_cast<TableViewRefreshType>(type));
1193         }
1194
1195         CheckEmptyListShowState();
1196
1197         Draw();
1198         Show();
1199
1200         SetLastResultReturn(r);
1201 }
1202
1203 result
1204 _GroupedListViewImpl::RefreshList(int groupIndex, int itemIndex, int elementId)
1205 {
1206         if ((groupIndex < 0) || (groupIndex >= GetCore().GetGroupCount()) || (itemIndex < 0) || (itemIndex >= GetCore().GetItemCountAt(groupIndex)))
1207         {
1208                 return E_OUT_OF_RANGE;
1209         }
1210
1211         result r = E_SUCCESS;
1212         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1213
1214         if (pListViewItem != null)
1215         {
1216                 r = (pListViewItem->RefreshElement(elementId)) ? E_SUCCESS : E_OUT_OF_RANGE;
1217         }
1218
1219         SetLastResultReturn(r);
1220 }
1221
1222 result
1223 _GroupedListViewImpl::UpdateList(void)
1224 {
1225         __needReloadItems = true;
1226
1227         result r = GetCore().UpdateTableView();
1228
1229         CheckEmptyListShowState();
1230
1231         Invalidate(true);
1232
1233         // API versioning for initial Show() operation
1234         if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
1235         {
1236                 Show();
1237         }
1238
1239         __needReloadItems = false;
1240
1241         SetLastResultReturn(r);
1242 }
1243
1244 void
1245 _GroupedListViewImpl::SetItemNeedsLazyDeletion(_ListViewItem* pItem)
1246 {
1247         _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
1248                         static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1249
1250         if (pProviderAdaptor != null)
1251         {
1252                 pProviderAdaptor->SetItemNeedsLazyDeletion(pItem);
1253         }
1254 }
1255
1256 result
1257 _GroupedListViewImpl::GetItemIndexFromPosition(const FloatPoint& position, int& groupIndex, int& itemIndex) const
1258 {
1259         result r = GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
1260
1261         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] There is no item at the specified position.");
1262
1263         SetLastResultReturn(r);
1264 }
1265
1266 result
1267 _GroupedListViewImpl::GetItemIndexFromPosition(const FloatPoint& position, int& groupIndex, int& itemIndex, int& elementId) const
1268 {
1269         elementId = -1;
1270
1271         result r =  GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
1272         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] There is no item at the specified position.");
1273
1274         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1275
1276         if (pListViewItem != null)
1277         {
1278                 FloatPoint originPosition = pListViewItem->GetPositionF();
1279                 originPosition.y -= GetCore().GetScrollPosition();
1280
1281                 elementId = pListViewItem->GetElementIdFromPosition(FloatPoint(position.x - originPosition.x, position.y - originPosition.y));
1282         }
1283
1284         SetLastResultReturn(r);
1285 }
1286
1287 result
1288 _GroupedListViewImpl::SetSectionColor(const Color& color)
1289 {
1290         return GetCore().SetSectionColor(color);
1291 }
1292
1293 Color
1294 _GroupedListViewImpl::GetSectionColor(void) const
1295 {
1296         return GetCore().GetSectionColor();
1297 }
1298
1299 result
1300 _GroupedListViewImpl::SetItemDividerColor(const Color& color)
1301 {
1302         return GetCore().SetItemDividerColor(color);
1303 }
1304
1305 Color
1306 _GroupedListViewImpl::GetItemDividerColor(void) const
1307 {
1308         return GetCore().GetItemDividerColor();
1309 }
1310
1311 void
1312 _GroupedListViewImpl::SetListBackgroundColor(const Color& color)
1313 {
1314         SetBackgroundColor(color);
1315 }
1316
1317 result
1318 _GroupedListViewImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
1319 {
1320         GetCore().SetBackgroundBitmap(const_cast<Bitmap*>(pBitmap));
1321         GetCore().SetBackgroundBitmapStretch(true);
1322
1323         SetLastResultReturn(E_SUCCESS);
1324 }
1325
1326 result
1327 _GroupedListViewImpl::SetBitmapOfEmptyList(const Bitmap* pBitmap)
1328 {
1329         if (pBitmap == null)
1330         {
1331                 if (__pEmptyBitmap != null)
1332                 {
1333                         GetCore().DetachChild(*__pEmptyBitmap);
1334
1335                         delete __pEmptyBitmap;
1336                         __pEmptyBitmap = null;
1337                 }
1338         }
1339         else
1340         {
1341                 if (__pEmptyBitmap == null)
1342                 {
1343                         __pEmptyBitmap = _Label::CreateLabelN();
1344                         SysTryReturn(NID_UI_CTRL, (__pEmptyBitmap != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1345
1346                         __pEmptyBitmap->SetVisibleState(false);
1347                         __pEmptyBitmap->SetMargin(0.0f, 0.0f);
1348
1349                         GetCore().AttachChild(*__pEmptyBitmap);
1350                 }
1351
1352                 __pEmptyBitmap->SetSize(FloatDimension(pBitmap->GetWidthF(), pBitmap->GetHeightF()));
1353                 __pEmptyBitmap->SetBackgroundColor(Color(0, 0, 0, 0));
1354                 __pEmptyBitmap->SetBackgroundBitmap(*pBitmap);
1355         }
1356
1357         AdjustLayoutOfEmptyList();
1358
1359         SetLastResultReturn(E_SUCCESS);
1360 }
1361
1362 result
1363 _GroupedListViewImpl::SetTextOfEmptyList(const String& text)
1364 {
1365         if (text.IsEmpty())
1366         {
1367                 if (__pEmptyText != null)
1368                 {
1369                         GetCore().DetachChild(*__pEmptyText);
1370
1371                         delete __pEmptyText;
1372                         __pEmptyText = null;
1373                 }
1374         }
1375         else
1376         {
1377                 if (__pEmptyText == null)
1378                 {
1379                         __pEmptyText = _Label::CreateLabelN();
1380                         SysTryReturn(NID_UI_CTRL, (__pEmptyText != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1381
1382                         __pEmptyText->SetVisibleState(false);
1383                         __pEmptyText->SetMargin(0.0f, 0.0f);
1384
1385                         GetCore().AttachChild(*__pEmptyText);
1386                 }
1387
1388                 TextObject* pText = new (std::nothrow) TextObject;
1389                 SysTryReturn(NID_UI_CTRL, (pText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1390
1391                 pText->Construct();
1392
1393                 TextSimple* pSimpleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(text.GetPointer()), text.GetLength());
1394                 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1395                 pText->AppendElement(*pSimpleText);
1396
1397                 float fontSize = 0.0f;
1398                 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, fontSize);
1399
1400                 Font font;
1401                 font.Construct(GetFont(), FONT_STYLE_PLAIN, fontSize);
1402                 pText->SetFont(&font, 0, pText->GetTextLength());
1403
1404                 FloatDimension listDimension = GetCore().GetSizeF();
1405
1406                 pText->SetBounds(FloatRectangle(0.0f, 0.0f, listDimension.width, 1.0f));
1407                 pText->Compose();
1408
1409                 FloatDimension labelDimension = pText->GetTextExtentF(0, pText->GetTextLength());
1410                 labelDimension.height = pText->GetTotalHeightF();
1411
1412                 if (labelDimension.width > listDimension.width)
1413                 {
1414                         pText->SetBounds(FloatRectangle(0.0f, 0.0f, listDimension.width, 1.0f));
1415                         pText->Compose();
1416
1417                         float labelHeight = pText->GetTotalHeightF();
1418
1419                         labelDimension.width = listDimension.width;
1420                         labelDimension.height = ((listDimension.height < labelHeight) ? listDimension.height : labelHeight);
1421                 }
1422
1423                 delete pText;
1424
1425                 __pEmptyText->SetSize(labelDimension);
1426                 __pEmptyText->SetBackgroundColor(Color(0, 0, 0, 0));
1427                 __pEmptyText->SetMargin(0.0f, 0.0f, 0.0f, 0.0f);
1428                 __pEmptyText->SetTextColor(__emptyTextColor);
1429                 __pEmptyText->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
1430                 __pEmptyText->SetText(text);
1431         }
1432
1433         AdjustLayoutOfEmptyList();
1434
1435         SetLastResultReturn(E_SUCCESS);
1436 }
1437
1438 String
1439 _GroupedListViewImpl::GetTextOfEmptyList(void) const
1440 {
1441         return ((__pEmptyText != null) ? __pEmptyText->GetText() : String());
1442 }
1443
1444 result
1445 _GroupedListViewImpl::SetTextColorOfEmptyList(const Color& color)
1446 {
1447         __emptyTextColor = color;
1448
1449         if (__pEmptyText != null)
1450         {
1451                 __pEmptyText->SetTextColor(color);
1452         }
1453
1454         SetLastResultReturn(E_SUCCESS);
1455 }
1456
1457 Color
1458 _GroupedListViewImpl::GetTextColorOfEmptyList(void) const
1459 {
1460         return __emptyTextColor;
1461 }
1462
1463 result
1464 _GroupedListViewImpl::ExpandGroup(int groupIndex)
1465 {
1466         SysTryReturn(NID_UI_CTRL, (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED), E_INVALID_OPERATION, E_INVALID_OPERATION,
1467                         "[E_INVALID_OPERATION] The control should be indexed style.");
1468
1469         return GetCore().ExpandGroup(groupIndex);
1470 }
1471
1472 result
1473 _GroupedListViewImpl::CollapseGroup(int groupIndex)
1474 {
1475         SysTryReturn(NID_UI_CTRL, (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED), E_INVALID_OPERATION, E_INVALID_OPERATION,
1476                         "[E_INVALID_OPERATION] The control should be indexed style.");
1477
1478         return GetCore().CollapseGroup(groupIndex);
1479 }
1480
1481 bool
1482 _GroupedListViewImpl::IsGroupExpanded(int groupIndex) const
1483 {
1484         return GetCore().IsGroupExpanded(groupIndex);
1485 }
1486
1487 result
1488 _GroupedListViewImpl::ExpandAllGroups(void)
1489 {
1490         SysTryReturn(NID_UI_CTRL, (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED), E_INVALID_OPERATION, E_INVALID_OPERATION,
1491                         "[E_INVALID_OPERATION] The control should be indexed style.");
1492
1493         return GetCore().ExpandAllGroup(true);
1494 }
1495
1496 result
1497 _GroupedListViewImpl::CollapseAllGroups(void)
1498 {
1499         SysTryReturn(NID_UI_CTRL, (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED), E_INVALID_OPERATION, E_INVALID_OPERATION,
1500                         "[E_INVALID_OPERATION] The control should be indexed style.");
1501
1502         return GetCore().CollapseAllGroup(true);
1503 }
1504
1505 void
1506 _GroupedListViewImpl::CheckEmptyListShowState(void)
1507 {
1508         bool isEmpty = (GetGroupCount() == 0);
1509
1510         if (__pEmptyBitmap != null)
1511         {
1512                 __pEmptyBitmap->SetVisibleState(isEmpty);
1513         }
1514         if (__pEmptyText != null)
1515         {
1516                 __pEmptyText->SetVisibleState(isEmpty);
1517         }
1518
1519         _AccessibilityContainer* pContainer = GetCore().GetAccessibilityContainer();
1520
1521         if (_AccessibilityManager::IsActivated() && (pContainer != null))
1522         {
1523                 if (isEmpty)
1524                 {
1525                         if (__pAccessibilityElement == null)
1526                         {
1527                                 __pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
1528
1529                                 SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityElement != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1530
1531                                 __pAccessibilityElement->SetName(L"ListView");
1532
1533                                 pContainer->RemoveAllElement();
1534                                 pContainer->AddElement(*__pAccessibilityElement);
1535                         }
1536
1537                         Rectangle bounds = GetBounds();
1538                         __pAccessibilityElement->SetBounds(Rectangle(0, 0, bounds.width, bounds.height));
1539
1540                         String accessibilityLable;
1541
1542                         if (__pEmptyBitmap != null)
1543                         {
1544                                 __pEmptyBitmap->GetAccessibilityContainer()->Activate(false);
1545
1546                                 accessibilityLable += L"Image, ";
1547                         }
1548                         if (__pEmptyText != null)
1549                         {
1550                                 __pEmptyText->GetAccessibilityContainer()->Activate(false);
1551
1552                                 accessibilityLable += __pEmptyText->GetText();
1553                                 accessibilityLable += L", ";
1554                         }
1555
1556                         accessibilityLable += L"No items";
1557
1558                         __pAccessibilityElement->SetLabel(accessibilityLable);
1559                 }
1560                 else
1561                 {
1562                         if (__pAccessibilityElement != null)
1563                         {
1564                                 if (pContainer->RemoveElement(*__pAccessibilityElement) != E_SUCCESS)
1565                                 {
1566                                         delete __pAccessibilityElement;
1567                                 }
1568                                 __pAccessibilityElement = null;
1569                         }
1570                 }
1571         }
1572 }
1573
1574 void
1575 _GroupedListViewImpl::AdjustLayoutOfEmptyList(void)
1576 {
1577         FloatDimension listDimension = GetCore().GetSizeF();
1578         FloatDimension emptyBitmap;
1579         FloatDimension emptyText;
1580         FloatPoint bitmapPos;
1581         FloatPoint textPos;
1582         float totalHeight = 0.0f;
1583         float horizontalSpacing = 0.0f;
1584
1585         if (__pEmptyBitmap != null)
1586         {
1587                 emptyBitmap = __pEmptyBitmap->GetSizeF();
1588         }
1589         if (__pEmptyText != null)
1590         {
1591                 emptyText = __pEmptyText->GetSizeF();
1592
1593                 if (__pEmptyBitmap != null)
1594                 {
1595                         GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_HORIZONTAL_SPACING, _CONTROL_ORIENTATION_PORTRAIT, horizontalSpacing);
1596                 }
1597         }
1598
1599         totalHeight = emptyBitmap.height + horizontalSpacing + emptyText.height;
1600
1601         if ((__pEmptyBitmap != null) && (__pEmptyText != null) && (totalHeight < listDimension.height))
1602         {
1603                 bitmapPos.x = ((_FloatCompare(listDimension.width, emptyBitmap.width)) ? 0.0f : (listDimension.width - emptyBitmap.width) / 2.0f);
1604                 bitmapPos.y = (listDimension.height - totalHeight) / 2.0f;
1605
1606                 textPos.x = ((_FloatCompare(listDimension.width, emptyText.width)) ? 0.0f : (listDimension.width - emptyText.width) / 2.0f);
1607                 textPos.y = bitmapPos.y + emptyBitmap.height + horizontalSpacing;
1608         }
1609         else
1610         {
1611                 if (__pEmptyBitmap != null)
1612                 {
1613                         bitmapPos.x = ((_FloatCompare(listDimension.width, emptyBitmap.width)) ? 0.0f : (listDimension.width - emptyBitmap.width) / 2.0f);
1614                         bitmapPos.y = ((listDimension.height <= totalHeight) ? 0.0f : (listDimension.height - totalHeight) / 2.0f);
1615                 }
1616
1617                 if (__pEmptyText != null)
1618                 {
1619                         textPos.x = ((_FloatCompare(listDimension.width, emptyText.width)) ? 0.0f : (listDimension.width - emptyText.width) / 2.0f);
1620                         textPos.y = ((listDimension.height <= totalHeight ) ? (bitmapPos.y + emptyBitmap.height + horizontalSpacing) : (listDimension.height - totalHeight) / 2.0f);
1621                 }
1622         }
1623
1624         if (__pEmptyBitmap != null)
1625         {
1626                 __pEmptyBitmap->SetPosition(bitmapPos);
1627         }
1628         if (__pEmptyText != null)
1629         {
1630                 __pEmptyText->SetPosition(textPos);
1631         }
1632
1633         CheckEmptyListShowState();
1634         Invalidate(true);
1635 }
1636
1637 result
1638 _GroupedListViewImpl::BeginReorderingMode(void)
1639 {
1640         SysTryReturn(NID_UI_CTRL, (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED), E_INVALID_OPERATION, E_INVALID_OPERATION,
1641                         "[E_INVALID_OPERATION] Reordering mode is supported only Indexed style.");
1642
1643         result r = GetCore().SetReorderModeEnabled(true);
1644
1645         SetLastResultReturn(r);
1646 }
1647
1648 result
1649 _GroupedListViewImpl::EndReorderingMode(void)
1650 {
1651         SysTryReturn(NID_UI_CTRL, (GetCore().GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED), E_INVALID_OPERATION, E_INVALID_OPERATION,
1652                         "[E_INVALID_OPERATION] Reordering mode is supported only Indexed style.");
1653
1654         result r = GetCore().SetReorderModeEnabled(false);
1655
1656         SetLastResultReturn(r);
1657 }
1658
1659 bool
1660 _GroupedListViewImpl::IsInReorderingMode(void) const
1661 {
1662         return GetCore().IsReorderModeEnabled();
1663 }
1664
1665 void
1666 _GroupedListViewImpl::SetScrollInputMode(ScrollInputMode mode)
1667 {
1668         GetCore().SetScrollInputMode(mode);
1669 }
1670
1671 ScrollInputMode
1672 _GroupedListViewImpl::GetScrollInputMode(void) const
1673 {
1674         return GetCore().GetScrollInputMode();
1675 }
1676
1677 result
1678 _GroupedListViewImpl::OpenContextItem(int groupIndex, int itemIndex)
1679 {
1680         return GetCore().OpenContextItem(groupIndex, itemIndex);
1681 }
1682
1683 result
1684 _GroupedListViewImpl::CloseContextItem(int groupIndex, int itemIndex)
1685 {
1686         return GetCore().CloseContextItem(groupIndex, itemIndex);
1687 }
1688
1689 bool
1690 _GroupedListViewImpl::IsContextItemOpened(int groupIndex, int itemIndex) const
1691 {
1692         return GetCore().IsContextItemOpened(groupIndex, itemIndex);
1693 }
1694
1695 void
1696 _GroupedListViewImpl::OnListViewContextItemStateChanged(_Control& source, int groupIndex, int itemIndex, int elementId,
1697                 ListContextItemStatus status)
1698 {
1699         if (__pListItemEvent != null)
1700         {
1701                 CloseContextItem(groupIndex, itemIndex);
1702
1703                 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1704
1705                 SetItemNeedsLazyDeletion(pListViewItem);
1706
1707                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(groupIndex, itemIndex, elementId, 0, NOTIFY_TYPE_SELCTED_CONTEXT_ITEM);
1708                 __pListItemEvent->Fire(*pArg);
1709
1710                 SetItemNeedsLazyDeletion(null);
1711         }
1712 }
1713
1714 void
1715 _GroupedListViewImpl::OnGroupedTableViewGroupItemStateChanged(_TableView& tableView, int groupIndex, _TableViewItem* pItem,
1716                 TableViewItemStatus status)
1717 {
1718         FireListViewItemEvent(groupIndex, -1, pItem, status);
1719 }
1720
1721 void
1722 _GroupedListViewImpl::OnGroupedTableViewItemStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pItem,
1723                 TableViewItemStatus status)
1724 {
1725         FireListViewItemEvent(groupIndex, itemIndex, pItem, status);
1726 }
1727
1728 void
1729 _GroupedListViewImpl::OnGroupedTableViewContextItemActivationStateChanged(_TableView& tableView, int groupIndex, int itemIndex,
1730                 _TableViewItem* pContextItem, bool activated)
1731 {
1732         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1733
1734         if (pListViewItem != null)
1735         {
1736                 pListViewItem->SetContextItemActivationState(activated);
1737         }
1738 }
1739
1740 void
1741 _GroupedListViewImpl::OnGroupedTableViewItemReordered(_TableView& tableView, int groupIndexFrom, int itemIndexFrom,
1742                 int groupIndexTo, int itemIndexTo)
1743 {
1744         if (__pListItemEvent != null)
1745         {
1746                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(groupIndexFrom, itemIndexFrom, groupIndexTo, itemIndexTo,
1747                                 NOTIFY_TYPE_REORDERED_ITEM);
1748                 __pListItemEvent->Fire(*pArg);
1749         }
1750 }
1751
1752 void
1753 _GroupedListViewImpl::OnSectionTableViewItemStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pItem,
1754                 TableViewItemStatus status)
1755 {
1756         FireListViewItemEvent(sectionIndex, itemIndex, pItem, status);
1757 }
1758
1759 void
1760 _GroupedListViewImpl::OnSectionTableViewContextItemActivationStateChanged(_TableView& tableView, int sectionIndex, int itemIndex,
1761                 _TableViewItem* pContextItem, bool activated)
1762 {
1763         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(sectionIndex, itemIndex));
1764
1765         if (pListViewItem != null)
1766         {
1767                 pListViewItem->SetContextItemActivationState(activated);
1768         }
1769 }
1770
1771 void
1772 _GroupedListViewImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1773 {
1774         if (__pListItemEvent != null)
1775         {
1776                 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1777
1778                 SetItemNeedsLazyDeletion(pListViewItem);
1779
1780                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(groupIndex, itemIndex, direction, 0, NOTIFY_TYPE_SWEPT_ITEM);
1781                 __pListItemEvent->Fire(*pArg);
1782
1783                 SetItemNeedsLazyDeletion(null);
1784         }
1785 }
1786
1787 void
1788 _GroupedListViewImpl::FireListViewItemEvent(int groupIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1789 {
1790         if (__pListItemEvent != null)
1791         {
1792                 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(pItem);
1793
1794                 if (pListViewItem != null)
1795                 {
1796                         SetItemNeedsLazyDeletion(pListViewItem);
1797
1798                         _ListViewItemStateChangedInfo itemInfo;
1799                         pListViewItem->GetLastStateChangedInfo(itemInfo);
1800
1801                         if ((__pLinkEvent != null) && (itemInfo.pUiLinkInfo != null))
1802                         {
1803                                 IEventArg* pLinkEventArg = _PublicLinkEvent::CreateLinkEventArgN(itemInfo.pUiLinkInfo->textInfo,
1804                                                 itemInfo.pUiLinkInfo->linkType, itemInfo.pUiLinkInfo->linkInfo);
1805                                 SysTryReturnVoidResult(NID_UI_CTRL, (pLinkEventArg != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _LinkEventArg.");
1806                                 __pLinkEvent->Fire(*pLinkEventArg);
1807
1808                         }
1809                         else
1810                         {
1811                                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(groupIndex, itemIndex, itemInfo.elementId, 0,
1812                                                 static_cast<NotifyType>(status));
1813                                 __pListItemEvent->Fire(*pArg);
1814                         }
1815
1816                         pListViewItem->ClearLastStateChangedInfo();
1817
1818                         SetItemNeedsLazyDeletion(null);
1819                 }
1820         }
1821 }
1822
1823 void
1824 _GroupedListViewImpl::FireListViewItemLongPressedEvent(void)
1825 {
1826         if (__pListItemEvent != null)
1827         {
1828                 int groupIndex = -1;
1829                 int itemIndex = -1;
1830                 int elementId = -1;
1831
1832                 if ((GetItemIndexFromPosition(GetCurrentTouchPosition(), groupIndex, itemIndex, elementId) == E_SUCCESS) && (itemIndex != -1))
1833                 {
1834                         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(groupIndex, itemIndex));
1835
1836                         if ((pListViewItem != null) && (!pListViewItem->IsContextItem()))
1837                         {
1838                                 SetItemNeedsLazyDeletion(pListViewItem);
1839
1840                                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(groupIndex, itemIndex, elementId, 0, NOTIFY_TYPE_LONG_PRESSED_ITEM);
1841                                 __pListItemEvent->Fire(*pArg);
1842
1843                                 SetItemNeedsLazyDeletion(null);
1844                         }
1845                 }
1846         }
1847 }
1848
1849 void
1850 _GroupedListViewImpl::OnScrollEndReached(_Control& source, ScrollEndEvent type)
1851 {
1852         if (__pScrollEvent != null)
1853         {
1854                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), type);
1855                 result r = GetLastResult();
1856                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1857
1858                 __pScrollEvent->Fire(*pEventArg);
1859         }
1860 }
1861
1862 void
1863 _GroupedListViewImpl::OnScrollPositionChanged(_Control& source, float scrollPosition)
1864 {
1865         if (__pScrollEvent != null)
1866         {
1867                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), scrollPosition);
1868                 result r = GetLastResult();
1869                 SysTryReturnVoidResult(NID_UI_CTRL, (pEventArg != null), r, "[%s] Propagating.", GetErrorMessage(r));
1870
1871                 __pScrollEvent->Fire(*pEventArg);
1872         }
1873 }
1874
1875 void
1876 _GroupedListViewImpl::OnScrollStopped(_Control& source)
1877 {
1878         if (__pScrollEvent != null)
1879         {
1880                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic());
1881                 result r = GetLastResult();
1882                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1883
1884                 __pScrollEvent->Fire(*pEventArg);
1885         }
1886 }
1887
1888 void
1889 _GroupedListViewImpl::OnUiFastScrollIndexSelected(_Control& source, _FastScrollIndex& index)
1890 {
1891         if (__pFastScrollEvent != null)
1892         {
1893                 String* pIndexText = index.GetIndexText();
1894                 if (pIndexText != null)
1895                 {
1896                         _FastScrollEventArg* pEventArg = new (std::nothrow) _FastScrollEventArg(GetPublic(), *pIndexText);
1897                         __pFastScrollEvent->Fire(*pEventArg);
1898                 }
1899         }
1900 }
1901
1902 void
1903 _GroupedListViewImpl::OnDraw(void)
1904 {
1905         _ControlImpl::OnDraw();
1906
1907         if (__redrawListView)
1908         {
1909                 CheckEmptyListShowState();
1910                 __redrawListView = false;
1911         }
1912 }
1913
1914 void
1915 _GroupedListViewImpl::OnChangeLayout(_ControlOrientation orientation)
1916 {
1917         __isOrientationChanged = true;
1918
1919         _ControlImpl::OnChangeLayout(orientation);
1920 }
1921
1922 void
1923 _GroupedListViewImpl::OnBoundsChanged(void)
1924 {
1925         _ControlImpl::OnBoundsChanged();
1926
1927         if (__pEmptyBitmap != null)
1928         {
1929                 SetBitmapOfEmptyList(__pEmptyBitmap->GetBackgroundBitmap());
1930         }
1931         if (__pEmptyText != null)
1932         {
1933                 SetTextOfEmptyList(__pEmptyText->GetText());
1934         }
1935
1936         if (__isOrientationChanged)
1937         {
1938                 __isOrientationChanged = false;
1939                 UpdateList();
1940         }
1941 }
1942
1943 void
1944 _GroupedListViewImpl::OnFontChanged(Font* pFont)
1945 {
1946         String fontName = GetFont();
1947         _GroupedListViewItemProviderAdaptor* pProviderAdaptor =
1948                         static_cast <_GroupedListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1949
1950         if (__pEmptyText != null)
1951         {
1952                 __pEmptyText->SetFont(fontName);
1953                 SetTextOfEmptyList(__pEmptyText->GetText());
1954         }
1955
1956         if (pProviderAdaptor != null)
1957         {
1958                 pProviderAdaptor->SetItemFont(fontName);
1959         }
1960
1961         int firstGroup = -1;
1962         int firstItem = -1;
1963         int lastGroup = -1;
1964         int lastItem = -1;
1965         int currentItem = -1;
1966         int lastItemInGroup = -1;
1967
1968         GetCore().GetFirstLoadedItemIndex(firstGroup, firstItem);
1969         GetCore().GetLastLoadedItemIndex(lastGroup, lastItem);
1970
1971         for (int i = firstGroup; i <= lastGroup; i++)
1972         {
1973                 currentItem = ((i == firstGroup) ? firstItem : -1);
1974                 lastItemInGroup = ((i == lastGroup) ? lastItem : (GetCore().GetItemCountAt(i) - 1));
1975
1976                 for (; currentItem <= lastItemInGroup; currentItem++)
1977                 {
1978                         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(i, currentItem));
1979
1980                         if (pListViewItem != null)
1981                         {
1982                                 pListViewItem->SetFont(fontName);
1983                         }
1984                 }
1985         }
1986 }
1987
1988 void
1989 _GroupedListViewImpl::OnFontInfoRequested(unsigned long& style, int& size)
1990 {
1991         float textSize = 0.0f;
1992         OnFontInfoRequested(style, textSize);
1993
1994         size = _CoordinateSystemUtils::ConvertToInteger(textSize);
1995 }
1996
1997 void
1998 _GroupedListViewImpl::OnFontInfoRequested(unsigned long& style, float& size)
1999 {
2000         GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, size);
2001         style = FONT_STYLE_PLAIN;
2002 }
2003
2004 FloatPoint
2005 _GroupedListViewImpl::GetCurrentTouchPosition(void)
2006 {
2007         FloatPoint currentTouchPos = _TouchManager::GetInstance()->GetScreenPoint(0);
2008         FloatRectangle bounds = GetCore().GetAbsoluteBoundsF();
2009
2010         currentTouchPos.x -= bounds.x;
2011         currentTouchPos.y -= bounds.y;
2012
2013         return currentTouchPos;
2014 }
2015
2016 result
2017 _GroupedListViewImpl::OnTouchEventListenerAdded(void)
2018 {
2019         return E_SUCCESS;
2020 }
2021
2022 result
2023 _GroupedListViewImpl::OnTouchEventListenerRemoved(void)
2024 {
2025         return E_SUCCESS;
2026 }
2027
2028 class _GroupedListViewMaker
2029         : public _UiBuilderControlMaker
2030 {
2031 public:
2032         _GroupedListViewMaker(_UiBuilder* uibuilder)
2033                 : _UiBuilderControlMaker(uibuilder){};
2034
2035         virtual ~_GroupedListViewMaker(){};
2036
2037         static _UiBuilderControlMaker*
2038         GetInstance(_UiBuilder* uibuilder)
2039         {
2040                 _GroupedListViewMaker* pGroupedListViewMaker = new (std::nothrow) _GroupedListViewMaker(uibuilder);
2041                 return pGroupedListViewMaker;
2042         };
2043 protected:
2044         virtual Tizen::Ui::Control*
2045         Make(_UiBuilderControl* pControl)
2046         {
2047                 result r = E_SYSTEM;
2048                 _UiBuilderControlLayout* pControlProperty = null;
2049                 GroupedListView* pGroupedListView = null;
2050                 FloatRectangle rect;
2051
2052                 ListScrollStyle scrollStyle = SCROLL_STYLE_FADE_OUT;
2053                 GroupedListViewStyle style = GROUPED_LIST_VIEW_STYLE_INDEXED;
2054                 ScrollInputMode scrollInputMode = SCROLL_INPUT_MODE_ALLOW_ANY_DIRECTION;
2055
2056                 String elementString;
2057                 bool itemDividerState = true;
2058                 int opacity = 100;
2059                 bool sweepEnabledState = false;
2060                 Color color;
2061
2062                 GetProperty(pControl, &pControlProperty);
2063                 if (pControlProperty == null)
2064                 {
2065                         return null;
2066                 }
2067
2068                 pGroupedListView = new (std::nothrow) GroupedListView();
2069                 if (pGroupedListView == null)
2070                 {
2071                         return null;
2072                 }
2073
2074                 rect = pControlProperty->GetRectF();
2075
2076                 String styleString;
2077                 styleString = pControlProperty->GetStyle();
2078
2079                 if (styleString.Equals(L"GROUPED_LIST_VIEW_STYLE_SECTION", false))
2080                 {
2081                         style = GROUPED_LIST_VIEW_STYLE_SECTION;
2082                 }
2083                 else
2084                 {
2085                         style = GROUPED_LIST_VIEW_STYLE_INDEXED;
2086                 }
2087
2088                 //Construct
2089                 if (pControl->GetElement(L"itemDivider", elementString))
2090                 {
2091                         if (elementString.Equals(L"true", false))
2092                         {
2093                                 itemDividerState = true;
2094                         }
2095                         else
2096                         {
2097                                 itemDividerState = false;
2098                         }
2099                 }
2100
2101                 if (pControl->GetElement(L"listScrollStyle", elementString))
2102                 {
2103                         if (elementString.Equals(L"SCROLL_STYLE_FIXED", false))
2104                         {
2105                                 scrollStyle = SCROLL_STYLE_FIXED;
2106                         }
2107                         else if (elementString.Equals(L"SCROLL_STYLE_FAST_SCROLL", false))
2108                         {
2109                                 scrollStyle = SCROLL_STYLE_FAST_SCROLL;
2110                         }
2111                         else if (elementString.Equals(L"SCROLL_STYLE_JUMP_TO_TOP", false))
2112                         {
2113                                 scrollStyle = SCROLL_STYLE_JUMP_TO_TOP;
2114                         }
2115                         else if (elementString.Equals(L"SCROLL_STYLE_THUMB", false))
2116                         {
2117                                 scrollStyle = SCROLL_STYLE_THUMB;
2118                         }
2119                 }
2120                 else if (pControl->GetElement(L"fastScroll", elementString))
2121                 {
2122                         if (elementString.Equals(L"true", false))
2123                         {
2124                                 scrollStyle = SCROLL_STYLE_FAST_SCROLL;
2125                         }
2126                 }
2127
2128                 r = pGroupedListView->Construct(rect, style, itemDividerState, scrollStyle);
2129                 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2130
2131                 // Set BackgroundsBitmap
2132                 if (pControl->GetElement("backgroundBitmapPath", elementString))
2133                 {
2134                         Bitmap* pBackgroundBitmap = null;
2135                         pBackgroundBitmap = LoadBitmapN(elementString);
2136                         if (pBackgroundBitmap != null)
2137                         {
2138                                 r = pGroupedListView->SetBackgroundBitmap(pBackgroundBitmap);
2139                                 delete pBackgroundBitmap;
2140                                 pBackgroundBitmap = null;
2141
2142                                 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2143                         }
2144                 }
2145
2146                 // Set Empty List
2147                 if (pControl->GetElement(L"textOfEmptyList", elementString))
2148                 {
2149                         r = pGroupedListView->SetTextOfEmptyList(elementString);
2150                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2151                 }
2152
2153                 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
2154                 {
2155                         ConvertStringToColor(elementString, color);
2156                         r = pGroupedListView->SetTextColorOfEmptyList(color);
2157                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2158                 }
2159
2160                 if (pControl->GetElement(L"bitmapPathOfEmptyList", elementString))
2161                 {
2162                         Bitmap* pBackgroundBitmap = null;
2163                         pBackgroundBitmap = LoadBitmapN(elementString); //__image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
2164                         if (pBackgroundBitmap != null)
2165                         {
2166                                 r = pGroupedListView->SetBitmapOfEmptyList(pBackgroundBitmap);
2167                                 delete pBackgroundBitmap;
2168                                 pBackgroundBitmap = null;
2169
2170                                 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2171                         }
2172                 }
2173
2174                 if (pControl->GetElement(L"backgroundColorOpacity", elementString) || pControl->GetElement(L"BGColorOpacity", elementString))
2175                 {
2176                         Base::Integer::Parse(elementString, opacity);
2177                 }
2178
2179                 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
2180                 {
2181                         ConvertStringToColor32(elementString, opacity, color);
2182                         r = pGroupedListView->SetBackgroundColor(color);
2183                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2184                 }
2185
2186                 if (pControl->GetElement(L"itemDividerColor", elementString))
2187                 {
2188                         ConvertStringToColor(elementString, color);
2189                         r = pGroupedListView->SetItemDividerColor(color);
2190                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2191                 }
2192
2193                 if (pControl->GetElement(L"sectionColor", elementString))
2194                 {
2195                         ConvertStringToColor(elementString, color);
2196                         r = pGroupedListView->SetSectionColor(color);
2197                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2198                 }
2199
2200                 if (pControl->GetElement(L"sweepEnabled", elementString))
2201                 {
2202                         {
2203                                 if (elementString.Equals(L"true", false))
2204                                 {
2205                                         sweepEnabledState = true;
2206                                 }
2207                                 else
2208                                 {
2209                                         sweepEnabledState = false;
2210                                 }
2211                         }
2212                         r = pGroupedListView->SetSweepEnabled(sweepEnabledState);
2213                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2214                 }
2215
2216                 // scroll Input Mode
2217                 if (pControl->GetElement(L"scrollInputMode", elementString))
2218                 {
2219                         if (elementString.Equals(L"SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION", false))
2220                         {
2221                                 scrollInputMode = SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION;
2222                         }
2223
2224                         pGroupedListView->SetScrollInputMode(scrollInputMode);
2225                 }
2226
2227                 return pGroupedListView;
2228
2229         CATCH:
2230                 delete pGroupedListView;
2231                 return null;
2232         }
2233
2234 private:
2235 }; // _GroupedListViewMaker
2236
2237 _GroupedListViewRegister::_GroupedListViewRegister()
2238 {
2239           _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2240           pUiBuilderControlTableManager->RegisterControl(L"GroupedListView", _GroupedListViewMaker::GetInstance);
2241 }
2242
2243 _GroupedListViewRegister::~_GroupedListViewRegister()
2244 {
2245           _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2246           pUiBuilderControlTableManager->UnregisterControl(L"GroupedListView");
2247 }
2248 static _GroupedListViewRegister GroupedListViewRegisterToUIbuilder;
2249 }}} // Tizen::Ui::Controls