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

📄 smscontainer.cpp

📁 个人手机助理套件:包含1、记事本(备忘录)、名片夹、名片夹的上传下载(异地备份)、短消息模块
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CSmsContainer from CCoeControl, MCoeControlObserver
*  Part of  : Sms
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES
#include <HelperGenius.rsg>
#include "HelperGenius.hrh"
#include "SmsContainer.h"
#include <aknlists.h>
#include "HelperGeniusAppUi.h"
#include <EikEnv.h>
#include <Helpergenius.mbg>
#include <fbs.h>
#include <AknUtils.h>
#include <stringloader.h>
#include <barsread.h>
#include <gulicon.h> 
#include <AknIconArray.h> 
#include <EIKCLB.H>
#include <eikfrlb.h> 
#include <eikslb.h> 





#define  DELPTR(p) if(p!=NULL){ delete p;p=NULL;}
// ================= MEMBER SmsS =======================

// C++ default constructor can NOT contain any code, that
// might leave.
//
CSmsContainer::CSmsContainer()
    {
	m_pListBox = NULL;
	   m_pBitmap = NULL;
	m_pListBoxArray = NULL;
    }

// EPOC default constructor can leave.
void CSmsContainer::ConstructL(const TRect& aRect)
     {
    CreateWindowL();

	m_pBitmap = new (ELeave) CFbsBitmap;
	TBuf<KMaxPath> pathMbm;
#ifdef __WINS__
	pathMbm.Copy(_L("z:\\system\\apps\\HelperGenius\\HelperGenius.mbm"));
#else
	CHelperGeniusAppUi* pApp = (CHelperGeniusAppUi*)CEikonEnv::Static()->AppUi();
	pApp->GetAppPath(pathMbm);
	
	pathMbm.Append(_L("HelperGenius.mbm"));
#endif
    User::LeaveIfError(CompleteWithAppPath(pathMbm));
    User::LeaveIfError(m_pBitmap->Load(pathMbm,EMbmHelpergeniusHelpergenius_icon_17));

	   m_pListBox = new(ELeave) CAknSingleGraphicStyleListBox;
	   CleanupStack::PushL(m_pListBox);
	   m_pListBox->ConstructL(this,EAknListBoxMarkableList | EAknListBoxMultiselectionList);
	   m_pListBox->SetContainerWindowL(*this);
	   m_pListBox->SetRect(aRect);
	   m_pListBox->CreateScrollBarFrameL(ETrue);
	   m_pListBox->ScrollBarFrame( )->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto);

	   m_pListBoxArray = new (ELeave) CDesCArrayFlat(4);
	   CleanupStack::PushL(m_pListBoxArray);
	   
	   SetupListIconsL();
	   AddInfoToList();

	   CTextListBoxModel* model = m_pListBox->Model();
	   model->SetItemTextArray( m_pListBoxArray );
	   model->SetOwnershipType(ELbmDoesNotOwnItemArray);
	   CleanupStack::Pop(2);	
	   m_pListBox->ActivateL();
	   m_pListBox->SetFocus( ETrue );
	   iIndex = 0;

     SetRect(aRect);
     ActivateL();


	 //来自网上
	 
// 	 LIT( KListItemFormat, "0\tItem %d" );
// 	 void CFMOForSymbianMailList::InitializeControlsL()
// 	 {
// 		 iListBox = new ( ELeave ) CAknSingleGraphicStyleListBox;
// 		 iListBox->SetContainerWindowL( *this );
// 		 {
// 			 TResourceReader reader;
// 			 iEikonEnv->CreateResourceReaderLC( reader, R_FMOFOR_SYMBIAN_MAIL_LIST_LIST_BOX );
// 			 iListBox->ConstructFromResourceL( reader );
// 			 CleanupStack::PopAndDestroy(); // reader internal state
// 		 }
// 		 // the listbox owns the items in the list and will free them
// 		 iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
// 		 
// 		 TBuf<20> itemText;
// 		 
// 		 CDesCArray* itemArray = new ( ELeave ) CDesCArrayFlat(4);
// 		 
// 		 for( TInt i = 1; i < 5; ++i )
// 		 {
// 			 itemText.Format( KListItemFormat(), i );
// 			 itemArray->AppendL( itemText );
// 		 }
// 		 
// 		 iListBox->Model()->SetItemTextArray( itemArray );
// 		 iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
// 		 iListBox->HandleItemAdditionL();
// 		 // setup the icon array so graphics-style boxes work
// 		 SetupListBoxIconsL();
// 		 
// 		 
// 		 // add list items
// 		 
// 		 iListBox->SetFocus( ETrue );
// 		 iFocusControl = iListBox;
// 		 
// 	 }

    }

