Apply gem
[platform/framework/native/shell.git] / src / FShell_AppWidgetView.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
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                FShell_AppWidgetView.cpp
19  * @brief               This is the implementation file for the _AppWidgetView class.
20  */
21
22 #include <new>
23 #include <errno.h>
24 #include <string.h>
25 #include <livebox.h>
26 #include <livebox-service.h>
27 #include <FBaseColLinkedListT.h>
28 #include <FBaseSysLog.h>
29 #include <FBaseString.h>
30 #include <FGrpBitmap.h>
31 #include <FGrpCanvas.h>
32 #include <FGrpDimension.h>
33 #include <FGrpPoint.h>
34 #include <FGrpRectangle.h>
35 #include <FUiAnimDisplayContext.h>
36 #include <FUiAnimVisualElementPropertyAnimation.h>
37 #include <FBase_StringConverter.h>
38 #include <FGrp_BitmapImpl.h>
39 #include <FMedia_ImageDecoder.h>
40 #include <FUi_TouchFlickGestureDetector.h>
41 #include <FUi_ResourceManager.h>
42 #include <FUi_CoordinateSystemUtils.h>
43 #include <FUiAnim_EflNode.h>
44 #include <FUiAnim_VisualElementImpl.h>
45 #include <FUiAnim_VisualElementSurfaceImpl.h>
46 #include <FUiCtrl_Frame.h>
47 #include "FShell_IAppWidgetViewEventListener.h"
48 #include "FShell_AppWidgetManagerImpl.h"
49 #include "FShell_AppWidgetView.h"
50 #include "FShell_AppWidgetViewPresenter.h"
51 #include "FShell_AppWidgetPopupView.h"
52 #include "FShell_AppWidgetViewManager.h"
53
54 using namespace std;
55 using namespace Tizen::App;
56 using namespace Tizen::Base;
57 using namespace Tizen::Base::Collection;
58 using namespace Tizen::Graphics;
59 using namespace Tizen::Ui;
60 using namespace Tizen::Ui::Controls;
61 using namespace Tizen::Ui::Animations;
62 using namespace Tizen::Media;
63
64 namespace Tizen { namespace Shell
65 {
66
67 const int ANIMATION_DURATION = 200;
68 const wchar_t* CLICK_ANIMATION = L"Click";
69 const wchar_t* FLICK_ANIMATION = L"Flick";
70
71 _AppWidgetView::_AppWidgetView(void)
72         : __pAppWidgetViewPresenter(new (std::nothrow) _AppWidgetViewPresenter(*this))
73         , __pAppWidget(null)
74         , __pAppWidgetViewManager(null)
75         , __resizeFromRemote(false)
76         , __updated(false)
77         , __pixmap(-1)
78         , __pAppWidgetViewEventListenerList(new (std::nothrow) LinkedListT<_IAppWidgetViewEventListener*>)
79 {
80         __pAppWidgetViewManager = _AppWidgetViewManager::GetInstance();
81         SysTryReturnVoidResult(NID_SHELL, __pAppWidgetViewManager, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
82 }
83
84 _AppWidgetView::~_AppWidgetView(void)
85 {
86         __pAppWidgetViewManager->RemoveAppWidgetView(this);
87
88         if (__pAppWidgetPopupView)
89         {
90                 __pAppWidgetPopupView->RemoveAppWidgetPopupEventListener(*this);
91         }
92
93         if (__pTouchFlickGestureDetector)
94         {
95                 RemoveGestureDetector(*__pTouchFlickGestureDetector);
96         }
97 }
98
99 _AppWidgetView*
100 _AppWidgetView::CreateAppWidgetViewN(void)
101 {
102         unique_ptr<_AppWidgetView> pAppWidgetView(new (std::nothrow) _AppWidgetView());
103         SysTryReturn(NID_SHELL, pAppWidgetView, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
104
105         result r = GetLastResult();
106         SysTryReturn(NID_SHELL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
107
108         pAppWidgetView->AcquireHandle();
109
110         SetLastResult(E_SUCCESS);
111
112         return pAppWidgetView.release();
113 }
114
115 result
116 _AppWidgetView::Initialize(const AppId& appId, const Tizen::Base::String& providerName, const Tizen::Graphics::FloatRectangle& rect, const String& userInfo)
117 {
118         SysLog(NID_SHELL, "appId [%ls]", appId.GetPointer());
119         SysLog(NID_SHELL, "providerName [%ls]", providerName.GetPointer());
120         SysLog(NID_SHELL, "[%d %d %d %d]", rect.x, rect.y, rect.width, rect.height);
121         SysLog(NID_SHELL, "userInfo [%ls]", userInfo.GetPointer());
122
123         result r = SetBounds(rect);
124         SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
125
126         r = __pAppWidgetViewPresenter->Initialize(appId, providerName);
127         SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
128
129         int width = 0;
130         int height = 0;
131
132         unique_ptr<ByteBuffer> pByteBuffer(_ImageDecoder::DecodeToBufferN(__pAppWidgetViewPresenter->GetAppIconPath(), MEDIA_PIXEL_FORMAT_BGRA8888, width, height));
133         unique_ptr<Bitmap> pBitmap(_BitmapImpl::GetNonScaledBitmapN(*pByteBuffer.get(), Dimension(width, height), BITMAP_PIXEL_FORMAT_ARGB8888));
134
135         __pAppIconBitmap = move(pBitmap);
136
137         __pAppWidget = __pAppWidgetViewManager->AddAppWidgetView(this, userInfo);
138         r = GetLastResult();
139         SysTryReturn(NID_SHELL, __pAppWidget, r, r, "[%s] Propagating.", GetErrorMessage(r));
140
141         if (!IsTouchEventEnabled())
142         {
143                 unique_ptr<_TouchFlickGestureDetector> pTouchFlickGestureDetector(new (std::nothrow) _TouchFlickGestureDetector());
144                 SysTryReturn(NID_SHELL, pTouchFlickGestureDetector, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
145
146                 pTouchFlickGestureDetector->SetDelayTouchEventEnabled(true);
147                 pTouchFlickGestureDetector->SetCancelTouchEventOnSuccessEnabled(true);
148
149                 r = AddGestureDetector(*pTouchFlickGestureDetector.get());
150                 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
151
152                 r = pTouchFlickGestureDetector->AddGestureListener(*this);
153                 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154
155                 __pTouchFlickGestureDetector = move(pTouchFlickGestureDetector);
156         }
157
158         Bitmap* pResourceBitmap = null;
159
160         r = GET_BITMAP_CONFIG_N(LIVEBOX::POPUP_BG_ARROW_UP, BITMAP_PIXEL_FORMAT_ARGB8888, pResourceBitmap);
161         SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
162
163         std::unique_ptr<Bitmap> pArrowUpBitmap(pResourceBitmap);
164
165         r = GET_BITMAP_CONFIG_N(LIVEBOX::POPUP_BG_ARROW_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, pResourceBitmap);
166         SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
167
168         __pArrowUpBitmap = move(pArrowUpBitmap);
169         __pArrowDownBitmap.reset(pResourceBitmap);
170
171         return r;
172 }
173
174 AppWidgetProviderInfo*
175 _AppWidgetView::GetAppWidgetProviderInfoN(void) const
176 {
177         AppWidgetProviderInfo* pProviderInfo = _AppWidgetManagerImpl::GetInstance()->GetAppWidgetProviderInfoN(GetAppId(), GetProviderName());
178         result r = GetLastResult();
179         SysTryReturn(NID_SHELL, pProviderInfo, null, r, "[%s] Propagating.", GetErrorMessage(r));
180         
181         return pProviderInfo;
182 }
183
184 result
185 _AppWidgetView::AddAppWidgetViewEventListener(_IAppWidgetViewEventListener& listener)
186 {
187         bool exist = __pAppWidgetViewEventListenerList->Contains(&listener);
188         SysTryReturn(NID_SHELL, exist == false, E_OBJ_ALREADY_EXIST, E_OBJ_ALREADY_EXIST, "[%s] Propagating.", GetErrorMessage(E_OBJ_ALREADY_EXIST));
189
190         __pAppWidgetViewEventListenerList->Add(&listener);
191
192         return E_SUCCESS;
193 }
194
195 result
196 _AppWidgetView::RemoveAppWidgetViewEventListener(_IAppWidgetViewEventListener& listener)
197 {
198         result r = __pAppWidgetViewEventListenerList->Remove(&listener);
199         SysTryReturn(NID_SHELL, r == E_SUCCESS, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] Propagating.", GetErrorMessage(E_OBJ_NOT_FOUND));
200
201         return E_SUCCESS;
202 }
203
204 _AppWidgetPopupView*
205 _AppWidgetView::GetAppWidgetPopup(void) const
206 {
207         return __pAppWidgetPopupView.get();
208 }
209
210 String
211 _AppWidgetView::GetAppId(void) const
212 {
213         return __pAppWidgetViewPresenter->GetAppId();
214 }
215
216 String
217 _AppWidgetView::GetAppWidgetId(void) const
218 {
219         return __pAppWidgetViewPresenter->GetAppWidgetId();
220 }
221
222 String
223 _AppWidgetView::GetProviderName(void) const
224 {
225         return __pAppWidgetViewPresenter->GetProviderName();
226 }
227
228 Bitmap*
229 _AppWidgetView::GetAppIconBitmap(void) const
230 {
231         return __pAppIconBitmap.get();
232 }
233
234 Bitmap*
235 _AppWidgetView::GetBitmap(void) const
236 {
237         return __pBitmap.get();
238 }
239
240 bool
241 _AppWidgetView::IsUpdated(void) const
242 {
243         return __updated;
244 }
245
246 FloatDimension
247 _AppWidgetView::GetAnchorSize(void) const
248 {
249         Bitmap* pArrowBitmap = null;
250         int lower = 0;
251         int upper = 0;
252
253         GetRemainingSpace(lower, upper);
254
255         if (lower > upper)
256         {
257                 pArrowBitmap = __pArrowDownBitmap.get();
258         }
259         else
260         {
261                 pArrowBitmap = __pArrowUpBitmap.get();
262         }
263
264         return FloatDimension(pArrowBitmap->GetWidth(), pArrowBitmap->GetHeight());
265 }
266
267 void
268 _AppWidgetView::CallProviderRemoved(void)
269 {
270         unique_ptr<IEnumeratorT<_IAppWidgetViewEventListener*> > pEnumerator(__pAppWidgetViewEventListenerList->GetEnumeratorN());
271         if (pEnumerator)
272         {
273                 while (pEnumerator->MoveNext() == E_SUCCESS)
274                 {
275                         _IAppWidgetViewEventListener* pListener = null;
276                         pEnumerator->GetCurrent(pListener);
277                         
278                         if (pListener)
279                         {
280                                 pListener->OnAppWidgetProviderRemoved(*this);
281                         }
282                 }
283         }
284 }
285
286 int
287 _AppWidgetView::GetPixmapId(void) const
288 {
289         return __pixmap;
290 }
291
292 livebox*
293 _AppWidgetView::GetNativeAppWidget(void) const
294 {
295         return __pAppWidget;
296 }
297
298 result
299 _AppWidgetView::OpenAppWidgetPopup(void)
300 {
301         result r = E_SUCCESS;
302
303         const _Control* pParent = GetParent();
304         r = GetLastResult();
305         SysTryReturn(NID_SHELL, pParent, r, r, "[%s] Propagating.", GetErrorMessage(r));
306
307         FloatDimension size = __pAppWidgetViewManager->GetAppWidgetPopupSize(__pAppWidget);
308         FloatRectangle popupBounds(0, 0, size.width, size.height);
309         FloatRectangle bounds = GetBoundsF();
310         FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
311
312         int lower = 0;
313         int upper = 0;
314
315         FloatDimension anchorSize = GetAnchorSize();
316         GetRemainingSpace(lower, upper);
317
318         if (lower > upper)
319         {
320                 popupBounds.y = absoluteBounds.y - size.height + anchorSize.height;
321         }
322         else
323         {
324                 popupBounds.y = absoluteBounds.y + absoluteBounds.height - anchorSize.height;
325         }
326
327         SysLog(NID_SHELL, "[%d %d]", popupBounds.y, size.height);
328
329         if (!__pAppWidgetPopupView)
330         {
331                 unique_ptr<_AppWidgetPopupView> pAppWidgetPopupView(_AppWidgetPopupView::CreateAppWidgetPopupN(*this));
332                 r = GetLastResult();
333                 SysTryReturn(NID_SHELL, pAppWidgetPopupView, r, r, "[%s] Propagating.", GetErrorMessage(r));
334
335                 r = pAppWidgetPopupView->Initialize(popupBounds);
336                 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
337
338                 r = pAppWidgetPopupView->AddAppWidgetPopupEventListener(*this);
339                 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
340
341                 __pAppWidgetPopupView = move(pAppWidgetPopupView);
342         }
343
344         __pAppWidgetPopupView->SetOwner(this);
345
346         r = __pAppWidgetPopupView->Open();
347         SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
348
349         return r;
350 }
351
352 void
353 _AppWidgetView::GetTouchPostion(const FloatPoint& point, double& x, double& y) const
354 {
355         FloatRectangle bounds = GetBoundsF();
356
357         x = static_cast<double>(point.x) / static_cast<double>(bounds.width);
358         y = static_cast<double>(point.y) / static_cast<double>(bounds.height);
359 }
360
361 void
362 _AppWidgetView::PlayClickAnimation(void)
363 {
364         VisualElementPropertyAnimation animation;
365         animation.SetPropertyName(L"transform.scale.xy");
366         animation.SetEndValue(Variant(FloatPoint(0.8f, 0.8f)));
367         animation.SetDuration(ANIMATION_DURATION);
368         animation.SetAutoReverseEnabled(true);
369
370         _VisualElement* pVisualElement = GetVisualElement();
371         result r = GetLastResult();
372         SysTryReturnVoidResult(NID_SHELL, pVisualElement, r, "[%s] Propagating.", GetErrorMessage(r));
373
374         pVisualElement->AddAnimation(CLICK_ANIMATION, animation);
375 }
376
377 void
378 _AppWidgetView::PlayFlickAnimation(void)
379 {
380         const int DISTANCE = 30;
381
382         _VisualElement* pVisualElement = GetVisualElement();
383         result r = GetLastResult();
384         SysTryReturnVoidResult(NID_SHELL, pVisualElement, r, "[%s] Propagating.", GetErrorMessage(r));
385
386         FloatRectangle startBounds(pVisualElement->GetBounds());
387         FloatRectangle endBounds(startBounds);
388         endBounds.y = startBounds.y + DISTANCE;
389
390         VisualElementPropertyAnimation animation;
391         animation.SetPropertyName(L"bounds");
392         animation.SetStartValue(Variant(startBounds));
393         animation.SetEndValue(Variant(endBounds));
394         animation.SetDuration(ANIMATION_DURATION);
395         animation.SetAutoReverseEnabled(true);
396         animation.SetVisualElementAnimationStatusEventListener(this);
397
398         pVisualElement->AddAnimation(FLICK_ANIMATION, animation);
399 }
400
401 void
402 _AppWidgetView::GetRemainingSpace(int& lower, int& upper) const
403 {
404         const _Control* pParent = GetParent();
405         result r = GetLastResult();
406         SysTryReturnVoidResult(NID_SHELL, pParent, r, "[%s] Propagating.", GetErrorMessage(r));
407
408         FloatRectangle parentClientBounds = pParent->GetClientBoundsF();
409         FloatRectangle viewBounds = GetBoundsF();
410
411         lower = viewBounds.y;
412         upper = parentClientBounds.height - viewBounds.y - viewBounds.height;
413
414         SysLog(NID_SHELL, "[%d %d]", lower, upper);
415 }
416
417 bool
418 _AppWidgetView::IsTouchEventEnabled(void) const
419 {
420         unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(GetAppId()));
421         int ret = livebox_service_mouse_event(pAppId.get());
422
423         return ( ret == 1 );
424 }
425
426 bool
427 _AppWidgetView::IsTouchEffectEnabled(void) const
428 {
429         unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(GetAppId()));
430         int sizeType = __pAppWidgetViewManager->GetAppWidgetSizeType(GetSizeF());
431         int ret = livebox_service_touch_effect(pAppId.get(), sizeType);
432
433         return ( ret == 1 );
434 }
435
436 result
437 _AppWidgetView::OnAttachedToMainTree(void)
438 {
439         result r = E_SUCCESS;
440
441         _Window* pWindow = _ControlManager::GetInstance()->GetCurrentFrame();
442         if (pWindow)
443         {
444                 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
445                 if (pFrame)
446                 {
447                         pFrame->AddFrameEventListener(*this);
448                 }
449
450                 __pAppWidgetViewManager->AddFrameEventListener();
451         }
452
453         return r;
454 }
455
456 result
457 _AppWidgetView::OnDetachingFromMainTree(void)
458 {
459         result r = E_SUCCESS;
460
461         _Window* pWindow = _ControlManager::GetInstance()->GetCurrentFrame();
462         if (pWindow)
463         {
464                 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
465                 if (pFrame)
466                 {
467                         pFrame->RemoveFrameEventListener(*this);
468                 }
469         }
470
471         return r;
472 }
473
474 void
475 _AppWidgetView::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
476 {
477 }
478
479 void
480 _AppWidgetView::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
481 {
482 }
483
484 void
485 _AppWidgetView::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
486 {
487 }
488
489 bool
490 _AppWidgetView::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
491 {
492         _FlickDirection direction = gesture.GetDirection();
493         if (direction == _FLICK_DIRECTION_DOWN)
494         {
495                 PlayFlickAnimation();
496                 OpenAppWidgetPopup();
497         }
498
499         return false;
500 }
501
502 bool
503 _AppWidgetView::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
504 {
505         return false;
506 }
507
508 void
509 _AppWidgetView::OnBoundsChanged(void)
510 {
511         FloatDimension size(GetSizeF());
512
513         if (!__resizeFromRemote)
514         {
515                 __pAppWidgetViewManager->SetAppWidgetSize(*this, size);
516                 __updated = false;
517         }
518 }
519
520 bool
521 _AppWidgetView::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
522 {
523         int type = livebox_lb_type(__pAppWidget);
524         if (((type == LB_TYPE_BUFFER) || (type == LB_TYPE_PIXMAP)) && IsTouchEventEnabled())
525         {
526                 double x = 0.0;
527                 double y = 0.0;
528
529                 Point position = _CoordinateSystemUtils::ConvertToInteger(touchInfo.GetCurrentPosition());
530                 GetTouchPostion(FloatPoint(static_cast<float>(position.x), static_cast<float>(position.y)), x, y);
531
532                 livebox_content_event(__pAppWidget, LB_MOUSE_DOWN, x, y);
533         }
534
535         return false;
536 }
537
538 bool
539 _AppWidgetView::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
540 {
541         FloatRectangle clientBounds(GetClientBoundsF());
542         Point position(_CoordinateSystemUtils::ConvertToInteger(touchInfo.GetCurrentPosition()));
543         FloatPoint floatPosition(static_cast<float>(position.x), static_cast<float>(position.y));
544
545         if (clientBounds.Contains(floatPosition) && IsTouchEffectEnabled())
546         {
547                 PlayClickAnimation();
548         }
549
550         double x = 0.0;
551         double y = 0.0;
552         GetTouchPostion(floatPosition, x, y);
553
554         int type = livebox_lb_type(__pAppWidget);
555          if (((type == LB_TYPE_BUFFER) || (type == LB_TYPE_PIXMAP)) && IsTouchEventEnabled())
556         {
557                 livebox_content_event(__pAppWidget, LB_MOUSE_UP, x, y);
558         }
559         
560         livebox_click(__pAppWidget, x, y);
561
562         return false;
563 }
564
565 bool
566 _AppWidgetView::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
567 {
568         int type = livebox_lb_type(__pAppWidget);
569          if (((type == LB_TYPE_BUFFER) || (type == LB_TYPE_PIXMAP)) && IsTouchEventEnabled())
570         {
571                 double x = 0.0;
572                 double y = 0.0;
573
574                 Point position = _CoordinateSystemUtils::ConvertToInteger(touchInfo.GetCurrentPosition());
575                 GetTouchPostion(FloatPoint(static_cast<float>(position.x), static_cast<float>(position.y)), x, y);
576
577                 livebox_content_event(__pAppWidget, LB_MOUSE_MOVE, x, y);
578         }
579
580         return false;
581 }
582
583 void
584 _AppWidgetView::OnAppWidgetPopupViewOpened(void)
585 {
586 }
587
588 void
589 _AppWidgetView::OnAppWidgetPopupViewClosed(void)
590 {
591         __pAppWidgetPopupView.reset(null);
592 }
593
594 void
595 _AppWidgetView::OnDraw(void)
596 {
597         __pAppWidgetViewPresenter->Draw();
598 }
599
600 void
601 _AppWidgetView::OnFrameActivated(const Tizen::Ui::Controls::_Frame& source)
602 {
603         if (__pAppWidget)
604         {
605                 livebox_set_visibility(__pAppWidget, LB_SHOW);
606         }
607 }
608
609 void
610 _AppWidgetView::OnFrameDeactivated(const Tizen::Ui::Controls::_Frame& source)
611 {
612         if (__pAppWidget)
613         {
614                 livebox_set_visibility(__pAppWidget, LB_HIDE_WITH_PAUSE);
615         }
616 }
617
618 void
619 _AppWidgetView::OnFrameMinimized(const Tizen::Ui::Controls::_Frame& source)
620 {
621 }
622
623 void
624 _AppWidgetView::OnFrameRestored(const Tizen::Ui::Controls::_Frame& source)
625 {
626 }
627
628 void
629 _AppWidgetView::OnAppWidgetUpdated(const Bitmap& bitmap, const FloatDimension& size)
630 {
631         __resizeFromRemote = true;
632         SetSize(size);
633         __resizeFromRemote = false;
634         __updated = true;
635
636         __pBitmap.reset(const_cast<Bitmap*>(&bitmap));
637
638         Invalidate(false);
639 }
640
641 void
642 _AppWidgetView::OnAppWidgetUpdated(int pixmap)
643 {
644         int x = 0;
645         int y = 0;
646         int width = 0;
647         int height = 0;
648
649         ecore_x_pixmap_geometry_get(pixmap, &x, &y, &width, &height);
650         SysTryReturnVoidResult(NID_SHELL, (width > 0) && (height > 0), E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid [0x%x %d %d].", pixmap, width , height);
651
652         if (__pixmap != pixmap )
653         {
654                 SetBackgroundColor(Color(0, 0, 0, 0));
655
656                 _VisualElement* pVisualElement = GetVisualElement();
657                 SysTryReturnVoidResult(NID_SHELL, pVisualElement, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
658
659                 _EflNode* pEflNode = dynamic_cast<_EflNode*>(pVisualElement->GetNativeNode());
660                 SysTryReturnVoidResult(NID_SHELL, pEflNode, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
661
662                 Evas_Object* pSmartObject = (Evas_Object*)pEflNode->GetGroupContainer();
663                 SysTryReturnVoidResult(NID_SHELL, pSmartObject, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
664
665                 Evas* pEvas = evas_object_evas_get(pSmartObject);
666                 SysTryReturnVoidResult(NID_SHELL, pEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
667
668                 __pPixmapObject.reset(evas_object_image_filled_add(pEvas));
669                 SysTryReturnVoidResult(NID_SHELL, __pPixmapObject, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
670
671                 _Window* pWindow = GetRootWindow();
672                 SysTryReturnVoidResult(NID_SHELL, pWindow, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
673
674                 DisplayContext* pDisplayContext = pWindow->GetDisplayContext();
675                 SysTryReturnVoidResult(NID_SHELL, pDisplayContext, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
676
677                 __pVisualElementSurface.reset(_VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(*pDisplayContext, (Handle)__pPixmapObject.get(), Dimension(width, height)));
678                 SysTryReturnVoidResult(NID_SHELL, __pVisualElementSurface, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
679
680                 unique_ptr<VisualElement, _VisualElementDeleter> pPixmapVisualElement(new (std::nothrow) VisualElement);
681                 SysTryReturnVoidResult(NID_SHELL, pPixmapVisualElement, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
682
683                 result r = pPixmapVisualElement->Construct();
684                 SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
685
686                 __pPixmapVisualElement = move(pPixmapVisualElement);
687                 __pPixmapVisualElement->SetImplicitAnimationEnabled(false);
688
689                 pVisualElement->AttachChild(__pPixmapVisualElement.get());
690
691                 __pPixmapVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, width, height));
692                 __pPixmapVisualElement->SetSurface(__pVisualElementSurface.get());
693                 __pPixmapVisualElement->SetShowState(true);
694
695                 evas_object_image_size_set(__pPixmapObject.get(), width, height);
696                 evas_object_image_colorspace_set(__pPixmapObject.get(), EVAS_COLORSPACE_ARGB8888);
697                 evas_object_image_alpha_set(__pPixmapObject.get(), EINA_TRUE);
698
699                 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
700
701                 evas_object_move(__pPixmapObject.get(), absoluteBounds.x, absoluteBounds.y);
702                 evas_object_show(__pPixmapObject.get());
703
704                 Evas_Native_Surface surface;
705
706                 surface.version = EVAS_NATIVE_SURFACE_VERSION;
707                 surface.type = EVAS_NATIVE_SURFACE_X11;
708                 surface.data.x11.visual = ecore_x_default_visual_get(ecore_x_display_get(), ecore_x_default_screen_get());
709                 surface.data.x11.pixmap = pixmap;
710
711                 evas_object_image_native_surface_set(__pPixmapObject.get(), &surface);
712 /*
713                 __pixmapDamage.reset(ecore_x_damage_new(pixmap, ECORE_X_DAMAGE_REPORT_RAW_RECTANGLES));
714                 SysTryReturnVoidResult(NID_SHELL, __pixmapDamage.get() != 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
715
716                 __pPixmapEventHandler.reset(ecore_event_handler_add(ECORE_X_EVENT_DAMAGE_NOTIFY, OnPixmapDamaged, (void*)this));
717                 SysTryReturnVoidResult(NID_SHELL, __pPixmapEventHandler, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
718 */
719                 SysLog(NID_SHELL, "[0x%x][%f %f]", surface.data.x11.pixmap, absoluteBounds.x, absoluteBounds.y);
720         }
721
722         SysLog(NID_SHELL, "[%d %d %d %d]", x, y, width, height);
723
724         evas_object_image_size_set(__pPixmapObject.get(), width, height);
725         evas_object_image_pixels_dirty_set(__pPixmapObject.get(), EINA_TRUE);
726         evas_object_image_fill_set(__pPixmapObject.get(), 0, 0, width, height);
727         evas_object_image_data_update_add(__pPixmapObject.get(), 0, 0, width, height);
728         evas_object_resize(__pPixmapObject.get(), width, height);
729
730         __resizeFromRemote = true;
731         SetSize(FloatDimension(static_cast<float>(width), static_cast<float>(height)));
732         __resizeFromRemote = false;
733         __updated = true;
734
735         __pixmap = pixmap;
736 }
737
738 Eina_Bool
739 _AppWidgetView::OnPixmapDamaged(void* pData, int type, void* pEvent)
740 {
741         _AppWidgetView* pAppWidgetView = static_cast<_AppWidgetView*>(pData);
742         SysTryReturn(NID_SHELL, pAppWidgetView != null, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[[E_INVALID_ARG] The argument is invalid.");
743
744         Ecore_X_Event_Damage* pDamageEvent = static_cast<Ecore_X_Event_Damage*>(pEvent);
745         SysTryReturn(NID_SHELL, pDamageEvent != null, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
746
747         unsigned int pixmap = static_cast<unsigned int>(pAppWidgetView->__pixmap);
748         SysTryReturn(NID_SHELL, pDamageEvent->drawable == pixmap, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid [%d %d].", pDamageEvent->drawable, pixmap);
749
750         int x = 0;
751         int y = 0;
752         int width = 0;
753         int height = 0;
754
755         ecore_x_pixmap_geometry_get(pixmap, &x, &y, &width, &height);
756         SysTryReturn(NID_SHELL, (width > 0) && (height > 0), ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid [0x%x %d %d].", pixmap, width , height);
757
758         Evas_Object* pPixmapObject = pAppWidgetView->__pPixmapObject.get();
759         SysTryReturn(NID_SHELL, pPixmapObject, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
760
761         evas_object_image_pixels_dirty_set(pPixmapObject, EINA_TRUE);
762         evas_object_image_fill_set(pPixmapObject, 0, 0, width, height);
763         evas_object_image_data_update_add(pPixmapObject, 0, 0, width, height);
764
765         SysLog(NID_SHELL, "[%d %d %d]", pixmap, width, height);
766
767         return ECORE_CALLBACK_DONE;
768 }
769
770 }} // Tizen::Shell