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

📄 esimgroupcontainer.cpp

📁 基于SIP协议的即时消息聊天功能设计,Symbian平台下实现
💻 CPP
字号:
/*
============================================================================
 Name        : ESIMGroupContainer.cpp
 Author      : hagu
 Version     :
 Copyright   : Your copyright notice
 Description : ESIMGroupContainer.cpp - source file
============================================================================
*/

// INCLUDE FILES
// Class include
#include "ESIMGroupContainer.h"
#include <eiklabel.h>  // for example label control
//#include <eikclbd.h> // CColumnListBoxData
#include <aknlists.h> // CAknSingleStyleListBox
#include <barsread.h> // TResource Reader
#include <stringloader.h> // StringLoader
#include <akniconarray.h> // CAknIcon
#include <eikclbd.h> // CColumnListBoxData

#include "ESIMGroupView.h"
#include "ESIMGroupItem.h"
#include "ESIMItemEngine.h"
#include <ESIM.rsg>
//#include <ESIM.mbg>

const TInt KNumberOfIcons(1);
const TInt KNumberOfNames(20);
const TInt KAknExListFindBoxTextLength( 20 ); // for findbox.

//************************
#include "ESIM.hrh" // constants
#include <akniconarray.h> // CAknIcon
#include <e32def.h> // STATIC_CAST
#include <eikmenub.h> // CEikMenuBar
#include <uikon.hrh> // TKeyCode #defines
#include <aknquerydialog.h> // CAknQueryDialog
#include <e32base.h>


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

// ---------------------------------------------------------
// CESIMGroupContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CESIMGroupContainer::ConstructL(const TRect& aRect, CESIMGroupView* aView)
    {
    CreateWindowL();

	iView = aView;

	CreateListL();//create group list
	iGroupListBox->SetListBoxObserver(this);
	SetupScrollBarsL();
	SetupListItemsL();//input some test items////
    SetRect(aRect);
    ActivateL();
    }

// Destructor
CESIMGroupContainer::~CESIMGroupContainer()
    {
    delete iGroupListBox;
    }

// ---------------------------------------------------------
// CESIMGroupContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CESIMGroupContainer::SizeChanged()
    {
    // TODO: Add here control resize code etc.
	if (iGroupListBox)
		iGroupListBox->SetRect(Rect());
    }

// ---------------------------------------------------------
// CESIMGroupContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CESIMGroupContainer::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }

// ---------------------------------------------------------
// CESIMGroupContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CESIMGroupContainer::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
            return iGroupListBox;
        default:
            return NULL;
        }
    }

// ---------------------------------------------------------
// CESIMGroupContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CESIMGroupContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    // TODO: Add your drawing code here
    // example code...
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }


// ********************************************************

/**
* Constructs the iGroupListBox, setting its window.
*
*/
void CESIMGroupContainer::CreateListL()
	{
	// First phase construction
	iGroupListBox = new (ELeave) CAknSingleStyleListBox;
	//iGroupListBox = new (ELeave) CAknDoubleStyleListBox;
	iGroupListBox->SetContainerWindowL(*this);
	
	// Second Phase Construction
	TResourceReader reader;
	CEikonEnv::Static()->CreateResourceReaderLC(reader, R_ESIM_GROUP_LISTBOX);
	iGroupListBox->ConstructFromResourceL(reader);
	CleanupStack::PopAndDestroy(); // reader
	}

void CESIMGroupContainer::SetupScrollBarsL()
	{
	iGroupListBox->CreateScrollBarFrameL();
	iGroupListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
		CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	}
/**
* Populates the list model's item array with a list of saved games
*/
void CESIMGroupContainer::SetupListItemsL()
	{
	//CDesCArray *groups = iEngine->GetContactGroupsL();
	CTextListBoxModel* model = iGroupListBox->Model();  // not taking ownership
	model->SetOwnershipType (ELbmOwnsItemArray);
	CDesCArray* savedGamesArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
	// Strings will be of the format "2\tSaved Game i", where i is a number from 1 to 10

	_LIT (KStringHeader, "\t%S");
	TBuf <16> aString;
	for (TInt i = 0; i< iEngine->GroupItemCount(); i++)
	{
		TPtrC ptr = ((iEngine->GroupItem(i))->Name())->Des();
		aString.Format(KStringHeader(), &ptr);
		savedGamesArray->AppendL (aString);
	}
	}

TInt CESIMGroupContainer::ListCount()
{
	CTextListBoxModel* model = iGroupListBox->Model();  // not taking ownership
	model->SetOwnershipType (ELbmOwnsItemArray);
	CDesCArray* savedGamesArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
	return savedGamesArray->Count();
}

//************************
/**
* Called by the framework whenever a key event occurs.	
* Passes the key event to the saved games list if it is not null, otherwise returns
* EKeyWasNotConsumed
* @param aKeyEvent the Key event which occured, e.g. select key pressed
* @param aType the type of Key event which occurred, e.g. key up, key down
* @return TKeyResponse EKeyWasNotConsumed if the key was not processed, EKeyWasConsumed if it was
*/
TKeyResponse CESIMGroupContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	if (iGroupListBox&&aKeyEvent.iCode != EKeyLeftArrow && aKeyEvent.iCode != EKeyRightArrow)
		return iGroupListBox->OfferKeyEventL (aKeyEvent, aType);
	else
		return EKeyWasNotConsumed;
// 		if (aKeyEvent.iScanCode == 16 || aKeyEvent.iScanCode == 17)
// 		{
// 			return iGroupListBox->OfferKeyEventL (aKeyEvent, aType);
// 		}
// 
// 		if (aKeyEvent.iScanCode == 167)
// 		{
// 			iEngine->EditGroupFormL(iGroupListBox->CurrentItemIndex());
// 			RefreshListL();
// 		}
// 		return EKeyWasNotConsumed;
	}


void CESIMGroupContainer::RefreshListL()
	{
	//清空列表
	CTextListBoxModel* model = iGroupListBox->Model();  // not taking ownership
	CDesCArray* items = STATIC_CAST(CDesCArray*, model->ItemTextArray());
	items->Delete(0, items->Count());

	//再将新的列表全部加入
	SetupListItemsL();

    iGroupListBox->HandleItemAdditionL();
	iGroupListBox->SetCurrentItemIndexAndDraw( 0 );
    SizeChanged();
    DrawNow();
	}

TInt CESIMGroupContainer::GetCurrentItemIndex()
{
	return iGroupListBox->CurrentItemIndex();
}

// ********************************************************


CEikColumnListBox* CESIMGroupContainer::ListBox() const
	{
	return iGroupListBox;
	}
/**
* Called by the framework whenever a list event occurs for which this container
* is an observer.
* @param aListBoxEvent The type of event which occured
*
*/
void CESIMGroupContainer::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aListBoxEvent)
	{
		TInt currentItemIndex(aListBox->CurrentItemIndex());
		iEngine->SetCurrentGroupIndex(currentItemIndex);

		SetCurrentGroupName( );
	// if the Select Key has been pressed CEikColumnListBox 
	if (aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) 
		{
// 		iView->HandleCommandL(EESIMCmdActiveGroupUserView);

			iView->HandleCommandL(EESIMGroupCmdSendMessage);

// 		iEngine->EditGroupFormL(iGroupListBox->CurrentItemIndex());
// 		RefreshListL();
		}
	}
void CESIMGroupContainer::SetCurrentGroupName( )
{
	iEngine->SetCurrentGroupName(iGroupListBox->CurrentItemIndex());
}
// End of File

⌨️ 快捷键说明

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