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

📄 pblistcontainer.cpp.bak

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

// INCLUDE FILES


#include <FunZone.rsg>
#include "FunZone.hrh"
#include "PBListContainer.h"
//#include <AknUtils.h>
#include <StringLoader.h>
#include "MEM_FREE.H"
#include "PBListView.h"
#include <aknlists.h> 
#include <AknQueryDialog.h>
class CAknTitlePane;
#include <akntitle.h>

//#include <barsread.h>

// ================= MEMBER FUNCTIONS =======================

// C++ default constructor can NOT contain any code, that
// might leave.
//
CPBListContainer::CPBListContainer(CAknTitlePane* atitlePane)
{
	i_pListBox      = NULL;
	i_pSearchBox    = NULL;
	i_pListBoxArray = NULL;
	i_pPBArray      = NULL;
	ititlePane      =atitlePane;
}

// EPOC default constructor can leave.
void CPBListContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
	SetRect(aRect);
	
    //SetExtentToWholeScreen();
	MakeListBoxL();
    ActivateL();
}

// Destructor
CPBListContainer::~CPBListContainer()
{
	MEM_FREE(i_pListBox)
		MEM_FREE(i_pSearchBox)
		MEM_FREE(i_pListBoxArray)
}

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

void CPBListContainer::FocusTo(TInt aCommand)
{
}

// ---------------------------------------------------------
// CPBListContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPBListContainer::SizeChanged()
{
	if (i_pListBox)
    {
        if (i_pSearchBox)
        {
			CAknSingleNumberStyleListBox* aknListBox = STATIC_CAST(CAknSingleNumberStyleListBox*,i_pListBox);
			AknFind::HandleFixedFindSizeChanged(this, aknListBox, i_pSearchBox);			
        }
        else
        {
            i_pListBox->SetRect(Rect()); // Sets rectangle of lstbox.
		}
    }
}

// ---------------------------------------------------------
// CPBListContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CPBListContainer::CountComponentControls() const
{
	if(i_pListBox && i_pSearchBox)
	{
		return 2;
	}
	else
	{
		return 0;
	} 
}

// ---------------------------------------------------------
// CPBListContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
CCoeControl* CPBListContainer::ComponentControl(TInt aIndex) const
{
	if(i_pSearchBox && aIndex)
	{
		return i_pSearchBox;
	}	
	else
	{
		return i_pListBox;
	}	
}


// ---------------------------------------------------------
// CPBListContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPBListContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbGray);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
	gc.SetBrushColor(KRgbWhite);
	gc.DrawEllipse(aRect);
	
// 	gc.SetPenStyle(CGraphicsContext::ESolidPen);
// 	gc.SetPenColor(TRgb(177,1,1));
// 	TPoint startPos(20, 30);
// 	TPoint endPos(120, 80);
// 	gc.DrawLine(startPos, endPos);
// 	gc.SetPenColor(KRgbBlack);
// 	gc.SetPenStyle(CGraphicsContext::ESolidPen);
// 	gc.DrawLine(TPoint(20,0), TPoint(20,184));
// 	gc.DrawLine(TPoint(20,184), TPoint(176,184));
}

// ---------------------------------------------------------
// CPBListContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CPBListContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType)
{
	TKeyResponse Ret = EKeyWasNotConsumed;	
	switch (aKeyEvent.iCode)
	{
	case EKeyDevice3:
		break;
	default:
		if(i_pPBArray->Count()!=0)
		{
			TInt Index=GetSelectedIndexL();
			ititlePane->SetTextL((*i_pPBArray)[Index]->GetHomeMobileNumber()->Des());
			ititlePane->DrawNow();
		}
			
		if(i_pListBox)
		{
			
			if ( i_pSearchBox )
			{
				TBool needRefresh( EFalse );
				if (AknFind::HandleFindOfferKeyEventL(aKeyEvent, aType,this,i_pListBox, i_pSearchBox,EFalse,needRefresh)==EKeyWasConsumed)
				{
					if ( needRefresh )
					{
						SizeChanged();
						DrawNow();
					}	
					return EKeyWasConsumed;
				}
			}
			Ret = i_pListBox->OfferKeyEventL(aKeyEvent, aType);
		}
		break;
	}
	return Ret;
}


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


