Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_UiScrollEvent.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 /**
19 * @file         FUiCtrl_UiScrollEvent.cpp
20 * @brief        This is the implementation for the _UiScrollEvent class.
21 */
22
23 #include <FBaseErrors.h>
24 #include <FBaseSysLog.h>
25 #include "FUiCtrl_UiScrollEvent.h"
26 #include "FUiCtrl_UiScrollEventArg.h"
27 #include "FUiCtrl_IScrollEventListener.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Runtime;
31
32 namespace Tizen { namespace Ui { namespace Controls
33 {
34
35 ////////////////////////////////////////////////////////////////////////////////
36 /// _UiScrollEvent class Lifecycle
37
38 _UiScrollEvent::_UiScrollEvent(void)
39         : __pSource(null)
40 {
41         // nothing
42 }
43
44 _UiScrollEvent::~_UiScrollEvent(void)
45 {
46         // nothing
47 }
48
49 result
50 _UiScrollEvent::Construct(const Tizen::Ui::_Control& source)
51 {
52         ClearLastResult();
53         result r = _Event::Initialize();
54         SysTryReturn(NID_UI, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
55
56         // set event source
57         __pSource = const_cast <_Control*>(&source);
58
59         return r;
60 }
61
62 ////////////////////////////////////////////////////////////////////////////////
63 /// __WindowEvent class Accessor
64
65 Tizen::Ui::_Control*
66 _UiScrollEvent::GetSource(void) const
67 {
68         ClearLastResult();
69         return __pSource;
70 }
71
72 ////////////////////////////////////////////////////////////////////////////////
73 /// _UiScrollEvent class Operation
74
75 void
76 _UiScrollEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
77 {
78         _IScrollEventListener* pScrollEventListener = dynamic_cast <_IScrollEventListener*>(&listener);
79         SysTryReturnVoidResult(NID_UI_CTRL, (pScrollEventListener != null), E_INVALID_ARG, "The invalid listener was given.");
80
81         // cast Argument
82         const _UiScrollEventArg* pArg = dynamic_cast <const _UiScrollEventArg*>(&arg);
83         SysTryReturnVoidResult(NID_UI_CTRL, (pArg != null), E_INVALID_ARG, "The invalid Event Argument was given.");
84
85         switch (pArg->GetEventType())
86         {
87         case SCROLL_EVENT_ON_SCROLL_STOPPED:
88                 pScrollEventListener->OnScrollStopped(*pArg->GetSource());
89                 break;
90         case SCROLL_EVENT_ON_SCROLL_POSITION_CHANGED:
91                 pScrollEventListener->OnScrollPositionChanged(*pArg->GetSource(), pArg->GetScrollPosition());
92                 break;
93         case SCROLL_EVENT_ON_SCROLL_END_REACHED:
94                 pScrollEventListener->OnScrollEndReached(*pArg->GetSource(), pArg->GetScrollType());
95                 break;
96         default:
97                 SysTryReturnVoidResult(NID_UI_CTRL, false, E_INVALID_ARG, "The invalid Event Argument was given.");
98                 break;
99         }
100 }
101
102 }}}     // Tizen::Ui::Controls