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