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_CoordinateSystemUtils.h"
32 #include "FUi_Window.h"
33 #include "FUiCtrl_Form.h"
34 #include "FUiCtrl_Indicator.h"
35 #include "FUiCtrl_IndicatorManager.h"
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Animations;
42 namespace Tizen { namespace Ui { namespace Controls
45 static const char* pPortraitSvcName = "elm_indicator_portrait";
46 static const char* pLandScapeSvcName = "elm_indicator_landscape";
47 static const char* pPortPublicKey = "__Plug_Ecore_Evas_Port";
48 static const char* pLandPublicKey = "__Plug_Ecore_Evas_Land";
49 static const char* pIndicatorKey = "Inidcator_Manager_Object";
50 static const int CONNECTION_INTERVAL = 1000;
53 _Indicator::CreateIndicator(void)
55 _Indicator* pIndicator = new (std::nothrow) _Indicator;
56 SysTryReturn(NID_UI_CTRL, pIndicator, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
57 SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
64 _Indicator::_Indicator(void)
65 : __pPortraitIndicatorEvasObject(null)
66 , __pLandscapeIndicatorEvasObject(null)
67 , __pConnectionTimer(null)
68 , __pPortraitVisualElement(null)
69 , __pLandscapeVisualElement(null)
70 , __pCurrentVisualElement(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;
90 _Indicator::SetIndicatorShowState(bool state, bool hide)
94 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
95 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
97 _Window* pWindow = GetRootWindow();
103 r = pEcoreEvas->SetIndicatorShowState(*pWindow, true);
107 r = pEcoreEvas->SetIndicatorShowState(*pWindow, state);
111 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
115 SetVisibleState(state);
119 SetIndicatorOpacity(__opacity);
126 _Indicator::SetIndicatorOpacity(_IndicatorOpacity opacity)
128 result r = E_SUCCESS;
130 if (opacity == _INDICATOR_OPACITY_OPAQUE)
132 SetBackgroundColor(0xff343432);
134 else if (opacity == _INDICATOR_OPACITY_TRANSLUCENT)
136 SetBackgroundColor(0x7f000000);
145 _Indicator::GetIndicatorShowState(void) const
151 _Indicator::GetIndicatorOpacity(void) const
157 _Indicator::GetIndicatorBounds(void) const
159 const Dimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSize();
160 const Dimension landscapeSize = Dimension(portraitSize.height, portraitSize.width);
162 _ControlOrientation orientation = GetOrientation();
164 Rectangle indicatorbounds(0, 0, 0, 0);
166 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
168 indicatorbounds.width = portraitSize.width;
172 indicatorbounds.width = landscapeSize.width;
174 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorbounds.height);
176 _CoordinateSystem* pCoordSystem = _CoordinateSystem::GetInstance();
177 SysTryReturn(NID_UI_CTRL, pCoordSystem, Rectangle(-1, -1, -1, -1), E_SYSTEM, "[E_SYSTEM] Coordinate system load failed.");
179 _ICoordinateSystemTransformer* pXformer = pCoordSystem->GetTransformer();
180 SysTryReturn(NID_UI_CTRL, pXformer, Rectangle(-1, -1, -1, -1), E_SYSTEM, "[E_SYSTEM] Coordinate system load failed.");
182 indicatorbounds = pXformer->Transform(indicatorbounds);
184 return indicatorbounds;
188 _Indicator::GetIndicatorBoundsF(void) const
190 const FloatDimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
191 const FloatDimension landscapeSize = FloatDimension(portraitSize.height, portraitSize.width);
193 _ControlOrientation orientation = GetOrientation();
195 FloatRectangle indicatorbounds(0.0f, 0.0f, 0.0f, 0.0f);
197 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
199 indicatorbounds.width = portraitSize.width;
203 indicatorbounds.width = landscapeSize.width;
205 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorbounds.height);
207 _CoordinateSystem* pCoordSystem = _CoordinateSystem::GetInstance();
208 SysTryReturn(NID_UI_CTRL, pCoordSystem, FloatRectangle(-1.0, -1.0, -1.0, -1.0), E_SYSTEM, "[E_SYSTEM] Coordinate system load failed.");
210 _ICoordinateSystemTransformer* pXformer = pCoordSystem->GetTransformer();
211 SysTryReturn(NID_UI_CTRL, pXformer, FloatRectangle(-1.0, -1.0, -1.0, -1.0), E_SYSTEM, "[E_SYSTEM] Coordinate system load failed.");
213 indicatorbounds = pXformer->Transform(indicatorbounds);
215 return indicatorbounds;
219 _Indicator::AddIndicatorObject(_Form* pForm)
221 result r = E_SUCCESS;
223 _Window* pWindow = GetRootWindow();
224 SysTryReturn(NID_UI_CTRL, pWindow, null, E_INVALID_STATE, "[E_INVALID_STATE] Indicator is not attached main tree.");
226 __pPortraitVisualElement = _IndicatorManager::GetInstance()->GetIndicatorVisualElement(pWindow, _INDICATOR_ORIENTATION_PORTRAIT, pForm);
227 SysTryReturn(NID_UI_CTRL, __pPortraitVisualElement, null, E_SYSTEM, "[E_SYSTEM] Indicator can not create the surface.");
228 __pLandscapeVisualElement = _IndicatorManager::GetInstance()->GetIndicatorVisualElement(pWindow, _INDICATOR_ORIENTATION_LANDSCAPE, pForm);
229 SysTryReturn(NID_UI_CTRL, __pLandscapeVisualElement, null, E_SYSTEM, "[E_SYSTEM] Indicator can not create the surface.");
230 __pPortraitIndicatorEvasObject = _IndicatorManager::GetInstance()->GetEvasObject(pWindow, pForm, _INDICATOR_ORIENTATION_PORTRAIT);
231 SysTryReturn(NID_UI_CTRL, __pPortraitIndicatorEvasObject, null, E_SYSTEM, "[E_SYSTEM] Indicator can not get the Evas_Object.");
232 __pLandscapeIndicatorEvasObject = _IndicatorManager::GetInstance()->GetEvasObject(pWindow, pForm, _INDICATOR_ORIENTATION_LANDSCAPE);
233 SysTryReturn(NID_UI_CTRL, __pLandscapeIndicatorEvasObject, null, E_SYSTEM, "[E_SYSTEM] Indicator can not get the Evas_Object.");
235 _ControlOrientation orientation = GetOrientation();
236 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
238 r = ChangeCurrentVisualElement(__pPortraitVisualElement);
242 r = ChangeCurrentVisualElement(__pLandscapeVisualElement);
245 Ecore_Evas *pEe = ecore_evas_object_ecore_evas_get(__pPortraitIndicatorEvasObject);
246 SysTryReturn(NID_UI_CTRL, pEe, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to get evas.");
248 ecore_evas_data_set(pEe, pPortPublicKey, __pPortraitIndicatorEvasObject);
249 ecore_evas_data_set(pEe, pLandPublicKey, __pLandscapeIndicatorEvasObject);
250 ecore_evas_data_set(pEe, pIndicatorKey, this);
251 ecore_evas_callback_delete_request_set(pEe, _Indicator::OnDisconnected);
257 _Indicator::DeleteIndicatorObject(void)
259 result r = E_SUCCESS;
261 _Window* pWindow = GetRootWindow();
262 SysTryReturn(NID_UI_CTRL, pWindow, null, E_INVALID_STATE, "[E_INVALID_STATE] Indicator is not attached main tree.");
264 r = _IndicatorManager::GetInstance()->ReleaseIndicatorVisualElement(pWindow, _INDICATOR_ORIENTATION_PORTRAIT, __pPortraitVisualElement);
265 r = _IndicatorManager::GetInstance()->ReleaseIndicatorVisualElement(pWindow, _INDICATOR_ORIENTATION_LANDSCAPE, __pLandscapeVisualElement);
267 _VisualElement* pIndicatorVisualElement = GetVisualElement();
268 if (__pPortraitVisualElement)
270 r = pIndicatorVisualElement->DetachChild(*__pPortraitVisualElement);
272 if (__pLandscapeVisualElement)
274 r = pIndicatorVisualElement->DetachChild(*__pLandscapeVisualElement);
277 __pPortraitIndicatorEvasObject = null;
278 __pLandscapeIndicatorEvasObject = null;
279 __pPortraitVisualElement = null;
280 __pLandscapeVisualElement = null;
281 __pCurrentVisualElement = null;
287 _Indicator::ChangeCurrentVisualElement(Tizen::Ui::Animations::_VisualElement* pVisualElement)
289 result r = E_SUCCESS;
291 if (!(__pCurrentVisualElement == pVisualElement))
293 _VisualElement* pIndicatorVisualElement = GetVisualElement();
294 r = pIndicatorVisualElement->AttachChild(*pVisualElement);
295 if (__pCurrentVisualElement)
297 r = pIndicatorVisualElement->DetachChild(*__pCurrentVisualElement);
299 __pCurrentVisualElement = pVisualElement;
306 _Indicator::OnChangeLayout(_ControlOrientation orientation)
308 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
310 ChangeCurrentVisualElement(__pPortraitVisualElement);
314 ChangeCurrentVisualElement(__pLandscapeVisualElement);
319 _Indicator::OnAttachedToMainTree(void)
321 result r = E_SUCCESS;
323 if (__pCurrentVisualElement)
325 r = ChangeCurrentVisualElement(__pCurrentVisualElement);
332 _Indicator::OnTimerExpired(Timer& timer)
334 Eina_Bool result = EINA_TRUE;
336 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
337 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
339 result = ecore_evas_extn_plug_connect(__pPortraitIndicatorEvasObject, pPortraitSvcName, 0, EINA_FALSE);
343 result = ecore_evas_extn_plug_connect(__pLandscapeIndicatorEvasObject, pLandScapeSvcName, 0, EINA_FALSE);
346 if (result == EINA_TRUE)
352 timer.Start(CONNECTION_INTERVAL);
357 _Indicator::OnDisconnected(Ecore_Evas *pEe)
359 _Indicator* pIndicator = (_Indicator*)ecore_evas_data_get(pEe, pIndicatorKey);
360 SysTryReturnVoidResult(NID_UI_CTRL, pIndicator, E_SYSTEM, "[E_SYSTEM] Unable to get Indicator Object");
362 if (pIndicator->__pConnectionTimer == null)
364 pIndicator->__pConnectionTimer = new (std::nothrow) Timer;
365 if (pIndicator->__pConnectionTimer == null)
370 result r = pIndicator->__pConnectionTimer->Construct(*pIndicator);
373 delete pIndicator->__pConnectionTimer;
374 pIndicator->__pConnectionTimer = null;
380 pIndicator->__pConnectionTimer->Start(CONNECTION_INTERVAL);
384 _Indicator::SetNotificationTrayOpenEnabled(bool enable)
386 _Window* pWindow = GetRootWindow();
387 SysTryReturn(NID_UI_CTRL, pWindow, null, E_INVALID_STATE, "[E_INVALID_STATE] Indicator is not attached main tree.");
389 Ecore_X_Window win = (Ecore_X_Window)pWindow->GetNativeHandle();
391 Ecore_X_Atom atomPanelScrollable = ecore_x_atom_get("_E_MOVE_PANEL_SCROLLABLE_STATE");
394 ecore_x_window_prop_card32_get(win, atomPanelScrollable, val, 3);
405 ecore_x_window_prop_card32_set(win, atomPanelScrollable, val, 3);
412 _Indicator::IsNotificationTrayOpenEnabled(void) const
414 _Window* pWindow = GetRootWindow();
415 SysTryReturn(NID_UI_CTRL, pWindow, false, E_INVALID_STATE, "[E_INVALID_STATE] Indicator is not attached main tree.");
417 Ecore_X_Window win = (Ecore_X_Window)pWindow->GetNativeHandle();
419 Ecore_X_Atom atomPanelScrollable = ecore_x_atom_get("_E_MOVE_PANEL_SCROLLABLE_STATE");
422 ecore_x_window_prop_card32_get(win, atomPanelScrollable, val, 3);
434 }}} // Tizen::Ui::Controls