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