// Destructor
CSmsContainer::~CSmsContainer()
    {
       DELPTR(m_pListBox);
	   DELPTR(m_pBitmap);
	   DELPTR(m_pListBoxArray);	   

    }

// ---------------------------------------------------------
// CSmsContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//

void CSmsContainer::FocusTo(TInt aCommand)
    {
    }

// ---------------------------------------------------------
// CSmsContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CSmsContainer::SizeChanged()
    {
      if(m_pListBox)
	{
		m_pListBox->SetRect(Rect( ) );
	}
    }

// ---------------------------------------------------------
// CSmsContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CSmsContainer::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }

// ---------------------------------------------------------
// CSmsContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CSmsContainer::ComponentControl(TInt aIndex) const
    {
		return m_pListBox;
    }

// ---------------------------------------------------------
// CSmsContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CSmsContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
	 gc.Clear(aRect);
	 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);  
 	gc.SetBrushColor(KRgbWhite);
	gc.DrawLine(TPoint(43,0),TPoint(43,142));  //画线
	gc.DrawLine(TPoint(43,142),TPoint(174,142));
	/******添加背景图片*******************************************/
//     gc.Clear(aRect);
//     TPoint topLeft(0,0);
// 	//    gc.DrawBitmap(TRect(topLeft,TSize(176,208)),m_pBitmap);
//     gc.BitBlt(topLeft,m_pBitmap,TRect(topLeft,TSize(176,208)));
    }

// ---------------------------------------------------------
// CSmsContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CSmsContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
	if(NULL != m_pListBox)
	{
		if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
		{
			if(iIndex == m_pListBoxArray->Count()-1)
				iIndex = 0;
			else
				++iIndex;
			return m_pListBox->OfferKeyEventL(aKeyEvent, aType);
		}
		else if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
		{
			if(iIndex == 0)
				iIndex = m_pListBoxArray->Count()-1;
			else
				--iIndex;
			return m_pListBox->OfferKeyEventL(aKeyEvent, aType);
		}
		return EKeyWasConsumed;
	}
    return EKeyWasNotConsumed;
}


// ---------------------------------------------------------
// CSmsContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CSmsContainer::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    }

