Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_SearchBarEvent.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 #include <new>
19 #include <FBaseErrors.h>
20 #include <FBaseSysLog.h>
21 #include "FUiCtrl_ISearchBarEventListener.h"
22 #include "FUiCtrl_SearchBarEvent.h"
23 #include "FUiCtrl_SearchBar.h"
24
25 // using namespace
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Runtime;
28
29 namespace Tizen { namespace Ui { namespace Controls
30 {
31
32 /**
33  * @class       _SearchBarEventArg
34  * @brief       This class is used as the argument to action event listener.
35  *
36  * This class is used as the argument to searchbar event listener. When an searchbar event is generated
37  * (such as when a searchbar is pressed) the SearchBarEvent calls SearchBarEventListener's OnActionPerformed
38  * with an instance of this class as an argument.
39  *
40  * From this class, one can find out, the (event) source object and the action ID.
41  */
42 class _OSP_EXPORT_ _SearchBarEventArg
43         : public IEventArg
44         , public Object
45 {
46 // Lifecycle
47 public:
48         /**
49          * This is the default class constructor.
50          *
51          * @param[in] status
52          */
53         _SearchBarEventArg(_SearchBarEventStatus status);
54
55         /**
56          * This is the class destructor.
57          *
58          */
59         virtual ~_SearchBarEventArg(void);
60
61
62 // Access
63 public:
64         /**
65         * This method returns the status which the event initially occurred.
66         *
67         * @return       See the comment above.
68         */
69         _SearchBarEventStatus GetStatus(void) const;
70
71
72 // Attribute
73 private:
74         /**
75         * Event status.
76         */
77         _SearchBarEventStatus __status;
78 };
79
80 _SearchBarEventArg::_SearchBarEventArg(_SearchBarEventStatus status)
81         : __status(status)
82 {
83         // nothing
84 }
85
86 _SearchBarEventArg::~_SearchBarEventArg(void)
87 {
88         // nothing
89 }
90
91 ////////////////////////////////////////////////////////////////////////////////
92 /// _SearchBarEventArg class Access
93
94 _SearchBarEventStatus
95 _SearchBarEventArg::GetStatus(void) const
96 {
97         return __status;
98 }
99
100
101 ////////////////////////////////////////////////////////////////////////////////
102 /// _SearchBarEvent class Lifecycle
103
104 _SearchBarEvent::_SearchBarEvent(const _SearchBar& source)
105         : __pSource(null)
106 {
107         result r = _Event::Initialize();
108
109         // set event source
110         if (r == E_SUCCESS)
111         {
112                 __pSource = &source;
113         }
114 }
115
116 _SearchBarEvent::~_SearchBarEvent(void)
117 {
118         // nothing
119 }
120
121 _SearchBarEvent*
122 _SearchBarEvent::CreateInstanceN(const _SearchBar& source)
123 {
124         _SearchBarEvent* pSearchBarEvent = new (std::nothrow) _SearchBarEvent(source);
125         SysTryReturn(NID_UI_CTRL, pSearchBarEvent, null, E_OUT_OF_MEMORY,
126                      "[E_OUT_OF_MEMORY] Memory allocation failed.");
127
128         if (IsFailed(GetLastResult()))
129         {
130                 goto CATCH;
131         }
132
133         return pSearchBarEvent;
134
135 CATCH:
136         delete pSearchBarEvent;
137         return null;
138 }
139
140 ////////////////////////////////////////////////////////////////////////////////
141 /// _WindowEvent class Accessor
142
143 const _SearchBar*
144 _SearchBarEvent::GetSource(void) const
145 {
146         return __pSource;
147 }
148
149 ////////////////////////////////////////////////////////////////////////////////
150 /// _SearchBarEvent class Operation
151
152 void
153 _SearchBarEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
154 {
155         // cast to _IActionEventListener
156         _ISearchBarEventListener* pSearchBarListener = dynamic_cast <_ISearchBarEventListener*>(&listener);
157         SysTryReturnVoidResult(NID_UI_CTRL, pSearchBarListener != null, E_INVALID_ARG,
158                                "[E_INVALID_ARG] Invalid argument(s) is used. The searchbar listener instance is null.");
159
160         // cast to _SearchBarEventArg
161         const _SearchBarEventArg* pArg = dynamic_cast <const _SearchBarEventArg*>(&arg);
162         SysTryReturnVoidResult(NID_UI_CTRL, pArg != null, E_INVALID_ARG,
163                                "[E_INVALID_ARG] Invalid argument(s) is used. The argument to searchbar event listener is null.");
164
165         _SearchBar* pSource = null;
166         pSource = const_cast <_SearchBar*>(__pSource);
167         SysTryReturnVoidResult(NID_UI_CTRL, pSource != null, E_INVALID_ARG,
168                                "[E_INVALID_ARG] Invalid argument(s) is used.The searchbar instance is null.");
169
170         // call cursor change event listener method
171         _SearchBarEventStatus status = pArg->GetStatus();
172         if (status == _SEARCH_BAR_EVENT_MODE_CHANGE)
173         {
174                 pSearchBarListener->OnSearchBarModeChanged(*pSource, pSource->GetMode());
175         }
176
177         SetLastResult(E_SUCCESS);
178
179         return;
180 }
181
182 IEventArg*
183 _SearchBarEvent::CreateSearchBarEventArgN(_SearchBarEventStatus status)
184 {
185         _SearchBarEventArg* pEventArg = new (std::nothrow) _SearchBarEventArg(status);
186         SysTryReturn(NID_UI_CTRL, pEventArg, null, E_OUT_OF_MEMORY,
187                      "[E_OUT_OF_MEMORY] Memory allocation failed.");
188
189         return pEventArg;
190 }
191
192 }}} // Tizen::Ui::Controls