Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_EditCopyPasteEvent.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_EditCopyPasteEvent.cpp
20  * @brief               This is the implementation file for the _EditCopyPasteEvent class.
21  */
22
23
24 // Includes
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
27 #include <new>
28 #include "FUiCtrl_EditCopyPasteEvent.h"
29
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Runtime;
33
34 namespace Tizen {namespace Ui {namespace Controls
35 {
36 /**
37  * @class
38  * @brief       This class is used as the argument to change event listener.
39  *
40  * This class is used as the argument to change event listener. When an change event is generated
41  * (such as when a button is pressed) the TextSelectionEvent calls TextSelectionEventListener's OnTextd
42  * with an instance of this class as an argument.
43  *
44  * From this class, one can find out, the (event) source object and the change ID.
45  */
46 class _OSP_EXPORT_ _EditCopyPasteEventArg
47         : public IEventArg
48         , public Object
49 {
50 // Lifecycle
51 public:
52         /**
53          * This is the default class constructor.
54          *
55          * @param[in]   source          A pointer to the Object instance which contains this instance.
56          */
57         _EditCopyPasteEventArg(CoreCopyPasteStatus status, CoreCopyPasteAction action);
58
59         /**
60          * This is the class destructor.
61          *
62          */
63         virtual ~_EditCopyPasteEventArg(void);
64
65 // Access
66         CoreCopyPasteStatus GetStatus(void) const;
67         CoreCopyPasteAction GetAction(void) const;
68
69
70 // Attribute
71 private:
72         CoreCopyPasteStatus __status;
73         CoreCopyPasteAction __action;
74 }; // _EditCopyPasteEventArg
75
76 _EditCopyPasteEventArg::_EditCopyPasteEventArg(CoreCopyPasteStatus status, CoreCopyPasteAction action)
77         : __status(status)
78         , __action(action)
79 {
80         // Nothing.
81 }
82
83 _EditCopyPasteEventArg::~_EditCopyPasteEventArg(void)
84 {
85         // Nothing.
86 }
87
88 CoreCopyPasteStatus
89 _EditCopyPasteEventArg::GetStatus(void) const
90 {
91         return __status;
92 }
93
94 CoreCopyPasteAction
95 _EditCopyPasteEventArg::GetAction(void) const
96 {
97         return __action;
98 }
99
100 ////////////////////////////////////////////////////////////////////////////////
101 /// _EditCopyPasteEvent class Lifecycle
102 _EditCopyPasteEvent::_EditCopyPasteEvent(const _EditCopyPasteManager& source)
103         : __pSource(null)
104 {
105         result r = _Event::Initialize();
106
107         // Set event source
108         if (r == E_SUCCESS)
109         {
110                 __pSource = &source;
111         }
112 }
113
114 _EditCopyPasteEvent::~_EditCopyPasteEvent(void)
115 {
116         // Nothing.
117 }
118
119 _EditCopyPasteEvent*
120 _EditCopyPasteEvent::CreateInstanceN(const _EditCopyPasteManager& source)
121 {
122         _EditCopyPasteEvent* pCoreCopyPasteEvent = new (std::nothrow) _EditCopyPasteEvent(source);
123         SysTryReturn(NID_UI_CTRL, pCoreCopyPasteEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
124
125         if (IsFailed(GetLastResult()))
126         {
127                 goto CATCH;
128         }
129
130         return pCoreCopyPasteEvent;
131
132 CATCH:
133         delete pCoreCopyPasteEvent;
134         return null;
135 }
136
137 const _EditCopyPasteManager*
138 _EditCopyPasteEvent::GetSource(void) const
139 {
140         return __pSource;
141 }
142
143 void
144 _EditCopyPasteEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
145 {
146         _IEditCopyPasteEventListener* pCopyPasteEventListener = dynamic_cast <_IEditCopyPasteEventListener*>(&listener);
147         SysTryReturnVoidResult(NID_UI_CTRL, pCopyPasteEventListener != null, E_INVALID_ARG, "The Invalid listener is given.\n");
148
149         _EditCopyPasteEventArg* pCopyPasteEventArg = dynamic_cast <_EditCopyPasteEventArg*>(const_cast<IEventArg*>(&arg));
150         SysTryReturnVoidResult(NID_UI_CTRL, pCopyPasteEventArg != null, E_INVALID_ARG, "The Invalid Event Argument is given.\n");
151
152         CoreCopyPasteStatus status = pCopyPasteEventArg->GetStatus();
153         CoreCopyPasteAction action = pCopyPasteEventArg->GetAction();
154
155         pCopyPasteEventListener->OnEditCopyPasteStatusChanged(status, action);
156
157         SetLastResult(E_SUCCESS);
158
159         return;
160 }
161
162 IEventArg*
163 _EditCopyPasteEvent::CreateCopyPasteEventArgN(CoreCopyPasteStatus status, CoreCopyPasteAction action)
164 {
165         _EditCopyPasteEventArg* pEventArg = new (std::nothrow) _EditCopyPasteEventArg(status, action);
166         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
167
168         return pEventArg;
169 }
170
171 }}} // Tizen::Ui::Controls