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