Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_SliderEvent.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_SliderEvent.cpp
19  * @brief               This is the implementation for the _SliderEvent class.
20  *
21  * This file contains the implementation of _SliderEvent class. @n
22  */
23
24 #include <new>
25 #include <FBaseSysLog.h>
26 #include <FBaseErrors.h>
27 #include "FUiCtrl_ISliderEventListener.h"
28 #include "FUiCtrl_SliderEvent.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Runtime;
32
33 namespace Tizen { namespace Ui { namespace Controls
34 {
35
36 class _OSP_EXPORT_ _SliderEventArg
37         : public IEventArg
38         , public Object
39 {
40 // Lifecycle
41 public:
42         _SliderEventArg(int value);
43         virtual ~_SliderEventArg(void);
44
45 // Access
46 public:
47         int GetValue(void) const;
48
49 // Attribute
50 private:
51         int __value;
52
53 }; // _SliderEventArg
54
55 _SliderEventArg::_SliderEventArg(int value)
56         : __value(value)
57 {
58 }
59
60 _SliderEventArg::~_SliderEventArg(void)
61 {
62 }
63
64 int
65 _SliderEventArg::GetValue(void) const
66 {
67         return __value;
68 }
69
70
71 _SliderEvent::_SliderEvent(const _Slider& source)
72         : __pSource(null)
73 {
74         result r = _Event::Initialize();
75
76         // set event source
77         if (r == E_SUCCESS)
78         {
79                 __pSource = const_cast <_Slider*>(&source);
80         }
81 }
82
83 _SliderEvent::~_SliderEvent(void)
84 {
85 }
86
87 _SliderEvent*
88 _SliderEvent::CreateInstanceN(const _Slider& source)
89 {
90         _SliderEvent* pSliderEvent = new (std::nothrow) _SliderEvent(source);
91         SysTryReturn(NID_UI_CTRL, pSliderEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
92
93         if (IsFailed(GetLastResult()))
94         {
95                 goto CATCH;
96         }
97
98         return pSliderEvent;
99
100 CATCH:
101         delete pSliderEvent;
102         pSliderEvent = null;
103
104         return null;
105 }
106
107 const _Slider*
108 _SliderEvent::GetSource(void) const
109 {
110         return __pSource;
111 }
112
113 void
114 _SliderEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
115 {
116         // cast to ISliderEventListener
117         _ISliderEventListener* pSliderListener = dynamic_cast <_ISliderEventListener*>(&listener);
118         SysTryReturnVoidResult(NID_UI_CTRL, pSliderListener != null, E_INVALID_ARG,
119                                 "[E_INVALID_ARG] Invalid argument(s) is used. The _ISliderEventListener is null");
120
121         // cast to _SliderEventArg
122         const _SliderEventArg* pSliderEventArg = dynamic_cast <const _SliderEventArg*>(&arg);
123         SysTryReturnVoidResult(NID_UI_CTRL, pSliderEventArg != null, E_INVALID_ARG,
124                                 "[E_INVALID_ARG] Invalid argument(s) is used. The _SliderEventArg is null");
125
126         // call cursor change event listener method
127         pSliderListener->OnSliderBarMoved(*__pSource, pSliderEventArg->GetValue());
128         SetLastResult(E_SUCCESS);
129         return ;
130 }
131
132 IEventArg*
133 _SliderEvent::CreateSliderEventArgN(int value)
134 {
135         _SliderEventArg* pEventArg = new (std::nothrow) _SliderEventArg(value);
136         SysTryReturn(NID_UI_CTRL, pEventArg != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
137
138         return pEventArg;
139 }
140
141 }}} // Tizen::Ui::Controls