Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_FrameEvent.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  * @file                FUiCtrl_FrameEvent.cpp
19  * @brief       This is the implementation for the _FrameEvent class.
20  * @version     1.0
21  */
22
23 #include <new>
24 #include <FUiCtrlFrame.h>
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
27 #include "FUiCtrl_IFrameEventListener.h"
28 #include "FUiCtrl_FrameEvent.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Runtime;
32
33 namespace Tizen { namespace Ui { namespace Controls
34 {
35 /**
36  * @class       _FrameEventArg
37  * @brief       This class is used as an argument of event listener's method.
38  *
39  * This class is used as an argument of event listener's method. When frame event is generated,
40  * the @c _FrameEvent instance calls WindowEventListener's method with instance of this class as an argument.
41  */
42 class _FrameEventArg
43         : public Tizen::Base::Object
44         , public Tizen::Base::Runtime::IEventArg
45 {
46 public:
47 // Lifecycle
48         /**
49          * This is the default class constructor.
50          *
51          * @param[in]   source                  A pointer to the _Frame instance which contains this instance.
52          * @param[in]   frameState          The frame event type.
53          */
54         _FrameEventArg(const _Frame& source, int frameState);
55
56         /**
57          * This is the class destructor.
58          *
59          */
60         virtual ~_FrameEventArg(void);
61
62 // Accessor
63         /**
64          * This method returns the Window object which the event initially occurred.
65          *
66          * @return      See the comment above.
67          *
68          */
69         const _Frame* GetSource(void) const;
70
71         /**
72          * This method returns the event type of frame event.
73          *
74          * @return      See the comment above.
75          */
76         int GetType(void) const;
77
78 private:
79 // Attribute
80         _Frame* __pSource;
81         int __frameState;
82 }; // _FrameEventArg
83
84 _FrameEventArg::_FrameEventArg(const _Frame& source, int frameState)
85         : __pSource(const_cast <_Frame*>(&source))
86         , __frameState(frameState)
87 {
88 }
89
90 _FrameEventArg::~_FrameEventArg(void)
91 {
92 }
93
94 const _Frame*
95 _FrameEventArg::GetSource(void) const
96 {
97         return __pSource;
98 }
99
100 int
101 _FrameEventArg::GetType(void) const
102 {
103         return __frameState;
104 }
105
106 _FrameEvent*
107 _FrameEvent::CreateInstanceN(const _Frame& source)
108 {
109         _FrameEvent* pFrameEvent = new (std::nothrow) _FrameEvent(source);
110         SysTryReturn(NID_UI_CTRL, pFrameEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
111
112         if (IsFailed(GetLastResult()))
113         {
114                 goto CATCH;
115         }
116
117         SetLastResult(E_SUCCESS);
118
119         return pFrameEvent;
120
121 CATCH:
122         delete pFrameEvent;
123         return null;
124 }
125
126 IEventArg*
127 _FrameEvent::CreateFrameEventArgN(const _Frame& source, int frameState)
128 {
129         _FrameEventArg* pEventArg = new (std::nothrow) _FrameEventArg(source, frameState);
130         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
131
132         SetLastResult(E_SUCCESS);
133
134         return pEventArg;
135 }
136
137 _FrameEvent::~_FrameEvent(void)
138 {
139 }
140
141 const _Frame*
142 _FrameEvent::GetSource(void) const
143 {
144         return __pSource;
145 }
146
147 void
148 _FrameEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
149 {
150         _IFrameEventListener* pFrameListener = dynamic_cast <_IFrameEventListener*>(&listener);
151         SysTryReturnVoidResult(NID_UI_CTRL, pFrameListener, E_INVALID_ARG, "[E_INVALID_ARG] The invalid listener was given.");
152
153         const _FrameEventArg* pArg = static_cast <const _FrameEventArg*>(&arg);
154         SysTryReturnVoidResult(NID_UI_CTRL, pArg, E_INVALID_ARG, "[E_INVALID_ARG] The invalid event argument was given.");
155
156         if (pArg->GetType() == _FRAME_STATUS_ACTIVATED)
157         {
158                 pFrameListener->OnFrameActivated(*pArg->GetSource());
159         }
160         else if (pArg->GetType() == _FRAME_STATUS_DEACTIVATED)
161         {
162                 pFrameListener->OnFrameDeactivated(*pArg->GetSource());
163         }
164         else if (pArg->GetType() == _FRAME_STATUS_MINIMIZED)
165         {
166                 pFrameListener->OnFrameMinimized(*pArg->GetSource());
167         }
168         else if (pArg->GetType() == _FRAME_STATUS_RESTORED)
169         {
170                 pFrameListener->OnFrameRestored(*pArg->GetSource());
171         }
172
173         return;
174 }
175
176 _FrameEvent::_FrameEvent(const _Frame& source)
177         : __pSource(null)
178 {
179         result r = _Event::Initialize();
180         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
181
182         __pSource = &source;
183
184         ClearLastResult();
185 }
186
187 }}} // Tizen::Ui::Controls