I am adding lines to the custom Listbox
1>adding line Control in void CCustomListBox::AppendLine() does not have anny effect, only constructl() does the drawing
ConstructL is called 1st time that control is drawn. Next time onwards CCustomListBox::AppendLine() is called.
CCustomListBox::AppendLine() tries add new lines to list box, after once the list box has been drawn with some lines.
Code:
CCustomColumnOfLineOfListBox::CCustomColumnOfLineOfListBox()
{
// No implementation required
}
CCustomColumnOfLineOfListBox::~CCustomColumnOfLineOfListBox()
{
}
CCustomColumnOfLineOfListBox* CCustomColumnOfLineOfListBox::NewLC(const TRect& aRect)
{
CCustomColumnOfLineOfListBox* self = new (ELeave) CCustomColumnOfLineOfListBox();
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
CCustomColumnOfLineOfListBox* CCustomColumnOfLineOfListBox::NewL(const TRect& aRect)
{
CCustomColumnOfLineOfListBox* self = CCustomColumnOfLineOfListBox::NewLC(aRect);
CleanupStack::Pop(); // self;
return self;
}
void CCustomColumnOfLineOfListBox::ConstructL(const TRect& aRect)
{
CreateWindowL();
// Set the windows size
SetRect(aRect);
// Activate the window, which makes it ready to be drawn
ActivateL();
}
/**
* From CoeControl,SizeChanged.
*/
void CCustomColumnOfLineOfListBox::SizeChanged()
{
}
/**
* From CoeControl,CountComponentControls.
*/
TInt CCustomColumnOfLineOfListBox::CountComponentControls() const
{
return 0;
}
/**
* From CCoeControl,ComponentControl.
*/
CCoeControl* CCustomColumnOfLineOfListBox::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
default:
return NULL;
}
}
/**
* From CCoeControl,Draw.
*/
void CCustomColumnOfLineOfListBox::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
CFont* fontUsed = const_cast<CFont*>(iEikonEnv ->LegendFont());//NormalFont());
gc.UseFont(fontUsed);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
gc.SetBrushColor(KRgbWhite);
gc.DrawText(_L("Sandeep"),aRect,fontUsed->AscentInPixels(),CGraphicsContext::ECenter);
}
/**
* From CCoeControl, HandleControlEventL.
*/
// event handling section
// e.g Listbox events
void CCustomColumnOfLineOfListBox::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
{
}
Code:
CCustomLineOfListbox::CCustomLineOfListbox()
{
// No implementation required
}
CCustomLineOfListbox::~CCustomLineOfListbox()
{
}
CCustomLineOfListbox* CCustomLineOfListbox::NewLC(const TRect& aRect)
{
CCustomLineOfListbox* self = new (ELeave)CCustomLineOfListbox();
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
CCustomLineOfListbox* CCustomLineOfListbox::NewL(const TRect& aRect)
{
CCustomLineOfListbox* self = CCustomLineOfListbox::NewLC(aRect);
CleanupStack::Pop(); // self;
return self;
}
void CCustomLineOfListbox::ConstructL(const TRect& aRect)
{
CreateWindowL();
TRect a(0,0,100,20);
TRect b(0,0,150,20);
TRect c(0,0,50,20);
iColumn1 = CCustomColumnOfLineOfListBox::NewL(a);
iColumn1->SetContainerWindowL( *this );
//iColumn1->SetTextL( _L("a") );
iColumn2 = CCustomColumnOfLineOfListBox::NewL(b);
iColumn2->SetContainerWindowL( *this );
//iColumn2->SetTextL( _L(" menu") );
iColumn3 = CCustomColumnOfLineOfListBox::NewL(c);
iColumn3->SetContainerWindowL( *this );
//iColumn3->SetTextL( _L("u") );
// Set the windows size
SetRect(a);
SetRect(b);
SetRect(c);
SetRect(aRect);
// Activate the window, which makes it ready to be drawn
ActivateL();
}
/**
* From CoeControl,SizeChanged.
*/
void CCustomLineOfListbox::SizeChanged()
{
iColumn1->SetExtent( this->iPosition, TSize(120,20) );
iColumn2->SetExtent( this->iPosition+TPoint(120,0), TSize(50,20) );
iColumn3->SetExtent( this->iPosition+TPoint(170,0), TSize(50,20) );
}
/**
* From CoeControl,CountComponentControls.
*/
TInt CCustomLineOfListbox::CountComponentControls() const
{
return 3;
}
/**
* From CCoeControl,ComponentControl.
*/
CCoeControl* CCustomLineOfListbox::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iColumn1;
case 1:
return iColumn2;
case 2:
return iColumn3;
default:
return NULL;
}
}
/**
* From CCoeControl,Draw.
*/
void CCustomLineOfListbox::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
CFont* fontUsed = const_cast<CFont*>(iEikonEnv ->LegendFont());//NormalFont());
gc.UseFont(fontUsed);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
gc.SetBrushColor(KRgbWhite);
//gc.DrawText(_L("Sandeep"),aRect,fontUsed->AscentInPixels(),CGraphicsContext::ECenter);
}
/**
* From CCoeControl, HandleControlEventL.
*/
// event handling section
// e.g Listbox events
void CCustomLineOfListbox::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
{
}
Code:
CCustomListBox::CCustomListBox(const TRect& aRect):iRect(aRect)
{
// No implementation required
}
CCustomListBox::~CCustomListBox()
{
}
//CCustomListBox* CCustomListBox::NewLC(const TRect& aRect)
// {
// CCustomListBox* self = new (ELeave) CCustomListBox();
// CleanupStack::PushL(self);
// self->ConstructL(aRect);
// return self;
// }
//
//CCustomListBox* CCustomListBox::NewL(const TRect& aRect)
// {
// CCustomListBox* self = CCustomListBox::NewLC(aRect);
// CleanupStack::Pop(); // self;
// return self;
// }
void CCustomListBox::ConstructL(const TRect& aRect)
{
CreateWindowL();
TInt width=aRect.Width()-26,height=20;
TRect a(0,0,width,height);
for(TInt i=0;i<2;i++)
{
CCustomLineOfListbox* TempLine=CCustomLineOfListbox::NewL(a);
TempLine->SetContainerWindowL( *this );
iLines.AppendL(TempLine);
SetRect(a);
}
SetRect(iRect);
ActivateL();
}
void CCustomListBox::AppendLine()
{
TRect a(0,0,iRect.Width(),20);
CCustomLineOfListbox* TempLine=CCustomLineOfListbox::NewL(a);
iLines.AppendL(TempLine);
TempLine->SetContainerWindowL(*this);
//for(TInt i=0;i<iLines.Count();i++) iLines[i]->SetContainerWindowL(*this);
this->RequestRelayout(TempLine);
}
/**
* From CoeControl,SizeChanged.
*/
void CCustomListBox::SizeChanged()
{
TInt x=17,y=40,width=iRect.Width()-50,height=20;
for(TInt i=0;i<iLines.Count();i++)
{
iLines[i]->SetExtent(TPoint(x,i*(height+1)+y), iLines[i]->MinimumSize());
}
}
/**
* From CoeControl,CountComponentControls.
*/
TInt CCustomListBox::CountComponentControls() const
{
return iLines.Count();
}
/**
* From CCoeControl,ComponentControl.
*/
CCoeControl* CCustomListBox::ComponentControl(TInt aIndex) const
{
if(aIndex>=0 && aIndex<iLines.Count())
return iLines[aIndex];
return NULL;
}
/**
* From CCoeControl,Draw.
*/
void CCustomListBox::Draw(const TRect& aRect) const
{
_LIT(KName,"Name Distance Rating");
CWindowGc& gc = SystemGc();
CFont* fontUsed = const_cast<CFont*>(iEikonEnv ->LegendFont());
gc.UseFont(fontUsed);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
TRect a(17,20,iRect.Width()-26,20);
gc.DrawRect(a);
gc.SetBrushColor(KRgbBlack);
gc.DrawText(KName,TPoint(20,38));
}
/**
* From CCoeControl, HandleControlEventL.
*/
// event handling section
// e.g Listbox events
void CCustomListBox::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
{
}