📄 logexamplecontainer.cpp
字号:
/*
* ============================================================================
* Name : CLogExampleContainer from LogExampleContainer.h
* 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 "LogExampleContainer.h"
#include "LogExEventForm.h"
#include <eiklabel.h> // for example label control
#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 = 2;
_LIT(KSingleStyleListBoxFofrmat, "%S\t%S"); // CAknSingleStyleListBox format "Head\tLabel"
_LIT(KExampleLabel, "Log Engine Example");
_LIT(KPanicMessageText, "Container");
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CLogExampleContainer::ConstructL(const TRect& aRect)
// Symbian two phased constructor
// ---------------------------------------------------------
//
void CLogExampleContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
iLabel->SetTextL( KExampleLabel );
// 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);
// Set listbox not visible
iEventsListBox->MakeVisible(EFalse);
// Construct list for events
iLogEvents = new (ELeave) CArrayPtrFlat<CLogEvent>(8);
SetRect(aRect);
ActivateL();
}
// ----------------------------------------------------
// CLogExampleContainer::~CLogExampleContainer()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CLogExampleContainer::~CLogExampleContainer()
{
delete iEventsListBox;
if(iLogEvents)
iLogEvents->ResetAndDestroy();
delete iLogEvents;
delete iLabel;
}
// ----------------------------------------------------
// CLogExampleContainer::ResetEventList()
// Empties the list of events
// ----------------------------------------------------
//
void CLogExampleContainer::ResetEventList()
{
iLogEvents->ResetAndDestroy(); // empty the list of events
CDesCArray* eventsArray = GetListBoxModel();
eventsArray->Reset();
}
// ----------------------------------------------------
// CLogExampleContainer::MakeVisible(TBool& aVisibility)
// Sets visibility
// ----------------------------------------------------
//
void CLogExampleContainer::MakeVisible(TBool& aVisibility)
{
iEventsListBox->MakeVisible(aVisibility);
}
// ----------------------------------------------------
// CLogExampleContainer::IsListBoxVisible()
// Returns true if listbox is visible, false if is not.
// ----------------------------------------------------
//
TBool CLogExampleContainer::IsListBoxVisible()
{
return iEventsListBox->IsVisible();
}
// ----------------------------------------------------
// CLogExampleContainer::ShowEventDetailsL()
// Shows event's details, which has been selected
// ----------------------------------------------------
//
void CLogExampleContainer::ShowEventDetailsL()
{
CLogEvent& event = *(iLogEvents->At(iEventsListBox->CurrentItemIndex()));
CLogExEventForm* form = CLogExEventForm::NewL(event);
form->ExecuteLD(R_LOGEXAMPLE_EVENTFORM_DIALOG);
}
// ----------------------------------------------------
// CLogExampleContainer::GetSelectedId(TLogId& aSelectedId)
// Gets currently selected item's index
// ----------------------------------------------------
//
void CLogExampleContainer::GetSelectedId(TLogId& aSelectedId)
{
iDeleteIndex = iEventsListBox->CurrentItemIndex();
__ASSERT_ALWAYS( (iDeleteIndex >= 0), User::Panic(KPanicMessageText, 1) );
aSelectedId = iLogEvents->At(iDeleteIndex)->Id();
}
// ----------------------------------------------------
// CLogExampleContainer::ListBoxItemCount()
// Returns amount of item's in listbox
// ----------------------------------------------------
//
TInt CLogExampleContainer::ListBoxItemCount()
{
return GetListBoxModel()->Count();
}
// ----------------------------------------------------
// CLogExampleContainer::NotifyEventReadL(const CLogEvent& aEvent)
// Reads an event and adds it to the list
// ----------------------------------------------------
//
void CLogExampleContainer::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
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
}
// ----------------------------------------------------
// CLogExampleContainer::NotifyEventAddedL(const CLogEvent& aEvent)
// Calls NotifyEventReadL to add an event to list
// ----------------------------------------------------
//
void CLogExampleContainer::NotifyEventAddedL(const CLogEvent& aEvent)
{
NotifyEventReadL(aEvent);
}
// ----------------------------------------------------
// CLogExampleContainer::NotifyEventDeletedL()
// Notifies an event is deleted
// ----------------------------------------------------
//
void CLogExampleContainer::NotifyEventDeletedL()
{
if(iDeleteIndex != -1)
{
delete iLogEvents->At(iDeleteIndex);
iLogEvents->Delete(iDeleteIndex);
iLogEvents->Compress();
CDesCArray* eventsArray = GetListBoxModel();
eventsArray->Delete(iDeleteIndex,1);
AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(iEventsListBox,
iDeleteIndex, ETrue);
}
iDeleteIndex = -1;
iEventsListBox->DrawNow(); // Update the list
}
// ---------------------------------------------------------
// CLogExampleContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CLogExampleContainer::SizeChanged()
{
iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
iEventsListBox->SetExtent(TPoint(0,0), iEventsListBox->MinimumSize());
}
// ---------------------------------------------------------
// CLogExampleContainer::CountComponentControls() const
// Return number of controls inside container (always 2)
// ---------------------------------------------------------
//
TInt CLogExampleContainer::CountComponentControls() const
{
return KNumberOfControls; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CLogExampleContainer::ComponentControl(TInt aIndex) const
// Gets the number of controls contained in a compound
// control.
// ---------------------------------------------------------
//
CCoeControl* CLogExampleContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iLabel;
case 1:
return iEventsListBox;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CLogExampleContainer::Draw(const TRect& aRect) const
// Draws rectangle
// ---------------------------------------------------------
//
void CLogExampleContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
// ---------------------------------------------------------
// CLogExampleContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// Framework calls, does nothing in this example
// ---------------------------------------------------------
//
void CLogExampleContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
// ---------------------------------------------------------
// CLogExampleContainer::HandleListBoxEventL(CEikListBox*
// /*aListBox*/, TListBoxEvent aListBoxEvent)
// Show details of event when item in the listbox is selected
// ---------------------------------------------------------
//
void CLogExampleContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/,
TListBoxEvent aListBoxEvent)
{
if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
(aListBoxEvent == MEikListBoxObserver::EEventItemClicked))
{
ShowEventDetailsL();
}
}
// ---------------------------------------------------------
// CLogExampleContainer::GetListBoxModel()
// Retrieves the model of the dynamic listbox
// and returns it.
// ---------------------------------------------------------
//
CDesCArray* CLogExampleContainer::GetListBoxModel()
{
CTextListBoxModel* model = iEventsListBox->Model();
model->SetOwnershipType (ELbmOwnsItemArray);
CDesCArray* eventsArray = static_cast<CDesCArray*>(model->ItemTextArray());
return eventsArray;
}
// ---------------------------------------------------------
// CLogExampleContainer::OfferKeyEventL(const TKeyEvent&
// aKeyEvent,TEventCode aType)
// Framework calls this method when a key event occurs.
// ---------------------------------------------------------
//
TKeyResponse CLogExampleContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
// Left and right arrow keyevents are used for tab switching,
// thus not offered to listbox
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 + -