1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstest/uibench/s60/testlauncher/src/testlistcontainer.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,173 @@
1.4 + // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 + // All rights reserved.
1.6 + // This component and the accompanying materials are made available
1.7 + // under the terms of "Eclipse Public License v1.0"
1.8 + // which accompanies this distribution, and is available
1.9 + // at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 + //
1.11 + // Initial Contributors:
1.12 + // Nokia Corporation - initial contribution.
1.13 + //
1.14 + // Contributors:
1.15 + //
1.16 + // Description:
1.17 + //
1.18 +
1.19 +
1.20 +#include "testlistcontainer.h"
1.21 +#include "testlistengine.h"
1.22 +#include "testlauncher.hrh"
1.23 +
1.24 +#include <testlauncher.rsg>
1.25 +#include <EIKAPP.H>
1.26 +#include <eikbtgpc.h>
1.27 +
1.28 +
1.29 +void CFileListContainer::ConstructL(const TRect& aRect)
1.30 + {
1.31 + CreateWindowL();
1.32 +
1.33 + iListBox = new (ELeave) CAknDoubleNumberStyleListBox;
1.34 + iListBox->SetContainerWindowL(*this);
1.35 + iListBox->ConstructL(this, EAknListBoxMarkableList);
1.36 +
1.37 + // Create the scroll indicator
1.38 + iListBox->CreateScrollBarFrameL(ETrue);
1.39 + iListBox->ScrollBarFrame()
1.40 + ->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
1.41 +
1.42 + iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
1.43 + iListBox->ActivateL();
1.44 +
1.45 + // Create the FileListEngine
1.46 + iAppEngine = new (ELeave) CFileListEngine;
1.47 +
1.48 +#ifdef __SERIES60_3X__
1.49 + iAppEngine->ConstructL();
1.50 +#else
1.51 + iAppEngine->ConstructL((CEikProcess*)(((CEikAppUi*)iCoeEnv->AppUi())->Application()->Process()));
1.52 +#endif
1.53 +
1.54 + SetFileListL(EFileListPictures, EFileListDate);
1.55 +
1.56 + SetRect(aRect);
1.57 + ActivateL();
1.58 + }
1.59 +
1.60 +CFileListContainer::~CFileListContainer()
1.61 + {
1.62 + delete iAppEngine;
1.63 + delete iListBox;
1.64 + }
1.65 +
1.66 +
1.67 +
1.68 +// This will set up filelist.
1.69 +// Directory and Size can be changed. See Filelist.hrh for possible values
1.70 +// This function is located in the container and not in the engine, because it
1.71 +// activates the listbox.
1.72 +void CFileListContainer::SetFileListL(TInt aDirectory, TInt aSizeDate)
1.73 + {
1.74 + // Set the listbox to use the file list model
1.75 + CDesCArray* items = static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray());
1.76 +
1.77 + // If there are items, they will be removed here
1.78 + if (iAppEngine->RemoveItems(items))
1.79 + {
1.80 + // This makes changes to the actual listbox
1.81 + iListBox->HandleItemRemovalL();
1.82 + }
1.83 +
1.84 + // Let's show directory
1.85 + iAppEngine->SetDirectory(aDirectory);
1.86 + // Let's decide whether to show file size or modification date
1.87 + iAppEngine->SetSizeDate(aSizeDate);
1.88 + // Do preparations for the FileList
1.89 + if(iAppEngine->StartFileList() == KErrNone)
1.90 + {
1.91 + // Create FileList Items in the ListBox
1.92 + iAppEngine->GetFileListItemsL(items);
1.93 + }
1.94 + // Close FileList session
1.95 + iAppEngine->EndFileList();
1.96 +
1.97 + // Refresh the listbox due to model change
1.98 + iListBox->HandleItemAdditionL();
1.99 + iListBox->SetCurrentItemIndex(0);
1.100 +
1.101 + // Set correct middle softkey
1.102 + CEikButtonGroupContainer * cbaGroup = iEikonEnv->AppUiFactory()->Cba();
1.103 + if (iAppEngine->IsDirListEmpty())
1.104 + {
1.105 + // Don't use middle softkey at all
1.106 + cbaGroup->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT);
1.107 + }
1.108 +
1.109 + iListBox->DrawNow();
1.110 + }
1.111 +
1.112 +// Called by framework when the view size is changed
1.113 +void CFileListContainer::SizeChanged()
1.114 + {
1.115 + // control resizing
1.116 + TRect rect = Rect();
1.117 + iListBox->SetExtent(TPoint(0,0),rect.Size());
1.118 + }
1.119 +
1.120 +// Called by framework when a key is pressed
1.121 +TKeyResponse CFileListContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
1.122 + {
1.123 + TKeyResponse ret;
1.124 +
1.125 + // See if we have a selection
1.126 + TInt code = aKeyEvent.iCode;
1.127 + switch(code)
1.128 + {
1.129 + // is navigator button pressed
1.130 + case EKeyOK:
1.131 + iAppEngine->LaunchCurrentL(iListBox->CurrentItemIndex());
1.132 + ret = EKeyWasConsumed;
1.133 + break;
1.134 +
1.135 + default:
1.136 + // Let Listbox take care of its key handling
1.137 + ret = iListBox->OfferKeyEventL(aKeyEvent, aType);
1.138 + break;
1.139 + }
1.140 + return ret;
1.141 + }
1.142 +
1.143 +void CFileListContainer::LaunchCurrentL()
1.144 + {
1.145 + iAppEngine->LaunchCurrentL(iListBox->CurrentItemIndex());
1.146 + }
1.147 +
1.148 +TInt CFileListContainer::CountComponentControls() const
1.149 + {
1.150 + return 1;
1.151 + }
1.152 +CCoeControl* CFileListContainer::ComponentControl(TInt aIndex) const
1.153 + {
1.154 + switch (aIndex)
1.155 + {
1.156 + case 0:
1.157 + return iListBox;
1.158 + default:
1.159 + return NULL;
1.160 + }
1.161 + }
1.162 +
1.163 +void CFileListContainer::Draw(const TRect& aRect) const
1.164 + {
1.165 + CWindowGc& gc = SystemGc();
1.166 + // drawing code
1.167 + gc.SetPenStyle(CGraphicsContext::ENullPen);
1.168 + gc.SetBrushColor(KRgbGray);
1.169 + gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
1.170 + gc.DrawRect(aRect);
1.171 + }
1.172 +
1.173 +void CFileListContainer::HandleControlEventL(CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/)
1.174 + {
1.175 + // empty
1.176 + }