2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\r
4 // Licensed under the Flora License, Version 1.0 (the License);
\r
5 // you may not use this file except in compliance with the License.
\r
6 // You may obtain a copy of the License at
\r
8 // http://floralicense.org/license/
\r
10 // Unless required by applicable law or agreed to in writing, software
\r
11 // distributed under the License is distributed on an AS IS BASIS,
\r
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 // See the License for the specific language governing permissions and
\r
14 // limitations under the License.
\r
17 //!Internet MultipleWindowForm class
\r
18 /*@file: MultipleWindowForm.cpp
\r
19 *@brief: The MultipleWindowForm provides multiple instance of mainscenes and displays them in a Listview
\r
23 #include <FAppUiApp.h>
\r
24 #include <FUiScenes.h>
\r
26 #include "IntCommonLib.h"
\r
27 #include "IntConfirmationPopup.h"
\r
28 #include "IntMainForm.h"
\r
29 #include "IntMultipleWindowForm.h"
\r
30 #include "IntMultipleWindowPresentationModel.h"
\r
31 #include "IntSceneRegister.h"
\r
33 using namespace Tizen::App;
\r
34 using namespace Tizen::Base;
\r
35 using namespace Tizen::Base::Collection;
\r
36 using namespace Tizen::Graphics;
\r
37 using namespace Tizen::Ui;
\r
38 using namespace Tizen::Ui::Controls;
\r
39 using namespace Tizen::Ui::Scenes;
\r
41 static const int W_ICON_IMAGE_WIDTH = 72;
\r
43 MultipleWindowForm::MultipleWindowForm(void)
\r
45 , __pListIconImage(null)
\r
46 , __pListDeleteImage(null)
\r
50 MultipleWindowForm::~MultipleWindowForm(void)
\r
52 if (__pListIconImage)
\r
54 delete __pListIconImage;
\r
55 __pListIconImage = null;
\r
57 if (__pListDeleteImage)
\r
59 delete __pListDeleteImage;
\r
60 __pListDeleteImage = null;
\r
65 MultipleWindowForm::Initialize(void)
\r
67 result r = E_SUCCESS;
\r
69 r = Construct(L"IDL_MULTIPLE_WINDOW");
\r
81 MultipleWindowForm::OnInitializing(void)
\r
83 result r = E_SUCCESS;
\r
84 FooterItem closeButton;
\r
85 FooterItem newButton;
\r
87 SceneManager* pSceneManager = SceneManager::GetInstance();
\r
89 if (pSceneManager == null)
\r
94 Footer* pFooter = GetFooter();
\r
96 if (pFooter == NULL)
\r
101 SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
\r
103 r = pSceneManager->AddSceneEventListener(IDSCN_MULTIPLE_WINDOW, *this);
\r
105 // Setup back event listener
\r
106 SetFormBackEventListener(this);
\r
107 pFooter->AddActionEventListener(*this);
\r
109 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
\r
113 __pListIconImage = pAppResource->GetBitmapN(L"ListIcon.png");
\r
114 __pListDeleteImage = pAppResource->GetBitmapN(L"deleteIcon.png");
\r
117 __pList = static_cast< ListView* >(GetControl(L"IDC_LISTVIEW"));
\r
119 if (__pList != null)
\r
121 __pList->SetItemProvider(*this);
\r
122 __pList->AddListViewItemEventListener(*this);
\r
125 AddOrientationEventListener(*this);
\r
126 // r = pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
\r
127 r = closeButton.Construct(IDA_BUTTON_CLOSEALL);
\r
128 r = closeButton.SetText(CommonUtil::GetString(L"IDS_BR_CLOSE_ALL"));
\r
129 r = pFooter->AddItem(closeButton);
\r
130 r = newButton.Construct(IDA_BUTTON_NEW);
\r
131 r = newButton.SetText(CommonUtil::GetString(L"IDS_BR_SK1_NEW_WINDOW"));
\r
132 r = pFooter->AddItem(newButton);
\r
138 MultipleWindowForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
\r
140 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
\r
142 GetFooter()->SetItemEnabled(1,false);
\r
146 GetFooter()->SetItemEnabled(1,true);
\r
150 __pList->UpdateList();
\r
152 GetFooter()->Invalidate(true);
\r
157 MultipleWindowForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
\r
159 if (__pListIconImage)
\r
161 delete __pListIconImage;
\r
162 __pListIconImage = NULL;
\r
168 MultipleWindowForm::OnTerminating(void)
\r
170 result r = E_SUCCESS;
\r
172 if (__pListIconImage)
\r
174 delete __pListIconImage;
\r
175 __pListIconImage = NULL;
\r
177 if (__pListDeleteImage)
\r
179 delete __pListDeleteImage;
\r
180 __pListDeleteImage = NULL;
\r
187 MultipleWindowForm::OnActionPerformed(const Control& source, int actionId)
\r
189 SceneManager* pSceneManager = SceneManager::GetInstance();
\r
191 if (pSceneManager == null)
\r
196 String closeWarning = CommonUtil::GetString(L"IDS_BR_CLOSE_ALL_WINDOWS_Q");
\r
200 case IDA_BUTTON_NEW:
\r
202 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
\r
204 if (pNewWindowInfo == null)
\r
208 result r = E_SUCCESS;
\r
209 SceneManager* pSceneManager = SceneManager::GetInstance();
\r
210 if (pSceneManager == NULL)
\r
214 ArrayList* pArgList = new(std::nothrow) ArrayList();
\r
215 if (pArgList == NULL)
\r
219 pArgList->Construct();
\r
221 pArgList->Add(*pNewWindowInfo);
\r
222 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
\r
223 if (pArgList != null)
\r
230 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
\r
236 case IDA_BUTTON_BACK:
\r
238 String* pSelectedScene = NULL;
\r
239 Object* value = NULL;
\r
240 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
\r
241 pSelectedScene = (String*) value;
\r
243 if (pSelectedScene)
\r
245 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
\r
246 delete pSelectedScene;
\r
247 pSelectedScene = null;
\r
250 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
\r
257 case IDA_BUTTON_CLOSEALL:
\r
259 __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
\r
260 __pConfirmationPopup->Initialize();
\r
261 __pConfirmationPopup->RemoveActionListener(*this);
\r
262 __pConfirmationPopup->AddActionListener(*this);
\r
263 __pConfirmationPopup->setMessage(closeWarning);
\r
264 __pConfirmationPopup->Show();
\r
268 case IDA_CONFIRMATION_NO:
\r
270 __pConfirmationPopup->SetShowState(false);
\r
271 __pConfirmationPopup->Show();
\r
274 case IDA_CONFIRMATION_YES:
\r
276 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
\r
277 if (pAllWindowList == NULL)
\r
281 int totalCount = pAllWindowList->GetCount();
\r
283 for (int count = 0; count < totalCount; count++)
\r
285 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
\r
286 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
\r
288 pAllWindowList->RemoveAll(true);
\r
289 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
\r
291 if (pNewWindowInfo == null)
\r
295 result r = E_SUCCESS;
\r
296 SceneManager* pSceneManager = SceneManager::GetInstance();
\r
297 if (pSceneManager == NULL)
\r
301 ArrayList* pArgList = new(std::nothrow) ArrayList();
\r
302 if (pArgList == NULL)
\r
306 r = pArgList->Construct();
\r
307 if (r == E_SUCCESS)
\r
309 pArgList->Add(*pNewWindowInfo);
\r
310 result r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
\r
311 if (pArgList != null)
\r
318 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
\r
322 __pConfirmationPopup->SetShowState(false);
\r
323 __pConfirmationPopup->Show();
\r
333 MultipleWindowForm::OnFormBackRequested(Form& source)
\r
336 String* pSelectedScene = NULL;
\r
337 Object* value = NULL;
\r
339 SceneManager* pSceneManager = SceneManager::GetInstance();
\r
340 if (pSceneManager == null)
\r
345 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
\r
346 pSelectedScene = (String*) value;
\r
347 if (pSelectedScene != NULL)
\r
349 result r = pSceneManager->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
\r
350 // delete pSelectedScene;
\r
353 AppLogDebug("MultipleWindowForm::OnFormBackRequested GoForward failed %s",GetErrorMessage(r));
\r
361 MultipleWindowForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
\r
367 MultipleWindowForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
\r
369 result r = E_SUCCESS;
\r
370 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
\r
373 if (elementId == IDA_FORMAT_DELETE_BITMAP)
\r
375 // get current scene ID and check if it is matching with deleted scene id
\r
376 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
\r
377 String* pSelectedScene = NULL;
\r
378 Object* pValue = NULL;
\r
382 SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
\r
383 MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
\r
384 pSelectedScene = (String*) pValue;
\r
385 pAllWindowList->RemoveAt(index, true);
\r
386 if (pSelectedScene->CompareTo(pWindowInfo->sceneID) == 0)
\r
388 //set current scene id to last scene id
\r
389 int totalCount = pAllWindowList->GetCount() - 1;
\r
390 WindowInfo* pLastIndexWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(totalCount));
\r
391 if (pLastIndexWindowInfo != NULL)
\r
393 String* pSelectedSceneID = new(std::nothrow) String(pLastIndexWindowInfo->sceneID);
\r
394 if (pSelectedSceneID != NULL)
\r
396 MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) pSelectedSceneID);
\r
403 count = MultipleWindowPresentationModel::GetInstance()->GetInstance()->GetAllWindowArrayList()->GetCount();
\r
407 GetFooter()->SetItemEnabled(1,false);
\r
411 GetFooter()->SetItemEnabled(1,true);
\r
416 GetFooter()->SetItemEnabled(0,false);
\r
419 GetFooter()->Invalidate(true);
\r
420 __pList->RefreshList(index, LIST_REFRESH_TYPE_ITEM_REMOVE);
\r
421 __pList->UpdateList();
\r
423 else if(elementId == IDA_FORMAT_BITMAP || elementId == IDA_FORMAT_TITLE_STRING
\r
424 || elementId == IDA_FORMAT_URL_STRING || elementId == -1)
\r
427 // launch the browser
\r
428 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
\r
429 if (pWindowInfo == NULL)
\r
433 SceneManager* pSceneManager = SceneManager::GetInstance();
\r
434 if (pSceneManager == NULL)
\r
438 ArrayList* pArgList = new(std::nothrow) ArrayList();
\r
439 if (pArgList == NULL)
\r
443 r = pArgList->Construct();
\r
448 pArgList->Add(*pWindowInfo);
\r
449 result r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
\r
451 if (r == E_SUCCESS)
\r
453 AppLogDebug("go forward success");
\r
457 AppLogDebug("go forward failed");
\r
459 if (pArgList != null)
\r
471 MultipleWindowForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
\r
477 MultipleWindowForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
\r
483 MultipleWindowForm::CreateItem(int index, int itemWidth)
\r
485 Rectangle listImageRect;
\r
486 Rectangle pagetTitleRect;
\r
487 Rectangle pageURLRect;
\r
488 Rectangle deleteImageRect;
\r
489 String pageTitle(L"");
\r
490 String pageURL(L"");
\r
491 result r = E_SUCCESS;
\r
492 int width = W_ICON_IMAGE_WIDTH;
\r
494 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
\r
495 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
\r
496 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
\r
498 if (pAllWindowList == null)
\r
502 WindowInfo* pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(index));
\r
503 if(pWindowInfo == null)
\r
507 CustomItem* pItem = new(std::nothrow) CustomItem();
\r
508 pageTitle = pWindowInfo->pageTitle;
\r
509 pageURL = pWindowInfo->pageUrl;
\r
510 if (pageURL.GetLength() == 0)
\r
513 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", nourl);
\r
514 pageURL = L"<"+ nourl +">";
\r
517 Rectangle screenBounds = GetBounds();
\r
518 r = pItem->Construct(Dimension(itemWidth, 128), style);
\r
524 if (pWindowInfo->pFavicon)
\r
527 if( __pListIconImage != NULL)
\r
529 delete __pListIconImage;
\r
530 __pListIconImage = null;
\r
533 __pListIconImage = new Bitmap();
\r
534 __pListIconImage->Construct(*(pWindowInfo->pFavicon),Rectangle(0,0,pWindowInfo->pFavicon->GetWidth(),pWindowInfo->pFavicon->GetHeight()));
\r
538 if( __pListIconImage != NULL)
\r
540 delete __pListIconImage;
\r
541 __pListIconImage = null;
\r
544 __pListIconImage = pAppResource->GetBitmapN(L"I01_icon_default_favicon.png");
\r
546 AppLog("deleteimg %d %d",__pListDeleteImage->GetWidth(),__pListDeleteImage->GetHeight());
\r
548 listImageRect.SetBounds(screenBounds.x + 16, screenBounds.y + 28,width, 72);
\r
549 pagetTitleRect.SetBounds(listImageRect.x + width + 16,10, screenBounds.width - 2 * width - 64, 60);
\r
550 pageURLRect.SetBounds(pagetTitleRect.x, pagetTitleRect.y + pagetTitleRect.height, screenBounds.width - 2 * width - 120, 48);
\r
551 deleteImageRect.SetBounds(screenBounds.width - __pListDeleteImage->GetWidth() - 24, (128 - __pListDeleteImage->GetHeight() - 8)/2, __pListDeleteImage->GetWidth() + 8, __pListDeleteImage->GetHeight() + 8);
\r
552 pItem->AddElement(listImageRect, IDA_FORMAT_BITMAP, *__pListIconImage, null, null);
\r
554 if (pageTitle.CompareTo(L"") != 0)
\r
556 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, pageTitle, 44, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, true);
\r
559 if (pageURL.CompareTo(L"") != 0)
\r
561 pItem->AddElement(pageURLRect, IDA_FORMAT_URL_STRING, pageURL, 32, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, true);
\r
564 if (pAllWindowList)
\r
566 if (pAllWindowList->GetCount() > 1)
\r
568 pItem->AddElement(deleteImageRect, IDA_FORMAT_DELETE_BITMAP, *__pListDeleteImage, null, null);
\r
569 pItem->SetElementSelectionEnabled(IDA_FORMAT_DELETE_BITMAP, true);
\r
576 MultipleWindowForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
\r
584 MultipleWindowForm::GetItemCount(void)
\r
586 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
\r
587 int windowCount = 0;
\r
589 if (pAllWindowList != null)
\r
591 windowCount = pAllWindowList->GetCount();
\r
593 if (windowCount < 2)
\r
595 GetFooter()->SetItemEnabled(0, false);
\r
599 GetFooter()->SetItemEnabled(0, true);
\r
601 GetFooter()->Invalidate(true);
\r
602 return windowCount;
\r
606 MultipleWindowForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
\r
610 __pList->UpdateList();
\r