Merge "Remove unnecessary exception." into tizen_2.2
[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         Ecore_Evas *pPortraitEe = ecore_evas_object_ecore_evas_get(__pPortraitIndicatorEvasObject);
433         Ecore_Evas *pLandscapeEe = ecore_evas_object_ecore_evas_get(__pLandscapeIndicatorEvasObject);
434
435         if (pPortraitEe)
436         {
437                 ecore_evas_callback_delete_request_set(pPortraitEe, null);
438                 ecore_evas_callback_msg_handle_set(pPortraitEe, null);
439         }
440
441         if (pLandscapeEe)
442         {
443                 ecore_evas_callback_delete_request_set(pLandscapeEe, null);
444                 ecore_evas_callback_msg_handle_set(pLandscapeEe, null);
445         }
446
447         __pPortraitIndicatorEvasObject = null;
448         __pLandscapeIndicatorEvasObject = null;
449         __pPortraitVisualElement = null;
450         __pLandscapeVisualElement = null;
451         __pCurrentVisualElement = null;
452
453         return r;
454 }
455
456 result
457 _Indicator::ChangeCurrentVisualElement(Tizen::Ui::Animations::_VisualElement* pVisualElement)
458 {
459         result r = E_SUCCESS;
460
461         if (!(__pCurrentVisualElement == pVisualElement))
462         {
463                 r = AttachChild(*pVisualElement);
464                 if (__pCurrentVisualElement)
465                 {
466                         r = DetachChild(*__pCurrentVisualElement);
467                 }
468                 __pCurrentVisualElement = pVisualElement;
469         }
470
471         return r;
472 }
473
474 void
475 _Indicator::OnChangeLayout(_ControlOrientation orientation)
476 {
477         RemoveIndicatorAnimations();
478         if (__pAnimationTimer != null)
479         {
480                 __pAnimationTimer->Cancel();
481                 __animationing = false;
482         }
483
484         Ecore_X_Window win = 0;
485         if (__pWindow)
486         {
487                 win = (Ecore_X_Window)__pWindow->GetNativeHandle();
488         }
489
490         __orientation = orientation;
491
492         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
493         {
494                 ChangeCurrentVisualElement(__pPortraitVisualElement);
495                 SetClipChildrenEnabled(true);
496
497                 if (__portraitautohide)
498                 {
499                         Color bgColor(0x00000000);
500                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
501                         if (__pPortraitVisualElement)
502                         {
503                                 __pPortraitVisualElement->SetShowState(false);
504                         }
505                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
506                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
507                 }
508                 else
509                 {
510                         SetIndicatorOpacity(__opacity);
511                         if (__pPortraitVisualElement)
512                         {
513                                 __pPortraitVisualElement->SetShowState(true);
514                         }
515                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_OPAQUE);
516                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_1);
517                 }
518
519         }
520         else
521         {
522                 ChangeCurrentVisualElement(__pLandscapeVisualElement);
523                 SetClipChildrenEnabled(false);
524
525                 if (__landscapeautohide)
526                 {
527                         Color bgColor(0x00000000);
528                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
529                         if (__pLandscapeVisualElement)
530                         {
531                                 __pLandscapeVisualElement->SetShowState(false);
532                         }
533                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
534                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
535                 }
536                 else
537                 {
538                         SetIndicatorOpacity(__opacity);
539                         if (__pLandscapeVisualElement)
540                         {
541                                 __pLandscapeVisualElement->SetShowState(true);
542                         }
543                         ecore_x_e_illume_indicator_opacity_set(win, ECORE_X_ILLUME_INDICATOR_OPAQUE);
544                         ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_1);
545                 }
546         }
547 }
548
549 result
550 _Indicator::OnAttachedToMainTree(void)
551 {
552         result r = E_SUCCESS;
553
554         if (__pCurrentVisualElement)
555         {
556                 r = ChangeCurrentVisualElement(__pCurrentVisualElement);
557         }
558
559         return r;
560 }
561
562 void
563 _Indicator::OnTimerExpired(Timer& timer)
564 {
565         if (__pConnectionTimer == &timer)
566         {
567                 Eina_Bool result = EINA_TRUE;
568
569                 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
570                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
571                 {
572                         result = ecore_evas_extn_plug_connect(__pPortraitIndicatorEvasObject, pPortraitSvcName, 0, EINA_FALSE);
573                 }
574                 else
575                 {
576                         result = ecore_evas_extn_plug_connect(__pLandscapeIndicatorEvasObject, pLandScapeSvcName, 0, EINA_FALSE);
577                 }
578
579                 if (result == EINA_TRUE)
580                 {
581                         timer.Cancel();
582                 }
583                 else
584                 {
585                         timer.Start(CONNECTION_INTERVAL);
586                 }
587         }
588         else if(__pAnimationTimer == &timer)
589         {
590                 ShowIndicatorEffect(false, ANIMATION_DURATION);
591
592                 timer.Cancel();
593                 __animationing = false;
594         }
595 }
596
597 void
598 _Indicator::OnDisconnected(Ecore_Evas *pEe)
599 {
600         _Indicator* pIndicator = (_Indicator*)ecore_evas_data_get(pEe, pIndicatorKey);
601         SysTryReturnVoidResult(NID_UI_CTRL, pIndicator, E_SYSTEM, "[E_SYSTEM] Unable to get Indicator Object");
602
603         if (pIndicator->__pConnectionTimer == null)
604         {
605                 pIndicator->__pConnectionTimer = new (std::nothrow) Timer;
606                 if (pIndicator->__pConnectionTimer == null)
607                 {
608                         return;
609                 }
610
611                 result r = pIndicator->__pConnectionTimer->Construct(*pIndicator);
612                 if (r != E_SUCCESS)
613                 {
614                         delete pIndicator->__pConnectionTimer;
615                         pIndicator->__pConnectionTimer = null;
616
617                         return;
618                 }
619         }
620
621         pIndicator->__pConnectionTimer->Start(CONNECTION_INTERVAL);
622 }
623
624 result
625 _Indicator::SetNotificationTrayOpenEnabled(bool enable)
626 {
627         Ecore_X_Window win = (Ecore_X_Window)__pWindow->GetNativeHandle();
628
629         Ecore_X_Atom atomPanelScrollable = ecore_x_atom_get("_E_MOVE_PANEL_SCROLLABLE_STATE");
630
631         unsigned int val[3];
632         int returnResult = ecore_x_window_prop_card32_get(win, atomPanelScrollable, val, 3);
633
634         if (returnResult)
635         {
636                 if (enable)
637                 {
638                         val[1] = 1;
639                 }
640                 else
641                 {
642                         val[1] = 0;
643                 }
644
645                 ecore_x_window_prop_card32_set(win, atomPanelScrollable, val, 3);
646         }
647
648         return E_SUCCESS;
649 }
650
651 bool
652 _Indicator::IsNotificationTrayOpenEnabled(void) const
653 {
654         Ecore_X_Window win = (Ecore_X_Window)__pWindow->GetNativeHandle();
655
656         Ecore_X_Atom atomPanelScrollable = ecore_x_atom_get("_E_MOVE_PANEL_SCROLLABLE_STATE");
657
658         unsigned int val[3];
659         int returnResult = ecore_x_window_prop_card32_get(win, atomPanelScrollable, val, 3);
660
661         if (returnResult)
662         {
663                 if (val[1] == 1)
664                 {
665                         return true;
666                 }
667                 else
668                 {
669                         return false;
670                 }
671         }
672         return false;
673 }
674
675 void
676 _Indicator::OnMessageHandle(Ecore_Evas *pEe, int msgDomain, int msgId, void *data, int size)
677 {
678         if (!data)
679         {
680                 return;
681         }
682
683         _Indicator* pIndicator = (_Indicator*)ecore_evas_data_get(pEe, pIndicatorKey);
684         SysTryReturnVoidResult(NID_UI_CTRL, pIndicator, E_SYSTEM, "[E_SYSTEM] Unable to get Indicator Object");
685
686         Evas_Object* pPortraitIndicatorEvasObject = (Evas_Object*)ecore_evas_data_get(pEe, pPortPublicKey);
687         Evas_Object* pLandscapeIndicatorEvasObject = (Evas_Object*)ecore_evas_data_get(pEe, pLandPublicKey);
688
689         if (msgDomain == MSG_DOMAIN_CONTROL_INDICATOR)
690         {
691                 if (msgId == MSG_ID_INDICATOR_REPEAT_EVENT)
692                 {
693                         int *repeat = (int*)data;
694                         if (1 == *repeat)
695                         {
696                                 if (pPortraitIndicatorEvasObject)
697                            {
698                                         evas_object_repeat_events_set(pPortraitIndicatorEvasObject, EINA_TRUE);
699                            }
700                                 if (pLandscapeIndicatorEvasObject)
701                                 {
702                            evas_object_repeat_events_set(pLandscapeIndicatorEvasObject, EINA_TRUE);
703                                 }
704                         }
705                         else
706                         {
707                                 if (pPortraitIndicatorEvasObject)
708                            {
709                            evas_object_repeat_events_set(pPortraitIndicatorEvasObject, EINA_FALSE);
710                            }
711                                 if (pLandscapeIndicatorEvasObject)
712                                 {
713                            evas_object_repeat_events_set(pLandscapeIndicatorEvasObject, EINA_FALSE);
714                                 }
715                         }
716                 }
717                 else if (msgId == MSG_ID_INDICATOR_START_ANIMATION)
718                 {
719                         _IndicatorDataAnimation* pData = (_IndicatorDataAnimation*)data;
720                         Ecore_X_Window win = 0;
721                         _Window* pWindow = pIndicator->__pWindow;
722                         if (pWindow)
723                         {
724                                         win = (Ecore_X_Window)pWindow->GetNativeHandle();
725                         }
726
727                         if (pData->xwin == win)
728                         {
729                                 pIndicator->ShowIndicatorEffect(true, pData->duration);
730                         }
731                 }
732
733         }
734 }
735
736 HitTestResult
737 _Indicator::OnHitTest(const Tizen::Graphics::FloatPoint& point)
738 {
739         if (!IsVisible())
740         {
741                 return HIT_TEST_NOWHERE;
742         }
743
744         if (!GetBounds().Contains(point))
745         {
746                 return HIT_TEST_NOWHERE;
747         }
748
749         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
750         {
751                 if (__portraitautohide)
752                 {
753                         return HIT_TEST_NOWHERE;
754                 }
755                 else
756                 {
757                         return HIT_TEST_MATCH;
758                 }
759         }
760         else
761         {
762                 if (__landscapeautohide)
763                 {
764                         return HIT_TEST_NOWHERE;
765                 }
766                 else
767                 {
768                         return HIT_TEST_MATCH;
769                 }
770         }
771
772 }
773
774 void
775 _Indicator::SetIndicatorOrientation(Tizen::Ui::_ControlOrientation orientation)
776 {
777         __orientation = orientation;
778 }
779
780 void
781 _Indicator::SetWindow(_Window* pWindow)
782 {
783         __pWindow = pWindow;
784 }
785
786 result
787 _Indicator::ShowIndicatorEffect(bool down, int duration)
788 {
789         Ecore_X_Window win = 0;
790         if (__pWindow)
791         {
792                 win = (Ecore_X_Window)__pWindow->GetNativeHandle();
793         }
794
795         VisualElementPropertyAnimation* pSlideAnimation = new (std::nothrow) VisualElementPropertyAnimation();
796         SysTryReturnResult(NID_UI_CTRL, pSlideAnimation, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
797
798         pSlideAnimation->SetDuration(duration);
799         pSlideAnimation->SetPropertyName( L"bounds.position");
800         pSlideAnimation->SetVisualElementAnimationStatusEventListener(this);
801
802         float indicatorHeight = 0.0f;
803         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, __orientation, indicatorHeight);
804
805         String* pUserData = null;
806         if (down)
807         {
808                 Color bgColor(0xff1e1e1e);
809                 SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
810
811                 if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
812                 {
813                         if (__pPortraitVisualElement)
814                         {
815                                 __pPortraitVisualElement->SetShowState(true);
816                         }
817                 }
818                 else
819                 {
820                         if (__pLandscapeVisualElement)
821                         {
822                                 __pLandscapeVisualElement->SetShowState(true);
823                         }
824                 }
825
826                 pSlideAnimation->SetStartValue(Variant(FloatPoint(0.0f, -indicatorHeight)));
827                 pSlideAnimation->SetEndValue(Variant(FloatPoint(0.0f, 0.0f)));
828                 ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_1);
829                 pUserData = new (std::nothrow) String(L"DownAnimation");
830                 SysTryReturnResult(NID_UI_CTRL, pUserData, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
831         }
832         else
833         {
834                 pSlideAnimation->SetStartValue(Variant(FloatPoint(0.0f, 0.0f)));
835                 pSlideAnimation->SetEndValue(Variant(FloatPoint(0.0f, -indicatorHeight)));
836                 ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
837                 pUserData = new (std::nothrow) String(L"UpAnimation");
838                 SysTryReturnResult(NID_UI_CTRL, pUserData, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
839         }
840         pSlideAnimation->SetUserData((void*)(pUserData));
841         AddAnimation( L"bounds.position", *pSlideAnimation);
842
843         delete pSlideAnimation;
844
845         return E_SUCCESS;
846 }
847
848 void
849 _Indicator::RemoveIndicatorAnimations(void)
850 {
851         if (__pAnimationTimer)
852         {
853                 __pAnimationTimer->Cancel();
854         }
855         RemoveAllAnimations();
856 }
857
858 bool
859 _Indicator::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
860 {
861         bool r = false;
862         if (IsVisible() ==false)
863         {
864                 return false;
865         }
866
867         int pointId = touchinfo.GetPointId();
868         _TouchManager* pTouchManager = _TouchManager::GetInstance();
869
870         FloatPoint touchPosition = source.ConvertToScreenPosition(touchinfo.GetCurrentPosition());
871         int indicatorHeight = 0;
872         if (__pWindow)
873         {
874                 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, __pWindow->GetOrientation(), indicatorHeight);
875         }
876         else
877         {
878                 return false;
879         }
880         if (touchPosition.y < indicatorHeight)
881         {
882                 if (__animationing)
883                 {
884                         return true;
885                 }
886                 else
887                 {
888                         __startTouchPoint = touchinfo.GetCurrentPosition();
889                         __touchPressed = true;
890                         __pointId = pointId;
891                 }
892
893                 if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
894                 {
895                         if (__portraitautohide)
896                         {
897                                 return false;
898                         }
899                         else
900                         {
901                                 return true;
902                         }
903                 }
904                 else
905                 {
906                         if (__landscapeautohide)
907                         {
908                                 return false;
909                         }
910                         else
911                         {
912                                 return true;
913                         }
914                 }
915         }
916
917         if (pTouchManager->IsListenerOnly(pointId) == true )
918         {
919                 return true;
920         }
921         else
922         {
923                 return false;
924         }
925 }
926
927 bool
928 _Indicator::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
929 {
930         if (IsVisible() ==false)
931         {
932                 return false;
933         }
934
935         _TouchManager* pTouchManager = _TouchManager::GetInstance();
936
937         if (__touchPressed)
938         {
939                 if (touchinfo.GetPointId() == __pointId)
940                 {
941                         __touchPressed = false;
942                 }
943
944                 FloatPoint touchPosition = source.ConvertToScreenPosition(touchinfo.GetCurrentPosition());
945                 int indicatorHeight = 0;
946                 if (__pWindow)
947                 {
948                         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, __pWindow->GetOrientation(), indicatorHeight);
949                 }
950                 else
951                 {
952                         return false;
953                 }
954                 if (touchPosition.y < indicatorHeight)
955                 {
956                         if (__animationing)
957                         {
958                                 return true;
959                         }
960                 }
961
962                 if (pTouchManager->IsListenerOnly(touchinfo.GetPointId()) == true)
963                 {
964                         return true;
965                 }
966                 else
967                 {
968                         return false;
969                 }
970         }
971         return false;
972 }
973
974 bool
975 _Indicator::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
976 {
977         bool r = false;
978
979         if (IsVisible() ==false)
980         {
981                 return false;
982         }
983
984         int pointId = touchinfo.GetPointId();
985         _TouchManager* pTouchManager = _TouchManager::GetInstance();
986
987         if (__touchPressed)
988         {
989                 FloatPoint touchPoint = touchinfo.GetCurrentPosition();
990                 float gap = touchPoint.y - __startTouchPoint.y;
991
992                 int touchGap = 0;
993                 if (__pWindow)
994                 {
995                         GET_SHAPE_CONFIG(FORM::INDICATOR_TOUCH_GAP, __pWindow->GetOrientation(), touchGap);
996                 }
997                 else
998                 {
999                         return false;
1000                 }
1001
1002                 if (gap < touchGap || __animationing)
1003                 {
1004                 }
1005                 else
1006                 {
1007                         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
1008                         {
1009                                 if (__portraitautohide)
1010                                 {
1011                                         ShowIndicatorEffect(true, ANIMATION_DURATION);
1012                                 }
1013                         }
1014                         else
1015                         {
1016                                 if (__landscapeautohide)
1017                                 {
1018                                         ShowIndicatorEffect(true, ANIMATION_DURATION);
1019                                 }
1020                         }
1021                 }
1022                 
1023                 if (pTouchManager->IsListenerOnly(pointId) == true)
1024                 {
1025                         r = true;
1026                 }
1027                 else
1028                 {
1029                         r = false;
1030                 }
1031         }
1032         else
1033         {
1034                 r = false;
1035         }
1036         return r;
1037 }
1038
1039 bool
1040 _Indicator::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1041 {
1042         return false;
1043 }
1044
1045 void
1046 _Indicator::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
1047 {
1048         String* pUserData = (String*) animation.GetUserData();
1049
1050         if ((pUserData != null) && (*pUserData == String(L"DownAnimation")))
1051         {
1052                 if (__pAnimationTimer == null)
1053                 {
1054                         __pAnimationTimer = new (std::nothrow) Timer;
1055                         if (__pAnimationTimer == null)
1056                         {
1057                                 return;
1058                         }
1059
1060                         result r = __pAnimationTimer->Construct(*this);
1061                         if (r != E_SUCCESS)
1062                         {
1063                                 delete __pAnimationTimer;
1064                                 __pAnimationTimer = null;
1065
1066                                 return;
1067                         }
1068                 }
1069
1070                 if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
1071                 {
1072                         if (__portraitautohide)
1073                         {
1074                                 __pAnimationTimer->Start(ANIMATION_INTERVAL);
1075                                 __animationing = true;
1076                         }
1077                 }
1078                 else
1079                 {
1080                         if (__landscapeautohide)
1081                         {
1082                                 __pAnimationTimer->Start(ANIMATION_INTERVAL);
1083                                 __animationing = true;
1084                         }
1085                 }
1086         }
1087 }
1088
1089 void
1090 _Indicator::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
1091 {
1092
1093 }
1094
1095 void
1096 _Indicator::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
1097 {
1098         String* pUserData = (String*) animation.GetUserData();
1099
1100         if ((pUserData != null) && (*pUserData == String(L"UpAnimation")))
1101         {
1102                 Color bgColor(0x00000000);
1103
1104                 int indicatorHeight = 0;
1105                 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, __pWindow->GetOrientation(), indicatorHeight);
1106                 SetBounds(FloatRectangle(0.0f, 0.0f, GetIndicatorBoundsF().width, indicatorHeight));
1107
1108                 if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
1109                 {
1110                         if (__portraitautohide)
1111                         {
1112                                 SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
1113                                 if (__pPortraitVisualElement && __portraitautohide)
1114                                 {
1115                                         __pPortraitVisualElement->SetShowState(false);
1116                                 }
1117                         }
1118                 }
1119                 else
1120                 {
1121                         if (__landscapeautohide)
1122                         {
1123                                 SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
1124                                 if (__pLandscapeVisualElement && __landscapeautohide)
1125                                 {
1126                                         __pLandscapeVisualElement->SetShowState(false);
1127                                 }
1128                         }
1129                 }
1130                 delete pUserData;
1131         }
1132 }
1133
1134 void
1135 _Indicator::Activate(void)
1136 {
1137         _UiEventManager::GetInstance()->AddTouchEventListener(*this);
1138
1139         return;
1140 }
1141
1142 void
1143 _Indicator::Deactivate(void)
1144 {
1145         _UiEventManager::GetInstance()->RemoveTouchEventListener(*this);
1146
1147         if (__pAnimationTimer)
1148         {
1149                 __pAnimationTimer->Cancel();
1150         }
1151         RemoveAllAnimations();
1152
1153         Ecore_X_Window win = 0;
1154         if (__pWindow)
1155         {
1156                 win = (Ecore_X_Window)__pWindow->GetNativeHandle();
1157         }
1158
1159         if (__orientation == _CONTROL_ORIENTATION_PORTRAIT)
1160         {
1161                 if (__portraitautohide)
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 (__pPortraitVisualElement)
1167                         {
1168                                 __pPortraitVisualElement->SetShowState(false);
1169                                 ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
1170                         }
1171                         __animationing = false;
1172                 }
1173         }
1174         else
1175         {
1176                 if (__landscapeautohide)
1177                 {
1178                         Color bgColor(0x00000000);
1179                         SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255.0f, (float)bgColor.GetGreen() / 255.0f, (float)bgColor.GetBlue() / 255.0f, (float)bgColor.GetAlpha() / 255.0f));
1180
1181                         if (__pLandscapeVisualElement)
1182                         {
1183                                 __pLandscapeVisualElement->SetShowState(false);
1184                                 ecore_x_e_illume_indicator_type_set(win, ECORE_X_ILLUME_INDICATOR_TYPE_2);
1185                         }
1186                         __animationing = false;
1187                 }
1188         }
1189
1190         return;
1191 }
1192
1193 }}} // Tizen::Ui::Controls