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;
53 MultipleWindowForm::~MultipleWindowForm(void)
57 delete __pListIconImage;
58 __pListIconImage = null;
60 if (__pListDeleteImage)
62 delete __pListDeleteImage;
63 __pListDeleteImage = null;
68 MultipleWindowForm::Initialize(void)
72 r = Construct(L"IDL_MULTIPLE_WINDOW");
84 MultipleWindowForm::OnInitializing(void)
87 FooterItem closeButton;
90 SceneManager* pSceneManager = SceneManager::GetInstance();
92 if (pSceneManager == null)
97 Footer* pFooter = GetFooter();
104 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
106 r = pSceneManager->AddSceneEventListener(IDSCN_MULTIPLE_WINDOW, *this);
108 // Setup back event listener
109 SetFormBackEventListener(this);
110 pFooter->AddActionEventListener(*this);
112 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
116 __pListIconImage = pAppResource->GetBitmapN(L"ListIcon.png");
117 __pListDeleteImage = pAppResource->GetBitmapN(L"deleteIcon.png");
120 __pList = static_cast< ListView* >(GetControl(L"IDC_LISTVIEW"));
124 __pList->SetItemProvider(*this);
125 __pList->AddListViewItemEventListener(*this);
129 AddOrientationEventListener(*this);
130 // r = pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
131 r = closeButton.Construct(IDA_BUTTON_CLOSEALL);
132 r = closeButton.SetText(CommonUtil::GetString(L"IDS_BR_CLOSE_ALL"));
133 r = pFooter->AddItem(closeButton);
134 r = newButton.Construct(IDA_BUTTON_NEW);
135 r = newButton.SetText(CommonUtil::GetString(L"IDS_BR_SK1_NEW_WINDOW"));
136 r = pFooter->AddItem(newButton);
142 MultipleWindowForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
144 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
146 GetFooter()->SetItemEnabled(1,false);
150 GetFooter()->SetItemEnabled(1,true);
154 __pList->UpdateList();
156 GetFooter()->Invalidate(true);
161 MultipleWindowForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
163 if (__pListIconImage)
165 delete __pListIconImage;
166 __pListIconImage = NULL;
172 MultipleWindowForm::OnTerminating(void)
174 result r = E_SUCCESS;
176 if (__pListIconImage)
178 delete __pListIconImage;
179 __pListIconImage = NULL;
181 if (__pListDeleteImage)
183 delete __pListDeleteImage;
184 __pListDeleteImage = NULL;
191 MultipleWindowForm::OnActionPerformed(const Control& source, int actionId)
193 SceneManager* pSceneManager = SceneManager::GetInstance();
195 if (pSceneManager == null)
200 String closeWarning = CommonUtil::GetString(L"IDS_BR_CLOSE_ALL_WINDOWS_Q");
206 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
208 if (pNewWindowInfo == null)
212 result r = E_SUCCESS;
213 SceneManager* pSceneManager = SceneManager::GetInstance();
214 if (pSceneManager == NULL)
218 ArrayList* pArgList = new(std::nothrow) ArrayList();
219 if (pArgList == NULL)
223 pArgList->Construct();
225 pArgList->Add(*pNewWindowInfo);
226 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
227 if (pArgList != null)
234 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
240 case IDA_BUTTON_BACK:
242 String* pSelectedScene = NULL;
243 Object* value = NULL;
244 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
245 pSelectedScene = (String*) value;
249 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
250 delete pSelectedScene;
251 pSelectedScene = null;
254 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
261 case IDA_BUTTON_CLOSEALL:
263 if (!__pConfirmationPopup)
265 __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
266 __pConfirmationPopup->Initialize();
268 __pConfirmationPopup->RemoveActionListener(*this);
269 __pConfirmationPopup->AddActionListener(*this);
270 __pConfirmationPopup->setMessage(closeWarning);
271 __pConfirmationPopup->Show();
275 case IDA_CONFIRMATION_NO:
277 __pConfirmationPopup->SetShowState(false);
278 __pConfirmationPopup->Show();
280 delete __pConfirmationPopup;
281 __pConfirmationPopup = null;
285 case IDA_CONFIRMATION_YES:
287 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
288 if (pAllWindowList == NULL)
292 int totalCount = pAllWindowList->GetCount();
294 for (int count = 0; count < totalCount; count++)
296 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
297 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
299 pAllWindowList->RemoveAll(true);
300 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
302 if (pNewWindowInfo == null)
306 result r = E_SUCCESS;
307 SceneManager* pSceneManager = SceneManager::GetInstance();
308 if (pSceneManager == NULL)
312 ArrayList* pArgList = new(std::nothrow) ArrayList();
313 if (pArgList == NULL)
317 r = pArgList->Construct();
320 pArgList->Add(*pNewWindowInfo);
321 result r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
322 if (pArgList != null)
329 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
333 __pConfirmationPopup->SetShowState(false);
334 __pConfirmationPopup->Show();
336 delete __pConfirmationPopup;
337 __pConfirmationPopup = null;
348 MultipleWindowForm::OnFormBackRequested(Form& source)
351 String* pSelectedScene = NULL;
352 Object* value = NULL;
354 SceneManager* pSceneManager = SceneManager::GetInstance();
355 if (pSceneManager == null)
360 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
361 pSelectedScene = (String*) value;
362 if (pSelectedScene != NULL)
364 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
365 // delete pSelectedScene;
368 AppLogDebug("MultipleWindowForm::OnFormBackRequested GoForward failed %s",GetErrorMessage(r));
376 MultipleWindowForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
382 MultipleWindowForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
384 result r = E_SUCCESS;
385 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
388 if (elementId == IDA_FORMAT_DELETE_BITMAP)
390 // get current scene ID and check if it is matching with deleted scene id
391 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
392 String* pSelectedScene = NULL;
393 Object* pValue = NULL;
397 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
398 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
399 pSelectedScene = (String*) pValue;
400 pAllWindowList->RemoveAt(index, true);
401 if (pSelectedScene->CompareTo(pWindowInfo->sceneID) == 0)
403 //set current scene id to last scene id
404 int totalCount = pAllWindowList->GetCount() - 1;
405 WindowInfo* pLastIndexWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(totalCount));
406 if (pLastIndexWindowInfo != NULL)
408 String* pSelectedSceneID = new(std::nothrow) String(pLastIndexWindowInfo->sceneID);
409 if (pSelectedSceneID != NULL)
411 MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) pSelectedSceneID);
418 count = MultipleWindowPresentationModel::GetInstance()->GetInstance()->GetAllWindowArrayList()->GetCount();
422 GetFooter()->SetItemEnabled(1,false);
426 GetFooter()->SetItemEnabled(1,true);
431 GetFooter()->SetItemEnabled(0,false);
434 GetFooter()->Invalidate(true);
435 __pList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
436 __pList->UpdateList();
438 else if(elementId == IDA_FORMAT_BITMAP || elementId == IDA_FORMAT_TITLE_STRING
439 || elementId == IDA_FORMAT_URL_STRING || elementId == -1)
442 // launch the browser
443 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
444 if (pWindowInfo == NULL)
448 SceneManager* pSceneManager = SceneManager::GetInstance();
449 if (pSceneManager == NULL)
453 ArrayList* pArgList = new(std::nothrow) ArrayList();
454 if (pArgList == NULL)
458 r = pArgList->Construct();
463 pArgList->Add(*pWindowInfo);
464 result r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
468 AppLogDebug("go forward success");
472 AppLogDebug("go forward failed");
474 if (pArgList != null)
486 MultipleWindowForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
492 MultipleWindowForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
498 MultipleWindowForm::CreateItem(int index, int itemWidth)
500 Rectangle listImageRect;
501 Rectangle pagetTitleRect;
502 Rectangle pageURLRect;
503 Rectangle deleteImageRect;
504 String pageTitle(L"");
506 result r = E_SUCCESS;
507 int width = W_ICON_IMAGE_WIDTH;
509 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
510 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
511 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
513 if (pAllWindowList == null)
517 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
518 if(pWindowInfo == null)
522 CustomItem* pItem = new(std::nothrow) CustomItem();
523 pageTitle = pWindowInfo->pageTitle;
524 pageURL = pWindowInfo->pageUrl;
525 if (pageURL.GetLength() == 0)
528 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", nourl);
529 pageURL = L"<"+ nourl +">";
532 if (pageTitle.GetLength() == 0)
535 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", pageTitle);
538 Rectangle screenBounds = GetBounds();
539 r = pItem->Construct(Dimension(itemWidth, 128), style);
545 if (pWindowInfo->pFavicon)
548 if( __pListIconImage != NULL)
550 delete __pListIconImage;
551 __pListIconImage = null;
554 __pListIconImage = new Bitmap();
555 __pListIconImage->Construct(*(pWindowInfo->pFavicon),Rectangle(0,0,pWindowInfo->pFavicon->GetWidth(),pWindowInfo->pFavicon->GetHeight()));
559 if( __pListIconImage != NULL)
561 delete __pListIconImage;
562 __pListIconImage = null;
565 __pListIconImage = pAppResource->GetBitmapN(L"I01_icon_default_favicon.png");
569 listImageRect.SetBounds(screenBounds.x + 16, screenBounds.y + 28,width, 72);
570 pagetTitleRect.SetBounds(listImageRect.x + width + 16,10, screenBounds.width - 2 * width - 24 - 64, 60);
571 pageURLRect.SetBounds(pagetTitleRect.x, pagetTitleRect.y + pagetTitleRect.height, screenBounds.width - 2 * width - 120, 48);
572 if(__pListDeleteImage != null)
574 deleteImageRect.SetBounds(screenBounds.width - __pListDeleteImage->GetWidth() - 24, (128 - __pListDeleteImage->GetHeight() - 8)/2, __pListDeleteImage->GetWidth() + 8, __pListDeleteImage->GetHeight() + 8);
576 pItem->AddElement(listImageRect, IDA_FORMAT_BITMAP, *__pListIconImage, null, null);
578 if (pageTitle.CompareTo(L"") != 0)
580 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, pageTitle, 44, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, true);
583 if (pageURL.CompareTo(L"") != 0)
585 pItem->AddElement(pageURLRect, IDA_FORMAT_URL_STRING, pageURL, 32, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, true);
590 if (pAllWindowList->GetCount() > 1)
592 pItem->AddElement(deleteImageRect, IDA_FORMAT_DELETE_BITMAP, *__pListDeleteImage, null, null);
593 pItem->SetElementSelectionEnabled(IDA_FORMAT_DELETE_BITMAP, true);
600 MultipleWindowForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
608 MultipleWindowForm::GetItemCount(void)
610 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
613 if (pAllWindowList != null)
615 windowCount = pAllWindowList->GetCount();
619 GetFooter()->SetItemEnabled(0, false);
623 GetFooter()->SetItemEnabled(0, true);
625 GetFooter()->Invalidate(true);
630 MultipleWindowForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
634 __pList->UpdateList();