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

📄 shenxianfourcontainer.cpp

📁 symbian学习例子
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CShenxianFourContainer from CCoeControl, MCoeControlObserver
*  Part of  : ShenxianFour
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES
#include <Shenxian.rsg>
#include "Shenxian.hrh"
#include "ShenxianFourContainer.h"
#include "ShenxianTowContainer.h"
#include "ShenxianAppUi.h"
#include <akngrid.h>
#include <aknlists.h>
#include <e32base.h>   //for CArrayPtr
#include <AknIconArray.h>//for CAknIconArray
#include <AknLists.h>//for AknListBoxLayouts


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

// C++ default constructor can NOT contain any code, that
// might leave.
//
CShenxianFourContainer::CShenxianFourContainer()
{
	m_pGrid = NULL;
}

// EPOC default constructor can leave.
void CShenxianFourContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
    m_pGrid = new(ELeave) CAknGrid;
    m_pGrid->SetContainerWindowL(*this);
    m_pGrid->ConstructL(this,EAknListBoxSelectionGrid);
    m_pGrid->SetEmptyGridTextL(_L(""));
    //布局设置
    m_pGrid->SetRect(aRect.Size( ));
    m_pGridType = EAknExGridSelectionGrid;
    //设置垂直排列或水平排列
    iVerticalOrientation = EFalse;
    iTopToBottom = ETrue;
    iLeftToRight = ETrue;
    //设置最大显示行数与列数
    iNumOfColumns = 3;
    iNumOfRows = 3;
    iNumOfItems = 9;
    //数据排列
    iContentType = EContainGraphic;
    iVerticalScrollingType = CAknGridView::EScrollIncrementLineAndLoops;
    iHorizontalScrollingType = CAknGridView::EScrollIncrementLineAndLoops;
    iSizeOfItems.iWidth = ( aRect.iBr.iX - aRect.iTl.iX)/iNumOfColumns;
    iSizeOfItems.iHeight = (aRect.iBr.iY - aRect.iTl.iY)/iNumOfRows;
    //
    m_pGrid->SetLayoutL( iVerticalOrientation,iLeftToRight,iTopToBottom,iNumOfColumns, iNumOfRows,iSizeOfItems);
    //设置水平移动方向
    m_pGrid->SetPrimaryScrollingType( iHorizontalScrollingType );
    //垂直
    m_pGrid->SetSecondaryScrollingType( iVerticalScrollingType );
    //load data
    LoadGraphicsL( );
    AddDataL( );
    iInstantsCreated = ETrue;
    //九宫格变化效果
    m_pGrid->SetCurrentDataIndex(0 );
    m_pGrid->MakeVisible(ETrue);
    m_pGrid->SetFocus(ETrue);
    m_pGrid->ActivateL( );
    m_pGrid->DrawNow( );

    SetRect(aRect);
    ActivateL();
}

// Destructor
CShenxianFourContainer::~CShenxianFourContainer()
{
	DELPTR(m_pGrid);
}

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

void CShenxianFourContainer::FocusTo(TInt aCommand)
{
}

// ---------------------------------------------------------
// CShenxianFourContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CShenxianFourContainer::SizeChanged()
{
}

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

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

// ---------------------------------------------------------
// CShenxianFourContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CShenxianFourContainer::Draw(const TRect& aRect) const
{
	
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbGray);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
	//	const CFont *nor = CEikonEnv::Static()->TitleFont();
	//	gc.UseFont(nor);
	
	//	gc.DrawText(*(message->GetName()),TPoint(20,60));
	//	gc.DrawText(*(message->GetTel()),TPoint(20,80));
	//	gc.DrawText(*(message->GetEmail()),TPoint(20,100));
	//   gc.DrawText(*(message->GetAddress()),TPoint(20,120));
	//	gc.DiscardFont();
	
	
}

// ---------------------------------------------------------
// CShenxianFourContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CShenxianFourContainer::OfferKeyEventL(
													 const TKeyEvent& aKeyEvent, TEventCode aType)
{
    if(NULL != m_pGrid)
		{
			return m_pGrid->OfferKeyEventL(aKeyEvent, aType);
		}
		else
		{
			return EKeyWasNotConsumed;
		}
}


// ---------------------------------------------------------
// CShenxianFourContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CShenxianFourContainer::HandleControlEventL(
												  CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
