Fix a log error
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_Indicator.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
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.
16 //
17 /**
18  * @file                FUiCtrl_Indicator.cpp
19  * @brief               This is the implementation file for the _Form class.
20  */
21
22 #include <FGrpRectangle.h>
23 #include <FUiAnimAnimationTransaction.h>
24 #include <FUiAnimVisualElementPropertyAnimation.h>
25 #include <FGrp_CoordinateSystem.h>
26 #include <FUiAnim_VisualElementSurfaceImpl.h>
27 #include "FUiAnim_VisualElement.h"
28 #include "FUiAnim_VisualElementImpl.h"
29 #include "FUiAnim_EflNode.h"
30 #include "FUi_EcoreEvasMgr.h"
31 #include "FUi_EcoreEvas.h"
32 #include "FUi_ResourceManager.h"
33 #include "FUi_CoordinateSystemUtils.h"
34 #include "FUi_UiEventManager.h"
35 #include "FUi_Window.h"
36 #include "FUi_TouchManager.h"
37 #include "FUiCtrl_Form.h"
38 #include "FUiCtrl_Indicator.h"
39 #include "FUiCtrl_IndicatorManager.h"
40 #include "FUiAnim_EflVisualElementSurfaceImpl.h"
41
42 using namespace Tizen::Base::Runtime;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Ui;
45 using namespace Tizen::Ui::Animations;
46
47 namespace
48 {
49 const char* pPortraitSvcName = "elm_indicator_portrait";
50 const char* pLandScapeSvcName = "elm_indicator_landscape";
51 const char* pPortPublicKey = "__Plug_Ecore_Evas_Port";
52 const char* pLandPublicKey = "__Plug_Ecore_Evas_Land";
53 const char* pIndicatorKey = "Inidcator_Manager_Object";
54 const int CONNECTION_INTERVAL = 1000;
55 const int ANIMATION_INTERVAL = 3000;
56 const int ANIMATION_DURATION = 200;
57
58 const int MSG_DOMAIN_CONTROL_INDICATOR = 0x10001;
59 const int MSG_ID_INDICATOR_REPEAT_EVENT = 0x10002;
60 const int MSG_ID_INDICATOR_START_ANIMATION = 0X10006;
61 }
62
63 namespace Tizen { namespace Ui { namespace Controls
64 {
65
66 struct _IndicatorDataAnimation
67 {
68    Ecore_X_Window xwin;
69    double duration;
70 };
71
72 _Indicator*
73 _Indicator::CreateIndicator(void)
74 {
75         result r = E_SUCCESS;
76         Color bgColor(0xff343432);
77
78         _Indicator* pIndicator = new (std::nothrow) _Indicator;
79         SysTryReturn(NID_UI_CTRL, pIndicator, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
80         SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
81
82         r = pIndicator->ConstructControlVisualElement();
83         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
84
85         pIndicator->SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
86
87         return pIndicator;
88
89 CATCH:
90         delete pIndicator;
91         return null;
92 }
93
94 _Indicator::_Indicator(void)
95         : __pPortraitIndicatorEvasObject(null)
96         , __pLandscapeIndicatorEvasObject(null)
97         , __pConnectionTimer(null)
98         , __pAnimationTimer(null)
99         , __pPortraitVisualElement(null)
100         , __pLandscapeVisualElement(null)
101         , __pCurrentVisualElement(null)
102         , __pWindow(null)
103         , __showstate(false)
104         , __portraitautohide(false)
105         , __landscapeautohide(false)
106         , __opacity(_INDICATOR_OPACITY_OPAQUE)
107         , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
108         , __startTouchPoint(0.0f, 0.0f)
109         , __animationing(false)
110         , __touchPressed(false)
111         , __quickpanelOpened(false)
112 {
113 }
114
115 _Indicator::~_Indicator(void)
116 {
117         if (__pConnectionTimer != null)
118         {
119                 __pConnectionTimer->Cancel();
120                 delete __pConnectionTimer;
121                 __pConnectionTimer = null;
122         }
123
124         if (__pAnimationTimer != null)
125         {
126                 __pAnimationTimer->Cancel();
127                 delete __pAnimationTimer;
128                 __pAnimationTimer = null;
129         }
130
131         _UiEventManager::GetInstance()->RemoveTouchEventListener(*this);
132 }
133
134 result
135 _Indicator::SetIndicatorShowState(bool state)
136 {
137         result r = E_SUCCESS;
138
139         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
140         SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
141
142         Ecore_X_Window win = 0;
143
144         if (__pWindow)
145         {
146                 r = pEcoreEvas->SetIndicatorShowState(*__pWindow, state);
147                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
148                 win = (Ecore_X_Window)__pWindow->GetNativeHandle();
149         }
150
151         __showstate = state;
152
153         SetShowState(state);
154
155         if (state)
156         {
157                 SetIndicatorOpacity(__opacity);
158         }
159
160         return r;
161 }
162
163 void
164 _Indicator::SetIndicatorAutoHide(bool portrait, bool landscape)
165 {
166         Ecore_X_Window win = 0;
167         if (__pWindow)
168         {
169                 win = (Ecore_X_Window)__pWindow->GetNativeHandle();
170         }
171
172         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
173         {
174                 if (portrait)
175                 {
176                         Color bgColor(0x00000000);
177                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
178                         if (__pPortraitVisualElement)
179                         {
180                                 __pPortraitVisualElement->SetShowState(false);
181                         }
182                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
183                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
184                 }
185                 else
186                 {
187                         SetIndicatorOpacity(__opacity);
188                         if (__pPortraitVisualElement)
189                         {
190                                 __pPortraitVisualElement->SetShowState(true);
191                         }
192                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_OPAQUE);
193                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_1);
194                 }
195         }
196         else
197         {
198                 if (landscape)
199                 {
200                         Color bgColor(0x00000000);
201                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
202                         if (__pLandscapeVisualElement)
203                         {
204                                 __pLandscapeVisualElement->SetShowState(false);
205                         }
206                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
207                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
208                 }
209                 else
210                 {
211                         SetIndicatorOpacity(__opacity);
212                         if (__pLandscapeVisualElement)
213                         {
214                                 __pLandscapeVisualElement->SetShowState(true);
215                         }
216                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_OPAQUE);
217                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_1);
218                 }
219         }
220         __portraitautohide = portrait;
221         __landscapeautohide = landscape;
222
223 }
224
225 result
226 _Indicator::SetIndicatorOpacity(_IndicatorOpacity opacity)
227 {
228         result r = E_SUCCESS;
229
230         if (opacity == _INDICATOR_OPACITY_OPAQUE)
231         {
232                 Color bgColor(0xff1e1e1e);
233                 SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
234         }
235         else if (opacity == _INDICATOR_OPACITY_TRANSLUCENT)
236         {
237                 if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
238                 {
239                         Color bgColor(0x7f000000);
240                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
241                 }
242                 else
243                 {
244                         Color bgColor(0x00000000);
245                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
246                 }
247         }
248
249         __opacity = opacity;
250
251         return r;
252 }
253
254 bool
255 _Indicator::GetIndicatorShowState(void) const
256 {
257         return __showstate;
258 }
259
260 _IndicatorOpacity
261 _Indicator::GetIndicatorOpacity(void) const
262 {
263         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
264         {
265                 if (__portraitautohide)
266                 {
267                         return _INDICATOR_OPACITY_TRANSPARENT;
268                 }
269         }
270         else
271         {
272                 if (__landscapeautohide)
273                 {
274                         return _INDICATOR_OPACITY_TRANSPARENT;
275                 }
276         }
277
278         return __opacity;
279 }
280
281 bool
282 _Indicator::GetIndicatorAutoHide(void) const
283 {
284         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
285         {
286                 return __portraitautohide;
287         }
288         else
289         {
290                 return __landscapeautohide;
291         }
292
293 }
294
295 Rectangle
296 _Indicator::GetIndicatorBounds(void) const
297 {
298         const Dimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSize();
299         const Dimension landscapeSize = Dimension(portraitSize.height, portraitSize.width);
300
301         Rectangle indicatorbounds(0, 0, 0, 0);
302
303         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
304         {
305                 indicatorbounds.width = portraitSize.width;
306         }
307         else
308         {
309                 indicatorbounds.width = landscapeSize.width;
310         }
311         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, __pWindow->GetOrientation(), indicatorbounds.height);
312
313         _CoordinateSystem* pCoordSystem = _CoordinateSystem::GetInstance();
314         SysTryReturn(NID_UI_CTRL, pCoordSystem, Rectangle(-1, -1, -1, -1), E_SYSTEM, "[E_SYSTEM] Coordinate system load failed.");
315
316         _ICoordinateSystemTransformer* pXformer = pCoordSystem->GetTransformer();
317         SysTryReturn(NID_UI_CTRL, pXformer, Rectangle(-1, -1, -1, -1), E_SYSTEM, "[E_SYSTEM] Coordinate system load failed.");
318
319         indicatorbounds = pXformer->Transform(indicatorbounds);
320
321         return indicatorbounds;
322 }
323
324 FloatRectangle
325 _Indicator::GetIndicatorBoundsF(void) const
326 {
327         const FloatDimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
328         const FloatDimension landscapeSize = FloatDimension(portraitSize.height, portraitSize.width);
329
330         FloatRectangle indicatorbounds(0.0f, 0.0f, 0.0f, 0.0f);
331
332         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
333         {
334                 indicatorbounds.width = portraitSize.width;
335         }
336         else
337         {
338                 indicatorbounds.width = landscapeSize.width;
339         }
340
341         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, __pWindow->GetOrientation(), indicatorbounds.height);
342
343         _CoordinateSystem* pCoordSystem = _CoordinateSystem::GetInstance();
344         SysTryReturn(NID_UI_CTRL, pCoordSystem, FloatRectangle(-1.0, -1.0, -1.0, -1.0), E_SYSTEM, "[E_SYSTEM] Coordinate system load failed.");
345
346         _ICoordinateSystemTransformer* pXformer = pCoordSystem->GetTransformer();
347         SysTryReturn(NID_UI_CTRL, pXformer, FloatRectangle(-1.0, -1.0, -1.0, -1.0), E_SYSTEM, "[E_SYSTEM] Coordinate system load failed.");
348
349         indicatorbounds = pXformer->Transform(indicatorbounds);
350
351         return indicatorbounds;
352 }
353
354 result
355 _Indicator::AddIndicatorObject(_Control* pControl, _Window* pWindow)
356 {
357         result r = E_SUCCESS;
358
359         __pWindow = pWindow;
360
361         __pPortraitVisualElement =      _IndicatorManager::GetInstance()->GetIndicatorVisualElement(pWindow, _INDICATOR_ORIENTATION_PORTRAIT, pControl);
362         SysTryReturn(NID_UI_CTRL, __pPortraitVisualElement, null,  E_SYSTEM, "[E_SYSTEM] Indicator can not create the surface.");
363         __pLandscapeVisualElement = _IndicatorManager::GetInstance()->GetIndicatorVisualElement(pWindow, _INDICATOR_ORIENTATION_LANDSCAPE, pControl);
364         SysTryReturn(NID_UI_CTRL, __pLandscapeVisualElement, null,  E_SYSTEM, "[E_SYSTEM] Indicator can not create the surface.");
365         __pPortraitIndicatorEvasObject = _IndicatorManager::GetInstance()->GetEvasObject(pWindow, pControl, _INDICATOR_ORIENTATION_PORTRAIT);
366         SysTryReturn(NID_UI_CTRL, __pPortraitIndicatorEvasObject, null,  E_SYSTEM, "[E_SYSTEM] Indicator can not get the Evas_Object.");
367         __pLandscapeIndicatorEvasObject = _IndicatorManager::GetInstance()->GetEvasObject(pWindow, pControl, _INDICATOR_ORIENTATION_LANDSCAPE);
368         SysTryReturn(NID_UI_CTRL, __pLandscapeIndicatorEvasObject, null,  E_SYSTEM, "[E_SYSTEM] Indicator can not get the Evas_Object.");
369
370         _ControlOrientation orientation = pControl->GetOrientation();
371         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
372         {
373                 r = ChangeCurrentVisualElement(__pPortraitVisualElement);
374         }
375         else
376         {
377                 r = ChangeCurrentVisualElement(__pLandscapeVisualElement);
378         }
379
380         Ecore_Evas* pPortraitEe = ecore_evas_object_ecore_evas_get(__pPortraitIndicatorEvasObject);
381         SysTryReturn(NID_UI_CTRL, pPortraitEe, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to get evas.");
382         Ecore_Evas* pLandscapeEe = ecore_evas_object_ecore_evas_get(__pLandscapeIndicatorEvasObject);
383         SysTryReturn(NID_UI_CTRL, pLandscapeEe, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to get evas.");
384
385         ecore_evas_data_set(pPortraitEe, pPortPublicKey, __pPortraitIndicatorEvasObject);
386         ecore_evas_data_set(pLandscapeEe, pLandPublicKey, __pLandscapeIndicatorEvasObject);
387         ecore_evas_data_set(pPortraitEe, pIndicatorKey, this);
388         ecore_evas_data_set(pLandscapeEe, pIndicatorKey, this);
389         ecore_evas_callback_delete_request_set(pPortraitEe, _Indicator::OnDisconnected);
390         ecore_evas_callback_delete_request_set(pLandscapeEe, _Indicator::OnDisconnected);
391
392         ecore_evas_callback_msg_handle_set(pPortraitEe, _Indicator::OnMessageHandle);
393         ecore_evas_callback_msg_handle_set(pLandscapeEe, _Indicator::OnMessageHandle);
394
395         Activate();
396
397         return r;
398 }
399
400 result
401 _Indicator::DeleteIndicatorObject(void)
402 {
403         result r = E_SUCCESS;
404
405         r = _IndicatorManager::GetInstance()->ReleaseIndicatorVisualElement(__pWindow, _INDICATOR_ORIENTATION_PORTRAIT, __pPortraitVisualElement);
406         r = _IndicatorManager::GetInstance()->ReleaseIndicatorVisualElement(__pWindow, _INDICATOR_ORIENTATION_LANDSCAPE, __pLandscapeVisualElement);
407
408         if (__pPortraitVisualElement)
409         {
410                 if (__pPortraitVisualElement == __pCurrentVisualElement)
411                 {
412                         r = DetachChild(*__pPortraitVisualElement);
413                 }
414         }
415         if (__pLandscapeVisualElement)
416         {
417                 if (__pLandscapeVisualElement == __pCurrentVisualElement)
418                 {
419                         r = DetachChild(*__pLandscapeVisualElement);
420                 }
421         }
422
423         Ecore_Evas* pPortraitEe = ecore_evas_object_ecore_evas_get(__pPortraitIndicatorEvasObject);
424         Ecore_Evas* pLandscapeEe = ecore_evas_object_ecore_evas_get(__pLandscapeIndicatorEvasObject);
425
426         if (pPortraitEe)
427         {
428                 ecore_evas_callback_delete_request_set(pPortraitEe, null);
429                 ecore_evas_callback_msg_handle_set(pPortraitEe, null);
430         }
431
432         if (pLandscapeEe)
433         {
434                 ecore_evas_callback_delete_request_set(pLandscapeEe, null);
435                 ecore_evas_callback_msg_handle_set(pLandscapeEe, null);
436         }
437
438         __pPortraitIndicatorEvasObject = null;
439         __pLandscapeIndicatorEvasObject = null;
440         __pPortraitVisualElement = null;
441         __pLandscapeVisualElement = null;
442         __pCurrentVisualElement = null;
443
444         return r;
445 }
446
447 result
448 _Indicator::ChangeCurrentVisualElement(Tizen::Ui::Animations::_VisualElement* pVisualElement)
449 {
450         result r = E_SUCCESS;
451
452         if (!(__pCurrentVisualElement == pVisualElement))
453         {
454                 r = AttachChild(*pVisualElement);
455                 if (__pCurrentVisualElement)
456                 {
457                         r = DetachChild(*__pCurrentVisualElement);
458                 }
459                 __pCurrentVisualElement = pVisualElement;
460         }
461
462         return r;
463 }
464
465 void
466 _Indicator::OnChangeLayout(_ControlOrientation orientation)
467 {
468         RemoveIndicatorAnimations();
469         if (__pAnimationTimer != null)
470         {
471                 __pAnimationTimer->Cancel();
472                 __animationing = false;
473         }
474
475         Ecore_X_Window win = 0;
476         if (__pWindow)
477         {
478                 win = (Ecore_X_Window)__pWindow->GetNativeHandle();
479         }
480
481         __orientation = orientation;
482
483         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
484         {
485                 ChangeCurrentVisualElement(__pPortraitVisualElement);
486                 SetClipChildrenEnabled(true);
487
488                 if (__portraitautohide)
489                 {
490                         Color bgColor(0x00000000);
491                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
492                         if (__pPortraitVisualElement)
493                         {
494                                 __pPortraitVisualElement->SetShowState(false);
495                         }
496                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
497                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
498                 }
499                 else
500                 {
501                         SetIndicatorOpacity(__opacity);
502                         if (__pPortraitVisualElement)
503                         {
504                                 __pPortraitVisualElement->SetShowState(true);
505                         }
506                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_OPAQUE);
507                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_1);
508                 }
509
510         }
511         else
512         {
513                 ChangeCurrentVisualElement(__pLandscapeVisualElement);
514                 SetClipChildrenEnabled(false);
515
516                 if (__landscapeautohide)
517                 {
518                         Color bgColor(0x00000000);
519                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
520                         if (__pLandscapeVisualElement)
521                         {
522                                 __pLandscapeVisualElement->SetShowState(false);
523                         }
524                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
525                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
526                 }
527                 else
528                 {
529                         SetIndicatorOpacity(__opacity);
530                         if (__pLandscapeVisualElement)
531                         {
532                                 __pLandscapeVisualElement->SetShowState(true);
533                         }
534                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_OPAQUE);
535                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_1);
536                 }
537         }
538 }
539
540 result
541 _Indicator::OnAttachedToMainTree(void)
542 {
543         result r = E_SUCCESS;
544
545         if (__pCurrentVisualElement)
546         {
547                 r = ChangeCurrentVisualElement(__pCurrentVisualElement);
548         }
549
550         return r;
551 }
552
553 void
554 _Indicator::OnTimerExpired(Timer& timer)
555 {
556         if (__pConnectionTimer == &timer)
557         {
558                 Eina_Bool result = EINA_TRUE;
559
560                 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
561                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
562                 {
563                         result = ecore_evas_extn_plug_connect(__pPortraitIndicatorEvasObject, pPortraitSvcName, 0, EINA_FALSE);
564                 }
565                 else
566                 {
567                         result = ecore_evas_extn_plug_connect(__pLandscapeIndicatorEvasObject, pLandScapeSvcName, 0, EINA_FALSE);
568                 }
569
570                 if (result == EINA_TRUE)
571                 {
572                         timer.Cancel();
573                 }
574                 else
575                 {
576                         timer.Start(CONNECTION_INTERVAL);
577                 }
578         }
579         else if(__pAnimationTimer == &timer)
580         {
581                 ShowIndicatorEffect(false, ANIMATION_DURATION);
582
583                 timer.Cancel();
584                 __animationing = false;
585         }
586 }
587
588 void
589 _Indicator::OnDisconnected(Ecore_Evas* pEe)
590 {
591         _Indicator* pIndicator = (_Indicator*)ecore_evas_data_get(pEe, pIndicatorKey);
592         SysTryReturnVoidResult(NID_UI_CTRL, pIndicator, E_SYSTEM, "[E_SYSTEM] Unable to get Indicator Object");
593
594         if (pIndicator->__pConnectionTimer == null)
595         {
596                 pIndicator->__pConnectionTimer = new (std::nothrow) Timer;
597                 if (pIndicator->__pConnectionTimer == null)
598                 {
599                         return;
600                 }
601
602                 result r = pIndicator->__pConnectionTimer->Construct(*pIndicator);
603                 if (r != E_SUCCESS)
604                 {
605                         delete pIndicator->__pConnectionTimer;
606                         pIndicator->__pConnectionTimer = null;
607
608                         return;
609                 }
610         }
611
612         pIndicator->__pConnectionTimer->Start(CONNECTION_INTERVAL);
613 }
614
615 result
616 _Indicator::SetNotificationTrayOpenEnabled(bool enable)
617 {
618         Ecore_X_Window win = (Ecore_X_Window)__pWindow->GetNativeHandle();
619
620         Ecore_X_Atom atomPanelScrollable = ecore_x_atom_get("_E_MOVE_PANEL_SCROLLABLE_STATE");
621
622         unsigned int val[3];
623         int returnResult = ecore_x_window_prop_card32_get(win, atomPanelScrollable, val, 3);
624
625         if (returnResult)
626         {
627                 if (enable)
628                 {
629                         val[1] = 1;
630                 }
631                 else
632                 {
633                         val[1] = 0;
634                 }
635
636                 ecore_x_window_prop_card32_set(win, atomPanelScrollable, val, 3);
637         }
638
639         return E_SUCCESS;
640 }
641
642 bool
643 _Indicator::IsNotificationTrayOpenEnabled(void) const
644 {
645         Ecore_X_Window win = (Ecore_X_Window)__pWindow->GetNativeHandle();
646
647         Ecore_X_Atom atomPanelScrollable = ecore_x_atom_get("_E_MOVE_PANEL_SCROLLABLE_STATE");
648
649         unsigned int val[3];
650         int returnResult = ecore_x_window_prop_card32_get(win, atomPanelScrollable, val, 3);
651
652         if (returnResult)
653         {
654                 if (val[1] == 1)
655                 {
656                         return true;
657                 }
658                 else
659                 {
660                         return false;
661                 }
662         }
663         return false;
664 }
665
666 void
667 _Indicator::OnMessageHandle(Ecore_Evas* pEe, int msgDomain, int msgId, void *data, int size)
668 {
669         if (!data)
670         {
671                 return;
672         }
673
674         _Indicator* pIndicator = (_Indicator*)ecore_evas_data_get(pEe, pIndicatorKey);
675         SysTryReturnVoidResult(NID_UI_CTRL, pIndicator, E_SYSTEM, "[E_SYSTEM] Unable to get Indicator Object");
676
677         Evas_Object* pPortraitIndicatorEvasObject = (Evas_Object*)ecore_evas_data_get(pEe, pPortPublicKey);
678         Evas_Object* pLandscapeIndicatorEvasObject = (Evas_Object*)ecore_evas_data_get(pEe, pLandPublicKey);
679
680         if (msgDomain == MSG_DOMAIN_CONTROL_INDICATOR)
681         {
682                 if (msgId == MSG_ID_INDICATOR_REPEAT_EVENT)
683                 {
684                         int* repeat = (int*)data;
685                         if (1 == *repeat)
686                         {
687                                 if (pPortraitIndicatorEvasObject)
688                            {
689                                         evas_object_repeat_events_set(pPortraitIndicatorEvasObject, EINA_TRUE);
690                            }
691                                 if (pLandscapeIndicatorEvasObject)
692                                 {
693                            evas_object_repeat_events_set(pLandscapeIndicatorEvasObject, EINA_TRUE);
694                                 }
695                         }
696                         else
697                         {
698                                 if (pPortraitIndicatorEvasObject)
699                            {
700                            evas_object_repeat_events_set(pPortraitIndicatorEvasObject, EINA_FALSE);
701                            }
702                                 if (pLandscapeIndicatorEvasObject)
703                                 {
704                            evas_object_repeat_events_set(pLandscapeIndicatorEvasObject, EINA_FALSE);
705                                 }
706                         }
707                 }
708                 else if (msgId == MSG_ID_INDICATOR_START_ANIMATION)
709                 {
710                         _IndicatorDataAnimation* pData = (_IndicatorDataAnimation*)data;
711                         Ecore_X_Window win = 0;
712                         _Window* pWindow = pIndicator->__pWindow;
713                         if (pWindow)
714                         {
715                                         win = (Ecore_X_Window)pWindow->GetNativeHandle();
716                         }
717
718                         if (pData->xwin == win)
719                         {
720                                 if (pIndicator->__orientation == _CONTROL_ORIENTATION_PORTRAIT)
721                                 {
722                                         if (pIndicator->__portraitautohide)
723                                         {
724                                                 pIndicator->ShowIndicatorEffect(true, pData->duration);
725                                         }
726                                 }
727                                 else
728                                 {
729                                         if (pIndicator->__landscapeautohide)
730                                         {
731                                                 pIndicator->ShowIndicatorEffect(true, pData->duration);
732                                         }
733                                 }
734                         }
735                 }
736
737         }
738 }
739
740 HitTestResult
741 _Indicator::OnHitTest(const Tizen::Graphics::FloatPoint& point)
742 {
743         if (!IsVisible())
744         {
745                 return HIT_TEST_NOWHERE;
746         }
747
748         if (!GetBounds().Contains(point))
749         {
750                 return HIT_TEST_NOWHERE;
751         }
752
753         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
754         {
755                 if (__portraitautohide)
756                 {
757                         return HIT_TEST_NOWHERE;
758                 }
759                 else
760                 {
761                         return HIT_TEST_MATCH;
762                 }
763         }
764         else
765         {
766                 if (__landscapeautohide)
767                 {
768                         return HIT_TEST_NOWHERE;
769                 }
770                 else
771                 {
772                         return HIT_TEST_MATCH;
773                 }
774         }
775
776 }
777
778 void
779 _Indicator::SetIndicatorOrientation(Tizen::Ui::_ControlOrientation orientation)
780 {
781         __orientation = orientation;
782 }
783
784 void
785 _Indicator::SetWindow(_Window* pWindow)
786 {
787         __pWindow = pWindow;
788 }
789
790 result
791 _Indicator::ShowIndicatorEffect(bool down, int duration)
792 {
793         Ecore_X_Window win = 0;
794         if (__pWindow)
795         {
796                 win = (Ecore_X_Window)__pWindow->GetNativeHandle();
797         }
798
799         VisualElementPropertyAnimation* pSlideAnimation = new (std::nothrow) VisualElementPropertyAnimation();
800         SysTryReturnResult(NID_UI_CTRL, pSlideAnimation, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
801
802         pSlideAnimation->SetDuration(duration);
803         pSlideAnimation->SetPropertyName(L"bounds.position");
804         pSlideAnimation->SetVisualElementAnimationStatusEventListener(this);
805
806         float indicatorHeight = 0.0f;
807         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, __orientation, indicatorHeight);
808
809         String* pUserData = null;
810         if (down)
811         {
812                 Color bgColor(0xff1e1e1e);
813                 SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
814
815                 if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
816                 {
817                         if (__pPortraitVisualElement)
818                         {
819                                 __pPortraitVisualElement->SetShowState(true);
820                         }
821                 }
822                 else
823                 {
824                         if (__pLandscapeVisualElement)
825                         {
826                                 __pLandscapeVisualElement->SetShowState(true);
827                         }
828                 }
829
830                 pSlideAnimation->SetStartValue(Variant(FloatPoint(0.0f, -indicatorHeight)));
831                 pSlideAnimation->SetEndValue(Variant(FloatPoint(0.0f, 0.0f)));
832                 ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_1);
833                 pUserData = new (std::nothrow) String(L"DownAnimation");
834                 SysTryReturnResult(NID_UI_CTRL, pUserData, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
835         }
836         else
837         {
838                 pSlideAnimation->SetStartValue(Variant(FloatPoint(0.0f, 0.0f)));
839                 pSlideAnimation->SetEndValue(Variant(FloatPoint(0.0f, -indicatorHeight)));
840                 ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
841                 pUserData = new (std::nothrow) String(L"UpAnimation");
842                 SysTryReturnResult(NID_UI_CTRL, pUserData, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
843         }
844         pSlideAnimation->SetUserData((void*)(pUserData));
845         AddAnimation(L"bounds.position", *pSlideAnimation);
846
847         delete pSlideAnimation;
848
849         return E_SUCCESS;
850 }
851
852 void
853 _Indicator::RemoveIndicatorAnimations(void)
854 {
855         if (__pAnimationTimer)
856         {
857                 __pAnimationTimer->Cancel();
858         }
859         RemoveAllAnimations();
860 }
861
862 bool
863 _Indicator::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
864 {
865         bool r = false;
866         if (IsVisible() ==false)
867         {
868                 return false;
869         }
870
871         int pointId = touchinfo.GetPointId();
872         _TouchManager* pTouchManager = _TouchManager::GetInstance();
873
874         FloatPoint touchPosition = source.ConvertToScreenPosition(touchinfo.GetCurrentPosition());
875         int indicatorHeight = 0;
876         if (__pWindow)
877         {
878                 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, __pWindow->GetOrientation(), indicatorHeight);
879         }
880         else
881         {
882                 return false;
883         }
884         if (touchPosition.y < indicatorHeight)
885         {
886                 if (__animationing)
887                 {
888                         return true;
889                 }
890                 else
891                 {
892                         __startTouchPoint = touchPosition;
893                         __touchPressed = true;
894                         __pointId = pointId;
895                 }
896
897                 if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
898                 {
899                         if (__portraitautohide)
900                         {
901                                 return false;
902                         }
903                         else
904                         {
905                                 return true;
906                         }
907                 }
908                 else
909                 {
910                         if (__landscapeautohide)
911                         {
912                                 return false;
913                         }
914                         else
915                         {
916                                 return true;
917                         }
918                 }
919         }
920
921         if (pTouchManager->IsListenerOnly(pointId) == true)
922         {
923                 return true;
924         }
925         else
926         {
927                 return false;
928         }
929 }
930
931 bool
932 _Indicator::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
933 {
934         if (IsVisible() ==false)
935         {
936                 return false;
937         }
938
939         _TouchManager* pTouchManager = _TouchManager::GetInstance();
940
941         if (__touchPressed)
942         {
943                 if (touchinfo.GetPointId() == __pointId)
944                 {
945                         __touchPressed = false;
946                 }
947
948                 FloatPoint touchPosition = source.ConvertToScreenPosition(touchinfo.GetCurrentPosition());
949                 int indicatorHeight = 0;
950                 if (__pWindow)
951                 {
952                         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, __pWindow->GetOrientation(), indicatorHeight);
953                 }
954                 else
955                 {
956                         return false;
957                 }
958                 if (touchPosition.y < indicatorHeight)
959                 {
960                         if (__animationing)
961                         {
962                                 _TouchManager* pTouchManager = _TouchManager::GetInstance();
963                                 if (pTouchManager)
964                                 {
965                                         if(pTouchManager->GetTouchControlSource() == &source)
966                                         {
967                                                 SysLog(NID_UI, "VisibleState changed false, Call SetTouchCanceled");
968                                                 pTouchManager->SetTouchCanceled(null);
969                                         }
970                                 }
971                                 return true;
972                         }
973                 }
974
975                 if (pTouchManager->IsListenerOnly(touchinfo.GetPointId()) == true)
976                 {
977                         _TouchManager* pTouchManager = _TouchManager::GetInstance();
978                         if (pTouchManager)
979                         {
980                                 if(pTouchManager->GetTouchControlSource() == &source)
981                                 {
982                                         SysLog(NID_UI, "VisibleState changed false, Call SetTouchCanceled");
983                                         pTouchManager->SetTouchCanceled(null);
984                                 }
985                         }
986                         return true;
987                 }
988                 else
989                 {
990                         return false;
991                 }
992         }
993         else if (__quickpanelOpened == true)
994         {
995                 OnChangeLayout(__orientation);
996                 __quickpanelOpened = false;
997         }
998         return false;
999 }
1000
1001 bool
1002 _Indicator::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1003 {
1004         bool r = false;
1005
1006         if (IsVisible() ==false)
1007         {
1008                 return false;
1009         }
1010
1011         int pointId = touchinfo.GetPointId();
1012         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1013
1014         if (__touchPressed)
1015         {
1016                 FloatPoint touchPoint = source.ConvertToScreenPosition(touchinfo.GetCurrentPosition());
1017                 float gap = touchPoint.y - __startTouchPoint.y;
1018
1019                 int touchGap = 0;
1020                 if (__pWindow)
1021                 {
1022                         GET_SHAPE_CONFIG(FORM::INDICATOR_TOUCH_GAP, __pWindow->GetOrientation(), touchGap);
1023                 }
1024                 else
1025                 {
1026                         return false;
1027                 }
1028
1029                 if (gap < touchGap || __animationing)
1030                 {
1031                 }
1032                 else
1033                 {
1034                         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
1035                         {
1036                                 if (__portraitautohide)
1037                                 {
1038                                         ShowIndicatorEffect(true, ANIMATION_DURATION);
1039                                 }
1040                         }
1041                         else
1042                         {
1043                                 if (__landscapeautohide)
1044                                 {
1045                                         ShowIndicatorEffect(true, ANIMATION_DURATION);
1046                                 }
1047                         }
1048                 }
1049                 
1050                 if (pTouchManager->IsListenerOnly(pointId) == true)
1051                 {
1052                         r = true;
1053                 }
1054                 else
1055                 {
1056                         r = false;
1057                 }
1058         }
1059         else
1060         {
1061                 if (__pAnimationTimer)
1062                 {
1063                         __pAnimationTimer->Cancel();
1064                 }
1065                 __quickpanelOpened = true;
1066                 __animationing = false;
1067                 r = false;
1068         }
1069         return r;
1070 }
1071
1072 bool
1073 _Indicator::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1074 {
1075         return false;
1076 }
1077
1078 void
1079 _Indicator::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
1080 {
1081         String* pUserData = (String*) animation.GetUserData();
1082
1083         if ((pUserData != null) && (*pUserData == String(L"DownAnimation")))
1084         {
1085                 if (__pAnimationTimer == null)
1086                 {
1087                         __pAnimationTimer = new (std::nothrow) Timer;
1088                         if (__pAnimationTimer == null)
1089                         {
1090                                 return;
1091                         }
1092
1093                         result r = __pAnimationTimer->Construct(*this);
1094                         if (r != E_SUCCESS)
1095                         {
1096                                 delete __pAnimationTimer;
1097                                 __pAnimationTimer = null;
1098
1099                                 return;
1100                         }
1101                 }
1102
1103                 if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
1104                 {
1105                         if (__portraitautohide)
1106                         {
1107                                 __pAnimationTimer->Start(ANIMATION_INTERVAL);
1108                                 __animationing = true;
1109                         }
1110                 }
1111                 else
1112                 {
1113                         if (__landscapeautohide)
1114                         {
1115                                 __pAnimationTimer->Start(ANIMATION_INTERVAL);
1116                                 __animationing = true;
1117                         }
1118                 }
1119         }
1120 }
1121
1122 void
1123 _Indicator::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
1124 {
1125
1126 }
1127
1128 void
1129 _Indicator::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
1130 {
1131         const FloatDimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
1132         const FloatDimension landscapeSize = FloatDimension(portraitSize.height, portraitSize.width);
1133
1134         String* pUserData = (String*) animation.GetUserData();
1135
1136         if ((pUserData != null) && (*pUserData == String(L"UpAnimation")))
1137         {
1138                 Color bgColor(0x00000000);
1139
1140                 int indicatorHeight = 0;
1141                 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, __pWindow->GetOrientation(), indicatorHeight);
1142
1143                 if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
1144                 {
1145                         if (__portraitautohide)
1146                         {
1147                                 SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
1148                                 if (__pPortraitVisualElement && __portraitautohide)
1149                                 {
1150                                         __pPortraitVisualElement->SetShowState(false);
1151                                 }
1152                         }
1153                         SetBounds(FloatRectangle(0.0f, 0.0f, portraitSize.width, indicatorHeight));
1154                 }
1155                 else
1156                 {
1157                         if (__landscapeautohide)
1158                         {
1159                                 SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
1160                                 if (__pLandscapeVisualElement && __landscapeautohide)
1161                                 {
1162                                         __pLandscapeVisualElement->SetShowState(false);
1163                                 }
1164                         }
1165                         SetBounds(FloatRectangle(0.0f, 0.0f, landscapeSize.width, indicatorHeight));
1166                 }
1167                 delete pUserData;
1168         }
1169 }
1170
1171 void
1172 _Indicator::Activate(void)
1173 {
1174         _UiEventManager::GetInstance()->AddTouchEventListener(*this);
1175
1176         return;
1177 }
1178
1179 void
1180 _Indicator::Deactivate(void)
1181 {
1182         _UiEventManager::GetInstance()->RemoveTouchEventListener(*this);
1183
1184         if (__pAnimationTimer)
1185         {
1186                 __pAnimationTimer->Cancel();
1187         }
1188         RemoveAllAnimations();
1189
1190         Ecore_X_Window win = 0;
1191         if (__pWindow)
1192         {
1193                 win = (Ecore_X_Window)__pWindow->GetNativeHandle();
1194         }
1195
1196         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
1197         {
1198                 if (__portraitautohide)
1199                 {
1200                         Color bgColor(0x00000000);
1201                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
1202
1203                         if (__pPortraitVisualElement)
1204                         {
1205                                 __pPortraitVisualElement->SetShowState(false);
1206                                 ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
1207                         }
1208                         __animationing = false;
1209                 }
1210         }
1211         else
1212         {
1213                 if (__landscapeautohide)
1214                 {
1215                         Color bgColor(0x00000000);
1216                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
1217
1218                         if (__pLandscapeVisualElement)
1219                         {
1220                                 __pLandscapeVisualElement->SetShowState(false);
1221                                 ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
1222                         }
1223                         __animationing = false;
1224                 }
1225         }
1226
1227         return;
1228 }
1229
1230 }}} // Tizen::Ui::Controls