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