Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_LinkEvent.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_LinkEvent.cpp
19 * @brief        This is the implementation for the _LinkEvent class.
20 * @version      1.0
21 */
22
23 // includes
24 #include <FBaseErrors.h>
25 #include <FBaseSysLog.h>
26 #include <new>
27 #include "FUiCtrl_LinkEvent.h"
28
29
30 // using namespace
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Runtime;
33 using namespace Tizen::Base::Utility;
34
35 namespace Tizen { namespace Ui { namespace Controls
36 {
37
38 /**
39  * @class       _LinkEventArg
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 TextSelectionEvent calls TextSelectionEventListener'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_ _LinkEventArg
49         : public IEventArg
50         , public Object
51 {
52 // Lifecycle
53 public:
54         /**
55          * This is the default class constructor.
56          *
57          */
58         _LinkEventArg(const String& text, LinkType linkType, const String& link);
59
60         /**
61          * This is the class destructor.
62          *
63          */
64         virtual ~_LinkEventArg(void);
65
66         String GetText(void) const;
67
68         LinkType GetLinkType(void) const;
69
70         String GetLinkText(void) const;
71
72
73 private:
74         String __text;
75
76         LinkType __linkType;
77
78         String __linkText;
79 }; // _LinkEventArg
80
81 ////////////////////////////////////////////////////////////////////////////////
82 /// _LinkEventArg class Lifecycle
83
84 _LinkEventArg::_LinkEventArg(const String& text, LinkType linkType, const String& link)
85         : __text(text)
86         , __linkType(linkType)
87         , __linkText(link)
88 {
89         // Nothing.
90 }
91
92 _LinkEventArg::~_LinkEventArg(void)
93 {
94         // Nothing.
95 }
96
97 String
98 _LinkEventArg::GetText(void) const
99 {
100         return __text;
101 }
102
103 LinkType
104 _LinkEventArg::GetLinkType(void) const
105 {
106         return __linkType;
107 }
108
109 String
110 _LinkEventArg::GetLinkText(void) const
111 {
112         return __linkText;
113 }
114
115 ////////////////////////////////////////////////////////////////////////////////
116 /// _LinkEvent class Lifecycle
117 _LinkEvent::_LinkEvent(const _Control& source)
118         : __pSource(null)
119 {
120         result r = _Event::Initialize();
121
122         // Set event source
123         if (r == E_SUCCESS)
124         {
125                 __pSource = &source;
126         }
127 }
128
129 _LinkEvent::~_LinkEvent(void)
130 {
131         // Nothing.
132 }
133
134 _LinkEvent*
135 _LinkEvent::CreateInstanceN(const _Control& source)
136 {
137         _LinkEvent* pCoreLinkEvent = new (std::nothrow) _LinkEvent(source);
138         SysTryReturn(NID_UI_CTRL, pCoreLinkEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
139
140         if (IsFailed(GetLastResult()))
141                 goto CATCH;
142
143         return pCoreLinkEvent;
144
145 CATCH:
146         delete pCoreLinkEvent;
147         return null;
148 }
149
150 const _Control*
151 _LinkEvent::GetSource(void) const
152 {
153         return __pSource;
154 }
155
156 void
157 _LinkEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
158 {
159         _IUiLinkEventListener* pLinkEventListener = dynamic_cast <_IUiLinkEventListener*>(&listener);
160         SysTryReturnVoidResult(NID_UI_CTRL, pLinkEventListener != null, E_INVALID_ARG, "The Invalid listener is given.\n");
161
162         _LinkEventArg* pLinkEventArg = dynamic_cast <_LinkEventArg*>(const_cast <IEventArg*>(&arg));
163         SysTryReturnVoidResult(NID_UI_CTRL, pLinkEventArg != null, E_INVALID_ARG, "The Invalid Event Argument is given.\n");
164
165         const String text = pLinkEventArg->GetText();
166         LinkType linkType = pLinkEventArg->GetLinkType();
167         const String linkText = pLinkEventArg->GetLinkText();
168
169         pLinkEventListener->OnLinkClicked(const_cast <_Control&>(*__pSource), text, linkType, linkText);
170
171         SetLastResult(E_SUCCESS);
172
173         return;
174 }
175
176 IEventArg*
177 _LinkEvent::CreateLinkEventArgN(String text, LinkType linkType, String link)
178 {
179         _LinkEventArg* pEventArg = new (std::nothrow) _LinkEventArg(text, linkType, link);
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