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)
51 MultipleWindowForm::~MultipleWindowForm(void)
55 delete __pListIconImage;
56 __pListIconImage = null;
58 if (__pListDeleteImage)
60 delete __pListDeleteImage;
61 __pListDeleteImage = null;
66 MultipleWindowForm::Initialize(void)
70 r = Construct(L"IDL_MULTIPLE_WINDOW");
82 MultipleWindowForm::OnInitializing(void)
85 FooterItem closeButton;
88 SceneManager* pSceneManager = SceneManager::GetInstance();
90 if (pSceneManager == null)
95 Footer* pFooter = GetFooter();
102 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
104 r = pSceneManager->AddSceneEventListener(IDSCN_MULTIPLE_WINDOW, *this);
106 // Setup back event listener
107 SetFormBackEventListener(this);
108 pFooter->AddActionEventListener(*this);
110 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
114 __pListIconImage = pAppResource->GetBitmapN(L"ListIcon.png");
115 __pListDeleteImage = pAppResource->GetBitmapN(L"deleteIcon.png");
118 __pList = static_cast< ListView* >(GetControl(L"IDC_LISTVIEW"));
122 __pList->SetItemProvider(*this);
123 __pList->AddListViewItemEventListener(*this);
126 AddOrientationEventListener(*this);
127 // r = pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
128 r = closeButton.Construct(IDA_BUTTON_CLOSEALL);
129 r = closeButton.SetText(CommonUtil::GetString(L"IDS_BR_CLOSE_ALL"));
130 r = pFooter->AddItem(closeButton);
131 r = newButton.Construct(IDA_BUTTON_NEW);
132 r = newButton.SetText(CommonUtil::GetString(L"IDS_BR_SK1_NEW_WINDOW"));
133 r = pFooter->AddItem(newButton);
139 MultipleWindowForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
141 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
143 GetFooter()->SetItemEnabled(1,false);
147 GetFooter()->SetItemEnabled(1,true);
151 __pList->UpdateList();
153 GetFooter()->Invalidate(true);
158 MultipleWindowForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
160 if (__pListIconImage)
162 delete __pListIconImage;
163 __pListIconImage = NULL;
169 MultipleWindowForm::OnTerminating(void)
171 result r = E_SUCCESS;
173 if (__pListIconImage)
175 delete __pListIconImage;
176 __pListIconImage = NULL;
178 if (__pListDeleteImage)
180 delete __pListDeleteImage;
181 __pListDeleteImage = NULL;
188 MultipleWindowForm::OnActionPerformed(const Control& source, int actionId)
190 SceneManager* pSceneManager = SceneManager::GetInstance();
192 if (pSceneManager == null)
197 String closeWarning = CommonUtil::GetString(L"IDS_BR_CLOSE_ALL_WINDOWS_Q");
203 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
205 if (pNewWindowInfo == null)
209 result r = E_SUCCESS;
210 SceneManager* pSceneManager = SceneManager::GetInstance();
211 if (pSceneManager == NULL)
215 ArrayList* pArgList = new(std::nothrow) ArrayList();
216 if (pArgList == NULL)
220 pArgList->Construct();
222 pArgList->Add(*pNewWindowInfo);
223 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
224 if (pArgList != null)
231 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
237 case IDA_BUTTON_BACK:
239 String* pSelectedScene = NULL;
240 Object* value = NULL;
241 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
242 pSelectedScene = (String*) value;
246 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
247 delete pSelectedScene;
248 pSelectedScene = null;
251 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
258 case IDA_BUTTON_CLOSEALL:
260 if (!__pConfirmationPopup)
262 __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
263 __pConfirmationPopup->Initialize();
265 __pConfirmationPopup->RemoveActionListener(*this);
266 __pConfirmationPopup->AddActionListener(*this);
267 __pConfirmationPopup->setMessage(closeWarning);
268 __pConfirmationPopup->Show();
272 case IDA_CONFIRMATION_NO:
274 __pConfirmationPopup->SetShowState(false);
275 __pConfirmationPopup->Show();
277 delete __pConfirmationPopup;
278 __pConfirmationPopup = null;
282 case IDA_CONFIRMATION_YES:
284 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
285 if (pAllWindowList == NULL)
289 int totalCount = pAllWindowList->GetCount();
291 for (int count = 0; count < totalCount; count++)
293 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
294 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
296 pAllWindowList->RemoveAll(true);
297 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
299 if (pNewWindowInfo == null)
303 result r = E_SUCCESS;
304 SceneManager* pSceneManager = SceneManager::GetInstance();
305 if (pSceneManager == NULL)
309 ArrayList* pArgList = new(std::nothrow) ArrayList();
310 if (pArgList == NULL)
314 r = pArgList->Construct();
317 pArgList->Add(*pNewWindowInfo);
318 result r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
319 if (pArgList != null)
326 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
330 __pConfirmationPopup->SetShowState(false);
331 __pConfirmationPopup->Show();
333 delete __pConfirmationPopup;
334 __pConfirmationPopup = null;
345 MultipleWindowForm::OnFormBackRequested(Form& source)
348 String* pSelectedScene = NULL;
349 Object* value = NULL;
351 SceneManager* pSceneManager = SceneManager::GetInstance();
352 if (pSceneManager == null)
357 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
358 pSelectedScene = (String*) value;
359 if (pSelectedScene != NULL)
361 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
362 // delete pSelectedScene;
365 AppLogDebug("MultipleWindowForm::OnFormBackRequested GoForward failed %s",GetErrorMessage(r));
373 MultipleWindowForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
379 MultipleWindowForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
381 result r = E_SUCCESS;
382 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
385 if (elementId == IDA_FORMAT_DELETE_BITMAP)
387 // get current scene ID and check if it is matching with deleted scene id
388 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
389 String* pSelectedScene = NULL;
390 Object* pValue = NULL;
394 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
395 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
396 pSelectedScene = (String*) pValue;
397 pAllWindowList->RemoveAt(index, true);
398 if (pSelectedScene->CompareTo(pWindowInfo->sceneID) == 0)
400 //set current scene id to last scene id
401 int totalCount = pAllWindowList->GetCount() - 1;
402 WindowInfo* pLastIndexWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(totalCount));
403 if (pLastIndexWindowInfo != NULL)
405 String* pSelectedSceneID = new(std::nothrow) String(pLastIndexWindowInfo->sceneID);
406 if (pSelectedSceneID != NULL)
408 MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) pSelectedSceneID);
415 count = MultipleWindowPresentationModel::GetInstance()->GetInstance()->GetAllWindowArrayList()->GetCount();
419 GetFooter()->SetItemEnabled(1,false);
423 GetFooter()->SetItemEnabled(1,true);
428 GetFooter()->SetItemEnabled(0,false);
431 GetFooter()->Invalidate(true);
432 __pList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
433 __pList->UpdateList();
435 else if(elementId == IDA_FORMAT_BITMAP || elementId == IDA_FORMAT_TITLE_STRING
436 || elementId == IDA_FORMAT_URL_STRING || elementId == -1)
439 // launch the browser
440 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
441 if (pWindowInfo == NULL)
445 SceneManager* pSceneManager = SceneManager::GetInstance();
446 if (pSceneManager == NULL)
450 ArrayList* pArgList = new(std::nothrow) ArrayList();
451 if (pArgList == NULL)
455 r = pArgList->Construct();
460 pArgList->Add(*pWindowInfo);
461 result r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
465 AppLogDebug("go forward success");
469 AppLogDebug("go forward failed");
471 if (pArgList != null)
483 MultipleWindowForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
489 MultipleWindowForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
495 MultipleWindowForm::CreateItem(int index, int itemWidth)
497 Rectangle listImageRect;
498 Rectangle pagetTitleRect;
499 Rectangle pageURLRect;
500 Rectangle deleteImageRect;
501 String pageTitle(L"");
503 result r = E_SUCCESS;
504 int width = W_ICON_IMAGE_WIDTH;
506 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
507 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
508 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
510 if (pAllWindowList == null)
514 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
515 if(pWindowInfo == null)
519 CustomItem* pItem = new(std::nothrow) CustomItem();
520 pageTitle = pWindowInfo->pageTitle;
521 pageURL = pWindowInfo->pageUrl;
522 if (pageURL.GetLength() == 0)
525 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", nourl);
526 pageURL = L"<"+ nourl +">";
529 if (pageTitle.GetLength() == 0)
532 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", pageTitle);
535 Rectangle screenBounds = GetBounds();
536 r = pItem->Construct(Dimension(itemWidth, 128), style);
542 if (pWindowInfo->pFavicon)
545 if( __pListIconImage != NULL)
547 delete __pListIconImage;
548 __pListIconImage = null;
551 __pListIconImage = new Bitmap();
552 __pListIconImage->Construct(*(pWindowInfo->pFavicon),Rectangle(0,0,pWindowInfo->pFavicon->GetWidth(),pWindowInfo->pFavicon->GetHeight()));
556 if( __pListIconImage != NULL)
558 delete __pListIconImage;
559 __pListIconImage = null;
562 __pListIconImage = pAppResource->GetBitmapN(L"I01_icon_default_favicon.png");
566 listImageRect.SetBounds(screenBounds.x + 16, screenBounds.y + 28,width, 72);
567 pagetTitleRect.SetBounds(listImageRect.x + width + 16,10, screenBounds.width - 2 * width - 24 - 64, 60);
568 pageURLRect.SetBounds(pagetTitleRect.x, pagetTitleRect.y + pagetTitleRect.height, screenBounds.width - 2 * width - 120, 48);
569 if(__pListDeleteImage != null)
571 deleteImageRect.SetBounds(screenBounds.width - __pListDeleteImage->GetWidth() - 24, (128 - __pListDeleteImage->GetHeight() - 8)/2, __pListDeleteImage->GetWidth() + 8, __pListDeleteImage->GetHeight() + 8);
573 pItem->AddElement(listImageRect, IDA_FORMAT_BITMAP, *__pListIconImage, null, null);
575 if (pageTitle.CompareTo(L"") != 0)
577 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, pageTitle, 44, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, true);
580 if (pageURL.CompareTo(L"") != 0)
582 pItem->AddElement(pageURLRect, IDA_FORMAT_URL_STRING, pageURL, 32, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, true);
587 if (pAllWindowList->GetCount() > 1)
589 pItem->AddElement(deleteImageRect, IDA_FORMAT_DELETE_BITMAP, *__pListDeleteImage, null, null);
590 pItem->SetElementSelectionEnabled(IDA_FORMAT_DELETE_BITMAP, true);
597 MultipleWindowForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
605 MultipleWindowForm::GetItemCount(void)
607 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
610 if (pAllWindowList != null)
612 windowCount = pAllWindowList->GetCount();
616 GetFooter()->SetItemEnabled(0, false);
620 GetFooter()->SetItemEnabled(0, true);
622 GetFooter()->Invalidate(true);
627 MultipleWindowForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
631 __pList->UpdateList();