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

📄 meglistcontainer.cpp

📁 symbian系统上的记事本程序
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CMegListContainer from CCoeControl, MCoeControlObserver
*  Part of  : Hello
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES


#include <EveryDay.rsg>
#include "EveryDay.hrh"
#include "MegListContainer.h"
#include <aknlists.h>
#include "common.h"
#include <AknQueryDialog.h>		//for CAknQueryDialog
#include <StringLoader.h>	//for StringLoader
// ================= MEMBER FUNCTIONS =======================

// C++ default constructor can NOT contain any code, that
// might leave.
//

CMegListContainer::CMegListContainer()
{
}

// EPOC default constructor can leave.
void CMegListContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
	m_pMegLlist = new( ELeave ) CAknDoubleNumberStyleListBox();
	CleanupStack::PushL(m_pMegLlist);
	m_pMegLlist->ConstructL(this, EAknListBoxMarkableList | EAknListBoxMultiselectionList);	
	m_pMegLlist->SetContainerWindowL(*this);
	m_pMegLlist->SetRect(aRect);
    m_pMegLlist->CreateScrollBarFrameL( ETrue );
    m_pMegLlist->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	
	m_ListBoxArray = new( ELeave ) CDesCArrayFlat(10);
	CleanupStack::PushL(m_ListBoxArray);
	
	CTextListBoxModel* model = m_pMegLlist->Model();
	model->SetItemTextArray(m_ListBoxArray);
	model->SetOwnershipType(ELbmDoesNotOwnItemArray);
	m_pMegLlist->ActivateL();
	
	CleanupStack::Pop(2);	
	m_pMegLlist->SetFocus( ETrue );
	
    SetRect(aRect);
    ActivateL();
}

// Destructor
CMegListContainer::~CMegListContainer()
{
	MEM_FREE(m_pMegLlist);
	MEM_FREE(m_ListBoxArray);
}

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

void CMegListContainer::FocusTo(TInt aCommand)
{
}

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

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

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

// ---------------------------------------------------------
// CMegListContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CMegListContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbYellow);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
}

// ---------------------------------------------------------
// CMegListContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CMegListContainer::OfferKeyEventL(
											   const TKeyEvent& aKeyEvent, TEventCode aType)
{
	if(m_pMegLlist != NULL)
	{
		if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
		{
			return m_pMegLlist->OfferKeyEventL(aKeyEvent, aType);
		}
		else if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
		{
			return m_pMegLlist->OfferKeyEventL(aKeyEvent, aType);
		}
		return EKeyWasConsumed;
	}
}


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


TInt CMegListContainer::GetListCount()
{
	TInt nIndex = 0;
	nIndex = m_pMegLlist->CurrentItemIndex();
	
	if(nIndex >= 0)
	{
		return nIndex;
	}
	else if(m_pMegLlist->Model()->NumberOfItems()==0)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

void CMegListContainer::AddInfoToList(const TDesC& aTit, const TDesC& aCon)
{
	TBuf<64> sBuf;
	sBuf.Append(_L(">>"));
	sBuf.Append(_L("\t"));
	if (aTit.Length() != 0)
	{	
		sBuf.Append(aTit);
	}
	else
	{
		
		sBuf.Append(_L("Error!"));
	}
	
	sBuf.Append(_L("\t"));
	if (aCon.Length() <= 20)
	{
		sBuf.Append(aCon);
	}
	else
	{
		sBuf.Append(aCon.Left(20));
		sBuf.Append(_L(" ..."));
	}
	
	m_ListBoxArray->AppendL(sBuf);
	m_pMegLlist->HandleItemAdditionL();
}
// End of File  
void CMegListContainer::DelInforFromList( TInt aIndex)
{
	m_ListBoxArray->Delete(aIndex);	
	m_pMegLlist->HandleItemRemovalL();	
	m_pMegLlist->HandleItemAdditionL();	
}
void CMegListContainer::GetListDelete(TInt& result)
{
	CAknQueryDialog* pdialog = CAknQueryDialog::NewL(CAknQueryDialog::ENoTone);
	TBuf <32>szTemp;
	StringLoader::Load(szTemp, R_QTN_IM_PBDELETE_MESSAGE);
	
	szTemp.Append(_L("\n"));
	
	TBuf <KMaxName> sInfo;
	sInfo.Copy(m_pMegLlist->Model()->ItemText(m_pMegLlist->CurrentItemIndex()));
	sInfo.TrimLeft();
	szTemp.Append(sInfo);
	szTemp.Append(_L("?"));
	pdialog->SetPromptL(szTemp);
	result = pdialog->ExecuteLD( R_QTN_PROMPT_DIALOG);
}

⌨️ 快捷键说明

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