2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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;
42 MultipleWindowForm::MultipleWindowForm(void)
44 , __pListIconImage(null)
45 , __pListDeleteImage(null)
49 MultipleWindowForm::~MultipleWindowForm(void)
53 delete __pListIconImage;
54 __pListIconImage = null;
56 if (__pListDeleteImage)
58 delete __pListDeleteImage;
59 __pListDeleteImage = null;
64 MultipleWindowForm::Initialize(void)
68 r = Construct(L"IDL_MULTIPLE_WINDOW");
80 MultipleWindowForm::OnInitializing(void)
83 FooterItem closeButton;
86 SceneManager* pSceneManager = SceneManager::GetInstance();
88 if (pSceneManager == null)
93 Footer* pFooter = GetFooter();
100 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
102 r = pSceneManager->AddSceneEventListener(IDSCN_MULTIPLE_WINDOW, *this);
104 // Setup back event listener
105 SetFormBackEventListener(this);
106 pFooter->AddActionEventListener(*this);
108 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
112 __pListIconImage = pAppResource->GetBitmapN(L"ListIcon.png");
113 __pListDeleteImage = pAppResource->GetBitmapN(L"deleteIcon.png");
116 __pList = static_cast< ListView* >(GetControl(L"IDC_LISTVIEW"));
120 __pList->SetItemProvider(*this);
121 __pList->AddListViewItemEventListener(*this);
124 AddOrientationEventListener(*this);
125 // r = pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
126 r = closeButton.Construct(IDA_BUTTON_CLOSEALL);
127 r = closeButton.SetText(CommonUtil::GetString(L"IDS_BR_CLOSE_ALL"));
128 r = pFooter->AddItem(closeButton);
129 r = newButton.Construct(IDA_BUTTON_NEW);
130 r = newButton.SetText(CommonUtil::GetString(L"IDS_BR_SK1_NEW_WINDOW"));
131 r = pFooter->AddItem(newButton);
137 MultipleWindowForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
139 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
141 GetFooter()->SetItemEnabled(1,false);
145 GetFooter()->SetItemEnabled(1,true);
149 __pList->UpdateList();
151 GetFooter()->Invalidate(true);
156 MultipleWindowForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
158 if (__pListIconImage)
160 delete __pListIconImage;
161 __pListIconImage = NULL;
167 MultipleWindowForm::OnTerminating(void)
169 result r = E_SUCCESS;
171 if (__pListIconImage)
173 delete __pListIconImage;
174 __pListIconImage = NULL;
176 if (__pListDeleteImage)
178 delete __pListDeleteImage;
179 __pListDeleteImage = NULL;
186 MultipleWindowForm::OnActionPerformed(const Control& source, int actionId)
188 SceneManager* pSceneManager = SceneManager::GetInstance();
190 if (pSceneManager == null)
195 String closeWarning = CommonUtil::GetString(L"IDS_BR_CLOSE_ALL_WINDOWS_Q");
201 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
203 if (pNewWindowInfo == null)
207 result r = E_SUCCESS;
208 SceneManager* pSceneManager = SceneManager::GetInstance();
209 if (pSceneManager == NULL)
213 ArrayList* pArgList = new(std::nothrow) ArrayList();
214 if (pArgList == NULL)
218 pArgList->Construct();
220 pArgList->Add(*pNewWindowInfo);
221 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
222 if (pArgList != null)
229 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
235 case IDA_BUTTON_BACK:
237 String* pSelectedScene = NULL;
238 Object* value = NULL;
239 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
240 pSelectedScene = (String*) value;
244 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
245 delete pSelectedScene;
246 pSelectedScene = null;
249 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
256 case IDA_BUTTON_CLOSEALL:
258 __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
259 __pConfirmationPopup->Initialize();
260 __pConfirmationPopup->RemoveActionListener(*this);
261 __pConfirmationPopup->AddActionListener(*this);
262 __pConfirmationPopup->setMessage(closeWarning);
263 __pConfirmationPopup->Show();
267 case IDA_CONFIRMATION_NO:
269 __pConfirmationPopup->SetShowState(false);
270 __pConfirmationPopup->Show();
273 case IDA_CONFIRMATION_YES:
275 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
276 if (pAllWindowList == NULL)
280 int totalCount = pAllWindowList->GetCount();
282 for (int count = 0; count < totalCount; count++)
284 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
285 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
287 pAllWindowList->RemoveAll(true);
288 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
290 if (pNewWindowInfo == null)
294 result r = E_SUCCESS;
295 SceneManager* pSceneManager = SceneManager::GetInstance();
296 if (pSceneManager == NULL)
300 ArrayList* pArgList = new(std::nothrow) ArrayList();
301 if (pArgList == NULL)
305 r = pArgList->Construct();
308 pArgList->Add(*pNewWindowInfo);
309 result r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
310 if (pArgList != null)
317 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
321 __pConfirmationPopup->SetShowState(false);
322 __pConfirmationPopup->Show();
332 MultipleWindowForm::OnFormBackRequested(Form& source)
335 String* pSelectedScene = NULL;
336 Object* value = NULL;
338 SceneManager* pSceneManager = SceneManager::GetInstance();
339 if (pSceneManager == null)
344 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
345 pSelectedScene = (String*) value;
346 if (pSelectedScene != NULL)
348 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
349 // delete pSelectedScene;
352 AppLogDebug("MultipleWindowForm::OnFormBackRequested GoForward failed %s",GetErrorMessage(r));
360 MultipleWindowForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
366 MultipleWindowForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
368 result r = E_SUCCESS;
369 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
372 if (elementId == IDA_FORMAT_DELETE_BITMAP)
374 // get current scene ID and check if it is matching with deleted scene id
375 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
376 String* pSelectedScene = NULL;
377 Object* pValue = NULL;
381 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
382 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
383 pSelectedScene = (String*) pValue;
384 pAllWindowList->RemoveAt(index, true);
385 if (pSelectedScene->CompareTo(pWindowInfo->sceneID) == 0)
387 //set current scene id to last scene id
388 int totalCount = pAllWindowList->GetCount() - 1;
389 WindowInfo* pLastIndexWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(totalCount));
390 if (pLastIndexWindowInfo != NULL)
392 String* pSelectedSceneID = new(std::nothrow) String(pLastIndexWindowInfo->sceneID);
393 if (pSelectedSceneID != NULL)
395 MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) pSelectedSceneID);
402 count = MultipleWindowPresentationModel::GetInstance()->GetInstance()->GetAllWindowArrayList()->GetCount();
406 GetFooter()->SetItemEnabled(1,false);
410 GetFooter()->SetItemEnabled(1,true);
415 GetFooter()->SetItemEnabled(0,false);
418 GetFooter()->Invalidate(true);
419 __pList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
420 __pList->UpdateList();
422 else if(elementId == IDA_FORMAT_BITMAP || elementId == IDA_FORMAT_TITLE_STRING
423 || elementId == IDA_FORMAT_URL_STRING || elementId == -1)
426 // launch the browser
427 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
428 if (pWindowInfo == NULL)
432 SceneManager* pSceneManager = SceneManager::GetInstance();
433 if (pSceneManager == NULL)
437 ArrayList* pArgList = new(std::nothrow) ArrayList();
438 if (pArgList == NULL)
442 r = pArgList->Construct();
447 pArgList->Add(*pWindowInfo);
448 result r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
452 AppLogDebug("go forward success");
456 AppLogDebug("go forward failed");
458 if (pArgList != null)
470 MultipleWindowForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
476 MultipleWindowForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
482 MultipleWindowForm::CreateItem(int index, int itemWidth)
484 Rectangle listImageRect;
485 Rectangle pagetTitleRect;
486 Rectangle pageURLRect;
487 Rectangle deleteImageRect;
488 String pageTitle(L"");
490 result r = E_SUCCESS;
493 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
494 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
495 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
497 if (pAllWindowList == null)
501 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
502 if(pWindowInfo == null)
506 CustomItem* pItem = new(std::nothrow) CustomItem();
507 pageTitle = pWindowInfo->pageTitle;
508 pageURL = pWindowInfo->pageUrl;
509 if (pageURL.GetLength() == 0)
512 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", nourl);
513 pageURL = L"<"+ nourl +">";
516 Rectangle screenBounds = GetBounds();
517 r = pItem->Construct(Dimension(itemWidth, 128), style);
523 if (pWindowInfo->pFavicon)
526 if( __pListIconImage != NULL)
528 delete __pListIconImage;
529 __pListIconImage = null;
532 __pListIconImage = new Bitmap();
533 __pListIconImage->Construct(*(pWindowInfo->pFavicon),Rectangle(0,0,pWindowInfo->pFavicon->GetWidth(),pWindowInfo->pFavicon->GetHeight()));
537 if( __pListIconImage != NULL)
539 delete __pListIconImage;
540 __pListIconImage = null;
543 __pListIconImage = pAppResource->GetBitmapN(L"I01_icon_default_favicon.png");
545 AppLog("deleteimg %d %d",__pListDeleteImage->GetWidth(),__pListDeleteImage->GetHeight());
547 listImageRect.SetBounds(screenBounds.x + 16, screenBounds.y + 28,width, 72);
548 pagetTitleRect.SetBounds(listImageRect.x + width + 16,10, screenBounds.width - 2 * width - 64, 60);
549 pageURLRect.SetBounds(pagetTitleRect.x, pagetTitleRect.y + pagetTitleRect.height, screenBounds.width - 2 * width - 120, 48);
550 deleteImageRect.SetBounds(screenBounds.width - __pListDeleteImage->GetWidth() - 24, (128 - __pListDeleteImage->GetHeight() - 8)/2, __pListDeleteImage->GetWidth() + 8, __pListDeleteImage->GetHeight() + 8);
551 pItem->AddElement(listImageRect, IDA_FORMAT_BITMAP, *__pListIconImage, null, null);
553 if (pageTitle.CompareTo(L"") != 0)
555 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, pageTitle, 44, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, true);
558 if (pageURL.CompareTo(L"") != 0)
560 pItem->AddElement(pageURLRect, IDA_FORMAT_URL_STRING, pageURL, 32, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, true);
565 if (pAllWindowList->GetCount() > 1)
567 pItem->AddElement(deleteImageRect, IDA_FORMAT_DELETE_BITMAP, *__pListDeleteImage, null, null);
568 pItem->SetElementSelectionEnabled(IDA_FORMAT_DELETE_BITMAP, true);
575 MultipleWindowForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
583 MultipleWindowForm::GetItemCount(void)
585 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
588 if (pAllWindowList != null)
590 windowCount = pAllWindowList->GetCount();
594 GetFooter()->SetItemEnabled(0, false);
598 GetFooter()->SetItemEnabled(0, true);
600 GetFooter()->Invalidate(true);
605 MultipleWindowForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
609 __pList->UpdateList();