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