📄 smsexamplemarkablelistcontainer.cpp
字号:
}
else if( iIdArray->Count() > aIndex )
{
TInt index = iSelectedIds->Find( (*iIdArray)[aIndex] );
if ( index != KErrNotFound )
{
iSelectedIds->Remove( index );
}
}
else
{
Panic(EGuiGeneral);
}
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::SetupListIconsL()
//
// Create icon array.
// ----------------------------------------------------------------------------
void CMarkableListContainer::SetupListIconsL()
{
// Get the name of the file containing the icons
HBufC* iconFilename = NULL;
iconFilename = StringLoader::LoadLC(R_ICON_FILE_NAME); //#ifdef in loc file
// Create an array of icons, reading them from the file
CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(KNumberOfIcons);
CleanupStack::PushL(icons);
#ifdef __UI_FRAMEWORKS_V2__ // NOT IN FP3, should executed also there
// because scalable ui is supported
CFbsBitmap* icon = NULL;
CFbsBitmap* iconMask = NULL;
CFbsBitmap* icon2 = NULL;
CFbsBitmap* iconMask2 = NULL;
AknIconUtils::CreateIconLC(icon, iconMask, *iconFilename,
EMbmSmsexampleTock,EMbmSmsexampleTock_mask);
CGulIcon* guiIcon = CGulIcon::NewL( icon, iconMask );
CleanupStack::PushL(guiIcon);
icons->AppendL( guiIcon );
CleanupStack::Pop(guiIcon);
CleanupStack::Pop(2); //icon, iconMask
AknIconUtils::CreateIconLC(icon2, iconMask2, *iconFilename,
EMbmSmsexampleTick,EMbmSmsexampleTick_mask);
CGulIcon* guiIcon2 = CGulIcon::NewL( icon2, iconMask2 );
CleanupStack::PushL(guiIcon2);
icons->AppendL( guiIcon2 );
CleanupStack::Pop(guiIcon2);
CleanupStack::Pop(2); //icon2, iconMask2
#else
CGulIcon* icon = iEikonEnv->CreateIconL(*iconFilename,
EMbmSmsexampleTock,
EMbmSmsexampleTock_mask);
CleanupStack::PushL(icon);
icons->AppendL(icon);
CleanupStack::Pop(icon);
icon =iEikonEnv->CreateIconL(*iconFilename, EMbmSmsexampleTick,
EMbmSmsexampleTick_mask);
CleanupStack::PushL(icon);
icons->AppendL(icon);
CleanupStack::Pop(icon);
#endif
CleanupStack::Pop(icons);
CleanupStack::PopAndDestroy(iconFilename);
// passing ownership of icons
iSmsListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::NewL(const TRect& aRect)
//
// Symbian OS 2 phase constructor.
// ----------------------------------------------------------------------------
CMarkableListContainer* CMarkableListContainer::NewL(const TRect& aRect)
{
CMarkableListContainer* self = CMarkableListContainer::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::NewLC(const TRect& aRect)
//
// Symbian OS 2 phase constructor.
// ----------------------------------------------------------------------------
CMarkableListContainer* CMarkableListContainer::NewLC(const TRect& aRect)
{
CMarkableListContainer* self = new (ELeave) CMarkableListContainer;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::~CMarkableListContainer()
//
// Destructor.
// ----------------------------------------------------------------------------
CMarkableListContainer::~CMarkableListContainer()
{
Cleanup();
}
void CMarkableListContainer::Cleanup()
{
iIdArray->Reset();
delete iIdArray;
iIdArray = 0;
iAddress->Reset();
delete iAddress;
iAddress = 0;
iMessage->Reset();
delete iMessage;
iMessage = 0;
delete iSmsListBox;
iSmsListBox = 0;
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::SizeChanged()
//
// Called by framework when the view size is changed
// ----------------------------------------------------------------------------
void CMarkableListContainer::SizeChanged()
{
iSmsListBox->SetExtent (KListPosition, iSmsListBox->MinimumSize());
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::CountComponentControls() const
//
// Called by the framework in compound controls
// ----------------------------------------------------------------------------
TInt CMarkableListContainer::CountComponentControls() const
{
return 1; // return number of controls inside this container
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::ComponentControl(TInt aIndex) const
//
// Called by the framework in compound controls
// ----------------------------------------------------------------------------
CCoeControl* CMarkableListContainer::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0:
return iSmsListBox;
default:
return NULL;
}
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::Draw(const TRect& aRect) const
//
// Called by the framework to draw this control.
// ----------------------------------------------------------------------------
void CMarkableListContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear(aRect);
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
// TEventCode aType)
//
// Called by the framework whenever a key event occurs.
// ----------------------------------------------------------------------------
TKeyResponse CMarkableListContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
{
if (iSmsListBox)
return iSmsListBox->OfferKeyEventL (aKeyEvent, aType);
else
return EKeyWasNotConsumed;
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::SetIdArray(RArray<TMsvId>* aArray)
// ----------------------------------------------------------------------------
void CMarkableListContainer::SetIdArray(RArray<TMsvId>* aArray)
{
iIdArray = aArray;
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::GetSelectedItems()
//
// Return an array of items that have been selected.
// ----------------------------------------------------------------------------
RArray<TMsvId>* CMarkableListContainer::GetSelectedItems()
{
return iSelectedIds;
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/,
// TListBoxEvent aListBoxEvent)
//
// Called by the framework whenever a list event occurs for which this container
// is an observer.
// ----------------------------------------------------------------------------
void CMarkableListContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/,
TListBoxEvent aListBoxEvent)
{
// if the Select Key has been pressed
if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
(aListBoxEvent == MEikListBoxObserver::EEventItemClicked))
{
MarkOrUnMarkL();
}
}
// ----------------------------------------------------------------------------
// CMarkableListContainer::AddItemL(const TDesC& aNewItem)
//
// Add an item into the listbox.
// ----------------------------------------------------------------------------
void CMarkableListContainer::AddItemL(const TDesC& aFirstLabel,
const TDesC& aSecondLabel)
{
CTextListBoxModel* model = iSmsListBox->Model();
model->SetOwnershipType (ELbmOwnsItemArray);
CDesCArray* smsArray = static_cast <CDesCArray*> (model->ItemTextArray());
TBuf <KAknExListAddItemBufLength> addedItem( KBeginIdx );
// List item string format: "0\tFirstLabel\tSecondLabel\t0"
// where 0 is index to icon array
// Listbox icon is required at the beginning of a descriptor,
//" \t" if there is no icon.
_LIT( KBeginning, "0\t");
addedItem.Append( KBeginning );
addedItem.Append( aFirstLabel );
// Second icon is always empty.
_LIT( KEnd, "\t");
addedItem.Append( KEnd );
addedItem.Append( aSecondLabel );
addedItem.Append( KEnd );
// Insert a new item into the array
smsArray->AppendL( addedItem );
iSmsListBox->HandleItemAdditionL();
}
// End of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -