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