Tizen 2.2.1
[framework/osp/web.git] / src / controls / FWebCtrl_SelectBox.cpp
index 6d8d94f..ac80e60 100755 (executable)
@@ -26,6 +26,7 @@
 #include <unique_ptr.h>
 #include <FBaseColAllElementsDeleter.h>
 #include <FBaseSysLog.h>
+#include <FCntDownloadRequest.h>
 #include <FGrpDimension.h>
 #include <FGrpRectangle.h>
 #include <FUiCtrlButton.h>
 #include <FUiIActionEventListener.h>
 #include <FUiKeyEventInfo.h>
 #include <FUiVerticalBoxLayout.h>
+#include <FCnt_DownloadManagerImpl.h>
 #include <FSys_SystemResource.h>
 #include <FUi_ResourceManager.h>
 #include "FWebCtrl_SelectBox.h"
+#include "FWebCtrl_WebImpl.h"
 
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
+using namespace Tizen::Content;
 using namespace Tizen::Graphics;
 using namespace Tizen::System;
 using namespace Tizen::Ui;
@@ -147,6 +151,8 @@ _SelectBox::_SelectBox(void)
        , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
        , __pWebView(null)
        , __pToggledArray(null)
+       , __url(L"")
+       , __pImpl(null)
 {
 }
 
@@ -164,7 +170,7 @@ _SelectBox::~_SelectBox(void)
 
 
 result
