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