modify license, permission and remove ^M char
[platform/framework/native/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 Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an ”AS IS” BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUi_ClipboardItem.cpp
20  * @brief               This is the implementation file for the _ClipboardItem class.
21  */
22
23 #include <new>
24 #include <FBaseString.h>
25 #include <FGrpBitmap.h>
26 #include <FBaseResult.h>
27 #include <FBaseSysLog.h>
28 #include "FUi_ClipboardItem.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
32
33 namespace Tizen { namespace Ui
34 {
35 _ClipboardItem*
36 _ClipboardItem::CreateInstanceN(ClipboardDataType type, const Object& data)
37 {
38         _ClipboardItem* pItem = new (std::nothrow) _ClipboardItem(type, data);
39         SysTryReturn(NID_UI, pItem, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
40
41         result r = GetLastResult();
42         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
43
44         SetLastResult(E_SUCCESS);
45
46         return pItem;
47
48 CATCH:
49         delete pItem;
50         return null;
51 }
52
53 _ClipboardItem::~_ClipboardItem(void)
54 {
55         if (__pString)
56         {
57                 delete __pString;
58                 __pString = null;
59         }
60
61         if (__pBitmap)
62         {
63                 delete __pBitmap;
64                 __pBitmap = null;
65         }
66 }
67
68 ClipboardDataType
69 _ClipboardItem::GetDataType(void) const
70 {
71         return __type;
72 }
73
74 const Object*
75 _ClipboardItem::GetData(void) const
76 {
77         if (__type == CLIPBOARD_DATA_TYPE_IMAGE)
78         {
79                 return __pBitmap;
80         }
81         else
82         {
83                 return __pString;
84         }
85 }
86
87 _ClipboardItem::_ClipboardItem(ClipboardDataType type, const Object& data)
88         : __type(type)
89         , __pString(null)
90         , __pBitmap(null)
91 {
92         SysTryReturnVoidResult(NID_UI,
93                                         (CLIPBOARD_DATA_TYPE_TEXT & type) ||
94                                         (CLIPBOARD_DATA_TYPE_HTML & type) ||
95                                         (CLIPBOARD_DATA_TYPE_IMAGE & type) ||
96                                         (CLIPBOARD_DATA_TYPE_VIDEO & type) ||
97                                         (CLIPBOARD_DATA_TYPE_AUDIO & type)
98                                    , E_INVALID_ARG, "[E_INVALID_ARG] The data type is invalid.");
99
100         if (type == CLIPBOARD_DATA_TYPE_IMAGE)
101         {
102                 const Bitmap* pBitmap = dynamic_cast<const Bitmap*>(&data);
103                 SysTryReturnVoidResult(NID_UI, pBitmap, E_INVALID_ARG, "[E_INVALID_ARG] The data is invalid.");
104
105                 __pBitmap = new (std::nothrow) Bitmap;
106                 SysTryReturnVoidResult(NID_UI, __pBitmap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
107
108                 result r = __pBitmap->Construct(*pBitmap, Rectangle(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()));
109                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
110         }
111         else
112         {
113                 const String* pString = dynamic_cast<const String*>(&data);
114                 SysTryReturnVoidResult(NID_UI, pString, E_INVALID_ARG, "[E_INVALID_ARG] The data is invalid.");
115
116                 __pString = new (std::nothrow) String(*pString);
117                 SysTryReturnVoidResult(NID_UI, __pString, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
118         }
119
120         SetLastResult(E_SUCCESS);
121
122         return;
123
124 CATCH:
125         delete __pBitmap;
126         __pBitmap = null;
127 }
128
129 }} // Tizen::Ui