Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_GalleryItem.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 #include <FBaseSysLog.h>
18 #include "FUiCtrl_GalleryItem.h"
19 #include "FUiCtrl_GalleryBitmap.h"
20
21 using namespace Tizen::Base;
22 using namespace Tizen::Graphics;
23
24 namespace Tizen { namespace Ui { namespace Controls {
25
26 _GalleryItem::_GalleryItem(_GalleryBitmap* pImage, String imageFilePath, _GalleryImageRotation rotation)
27         : __pOriginImage(pImage)
28         , __pImage(null)
29         , __imageFilePath(imageFilePath)
30         , __rotation(rotation)
31         , __itemIndex(-1)
32 {
33         // Do nothing
34 }
35
36 _GalleryItem::~_GalleryItem(void)
37 {
38
39         delete __pOriginImage;
40         __pOriginImage = null;
41
42         delete __pImage;
43         __pImage = null;
44 }
45
46 void
47 _GalleryItem::SetGalleryItemImage(_GalleryBitmap* pImage)
48 {
49         delete __pImage;
50         __pImage = pImage;
51 }
52
53 _GalleryBitmap*
54 _GalleryItem::GetGalleryItemImage(void) const
55 {
56         if (__pOriginImage == null)
57         {
58                 SetLastResult(E_SYSTEM);
59                 return null;
60         }
61
62         Dimension dim = __pOriginImage->GetSize();
63         Rectangle rect(0, 0, dim.width, dim.height);
64
65         result r = E_SUCCESS;
66         _GalleryBitmap* pImage = null;
67
68         Bitmap* pBitmap = new(std::nothrow) Bitmap();
69         SysTryCatch(NID_UI_CTRL, pBitmap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
70
71         r = pBitmap->Construct(*__pOriginImage->GetInternalBitmap(), rect);
72         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
73
74         pImage = _GalleryBitmap::CreateGalleryBitmapN(pBitmap);
75         SysTryCatch(NID_UI_CTRL, pImage != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
76         pImage->SetBitmapRotation(__pOriginImage->GetBitmapRotation());
77         const_cast<_GalleryItem*>(this)->SetGalleryItemImage(pImage);
78
79         delete pBitmap;
80         return pImage;
81
82 CATCH:
83         delete pBitmap;
84         const_cast<_GalleryItem*>(this)->SetGalleryItemImage(null);
85         return null;
86 }
87
88 void
89 _GalleryItem::SetOriginGalleryItemImage(_GalleryBitmap* pImage)
90 {
91         delete __pOriginImage;
92         __pOriginImage = pImage;
93 }
94
95 _GalleryBitmap*
96 _GalleryItem::GetOriginItemImage(void) const
97 {
98         return __pOriginImage;
99 }
100
101 void
102 _GalleryItem::SetGalleryItemFilePath(String& filePath)
103 {
104         __imageFilePath = filePath;
105 }
106
107 String
108 _GalleryItem::GetGalleryItemFilePath(void) const
109 {
110         return __imageFilePath;
111 }
112
113 void
114 _GalleryItem::SetGalleryRotation(_GalleryImageRotation rotation)
115 {
116         __rotation = rotation;
117 }
118
119 _GalleryImageRotation
120 _GalleryItem::GetGalleryRotation(void) const
121 {
122         return __rotation;
123 }
124
125 void
126 _GalleryItem::SetItemIndex(int groupIndex, int itemIndex)
127 {
128         __itemIndex = itemIndex;
129 }
130
131 void
132 _GalleryItem::GetItemIndex(int& groupIndex, int& itemIndex) const
133 {
134         groupIndex = 0;
135         itemIndex = __itemIndex;
136 }
137
138 }}} // Tizen::Ui::Controls