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 delete __pConfirmationPopup;
268 __pConfirmationPopup = null;
270 if (!__pConfirmationPopup)
272 __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
273 __pConfirmationPopup->Initialize();
275 __pConfirmationPopup->RemoveActionListener(*this);
276 __pConfirmationPopup->AddActionListener(*this);
277 __pConfirmationPopup->setMessage(closeWarning);
278 __pConfirmationPopup->Show();
282 case IDA_CONFIRMATION_NO:
284 __pConfirmationPopup->SetShowState(false);
285 __pConfirmationPopup->Show();
287 delete __pConfirmationPopup;
288 __pConfirmationPopup = null;
292 case IDA_CONFIRMATION_YES:
294 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
295 if (pAllWindowList == NULL)
299 int totalCount = pAllWindowList->GetCount();
301 for (int count = 0; count < totalCount; count++)
303 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
304 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
306 pAllWindowList->RemoveAll(true);
307 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
309 if (pNewWindowInfo == null)
313 result r = E_SUCCESS;
314 SceneManager* pSceneManager = SceneManager::GetInstance();
315 if (pSceneManager == NULL)
319 ArrayList* pArgList = new(std::nothrow) ArrayList();
320 if (pArgList == NULL)
324 r = pArgList->Construct();
327 pArgList->Add(*pNewWindowInfo);
328 result r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
329 if (pArgList != null)
336 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
340 __pConfirmationPopup->SetShowState(false);
341 __pConfirmationPopup->Show();
343 delete __pConfirmationPopup;
344 __pConfirmationPopup = null;
355 MultipleWindowForm::OnFormBackRequested(Form& source)
358 String* pSelectedScene = NULL;
359 Object* value = NULL;
361 SceneManager* pSceneManager = SceneManager::GetInstance();
362 if (pSceneManager == null)
367 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
368 pSelectedScene = (String*) value;
369 if (pSelectedScene != NULL)
371 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
372 // delete pSelectedScene;
375 AppLogDebug("MultipleWindowForm::OnFormBackRequested GoForward failed %s",GetErrorMessage(r));
383 MultipleWindowForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
389 MultipleWindowForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
391 result r = E_SUCCESS;
392 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
395 if (elementId == IDA_FORMAT_DELETE_BITMAP)
397 // get current scene ID and check if it is matching with deleted scene id
398 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
399 String* pSelectedScene = NULL;
400 Object* pValue = NULL;
404 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
405 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
406 pSelectedScene = (String*) pValue;
407 pAllWindowList->RemoveAt(index, true);
408 if (pSelectedScene->CompareTo(pWindowInfo->sceneID) == 0)
410 //set current scene id to last scene id
411 int totalCount = pAllWindowList->GetCount() - 1;
412 WindowInfo* pLastIndexWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(totalCount));
413 if (pLastIndexWindowInfo != NULL)
415 String* pSelectedSceneID = new(std::nothrow) String(pLastIndexWindowInfo->sceneID);
416 if (pSelectedSceneID != NULL)
418 MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) pSelectedSceneID);
425 count = MultipleWindowPresentationModel::GetInstance()->GetInstance()->GetAllWindowArrayList()->GetCount();
429 GetFooter()->SetItemEnabled(1,false);
433 GetFooter()->SetItemEnabled(1,true);
438 GetFooter()->SetItemEnabled(0,false);
441 GetFooter()->Invalidate(true);
442 __pList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
443 __pList->UpdateList();
445 else if(elementId == IDA_FORMAT_BITMAP || elementId == IDA_FORMAT_TITLE_STRING
446 || elementId == IDA_FORMAT_URL_STRING || elementId == -1)
449 // launch the browser
450 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
451 if (pWindowInfo == NULL)
455 SceneManager* pSceneManager = SceneManager::GetInstance();
456 if (pSceneManager == NULL)
460 ArrayList* pArgList = new(std::nothrow) ArrayList();
461 if (pArgList == NULL)
465 r = pArgList->Construct();
470 pArgList->Add(*pWindowInfo);
471 result r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
475 AppLogDebug("go forward success");
479 AppLogDebug("go forward failed");
481 if (pArgList != null)
493 MultipleWindowForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
499 MultipleWindowForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
505 MultipleWindowForm::CreateItem(int index, int itemWidth)
507 Rectangle listImageRect;
508 Rectangle pagetTitleRect;
509 Rectangle pageURLRect;
510 Rectangle deleteImageRect;
511 String pageTitle(L"");
513 result r = E_SUCCESS;
514 int width = W_ICON_IMAGE_WIDTH;
516 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
517 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
518 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
520 if (pAllWindowList == null)
524 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
525 if(pWindowInfo == null)
529 CustomItem* pItem = new(std::nothrow) CustomItem();
530 pageTitle = pWindowInfo->pageTitle;
531 pageURL = pWindowInfo->pageUrl;
532 if (pageURL.GetLength() == 0)
535 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", nourl);
536 pageURL = L"<"+ nourl +">";
539 if (pageTitle.GetLength() == 0)
542 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", pageTitle);
545 Rectangle screenBounds = GetBounds();
546 r = pItem->Construct(Dimension(itemWidth, 128 + (__fontSize - 44)), style);
552 if (pWindowInfo->pFavicon)
555 if( __pListIconImage != NULL)
557 delete __pListIconImage;
558 __pListIconImage = null;
561 __pListIconImage = new Bitmap();
562 __pListIconImage->Construct(*(pWindowInfo->pFavicon),Rectangle(0,0,pWindowInfo->pFavicon->GetWidth(),pWindowInfo->pFavicon->GetHeight()));
566 if( __pListIconImage != NULL)
568 delete __pListIconImage;
569 __pListIconImage = null;
572 __pListIconImage = pAppResource->GetBitmapN(L"I01_icon_default_favicon.png");
576 listImageRect.SetBounds(screenBounds.x + 16, screenBounds.y + 28 + (__fontSize - 44)/2,width, 72 );
577 pagetTitleRect.SetBounds(listImageRect.x + width + 16,10, screenBounds.width - 2 * width - 24 - 64, 72 + (__fontSize - 44));
578 pageURLRect.SetBounds(pagetTitleRect.x, pagetTitleRect.y + pagetTitleRect.height, screenBounds.width - 2 * width - 120, 48);
579 if(__pListDeleteImage != null)
581 deleteImageRect.SetBounds(screenBounds.width - __pListDeleteImage->GetWidth() - 24, (128 + (__fontSize - 44) - __pListDeleteImage->GetHeight() - 8)/2, __pListDeleteImage->GetWidth() + 8, __pListDeleteImage->GetHeight() + 8);
583 pItem->AddElement(listImageRect, IDA_FORMAT_BITMAP, *__pListIconImage, null, null);
585 if (pageTitle.CompareTo(L"") != 0)
587 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, pageTitle, __fontSize, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, true);
590 if (pageURL.CompareTo(L"") != 0)
592 pItem->AddElement(pageURLRect, IDA_FORMAT_URL_STRING, pageURL, 32, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, true);
597 if (pAllWindowList->GetCount() > 1)
599 pItem->AddElement(deleteImageRect, IDA_FORMAT_DELETE_BITMAP, *__pListDeleteImage, null, null);
600 pItem->SetElementSelectionEnabled(IDA_FORMAT_DELETE_BITMAP, true);
607 MultipleWindowForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
615 MultipleWindowForm::GetItemCount(void)
617 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
620 if (pAllWindowList != null)
622 windowCount = pAllWindowList->GetCount();
626 GetFooter()->SetItemEnabled(0, false);
630 GetFooter()->SetItemEnabled(0, true);
632 GetFooter()->Invalidate(true);
637 MultipleWindowForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
641 __pList->UpdateList();