Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_PublicSearchBarEvent.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_PublicSearchBarEvent.cpp
20 * @brief        This is the implementation for the PublicSearcBarEvent class.
21 * @version      1.0
22 */
23
24 #include <new>
25 #include <FBaseErrors.h>
26 #include <FUiCtrlSearchBar.h>
27 #include <FBaseSysLog.h>
28 #include "FUiCtrl_PublicSearchBarEvent.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       _PublicSearchBarEventArg
39  * @brief       This class is used as the argument to searchbar event listener.
40  *
41  * This class is used as the argument to searchbar event listener. When an searchbar event is generated
42  * (such as when a searchbar is pressed) the SearchBarEvent calls SearchBarEventListener's OnSearchBarModeChanged
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 action ID.
46  */
47 class _OSP_EXPORT_ _PublicSearchBarEventArg
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          * @param[in]   status
57          */
58         _PublicSearchBarEventArg(SearchBarEventStatus status);
59
60         /**
61          * This is the class destructor.
62          *
63          */
64         virtual ~_PublicSearchBarEventArg(void);
65
66
67 // Access
68 public:
69         /**
70         * This method returns the actionId which the event initially occurred.
71         *
72         * @return       See the comment above.
73         */
74         SearchBarEventStatus GetStatus(void) const;
75
76
77 // Attribute
78 private:
79         /**
80         * Event status.
81         */
82         SearchBarEventStatus __status;
83 };
84
85 _PublicSearchBarEventArg::_PublicSearchBarEventArg(SearchBarEventStatus status)
86         : __status(status)
87 {
88         // nothing
89 }
90
91 _PublicSearchBarEventArg::~_PublicSearchBarEventArg(void)
92 {
93         // nothing
94 }
95
96 ////////////////////////////////////////////////////////////////////////////////
97 /// _SearchBarEventArg class Access
98 SearchBarEventStatus
99 _PublicSearchBarEventArg::GetStatus(void) const
100 {
101         return __status;
102 }
103
104 ////////////////////////////////////////////////////////////////////////////////
105 /// _PublicSearchBarEvent class Lifecycle
106 _PublicSearchBarEvent::_PublicSearchBarEvent(const SearchBar& source)
107         : __pSource(null)
108 {
109         result r = _Event::Initialize();
110
111         // set event source
112         if (r == E_SUCCESS)
113         {
114                 __pSource = &source;
115         }
116 }
117
118 _PublicSearchBarEvent::~_PublicSearchBarEvent(void)
119 {
120         // nothing
121 }
122
123 _PublicSearchBarEvent*
124 _PublicSearchBarEvent::CreateInstanceN(const SearchBar& source)
125 {
126         _PublicSearchBarEvent* pPublicSearchBarEvent = new (std::nothrow) _PublicSearchBarEvent(source);
127         SysTryReturn(NID_UI_CTRL, pPublicSearchBarEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
128
129         if (IsFailed(GetLastResult()))
130         {
131                 goto CATCH;
132         }
133
134         return pPublicSearchBarEvent;
135
136 CATCH:
137         delete pPublicSearchBarEvent;
138         return null;
139 }
140
141 ////////////////////////////////////////////////////////////////////////////////
142 /// _WindowEvent class Accessor
143
144 const SearchBar*
145 _PublicSearchBarEvent::GetSource(void) const
146 {
147         return __pSource;
148 }
149
150 ////////////////////////////////////////////////////////////////////////////////
151 /// _PublicActionEvent class Operation
152
153 void
154 _PublicSearchBarEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
155
156 {
157         // cast to IActionEventListener
158         ISearchBarEventListener* pSearchBarListener = dynamic_cast <ISearchBarEventListener*>(&listener);
159         SysTryReturnVoidResult(NID_UI_CTRL, pSearchBarListener != null, E_INVALID_ARG, "[E_INVALID_ARG] The invalid listener was given.");
160
161         // cast to _PublicSearchBarEventArg
162         const _PublicSearchBarEventArg* pArg = dynamic_cast <const _PublicSearchBarEventArg*>(&arg);
163         SysTryReturnVoidResult(NID_UI_CTRL, pArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The invalid Event Argument was given.");
164
165         SearchBar* pSource = null;
166         pSource = const_cast <SearchBar*>(__pSource);
167         SysTryReturnVoidResult(NID_UI_CTRL, pSource != null, E_INVALID_ARG, "[E_INVALID_ARG] The invalid Event Argument was given.");
168
169         // call cursor change event listener method
170         SearchBarEventStatus status = pArg->GetStatus();
171         if (status == SEARCH_BAR_EVENT_MODE_CHANGE)
172         {
173                 pSearchBarListener->OnSearchBarModeChanged(*pSource, pSource->GetMode());
174         }
175
176         SetLastResult(E_SUCCESS);
177
178         return;
179 }
180
181 IEventArg*
182 _PublicSearchBarEvent::CreateSearchBarEventArgN(SearchBarEventStatus status)
183 {
184         _PublicSearchBarEventArg* pEventArg = new (std::nothrow) _PublicSearchBarEventArg(status);
185         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
186
187         return pEventArg;
188 }
189
190 }}} // Tizen::Ui::Controls