Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_PublicActionEvent.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_PublicActionEvent.cpp
19 * @brief        This is the implementation for the _PublicActionEvent class.
20 */
21
22 #include <new>
23 #include <FUiIActionEventListener.h>
24 #include <FBaseErrors.h>
25 #include <FBaseSysLog.h>
26 #include "FUiCtrl_PublicActionEvent.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Runtime;
30
31 namespace Tizen { namespace Ui { namespace Controls
32 {
33
34 /**
35  * @class       _PublicActionEventArg
36  * @brief       This class is used as the argument to action event listener.
37  *
38  * This class is used as the argument to action event listener. When an action event is generated
39  * (such as when a button is pressed) the ActionEvent calls ActionEventListener's OnActionPerformed
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 action ID.
43  */
44 class _OSP_EXPORT_ _PublicActionEventArg
45         : public IEventArg
46         , public Object
47 {
48 public:
49         /**
50          * This is the default class constructor.
51          *
52          * @param[in]   source          A pointer to the Object instance which contains this instance.
53          * @param[in] actionId  Action Id.
54          */
55         _PublicActionEventArg(int actionId);
56
57         /**
58          * This is the class destructor.
59          *
60          */
61         virtual ~_PublicActionEventArg(void);
62
63 public:
64         /**
65         * This method returns the actionId which the event initially occurred.
66         *
67         * @return       See the comment above.
68         */
69         int GetActionId(void) const;
70
71 private:
72         /**
73         * Action Id.
74         */
75         int __actionId;
76 }; // _PublicActionEventArg
77
78 _PublicActionEventArg::_PublicActionEventArg(int actionId)
79         : __actionId(actionId)
80 {
81         // nothing
82 }
83
84 _PublicActionEventArg::~_PublicActionEventArg(void)
85 {
86         // nothing
87 }
88
89 int
90 _PublicActionEventArg::GetActionId(void) const
91 {
92         return __actionId;
93 }
94
95 _PublicActionEvent::_PublicActionEvent(const Control& source)
96         : __pSource(null)
97 {
98         result r = _Event::Initialize();
99
100         // set event source
101         if (r == E_SUCCESS)
102         {
103                 __pSource = &source;
104                 SetLastResult(E_SUCCESS);
105         }
106 }
107
108 _PublicActionEvent::~_PublicActionEvent(void)
109 {
110         // nothing
111 }
112
113 _PublicActionEvent*
114 _PublicActionEvent::CreateInstanceN(const Control& source)
115 {
116         _PublicActionEvent* pPublicActionEvent = new (std::nothrow) _PublicActionEvent(source);
117         SysTryReturn(NID_UI_CTRL, pPublicActionEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
118
119         if (IsFailed(GetLastResult()))
120         {
121                 goto CATCH;
122         }
123
124         return pPublicActionEvent;
125
126 CATCH:
127         delete pPublicActionEvent;
128         return null;
129 }
130
131 const Control*
132 _PublicActionEvent::GetSource(void) const
133 {
134         return __pSource;
135 }
136
137 void
138 _PublicActionEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
139 {
140         // cast to IActionEventListener
141         IActionEventListener* pActionListener = dynamic_cast <IActionEventListener*>(&listener);
142         SysTryReturnVoidResult(NID_UI_CTRL, pActionListener != null, E_INVALID_ARG,
143                                 "[E_INVALID_ARG] The invalid listener was given.\n");
144
145         // cast to _PublicActionEventArg
146         const _PublicActionEventArg* pArg = dynamic_cast <const _PublicActionEventArg*>(&arg);
147         SysTryReturnVoidResult(NID_UI_CTRL, pArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The invalid Event Argument was given.\n");
148
149         // call cursor change event listener method
150         pActionListener->OnActionPerformed(*__pSource, pArg->GetActionId());
151
152         SetLastResult(E_SUCCESS);
153
154         return;
155 }
156
157 IEventArg*
158 _PublicActionEvent::CreateActionEventArgN(int actionId)
159 {
160         _PublicActionEventArg* pEventArg = new (std::nothrow) _PublicActionEventArg(actionId);
161         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
162
163         return pEventArg;
164 }
165
166 }}} // Tizen::Ui::Controls