⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logexamplecontainer.cpp

📁 专业的用于查询手机通话记录的代码
💻 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 <akndef.h>    // scalable UI support
#include <aknutils.h>  // scalable UI support
#include <gdi.h>  // TFontSpec
//#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 = 1;
// CAknSingleStyleListBox format "Head\tLabel"
_LIT(KSingleStyleListBoxFofrmat, "%S\t%S");
_LIT(KPanicMessageText, "Container");

// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CLogExampleContainer::ConstructL(const TRect& aRect)
// Symbian two phased constructor
// ---------------------------------------------------------
//
void CLogExampleContainer::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();
    }

// ----------------------------------------------------
// CLogExampleContainer::~CLogExampleContainer()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CLogExampleContainer::~CLogExampleContainer()
    {
    delete iEventsListBox;
    if (iLogEvents)
        iLogEvents->ResetAndDestroy();
    delete iLogEvents;
    }

// ----------------------------------------------------
// CLogExampleContainer::ResetEventList()
// Empties the list of events
// ----------------------------------------------------
//
void CLogExampleContainer::ResetEventList()
    {
    iLogEvents->ResetAndDestroy(); // empty the list of events 
    CDesCArray* eventsArray = GetListBoxModel();
    eventsArray->Reset();
    }

// ----------------------------------------------------
// CLogExampleContainer::ShowEventDetailsL()
// Shows event's details, which has been selected
// ----------------------------------------------------
//
void CLogExampleContainer::ShowEventDetailsL()
    {
    TInt curIndex = iEventsListBox->CurrentItemIndex();
    if (curIndex>=0 && curIndex<iLogEvents->Count())
        {
        CLogEvent& event = *(iLogEvents->At(curIndex));
        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 && iDeleteIndex<iLogEvents->Count()),
            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 >= 0 && iDeleteIndex<iLogEvents->Count())
        {
        delete iLogEvents->At(iDeleteIndex);
        iLogEvents->Delete(iDeleteIndex);
        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()
    {
    iEventsListBox->SetExtent(TPoint(0, 0), iEventsListBox->MinimumSize());
    }

// ---------------------------------------------------------
// Called by the framework when resource is changed (e.g.
// the fold is flipped open).
// ---------------------------------------------------------
void CLogExampleContainer::HandleResourceChange(TInt aType)
    {
    CCoeControl::HandleResourceChange(aType);

    // Scalable UI support
    if (aType==KEikDynamicLayoutVariantSwitch)
        {
        TRect rect;
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
        SetRect(rect);
        }
    }

// ---------------------------------------------------------
// 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 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)
    {
    return iEventsListBox->OfferKeyEventL(aKeyEvent, aType);
    }

// End of File  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -