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