2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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
9 // http://floralicense.org/license/
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.
19 * @file FUi_OrientationAgent.cpp
20 * @brief This is the implementation file for the _OrientationAgent class.
23 #include <unique_ptr.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseColArrayList.h>
27 #include "FUi_OrientationAgent.h"
28 #include "FUi_ControlManager.h"
29 #include "FUi_ControlImplManager.h"
30 #include "FUi_PublicOrientationEvent.h"
31 #include "FUi_ControlImpl.h"
32 #include "FUi_Window.h"
33 #include "FUiCtrl_FormImpl.h"
34 #include "FUiCtrl_FrameImpl.h"
35 #include "FUiCtrl_Frame.h"
36 #include "FUiCtrl_Form.h"
37 #include "FUi_EcoreEvasMgr.h"
38 #include "FUi_EcoreEvas.h"
39 #include "FUi_ControlManager.h"
40 #include "FUi_UiNotificationEvent.h"
41 #include "FUi_UiEventManager.h"
42 #include "FUi_TouchManager.h"
45 using namespace Tizen::Base;
46 using namespace Tizen::Base::Collection;
47 using namespace Tizen::Base::Runtime;
48 using namespace Tizen::Ui::Controls;
49 using namespace Tizen::Graphics;
53 const wchar_t* _REQUEST_ORIENTATION_EVENT = L"RequestOrientationEvent";
56 namespace Tizen { namespace Ui {
59 _OrientationAgent::CreateInstanceN(Control& publicControl)
61 _OrientationAgent* pAgent = new (std::nothrow) _OrientationAgent(publicControl);
62 SysTryReturn(NID_UI, pAgent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
64 result r = GetLastResult();
65 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
67 SetLastResult(E_SUCCESS);
76 _OrientationAgent::_OrientationAgent(Control& publicControl)
77 : __publicControl(publicControl)
78 , __pPublicEvent(null)
79 , __mode(ORIENTATION_PORTRAIT)
80 , __status(ORIENTATION_STATUS_PORTRAIT)
81 , __tempStatus(ORIENTATION_STATUS_PORTRAIT)
82 , __firePublicEvent(false)
83 , __statusChanged(false)
84 , __updateStatus(true)
87 _PublicOrientationEvent* pPublicEvent = _PublicOrientationEvent::CreateInstanceN(publicControl);
89 result r = GetLastResult();
90 SysTryReturnVoidResult(NID_UI, pPublicEvent, r, "[%s] Propagating.", GetErrorMessage(r));
92 __pPublicEvent = pPublicEvent;
94 SetLastResult(E_SUCCESS);
97 _OrientationAgent::~_OrientationAgent(void)
101 delete __pPublicEvent;
102 __pPublicEvent = null;
107 _OrientationAgent::AddListener(IOrientationEventListener& listener)
109 result r = __pPublicEvent->AddListener(listener);
110 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
112 SetLastResult(E_SUCCESS);
116 _OrientationAgent::RemoveListener(IOrientationEventListener& listener)
118 result r = __pPublicEvent->RemoveListener(listener);
119 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
121 SetLastResult(E_SUCCESS);
125 _OrientationAgent::GetMode(void) const
131 _OrientationAgent::GetStatus(void) const
137 _OrientationAgent::SetMode(Orientation mode)
139 SysTryReturnVoidResult(NID_UI, mode != ORIENTATION_NONE, E_INVALID_ARG, "[E_INVALID_ARG] A specified input parameter is invalid.");
141 SetLastResult(E_SUCCESS);
153 _OrientationAgent::Update(bool draw)
155 // Update orientation status(Not Auto-mode)
156 // Request rotation to window manager -> async -> Update VEs
157 // Window(not rotation) -> sync -> UpdateVEs
159 SysLog(NID_UI, "[WM ROTATION][AGENT 0x%x] ---------- Update : START ----------", this);
161 _ControlImplManager* pImplManager = _ControlImplManager::GetInstance();
162 SysAssert(pImplManager);
164 _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
170 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
176 bool autoMode = false;
178 if ((__mode == ORIENTATION_AUTOMATIC) || (__mode == ORIENTATION_AUTOMATIC_FOUR_DIRECTION))
183 // if (autoMode == false)
186 // Update orientation status
188 // Fire orientation event
190 // Set preffered rotation
192 _Window* pWindow = pImpl->GetCore().GetRootWindow();
193 NativeWindowHandle handle = 0;
196 handle = pWindow->GetNativeHandle();
199 OrientationStatus status = pImplManager->GetOrientationStatus(__mode);
200 SysLog(NID_UI, "[WM ROTATION][AGENT 0x%x][WIN 0x%x] Update : __mode(%d) -> status(%d)", this, handle, __mode, status);
202 if (__updateStatus == true)
204 __statusChanged = false;
205 if (__status != status)
207 __statusChanged = true;
208 __updateStatus = false;
214 pEcoreEvas->AllowSetWindowBounds(false);
216 pEcoreEvas->AllowSetWindowBounds(true);
218 // For the form to be made by Ui-Builder
219 if ((draw == true) && (__statusChanged == true))
221 _ControlOrientation coreOrientation =
222 (status == ORIENTATION_STATUS_PORTRAIT || status == ORIENTATION_STATUS_PORTRAIT_REVERSE) ?
223 _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
226 bool exist = pImpl->GetBuilderBounds(coreOrientation, temp);
229 pImpl->Invalidate(true);
233 // Despite not changing status, it needs to rotate screen.
234 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(__publicControl);
235 pImplManager->RotateScreen(pControlImpl, status);
237 _Window* pRootWindow = pImpl->GetCore().GetRootWindow();
240 SetRotation(*pRootWindow, __mode);
246 // Set preffered rotation
248 // _Window* pRootWindow = pImpl->GetCore().GetRootWindow();
251 // SetRotation(*pRootWindow, __mode);
257 SysLog(NID_UI, "[WM ROTATION][AGENT 0x%x] ---------- Update : END ----------", this);
261 _OrientationAgent::UpdateOrientation(void)
263 // Get window rotation
265 // Fire orientation event
266 // Update window bounds
269 SysLog(NID_UI, "[WM ROTATION][AGENT 0x%x] ---------- UpdateOrientation : START ----------", this);
271 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
277 _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
283 _Window* pRootWindow = pImpl->GetCore().GetRootWindow();
289 int rotation = pEcoreEvas->GetWindowRotation(*pRootWindow);
290 OrientationStatus status = ORIENTATION_STATUS_NONE;
294 status = ORIENTATION_STATUS_PORTRAIT;
297 status = ORIENTATION_STATUS_LANDSCAPE;
300 status = ORIENTATION_STATUS_PORTRAIT_REVERSE;
303 status = ORIENTATION_STATUS_LANDSCAPE_REVERSE;
309 if (__updateStatus == true)
311 __statusChanged = false;
312 if (__status != status)
314 __statusChanged = true;
315 __updateStatus = false;
321 pEcoreEvas->AllowSetWindowBounds(false);
322 FireEvent(status, true);
323 pEcoreEvas->AllowSetWindowBounds(true);
325 // For the form to be made by Ui-Builder
326 if ((__draw == true) && (__statusChanged == true))
328 _ControlOrientation coreOrientation =
329 (status == ORIENTATION_STATUS_PORTRAIT || status == ORIENTATION_STATUS_PORTRAIT_REVERSE) ?
330 _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
333 bool exist = pImpl->GetBuilderBounds(coreOrientation, temp);
336 pImpl->Invalidate(true);
340 pEcoreEvas->RotateWindow(*pRootWindow, rotation, false);
342 if (__statusChanged == true)
344 _TouchManager* pTouchManager = _TouchManager::GetInstance();
347 pTouchManager->SetTouchCanceled(null);
351 pImpl->Invalidate(true);
353 Rectangle bounds = pRootWindow->GetBounds();
354 SysLog(NID_UI, "[WM ROTATION][AGENT 0x%x][WIN 0x%x, ROT %d, %d, %d, %d, %d] Update Orientation.", this, pRootWindow->GetNativeHandle(), rotation, bounds.x, bounds.y, bounds.width, bounds.height);
356 SysLog(NID_UI, "[WM ROTATION][AGENT 0x%x] ---------- UpdateOrientation : END ----------", this);
360 _OrientationAgent::RequestOrientationEvent(void)
364 _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
365 SysTryReturnVoidResult(NID_UI, pImpl, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
367 unique_ptr<ArrayList> pEventArgs(new (std::nothrow) ArrayList());
368 SysTryReturnVoidResult(NID_UI, pEventArgs, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
369 pEventArgs->Construct();
371 unique_ptr<String> pString(new (std::nothrow) Tizen::Base::String(_REQUEST_ORIENTATION_EVENT));
372 SysTryReturnVoidResult(NID_UI, pString, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
374 pEventArgs->Add(*(pString.get()));
376 _UiNotificationEvent event(pImpl->GetCore().GetHandle(), pEventArgs.get());
378 result r = _UiEventManager::GetInstance()->PostEvent(event);
379 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
382 pEventArgs.release();
386 _OrientationAgent::FireOrientationEvent(void)
388 if (__firePublicEvent)
393 __firePublicEvent = true;
395 SysLog(NID_UI, "Fire the orientation event.");
399 IEventArg* pArg = _PublicOrientationEvent::CreateOrientationEventArgN(*__pPublicEvent->GetSource(), __status);
400 __pPublicEvent->Fire(*pArg);
402 __updateStatus = true;
407 _OrientationAgent::FireEvent(OrientationStatus status, bool callback)
411 _ControlManager* pCoreManager = _ControlManager::GetInstance();
412 SysAssert(pCoreManager);
414 _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
420 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
426 _ControlOrientation coreOrientation =
427 (status == ORIENTATION_STATUS_PORTRAIT || status == ORIENTATION_STATUS_PORTRAIT_REVERSE) ?
428 _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
430 _ControlImplManager* pImplManager = _ControlImplManager::GetInstance();
431 SysAssert(pImplManager);
434 pCoreManager->SetOrientation(coreOrientation);
435 pImplManager->SetOrientationStatus(status);
436 pImpl->GetCore().ChangeLayout(coreOrientation);
438 int owneeCount = pImpl->GetCore().GetOwneeCount();
439 for (int i = 0; i < owneeCount; i++)
441 _Window* pOwnee = pImpl->GetCore().GetOwnee(i);
444 if (pOwnee->GetWindowType() == _WINDOW_TYPE_VE)
446 pOwnee->ChangeLayout(coreOrientation);
450 if (!((callback == true) && (pOwnee->IsRotationSynchronized() == true)))
452 pOwnee->ChangeLayout(coreOrientation);
455 if (pOwnee->GetVisibleState() == true)
457 pEcoreEvas->SetOwner(*pOwnee, pImpl->GetCore());
463 _Control* pParent = pImpl->GetCore().GetParent();
466 int owneeCount = pParent->GetOwneeCount();
467 for (int i = 0; i < owneeCount; i++)
469 _Window* pOwnee = pParent->GetOwnee(i);
472 if (pOwnee->GetWindowType() == _WINDOW_TYPE_VE)
474 pOwnee->ChangeLayout(coreOrientation);
478 if (!((callback == true) && (pOwnee->IsRotationSynchronized() == true)))
480 pOwnee->ChangeLayout(coreOrientation);
483 if (pOwnee->GetVisibleState() == true)
485 pEcoreEvas->SetOwner(*pOwnee, *pParent);
493 if (__firePublicEvent && __statusChanged)
495 IEventArg* pArg = _PublicOrientationEvent::CreateOrientationEventArgN(*__pPublicEvent->GetSource(), status);
496 __pPublicEvent->Fire(*pArg);
498 __updateStatus = true;
503 _OrientationAgent::SetRotation(const _Window& window, Orientation orientation)
505 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
513 case ORIENTATION_PORTRAIT:
514 pEcoreEvas->SetWindowPreferredRotation(window, 0);
516 case ORIENTATION_LANDSCAPE:
517 pEcoreEvas->SetWindowPreferredRotation(window, 270);
519 case ORIENTATION_PORTRAIT_REVERSE:
520 pEcoreEvas->SetWindowPreferredRotation(window, 180);
522 case ORIENTATION_LANDSCAPE_REVERSE:
523 pEcoreEvas->SetWindowPreferredRotation(window, 90);
525 case ORIENTATION_AUTOMATIC:
527 pEcoreEvas->SetWindowPreferredRotation(window, -1);
528 int autoRotation[3] = {0, 90, 270};
529 pEcoreEvas->SetWindowAvailabledRotation(window, autoRotation, 3);
533 case ORIENTATION_AUTOMATIC_FOUR_DIRECTION:
535 pEcoreEvas->SetWindowPreferredRotation(window, -1);
536 int autoFourRotation[4] = {0, 90, 180, 270};
537 pEcoreEvas->SetWindowAvailabledRotation(window, autoFourRotation, 4);