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.
18 * @file FUi_OrientationAgent.cpp
19 * @brief This is the implementation file for the _OrientationAgent class.
21 #include <FBaseSysLog.h>
22 #include "FUi_OrientationAgent.h"
23 #include "FUi_ControlManager.h"
24 #include "FUi_ControlImplManager.h"
25 #include "FUi_PublicOrientationEvent.h"
26 #include "FUi_ControlImpl.h"
27 #include "FUi_Window.h"
28 #include "FUiCtrl_FormImpl.h"
29 #include "FUiCtrl_FrameImpl.h"
30 #include "FUiCtrl_Frame.h"
31 #include "FUi_EcoreEvasMgr.h"
32 #include "FUi_EcoreEvas.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Graphics;
39 namespace Tizen { namespace Ui {
42 _OrientationAgent::CreateInstanceN(Control& publicControl)
44 _OrientationAgent* pAgent = new (std::nothrow) _OrientationAgent(publicControl);
45 SysTryReturn(NID_UI, pAgent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
47 result r = GetLastResult();
48 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
50 SetLastResult(E_SUCCESS);
59 _OrientationAgent::_OrientationAgent(Control& publicControl)
60 : __publicControl(publicControl)
61 , __pPublicEvent(null)
62 , __mode(ORIENTATION_PORTRAIT)
63 , __status(ORIENTATION_STATUS_PORTRAIT)
64 , __firePublicEvent(false)
65 , __statusChanged(false)
66 , __updateStatus(true)
68 _PublicOrientationEvent* pPublicEvent = _PublicOrientationEvent::CreateInstanceN(publicControl);
70 result r = GetLastResult();
71 SysTryReturnVoidResult(NID_UI, pPublicEvent, r, "[%s] Propagating.", GetErrorMessage(r));
73 __pPublicEvent = pPublicEvent;
75 SetLastResult(E_SUCCESS);
78 _OrientationAgent::~_OrientationAgent(void)
82 delete __pPublicEvent;
83 __pPublicEvent = null;
88 _OrientationAgent::AddListener(IOrientationEventListener& listener)
90 result r = __pPublicEvent->AddListener(listener);
91 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
93 SetLastResult(E_SUCCESS);
97 _OrientationAgent::RemoveListener(IOrientationEventListener& listener)
99 result r = __pPublicEvent->RemoveListener(listener);
100 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
102 SetLastResult(E_SUCCESS);
106 _OrientationAgent::GetMode(void) const
112 _OrientationAgent::GetStatus(void) const
118 _OrientationAgent::SetMode(Orientation mode)
120 SysTryReturnVoidResult(NID_UI, mode != ORIENTATION_NONE, E_INVALID_ARG, "[E_INVALID_ARG] A specified input parameter is invalid.");
122 SetLastResult(E_SUCCESS);
134 _OrientationAgent::Update(bool draw)
136 _ControlImplManager* pImplManager = _ControlImplManager::GetInstance();
137 SysAssert(pImplManager);
139 _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
145 OrientationStatus status = pImplManager->GetOrientationStatus(__mode);
147 if (__updateStatus == true)
149 __statusChanged = false;
150 if (__status != status)
152 __statusChanged = true;
153 __updateStatus = false;
159 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
165 pEcoreEvas->AllowSetWindowBounds(false);
167 pEcoreEvas->AllowSetWindowBounds(true);
169 // For the form to be made by Ui-Builder
170 if ((draw == true) && (__statusChanged == true))
172 _ControlOrientation coreOrientation =
173 (status == ORIENTATION_STATUS_PORTRAIT || status == ORIENTATION_STATUS_PORTRAIT_REVERSE) ?
174 _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
177 bool exist = pImpl->GetBuilderBounds(coreOrientation, temp);
180 pImpl->Invalidate(true);
184 // Despite not changing status, it needs to rotate screen.
185 #if !defined(MULTI_WINDOW)
186 pImplManager->RotateScreen(status);
188 _ControlImpl* pControlImpl = _ControlImpl::GetInstance(__publicControl);
189 pImplManager->RotateScreen(pControlImpl, status);
194 _OrientationAgent::FireOrientationEvent(void)
196 if (__firePublicEvent)
201 __firePublicEvent = true;
205 IEventArg* pArg = _PublicOrientationEvent::CreateOrientationEventArgN(*__pPublicEvent->GetSource(), __status);
206 __pPublicEvent->Fire(*pArg);
208 __updateStatus = true;
213 _OrientationAgent::FireEvent(OrientationStatus status)
217 _ControlManager* pCoreManager = _ControlManager::GetInstance();
218 SysAssert(pCoreManager);
220 _ControlImpl* pImpl = _ControlImpl::GetInstance(__publicControl);
226 _ControlOrientation coreOrientation =
227 (status == ORIENTATION_STATUS_PORTRAIT || status == ORIENTATION_STATUS_PORTRAIT_REVERSE) ?
228 _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
230 _ControlImplManager* pImplManager = _ControlImplManager::GetInstance();
231 SysAssert(pImplManager);
234 pCoreManager->SetOrientation(coreOrientation);
235 pImplManager->SetOrientationStatus(status);
236 pImpl->GetCore().ChangeLayout(coreOrientation);
239 int owneeCount = pImpl->GetCore().GetOwneeCount();
240 for (int i = 0; i < owneeCount; i++)
242 _Window* pOwnee = pImpl->GetCore().GetOwnee(i);
246 pOwnee->ChangeLayout(coreOrientation);
251 if (__firePublicEvent && __statusChanged)
253 IEventArg* pArg = _PublicOrientationEvent::CreateOrientationEventArgN(*__pPublicEvent->GetSource(), status);
254 __pPublicEvent->Fire(*pArg);
256 __updateStatus = true;