📄 aknexgridcontainerasselection.cpp
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */
// INCLUDE FILES
#include <aknlists.h>
#include <akntitle.h>
#include <AknQueryDialog.h>
#include <AknIconArray.h>
#include <AknExGrid.rsg>
#include <AknExGrid.mbg>
#include "AknExGrid.hrh"
#include "AknExGridContainerAsSelection.h"
#include "AknExGridDialogFillingOrder.h"
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CAknExGridContainerAsSelection* CAknExGridContainerAsSelection::NewL(
const TRect& aRect,
TAknExGridGridType aGridType )
{
CAknExGridContainerAsSelection* self = NewLC( aRect, aGridType );
CleanupStack::Pop( self );
return self;
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CAknExGridContainerAsSelection* CAknExGridContainerAsSelection::NewLC(
const TRect& aRect,
TAknExGridGridType aGridType )
{
CAknExGridContainerAsSelection* self =
new ( ELeave ) CAknExGridContainerAsSelection();
CleanupStack::PushL( self );
self->ConstructL( aRect, aGridType );
return self;
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::CAknExGridContainerAsSelection()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CAknExGridContainerAsSelection::CAknExGridContainerAsSelection()
: iGrid( NULL ), iGridType( EAknExGridSelectionGrid ),
iLabel( NULL ), iToDoLabel( NULL )
{
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsSelection::ConstructL(
const TRect& aRect, TAknExGridGridType aGridType )
{
CreateWindowL();
// Create labels
TBuf< KLengthOfLabelString > label;
iLabel = new ( ELeave ) CEikLabel;
iLabel->SetContainerWindowL( *this );
iCoeEnv->ReadResource( label, R_EXGR_LABEL_VIEW_AS_SELECTION );
iLabel->SetTextL( label );
TBuf< KLengthOfToDoLabelString > dolabel;
iToDoLabel = new ( ELeave ) CEikLabel;
iToDoLabel->SetContainerWindowL( *this );
iCoeEnv->ReadResource( dolabel, R_EXGR_DOLABEL_VIEW_AS_SELECTION );
iToDoLabel->SetTextL( dolabel );
iTestNumber = 0;
// Create a grid
iGrid = new ( ELeave ) CAknGrid;
iGrid->SetContainerWindowL( *this );
iGridM = new ( ELeave ) CAknGridM;
iGridType = aGridType;
iGrid->SetModel( iGridM );
if ( iGridType == EAknExGridSelectionGrid )
{
iGrid->ConstructL( this, EAknListBoxSelectionGrid );
iTitles = iCoeEnv->ReadDesCArrayResourceL( R_EXGR_TITLE_SELECTION );
CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
CAknTitlePane* titlePane = static_cast<CAknTitlePane*>
( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
titlePane->SetTextL( ( *iTitles )[ESelectionTest1] );
}
else
{
iGrid->ConstructL( this, EAknListBoxMarkableGrid );
iTitles = iCoeEnv->ReadDesCArrayResourceL( R_EXGR_TITLE_MARKABLE );
CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
CAknTitlePane* titlePane = static_cast<CAknTitlePane*>
( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
titlePane->SetTextL( ( *iTitles )[EMarkableTest1] );
}
// Set initial parameters for the grid
iVerticalOrientation = ETrue;
iTopToBottom = ETrue;
iLeftToRight = ETrue;
iNumOfColumns = KNumOfSelectionColumns;
iNumOfRows = KNumOfSelectionRows;
iContentType = EContainBoth;
iNumOfItems = KInitialNumOfItemsInSelection;
iVerticalScrollingType = CAknGridView::EScrollIncrementLineAndLoops;
iHorizontalScrollingType = CAknGridView::EScrollIncrementLineAndLoops;
// Set empty text
TBuf< KLengthOfEmptyText > emptyText;
iCoeEnv->ReadResource( emptyText, R_EXGR_TEXT_EMPTY_SELECTION_GRID );
iGrid->SetEmptyGridTextL( emptyText );
// Set Layout
iGrid->SetRect( aRect );
iSizeOfItems.iWidth = ( aRect.iBr.iX - aRect.iTl.iX ) / iNumOfColumns;
iSizeOfItems.iHeight = ( aRect.iBr.iY - aRect.iTl.iY ) / iNumOfRows;
SetGridLayoutL();
// Create resouce for grid
CreateGridResourceL();
iInstantsCreated = ETrue;
// Activate view
SetRect( aRect );
ActivateL();
// Activate the grid
iGrid->MakeVisible( ETrue );
iGrid->SetFocus( ETrue );
iGrid->ActivateL();
iGrid->DrawNow();
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::~CAknExGridContainerAsSelection()
// Destructor.
// -----------------------------------------------------------------------------
//
CAknExGridContainerAsSelection::~CAknExGridContainerAsSelection()
{
if ( iInstantsCreated )
{
delete iLabel;
delete iToDoLabel;
delete iGrid;
}
delete iTitles;
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::InsertDataL()
// Inserts data to the current index in grid.
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsSelection::InsertDataL( TInt aNum )
{
// The number of items in the grid.
TInt numberOfData = iGrid->GridModel()->NumberOfData();
// If there is no item in grid
if ( numberOfData < 1 )
{
AddDataL( aNum );
return;
}
MDesCArray *array = iGrid->Model()->ItemTextArray();
CDesCArray *cArray = ( CDesCArray* )array;
// Creates text which is added to the grid.
TBuf< KLengthOfItemResourceString > number;
TBuf< KLengthOfItemResourceString > format;
if ( iGridType == EAknExGridMarkableGrid )
{
iCoeEnv->ReadResource( format,
R_EXGR_FORMATSTRING_MARKABLEITEM );
}
else
{
iCoeEnv->ReadResource( format,
R_EXGR_FORMATSTRING_SELECTIONITEM );
}
// This shows current index item.
TInt oldCurrIndex = iGrid->CurrentDataIndex();
// If the number of items in Grid is more than zero
for ( TInt loop = numberOfData + aNum; loop > numberOfData; loop-- )
{
number.Format( format, loop );
// Insert the item to the current index.
cArray->InsertL( oldCurrIndex , number );
}
// Inform list box that data was added.
iGrid->HandleItemAdditionL();
// If item size changes we need to alter the item style
ApplySelGridGraphicStyleL();
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::AddDataL()
// Adds data to the last index in the grid.
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsSelection::AddDataL( TInt aNum )
{
MDesCArray* array = iGrid->Model()->ItemTextArray();
CDesCArray* cArray = ( CDesCArray* )array;
// Creates text which is added to the grid.
TBuf<KLengthOfItemResourceString> number;
TBuf<KLengthOfItemResourceString> format;
if ( iGridType == EAknExGridMarkableGrid )
{
iCoeEnv->ReadResource( format,
R_EXGR_FORMATSTRING_MARKABLEITEM );
}
else
{
iCoeEnv->ReadResource( format,
R_EXGR_FORMATSTRING_SELECTIONITEM );
}
// The number of items in the grid.
TInt numberOfData = iGrid->GridModel()->NumberOfData();
// Add the item to the last index
for ( TInt loop = numberOfData; loop < aNum + numberOfData; loop++ )
{
number.Format( format, loop + 1 );
cArray->AppendL( number );
}
// Inform list box that data was added.
iGrid->HandleItemAdditionL();
// If item size changes we need to alter the item style
ApplySelGridGraphicStyleL();
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::RemoveDataL()
// Removes data from the current index.
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsSelection::RemoveDataL( TInt aNum, TBool aWhere )
{
MDesCArray *array = iGrid->Model()->ItemTextArray();
CDesCArray *cArray = ( CDesCArray* )array;
// The number of items in the grid.
TInt numberOfData = iGrid->GridModel()->NumberOfData();
if ( numberOfData < 1 )
// In the case that there is no item in grid.
{
TBuf< KLengthOfAboutString > noItem;
iCoeEnv->ReadResource( noItem, R_EXGR_TEXT_NO_ITEM );
iEikonEnv->AlertWin( noItem );
return;
}
TInt oldCurrIndex = iGrid->CurrentItemIndex();
TInt newCurrIndex = oldCurrIndex;
if ( aWhere )
{
if ( numberOfData - oldCurrIndex < aNum )
{
aNum = numberOfData - oldCurrIndex;
}
newCurrIndex = oldCurrIndex;
}
else
{
if ( ( numberOfData < aNum ) || ( aNum < 0 ) )
{
aNum = numberOfData;
}
newCurrIndex = numberOfData - aNum;
}
// Delete Items.
cArray->Delete( newCurrIndex, aNum );
iGrid->HandleItemRemovalL();
TBool oldCurrIndexWasRemoved = ETrue;
if ( aWhere && ( oldCurrIndex < numberOfData - aNum ) )
{
oldCurrIndexWasRemoved = EFalse;
}
// If item size changes, need to alter the item style
ApplySelGridGraphicStyleL();
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::SetVerticalScrollingType()
// Sets vertical scrolling type to member variables.
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsSelection::SetVerticalScrollingTypeL(
CAknGridView::TScrollingType aScrollingType )
{
iVerticalScrollingType = aScrollingType;
SetGridLayoutL();
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::SetHorizontalScrollingType()
// Sets horizontal scrolling type to member variables
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsSelection::SetHorizontalScrollingTypeL(
CAknGridView::TScrollingType aScrollingType )
{
iHorizontalScrollingType = aScrollingType;
SetGridLayoutL();
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::SetOrientation()
// Sets orientation to member variables
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsSelection::SetOrientation(
TBool aVerticalOrientation,
TBool aToRight, TBool aToBottom )
{
iVerticalOrientation = aVerticalOrientation;
iLeftToRight = aToRight;
iTopToBottom = aToBottom;
}
// -----------------------------------------------------------------------------
// CAknExGridContainerAsSelection::GetOrientation()
// Gets orientation from member variables
// -----------------------------------------------------------------------------
//
void CAknExGridContainerAsSelection::GetOrientation(
TBool& aVerticalOrientation,
TBool& aToRight, TBool& aToBottom )
{
aVerticalOrientation = iVerticalOrientation;
aToRight = iLeftToRight;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -