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