-_SelectBox::Construct(bool isMultiSelect, const String& title, int listCount, Evas_Object* pWebView)
+_SelectBox::Construct(Tizen::Web::Controls::_WebImpl* pImpl, bool isMultiSelect, const String& title, int listCount, Evas_Object* pWebView, const String& url)
 {
        result r = E_SUCCESS;
        Rectangle rect;
@@ -174,6 +180,8 @@ _SelectBox::Construct(bool isMultiSelect, const String& title, int listCount, Ev
        int listViewHeight = 0;
 
        __pWebView = pWebView;
+       __url = const_cast< String& >(url);
+       __pImpl = pImpl;
 
        GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, __orientation, listItemHeight);
 
@@ -182,7 +190,7 @@ _SelectBox::Construct(bool isMultiSelect, const String& title, int listCount, Ev
        _WebPopupData* pPopupData = _WebPopup::GetPopupData();
        SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-       listMaxHeihgt = listCount * listItemHeight + pPopupData->btnDim.height + pPopupData->spacePad;
+       listMaxHeihgt = listCount * listItemHeight;
 
        rect.height = listMaxHeihgt;
        rect.width = pPopupData->popupDim.width;
@@ -216,40 +224,32 @@ _SelectBox::Construct(bool isMultiSelect, const String& title, int listCount, Ev
 
        __pListView = pListView.release();
 
-       Panel* pButtonPanel = CreateAndAddPanel();
-       SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
-
-       _SystemResource* pSysResource = _SystemResource::GetInstance();
-       SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
-
-       ArrayList idList;
-       r = idList.Construct();
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
        if (__multiSelection)
        {
+               Panel* pButtonPanel = CreateAndAddPanel();
+               SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
+
+               _SystemResource* pSysResource = _SystemResource::GetInstance();
+               SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
+
+               ArrayList idList;
+               r = idList.Construct();
+               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
                idList.Add(*(new Integer(ID_BUTTON_SELECTION)));
-       }
-       idList.Add(*(new Integer(ID_BUTTON_CANCEL)));
 
-       ArrayList titleList;
-       r = titleList.Construct();
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-       if (__multiSelection)
-       {
-               titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_BODY_DONE"))));
+               ArrayList titleList;
+               r = titleList.Construct();
+               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
 
                __pToggledArray = eina_inarray_new(sizeof(int), 0);
                SysTryReturnResult(NID_WEB_CTRL, __pToggledArray, E_OUT_OF_MEMORY, "Memory Allocation failed.");
-       }
-       titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL"))));
 
-       r = CreateAndAddButtons(idList, titleList, pButtonPanel);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
-       SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
-
-       pLayout->SetSpacing(*pButtonPanel,  pPopupData->spacePad);
+               r = CreateAndAddButtons(idList, titleList, pButtonPanel);
+               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       }
 
        SetPropagatedKeyEventListener(this);
        
@@ -418,15 +418,33 @@ _SelectBox::OnListViewItemStateChanged(ListView& listView, int index, int elemen
        else
        {
                //In case of single selection ... update the index.
-               __SelectedIndex = index;
-               SysLog(NID_WEB_CTRL,"The current value of Update Selected index is %d",index);
-               if (__pWebView)
+               if (__url.GetLength() == 0)
                {
-                       ewk_view_popup_menu_select(__pWebView, __SelectedIndex);
+                       __SelectedIndex = index;
+                       SysLog(NID_WEB_CTRL,"The current value of Update Selected index is %d",index);
+                       if (__pWebView)
+                       {
+                               ewk_view_popup_menu_select(__pWebView, __SelectedIndex);
+                       }
+               }
+               else
+               {
+                       result r = E_SUCCESS;
+
+                       RequestId reqId = 0;
+                       DownloadRequest request(__url);
+
+                       _DownloadManagerImpl* pManagerImpl = _DownloadManagerImpl::GetInstance();
+                       SysTryReturnVoidResult(NID_WEB_CTRL, pManagerImpl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+                       r = pManagerImpl->Start(request, reqId);
+                       SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
                }
 
-               result r = HidePopup(__SelectedIndex);
+               result r = HidePopup();
                SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+               
+               __pImpl->SendUserEvent(ID_USER_SCRIPT_SELECTBOX_CLOSE, null);
        }
 }
 
@@ -441,37 +459,42 @@ _SelectBox::OnListViewItemSwept(ListView& listView, int index, SweepDirection di
 void
 _SelectBox::OnActionPerformed(const Control& source, int actionId)
 {
-       switch (actionId)
-       {
-       case ID_BUTTON_SELECTION:
-       {
-               ewk_view_popup_menu_multiple_select(__pWebView, __pToggledArray);
-               break;
-       }
-       case ID_BUTTON_CANCEL:
+       result r = HidePopup();
+       SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       if (__url.GetLength() == 0)
        {
-               if (__multiSelection)
+               switch (actionId)
+               {
+               case ID_BUTTON_SELECTION:
                {
-                       ewk_view_popup_menu_multiple_select(__pWebView, null);
+                       ewk_view_popup_menu_multiple_select(__pWebView, __pToggledArray);
+                       break;
                }
-               else
+               case ID_BUTTON_CANCEL:
                {
-                       ewk_view_popup_menu_select(__pWebView, __prevIndex);
+                       if (__multiSelection)
+                       {
+                               ewk_view_popup_menu_multiple_select(__pWebView, null);
+                       }
+                       else
+                       {
+                               ewk_view_popup_menu_select(__pWebView, __prevIndex);
+                       }
+                       break;
+               }
+               default:
+                       SysAssertf(false, "Invalid Action ID");
                }
-               break;
-       }
-       default:
-               SysAssertf(false, "Invalid Action ID");
        }
 
-       result r = HidePopup(__SelectedIndex);
-       SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+       __pImpl->SendUserEvent(ID_USER_SCRIPT_SELECTBOX_CLOSE, null);
 }
 
 bool
 _SelectBox::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
 {
-       return true;
+       return false;
 }
 
 bool
@@ -479,22 +502,28 @@ _SelectBox::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
 {
        if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
        {
-               if (__multiSelection)
-               {
-                       ewk_view_popup_menu_multiple_select(__pWebView, null);
-               }
-               else
-               {
-                       ewk_view_popup_menu_select(__pWebView, __prevIndex);
-               }
-               result r = HidePopup(__SelectedIndex);
+               result r = HidePopup();
                if (IsFailed(r))
                {
                        SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
                }
+
+               if (__url.GetLength() == 0)
+               {
+                       if (__multiSelection)
+                       {
+                               ewk_view_popup_menu_multiple_select(__pWebView, null);
+                       }
+                       else
+                       {
+                               ewk_view_popup_menu_select(__pWebView, __prevIndex);
+                       }
+               }
+
+               __pImpl->SendUserEvent(ID_USER_SCRIPT_SELECTBOX_CLOSE, null);
        }
 
-       return true;
+       return false;
 }
 
 bool