📄 snakinglistview.cpp
字号:
/*****************************************************************************
COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2005.
The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
The use of the software is subject to the terms of the end-user license
agreement which accompanies or is included with the software. The software is
provided "as is" and Sony Ericsson specifically disclaim any warranty or
condition whatsoever regarding merchantability or fitness for a specific
purpose, title or non-infringement. No warranty of any kind is made in
relation to the condition, suitability, availability, accuracy, reliability,
merchantability and/or non-infringement of the software provided herein.
*****************************************************************************/
// SnakingListViews.cpp
//
//
#include "ListViews.h"
#include "ListViews_Application.h" // KUidListViews
#include "SnakingListView.h"
#include <eiktxlbm.h>
#include <eikclbd.h>
#include <quartzkeys.h> // EQuartzKeyXxx
#include <eikmenub.h> // CEikMenuBar
#include <w32std.h> // RWindow
#include <gulicon.h> // CGulIcon
CSnakingListView* CSnakingListView::NewL(const TRect& aRect)
{
CSnakingListView * self = new(ELeave) CSnakingListView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
CleanupStack::Pop();
return self;
}
CSnakingListView::~CSnakingListView()
{
delete iTextListEmpty;
if(iListBox)
delete iListBox;
}
void CSnakingListView::ConstructL(const TRect& aRect)
{
iListBox = 0;
iDisplayList = EFalse;
iViewId.iViewUid = TUid::Uid(EListViewsCmdSnakingListView);
iViewId.iAppUid = KUidListViews;
CreateWindowL();
SetRect(aRect);
// initiate iTextListEmpty - Fetch the text from the resource file.
iTextListEmpty = iEikonEnv->AllocReadResourceL(R_LISTVIEWS_LIST_EMPTY);
CreateList(EListViewsCmdColumnOpt1);
// Get the array of text items held by the list box's model
CDesCArray* array = ((CDesCArray *)iListBox->Model()->ItemTextArray());
// populate it with text items - contacts names
PopulateList(array);
// Handle the addition of items to the list box model.
iListBox->HandleItemAdditionL(); // This also redraws the list box.
// Set the item at index 0
iListBox->SetCurrentItemIndex(0);
// Set the list box control with a focus - this gives the blue highlighting
// effect shown in the pictures above.
iListBox->SetFocus(ETrue);
iListBox->ActivateL();
}
TKeyResponse CSnakingListView::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
{
if (aType == EEventKey)
{
if (aKeyEvent.iCode == EQuartzKeyTwoWayDown)
{
iListBox->View()->MoveCursorL( CListBoxView::ECursorNextItem,
CListBoxView::ENoSelection);
iListBox->UpdateScrollBarsL();
return EKeyWasConsumed;
}
else if (aKeyEvent.iCode == EQuartzKeyTwoWayUp)
{
iListBox->View()->MoveCursorL( CListBoxView::ECursorPreviousItem,
CListBoxView::ENoSelection );
iListBox->UpdateScrollBarsL();
return EKeyWasConsumed;
}
}
return iListBox->OfferKeyEventL(aKeyEvent, aType);
}
void CSnakingListView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
if (aPointerEvent.iType == TPointerEvent::EButton1Down)
{
TPoint penXY = aPointerEvent.iPosition;
int yMod = (int)( ((penXY.iY-6) / iListBox->ItemHeight()) +
iListBox->View()->TopItemIndex() );
if (yMod < 0)
yMod = 0;
if ((yMod <= iListBox->View()->BottomItemIndex()) && (yMod < 236))
{
iListBox->View()->VerticalMoveToItemL(yMod,
CListBoxView::EDisjointSelection);
iListBox->UpdateScrollBarsL();
}
}
}
void CSnakingListView::HandleCommandL(TInt aCommand)
{
delete iListBox;
CreateList(aCommand);
// Get the array of text items held by the list box's model
CDesCArray* array = ((CDesCArray *)iListBox->Model()->ItemTextArray());
// populate it with text items - contacts names
PopulateList(array);
// Handle the addition of items to the list box model.
iListBox->HandleItemAdditionL(); // This also redraws the list box.
// Set the item at index 0
iListBox->SetCurrentItemIndex(0);
// Set the list box control with a focus - this gives the blue highlighting
// effect shown in the pictures above.
iListBox->SetFocus(ETrue);
iListBox->ActivateL();
iListBox->DrawNow();
}
TVwsViewId CSnakingListView::ViewId() const
{
return iViewId;
}
void CSnakingListView::Draw(const TRect& /*aRect*/) const
{
// Window graphics context
CWindowGc& gc = SystemGc();
// Start with a clear screen
gc.Clear();
TRect rect = Rect();
const CFont* font = iEikonEnv->TitleFont();
gc.UseFont(font);
TInt baseline = rect.Height()/2 - font->AscentInPixels()/2;
gc.DrawText(*iTextListEmpty, rect, baseline, CGraphicsContext::ECenter);
gc.DiscardFont();
}
TInt CSnakingListView::CountComponentControls() const
{
if(iListBox && iDisplayList)
return 1;
else
return 0;
}
CCoeControl* CSnakingListView::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0:
return iListBox;
default:
return 0;
}
}
void CSnakingListView::ViewActivatedL( const TVwsViewId& /*aPrevViewId*/,
TUid /*aCustomMessageId*/,
const TDesC8& /*aCustomMessage*/ )
{
ActivateL();
MEikAppUiFactory* factory = iEikonEnv->AppUiFactory();
factory->MenuBar()->ChangeMenuBarL(0,
R_LISTVIEWS_MENUBAR_SNAKING_LISTBOX,
EFalse);
MakeVisible(ETrue);
}
void CSnakingListView::ViewDeactivated()
{
MakeVisible(EFalse);
}
void CSnakingListView::CreateList(TInt aFlag)
{
// Construct a list box
iListBox = new (ELeave) CEikSnakingTextListBox;
// flag can be different
switch(aFlag)
{
case EListViewsCmdColumnOpt1 :
iListBox->ConstructL(this, 0);
break;
case EListViewsCmdColumnOpt2 :
iListBox->ConstructL(this, CEikListBox::EMultipleSelection);
break;
}
// set this view as the parent of the control
iListBox->SetContainerWindowL( *this );
// set look and behaviour:
// column can not be greater than avilable screen area
iListBox->SetColumnWidth(Rect().Width()-30);
// - set scrolling capabilities
iListBox->CreateScrollBarFrameL();
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto,
CEikScrollBarFrame::EAuto);
// - set listbox bordes
iListBox->SetBorder(TGulBorder::EDeepRaisedWithOutline);
// - set position
TPoint p;
TSize sz;
p.iX = 0;
p.iY = 0;
sz.iWidth = 208;
sz.iHeight = 240; // max 255
iListBox->SetExtent(p, sz);
}
// this function fills list with all contact names, sorted alphabetically
void CSnakingListView::PopulateList(CDesCArray *aArray)
{
// put names into array
aArray->AppendL(_L("Jenny Annie"));
aArray->AppendL(_L("Chris Stoll"));
aArray->AppendL(_L("David Mine"));
aArray->AppendL(_L("Johnny Longname"));
aArray->AppendL(_L("Mike Henry"));
aArray->AppendL(_L("Susan"));
aArray->AppendL(_L("Gooch"));
aArray->AppendL(_L("Steve"));
aArray->AppendL(_L("Paul Hasverylongnameman"));
aArray->AppendL(_L("Cindy Crawford"));
aArray->AppendL(_L("Greg O'Hara"));
aArray->AppendL(_L("Erik Rednose"));
aArray->AppendL(_L("Kenny"));
aArray->AppendL(_L("Kyle"));
aArray->AppendL(_L("Bennet Mill"));
aArray->AppendL(_L("Justin"));
aArray->AppendL(_L("Ridiculously long test name used to see if my code works."));
iDisplayList = ETrue;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -