📄 logexamplecontainer2.cpp
字号:
/*
* ============================================================================
* Name : CLogExampleContainer2 from LogExampleContainer2.cpp
* Part of : LogExample
* Created : 26.05.2005 by Forum Nokia
* Implementation notes:
* Initial content was generated by Series 60 Application Wizard.
* Version : 1.0
* Copyright: Nokia Corporation
* ============================================================================
*/
// INCLUDE FILES
#include "LogExampleContainer2.h"
#include "LogExEventForm.h"
#include <aknlists.h> // CAknSingleStyleListBox
#include <barsread.h> // TResourceReader
#include <stringloader.h> //StringLoader
#include <AknGlobalNote.h> //CAknGlobalNote
#include <eiklbo.h> // MEikListBoxObserver
#include <LogExample.rsg>
// CONSTANTS
const TInt KMaxListItemTextLength = 128;
const TInt KNumberOfControls = 1;
_LIT(KSingleStyleListBoxFofrmat, "%S\t%S"); // CAknSingleStyleListBox format "Head\tLabel"
_LIT(KPanicMessageText, "Container2");
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CLogExampleContainer2::ConstructL(const TRect& aRect)
// Symbian two phased constructor
// ---------------------------------------------------------
//
void CLogExampleContainer2::ConstructL(const TRect& aRect)
{
CreateWindowL();
// Construction of dynamic listbox which shows the events
iEventsListBox = new (ELeave) CAknSingleHeadingStyleListBox;
iEventsListBox->SetContainerWindowL(*this);
// set observer for the list
iEventsListBox->SetListBoxObserver(this);
// Second Phase Construction
TResourceReader reader;
CEikonEnv::Static()->CreateResourceReaderLC(reader, R_DYNAMICLIST_EVENTS_LISTBOX);
iEventsListBox->ConstructFromResourceL( reader );
CleanupStack::PopAndDestroy(); //reader
// set scrollbars
iEventsListBox->CreateScrollBarFrameL();
iEventsListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,
CEikScrollBarFrame::EAuto);
// Construct list for events
iLogEvents = new (ELeave) CArrayPtrFlat<CLogEvent>(8);
iDeleteIndex = -1;
SetRect(aRect);
ActivateL();
}
// ----------------------------------------------------
// CLogExampleContainer2::~CLogExampleContainer2()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CLogExampleContainer2::~CLogExampleContainer2()
{
delete iEventsListBox;
if(iLogEvents)
iLogEvents->ResetAndDestroy();
delete iLogEvents;
}
// ----------------------------------------------------
// CLogExampleContainer2::ResetEventList()
// Empties the list of events
// ----------------------------------------------------
//
void CLogExampleContainer2::ResetEventList()
{
iLogEvents->ResetAndDestroy();
CDesCArray* eventsArray = GetListBoxModel();
eventsArray->Reset();
}
// ----------------------------------------------------
// CLogExampleContainer2::ShowEventDetails()
// Shows event's details, which has been selected
// ----------------------------------------------------
//
void CLogExampleContainer2::ShowEventDetailsL()
{
CLogEvent& event = *(iLogEvents->At(iEventsListBox->CurrentItemIndex()));
CLogExEventForm* form = CLogExEventForm::NewL(event);
form->ExecuteLD(R_LOGEXAMPLE_EVENTFORM_DIALOG);
}
// ----------------------------------------------------
// CLogExampleContainer2::GetSelectedId(TLogId& aSelectedId)
// Gets currently selected item's index
// ----------------------------------------------------
//
void CLogExampleContainer2::GetSelectedId(TLogId& aSelectedId)
{
iDeleteIndex = iEventsListBox->CurrentItemIndex();
__ASSERT_ALWAYS( (iDeleteIndex >= 0), User::Panic(KPanicMessageText, 1) );
aSelectedId = iLogEvents->At(iDeleteIndex)->Id();
}
// ----------------------------------------------------
// CLogExampleContainer2::ListBoxItemCount()
// Returns amount of item's in listbox
// ----------------------------------------------------
//
TInt CLogExampleContainer2::ListBoxItemCount()
{
return GetListBoxModel()->Count();
}
// ----------------------------------------------------
// CLogExampleContainer2::NotifyEventReadL(const CLogEvent& aEvent)
// Reads an event and adds it to the list.
// ----------------------------------------------------
//
void CLogExampleContainer2::NotifyEventReadL(const CLogEvent& aEvent)
{
// Copy the element to the list of events
// This avoids another asynchronous request
// if details of events needs to be shown
CLogEvent* event = CLogEvent::NewL();
CleanupStack::PushL(event);
event->CopyL(aEvent);
iLogEvents->AppendL(event);
CleanupStack::Pop(event);
CDesCArray* eventsArray = GetListBoxModel();
TBuf<KMaxListItemTextLength> listItemText;
// Format the listbox element ("Head\tLabel" see KSingleStyleListBoxFormat).
// Check if the RemotyParty descriptor is empty. In that case show number instead.0
if(aEvent.RemoteParty().Length() == 0)
{
listItemText.Format(KSingleStyleListBoxFofrmat,
&(aEvent.Description()),
&(aEvent.Number()));
}
else
{
listItemText.Format(KSingleStyleListBoxFofrmat,
&(aEvent.Description()),
&(aEvent.RemoteParty()));
}
eventsArray->AppendL(listItemText); // Put the formatted item to the listbox
iEventsListBox->HandleItemAdditionL();
iEventsListBox->DrawNow(); // Update the list
}
// ----------------------------------------------------
// CLogExampleContainer2::NotifyEventAddedL(const CLogEvent& aEvent)
// Calls NotifyEventReadL to add an event to list
// ----------------------------------------------------
//
void CLogExampleContainer2::NotifyEventAddedL(const CLogEvent& aEvent)
{
NotifyEventReadL(aEvent);
}
// ----------------------------------------------------
// CLogExampleContainer2::NotifyEventDeletedL()
// Notifies an event is deleted
// ----------------------------------------------------
//
void CLogExampleContainer2::NotifyEventDeletedL()
{
if(iDeleteIndex != -1)
{
delete iLogEvents->At(iDeleteIndex);
iLogEvents->Delete(iDeleteIndex);
CDesCArray* eventsArray = GetListBoxModel();
eventsArray->Delete(iDeleteIndex);
AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(iEventsListBox,
iDeleteIndex, ETrue);
}
iDeleteIndex = -1;
iEventsListBox->DrawNow(); // Update the list
}
// ---------------------------------------------------------
// CLogExampleContainer2::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CLogExampleContainer2::SizeChanged()
{
iEventsListBox->SetExtent(TPoint(0,0), iEventsListBox->MinimumSize());
}
// ---------------------------------------------------------
// CLogExampleContainer2::CountComponentControls() const
// Return number of controls inside container (always 1)
// ---------------------------------------------------------
//
TInt CLogExampleContainer2::CountComponentControls() const
{
return KNumberOfControls; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CLogExampleContainer2::ComponentControl(TInt aIndex) const
// Gets the number of controls contained in a compound
// control.
// ---------------------------------------------------------
//
CCoeControl* CLogExampleContainer2::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iEventsListBox;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CLogExampleContainer2::Draw(const TRect& aRect) const
// Draws rectangle
// ---------------------------------------------------------
//
void CLogExampleContainer2::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
// ---------------------------------------------------------
// CLogExampleContainer2::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// Framework calls, does nothing in this example
// ---------------------------------------------------------
//
void CLogExampleContainer2::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
// ---------------------------------------------------------
// CLogExampleContainer2::HandleListBoxEventL(CEikListBox*
// /*aListBox*/, TListBoxEvent aListBoxEvent)
// Shows details of event when item in the listbox is selected
// ---------------------------------------------------------
//
void CLogExampleContainer2::HandleListBoxEventL(CEikListBox* /*aListBox*/,
TListBoxEvent aListBoxEvent)
{
if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
(aListBoxEvent == MEikListBoxObserver::EEventItemClicked))
{
ShowEventDetailsL();
}
}
// ---------------------------------------------------------
// CLogExampleContainer2::GetListBoxModel()
// Retrieves the model of the dynamic listbox
// and returns it.
// ---------------------------------------------------------
//
CDesCArray* CLogExampleContainer2::GetListBoxModel()
{
CTextListBoxModel* model = iEventsListBox->Model();
model->SetOwnershipType (ELbmOwnsItemArray);
CDesCArray* eventsArray = static_cast<CDesCArray*>(model->ItemTextArray());
return eventsArray;
}
// ---------------------------------------------------------
// CLogExampleContainer2::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
// Framework calls this method when a key event occurs.
// ---------------------------------------------------------
//
TKeyResponse CLogExampleContainer2::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
{
//Left and right arrow keyevents are used for tab switching, thus returned
if(aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow)
{
return EKeyWasNotConsumed;
}
else
{
return iEventsListBox->OfferKeyEventL (aKeyEvent, aType);
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -