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