// ---------------------------------------------------------
// CSymTorrentSearchContainer::ConstructL
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CSymTorrentSearchContainer::ConstructL(const TRect& aRect, 
	CSymTorrentAppUi* aAppUi, CSTTorrentManager* aTorrentMgr)
{
	iAppUi=aAppUi;
	iTorrentMgr=aTorrentMgr;
    CreateWindowL();

    iListBox = new (ELeave) CAknDoubleGraphicStyleListBox();
    iListBox->SetMopParent(this);
	iListBox->ConstructL(this, EAknListBoxSelectionList);
	iListBox->SetContainerWindowL(*this);
	
	iListBox->View()->SetListEmptyTextL(_L("(empty)"));

	//create scrollbar
	iListBox->CreateScrollBarFrameL();
	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
		CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	
	CArrayPtr<CGulIcon>* icons = new (ELeave) CAknIconArray(1);  // must be initialized with the number of icons used by the list!
	CleanupStack::PushL(icons);

	#ifdef EKA2
	{
		CGulIcon* chainLinkIcon = CGulIcon::NewL();
		CleanupStack::PushL(chainLinkIcon);
		
		CFbsBitmap* chainLinkBmp = NULL;
		CFbsBitmap* chainLinkMask = NULL;
		AknIconUtils::CreateIconLC(chainLinkBmp, chainLinkMask, KBitmapFile,
			EMbmSymtorrentChainlink, EMbmSymtorrentChainlink_mask);	
		chainLinkIcon->SetBitmap(chainLinkBmp);
		chainLinkIcon->SetMask(chainLinkMask);
		CleanupStack::Pop(2);
		icons->InsertL(0, chainLinkIcon);
		CleanupStack::Pop();				
	}
	#else
	{
		CEikonEnv* eikEnv = CEikonEnv::Static();
		
		icons->AppendL(eikEnv->CreateIconL(KBitmapFile, 
			EMbmSymtorrentChainlink, EMbmSymtorrentChainlink_mask));	
	}
	#endif
			
	CleanupStack::Pop(icons); // icons
	iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);

    SetRect(aRect);
    
    CDesCArray* itemArray = static_cast<CDesCArray*>
		(iListBox->Model()->ItemTextArray());
	itemArray->InsertL(0, _L("0\tFirst line\tSecond line"));			
    
   
    ActivateL();
}
void CMainMenuGridContainer::AddItemL(TInt aBitmapId, TInt aMaskId, 
                                      TInt aIndex) 
{
   CArrayPtr<CGulIcon>* icons = 
      iGrid->ItemDrawer()->FormattedCellData()->IconArray();
   if (!icons) {
      icons = new ( ELeave ) CAknIconArray(9);
      iGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons);
   }
   CleanupStack::PushL(icons);

   CFbsBitmap* bitmap;
   CFbsBitmap* mask;

#ifdef NAV2_CLIENT_SERIES60_V3
   AknIconUtils::CreateIconL(bitmap, mask, iView->GetMbmName(), 
                             aBitmapId, aMaskId);
   AknIconUtils::SetSize(bitmap, iIconRect.Size(),
                         EAspectRatioPreservedAndUnusedSpaceRemoved);
#else
   bitmap = iEikonEnv->CreateBitmapL(iView->GetMbmName(), aBitmapId);
   mask = iEikonEnv->CreateBitmapL(iView->GetMbmName(), aMaskId);
#endif

   CleanupStack::PushL(bitmap);
   CleanupStack::PushL(mask);

   if (aIndex >= 0 && aIndex < icons->Count()) {
      icons->InsertL(aIndex, CGulIcon::NewL(bitmap, mask));
   } else {
      icons->AppendL(CGulIcon::NewL(bitmap, mask));
   }
   CleanupStack::Pop(mask);
   CleanupStack::Pop(bitmap);
   CleanupStack::Pop(icons);

   _LIT(KItem, "%d\t\t0");
   TBuf<8> buf;
   MDesCArray* array = iGrid->Model()->ItemTextArray();
   CDesCArray* cArray = (CDesCArray*)array;
   if (aIndex >= 0 && aIndex < icons->Count()) {
      buf.Format(KItem, aIndex);
      cArray->InsertL(aIndex, buf);
      aIndex++;
      //We need to delete and re-index the array since we inserted
      //a new icon in the icon array.
      cArray->Delete(aIndex, icons->Count() - aIndex);
      for (TInt i = aIndex; i < icons->Count(); i++) {
         buf.Format(KItem, i);
         cArray->AppendL(buf);
      }
   } else {
      buf.Format(KItem, (icons->Count() - 1));
      cArray->AppendL(buf);
   }
   //Inform list box that data was added.
   iGrid->HandleItemAdditionL();
}