Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / FUi_PublicOrientationEvent.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        FUi_PublicOrientationEvent.cpp
20  * @brief       This is the implementation for the _PublicOrientationEvent class.
21  * @version     1.0
22  */
23
24 #include <new>
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
27 #include "FUi_PublicOrientationEvent.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Runtime;
31
32 namespace Tizen { namespace Ui
33 {
34 /**
35  * @class       _PublicOrientationEventArg
36  * @brief       This class is used as the argument to orientation event listener.
37  *
38  * This class is used as the argument to orientation event listener. When an orientation event is generated
39  * (such as when a button is pressed) the OrientationEvent calls OrientationEventListener's OnOrientationPerformed
40  * with an instance of this class as an argument.
41  *
42  * From this class, one can find out, the (event) source object and the orientation ID.
43  */
44 class _PublicOrientationEventArg
45         : public Tizen::Base::Runtime::IEventArg
46         , public Tizen::Base::Object
47 {
48 public:
49         _PublicOrientationEventArg(const Control& source, OrientationStatus orientationStatus);
50
51         virtual ~_PublicOrientationEventArg(void);
52
53         const Control* GetSource(void) const;
54         int GetOrientationStatus(void) const;
55
56 private:
57         _PublicOrientationEventArg(const _PublicOrientationEventArg& rhs);
58         _PublicOrientationEventArg& operator =(const _PublicOrientationEventArg& rhs);
59
60 private:
61         Control* __pSource;
62         OrientationStatus __orientationStatus;
63 }; // _PublicOrientationEventArg
64
65 _PublicOrientationEventArg::_PublicOrientationEventArg(const Control& source, OrientationStatus orientationStatus)
66         : __pSource(const_cast <Control*>(&source))
67         , __orientationStatus(orientationStatus)
68 {
69 }
70
71 _PublicOrientationEventArg::~_PublicOrientationEventArg(void)
72 {
73 }
74
75 const Control*
76 _PublicOrientationEventArg::GetSource(void) const
77 {
78         return __pSource;
79 }
80
81 int
82 _PublicOrientationEventArg::GetOrientationStatus(void) const
83 {
84         return __orientationStatus;
85 }
86
87 _PublicOrientationEvent*
88 _PublicOrientationEvent::CreateInstanceN(const Control& source)
89 {
90         _PublicOrientationEvent* pPublicOrientationEvent = new (std::nothrow) _PublicOrientationEvent(source);
91         SysTryReturn(NID_UI, pPublicOrientationEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
92
93         result r = GetLastResult();
94         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
95
96         SetLastResult(E_SUCCESS);
97
98         return pPublicOrientationEvent;
99
100 CATCH:
101         delete pPublicOrientationEvent;
102         return null;
103 }
104
105 IEventArg*
106 _PublicOrientationEvent::CreateOrientationEventArgN(const Control& source, OrientationStatus orientationStatus)
107 {
108         _PublicOrientationEventArg* pEventArg = new (std::nothrow) _PublicOrientationEventArg(source, orientationStatus);
109         SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
110
111         SetLastResult(E_SUCCESS);
112
113         return pEventArg;
114 }
115
116 _PublicOrientationEvent::~_PublicOrientationEvent(void)
117 {
118 }
119
120 const Control*
121 _PublicOrientationEvent::GetSource(void) const
122 {
123         return __pSource;
124 }
125
126 void
127 _PublicOrientationEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
128 {
129         IOrientationEventListener* pEventListener = dynamic_cast <IOrientationEventListener*>(&listener);
130         SysTryReturnVoidResult(NID_UI, pEventListener, E_INVALID_ARG, "[E_INVALID_ARG] A specified input parameter is invalid.");
131
132         const _PublicOrientationEventArg* pArg = dynamic_cast <const _PublicOrientationEventArg*>(&arg);
133         SysTryReturnVoidResult(NID_UI, pArg, E_INVALID_ARG, "[E_INVALID_ARG] A specified input parameter is invalid.");
134
135         SysLog(NID_UI, "[WM ROTATION] Fire the public orientation event with %d -> 0x%x", pArg->GetOrientationStatus(), __pSource);
136
137         pEventListener->OnOrientationChanged(*__pSource, (OrientationStatus)(pArg->GetOrientationStatus()));
138
139         SetLastResult(E_SUCCESS);
140 }
141
142 _PublicOrientationEvent::_PublicOrientationEvent(const Control& source)
143         : __pSource(null)
144 {
145         result r = _Event::Initialize();
146         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
147
148         __pSource = &source;
149
150         SetLastResult(E_SUCCESS);
151 }
152
153 }} // Tizen::Ui