add patch
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_PublicSplitPanelEvent.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_PublicSplitPanelEvent.cpp
20 * @brief        This is the implementation for the _PublicSplitPanelEvent class.
21 * @version      1.0
22 */
23
24 // includes
25 #include <new>
26 #include <FBaseErrors.h>
27 #include <FBaseRtIEventListener.h>
28 #include <FUiCtrlSplitPanel.h>
29 #include <FBaseSysLog.h>
30 #include "FUiCtrl_PublicSplitPanelEvent.h"
31 #include "FUiCtrl_SplitPanelImpl.h"
32
33
34 // using namespace
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Runtime;
37
38 namespace Tizen { namespace Ui { namespace Controls
39 {
40
41 /**
42  * @class       _PublicSplitPanelEventArg
43  * @brief       This class is used as the argument to change event listener.
44  *
45  * This class is used as the argument to change event listener. When an change event is generated
46  * (such as when a button is pressed) the SplitPanelEvent calls SplitPanelEventListener's OnTextd
47  * with an instance of this class as an argument.
48  *
49  * From this class, one can find out, the (event) source object and the change ID.
50  */
51 class _OSP_EXPORT_ _PublicSplitPanelEventArg
52         : public Tizen::Base::Runtime::IEventArg
53         , public Tizen::Base::Object
54 {
55 // Lifecycle
56 public:
57         /**
58          * This is the default class constructor.
59          *
60          * @param[in]   status
61          */
62         _PublicSplitPanelEventArg(SplitPanelEventStatus status);
63
64         /**
65          * This is the class destructor.
66          *
67          */
68         virtual ~_PublicSplitPanelEventArg(void);
69
70
71 // Access
72 public:
73         SplitPanelEventStatus GetStatus(void) const;
74
75 // Attribute
76 private:
77         /**
78          * Status
79          */
80         SplitPanelEventStatus __status;
81 }; // _PublicSplitPanelEventArg
82
83 ////////////////////////////////////////////////////////////////////////////////
84 /// _PublicSplitPanelEventArg class Lifecycle
85
86 _PublicSplitPanelEventArg::_PublicSplitPanelEventArg(SplitPanelEventStatus status)
87         : __status(status)
88 {
89         // Nothing
90 }
91
92 _PublicSplitPanelEventArg::~_PublicSplitPanelEventArg(void)
93 {
94         // Nothing.
95 }
96
97 SplitPanelEventStatus
98 _PublicSplitPanelEventArg::GetStatus(void) const
99 {
100         return __status;
101 }
102
103 ////////////////////////////////////////////////////////////////////////////////
104 /// _PublicSplitPanelEvent class Lifecycle
105 _PublicSplitPanelEvent::_PublicSplitPanelEvent(const SplitPanel& source)
106         : __pSource(null)
107 {
108         //result r = Event::Construct();
109         result r = _Event::Initialize();
110
111         // Set event source
112         if (r == E_SUCCESS)
113         {
114                 __pSource = &source;
115         }
116 }
117
118 _PublicSplitPanelEvent::~_PublicSplitPanelEvent(void)
119 {
120         // Nothing.
121 }
122
123 _PublicSplitPanelEvent*
124 _PublicSplitPanelEvent::CreateInstanceN(const SplitPanel& source)
125 {
126         _PublicSplitPanelEvent* pPublicSplitPanelEvent = new (std::nothrow) _PublicSplitPanelEvent(source);
127         SysTryReturn(NID_UI_CTRL, pPublicSplitPanelEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
128
129         return pPublicSplitPanelEvent;
130 }
131
132 // Accessors
133
134 const SplitPanel*
135 _PublicSplitPanelEvent::GetSource(void) const
136 {
137         return __pSource;
138 }
139
140 // Operations
141
142 void
143 _PublicSplitPanelEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
144 {
145         // cast to IActionEventListener
146         ISplitPanelEventListener* pSplitPanelEventListener = dynamic_cast <ISplitPanelEventListener*>(&listener);
147         ISplitPanelEventListenerF* pSplitPanelEventListenerF = dynamic_cast <ISplitPanelEventListenerF*>(&listener);
148         SysTryReturnVoidResult(NID_UI_CTRL, pSplitPanelEventListener != null || pSplitPanelEventListenerF != null, E_INVALID_ARG, "[E_INVALID_ARG] The invalid listener was given.");
149
150         // cast to _PublicSplitPanelEventArg
151         const _PublicSplitPanelEventArg* pArg = dynamic_cast <const _PublicSplitPanelEventArg*>(&arg);
152         SysTryReturnVoidResult(NID_UI_CTRL, pArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The invalid Event Argument was given.");
153
154         SplitPanel* pSource = null;
155         pSource = const_cast <SplitPanel*>(__pSource);
156
157         // call cursor change event listener method
158         SplitPanelEventStatus status = pArg->GetStatus();
159         if (status == SPLIT_PANEL_EVENT_DIVIDER_POSITION_CHANGE)
160         {
161                 if (pSplitPanelEventListener != null)
162                 {
163                         pSplitPanelEventListener->OnDividerPositionChanged(*pSource, pSource->GetDividerPosition());
164                 }
165
166                 if (pSplitPanelEventListenerF != null)
167                 {
168                         pSplitPanelEventListenerF->OnDividerPositionChanged(*pSource, pSource->GetDividerPositionF());
169                 }
170         }
171         else
172         {
173                 if (pSplitPanelEventListener != null)
174                 {
175                         pSplitPanelEventListener->OnDividerDoublePressed(*pSource);
176                 }
177
178                 if (pSplitPanelEventListenerF != null)
179                 {
180                         pSplitPanelEventListenerF->OnDividerDoublePressed(*pSource);
181                 }
182         }
183 }
184
185 IEventArg*
186 _PublicSplitPanelEvent::CreateSplitPanelEventArgN(SplitPanelEventStatus status)
187 {
188         _PublicSplitPanelEventArg* pEventArg = new (std::nothrow) _PublicSplitPanelEventArg(status);
189         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
190
191         return pEventArg;
192 }
193
194 }}} // Tizen::Ui::Controls