Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_PublicFrameEvent.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_PublicFrameEvent.cpp
19  * @brief       This is the implementation for the _PublicFrameEvent class.
20  * @version     1.0
21  */
22
23 #include <new>
24 #include <FUiCtrlFrame.h>
25 #include <FUiCtrlIFrameEventListener.h>
26 #include <FBaseErrors.h>
27 #include <FBaseSysLog.h>
28 #include "FUiCtrl_PublicFrameEvent.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       _PublicFrameEventArg
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 _PublicFrameEvent instance calls WindowEventListener's method with instance of this class as an argument.
41  */
42 class _PublicFrameEventArg
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         _PublicFrameEventArg(const Frame& source, int frameState);
55
56         /**
57          * This is the class destructor.
58          *
59          */
60         virtual ~_PublicFrameEventArg(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 }; // _PublicFrameEventArg
83
84 _PublicFrameEventArg::_PublicFrameEventArg(const Frame& source, int frameState)
85         : __pSource(const_cast <Frame*>(&source))
86         , __frameState(frameState)
87 {
88 }
89
90 _PublicFrameEventArg::~_PublicFrameEventArg(void)
91 {
92 }
93
94 const Frame*
95 _PublicFrameEventArg::GetSource(void) const
96 {
97         return __pSource;
98 }
99
100 int
101 _PublicFrameEventArg::GetType(void) const
102 {
103         return __frameState;
104 }
105
106 _PublicFrameEvent*
107 _PublicFrameEvent::CreateInstanceN(const Frame& source)
108 {
109         _PublicFrameEvent* pPublicFrameEvent = new (std::nothrow) _PublicFrameEvent(source);
110         SysTryReturn(NID_UI_CTRL, pPublicFrameEvent, 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 pPublicFrameEvent;
120
121 CATCH:
122         delete pPublicFrameEvent;
123         return null;
124 }
125
126 IEventArg*
127 _PublicFrameEvent::CreateFrameEventArgN(const Frame& source, int frameState)
128 {
129         _PublicFrameEventArg* pEventArg = new (std::nothrow) _PublicFrameEventArg(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 _PublicFrameEvent::~_PublicFrameEvent(void)
138 {
139 }
140
141 const Frame*
142 _PublicFrameEvent::GetSource(void) const
143 {
144         return __pSource;
145 }
146
147 void
148 _PublicFrameEvent::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 _PublicFrameEventArg* pArg = static_cast <const _PublicFrameEventArg*>(&arg);
154         SysTryReturnVoidResult(NID_UI_CTRL, pArg, E_INVALID_ARG, "[E_INVALID_ARG] The invalid event argument was given.");
155
156         int type = pArg->GetType();
157         switch (type)
158         {
159         case FRAME_STATE_TERMINATING :
160                 pFrameListener->OnFrameTerminating(*pArg->GetSource());
161                 break;
162         case FRAME_STATE_ACTIVATED :
163                 pFrameListener->OnFrameActivated(*pArg->GetSource());
164                 break;
165         case FRAME_STATE_DEACTIVATED :
166                 pFrameListener->OnFrameDeactivated(*pArg->GetSource());
167                 break;
168         case FRAME_STATE_MINIMIZED:
169                 pFrameListener->OnFrameMinimized(*pArg->GetSource());
170                 break;
171         case FRAME_STATE_RESTORED:
172                 pFrameListener->OnFrameRestored(*pArg->GetSource());
173                 break;
174         default :
175                 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] The invalid event argument was given.");
176                 break;
177         }
178
179         SetLastResult(E_SUCCESS);
180
181         return;
182 }
183
184 _PublicFrameEvent::_PublicFrameEvent(const Frame& source)
185         : __pSource(null)
186 {
187         result r = _Event::Initialize();
188         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
189
190         __pSource = &source;
191         ClearLastResult();
192 }
193
194 }}} // Tizen::Ui::Controls