Tizen 2.1 base
[framework/osp/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 Flora License, Version 1.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://floralicense.org/license/
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_KeypadEvent.cpp
19 * @brief                This file contains implementation of _KeypadEvent class
20 *
21 * This file contains implementation of _KeypadEvent class.
22 */
23
24 // Includes
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
27 #include <new>
28 #include "FUiCtrl_KeypadEvent.h"
29
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Runtime;
33
34 namespace Tizen {namespace Ui {namespace Controls
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_ _KeypadEventArg
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         _KeypadEventArg(CoreKeypadAction actionId, CoreKeypadEventStatus status);
58
59         /**
60          * This is the class destructor.
61          *
62          */
63         virtual ~_KeypadEventArg(void);
64
65
66 // Access
67 public:
68         CoreKeypadAction GetKeypadActionId() const;
69
70         CoreKeypadEventStatus GetStatus() const;
71
72 // Attribute
73 private:
74         /**
75         * Event source.
76         */
77         CoreKeypadAction __actionId;
78
79         /**
80         * status.
81         */
82         CoreKeypadEventStatus __status;
83 }; // _KeypadEventArg
84
85 ////////////////////////////////////////////////////////////////////////////////
86 /// __TextSelectionEventArg class Lifecycle
87
88 _KeypadEventArg::_KeypadEventArg(CoreKeypadAction actionId, CoreKeypadEventStatus status)
89 {
90         __actionId = actionId;
91         __status = status;
92 }
93
94 _KeypadEventArg::~_KeypadEventArg(void)
95 {
96         // Nothing.
97 }
98
99 CoreKeypadAction
100 _KeypadEventArg::GetKeypadActionId(void) const
101 {
102         return __actionId;
103 }
104
105 CoreKeypadEventStatus
106 _KeypadEventArg::GetStatus() const
107 {
108         return __status;
109 }
110
111 ////////////////////////////////////////////////////////////////////////////////
112 /// __TextSelectionEvent class Lifecycle
113 _KeypadEvent::_KeypadEvent(const _Control& source)
114         : __pSource(null)
115 {
116         result r = _Event::Initialize();
117
118         // set event source
119         if (r == E_SUCCESS)
120         {
121                 __pSource = &source;
122         }
123 }
124
125 _KeypadEvent::~_KeypadEvent(void)
126 {
127         // Nothing.
128 }
129
130 _KeypadEvent*
131 _KeypadEvent::CreateInstanceN(const _Control& source)
132 {
133         _KeypadEvent* pCoreKeypadEvent = new (std::nothrow) _KeypadEvent(source);
134         SysTryReturn(NID_UI_CTRL, pCoreKeypadEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
135
136         if (IsFailed(GetLastResult()))
137         {
138                 goto CATCH;
139         }
140
141         return pCoreKeypadEvent;
142 CATCH:
143         delete pCoreKeypadEvent;
144         return null;
145 }
146
147 const _Control*
148 _KeypadEvent::GetSource(void) const
149 {
150         return __pSource;
151 }
152
153 // Operations
154
155 void
156 _KeypadEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
157 {
158         // param checking
159         _IKeypadEventListener* pKeypadEventListener = dynamic_cast <_IKeypadEventListener*>(&listener);
160         SysTryReturnVoidResult(NID_UI_CTRL, pKeypadEventListener != null, E_INVALID_ARG,
161                                 "[E_INVALID_ARG] The invalid listener was given.\n");
162
163         const _KeypadEventArg* pKeypadEventArg = dynamic_cast <const _KeypadEventArg*>(&arg);
164         SysTryReturnVoidResult(NID_UI_CTRL, pKeypadEventArg != null, E_INVALID_ARG,
165                                 "[E_INVALID_ARG] The invalid Event Argument was given.\n");
166
167         CoreKeypadAction keypadAction = pKeypadEventArg->GetKeypadActionId();
168
169         CoreKeypadEventStatus status = pKeypadEventArg->GetStatus();
170         switch (status)
171         {
172         case CORE_KEYPAD_EVENT_STATUS_CREATED:
173                 pKeypadEventListener->OnKeypadWillOpen();
174                 break;
175
176         case CORE_KEYPAD_EVENT_STATUS_OPEN:
177                 pKeypadEventListener->OnKeypadOpened();
178                 break;
179
180         case CORE_KEYPAD_EVENT_STATUS_CLOSE:
181                 pKeypadEventListener->OnKeypadClosed();
182                 break;
183
184         case CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED:
185                 pKeypadEventListener->OnKeypadBoundsChanged();
186                 break;
187
188         case CORE_KEYPAD_EVENT_STATUS_ENTERACTION:
189                 pKeypadEventListener->OnKeypadActionPerformed(keypadAction);
190                 break;
191
192         default:
193                 break;
194         }
195
196         SetLastResult(E_SUCCESS);
197
198         return;
199 }
200
201 IEventArg*
202 _KeypadEvent::CreateKeypadEventArgN(CoreKeypadAction actionId, CoreKeypadEventStatus status)
203 {
204         _KeypadEventArg* pEventArg = new (std::nothrow) _KeypadEventArg(actionId, status);
205         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
206
207         return pEventArg;
208 }
209
210 }}} // Tizen::Ui::Controls