/*****************************************************************/
TInt CPBListContainer::GetSelectedIndexL()	//获取列表的当前下标
{
	TInt Ret(-1);
	if(i_pListBox)
	{
		TInt CurrItemInd = i_pListBox->CurrentItemIndex();
		CAknFilteredTextListBoxModel* model =STATIC_CAST(CAknFilteredTextListBoxModel*,i_pListBox->Model());		
		if(model && CurrItemInd >= 0)
		{	
			Ret = model->Filter()->FilteredItemIndex(CurrItemInd);	//It is used to fetch the content of a list item after filter has been used
		}				//Tests if cache cleanup should be performed on a message entry.
	}
	return Ret;
}

void CPBListContainer::HandleResourceChange(TInt aType)
{
	TRect rect;
	
    if ( aType==KEikDynamicLayoutVariantSwitch )
    {   
		CWsScreenDevice* ws = CEikonEnv::Static()->ScreenDevice(); 
		rect = ws->SizeInPixels();
        SetRect(rect);
    }
	CCoeControl::HandleResourceChange(aType);
}
void CPBListContainer::UpdateScrollBar(CAknSingleNumberStyleListBox* aListBox)
{
    if (aListBox)
	{   
        TInt pos(aListBox->View()->CurrentItemIndex());
        if (aListBox->ScrollBarFrame())
		{
            aListBox->ScrollBarFrame()->MoveVertThumbTo(pos);
		}
	}
}

CAknSearchField* CPBListContainer::CreateFindBoxL(CAknSingleNumberStyleListBox* aListBox,CTextListBoxModel* aModel, CAknSearchField::TSearchFieldStyle aStyle)
{
    CAknSearchField* findbox = NULL;
	
    if (aListBox && aModel)
	{
        // Gets pointer of CAknFilteredTextListBoxModel.
        CAknFilteredTextListBoxModel* model =STATIC_CAST( CAknFilteredTextListBoxModel*, aModel);
        // Creates FindBox.
        findbox = CAknSearchField::NewL( *this, aStyle, NULL, 20);
        CleanupStack::PushL(findbox);
        // Creates CAknListBoxFilterItems class.
        model->CreateFilterL( aListBox, findbox );
        //Filter can get by model->Filter();
        CleanupStack::Pop(findbox); // findbox
	}
    return findbox;
}


void CPBListContainer::MakeListBoxL()
{
	TInt MySetIndex(0);
	
	if(i_pListBox)
	{
		MySetIndex = GetSelectedIndexL();
	}
	/*******************Rss**********************************/
// 	i_pListBox = new( ELeave ) CAknSingleNumberStyleListBox();
// 	CleanupStack::PushL(i_pListBox);
// 	i_pListBox->SetContainerWindowL(*this);
// 	TResourceReader reader;
// 	CEikonEnv::Static()->CreateResourceReaderLC(reader, R_LISTBOX);
//     i_pListBox->ConstructFromResourceL(reader);
// 	CleanupStack::PopAndDestroy();
	/***************Code*************************************/
    i_pListBox   = new( ELeave ) CAknSingleNumberStyleListBox;
	CleanupStack::PushL(i_pListBox);
	i_pListBox->ConstructL(this,EAknListBoxMarkableList);
	
	//无名片时显示(无名片)
	ShowNoCard();
	
	i_pListBoxArray = new (ELeave) CDesCArrayFlat (10);
	CleanupStack::PushL(i_pListBoxArray);
	// get Model
	CTextListBoxModel* model = i_pListBox->Model();
	// setItemTextArray
	model->SetItemTextArray( i_pListBoxArray );
	// setOwnershipType NotOwn
	model->SetOwnershipType(ELbmDoesNotOwnItemArray);
	
	
	i_pListBox->CreateScrollBarFrameL( ETrue );
    i_pListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
	i_pListBox->SetRect(Rect());
	
	i_pSearchBox = CreateFindBoxL(i_pListBox, i_pListBox->Model(),CAknSearchField::ESearch);
	SizeChanged();
	
	i_pListBox->ActivateL();
	
	TInt ItemsCount = i_pListBox->Model()->ItemTextArray()->MdcaCount();
	
	if(ItemsCount > MySetIndex && MySetIndex >= 0)
		i_pListBox->SetCurrentItemIndex(MySetIndex);
	else if(ItemsCount > 0)
		i_pListBox->SetCurrentItemIndex(0);
	
	CleanupStack::Pop(2);
	UpdateScrollBar(i_pListBox);
}


