halviewcontainer.cpp
来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C++ 代码 · 共 264 行
CPP
264 行
/**
*
* @brief Definition of CHalViewContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDES
// Class include
#include "HalViewContainer.h"
// System includes
#include <eikclbd.h>
#include <eiklabel.h> // CEikLabel
#include <badesca.h>
#include <aknlists.h> // CAknDoubleGraphicStyleListBox
#include <akniconarray.h>
#include <barsread.h> // TResourceReader
#include <hal_data.h> // HALData::TAttribute
#include <HalView.rsg>
#include <HalView.mbg>
#include <stringloader.h> // StringLoader
#include "HalViewDocument.h"
#include "HalViewAppUi.h"
#include "HalViewView.h"
// CONSTANTS
const TInt KAttributesPerListBox = 15;
const TInt KMaxBufferSize = 64;
const TInt KNumIcons = 2;
_LIT(KTab, "\t");
// ================= MEMBER FUNCTIONS =======================
/**
* Constructor forcing creator to supply document and view objects
*/
CHalViewContainer::CHalViewContainer(CHalViewView& aView)
:iView(aView)
{
}
/**
* Destructor. Frees up memory
*/
CHalViewContainer::~CHalViewContainer()
{
delete iListBox;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CHalViewContainer using the constructor and ConstructL
* method. the constructed object is popped from the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CHalViewContainer
*/
CHalViewContainer* CHalViewContainer::NewL(CHalViewView& aView, const TRect& aRect)
{
CHalViewContainer* self = new (ELeave) CHalViewContainer(aView);
CleanupStack::PushL(self);
self->ConstructL(aRect);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2nd phase constructor. Creates a Window for the controls, which it contains.
* @param aRect The rectangle for this window
*/
void CHalViewContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
ActivateL();
}
/**
* Causes the container to create and display the appropriate
* list box for the given id (== active tab)
*/
void CHalViewContainer::DisplayAttributesByIdL(TInt aId)
{
// Calculate the range of HAL entries to display on this tab.
iFirstEntry = aId * KAttributesPerListBox;
iLastEntry = iFirstEntry + KAttributesPerListBox;
TInt maxAttribute = static_cast<CHalViewDocument*>(static_cast<CHalViewAppUi*>(ControlEnv()->AppUi())->Document())->NumHalEntries();
// there are less items in the last list box
if (iLastEntry > maxAttribute)
{
iLastEntry = maxAttribute;
}
// construct the list box
delete iListBox;
iListBox = NULL;
iListBox = new (ELeave) CAknDoubleGraphicStyleListBox;
iListBox->ConstructL(this, EAknListBoxSelectionList);
// set the icons in the list box
CArrayPtr<CGulIcon>* icons = new (ELeave) CAknIconArray(KNumIcons);
CleanupStack::PushL(icons);
HBufC* mbmFileName = StringLoader::LoadLC(R_HAL_VIEW_MBM_FILE_NAME); // Buffer on cleanup stack
icons->AppendL(iEikonEnv->CreateIconL(*mbmFileName, EMbmHalviewNo, EMbmHalviewNom));
icons->AppendL(iEikonEnv->CreateIconL(*mbmFileName, EMbmHalviewYes, EMbmHalviewYesm));
CleanupStack::PopAndDestroy(mbmFileName);
// pass ownership of icons to the list box
iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
CleanupStack::Pop(icons);
ReadHalValuesL(aId);
// Creates scrollbar.
iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
iListBox->SetRect(Rect());
iListBox->ActivateL();
DrawNow();
}
/**
* Fill the list box with values read from the HAL
*/
void CHalViewContainer::ReadHalValuesL(TInt aId)
{
TInt resourceId(CalculateResourceIdL(aId));
// Take ownership of headings array.
CDesC16ArrayFlat* headings = iEikonEnv->ReadDesC16ArrayResourceL(resourceId);
CleanupStack::PushL(headings);
CDesCArray* itemArray = static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray());
for (TInt index = 0; index < headings->Count() && index + iFirstEntry < iLastEntry; ++index)
{
TBuf<KMaxBufferSize> thisEntry;
CHalViewDocument* document = static_cast<CHalViewDocument*>(static_cast<CHalViewAppUi*>(ControlEnv()->AppUi())->Document());
// If the entry is dynamic then display the icon created using the bitmap EMbmHalviewYes to show this.
if (document->GetHalEntry(index).iProperties & HAL::EEntryDynamic)
{
thisEntry.AppendNum(1);
}
else // Display the icon created using the bitmap EMbmHalviewNo to show that it is not dynamic.
{
thisEntry.AppendNum(0);
}
thisEntry.Append(KTab);
thisEntry.Append((*headings)[index]);
thisEntry.Append(KTab);
thisEntry.AppendNum(document->GetHalEntry(index).iValue);
itemArray->AppendL(thisEntry);
}
CleanupStack::PopAndDestroy(); // headings
iListBox->HandleItemAdditionL();
}
/**
* Get the correct headings list for the given tab id.
*/
TInt CHalViewContainer::CalculateResourceIdL(TInt aId)
{
TInt resourceId(0);
switch (aId)
{
case 0:
resourceId = R_HALVIEW_LISTBOX1_HEADINGS;
break;
case 1:
resourceId = R_HALVIEW_LISTBOX2_HEADINGS;
break;
case 2:
resourceId = R_HALVIEW_LISTBOX3_HEADINGS;
break;
case 3:
resourceId = R_HALVIEW_LISTBOX4_HEADINGS;
break;
case 4:
resourceId = R_HALVIEW_LISTBOX5_HEADINGS;
break;
}
return resourceId;
}
/**
* Called by the framework in compound controls
* @return The number of controls in this CHalViewContainer
*/
TInt CHalViewContainer::CountComponentControls() const
{
if (iListBox)
{
return 1;
}
return 0;
}
/**
* Called by the framework in compound controls
* @param The index of the control to return
* @return The control for aIndex
*/
CCoeControl* CHalViewContainer::ComponentControl(TInt aIndex) const
{
if (aIndex == 0)
{
return iListBox;
}
return NULL;
}
/**
* Called by the framework to draw this control. Clears the area in
* aRect.
* @param aRect in which to draw
*/
void CHalViewContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear(aRect);
}
/**
* Respond to key events. Allow tab control to consume right/left arrows
*/
TKeyResponse CHalViewContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
// Ignore non-event keys
if (aType != EEventKey)
{
return EKeyWasNotConsumed;
}
// Pass left/right arrow keys to tab container
else if (aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow)
{
return iView.OfferKeyToTabGroupL(aKeyEvent, aType);
}
// Pass other key events to the listbox, if present
else if (iListBox)
{
return iListBox->OfferKeyEventL(aKeyEvent, aType);
}
return EKeyWasNotConsumed;
}
// End of File
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?