Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_GalleryItemProviderAdaptorImpl.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 #include <FBaseErrors.h>
18 #include <FUiCtrlGalleryItem.h>
19 #include <FUiCtrlIGalleryItemProvider.h>
20 #include <FBaseSysLog.h>
21 #include "FUiCtrl_GalleryItemProviderAdaptorImpl.h"
22 #include "FUiCtrl_GalleryItemImpl.h"
23 #include "FUiCtrl_GalleryItem.h"
24
25 namespace Tizen { namespace Ui { namespace Controls {
26
27 _GalleryItemProviderAdaptorImpl::_GalleryItemProviderAdaptorImpl(void)
28         : __pItemProvider(null)
29 {
30         // Do nothing
31 }
32
33 _GalleryItemProviderAdaptorImpl::~_GalleryItemProviderAdaptorImpl(void)
34 {
35         // Do nothing
36 }
37
38 void
39 _GalleryItemProviderAdaptorImpl::SetGalleryItemProvider(const IGalleryItemProvider& itemProvider)
40 {
41         __pItemProvider = &const_cast<IGalleryItemProvider&>(itemProvider);
42 }
43
44 bool
45 _GalleryItemProviderAdaptorImpl::HasGalleryItemProvider(void) const
46 {
47         return __pItemProvider != null ? true : false;
48 }
49
50 _GalleryItem*
51 _GalleryItemProviderAdaptorImpl::CreateItem(int index)
52 {
53         if (HasGalleryItemProvider() == false)
54         {
55                 return null;
56         }
57
58         GalleryItem* pPublicItem = __pItemProvider->CreateItem(index);
59         if (pPublicItem != null)
60         {
61                 _GalleryItemImpl* pImplItem = _GalleryItemImpl::GetInstance(*pPublicItem);
62                 SysTryReturn(NID_UI_CTRL, pImplItem != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Gallery item impl is null.");
63                 pImplItem->GetCore().SetAppInfo(pImplItem);
64                 return &pImplItem->GetCore();
65         }
66
67         SetLastResult(E_SUCCESS);
68         return null;
69 }
70
71 bool
72 _GalleryItemProviderAdaptorImpl::UnloadItem(int index, _GalleryItem* pItem)
73 {
74         if (HasGalleryItemProvider() == false)
75         {
76                 return true;
77         }
78
79         SysTryReturn(NID_UI_CTRL, pItem != null, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The pItem is null.");
80
81         _GalleryItemImpl* pImplItem = static_cast<_GalleryItemImpl*>(pItem->GetAppInfo());
82         GalleryItem* pPublicItem = static_cast<GalleryItem*>(&pImplItem->GetPublic());
83
84         SetLastResult(E_SUCCESS);
85         if (__pItemProvider->DeleteItem(index, pPublicItem) == false)
86         {
87                 delete pPublicItem;
88         }
89
90         return true;
91 }
92
93 bool
94 _GalleryItemProviderAdaptorImpl::DeleteItem(int index, _GalleryItem* pItem)
95 {
96         _GalleryItemImpl* pImplItem = static_cast<_GalleryItemImpl*>(pItem->GetAppInfo());
97         GalleryItem* pPublicItem = &pImplItem->GetPublic();
98         delete pPublicItem;
99
100         SetLastResult(E_SUCCESS);
101         return true;
102 }
103
104 int
105 _GalleryItemProviderAdaptorImpl::GetItemCount(void) const
106 {
107         if (HasGalleryItemProvider() == false)
108         {
109                 return 0;
110         }
111         return __pItemProvider->GetItemCount();
112 }
113
114 }}} // Tizen::Ui::Controls