modify license, permission and remove ^M char
[platform/framework/native/uifw.git] / src / ui / FUi_ImeOrientationAgent.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        FUi_ImeOrientationAgent.cpp
20  * @brief       This is the implementation file for the _ImeOrientationAgent class.
21  */
22
23 #include <unique_ptr.h>
24 #include <app.h>
25 #include <Elementary.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseColArrayList.h>
28 #include "FUi_ImeOrientationAgent.h"
29 #include "FUi_ControlManager.h"
30 #include "FUi_ControlImplManager.h"
31 #include "FUi_PublicOrientationEvent.h"
32 #include "FUi_ControlImpl.h"
33 #include "FUi_Window.h"
34 #include "FUiCtrl_FormImpl.h"
35 #include "FUiCtrl_FrameImpl.h"
36 #include "FUiCtrl_Frame.h"
37 #include "FUiCtrl_Form.h"
38 #include "FUi_EcoreEvasMgr.h"
39 #include "FUi_EcoreEvas.h"
40 #include "FUi_ControlManager.h"
41 #include "FUi_UiNotificationEvent.h"
42 #include "FUi_UiEventManager.h"
43 #include "FUiAnim_RootVisualElement.h"
44 #include "FUiAnim_EflLayer.h"
45
46 using namespace std;
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Base::Runtime;
50 using namespace Tizen::Ui::Controls;
51 using namespace Tizen::Ui::Animations;
52 using namespace Tizen::Graphics;
53
54 namespace Tizen { namespace Ui {
55
56 _ImeOrientationAgent*
57 _ImeOrientationAgent::CreateInstanceN(Control& publicControl)
58 {
59         SysLog(NID_UI, "[Ime Rotation]");
60
61         _ImeOrientationAgent* pAgent = new (std::nothrow) _ImeOrientationAgent(publicControl);
62         SysTryReturn(NID_UI, pAgent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
63
64         result r = GetLastResult();
65         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
66
67         SetLastResult(E_SUCCESS);
68
69         return pAgent;
70
71 CATCH:
72         delete pAgent;
73         return null;
74 }
75
76 _ImeOrientationAgent::_ImeOrientationAgent(Control& publicControl)
77         : __publicControl(publicControl)
78         , __pPublicEvent(null)
79         , __status(ORIENTATION_STATUS_PORTRAIT)
80 {
81         _PublicOrientationEvent* pPublicEvent = _PublicOrientationEvent::CreateInstanceN(publicControl);
82
83         result r = GetLastResult();
84         SysTryReturnVoidResult(NID_UI, pPublicEvent, r, "[%s] Propagating.", GetErrorMessage(r));
85
86         __pPublicEvent = pPublicEvent;
87
88         SetLastResult(E_SUCCESS);
89 }
90
91 _ImeOrientationAgent::~_ImeOrientationAgent(void)
92 {
93         if (__pPublicEvent)
94         {
95                 delete __pPublicEvent;
96                 __pPublicEvent = null;
97         }
98 }
99
100 void
101 _ImeOrientationAgent::AddListener(IOrientationEventListener& listener)
102 {
103         result r = __pPublicEvent->AddListener(listener);
104         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
105
106         SetLastResult(E_SUCCESS);
107 }
108
109 void
110 _ImeOrientationAgent::RemoveListener(IOrientationEventListener& listener)
111 {
112         result r = __pPublicEvent->RemoveListener(listener);
113         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
114
115         SetLastResult(E_SUCCESS);
116 }
117
118 OrientationStatus
119 _ImeOrientationAgent::GetStatus(void) const
120 {
121         return __status;
122 }
123
124 void
125 _ImeOrientationAgent::UpdateOrientation(int angle)
126 {
127         SysLog(NID_UI, "[Ime Rotation]");
128
129         _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
130         if (!pImpl)
131         {
132                 return;
133         }
134
135         _Window* pRootWindow = pImpl->GetCore().GetRootWindow();
136         if (!pRootWindow)
137         {
138                 return;
139         }
140
141         int rotation = angle;
142
143         _RootVisualElement* pRootVisualElement = pRootWindow->GetRootVisualElement();
144         if (!pRootVisualElement)
145         {
146                 SysLog(NID_UI, "[Ime Rotation] The root visual element is null.");
147                 return;
148         }
149
150         _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVisualElement->GetNativeLayer());
151         if (!pLayer)
152         {
153                 SysLog(NID_UI, "[Ime Rotation] The efl layer is null.");
154                 return;
155         }
156
157         Evas_Object* pWinObj = pLayer->GetElmWin();
158
159         if (pWinObj)
160         {
161                 elm_win_rotation_with_resize_set(pWinObj, rotation);
162         }
163
164         OrientationStatus status = ORIENTATION_STATUS_NONE;
165         switch (rotation)
166         {
167         case 0:
168                 status = ORIENTATION_STATUS_PORTRAIT;
169                 break;
170         case 270:
171                 status = ORIENTATION_STATUS_LANDSCAPE;
172                 break;
173         case 180:
174                 status = ORIENTATION_STATUS_PORTRAIT_REVERSE;
175                 break;
176         case 90:
177                 status = ORIENTATION_STATUS_LANDSCAPE_REVERSE;
178                 break;
179         default:
180                 break;
181         }
182
183         __status = status;
184
185         FireEvent(status);
186         pImpl->Invalidate(true);
187 }
188
189 void
190 _ImeOrientationAgent::FireEvent(OrientationStatus status)
191 {
192         ClearLastResult();
193
194         _ControlManager* pCoreManager = _ControlManager::GetInstance();
195         SysAssert(pCoreManager);
196
197         _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
198         if (!pImpl)
199         {
200                 return;
201         }
202
203         _ControlOrientation coreOrientation =
204                 (status == ORIENTATION_STATUS_PORTRAIT || status == ORIENTATION_STATUS_PORTRAIT_REVERSE) ?
205                 _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
206
207         _ControlImplManager* pImplManager = _ControlImplManager::GetInstance();
208         SysAssert(pImplManager);
209
210         // Core
211         pCoreManager->SetOrientation(coreOrientation);
212         pImplManager->SetOrientationStatus(status);
213         pImpl->GetCore().ChangeLayout(coreOrientation);
214
215         // Public
216         IEventArg* pArg = _PublicOrientationEvent::CreateOrientationEventArgN(*__pPublicEvent->GetSource(), status);
217         __pPublicEvent->Fire(*pArg);
218 }
219
220 }} // Tizen::Ui