Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_PublicKeypadEvent.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_PublicKeypadEvent.cpp
19 * @brief        This is the implementation for the _PublicKeypadEvent class.
20 *
21 * This file contains implementation of _PublicKeypadEvent class.
22 */
23
24 // Includes
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
27 #include <new>
28 #include "FUiCtrl_PublicKeypadEvent.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Runtime;
32
33 namespace Tizen {namespace Ui {namespace Controls
34 {
35
36 /**
37  * @class
38  * @brief       This class is used as the argument to change event listener.
39  *
40  * This class is used as the argument to change event listener. When an change event is generated
41  * (such as when a button is pressed) the TextSelectionEvent calls TextSelectionEventListener's OnTextd
42  * with an instance of this class as an argument.
43  *
44  * From this class, one can find out, the (event) source object and the change ID.
45  */
46 class _OSP_EXPORT_ _PublicKeypadEventArg
47         : public IEventArg
48         , public Object
49 {
50 // Lifecycle
51 public:
52         /**
53          * This is the default class constructor.
54          *
55          * @param[in]   source          A pointer to the Object instance which contains this instance.
56          */
57         _PublicKeypadEventArg(const Control& source, KeypadAction actionId, KeypadEventStatus status);
58
59         /**
60          * This is the class destructor.
61          *
62          */
63         virtual ~_PublicKeypadEventArg(void);
64
65
66 // Access
67 public:
68         /**
69         * This method returns the object which the event initially occurred.
70         *
71         * @return       The object  which the event initially occurred.
72         */
73         const Control* GetSource(void) const;
74
75         KeypadAction GetKeypadActionId() const;
76
77         KeypadEventStatus GetStatus() const;
78
79 // Attribute
80 private:
81         /**
82         * Event source.
83         */
84         const Control* __pSource;
85
86         /**
87         * Event source.
88         */
89         KeypadAction __actionId;
90
91         /**
92         * status.
93         */
94         KeypadEventStatus __status;
95 }; // _PublicKeypadEventArg
96
97 ////////////////////////////////////////////////////////////////////////////////
98 /// __TextSelectionEventArg class Lifecycle
99
100 _PublicKeypadEventArg::_PublicKeypadEventArg(const Control& source, KeypadAction actionId, Controls::KeypadEventStatus status)
101 {
102         __pSource = &source;
103         __actionId = actionId;
104         __status = status;
105 }
106
107 _PublicKeypadEventArg::~_PublicKeypadEventArg(void)
108 {
109         // Nothing.
110 }
111
112 const Control*
113 _PublicKeypadEventArg::GetSource(void) const
114 {
115         return __pSource;
116 }
117
118 KeypadAction
119 _PublicKeypadEventArg::GetKeypadActionId(void) const
120 {
121         return __actionId;
122 }
123
124 KeypadEventStatus
125 _PublicKeypadEventArg::GetStatus() const
126 {
127         return __status;
128 }
129
130 ////////////////////////////////////////////////////////////////////////////////
131 /// __TextSelectionEvent class Lifecycle
132 _PublicKeypadEvent::_PublicKeypadEvent(const Control& source)
133         : __pSource(null)
134 {
135         result r = _Event::Initialize();
136
137         // set event source
138         if (r == E_SUCCESS)
139                 __pSource = &source;
140 }
141
142 _PublicKeypadEvent::~_PublicKeypadEvent(void)
143 {
144         // Nothing.
145 }
146
147 _PublicKeypadEvent*
148 _PublicKeypadEvent::CreateInstanceN(const Control& source)
149 {
150         _PublicKeypadEvent* pPublicKeypadEvent = new (std::nothrow) _PublicKeypadEvent(source);
151         SysTryReturn(NID_UI_CTRL, pPublicKeypadEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
152
153         return pPublicKeypadEvent;
154 }
155
156 const Control*
157 _PublicKeypadEvent::GetSource(void) const
158 {
159         return __pSource;
160 }
161
162 // Operations
163
164 void
165 _PublicKeypadEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
166 {
167         IKeypadEventListener* pKeypadEventListener = dynamic_cast <IKeypadEventListener*>(&listener);
168         SysTryReturnVoidResult(NID_UI_CTRL, pKeypadEventListener != null, E_INVALID_ARG,
169                                 "[E_INVALID_ARG] The invalid listener was given.\n");
170
171         const _PublicKeypadEventArg* pKeypadEventArg = dynamic_cast <const _PublicKeypadEventArg*>(&arg);
172         SysTryReturnVoidResult(NID_UI_CTRL, pKeypadEventArg != null, E_INVALID_ARG,
173                                 "[E_INVALID_ARG] The invalid Event Argument was given.\n");
174
175         Control* tempSource = null;
176         tempSource = const_cast <Control*>(pKeypadEventArg->GetSource());
177         KeypadAction keypadAction = pKeypadEventArg->GetKeypadActionId();
178
179         Controls::KeypadEventStatus status = pKeypadEventArg->GetStatus();
180         switch (status)
181         {
182         case KEYPAD_EVENT_STATUS_CREATED:
183                 pKeypadEventListener->OnKeypadWillOpen(*tempSource);
184                 break;
185
186         case KEYPAD_EVENT_STATUS_OPEN:
187                 pKeypadEventListener->OnKeypadOpened(*tempSource);
188                 break;
189
190         case KEYPAD_EVENT_STATUS_CLOSE:
191                 pKeypadEventListener->OnKeypadClosed(*tempSource);
192                 break;
193
194         case KEYPAD_EVENT_STATUS_BOUNDS_CHANGED:
195                 pKeypadEventListener->OnKeypadBoundsChanged(*tempSource);
196                 break;
197
198         case KEYPAD_EVENT_STATUS_ENTERACTION:
199                 pKeypadEventListener->OnKeypadActionPerformed(*tempSource, keypadAction);
200                 break;
201
202         default:
203                 break;
204         }
205
206         SetLastResult(E_SUCCESS);
207
208         return;
209 }
210
211 Tizen::Base::Runtime::IEventArg*
212 _PublicKeypadEvent::CreateKeypadEventArgN(const Tizen::Ui::Control& source, Tizen::Ui::KeypadAction actionId,
213                                                                                   KeypadEventStatus status)
214 {
215         _PublicKeypadEventArg* pEventArg = new (std::nothrow) _PublicKeypadEventArg(source, actionId, status);
216         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
217
218         return pEventArg;
219 }
220
221 }}} // Tizen::Ui::Controls