Changed indicator bg color.
[platform/framework/native/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 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_TextEvent.cpp
20 * @brief        This is the implementation for the TextEvent class.
21 * @version      1.0
22 */
23
24 // includes
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
27 #include <new>
28 #include "FUiCtrl_ITextEventListener.h"
29 #include "FUiCtrl_TextEvent.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       _TextEventArg
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_ _TextEventArg
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         _TextEventArg(CoreTextEventStatus status);
62
63         /**
64          * This is the class destructor.
65          *
66          */
67         virtual ~_TextEventArg(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         CoreTextEventStatus GetStatus(void) const;
78
79
80 // Attribute
81 private:
82         /**
83         * Action Id.
84         */
85         CoreTextEventStatus __status;
86 }; // _TextEventArg
87
88 _TextEventArg::_TextEventArg(CoreTextEventStatus status)
89         : __status(status)
90 {
91         // nothing
92 }
93
94 _TextEventArg::~_TextEventArg(void)
95 {
96         // nothing
97 }
98
99 ////////////////////////////////////////////////////////////////////////////////
100 /// _TextEventArg class Access
101
102 CoreTextEventStatus
103 _TextEventArg::GetStatus(void) const
104 {
105         return __status;
106 }
107
108
109 ////////////////////////////////////////////////////////////////////////////////
110 /// _TextEvent class Lifecycle
111
112 _TextEvent::_TextEvent(const _Control& source)
113         : __pSource(null)
114 {
115         result r = _Event::Initialize();
116
117         // set event source
118         if (r == E_SUCCESS)
119         {
120                 __pSource = &source;
121         }
122 }
123
124 _TextEvent::~_TextEvent(void)
125 {
126         // nothing
127 }
128
129 _TextEvent*
130 _TextEvent::CreateInstanceN(const _Control& source)
131 {
132         _TextEvent* pCoreTextEvent = new (std::nothrow) _TextEvent(source);
133         SysTryReturn(NID_UI_CTRL, pCoreTextEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
134
135         if (IsFailed(GetLastResult()))
136         {
137                 goto CATCH;
138         }
139
140         return pCoreTextEvent;
141
142 CATCH:
143         delete pCoreTextEvent;
144         return null;
145 }
146
147 ////////////////////////////////////////////////////////////////////////////////
148 /// _WindowEvent class Accessor
149
150 const _Control*
151 _TextEvent::GetSource(void) const
152 {
153         return __pSource;
154 }
155
156 ////////////////////////////////////////////////////////////////////////////////
157 /// _TextEvent class Operation
158
159 void
160 _TextEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
161 {
162         // cast to _ITextEventListener
163         _ITextEventListener* pTextListener = dynamic_cast <_ITextEventListener*>(&listener);
164         SysTryReturnVoidResult(NID_UI_CTRL, pTextListener != null, E_INVALID_ARG,
165                                 "[E_INVALID_ARG] The invalid listener was given.\n");
166
167         // cast to _TextEventArg
168         const _TextEventArg* pArg = dynamic_cast <const _TextEventArg*>(&arg);
169         SysTryReturnVoidResult(NID_UI_CTRL, pArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The invalid Event Argument was given.\n");
170
171         CoreTextEventStatus stauts = pArg->GetStatus();
172         if (stauts == CORE_TEXT_EVENT_CHANGED)
173         {
174                 pTextListener->OnTextValueChanged(*__pSource);
175         }
176         else if (stauts == CORE_TEXT_EVENT_CANCELED)
177         {
178                 pTextListener->OnTextValueChangeCanceled(*__pSource);
179         }
180
181         SetLastResult(E_SUCCESS);
182
183         return;
184 }
185
186 IEventArg*
187 _TextEvent::CreateTextEventArgN(CoreTextEventStatus status)
188 {
189         _TextEventArg* pEventArg = new (std::nothrow) _TextEventArg(status);
190         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
191
192         return pEventArg;
193 }
194
195 }}} // Tizen::Ui::Controls