Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_ExpandableEditAreaEvent.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_ExpandableEditAreaEvent.cpp
19 * @brief        This is the implementation for the _ExpandableEditAreaEvent class.
20 * @version      1.0
21 */
22
23 // includes
24 #include <FBaseSysLog.h>
25 #include <FBaseErrors.h>
26 #include <new>
27 #include "FUiCtrl_ExpandableEditAreaEvent.h"
28 #include "FUiCtrl_IExpandableEditAreaEventListener.h"
29
30 // using namespace
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Runtime;
33
34 namespace Tizen {namespace Ui {namespace Controls
35 {
36
37 /**
38  * @class       _CoreExpandableEditAreaEventArg
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 TextEvent calls TextEventListener'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_ _CoreExpandableEditAreaEventArg
48         : public IEventArg
49         , public 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         _CoreExpandableEditAreaEventArg(_ExpandableEditAreaEventStatus status, int tokenIndex = -1);
60
61         /**
62          * This is the class destructor.
63          *
64          */
65         virtual ~_CoreExpandableEditAreaEventArg(void);
66
67
68 // Access
69 public:
70         /**
71         * This method returns the TextEventStatus 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         * Action Id.
84         */
85         _ExpandableEditAreaEventStatus __status;
86
87         int __newLineCount;
88 };      // _CoreExpandableEditAreaEventArg
89
90 _CoreExpandableEditAreaEventArg::_CoreExpandableEditAreaEventArg(_ExpandableEditAreaEventStatus status, int newLineCount)
91         : __status(status)
92         , __newLineCount(newLineCount)
93 {
94         // nothing
95 }
96
97 _CoreExpandableEditAreaEventArg::~_CoreExpandableEditAreaEventArg(void)
98 {
99         // nothing
100 }
101
102 ////////////////////////////////////////////////////////////////////////////////
103 /// _CoreExpandableEditAreaEventArg class Access
104
105 _ExpandableEditAreaEventStatus
106 _CoreExpandableEditAreaEventArg::GetStatus(void) const
107 {
108         return __status;
109 }
110
111 int
112 _CoreExpandableEditAreaEventArg::GetNewLineCount(void) const
113 {
114         return __newLineCount;
115 }
116
117 ////////////////////////////////////////////////////////////////////////////////
118 /// _CoreExpandableEditAreaEvent class Lifecycle
119
120 _ExpandableEditAreaEvent::_ExpandableEditAreaEvent(const _Control& source)
121         : __pSource(null)
122 {
123         result r = _Event::Initialize();
124
125         // set event source
126         if (r == E_SUCCESS)
127         {
128                 __pSource = &source;
129         }
130 }
131
132 _ExpandableEditAreaEvent::~_ExpandableEditAreaEvent(void)
133 {
134         // nothing
135 }
136
137 _ExpandableEditAreaEvent*
138 _ExpandableEditAreaEvent::CreateInstanceN(const _Control& source)
139 {
140         _ExpandableEditAreaEvent* pCoreTextEvent = new (std::nothrow) _ExpandableEditAreaEvent(source);
141         SysTryReturn(NID_UI_CTRL, pCoreTextEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
142
143         if (IsFailed(GetLastResult()))
144         {
145                 goto CATCH;
146         }
147
148         return pCoreTextEvent;
149
150 CATCH:
151         delete pCoreTextEvent;
152         return null;
153 }
154
155 ////////////////////////////////////////////////////////////////////////////////
156 /// _WindowEvent class Accessor
157
158 const _Control*
159 _ExpandableEditAreaEvent::GetSource(void) const
160 {
161         return __pSource;
162 }
163
164 ////////////////////////////////////////////////////////////////////////////////
165 /// _CoreExpandableEditAreaEvent class Operation
166
167 void
168 _ExpandableEditAreaEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
169 {
170         // cast to _ITextEventListener
171         _IExpandableEditAreaEventListener* pExpandableEditAreaEventListener =
172                 dynamic_cast <_IExpandableEditAreaEventListener*>(&listener);
173         SysTryReturnVoidResult(NID_UI_CTRL, pExpandableEditAreaEventListener != null, E_INVALID_ARG,
174                                 "[E_INVALID_ARG] The invalid listener was given.\n");
175
176         // cast to _CoreExpandableEditAreaEventArg
177         const _CoreExpandableEditAreaEventArg* pArg = dynamic_cast <const _CoreExpandableEditAreaEventArg*>(&arg);
178         SysTryReturnVoidResult(NID_UI_CTRL, pArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The invalid Event Argument was given.\n");
179
180         _ExpandableEditAreaEventStatus status = pArg->GetStatus();
181         if (status == _EXPANDABLE_EDITAREA_EVENT_ADDED)
182         {
183                 pExpandableEditAreaEventListener->OnExpandableEditAreaLineAdded(*__pSource, pArg->GetNewLineCount());
184         }
185         else if (status == _EXPANDABLE_EDITAREA_EVENT_REMOVED)
186         {
187                 pExpandableEditAreaEventListener->OnExpandableEditAreaLineRemoved(*__pSource, pArg->GetNewLineCount());
188         }
189
190         SetLastResult(E_SUCCESS);
191
192         return;
193 }
194
195 IEventArg*
196 _ExpandableEditAreaEvent::CreateExpandableEditAreaEventArgN(_ExpandableEditAreaEventStatus status, int newLineCount)
197 {
198         _CoreExpandableEditAreaEventArg* pEventArg = new (std::nothrow) _CoreExpandableEditAreaEventArg(status, newLineCount);
199         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
200
201         return pEventArg;
202 }
203
204 }}} // Tizen::Ui::Controls