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