chxavinfolist.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:4k
- /*****************************************************************************
- * chxavinfolist.cpp
- * -----------------
- *
- * Synopsis:
- * Info list manager for stuff.
- *
- *
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *****************************************************************************/
- // Symbian includes...
- #include <e32base.h>
- #include <badesca.h>
- #include <bamdesca.h>
- #include <coeutils.h>
- #include <aknenv.h>
- // Includes from this project...
- #include "chxavmisc.h"
- #include "chxavinfolist.h"
- #include "chxavcleanupstack.h"
- #include "chxavcleanstring.h"
- #include "chxavmiscconstants.h"
- ///////////////////////////////////
- // ctor
- CHXAvInfoList::CHXAvInfoList()
- {
- }
- ///////////////////////////////////
- // dtor
- CHXAvInfoList::~CHXAvInfoList()
- {
- }
- void CHXAvInfoList::ConstructL()
- {
- m_pFont = CEikonEnv::Static()->NormalFont();
- m_pLabels = new (ELeave) CDesCArrayFlat( CHXAvMisc::k_defaultArrayGranularity );
- m_pFields = new (ELeave) CDesCArrayFlat( CHXAvMisc::k_defaultArrayGranularity );
- const TInt k_cchMaxDisplayLine = 50;
- m_pbuff = HBufC::NewL(k_cchMaxDisplayLine);
- }
- ///////////////////////////////////
- //
- void CHXAvInfoList::AddLineL(const TDesC& caption, const TDesC& fieldText, AddLineFlag flag)
- {
- // make sure field is stripped of bad (unprintable) characters (caption is assumed good)
- HBufC* pFixedText = CHXAvMisc::AllocDisplayFriendlyStringL(fieldText);
- AUTO_PUSH_POP_DEL(pFixedText);
- if( 0 == pFixedText->Length() && skipEmptyLine == flag )
- {
- // skip this; we don't display lines with empty fields
- return;
- }
- HBufC* pField = 0;
- if (pFixedText->Length())
- {
- pField = pFixedText->AllocL();
- }
- else
- {
- pField = CHXAvMisc::KOneSpace().AllocL();
- }
- AUTO_PUSH_POP_DEL(pField);
- CArrayFix<TInt>* pWidths = new ( ELeave ) CArrayFixFlat<TInt>(CHXAvMisc::k_defaultArrayGranularity);
- AUTO_PUSH_POP_DEL(pWidths);
- TInt cxFieldText = m_pFont->TextWidthInPixels(fieldText);
- if( cxFieldText > CHXAvMisc::k_cxMaxPopupListBoxLine )
- {
- TInt lineCount = cxFieldText / CHXAvMisc::k_cxMaxPopupListBoxLine + 2;
- pWidths->AppendL( CHXAvMisc::k_cxMaxPopupListBoxLine, lineCount );
- }
- else
- {
- pWidths->AppendL( CHXAvMisc::k_cxMaxPopupListBoxLine, 4);
- }
- //
- // split up field into lines: pField -> array of broken up lines (pLines)
- //
- CArrayFix<TPtrC>* pLines = new ( ELeave ) CArrayFixFlat<TPtrC>(CHXAvMisc::k_defaultArrayGranularity);
- AUTO_PUSH_POP_DEL(pLines);
- AknTextUtils::WrapToArrayL(
- *pField,
- *pWidths,
- *m_pFont,
- *pLines );
- // add as many lines as necessary to fully display field of text
- const TInt count = pLines->Count();
- for ( TInt idx = 0; idx < count; ++idx )
- {
- // caption field
- if (0 == idx)
- {
- // first line gets actual caption
- m_pLabels->AppendL(caption);
- }
- else
- {
- m_pLabels->AppendL(CHXAvMisc::KOneSpace);
- }
- // value field
- m_pFields->AppendL((*pLines)[idx]);
- }
- }
- ///////////////////////////////////
- // add one or more lines (as many as necessary) to display
- // given field of text
- //
- void CHXAvInfoList::AddLineL(TInt idCaptionText, const TDesC& fieldText, AddLineFlag flag)
- {
- CHXAvCleanString caption(idCaptionText);
- AddLineL(caption(), fieldText, flag);
- }
- ///////////////////////////////////
- //
- void CHXAvInfoList::AddLinesL(const MDesCArray* pCaptions, const MDesCArray* pFields, AddLineFlag flag)
- {
- HX_ASSERT(pCaptions->MdcaCount() == pFields->MdcaCount());
- TInt count = pCaptions->MdcaCount();
- for(TInt idx = 0; idx < count; ++idx)
- {
- AddLineL(pCaptions->MdcaPoint(idx), pFields->MdcaPoint(idx), flag);
- }
- }
- ///////////////////////////////////
- //
- TInt CHXAvInfoList::MdcaCount() const
- {
- return m_pLabels->Count();
- }
- ///////////////////////////////////
- //
- TPtrC CHXAvInfoList::MdcaPoint(TInt aIndex) const
- {
- TPtr ptr = m_pbuff->Des();
- ptr.Zero();
- ptr.Append((*m_pLabels)[aIndex]);
- ptr.Append(CHXAvMisc::KListColumnDelimiter);
- ptr.Append((*m_pFields)[aIndex]);
- return ptr;
- }