add patch
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_ColorChangeEvent.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         FUiCtrl_ColorChangeEvent.cpp
20 * @brief        This is the implementation for the _ColorChangeEvent class.
21 */
22
23 #include <new>
24 #include <FBaseSysLog.h>
25 #include <FBaseErrors.h>
26 #include <FGrpColor.h>
27 #include "FUiCtrl_ColorChangeEvent.h"
28 #include "FUiCtrl_IColorChangeEventListener.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Runtime;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Ui;
34
35 namespace Tizen { namespace Ui { namespace Controls
36 {
37
38 class _OSP_EXPORT_ _ColorChangeEventArg
39         : public IEventArg
40         , public Object
41 {
42 public:
43         _ColorChangeEventArg(const Color& color)
44                 : __color(color)
45         {
46         }
47
48         virtual ~_ColorChangeEventArg(void)
49         {
50         }
51
52         const Color
53         GetColor(void) const
54         {
55                 return __color;
56         }
57
58 private:
59         _ColorChangeEventArg(const _ColorChangeEventArg&);
60
61         _ColorChangeEventArg& operator=(const _ColorChangeEventArg&);
62
63 private:
64         Color __color;
65 }; // _ColorChangeEventArg
66
67 _ColorChangeEvent::_ColorChangeEvent(const _Control& source)
68         : __pSource(null)
69 {
70         result r = _Event::Initialize();
71
72         // set event source
73         if (r == E_SUCCESS)
74         {
75                 __pSource = &source;
76         }
77 }
78
79 _ColorChangeEvent::~_ColorChangeEvent(void)
80 {
81 }
82
83 const _Control*
84 _ColorChangeEvent::GetSource(void) const
85 {
86         return (__pSource);
87 }
88
89 void
90 _ColorChangeEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
91 {
92         _IColorChangeEventListener* pColorChangeListener = dynamic_cast <_IColorChangeEventListener*>(&listener);
93         SysTryReturnVoidResult(NID_UI_CTRL, (pColorChangeListener != null), E_INVALID_ARG,
94                                 "[E_INVALID_ARG] Invalid argument(s) is used. The _IColorChangeEventListener instance is null.");
95
96         const _ColorChangeEventArg* pArg = dynamic_cast <const _ColorChangeEventArg*>(&arg);
97         SysTryReturnVoidResult(NID_UI_CTRL, (pArg != null), E_INVALID_ARG,
98                                 "[E_INVALID_ARG] Invalid argument(s) is used. The _ColorChangeEventArg instance is null.");
99
100         pColorChangeListener->OnColorChanged(*__pSource, Color(pArg->GetColor()));
101
102         return;
103 }
104
105 _ColorChangeEvent*
106 _ColorChangeEvent::CreateInstanceN(const _Control& source)
107 {
108         _ColorChangeEvent* pColorChangeEvent = new (std::nothrow) _ColorChangeEvent(source);
109         SysTryReturn(NID_UI_CTRL, (pColorChangeEvent != null), null, E_OUT_OF_MEMORY,
110                                 "[E_OUT_OF_MEMORY] Memory allocation failed.");
111
112         if (IsFailed(GetLastResult()))
113         {
114                 delete pColorChangeEvent;
115                 return null;
116         }
117
118         return pColorChangeEvent;
119 }
120
121 IEventArg*
122 _ColorChangeEvent::CreateColorChangeEventArgN(const Color& color)
123 {
124         _ColorChangeEventArg* pEventArg = new (std::nothrow) _ColorChangeEventArg(color);
125         SysTryReturn(NID_UI_CTRL, (pEventArg != null), null, E_OUT_OF_MEMORY,
126                                 "[E_OUT_OF_MEMORY] Memory allocation failed.");
127
128         return pEventArg;
129 }
130
131 }}} // Tizen::Ui::Controls