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

📄 smsexamplemarkablelistcontainer.cpp

📁 Symbian源代码发送短消息值的参考 源代码发送短消息值的参考
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
* ============================================================================
*  Name     : CMarkableListContainer from SMSExampleMarkableListContainer.h
*  Part of  : SMSExample
*  Created  : 12.03.2005 by Forum Nokia
*  Version  : 1.0
*  Copyright: Nokia Corporation
* ============================================================================
*/

// INCLUDE FILES
#include "SMSExampleMarkableListContainer.h"
#include "SmsExamplePanics.pan"

#include <akniconarray.h> // CAknIcon
#include <aknlists.h> // CAknDoubleGraphicStyleListBox
#include <barsread.h> // TResource Reader
#include <e32def.h> // STATIC_CAST
#include <SMSExample.mbg> // icons
#include <smsexample.rsg> // R_SMSEXAMPLE_MARKABLE_LISTBOX
#include <stringloader.h> // StringLoader
#include <uikon.hrh> // TKeyCode #defines

#ifdef __UI_FRAMEWORKS_V2__
    #include <GULICON.H>
    #include <AknIconUtils.h>
    #include <FBS.H> //fbscli.lib
#endif

#define KListPosition TPoint(0,0)

const TInt KAknExListAddItemBufLength(512);
const TInt KNumberOfIcons(2);
const TInt KBeginIdx=0;
const TInt KEndIdx=2;

_LIT(KIconSelectedText,"1\t");
_LIT(KIconNotSelectedText,"0\t");

// ----------------------------------------------------------------------------
// CMarkableListContainer::ConstructL(const TRect& aRect)
//
// Symbian OS 2 phase constructor. Creates a Window for the controls, which it
// contains.
// ----------------------------------------------------------------------------
void CMarkableListContainer::ConstructL(const TRect& aRect)
	{
	CreateWindowL();

	// Create the list
	CreateListL();

	iAddress = 0;
	iMessage = 0;

	// Set the icons in the list's drawer
	SetupListIconsL();

	// Set up scroll bars
	SetupScrollBarsL();

	iSelectedIds = new (ELeave) RArray<TMsvId>;

	SetRect(aRect);
	ActivateL();
	}

// ----------------------------------------------------------------------------
// CMarkableListContainer::CreateListL()
//
// 2nd phase constructor constructs the iSmsListBox and sets its window.
// ----------------------------------------------------------------------------
void CMarkableListContainer::CreateListL()
	{
	// First phase construction
	iSmsListBox = new (ELeave) CAknDoubleGraphicStyleListBox();
	iSmsListBox->SetContainerWindowL(*this);
	iSmsListBox->SetListBoxObserver(this);

	// Second Phase Construction
	TResourceReader reader;
	CEikonEnv::Static()->CreateResourceReaderLC(reader,
	                                            R_SMSEXAMPLE_MARKABLE_LISTBOX);
	iSmsListBox->ConstructFromResourceL(reader);
	CleanupStack::PopAndDestroy(); // reader
	}

// ----------------------------------------------------------------------------
// CMarkableListContainer::SetupScrollBarsL()
//
// Create scrollbars. Scrollbars appear automatically.
// ----------------------------------------------------------------------------
void CMarkableListContainer::SetupScrollBarsL()
	{
	iSmsListBox->CreateScrollBarFrameL(ETrue);
	iSmsListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
		CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	}

// ----------------------------------------------------------------------------
// CMarkableListContainer::SetArraysL(CDesCArrayFlat* aAddress,
//								  	  CDesCArrayFlat* aMessage )
//
// Insert both lists into listbox.
// ----------------------------------------------------------------------------
void CMarkableListContainer::SetArraysL(CDesCArrayFlat* aAddress,
                                        CDesCArrayFlat* aMessage )
	{
	iAddress = aAddress;
	iMessage = aMessage;

	for (TInt i = 0; i < aAddress->Count(); i++)
		{
		AddItemL( (*aAddress)[i], (*aMessage)[i] );
		}
	}