//////********往列表添加内蓉的方法,自己写的***************************/
//void CShenxianFourContainer::AddInfoToList(TInt aIndex,const TDesC& aText)
//{
//	TBuf<64> sBuf;
//	sBuf.AppendNum(aIndex);
//	sBuf.Append(_L("\t"));
//	sBuf.Append(aText);
//	m_pListArray->AppendL(sBuf);
//	m_pListBox->HandleItemAdditionL( );//update listbox.
//}

//void CShenxianFourContainer::DeleteInfoFromListL( TInt aIndex )
//{
//	if(m_pListArray->MdcaCount())
//	{
//		m_pListArray->Delete(aIndex);
//	}
//	return ;
//}

void CShenxianFourContainer::LoadGraphicsL( )
{
   CShenxianAppUi* pApp = (CShenxianAppUi*)CEikonEnv::Static( )->AppUi();
   CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(iNumOfItems);
   CleanupStack::PushL(icons);
   if( m_pGridType == EAknExGridSelectionGrid )
    {
       icons->AppendL(pApp->LoadGraphicsL(1));
       icons->AppendL(pApp->LoadGraphicsL(1));
       icons->AppendL(pApp->LoadGraphicsL(1));
       icons->AppendL(pApp->LoadGraphicsL(0));
       icons->AppendL(pApp->LoadGraphicsL(0));
       icons->AppendL(pApp->LoadGraphicsL(0));
       icons->AppendL(pApp->LoadGraphicsL(1));
       icons->AppendL(pApp->LoadGraphicsL(1));
       icons->AppendL(pApp->LoadGraphicsL(1));
    }
    m_pGrid->ItemDrawer( )->FormattedCellData( )->SetIconArrayL(icons);
    CleanupStack::Pop( );
}

void CShenxianFourContainer::AddDataL( )
{
  MDesCArray* array = m_pGrid->Model( )->ItemTextArray( );
  CDesCArray* cArray = ( CDesCArray* )array;
  TBuf<32> sBuf;
//SMS
  sBuf.Copy(_L("0\t"));
  sBuf.Append(_L("abc"));
  cArray->AppendL(sBuf);  

  sBuf.Copy(_L("1\t"));
  sBuf.Append(_L("abc"));
  cArray->AppendL(sBuf); 

  sBuf.Copy(_L("2\t"));
  sBuf.Append(_L("abc"));
  cArray->AppendL(sBuf); 

  sBuf.Copy(_L("3\t"));
  sBuf.Append(_L("abc"));
  cArray->AppendL(sBuf); 
 
  sBuf.Copy(_L("4\t"));
  sBuf.Append(_L("abc"));
  cArray->AppendL(sBuf); 

  sBuf.Copy(_L("5\t"));
  sBuf.Append(_L("abc"));
  cArray->AppendL(sBuf); 
  
  sBuf.Copy(_L("6\t"));
  sBuf.Append(_L("abc"));
  cArray->AppendL(sBuf); 

  sBuf.Copy(_L("7\t"));
  sBuf.Append(_L("abc"));
  cArray->AppendL(sBuf); 

  sBuf.Copy(_L("8\t"));
  sBuf.Append(_L("abc"));
  cArray->AppendL(sBuf);

  m_pGrid->HandleItemAdditionL( );
 ApplySelGridGraphicStyleL( );
} 

void CShenxianFourContainer::ApplySelGridGraphicStyleL( )
{
  if(!m_pGrid)
  {
    return;
  }
  AknListBoxLayouts::SetupStandardGrid(*m_pGrid);
  const CFont* foutText = ApacPlain12( );
  TInt nX = (m_pGrid->ColumnWidth( ) - 24)/2;
  TInt nY = (m_pGrid->ItemHeight( ) - 24 -foutText->HeightInPixels( ) )/2;
  AknListBoxLayouts::SetupFormGfxCell( *m_pGrid,
                                       m_pGrid->ItemDrawer( ),
                                       0,
                                       nX,
                                       nY,
                                       0,
                                       0,
                                       24,
                                       24,
                                       TPoint( nX, nY),
                                       TPoint( 24+nX,24+nY));
  AknListBoxLayouts::SetupFormAntiFlickerTextCell( *m_pGrid,
                                                 m_pGrid->ItemDrawer( ),
                                                 1,
                                                 foutText,
                                                 215,
                                                 0,
                                                 0,
                                                 24+nY+foutText->HeightInPixels( ),
                                                 m_pGrid->ColumnWidth( ),
                                                 CGraphicsContext::ECenter,
                                                 TPoint( 0, 24+nY),
                                                 TPoint( m_pGrid->ColumnWidth( ),m_pGrid->ItemHeight( )));
  DrawNow( );
}

// End of File  

⌨️ 快捷键说明

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