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