// ----------------------------------------------------------------------------
// CMarkableListContainer::MarkAllL(TBool aSelectionMode)
//
// Select or deselect all messages that ListBox displayes.
// ----------------------------------------------------------------------------
void CMarkableListContainer::MarkAllL(TBool aSelectionMode)
	{
	if  (iSmsListBox)
		{
		// Not taking ownership
		CTextListBoxModel* model = iSmsListBox->Model();
		model->SetOwnershipType (ELbmOwnsItemArray);
		CDesCArray* smsArray = STATIC_CAST(CDesCArray*,model->ItemTextArray());

		// Change all icon values.
		for (TInt i = 0; i < smsArray->Count(); i++)
			{
			TBuf <KAknExListAddItemBufLength> changeItem( (*smsArray)[i] );


			if ( aSelectionMode ) // Select one item
				{
				// Change the icon to selected
				changeItem.Replace(KBeginIdx, KEndIdx, KIconSelectedText);
				}
			else  // Deselect one item
				{
				// Change the icon to not selected
				changeItem.Replace(KBeginIdx, KEndIdx, KIconNotSelectedText);
				}

				// Delete one item
				smsArray->Delete(i);
				// Insert changed item back.
				smsArray->InsertL(i, changeItem);
			}

			// Change selected ids array to match the case.
			if ( aSelectionMode )
				{
				// Select all.
				SelectItem( 0, ETrue );
				}
			else
				{
				// Deselect all.
				DeSelectItem( 0, ETrue );
				}

			iSmsListBox->HandleItemAdditionL();
		}
	}

// ----------------------------------------------------------------------------
// CMarkableListContainer::MarkOrUnMarkL()
//
// Change icon and modify iIdArray to correspond situation.
// The icon is used to display if the item has been selected or not.
// ----------------------------------------------------------------------------
void CMarkableListContainer::MarkOrUnMarkL()
	{
	if  (iSmsListBox)
		{
		// Cursor's current position
		TInt itemIndex = iSmsListBox->CurrentItemIndex();

		if (itemIndex >= 0)
			{
			// not taking ownership
			CTextListBoxModel* model = iSmsListBox->Model();
			model->SetOwnershipType (ELbmOwnsItemArray);
			CDesCArray* smsArray = STATIC_CAST(CDesCArray*,
			                                   model->ItemTextArray());

			if( smsArray->Count() <= itemIndex )
	    		{
    		    User::Leave(KErrTooBig);
	    		}

			TBuf <KAknExListAddItemBufLength> changeItem(
			                                            (*smsArray)[itemIndex]
			                                            );

			// Compare index to see which is the case. Deselected -> Selected
			if ( changeItem.Left(KEndIdx) == KIconNotSelectedText )
				{
				changeItem.Replace(KBeginIdx, KEndIdx, KIconSelectedText);
				// Modify iIdArray
				SelectItem( itemIndex, EFalse );
				} // Selected -> Deselected
			else if ( changeItem.Left(KEndIdx) == KIconSelectedText )
				{
				changeItem.Replace(KBeginIdx, KEndIdx, KIconNotSelectedText);
				// Modify iIdArray
				DeSelectItem( itemIndex, EFalse );
				}

			smsArray->Delete(itemIndex);
			smsArray->InsertL(itemIndex, changeItem);

			iSmsListBox->HandleItemAdditionL();
			}
		}
	}

// ----------------------------------------------------------------------------
// CMarkableListContainer::SelectItem(TInt aIndex, TBool aSelectAll)
//
// Select item.
// ----------------------------------------------------------------------------
void CMarkableListContainer::SelectItem(TInt aIndex, TBool aSelectAll)
	{
	// Copy
	if ( aSelectAll )
		{
		iSelectedIds->Reset();
		for (TInt i = 0; i < iIdArray->Count(); i++)
			{
			iSelectedIds->Append( (*iIdArray)[i] );
			}
		}
	else if( iIdArray->Count() > aIndex )
		{
		TMsvId id = (*iIdArray)[aIndex];
		// Try to find the id, if not present then append id onto list.
		if ( KErrNotFound == iSelectedIds->Find( id ) )
			{
			iSelectedIds->Append( id );
			}
		}
	else
	    {
	    Panic(EGuiGeneral);
	    }

	}

// ----------------------------------------------------------------------------
// CMarkableListContainer::DeSelectItem(TInt aIndex, TBool aDeselectAll)
//
// Deselect item.
// ----------------------------------------------------------------------------
void CMarkableListContainer::DeSelectItem(TInt aIndex, TBool aDeselectAll)
	{
	if ( aDeselectAll )
		{
		iSelectedIds->Reset();

⌨️ 快捷键说明

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