void CSmsContainer::AddInfoToList()
{
// 	CHelperGeniusAppUi* pApp = (CHelperGeniusAppUi*)CEikonEnv::Static()->AppUi();
// 	CArrayVarFlat<CSmsInfo>* aSmsInfo = pApp->GetArray(); 
// 	for(TInt i = 0;i<aSmsInfo->Count();i++)
// 	{
// 		TBuf<64> sBuf;
// 		sBuf.Zero();
// 		sBuf.AppendNum(i+1);
// 		sBuf.Append(_L("\t"));
// 		TBuf<15> strTilte;
// 		strTilte.Zero( );
// 		(aSmsInfo->At(i)).GetTitle(strTilte);
// 		sBuf.Append(strTilte);	
// 		m_pListBoxArray->AppendL(sBuf);
// 	}



	// 	 LIT( KListItemFormat, "0\tItem %d" );
	// 	 void CFMOForSymbianMailList::InitializeControlsL()
	// 	 {
	// 		 iListBox = new ( ELeave ) CAknSingleGraphicStyleListBox;
	// 		 iListBox->SetContainerWindowL( *this );
	// 		 {
	// 			 TResourceReader reader;
	// 			 iEikonEnv->CreateResourceReaderLC( reader, R_FMOFOR_SYMBIAN_MAIL_LIST_LIST_BOX );
	// 			 iListBox->ConstructFromResourceL( reader );
	// 			 CleanupStack::PopAndDestroy(); // reader internal state
	// 		 }
	// 		 // the listbox owns the items in the list and will free them
	// 		 iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
	// 		 
	// 		 TBuf<20> itemText;
	// 		 
	// 		 CDesCArray* itemArray = new ( ELeave ) CDesCArrayFlat(4);
	// 		 
	// 		 for( TInt i = 1; i < 5; ++i )
	// 		 {
	// 			 itemText.Format( KListItemFormat(), i );
	// 			 itemArray->AppendL( itemText );
	// 		 }
	// 		 
	// 		 iListBox->Model()->SetItemTextArray( itemArray );
	// 		 iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
	// 		 iListBox->HandleItemAdditionL();
	// 		 // setup the icon array so graphics-style boxes work
	// 		 SetupListBoxIconsL();
	// 		 
	// 		 
	// 		 // add list items
	// 		 
	// 		 iListBox->SetFocus( ETrue );
	// 		 iFocusControl = iListBox;
	// 		 
// 	 }


    
	TBuf<20> itemText, buf;
//添加写信息图标及中文
	_LIT( KListItemFormat1, "0\t" );	
	itemText.Format(KListItemFormat1());
	CEikonEnv::Static()->ReadResource( buf, R_QTN_MH_SMS_WRITESMS );
	itemText.Append(buf);
	m_pListBoxArray->AppendL( itemText );

//添加收件箱图标及中文
	_LIT( KListItemFormat2, "1\t " );
	itemText.Format(KListItemFormat2());
	buf.Zero();
	CEikonEnv::Static()->ReadResource( buf, R_QTN_MH_SMS_INBOX );
	itemText.Append(buf);
	m_pListBoxArray->AppendL( itemText );

//添加草稿箱图标及中文
	_LIT( KListItemFormat3, "2\t " );
	itemText.Format(KListItemFormat3());
	buf.Zero();
	CEikonEnv::Static()->ReadResource( buf, R_QTN_MH_SMS_DRAFTS );
	itemText.Append(buf);
	m_pListBoxArray->AppendL( itemText );

//添加已发信息图标及中文
	_LIT( KListItemFormat4, "3\t " );
	itemText.Format(KListItemFormat4());
	buf.Zero();
	CEikonEnv::Static()->ReadResource( buf, R_QTN_MH_SMS_SENT );
	itemText.Append(buf);
	m_pListBoxArray->AppendL( itemText );



    

// 
// 	for( TInt i = 0; i < 4; ++i )
// 	 {
// 		 itemText.Format( KListItemFormat(), i );
// 		 m_pListBoxArray->AppendL( itemText );
// 	 }

	

// 	TBuf<32> sBuf, buf;	
// 	sBuf.Append(_L("\t"));
// 	CEikonEnv::Static()->ReadResource( buf, R_QTN_MH_SMS_WRITESMS );
// 	sBuf.Append(buf);
	//m_pListBoxArray->AppendL(sBuf);

// 	CEikonEnv::Static()->ReadResource( buf, R_QTN_MH_SMS_RECEIVESMS );	
// 	m_pListBoxArray->AppendL(buf);
// 
// 	CEikonEnv::Static()->ReadResource( buf, R_QTN_MH_SMS_DRAFTSMS );	
// 	m_pListBoxArray->AppendL(buf);
// 	
// 	CEikonEnv::Static()->ReadResource( buf, R_QTN_MH_SMS_SENDEDSMS );	
// 	m_pListBoxArray->AppendL(buf);	

	// update listbox
//	m_pListBox->HandleItemAdditionL();
}
TInt CSmsContainer::GetIndex()
{
	return iIndex;	
}
CDesCArrayFlat* CSmsContainer::GetListBoxArray()
{
	return m_pListBoxArray;
}

CAknSingleGraphicStyleListBox* CSmsContainer::GetListBox()
{
	return m_pListBox;
}

void CSmsContainer::SetupListIconsL(   )
{
	HBufC*  iconFileName;
	iconFileName = StringLoader::LoadLC( R_ICON_FILE_NAME );
	CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(4);   ////??????????? 不用释放吗?
	CleanupStack::PushL(icons);
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName,EMbmHelpergeniusWritesms,EMbmHelpergeniusWritesms_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName,EMbmHelpergeniusReceivesms,EMbmHelpergeniusReceivesms_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName,EMbmHelpergeniusDraftsms,EMbmHelpergeniusDraftsms_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName,EMbmHelpergeniusSendedsms,EMbmHelpergeniusSendedsms_mask));
	CleanupStack::Pop(icons);
	CleanupStack::PopAndDestroy(iconFileName);
	m_pListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
	//m_pListBox->ItemDrawer()->FormattedCellData()->SetIconArray(icons);	
}
// End of File  

⌨️ 快捷键说明

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