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 FUiCtrl_Indicator.cpp
19 * @brief This is the implementation file for the _Form class.
22 #include <FGrpRectangle.h>
23 #include <FGrp_CoordinateSystem.h>
24 #include <FUiAnim_VisualElementSurfaceImpl.h>
25 #include "FUiAnim_VisualElement.h"
26 #include "FUiAnim_VisualElementImpl.h"
27 #include "FUiAnim_EflNode.h"
28 #include "FUi_EcoreEvasMgr.h"
29 #include "FUi_EcoreEvas.h"
30 #include "FUi_ResourceManager.h"
31 #include "FUi_Window.h"
32 #include "FUiCtrl_Form.h"
33 #include "FUiCtrl_Indicator.h"
34 #include "FUiCtrl_IndicatorManager.h"
36 using namespace Tizen::Base::Runtime;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Animations;
41 namespace Tizen { namespace Ui { namespace Controls
44 static const char* pPortraitSvcName = "elm_indicator_portrait";
45 static const char* pLandScapeSvcName = "elm_indicator_landscape";
46 static const char* pPortPublicKey = "__Plug_Ecore_Evas_Port";
47 static const char* pLandPublicKey = "__Plug_Ecore_Evas_Land";
48 static const char* pIndicatorKey = "Inidcator_Manager_Object";
49 static const int CONNECTION_INTERVAL = 1000;
52 _Indicator::CreateIndicator(void)
54 _Indicator* pIndicator = new (std::nothrow) _Indicator;
55 SysTryReturn(NID_UI_CTRL, pIndicator, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
56 SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
63 _Indicator::_Indicator(void)
64 : __pPortraitIndicatorEvasObject(null)
65 , __pLandscapeIndicatorEvasObject(null)
66 , __pConnectionTimer(null)
67 , __pPortraitSurface(null)
68 , __pLandScapeSurface(null)
69 , __pCurrentSurface(null)
70 , __pVisualElement(null)
72 , __opacity(_INDICATOR_OPACITY_OPAQUE)
74 SetBackgroundColor(0xff343432);
79 _Indicator::~_Indicator(void)
81 if (__pConnectionTimer != null)
83 __pConnectionTimer->Cancel();
84 delete __pConnectionTimer;
85 __pConnectionTimer = null;
88 __pPortraitSurface = null;
89 __pLandScapeSurface = null;
90 __pCurrentSurface = null;
94 _Indicator::SetIndicatorShowState(bool state)
98 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
99 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
101 _Window* pWindow = GetRootWindow();
105 r = pEcoreEvas->SetIndicatorShowState(*pWindow, state);
108 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
112 SetVisibleState(state);
116 SetIndicatorOpacity(__opacity);
123 _Indicator::SetIndicatorOpacity(_IndicatorOpacity opacity)
125 result r = E_SUCCESS;
127 if (opacity == _INDICATOR_OPACITY_OPAQUE)
129 SetBackgroundColor(0xff343432);
131 else if (opacity == _INDICATOR_OPACITY_TRANSLUCENT)
133 SetBackgroundColor(0x7f000000);
142 _Indicator::GetIndicatorShowState(void) const
148 _Indicator::GetIndicatorOpacity(void) const
154 _Indicator::GetIndicatorBounds(void) const
156 const Dimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSize();
157 const Dimension landscapeSize = Dimension(portraitSize.height, portraitSize.width);
159 _ControlOrientation orientation = GetOrientation();
161 Rectangle indicatorbounds(0, 0, 0, 0);
163 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
165 indicatorbounds.width = portraitSize.width;
169 indicatorbounds.width = landscapeSize.width;
171 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorbounds.height);
173 _CoordinateSystem* pCoordSystem = _CoordinateSystem::GetInstance();
174 SysTryReturn(NID_UI_CTRL, pCoordSystem, Rectangle(-1, -1, -1, -1), E_SYSTEM, "[E_SYSTEM] Coordinate system load failed.");
176 _ICoordinateSystemTransformer* pXformer = pCoordSystem->GetTransformer();
177 SysTryReturn(NID_UI_CTRL, pXformer, Rectangle(-1, -1, -1, -1), E_SYSTEM, "[E_SYSTEM] Coordinate system load failed.");
179 indicatorbounds = pXformer->Transform(indicatorbounds);
181 return indicatorbounds;
185 _Indicator::AddEvasObject(_Form* pForm)
187 result r = E_SUCCESS;
189 _Window* pWindow = GetRootWindow();
190 SysTryReturn(NID_UI_CTRL, pWindow, null, E_INVALID_STATE, "[E_INVALID_STATE] Indicator is not attached main tree.");
192 __pPortraitSurface = _IndicatorManager::GetInstance()->GetSurface(pWindow, _INDICATOR_ORIENTATION_PORTRAIT, pForm);
193 SysTryReturn(NID_UI_CTRL, __pPortraitSurface, null, E_SYSTEM, "[E_SYSTEM] Indicator can not create the surface.");
194 __pLandScapeSurface = _IndicatorManager::GetInstance()->GetSurface(pWindow, _INDICATOR_ORIENTATION_LANDSCAPE, pForm);
195 SysTryReturn(NID_UI_CTRL, __pLandScapeSurface, null, E_SYSTEM, "[E_SYSTEM] Indicator can not create the surface.");
196 __pPortraitIndicatorEvasObject = _IndicatorManager::GetInstance()->GetEvasObject(pWindow, pForm, _INDICATOR_ORIENTATION_PORTRAIT);
197 SysTryReturn(NID_UI_CTRL, __pPortraitIndicatorEvasObject, null, E_SYSTEM, "[E_SYSTEM] Indicator can not get the Evas_Object.");
198 __pLandscapeIndicatorEvasObject = _IndicatorManager::GetInstance()->GetEvasObject(pWindow, pForm, _INDICATOR_ORIENTATION_LANDSCAPE);
199 SysTryReturn(NID_UI_CTRL, __pLandscapeIndicatorEvasObject, null, E_SYSTEM, "[E_SYSTEM] Indicator can not get the Evas_Object.");
201 _ControlOrientation orientation = GetOrientation();
202 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
204 __pCurrentSurface = __pPortraitSurface;
208 __pCurrentSurface = __pLandScapeSurface;
211 if (!__pVisualElement)
213 __pVisualElement = new (std::nothrow) _VisualElement;
214 SysTryReturn(NID_UI_CTRL, __pVisualElement, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
215 r = __pVisualElement->Construct();
216 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, E_SYSTEM, "[E_SYSTEM] System error occurred.");
217 __pVisualElement->SetImplicitAnimationEnabled(false);
218 __pVisualElement->SetShowState(true);
220 _VisualElement* pIndicatorVisualElement = GetVisualElement();
221 pIndicatorVisualElement->AttachChild(*__pVisualElement);
224 r = SetSurface(__pCurrentSurface);
225 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, GetErrorMessage(r));
227 Ecore_Evas *pEe = ecore_evas_object_ecore_evas_get(__pPortraitIndicatorEvasObject);
228 SysTryReturn(NID_UI_CTRL, pEe, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to get evas.");
230 ecore_evas_data_set(pEe, pPortPublicKey, __pPortraitIndicatorEvasObject);
231 ecore_evas_data_set(pEe, pLandPublicKey, __pLandscapeIndicatorEvasObject);
232 ecore_evas_data_set(pEe, pIndicatorKey, this);
233 ecore_evas_callback_delete_request_set(pEe, _Indicator::OnDisconnected);
239 _Indicator::DeleteEvasObject(void)
241 result r = E_SUCCESS;
243 _Window* pWindow = GetRootWindow();
244 SysTryReturn(NID_UI_CTRL, pWindow, null, E_INVALID_STATE, "[E_INVALID_STATE] Indicator is not attached main tree.");
246 r = _IndicatorManager::GetInstance()->ReleaseSurface(pWindow, _INDICATOR_ORIENTATION_PORTRAIT, __pPortraitSurface);
247 r = _IndicatorManager::GetInstance()->ReleaseSurface(pWindow, _INDICATOR_ORIENTATION_LANDSCAPE, __pLandScapeSurface);
249 r = SetSurface(null);
251 __pPortraitIndicatorEvasObject = null;
252 __pLandscapeIndicatorEvasObject = null;
253 __pPortraitSurface = null;
254 __pLandScapeSurface = null;
255 __pCurrentSurface = null;
261 _Indicator::SetSurface(VisualElementSurface* pSurface)
263 result r = E_SUCCESS;
265 if (__pVisualElement)
267 r = __pVisualElement->SetBounds(FloatRectangle(0, 0, GetSize().width, GetSize().height));
268 r = __pVisualElement->SetSurface(pSurface);
275 _Indicator::OnChangeLayout(_ControlOrientation orientation)
277 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
279 __pCurrentSurface = __pPortraitSurface;
280 SetSurface(__pCurrentSurface);
282 evas_object_smart_member_del(__pLandscapeIndicatorEvasObject);
283 evas_object_show(__pPortraitIndicatorEvasObject);
284 evas_object_hide(__pLandscapeIndicatorEvasObject);
288 __pCurrentSurface = __pLandScapeSurface;
289 SetSurface(__pCurrentSurface);
291 evas_object_smart_member_del(__pPortraitIndicatorEvasObject);
292 evas_object_show(__pLandscapeIndicatorEvasObject);
293 evas_object_hide(__pPortraitIndicatorEvasObject);
298 _Indicator::OnAttachedToMainTree(void)
300 result r = E_SUCCESS;
302 if (__pCurrentSurface)
304 r = SetSurface(__pCurrentSurface);
311 _Indicator::OnTimerExpired(Timer& timer)
313 Eina_Bool result = EINA_TRUE;
315 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
316 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
318 result = ecore_evas_extn_plug_connect(__pPortraitIndicatorEvasObject, pPortraitSvcName, 0, EINA_FALSE);
322 result = ecore_evas_extn_plug_connect(__pLandscapeIndicatorEvasObject, pLandScapeSvcName, 0, EINA_FALSE);
325 if (result == EINA_TRUE)
331 timer.Start(CONNECTION_INTERVAL);
336 _Indicator::OnDisconnected(Ecore_Evas *pEe)
338 _Indicator* pIndicator = (_Indicator*)ecore_evas_data_get(pEe, pIndicatorKey);
339 SysTryReturnVoidResult(NID_UI_CTRL, pIndicator, E_SYSTEM, "[E_SYSTEM] Unable to get Indicator Object");
341 if (pIndicator->__pConnectionTimer == null)
343 pIndicator->__pConnectionTimer = new (std::nothrow) Timer;
344 if (pIndicator->__pConnectionTimer == null)
349 result r = pIndicator->__pConnectionTimer->Construct(*pIndicator);
352 delete pIndicator->__pConnectionTimer;
353 pIndicator->__pConnectionTimer = null;
359 pIndicator->__pConnectionTimer->Start(CONNECTION_INTERVAL);
362 }}} // Tizen::Ui::Controls