Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_TextBlockEvent.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_TextBlockEvent.cpp
20 * @brief        This is the implementation for the _TextBlockEvent class.
21 * @version      1.0
22 */
23
24 // includes
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
27 #include <new>
28 #include "FUiCtrl_TextBlockEvent.h"
29 #include "FUiCtrl_ITextBlockEventListener.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 /**
39  * @class       _TextBlockEventArg
40  * @brief       This class is used as the argument to change event listener.
41  *
42  * This class is used as the argument to change event listener. When an change event is generated
43  * (such as when a button is pressed) the TextBlockEvent calls TextBlockEventListener's OnTextd
44  * with an instance of this class as an argument.
45  *
46  * From this class, one can find out, the (event) source object and the change ID.
47  */
48 class _OSP_EXPORT_ _TextBlockEventArg
49         : public IEventArg
50         , public Object
51 {
52 // Lifecycle
53 public:
54         /**
55          * This is the default class constructor.
56          *
57          */
58         _TextBlockEventArg(int start, int end);
59
60         /**
61          * This is the class destructor.
62          *
63          */
64         virtual ~_TextBlockEventArg(void);
65
66
67 // Access
68 public:
69         const int GetStartPosition(void) const;
70
71         const int GetEndPosition(void) const;
72
73 // Attribute
74 private:
75         /**
76         * Start position.
77         */
78         int __start;
79
80         /**
81         * End position.
82         */
83         int __end;
84 }; // _TextBlockEventArg
85
86 ////////////////////////////////////////////////////////////////////////////////
87 /// _TextBlockEventArg class Lifecycle
88
89 _TextBlockEventArg::_TextBlockEventArg(int start, int end)
90         : __start(start)
91         , __end(end)
92 {
93         // Nothing
94 }
95
96 _TextBlockEventArg::~_TextBlockEventArg(void)
97 {
98         // Nothing.
99 }
100
101 const int
102 _TextBlockEventArg::GetStartPosition(void) const
103 {
104         return __start;
105 }
106
107 const int
108 _TextBlockEventArg::GetEndPosition(void) const
109 {
110         return __end;
111 }
112
113 ////////////////////////////////////////////////////////////////////////////////
114 /// _TextBlockEvent class Lifecycle
115 _TextBlockEvent::_TextBlockEvent(const _Control& source)
116         : __pSource(null)
117 {
118         result r = _Event::Initialize();
119
120         // Set event source
121         if (r == E_SUCCESS)
122         {
123                 __pSource = &source;
124         }
125 }
126
127 _TextBlockEvent::~_TextBlockEvent(void)
128 {
129         // Nothing.
130 }
131
132 _TextBlockEvent*
133 _TextBlockEvent::CreateInstanceN(const _Control& source)
134 {
135         _TextBlockEvent* pCoreTextBlockEvent = new (std::nothrow) _TextBlockEvent(source);
136         SysTryReturn(NID_UI_CTRL, pCoreTextBlockEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
137
138         if (IsFailed(GetLastResult()))
139         {
140                 goto CATCH;
141         }
142
143         return pCoreTextBlockEvent;
144
145 CATCH:
146         delete pCoreTextBlockEvent;
147         return null;
148 }
149
150 // Accessors
151
152 const _Control*
153 _TextBlockEvent::GetSource(void) const
154 {
155         return __pSource;
156 }
157
158 // Operations
159
160 void
161 _TextBlockEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
162 {
163         _ITextBlockEventListener* pTextBlockEventListener = dynamic_cast <_ITextBlockEventListener*>(&listener);
164         SysTryReturnVoidResult(NID_UI_CTRL, pTextBlockEventListener != null, E_INVALID_ARG, "The Invalid listener is given.\n");
165
166         const _TextBlockEventArg* pTextBlockEventArg = dynamic_cast <const _TextBlockEventArg*>(&arg);
167         SysTryReturnVoidResult(NID_UI_CTRL, pTextBlockEventArg != null, E_INVALID_ARG, "The Invalid Event Argument is given.\n");
168
169         pTextBlockEventListener->OnTextBlockSelected(const_cast <_Control&>(*__pSource),
170                                                                                                  pTextBlockEventArg->GetStartPosition(), pTextBlockEventArg->GetEndPosition());
171
172         SetLastResult(E_SUCCESS);
173
174         return;
175 }
176
177 IEventArg*
178 _TextBlockEvent::CreateTextBlockEventArgN(int start, int end)
179 {
180         _TextBlockEventArg* pEventArg = new (std::nothrow) _TextBlockEventArg(start, end);
181         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
182
183         return pEventArg;
184 }
185
186 }}} // Tizen::Ui::Controls