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