modify dynamic viewer sample
authorkeonpyo.kong <keonpyo.kong@samsung.com>
Mon, 20 May 2013 13:30:17 +0000 (22:30 +0900)
committerkeonpyo.kong <keonpyo.kong@samsung.com>
Mon, 20 May 2013 13:30:17 +0000 (22:30 +0900)
Change-Id: I85eef85acf226e5372d84e080a9701ceec9e6b1c
Signed-off-by: keonpyo.kong <keonpyo.kong@samsung.com>
project/inc/ViewForm.h
project/src/ViewForm.cpp

index 645ad8f..d7d03f0 100644 (file)
@@ -33,6 +33,7 @@ class ViewForm
        , public Tizen::Ui::Controls::IFormBackEventListener
        , public Tizen::Ui::Scenes::ISceneEventListener
        , public Tizen::Shell::IAppWidgetViewEventListener
+       , public Tizen::Ui::IPropagatedTouchEventListener
 {
 public:
        ViewForm(void);
@@ -40,6 +41,13 @@ public:
        bool Initialize();
        virtual result OnInitializing(void);
        virtual result OnTerminating(void);
+       virtual bool OnTouchPressed(Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo){}
+       virtual bool OnTouchReleased(Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo){}
+       virtual bool OnTouchMoved(Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo){}
+       virtual bool OnTouchCanceled(Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo){}
+       virtual bool OnPreviewTouchPressed(Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo);
+       virtual bool OnPreviewTouchReleased(Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo){}
+       virtual bool OnPreviewTouchMoved(Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo);
 
 private:
        void CreateAppWidgetView(const Tizen::Base::String& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& userInfo);
@@ -54,6 +62,12 @@ private:
        Tizen::Ui::Controls::ContextMenu* __pContextMenu;
        Tizen::Base::Collection::IList* __pSizeInfoList;
        static const int ID_FOOTER_ITEM1 = 1001;
+       static const int ID_FOOTER_BUTTON1 = 1002;
+       int __prevX;
+       int __prevY;
+       int __FooterItemIndex;
+       bool __isMoveMode;
+       Tizen::Ui::Controls::FooterItem* __pFooterItem;
 }; // ViewForm
 
 #endif // _VIEW_FORM_H_
index ab4e826..5f28a3c 100644 (file)
@@ -44,6 +44,11 @@ ViewForm::ViewForm(void)
        : __pAppWidgetView(null)
        , __pContextMenu(null)
        , __pSizeInfoList(null)
+       , __prevX(0)
+       , __prevY(0)
+       , __FooterItemIndex(1)
+       , __isMoveMode(false)
+       , __pFooterItem(null)
 {
 }
 
@@ -68,6 +73,12 @@ ViewForm::OnInitializing(void)
        SetFormBackEventListener(this);
        Footer* pFooter = GetFooter();
        pFooter->AddActionEventListener(*this);
+       SetPropagatedTouchEventListener(this);
+
+       __pFooterItem = new FooterItem();
+       __pFooterItem->Construct(ID_FOOTER_BUTTON1);
+       __pFooterItem->SetText(L"Move");
+       pFooter->AddItem(*__pFooterItem);
        return r;
 }
 
@@ -158,7 +169,31 @@ void
 ViewForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
 {
        AppLog("(%d)", actionId);
-
+       if(actionId == ID_FOOTER_BUTTON1)
+       {
+               Footer* pFooter = GetFooter();
+               String str = L"";
+               if (pFooter && __pFooterItem)
+               {
+                       pFooter->RemoveItemAt(__FooterItemIndex);
+               }
+               if (__isMoveMode == false)
+               {
+                       str = L"Done";
+                       __isMoveMode = true;
+               }
+               else
+               {
+                       str = L"Move";
+                       __isMoveMode = false;
+               }
+               __pFooterItem = new FooterItem();
+               __pFooterItem->Construct(ID_FOOTER_BUTTON1);
+               __pFooterItem->SetText(str);
+               pFooter->AddItem(*__pFooterItem);
+               Invalidate(true);
+               return;
+       }
        if (actionId == ID_FOOTER_ITEM1)
        {
                if (__pContextMenu && (__pContextMenu->GetItemCount() > 0))
@@ -178,7 +213,21 @@ ViewForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
                
                if (__pAppWidgetView)
                {
-                       __pAppWidgetView->SetSize(pSizeInfo->GetSize());
+                       FloatDimension dim = pSizeInfo->GetSize();
+                       Rectangle Rect = __pAppWidgetView->GetBounds();
+                       Rectangle ClientRect = GetClientAreaBounds();
+                       int newX = Rect.x;
+                       int newY = Rect.y;
+                       if(Rect.x + dim.width > ClientRect.width)
+                       {
+                               newX = ClientRect.width - dim.width;
+                       }
+                       if(Rect.y +  dim.height > ClientRect.height)
+                       {
+                               newY = ClientRect.height - dim.height;
+                       }
+
+                       __pAppWidgetView->SetBounds(Rectangle(newX,newY,dim.width,dim.height));
                }
        }
 }
@@ -244,3 +293,60 @@ ViewForm::OnAppWidgetProviderRemoved(Tizen::Shell::AppWidgetView &appWidgetView)
        notiMgr.NotifyTextMessage(L"AppWidget provider is removed due to provider error.");
 }
 
+bool
+ViewForm::OnPreviewTouchPressed(Control& source, const TouchEventInfo& touchEventInfo)
+{
+       Point curPos(touchEventInfo.GetCurrentPosition().x,touchEventInfo.GetCurrentPosition().y);
+       if (&source == __pAppWidgetView)
+       {
+               __prevX = curPos.x;
+               __prevY = curPos.y;
+       }
+       return true;
+}
+
+bool
+ViewForm::OnPreviewTouchMoved(Control& source, const TouchEventInfo& touchEventInfo)
+{
+       if (&source == __pAppWidgetView && __isMoveMode == true)
+       {
+               Touch touch;
+               Point curPos(touchEventInfo.GetCurrentPosition().x,touchEventInfo.GetCurrentPosition().y);
+
+               int gapX = curPos.x - __prevX;
+               int gapY = curPos.y - __prevY;
+
+               Point appWidgetPos = __pAppWidgetView->GetPosition();
+               Rectangle frameRec = __pAppWidgetView->GetBounds();
+               Rectangle clientRect = GetClientAreaBounds();
+
+               int newX = appWidgetPos.x + gapX;
+               int newY = appWidgetPos.y + gapY;
+
+               if(newX + frameRec.width > clientRect.width)
+               {
+                       newX = clientRect.width - frameRec.width;
+               }
+               if(newX < 0)
+               {
+                       newX = 0;
+               }
+               if (newY + frameRec.height > clientRect.height)
+               {
+                       newY = clientRect.height - frameRec.height;
+               }
+               if (newY < 0)
+               {
+                       newY = 0;
+               }
+               __pAppWidgetView->SetPosition(newX, newY);
+               __prevX = curPos.x;
+               __prevY = curPos.y;
+               return true;
+       }
+       else
+       {
+               return false;
+       }
+
+}