2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 //!Internet MultipleWindowForm class
18 /*@file: MultipleWindowForm.cpp
19 *@brief: The MultipleWindowForm provides multiple instance of mainscenes and displays them in a Listview
23 #include <FAppUiApp.h>
24 #include <FUiScenes.h>
26 #include "IntCommonLib.h"
27 #include "IntConfirmationPopup.h"
28 #include "IntMainForm.h"
29 #include "IntMultipleWindowForm.h"
30 #include "IntMultipleWindowPresentationModel.h"
31 #include "IntSceneRegister.h"
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
41 static const int W_ICON_IMAGE_WIDTH = 72;
43 MultipleWindowForm::MultipleWindowForm(void)
45 , __pListIconImage(null)
46 , __pListDeleteImage(null)
47 ,__pConfirmationPopup(null)
49 __startPosition.x = -1;
50 __startPosition.y = -1;
54 MultipleWindowForm::~MultipleWindowForm(void)
58 delete __pListIconImage;
59 __pListIconImage = null;
61 if (__pListDeleteImage)
63 delete __pListDeleteImage;
64 __pListDeleteImage = null;
69 MultipleWindowForm::Initialize(void)
73 r = Construct(L"IDL_MULTIPLE_WINDOW");
85 MultipleWindowForm::OnInitializing(void)
88 FooterItem closeButton;
91 __fontSize = CommonUtil::GetFontSize();
92 SceneManager* pSceneManager = SceneManager::GetInstance();
94 if (pSceneManager == null)
99 Footer* pFooter = GetFooter();
106 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
108 r = pSceneManager->AddSceneEventListener(IDSCN_MULTIPLE_WINDOW, *this);
110 // Setup back event listener
111 SetFormBackEventListener(this);
112 pFooter->AddActionEventListener(*this);
114 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
118 __pListIconImage = pAppResource->GetBitmapN(L"ListIcon.png");
119 __pListDeleteImage = pAppResource->GetBitmapN(L"deleteIcon.png");
122 __pList = static_cast< ListView* >(GetControl(L"IDC_LISTVIEW"));
126 __pList->SetItemProvider(*this);
127 __pList->AddListViewItemEventListener(*this);
131 AddOrientationEventListener(*this);
132 // r = pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
133 r = closeButton.Construct(IDA_BUTTON_CLOSEALL);
134 r = closeButton.SetText(CommonUtil::GetString(L"IDS_BR_OPT_CLOSE_ALL"));
135 r = pFooter->AddItem(closeButton);
136 r = newButton.Construct(IDA_BUTTON_NEW);
137 r = newButton.SetText(CommonUtil::GetString(L"IDS_BR_OPT_NEW_WINDOW"));
138 r = pFooter->AddItem(newButton);
144 MultipleWindowForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
146 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
148 GetFooter()->SetItemEnabled(1,false);
152 GetFooter()->SetItemEnabled(1,true);
156 __pList->UpdateList();
158 GetFooter()->Invalidate(true);
163 MultipleWindowForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
165 if (__pListIconImage)
167 delete __pListIconImage;
168 __pListIconImage = NULL;
174 MultipleWindowForm::OnTerminating(void)
176 result r = E_SUCCESS;
178 if (__pListIconImage)
180 delete __pListIconImage;
181 __pListIconImage = NULL;
183 if (__pListDeleteImage)
185 delete __pListDeleteImage;
186 __pListDeleteImage = NULL;
193 MultipleWindowForm::OnActionPerformed(const Control& source, int actionId)
195 SceneManager* pSceneManager = SceneManager::GetInstance();
197 if (pSceneManager == null)
202 String closeWarning = CommonUtil::GetString(L"IDS_BR_POP_CLOSE_ALL_OPENED_WINDOWS_AND_GO_TO_THE_HOMEPAGE");
208 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
210 if (pNewWindowInfo == null)
214 result r = E_SUCCESS;
215 SceneManager* pSceneManager = SceneManager::GetInstance();
216 if (pSceneManager == NULL)
220 ArrayList* pArgList = new(std::nothrow) ArrayList();
221 if (pArgList == NULL)
225 pArgList->Construct();
227 pArgList->Add(*pNewWindowInfo);
228 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
229 if (pArgList != null)
236 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
242 case IDA_BUTTON_BACK:
244 String* pSelectedScene = NULL;
245 Object* value = NULL;
246 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
247 pSelectedScene = (String*) value;
251 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
252 delete pSelectedScene;
253 pSelectedScene = null;
256 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
263 case IDA_BUTTON_CLOSEALL:
265 if (!__pConfirmationPopup)
267 __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
268 __pConfirmationPopup->Initialize();
270 __pConfirmationPopup->RemoveActionListener(*this);
271 __pConfirmationPopup->AddActionListener(*this);
272 __pConfirmationPopup->setMessage(closeWarning);
273 __pConfirmationPopup->Show();
277 case IDA_CONFIRMATION_NO:
279 __pConfirmationPopup->SetShowState(false);
280 __pConfirmationPopup->Show();
282 delete __pConfirmationPopup;
283 __pConfirmationPopup = null;
287 case IDA_CONFIRMATION_YES:
289 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
290 if (pAllWindowList == NULL)
294 int totalCount = pAllWindowList->GetCount();
296 for (int count = 0; count < totalCount; count++)
298 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
299 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
301 pAllWindowList->RemoveAll(true);
302 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
304 if (pNewWindowInfo == null)
308 result r = E_SUCCESS;
309 SceneManager* pSceneManager = SceneManager::GetInstance();
310 if (pSceneManager == NULL)
314 ArrayList* pArgList = new(std::nothrow) ArrayList();
315 if (pArgList == NULL)
319 r = pArgList->Construct();
322 pArgList->Add(*pNewWindowInfo);
323 result r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
324 if (pArgList != null)
331 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
335 __pConfirmationPopup->SetShowState(false);
336 __pConfirmationPopup->Show();
338 delete __pConfirmationPopup;
339 __pConfirmationPopup = null;
350 MultipleWindowForm::OnFormBackRequested(Form& source)
353 String* pSelectedScene = NULL;
354 Object* value = NULL;
356 SceneManager* pSceneManager = SceneManager::GetInstance();
357 if (pSceneManager == null)
362 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
363 pSelectedScene = (String*) value;
364 if (pSelectedScene != NULL)
366 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
367 // delete pSelectedScene;
370 AppLogDebug("MultipleWindowForm::OnFormBackRequested GoForward failed %s",GetErrorMessage(r));
378 MultipleWindowForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
384 MultipleWindowForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
386 result r = E_SUCCESS;
387 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
390 if (elementId == IDA_FORMAT_DELETE_BITMAP)
392 // get current scene ID and check if it is matching with deleted scene id
393 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
394 String* pSelectedScene = NULL;
395 Object* pValue = NULL;
399 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
400 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
401 pSelectedScene = (String*) pValue;
402 pAllWindowList->RemoveAt(index, true);
403 if (pSelectedScene->CompareTo(pWindowInfo->sceneID) == 0)
405 //set current scene id to last scene id
406 int totalCount = pAllWindowList->GetCount() - 1;
407 WindowInfo* pLastIndexWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(totalCount));
408 if (pLastIndexWindowInfo != NULL)
410 String* pSelectedSceneID = new(std::nothrow) String(pLastIndexWindowInfo->sceneID);
411 if (pSelectedSceneID != NULL)
413 MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) pSelectedSceneID);
420 count = MultipleWindowPresentationModel::GetInstance()->GetInstance()->GetAllWindowArrayList()->GetCount();
424 GetFooter()->SetItemEnabled(1,false);
428 GetFooter()->SetItemEnabled(1,true);
433 GetFooter()->SetItemEnabled(0,false);
436 GetFooter()->Invalidate(true);
437 __pList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
438 __pList->UpdateList();
440 else if(elementId == IDA_FORMAT_BITMAP || elementId == IDA_FORMAT_TITLE_STRING
441 || elementId == IDA_FORMAT_URL_STRING || elementId == -1)
444 // launch the browser
445 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
446 if (pWindowInfo == NULL)
450 SceneManager* pSceneManager = SceneManager::GetInstance();
451 if (pSceneManager == NULL)
455 ArrayList* pArgList = new(std::nothrow) ArrayList();
456 if (pArgList == NULL)
460 r = pArgList->Construct();
465 pArgList->Add(*pWindowInfo);
466 result r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
470 AppLogDebug("go forward success");
474 AppLogDebug("go forward failed");
476 if (pArgList != null)
488 MultipleWindowForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
494 MultipleWindowForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
500 MultipleWindowForm::CreateItem(int index, int itemWidth)
502 Rectangle listImageRect;
503 Rectangle pagetTitleRect;
504 Rectangle pageURLRect;
505 Rectangle deleteImageRect;
506 String pageTitle(L"");
508 result r = E_SUCCESS;
509 int width = W_ICON_IMAGE_WIDTH;
511 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
512 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
513 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
515 if (pAllWindowList == null)
519 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
520 if(pWindowInfo == null)
524 CustomItem* pItem = new(std::nothrow) CustomItem();
525 pageTitle = pWindowInfo->pageTitle;
526 pageURL = pWindowInfo->pageUrl;
527 if (pageURL.GetLength() == 0)
530 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", nourl);
531 pageURL = L"<"+ nourl +">";
534 if (pageTitle.GetLength() == 0)
537 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", pageTitle);
540 Rectangle screenBounds = GetBounds();
541 r = pItem->Construct(Dimension(itemWidth, 128 + (__fontSize - 44)), style);
547 if (pWindowInfo->pFavicon)
550 if( __pListIconImage != NULL)
552 delete __pListIconImage;
553 __pListIconImage = null;
556 __pListIconImage = new Bitmap();
557 __pListIconImage->Construct(*(pWindowInfo->pFavicon),Rectangle(0,0,pWindowInfo->pFavicon->GetWidth(),pWindowInfo->pFavicon->GetHeight()));
561 if( __pListIconImage != NULL)
563 delete __pListIconImage;
564 __pListIconImage = null;
567 __pListIconImage = pAppResource->GetBitmapN(L"I01_icon_default_favicon.png");
571 listImageRect.SetBounds(screenBounds.x + 16, screenBounds.y + 28 + (__fontSize - 44)/2,width, 72 );
572 pagetTitleRect.SetBounds(listImageRect.x + width + 16,10, screenBounds.width - 2 * width - 24 - 64, 60 + (__fontSize - 44));
573 pageURLRect.SetBounds(pagetTitleRect.x, pagetTitleRect.y + pagetTitleRect.height, screenBounds.width - 2 * width - 120, 48);
574 if(__pListDeleteImage != null)
576 deleteImageRect.SetBounds(screenBounds.width - __pListDeleteImage->GetWidth() - 24, (128 + (__fontSize - 44) - __pListDeleteImage->GetHeight() - 8)/2, __pListDeleteImage->GetWidth() + 8, __pListDeleteImage->GetHeight() + 8);
578 pItem->AddElement(listImageRect, IDA_FORMAT_BITMAP, *__pListIconImage, null, null);
580 if (pageTitle.CompareTo(L"") != 0)
582 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, pageTitle, __fontSize, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, true);
585 if (pageURL.CompareTo(L"") != 0)
587 pItem->AddElement(pageURLRect, IDA_FORMAT_URL_STRING, pageURL, 32, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, true);
592 if (pAllWindowList->GetCount() > 1)
594 pItem->AddElement(deleteImageRect, IDA_FORMAT_DELETE_BITMAP, *__pListDeleteImage, null, null);
595 pItem->SetElementSelectionEnabled(IDA_FORMAT_DELETE_BITMAP, true);
602 MultipleWindowForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
610 MultipleWindowForm::GetItemCount(void)
612 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
615 if (pAllWindowList != null)
617 windowCount = pAllWindowList->GetCount();
621 GetFooter()->SetItemEnabled(0, false);
625 GetFooter()->SetItemEnabled(0, true);
627 GetFooter()->Invalidate(true);
632 MultipleWindowForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
636 __pList->UpdateList();