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;
41 static const int W_ICON_IMAGE_WIDTH = 72;
43 MultipleWindowForm::MultipleWindowForm(void)
45 , __pListIconImage(null)
46 , __pListDeleteImage(null)
50 MultipleWindowForm::~MultipleWindowForm(void)
54 delete __pListIconImage;
55 __pListIconImage = null;
57 if (__pListDeleteImage)
59 delete __pListDeleteImage;
60 __pListDeleteImage = null;
65 MultipleWindowForm::Initialize(void)
69 r = Construct(L"IDL_MULTIPLE_WINDOW");
81 MultipleWindowForm::OnInitializing(void)
84 FooterItem closeButton;
87 SceneManager* pSceneManager = SceneManager::GetInstance();
89 if (pSceneManager == null)
94 Footer* pFooter = GetFooter();
101 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
103 r = pSceneManager->AddSceneEventListener(IDSCN_MULTIPLE_WINDOW, *this);
105 // Setup back event listener
106 SetFormBackEventListener(this);
107 pFooter->AddActionEventListener(*this);
109 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
113 __pListIconImage = pAppResource->GetBitmapN(L"ListIcon.png");
114 __pListDeleteImage = pAppResource->GetBitmapN(L"deleteIcon.png");
117 __pList = static_cast< ListView* >(GetControl(L"IDC_LISTVIEW"));
121 __pList->SetItemProvider(*this);
122 __pList->AddListViewItemEventListener(*this);
125 AddOrientationEventListener(*this);
126 // r = pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
127 r = closeButton.Construct(IDA_BUTTON_CLOSEALL);
128 r = closeButton.SetText(CommonUtil::GetString(L"IDS_BR_CLOSE_ALL"));
129 r = pFooter->AddItem(closeButton);
130 r = newButton.Construct(IDA_BUTTON_NEW);
131 r = newButton.SetText(CommonUtil::GetString(L"IDS_BR_SK1_NEW_WINDOW"));
132 r = pFooter->AddItem(newButton);
138 MultipleWindowForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
140 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
142 GetFooter()->SetItemEnabled(1,false);
146 GetFooter()->SetItemEnabled(1,true);
150 __pList->UpdateList();
152 GetFooter()->Invalidate(true);
157 MultipleWindowForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
159 if (__pListIconImage)
161 delete __pListIconImage;
162 __pListIconImage = NULL;
168 MultipleWindowForm::OnTerminating(void)
170 result r = E_SUCCESS;
172 if (__pListIconImage)
174 delete __pListIconImage;
175 __pListIconImage = NULL;
177 if (__pListDeleteImage)
179 delete __pListDeleteImage;
180 __pListDeleteImage = NULL;
187 MultipleWindowForm::OnActionPerformed(const Control& source, int actionId)
189 SceneManager* pSceneManager = SceneManager::GetInstance();
191 if (pSceneManager == null)
196 String closeWarning = CommonUtil::GetString(L"IDS_BR_CLOSE_ALL_WINDOWS_Q");
202 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
204 if (pNewWindowInfo == null)
208 result r = E_SUCCESS;
209 SceneManager* pSceneManager = SceneManager::GetInstance();
210 if (pSceneManager == NULL)
214 ArrayList* pArgList = new(std::nothrow) ArrayList();
215 if (pArgList == NULL)
219 pArgList->Construct();
221 pArgList->Add(*pNewWindowInfo);
222 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
223 if (pArgList != null)
230 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
236 case IDA_BUTTON_BACK:
238 String* pSelectedScene = NULL;
239 Object* value = NULL;
240 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
241 pSelectedScene = (String*) value;
245 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
246 delete pSelectedScene;
247 pSelectedScene = null;
250 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
257 case IDA_BUTTON_CLOSEALL:
259 __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
260 __pConfirmationPopup->Initialize();
261 __pConfirmationPopup->RemoveActionListener(*this);
262 __pConfirmationPopup->AddActionListener(*this);
263 __pConfirmationPopup->setMessage(closeWarning);
264 __pConfirmationPopup->Show();
268 case IDA_CONFIRMATION_NO:
270 __pConfirmationPopup->SetShowState(false);
271 __pConfirmationPopup->Show();
274 case IDA_CONFIRMATION_YES:
276 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
277 if (pAllWindowList == NULL)
281 int totalCount = pAllWindowList->GetCount();
283 for (int count = 0; count < totalCount; count++)
285 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
286 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
288 pAllWindowList->RemoveAll(true);
289 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
291 if (pNewWindowInfo == null)
295 result r = E_SUCCESS;
296 SceneManager* pSceneManager = SceneManager::GetInstance();
297 if (pSceneManager == NULL)
301 ArrayList* pArgList = new(std::nothrow) ArrayList();
302 if (pArgList == NULL)
306 r = pArgList->Construct();
309 pArgList->Add(*pNewWindowInfo);
310 result r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
311 if (pArgList != null)
318 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
322 __pConfirmationPopup->SetShowState(false);
323 __pConfirmationPopup->Show();
333 MultipleWindowForm::OnFormBackRequested(Form& source)
336 String* pSelectedScene = NULL;
337 Object* value = NULL;
339 SceneManager* pSceneManager = SceneManager::GetInstance();
340 if (pSceneManager == null)
345 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
346 pSelectedScene = (String*) value;
347 if (pSelectedScene != NULL)
349 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
350 // delete pSelectedScene;
353 AppLogDebug("MultipleWindowForm::OnFormBackRequested GoForward failed %s",GetErrorMessage(r));
361 MultipleWindowForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
367 MultipleWindowForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
369 result r = E_SUCCESS;
370 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
373 if (elementId == IDA_FORMAT_DELETE_BITMAP)
375 // get current scene ID and check if it is matching with deleted scene id
376 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
377 String* pSelectedScene = NULL;
378 Object* pValue = NULL;
382 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
383 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
384 pSelectedScene = (String*) pValue;
385 pAllWindowList->RemoveAt(index, true);
386 if (pSelectedScene->CompareTo(pWindowInfo->sceneID) == 0)
388 //set current scene id to last scene id
389 int totalCount = pAllWindowList->GetCount() - 1;
390 WindowInfo* pLastIndexWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(totalCount));
391 if (pLastIndexWindowInfo != NULL)
393 String* pSelectedSceneID = new(std::nothrow) String(pLastIndexWindowInfo->sceneID);
394 if (pSelectedSceneID != NULL)
396 MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) pSelectedSceneID);
403 count = MultipleWindowPresentationModel::GetInstance()->GetInstance()->GetAllWindowArrayList()->GetCount();
407 GetFooter()->SetItemEnabled(1,false);
411 GetFooter()->SetItemEnabled(1,true);
416 GetFooter()->SetItemEnabled(0,false);
419 GetFooter()->Invalidate(true);
420 __pList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
421 __pList->UpdateList();
423 else if(elementId == IDA_FORMAT_BITMAP || elementId == IDA_FORMAT_TITLE_STRING
424 || elementId == IDA_FORMAT_URL_STRING || elementId == -1)
427 // launch the browser
428 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
429 if (pWindowInfo == NULL)
433 SceneManager* pSceneManager = SceneManager::GetInstance();
434 if (pSceneManager == NULL)
438 ArrayList* pArgList = new(std::nothrow) ArrayList();
439 if (pArgList == NULL)
443 r = pArgList->Construct();
448 pArgList->Add(*pWindowInfo);
449 result r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
453 AppLogDebug("go forward success");
457 AppLogDebug("go forward failed");
459 if (pArgList != null)
471 MultipleWindowForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
477 MultipleWindowForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
483 MultipleWindowForm::CreateItem(int index, int itemWidth)
485 Rectangle listImageRect;
486 Rectangle pagetTitleRect;
487 Rectangle pageURLRect;
488 Rectangle deleteImageRect;
489 String pageTitle(L"");
491 result r = E_SUCCESS;
492 int width = W_ICON_IMAGE_WIDTH;
494 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
495 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
496 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
498 if (pAllWindowList == null)
502 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
503 if(pWindowInfo == null)
507 CustomItem* pItem = new(std::nothrow) CustomItem();
508 pageTitle = pWindowInfo->pageTitle;
509 pageURL = pWindowInfo->pageUrl;
510 if (pageURL.GetLength() == 0)
513 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", nourl);
514 pageURL = L"<"+ nourl +">";
517 if (pageTitle.GetLength() == 0)
520 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", pageTitle);
523 Rectangle screenBounds = GetBounds();
524 r = pItem->Construct(Dimension(itemWidth, 128), style);
530 if (pWindowInfo->pFavicon)
533 if( __pListIconImage != NULL)
535 delete __pListIconImage;
536 __pListIconImage = null;
539 __pListIconImage = new Bitmap();
540 __pListIconImage->Construct(*(pWindowInfo->pFavicon),Rectangle(0,0,pWindowInfo->pFavicon->GetWidth(),pWindowInfo->pFavicon->GetHeight()));
544 if( __pListIconImage != NULL)
546 delete __pListIconImage;
547 __pListIconImage = null;
550 __pListIconImage = pAppResource->GetBitmapN(L"I01_icon_default_favicon.png");
552 AppLog("deleteimg %d %d",__pListDeleteImage->GetWidth(),__pListDeleteImage->GetHeight());
554 listImageRect.SetBounds(screenBounds.x + 16, screenBounds.y + 28,width, 72);
555 pagetTitleRect.SetBounds(listImageRect.x + width + 16,10, screenBounds.width - 2 * width - 64, 60);
556 pageURLRect.SetBounds(pagetTitleRect.x, pagetTitleRect.y + pagetTitleRect.height, screenBounds.width - 2 * width - 120, 48);
557 deleteImageRect.SetBounds(screenBounds.width - __pListDeleteImage->GetWidth() - 24, (128 - __pListDeleteImage->GetHeight() - 8)/2, __pListDeleteImage->GetWidth() + 8, __pListDeleteImage->GetHeight() + 8);
558 pItem->AddElement(listImageRect, IDA_FORMAT_BITMAP, *__pListIconImage, null, null);
560 if (pageTitle.CompareTo(L"") != 0)
562 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, pageTitle, 44, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, true);
565 if (pageURL.CompareTo(L"") != 0)
567 pItem->AddElement(pageURLRect, IDA_FORMAT_URL_STRING, pageURL, 32, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, true);
572 if (pAllWindowList->GetCount() > 1)
574 pItem->AddElement(deleteImageRect, IDA_FORMAT_DELETE_BITMAP, *__pListDeleteImage, null, null);
575 pItem->SetElementSelectionEnabled(IDA_FORMAT_DELETE_BITMAP, true);
582 MultipleWindowForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
590 MultipleWindowForm::GetItemCount(void)
592 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
595 if (pAllWindowList != null)
597 windowCount = pAllWindowList->GetCount();
601 GetFooter()->SetItemEnabled(0, false);
605 GetFooter()->SetItemEnabled(0, true);
607 GetFooter()->Invalidate(true);
612 MultipleWindowForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
616 __pList->UpdateList();