void CPBListContainer::SetItemToListBox (RPointerArray<CPBInfo>*& a_pPBArray)
{
	// 	i_pListBox->DrawNow();
	
	i_pListBoxArray->Reset();
	TInt i = 0;		
	for (i = 0; i < a_pPBArray->Count(); i++)
	{
		TBuf<KMaxPath> szTemp;
		szTemp.Copy(_L("\t"));
		HBufC * sNameBuf = NULL;
		
		sNameBuf = (*a_pPBArray)[i]->GetLastName();
		// 判断是否为空
		if (sNameBuf != NULL)
		{
			szTemp.Append(sNameBuf->Des());
		}
		sNameBuf=(*a_pPBArray)[i]->GetFirstName();
		if (sNameBuf != NULL)
		{
			szTemp.Append(sNameBuf->Des());
		}

// 		if (((*a_pPBArray)[i]->GetLastName()==NULL)&& ((*a_pPBArray)[i]->GetFirstName()==NULL))	
// 		{
// 			szTemp.Copy(_L("\t"));
// 			TBuf<32> szNoName;
// 			StringLoader::Load(szNoName, R_QTN_MH_PBLIST_NONAME);
// 			szTemp.Append(szNoName);
// 		}
		//		iEikonEnv->InfoMsg(szTemp);
		i_pListBoxArray->AppendL(szTemp);
	}
	i_pListBox->HandleItemAdditionL();
	
}


void CPBListContainer::GetDeleteResult (TInt & anResult)
{
	// querDialog
	CAknQueryDialog* pdialog = CAknQueryDialog::NewL(CAknQueryDialog::ENoTone);
	
	TBuf <32>szTemp;
	StringLoader::Load(szTemp, R_QTN_MH_PBLIST_DEL_SHOW);
	
	szTemp.Append(_L("\n"));
	
	TBuf <KMaxName> sInfo;
	sInfo.Copy(i_pListBox->Model()->ItemText(i_pListBox->CurrentItemIndex()));
	sInfo.TrimLeft();
	szTemp.Append(sInfo);
	szTemp.Append(_L("?"));
	pdialog->SetPromptL(szTemp);
	anResult = pdialog->ExecuteLD(R_QTN_PROMPT_DIALOG);
}


void CPBListContainer::ShowNoCard()
{
	//无名片时显示(无名片)
	TBuf<32> szNoCard;
	StringLoader::Load(szNoCard, R_QTN_MH_PBLIST_NOITEM);
	i_pListBox->View()->SetListEmptyTextL(szNoCard);
}

void CPBListContainer::HandleMarkCommandL(TInt aCommand)
{
    if (i_pListBox)
    {
        AknSelectionService::HandleMarkableListProcessCommandL (aCommand, i_pListBox);
    }
}

void CPBListContainer::SendArray(RPointerArray<CPBInfo>* a_pPBArray)
{
	i_pPBArray=a_pPBArray;
}
// End of File  

⌨️ 快捷键说明

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