Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_TextEvent.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_TextEvent.cpp
19 * @brief        This is the implementation for the TextEvent class.
20 * @version      1.0
21 */
22
23 // includes
24 #include <FBaseErrors.h>
25 #include <FBaseSysLog.h>
26 #include <new>
27 #include "FUiCtrl_ITextEventListener.h"
28 #include "FUiCtrl_TextEvent.h"
29
30
31 // using namespace
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Runtime;
34
35 namespace Tizen { namespace Ui { namespace Controls
36 {
37
38 /**
39  * @class       _TextEventArg
40  * @brief       This class is used as the argument to action event listener.
41  *
42  * This class is used as the argument to action event listener. When an action event is generated
43  * (such as when a button is pressed) the TextEvent calls TextEventListener's OnActionPerformed
44  * with an instance of this class as an argument.
45  *
46  * From this class, one can find out, the (event) source object and the action ID.
47  */
48 class _OSP_EXPORT_ _TextEventArg
49         : public IEventArg
50         , public Object
51 {
52 // Lifecycle
53 public:
54         /**
55          * This is the default class constructor.
56          *
57          * @param[in]   source          A pointer to the Object instance which contains this instance.
58          * @param[in] actionId  Action Id.
59          */
60         _TextEventArg(CoreTextEventStatus status);
61
62         /**
63          * This is the class destructor.
64          *
65          */
66         virtual ~_TextEventArg(void);
67
68
69 // Access
70 public:
71         /**
72         * This method returns the TextEventStatus which the event initially occurred.
73         *
74         * @return       See the comment above.
75         */
76         CoreTextEventStatus GetStatus(void) const;
77
78
79 // Attribute
80 private:
81         /**
82         * Action Id.
83         */
84         CoreTextEventStatus __status;
85 }; // _TextEventArg
86
87 _TextEventArg::_TextEventArg(CoreTextEventStatus status)
88         : __status(status)
89 {
90         // nothing
91 }
92
93 _TextEventArg::~_TextEventArg(void)
94 {
95         // nothing
96 }
97
98 ////////////////////////////////////////////////////////////////////////////////
99 /// _TextEventArg class Access
100
101 CoreTextEventStatus
102 _TextEventArg::GetStatus(void) const
103 {
104         return __status;
105 }
106
107
108 ////////////////////////////////////////////////////////////////////////////////
109 /// _TextEvent class Lifecycle
110
111 _TextEvent::_TextEvent(const _Control& source)
112         : __pSource(null)
113 {
114         result r = _Event::Initialize();
115
116         // set event source
117         if (r == E_SUCCESS)
118         {
119                 __pSource = &source;
120         }
121 }
122
123 _TextEvent::~_TextEvent(void)
124 {
125         // nothing
126 }
127
128 _TextEvent*
129 _TextEvent::CreateInstanceN(const _Control& source)
130 {
131         _TextEvent* pCoreTextEvent = new (std::nothrow) _TextEvent(source);
132         SysTryReturn(NID_UI_CTRL, pCoreTextEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
133
134         if (IsFailed(GetLastResult()))
135         {
136                 goto CATCH;
137         }
138
139         return pCoreTextEvent;
140
141 CATCH:
142         delete pCoreTextEvent;
143         return null;
144 }
145
146 ////////////////////////////////////////////////////////////////////////////////
147 /// _WindowEvent class Accessor
148
149 const _Control*
150 _TextEvent::GetSource(void) const
151 {
152         return __pSource;
153 }
154
155 ////////////////////////////////////////////////////////////////////////////////
156 /// _TextEvent class Operation
157
158 void
159 _TextEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
160 {
161         // cast to _ITextEventListener
162         _ITextEventListener* pTextListener = dynamic_cast <_ITextEventListener*>(&listener);
163         SysTryReturnVoidResult(NID_UI_CTRL, pTextListener != null, E_INVALID_ARG,
164                                 "[E_INVALID_ARG] The invalid listener was given.\n");
165
166         // cast to _TextEventArg
167         const _TextEventArg* pArg = dynamic_cast <const _TextEventArg*>(&arg);
168         SysTryReturnVoidResult(NID_UI_CTRL, pArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The invalid Event Argument was given.\n");
169
170         CoreTextEventStatus stauts = pArg->GetStatus();
171         if (stauts == CORE_TEXT_EVENT_CHANGED)
172         {
173                 pTextListener->OnTextValueChanged(*__pSource);
174         }
175         else if (stauts == CORE_TEXT_EVENT_CANCELED)
176         {
177                 pTextListener->OnTextValueChangeCanceled(*__pSource);
178         }
179
180         SetLastResult(E_SUCCESS);
181
182         return;
183 }
184
185 IEventArg*
186 _TextEvent::CreateTextEventArgN(CoreTextEventStatus status)
187 {
188         _TextEventArg* pEventArg = new (std::nothrow) _TextEventArg(status);
189         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
190
191         return pEventArg;
192 }
193
194 }}} // Tizen::Ui::Controls