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