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