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

📄 notecontainer.cpp

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

// INCLUDE FILES
#include <HelperGenius.rsg>
#include "HelperGenius.hrh"
#include "NoteContainer.h"
#include <aknlists.h>
#include "HelperGeniusAppUi.h"
#include "NoteInfo.h"
#include <Helpergenius.mbg>
#include <fbs.h>
#include <AknUtils.h>

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

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

// EPOC default constructor can leave.
void CNoteContainer::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) CAknSingleNumberStyleListBox;
    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);
//	CleanupStack::Pop(m_pListBox);
	m_pListBoxArray = new (ELeave) CDesCArrayFlat(10);
	CleanupStack::PushL(m_pListBoxArray);
	AddInfoToList();
	CTextListBoxModel* model = m_pListBox->Model();
	// set items and ownership
	model->SetItemTextArray( m_pListBoxArray );
	model->SetOwnershipType(ELbmDoesNotOwnItemArray);
	CleanupStack::Pop(2);	
	
	m_pListBox->ActivateL();
	// 	m_pListBox->MakeVisible(ETrue);
	m_pListBox->SetFocus( ETrue );
	iIndex = 0;
    SetRect(aRect);
    ActivateL();
    }

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

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

void CNoteContainer::FocusTo(TInt aCommand)
    {
    }

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

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

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

// ---------------------------------------------------------
// CNoteContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CNoteContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
	/******添加背景图片*******************************************/
    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)));
    }

// ---------------------------------------------------------
// CNoteContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CNoteContainer::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;
}


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

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

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

⌨️ 快捷键说明

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