Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / FUi_UiFocusEvent.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                FUi_UiFocusEvent.cpp
19  * @brief               This is the implementation file for _UiFocusEvent class.
20  */
21
22 #include <FBaseSysLog.h>
23 #include <FBaseResult.h>
24 #include "FUi_UiFocusEvent.h"
25 #include "FUi_IFocusEventListener.h"
26 #include "FUi_Control.h"
27
28 namespace Tizen { namespace Ui
29 {
30
31 _UiFocusEvent::_UiFocusEvent(const _UiObjectHandle& destination, FocusStatus focusState, _UiEventRouteType routeType, const _UiObjectHandle& source)
32         : _UiEvent(destination, source, routeType)
33         , __focusState(focusState)
34 {
35 }
36
37 _UiFocusEvent::~_UiFocusEvent(void)
38 {
39 }
40
41 _UiFocusEvent::_UiFocusEvent(const _UiFocusEvent& rhs)
42         : _UiEvent(rhs)
43         , __focusState(rhs.__focusState)
44 {
45 }
46
47 _UiFocusEvent&
48 _UiFocusEvent::operator =(const _UiFocusEvent& rhs)
49 {
50         _UiEvent::operator =(rhs);
51
52         if (this != &rhs)
53         {
54                 __focusState = rhs.__focusState;
55         }
56
57         return *this;
58 }
59
60 FocusStatus
61 _UiFocusEvent::GetFocusState(void) const
62 {
63         return __focusState;
64 }
65
66 _UiFocusEvent*
67 _UiFocusEvent::CloneN(void) const
68 {
69         return new (std::nothrow) _UiFocusEvent(*this);
70 }
71
72 _UiEventType
73 _UiFocusEvent::GetEventType(void) const
74 {
75         return _UI_EVENT_FOCUS;
76 }
77
78 result
79 _UiFocusEvent::OnPreviewEventProcessing(const _Control& control, bool& isFiltered)
80 {
81         return E_SUCCESS;
82 }
83
84 result
85 _UiFocusEvent::OnEventProcessing(const _Control& control, bool& isFiltered)
86 {
87         _IFocusEventListener* pFocusListener = control.GetEventListener<_UI_EVENT_FOCUS, _IFocusEventListener*>();
88         SysTryReturn(NID_UI, pFocusListener, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
89
90         return FireListener(pFocusListener, isFiltered);
91 }
92
93 result
94 _UiFocusEvent::OnListenerProcessing(const _IUiEventListener& listener, bool& isFiltered)
95 {
96         if (isFiltered)
97         {
98                 return E_SUCCESS;
99         }
100
101         _IFocusEventListener* pFocusListener = dynamic_cast <_IFocusEventListener*>(const_cast <_IUiEventListener*>(&listener));
102         SysTryReturn(NID_UI, pFocusListener, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
103
104         return FireListener(pFocusListener, isFiltered);
105 }
106
107 result
108 _UiFocusEvent::FireListener(const _IFocusEventListener* pListener, bool& isFiltered)
109 {
110         SysTryReturn(NID_UI, pListener, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
111
112         result r = E_SUCCESS;
113
114         _IFocusEventListener* pFocusListener = const_cast <_IFocusEventListener*>(pListener);
115         SysTryReturn(NID_UI, pFocusListener, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
116
117         const _Control* pTarget = GetControl(GetDestination());
118         SysTryReturn(NID_UI, pTarget, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
119
120         // call a listener method by the key state
121         switch (GetFocusState())
122         {
123         case FOCUS_GAINED:
124                 isFiltered = pFocusListener->OnFocusGained(*pTarget);
125                 break;
126
127         case FOCUS_LOST:
128                 isFiltered = pFocusListener->OnFocusLost(*pTarget);
129                 break;
130
131         default:
132                 //SysLogI(NID_UI, "unable to determine the key event type.");
133                 r = E_SYSTEM;
134                 break;
135         }
136
137         return r;
138 }
139 }}//Tizen::Ui