2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
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>
24 #include <FBaseSysLog.h>
25 #include <FBaseColArrayList.h>
26 #include "FUi_OrientationAgent.h"
27 #include "FUi_ControlManager.h"
28 #include "FUi_ControlImplManager.h"
29 #include "FUi_PublicOrientationEvent.h"
30 #include "FUi_ControlImpl.h"
31 #include "FUi_Window.h"
32 #include "FUiCtrl_FormImpl.h"
33 #include "FUiCtrl_FrameImpl.h"
34 #include "FUiCtrl_Frame.h"
35 #include "FUiCtrl_Form.h"
36 #include "FUi_EcoreEvasMgr.h"
37 #include "FUi_EcoreEvas.h"
38 #include "FUi_ControlManager.h"
39 #include "FUi_UiNotificationEvent.h"
40 #include "FUi_UiEventManager.h"
43 using namespace Tizen::Base;
44 using namespace Tizen::Base::Collection;
45 using namespace Tizen::Base::Runtime;
46 using namespace Tizen::Ui::Controls;
47 using namespace Tizen::Graphics;
49 namespace Tizen { namespace Ui {
51 const String _REQUEST_ORIENTATION_EVENT = L"RequestOrientationEvent";
54 _OrientationAgent::CreateInstanceN(Control& publicControl)
56 _OrientationAgent* pAgent = new (std::nothrow) _OrientationAgent(publicControl);
57 SysTryReturn(NID_UI, pAgent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
59 result r = GetLastResult();
60 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
62 SetLastResult(E_SUCCESS);
71 _OrientationAgent::_OrientationAgent(Control& publicControl)
72 : __publicControl(publicControl)
73 , __pPublicEvent(null)
74 , __mode(ORIENTATION_PORTRAIT)
75 , __status(ORIENTATION_STATUS_PORTRAIT)
76 , __firePublicEvent(false)
77 , __statusChanged(false)
78 , __updateStatus(true)
80 _PublicOrientationEvent* pPublicEvent = _PublicOrientationEvent::CreateInstanceN(publicControl);
82 result r = GetLastResult();
83 SysTryReturnVoidResult(NID_UI, pPublicEvent, r, "[%s] Propagating.", GetErrorMessage(r));
85 __pPublicEvent = pPublicEvent;
87 SetLastResult(E_SUCCESS);
90 _OrientationAgent::~_OrientationAgent(void)
94 delete __pPublicEvent;
95 __pPublicEvent = null;
100 _OrientationAgent::AddListener(IOrientationEventListener& listener)
102 result r = __pPublicEvent->AddListener(listener);
103 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
105 SetLastResult(E_SUCCESS);
109 _OrientationAgent::RemoveListener(IOrientationEventListener& listener)
111 result r = __pPublicEvent->RemoveListener(listener);
112 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
114 SetLastResult(E_SUCCESS);
118 _OrientationAgent::GetMode(void) const
124 _OrientationAgent::GetStatus(void) const
130 _OrientationAgent::SetMode(Orientation mode)
132 SysTryReturnVoidResult(NID_UI, mode != ORIENTATION_NONE, E_INVALID_ARG, "[E_INVALID_ARG] A specified input parameter is invalid.");
134 SetLastResult(E_SUCCESS);
146 _OrientationAgent::Update(bool draw)
148 _ControlImplManager* pImplManager = _ControlImplManager::GetInstance();
149 SysAssert(pImplManager);
151 _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
157 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
163 _Form* pForm = dynamic_cast<_Form*>(&(pImpl->GetCore()));
166 _Control* pParent = pForm->GetParent();
170 int index = pParent->GetChildIndex(*pForm);
171 int childCount = pParent->GetChildCount();
173 if (index == (childCount - 1))
175 _Window* pWindow = pForm->GetRootWindow();
178 if ((__mode == ORIENTATION_AUTOMATIC) || (__mode == ORIENTATION_AUTOMATIC_FOUR_DIRECTION))
180 pEcoreEvas->SetWindowOrientationEnabled(*pWindow, true);
181 pWindow->SetOrientationEnabled(true);
185 pEcoreEvas->SetWindowOrientationEnabled(*pWindow, false);
186 pWindow->SetOrientationEnabled(false);
194 _Frame* pFrame = dynamic_cast<_Frame*>(&(pImpl->GetCore()));
197 int childCount = pFrame->GetChildCount();
200 _Window* pCurrentFrame = _ControlManager::GetInstance()->GetCurrentFrame();
201 if (pCurrentFrame == pFrame)
203 if ((__mode == ORIENTATION_AUTOMATIC) || (__mode == ORIENTATION_AUTOMATIC_FOUR_DIRECTION))
205 pEcoreEvas->SetWindowOrientationEnabled(*pFrame, true);
206 pFrame->SetOrientationEnabled(true);
210 pEcoreEvas->SetWindowOrientationEnabled(*pFrame, false);
211 pFrame->SetOrientationEnabled(false);
218 OrientationStatus status = pImplManager->GetOrientationStatus(__mode);
220 if (__updateStatus == true)
222 __statusChanged = false;
223 if (__status != status)
225 __statusChanged = true;
226 __updateStatus = false;
232 pEcoreEvas->AllowSetWindowBounds(false);
234 pEcoreEvas->AllowSetWindowBounds(true);
236 // For the form to be made by Ui-Builder
237 if ((draw == true) && (__statusChanged == true))
239 _ControlOrientation coreOrientation =
240 (status == ORIENTATION_STATUS_PORTRAIT || status == ORIENTATION_STATUS_PORTRAIT_REVERSE) ?
241 _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
244 bool exist = pImpl->GetBuilderBounds(coreOrientation, temp);
247 pImpl->Invalidate(true);
251 // Despite not changing status, it needs to rotate screen.
252 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(__publicControl);
253 pImplManager->RotateScreen(pControlImpl, status);
257 _OrientationAgent::RequestOrientationEvent(void)
261 _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
262 SysTryReturnVoidResult(NID_UI, pImpl, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
264 unique_ptr<ArrayList> pEventArgs(new (std::nothrow) ArrayList());
265 SysTryReturnVoidResult(NID_UI, pEventArgs, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
266 pEventArgs->Construct();
268 unique_ptr<String> pString(new (std::nothrow) Tizen::Base::String(_REQUEST_ORIENTATION_EVENT));
269 SysTryReturnVoidResult(NID_UI, pString, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
271 pEventArgs->Add(*(pString.get()));
273 _UiNotificationEvent event(pImpl->GetCore().GetHandle(), pEventArgs.get());
275 result r = _UiEventManager::GetInstance()->PostEvent(event);
276 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
279 pEventArgs.release();
283 _OrientationAgent::FireOrientationEvent(void)
285 if (__firePublicEvent)
290 __firePublicEvent = true;
292 SysLog(NID_UI, "Fire the orientation event.");
296 IEventArg* pArg = _PublicOrientationEvent::CreateOrientationEventArgN(*__pPublicEvent->GetSource(), __status);
297 __pPublicEvent->Fire(*pArg);
299 __updateStatus = true;
304 _OrientationAgent::FireEvent(OrientationStatus status)
308 _ControlManager* pCoreManager = _ControlManager::GetInstance();
309 SysAssert(pCoreManager);
311 _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
317 _ControlOrientation coreOrientation =
318 (status == ORIENTATION_STATUS_PORTRAIT || status == ORIENTATION_STATUS_PORTRAIT_REVERSE) ?
319 _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
321 _ControlImplManager* pImplManager = _ControlImplManager::GetInstance();
322 SysAssert(pImplManager);
325 pCoreManager->SetOrientation(coreOrientation);
326 pImplManager->SetOrientationStatus(status);
327 pImpl->GetCore().ChangeLayout(coreOrientation);
330 int owneeCount = pImpl->GetCore().GetOwneeCount();
331 for (int i = 0; i < owneeCount; i++)
333 _Window* pOwnee = pImpl->GetCore().GetOwnee(i);
337 pOwnee->ChangeLayout(coreOrientation);
342 if (__firePublicEvent && __statusChanged)
344 IEventArg* pArg = _PublicOrientationEvent::CreateOrientationEventArgN(*__pPublicEvent->GetSource(), status);
345 __pPublicEvent->Fire(*pArg);
347 __updateStatus = true;