Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / FUi_ClipboardItem.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  * @file                FUi_ClipboardItem.cpp
19  * @brief               This is the implementation file for the _ClipboardItem class.
20  */
21 #include <new>
22 #include <FBaseString.h>
23 #include <FGrpBitmap.h>
24 #include <FBaseResult.h>
25 #include <FBaseSysLog.h>
26 #include "FUi_ClipboardItem.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
30
31 namespace Tizen { namespace Ui
32 {
33 _ClipboardItem*
34 _ClipboardItem::CreateInstanceN(ClipboardDataType type, const Object& data)
35 {
36         _ClipboardItem* pItem = new (std::nothrow) _ClipboardItem(type, data);
37         SysTryReturn(NID_UI, pItem, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
38
39         result r = GetLastResult();
40         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
41
42         SetLastResult(E_SUCCESS);
43
44         return pItem;
45
46 CATCH:
47         delete pItem;
48         return null;
49 }
50
51 _ClipboardItem::~_ClipboardItem(void)
52 {
53         if (__pString)
54         {
55                 delete __pString;
56                 __pString = null;
57         }
58
59         if (__pBitmap)
60         {
61                 delete __pBitmap;
62                 __pBitmap = null;
63         }
64 }
65
66 ClipboardDataType
67 _ClipboardItem::GetDataType(void) const
68 {
69         return __type;
70 }
71
72 const Object*
73 _ClipboardItem::GetData(void) const
74 {
75         if (__type == CLIPBOARD_DATA_TYPE_IMAGE)
76         {
77                 return __pBitmap;
78         }
79         else
80         {
81                 return __pString;
82         }
83 }
84
85 _ClipboardItem::_ClipboardItem(ClipboardDataType type, const Object& data)
86         : __type(type)
87         , __pString(null)
88         , __pBitmap(null)
89 {
90         SysTryReturnVoidResult(NID_UI,
91                                         (CLIPBOARD_DATA_TYPE_TEXT & type) ||
92                                         (CLIPBOARD_DATA_TYPE_HTML & type) ||
93                                         (CLIPBOARD_DATA_TYPE_IMAGE & type) ||
94                                         (CLIPBOARD_DATA_TYPE_VIDEO & type) ||
95                                         (CLIPBOARD_DATA_TYPE_AUDIO & type)
96                                    , E_INVALID_ARG, "[E_INVALID_ARG] The data type is invalid.");
97
98         if (type == CLIPBOARD_DATA_TYPE_IMAGE)
99         {
100                 const Bitmap* pBitmap = dynamic_cast<const Bitmap*>(&data);
101                 SysTryReturnVoidResult(NID_UI, pBitmap, E_INVALID_ARG, "[E_INVALID_ARG] The data is invalid.");
102
103                 __pBitmap = new (std::nothrow) Bitmap;
104                 SysTryReturnVoidResult(NID_UI, __pBitmap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
105
106                 result r = __pBitmap->Construct(*pBitmap, Rectangle(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()));
107                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
108         }
109         else
110         {
111                 const String* pString = dynamic_cast<const String*>(&data);
112                 SysTryReturnVoidResult(NID_UI, pString, E_INVALID_ARG, "[E_INVALID_ARG] The data is invalid.");
113
114                 __pString = new (std::nothrow) String(*pString);
115                 SysTryReturnVoidResult(NID_UI, __pString, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
116         }
117
118         SetLastResult(E_SUCCESS);
119
120         return;
121
122 CATCH:
123         delete __pBitmap;
124         __pBitmap = null;
125 }
126
127 }} // Tizen::Ui