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"
32 #include "IntSettingPresentationModel.h"
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
42 static const int W_ICON_IMAGE_WIDTH = 72;
44 MultipleWindowForm::MultipleWindowForm(void)
46 , __pListIconImage(null)
47 , __pListDeleteImage(null)
48 ,__pConfirmationPopup(null)
50 __startPosition.x = -1;
51 __startPosition.y = -1;
55 MultipleWindowForm::~MultipleWindowForm(void)
59 delete __pListIconImage;
60 __pListIconImage = null;
62 if (__pListDeleteImage)
64 delete __pListDeleteImage;
65 __pListDeleteImage = null;
70 MultipleWindowForm::Initialize(void)
74 r = Construct(L"IDL_MULTIPLE_WINDOW");
86 MultipleWindowForm::OnInitializing(void)
89 FooterItem closeButton;
92 __fontSize = CommonUtil::GetFontSize();
93 SceneManager* pSceneManager = SceneManager::GetInstance();
95 if (pSceneManager == null)
100 Footer* pFooter = GetFooter();
107 // SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
109 r = pSceneManager->AddSceneEventListener(IDSCN_MULTIPLE_WINDOW, *this);
111 // Setup back event listener
112 SetFormBackEventListener(this);
113 pFooter->AddActionEventListener(*this);
115 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
119 __pListIconImage = pAppResource->GetBitmapN(L"ListIcon.png");
120 __pListDeleteImage = pAppResource->GetBitmapN(L"deleteIcon.png");
123 __pList = static_cast< ListView* >(GetControl(L"IDC_LISTVIEW"));
127 __pList->SetItemProvider(*this);
128 __pList->AddListViewItemEventListener(*this);
132 AddOrientationEventListener(*this);
133 // r = pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
134 r = closeButton.Construct(IDA_BUTTON_CLOSEALL);
135 r = closeButton.SetText(CommonUtil::GetString(L"IDS_BR_OPT_CLOSE_ALL"));
136 r = pFooter->AddItem(closeButton);
137 r = newButton.Construct(IDA_BUTTON_NEW);
138 r = newButton.SetText(CommonUtil::GetString(L"IDS_BR_OPT_NEW_WINDOW"));
139 r = pFooter->AddItem(newButton);
145 MultipleWindowForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
147 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
149 GetFooter()->SetItemEnabled(1,false);
153 GetFooter()->SetItemEnabled(1,true);
157 __pList->UpdateList();
159 GetFooter()->Invalidate(true);
164 MultipleWindowForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
166 if (__pListIconImage)
168 delete __pListIconImage;
169 __pListIconImage = NULL;
175 MultipleWindowForm::OnTerminating(void)
177 result r = E_SUCCESS;
179 if (__pListIconImage)
181 delete __pListIconImage;
182 __pListIconImage = NULL;
184 if (__pListDeleteImage)
186 delete __pListDeleteImage;
187 __pListDeleteImage = NULL;
194 MultipleWindowForm::OnActionPerformed(const Control& source, int actionId)
196 SceneManager* pSceneManager = SceneManager::GetInstance();
198 if (pSceneManager == null)
203 String closeWarning = CommonUtil::GetString(L"IDS_BR_POP_CLOSE_ALL_OPENED_WINDOWS_AND_GO_TO_THE_HOMEPAGE");
209 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
211 if (pNewWindowInfo == null)
215 result r = E_SUCCESS;
216 SceneManager* pSceneManager = SceneManager::GetInstance();
217 if (pSceneManager == NULL)
221 ArrayList* pArgList = new(std::nothrow) ArrayList();
222 if (pArgList == NULL)
226 pArgList->Construct();
228 pArgList->Add(*pNewWindowInfo);
229 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
230 if (pArgList != null)
237 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
243 case IDA_BUTTON_BACK:
245 String* pSelectedScene = NULL;
246 Object* value = NULL;
247 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
248 pSelectedScene = (String*) value;
252 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
253 delete pSelectedScene;
254 pSelectedScene = null;
257 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
264 case IDA_BUTTON_CLOSEALL:
266 if(__pConfirmationPopup)
268 delete __pConfirmationPopup;
269 __pConfirmationPopup = null;
271 if (!__pConfirmationPopup)
273 __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
274 __pConfirmationPopup->Initialize();
276 __pConfirmationPopup->RemoveActionListener(*this);
277 __pConfirmationPopup->AddActionListener(*this);
278 __pConfirmationPopup->setMessage(closeWarning);
279 __pConfirmationPopup->Show();
283 case IDA_CONFIRMATION_NO:
285 __pConfirmationPopup->SetShowState(false);
286 __pConfirmationPopup->Show();
288 delete __pConfirmationPopup;
289 __pConfirmationPopup = null;
293 case IDA_CONFIRMATION_YES:
295 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
296 if (pAllWindowList == NULL)
300 int totalCount = pAllWindowList->GetCount();
302 for (int count = 0; count < totalCount; count++)
304 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
305 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
307 pAllWindowList->RemoveAll(true);
308 String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
309 if (homePage == (L"IDS_BR_BODY_MOST_VISITED_SITES") || homePage == (L"IDS_BR_BODY_BLANK_PAGE"))
313 else if (homePage == CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"))
315 AppLog("InternetApp::OnAppInitialized homaepage = userhomepage");
316 homePage = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
317 AppLog("InternetApp::OnAppInitialized fav URL = %ls ",homePage.GetPointer());
320 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(homePage);
322 if (pNewWindowInfo == null)
326 pNewWindowInfo->isAppcontrolTriggered = true;
327 result r = E_SUCCESS;
328 SceneManager* pSceneManager = SceneManager::GetInstance();
329 if (pSceneManager == NULL)
333 ArrayList* pArgList = new(std::nothrow) ArrayList();
334 if (pArgList == NULL)
338 r = pArgList->Construct();
341 pArgList->Add(*pNewWindowInfo);
342 result r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
343 if (pArgList != null)
350 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
354 __pConfirmationPopup->SetShowState(false);
355 __pConfirmationPopup->Show();
357 delete __pConfirmationPopup;
358 __pConfirmationPopup = null;
369 MultipleWindowForm::OnFormBackRequested(Form& source)
372 String* pSelectedScene = NULL;
373 Object* value = NULL;
375 SceneManager* pSceneManager = SceneManager::GetInstance();
376 if (pSceneManager == null)
381 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
382 pSelectedScene = (String*) value;
383 if (pSelectedScene != NULL)
385 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
386 // delete pSelectedScene;
389 AppLogDebug("MultipleWindowForm::OnFormBackRequested GoForward failed %s",GetErrorMessage(r));
397 MultipleWindowForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
403 MultipleWindowForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
405 result r = E_SUCCESS;
406 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
409 if (elementId == IDA_FORMAT_DELETE_BITMAP)
411 // get current scene ID and check if it is matching with deleted scene id
412 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
413 String* pSelectedScene = NULL;
414 Object* pValue = NULL;
418 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
419 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
420 pSelectedScene = (String*) pValue;
421 pAllWindowList->RemoveAt(index, true);
422 if (pSelectedScene->CompareTo(pWindowInfo->sceneID) == 0)
424 //set current scene id to last scene id
425 int totalCount = pAllWindowList->GetCount() - 1;
426 WindowInfo* pLastIndexWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(totalCount));
427 if (pLastIndexWindowInfo != NULL)
429 String* pSelectedSceneID = new(std::nothrow) String(pLastIndexWindowInfo->sceneID);
430 if (pSelectedSceneID != NULL)
432 MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) pSelectedSceneID);
439 count = MultipleWindowPresentationModel::GetInstance()->GetInstance()->GetAllWindowArrayList()->GetCount();
443 GetFooter()->SetItemEnabled(1,false);
447 GetFooter()->SetItemEnabled(1,true);
452 GetFooter()->SetItemEnabled(0,false);
455 GetFooter()->Invalidate(true);
456 __pList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
457 __pList->UpdateList();
459 else if(elementId == IDA_FORMAT_BITMAP || elementId == IDA_FORMAT_TITLE_STRING
460 || elementId == IDA_FORMAT_URL_STRING || elementId == -1)
463 // launch the browser
464 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
465 if (pWindowInfo == NULL)
469 SceneManager* pSceneManager = SceneManager::GetInstance();
470 if (pSceneManager == NULL)
474 ArrayList* pArgList = new(std::nothrow) ArrayList();
475 if (pArgList == NULL)
479 r = pArgList->Construct();
484 pArgList->Add(*pWindowInfo);
485 result r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
489 AppLogDebug("go forward success");
493 AppLogDebug("go forward failed");
495 if (pArgList != null)
507 MultipleWindowForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
513 MultipleWindowForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
519 MultipleWindowForm::CreateItem(int index, int itemWidth)
521 Rectangle listImageRect;
522 Rectangle pagetTitleRect;
523 Rectangle pageURLRect;
524 Rectangle deleteImageRect;
525 String pageTitle(L"");
527 result r = E_SUCCESS;
528 int width = W_ICON_IMAGE_WIDTH;
530 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
531 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
532 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
534 if (pAllWindowList == null)
538 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
539 if(pWindowInfo == null)
543 CustomItem* pItem = new(std::nothrow) CustomItem();
544 pageTitle = pWindowInfo->pageTitle;
545 pageURL = pWindowInfo->pageUrl;
546 if (pageURL.GetLength() == 0)
549 pAppResource->GetString(L"IDS_BR_BODY_BLANK_PAGE", nourl);
550 pageURL = L"<"+ nourl +">";
553 if (pageTitle.GetLength() == 0)
556 pAppResource->GetString(L"IDS_BR_BODY_BLANK_PAGE", pageTitle);
559 Rectangle screenBounds = GetBounds();
560 r = pItem->Construct(Dimension(itemWidth, 128 + (__fontSize - 44)), style);
566 if (pWindowInfo->pFavicon)
569 if( __pListIconImage != NULL)
571 delete __pListIconImage;
572 __pListIconImage = null;
575 __pListIconImage = new Bitmap();
576 __pListIconImage->Construct(*(pWindowInfo->pFavicon),Rectangle(0,0,pWindowInfo->pFavicon->GetWidth(),pWindowInfo->pFavicon->GetHeight()));
580 if( __pListIconImage != NULL)
582 delete __pListIconImage;
583 __pListIconImage = null;
586 __pListIconImage = pAppResource->GetBitmapN(L"I01_icon_default_favicon.png");
590 listImageRect.SetBounds(screenBounds.x + 16, screenBounds.y + 28 + (__fontSize - 44)/2,width, 72 );
591 pagetTitleRect.SetBounds(listImageRect.x + width + 16,10, screenBounds.width - 2 * width - 24 - 64, 72 + (__fontSize - 44));
592 pageURLRect.SetBounds(pagetTitleRect.x, pagetTitleRect.y + pagetTitleRect.height, screenBounds.width - 2 * width - 120, 48);
593 if(__pListDeleteImage != null)
595 deleteImageRect.SetBounds(screenBounds.width - __pListDeleteImage->GetWidth() - 24, (128 + (__fontSize - 44) - __pListDeleteImage->GetHeight() - 8)/2, __pListDeleteImage->GetWidth() + 8, __pListDeleteImage->GetHeight() + 8);
597 pItem->AddElement(listImageRect, IDA_FORMAT_BITMAP, *__pListIconImage, null, null);
599 if (pageTitle.CompareTo(L"") != 0)
601 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, pageTitle, __fontSize, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, true);
604 if (pageURL.CompareTo(L"") != 0)
606 pItem->AddElement(pageURLRect, IDA_FORMAT_URL_STRING, pageURL, 32, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, true);
611 if (pAllWindowList->GetCount() > 1)
613 pItem->AddElement(deleteImageRect, IDA_FORMAT_DELETE_BITMAP, *__pListDeleteImage, null, null);
614 pItem->SetElementSelectionEnabled(IDA_FORMAT_DELETE_BITMAP, true);
621 MultipleWindowForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
629 MultipleWindowForm::GetItemCount(void)
631 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
634 if (pAllWindowList != null)
636 windowCount = pAllWindowList->GetCount();
640 GetFooter()->SetItemEnabled(0, false);
644 GetFooter()->SetItemEnabled(0, true);
646 GetFooter()->Invalidate(true);
651 MultipleWindowForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
655 __pList->UpdateList();