Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / controls / FUiCtrl_PublicLinkEvent.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_PublicLinkEvent.cpp
19 * @brief        This is the implementation for the _PublicLinkEvent class.
20 * @version      1.0
21 */
22
23 // includes
24 #include <FBaseErrors.h>
25 #include <FBaseSysLog.h>
26 #include <new>
27 #include "FUiCtrl_PublicLinkEvent.h"
28
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       _PublicLinkEventArg
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 TextSelectionEvent calls TextSelectionEventListener'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_ _PublicLinkEventArg
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          */
57         _PublicLinkEventArg(const Tizen::Base::String& text, Tizen::Base::Utility::LinkType linkType, const Tizen::Base::String& link);
58
59         /**
60          * This is the class destructor.
61          *
62          */
63         virtual ~_PublicLinkEventArg(void);
64
65         /**
66          * Gets the text.
67          *
68          * @return      The text.
69          */
70         Tizen::Base::String GetText(void) const;
71
72         /**
73          * Gets the link type.
74          *
75          * @return      The link type.
76          */
77         Tizen::Base::Utility::LinkType GetLinkType(void) const;
78
79         /**
80          * Gets the link text.
81          *
82          * @return      The link text.
83          */
84         Tizen::Base::String GetLinkText(void) const;
85
86
87 private:
88         /**
89         * The text.
90         */
91         Tizen::Base::String __text;
92
93         /**
94         * The linktype.
95         */
96         Tizen::Base::Utility::LinkType __linkType;
97
98         /**
99         * The link text.
100         */
101         Tizen::Base::String __linkText;
102 }; // _PublicLinkEventArg
103
104 ////////////////////////////////////////////////////////////////////////////////
105 /// _PublicLinkEventArg class Lifecycle
106
107 _PublicLinkEventArg::_PublicLinkEventArg(const Tizen::Base::String& text, Tizen::Base::Utility::LinkType linkType, const Tizen::Base::String& link)
108         : __text(text)
109         , __linkType(linkType)
110         , __linkText(link)
111 {
112         // Nothing.
113 }
114
115 _PublicLinkEventArg::~_PublicLinkEventArg(void)
116 {
117         // Nothing.
118 }
119
120 Tizen::Base::String
121 _PublicLinkEventArg::GetText(void) const
122 {
123         return __text;
124 }
125
126 Tizen::Base::Utility::LinkType
127 _PublicLinkEventArg::GetLinkType(void) const
128 {
129         return __linkType;
130 }
131
132 Tizen::Base::String
133 _PublicLinkEventArg::GetLinkText(void) const
134 {
135         return __linkText;
136 }
137
138 ////////////////////////////////////////////////////////////////////////////////
139 /// _PublicLinkEvent class Lifecycle
140 _PublicLinkEvent::_PublicLinkEvent(const Tizen::Ui::Control& source)
141         : __pSource(null)
142 {
143         result r = _Event::Initialize();
144
145         // Set event source
146         if (r == E_SUCCESS)
147         {
148                 __pSource = &source;
149         }
150 }
151
152 _PublicLinkEvent::~_PublicLinkEvent(void)
153 {
154         // Nothing.
155 }
156
157 _PublicLinkEvent*
158 _PublicLinkEvent::CreateInstanceN(const Tizen::Ui::Control& source)
159 {
160         _PublicLinkEvent* pPublicLinkEvent = new (std::nothrow) _PublicLinkEvent(source);
161         SysTryReturn(NID_UI_CTRL, pPublicLinkEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
162
163         return pPublicLinkEvent;
164 }
165
166 const Tizen::Ui::Control*
167 _PublicLinkEvent::GetSource(void) const
168 {
169         return __pSource;
170 }
171
172 void
173 _PublicLinkEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
174 {
175         IUiLinkEventListener* pLinkEventListener = dynamic_cast <IUiLinkEventListener*>(&listener);
176         SysTryReturnVoidResult(NID_UI_CTRL, pLinkEventListener != null, E_INVALID_ARG, "The Invalid listener is given.\n");
177
178         _PublicLinkEventArg* pLinkEventArg = dynamic_cast <_PublicLinkEventArg*>(const_cast <IEventArg*>(&arg));
179         SysTryReturnVoidResult(NID_UI_CTRL, pLinkEventArg != null, E_INVALID_ARG, "The Invalid Event Argument is given.\n");
180
181         const Tizen::Base::String text = pLinkEventArg->GetText();
182         Tizen::Base::Utility::LinkType linkType = pLinkEventArg->GetLinkType();
183         const Tizen::Base::String linkText = pLinkEventArg->GetLinkText();
184
185         pLinkEventListener->OnLinkClicked(const_cast <Tizen::Ui::Control&>(*__pSource), text, linkType, linkText);
186
187         SetLastResult(E_SUCCESS);
188
189         return;
190 }
191
192 IEventArg*
193 _PublicLinkEvent::CreateLinkEventArgN(Tizen::Base::String text, Tizen::Base::Utility::LinkType linkType, Tizen::Base::String link)
194 {
195         _PublicLinkEventArg* pEventArg = new (std::nothrow) _PublicLinkEventArg(text, linkType, link);
196         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
197
198         return pEventArg;
199 }
200
201 }}} // Tizen::Ui::Controls