Need help on Custom Listbox using custom Itemdrawer
| Sun, 2008-01-20 06:15 | |
|
I have downloaded the multilist example of dreambox and am trying to add a custom Item drawer to it to extend its functionality with a custom itemdrawer class .
void CDreamColumnListBoxSub::ConstructL(CDreamColumnListBox* aParent,TInt aFlags,const CFont* aFont) {
////////////////////////////////////////////////////////////For some instance this line refuses to compile////////////////////////////
CEikColumnListBox::ConstructL(aParent,aFlags,aFont);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
iParent=aParent;
CreateItemDrawerL();
}
void CDreamColumnListBoxSub::HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType) {
CEikColumnListBox::HandleScrollEventL(aScrollBar,aEventType);
// now report this scroll event "up" to the parent list box so that
// the header can be "scrolled as well
iParent->HandleScrollEventL(aScrollBar,aEventType);
}
void CDreamColumnListBoxSub::CreateItemDrawerL()
{
//////////////////[="Red"][="3"]Kern Exec 3 Panic Error after this line[/][/]//////////////////
iItemDrawer = new (ELeave) CMultiColumnItemDrawer(Model(),iListFont,CColumnListBoxData::NewL(),this);
////////////////////////////////////////////////////////
}
#ifndef MULTICOLUMNITEMDRAWER_H_
#define MULTICOLUMNITEMDRAWER_H_
#include <eikclb.h>
#include <eikclbd.h>
#include <eiklbm.h>
#include <gdi.h>
#include <e32def.h>
#include <e32std.h>
#include "CDreamColumnListBoxSub.h"
//FORWARD DECLARATION
class CDreamColumnListBoxSub;
class CFont;
//CLASS DECLARATION
class CMultiColumnItemDrawer : public CColumnListBoxItemDrawer
{
public:
CMultiColumnItemDrawer(MTextListBoxModel *aTextListBoxModel, const CFont *aFont,
CColumnListBoxData *aColumnData, CDreamColumnListBoxSub * aListBox);
virtual ~CMultiColumnItemDrawer();
private: // CListItemDrawer
void DrawActualItem(TInt aItemIndex, const TRect& aActualItemRect,TBool aItemIsCurrent,
TBool aViewIsEmphasized, TBool aViewIsDimmed,TBool aItemIsSelected) const;
private:
CDreamColumnListBoxSub* iListBox;
//const CFont * iFont;
TInt iCurPos; // starting position for the next column, and at the
// same time total width of the control
TInt iCurOffset;
};
#endif /*MULTICOLUMNITEMDRAWER_H_*/
#include "MultiColumnItemDrawer.h"
CMultiColumnItemDrawer::CMultiColumnItemDrawer(MTextListBoxModel *aTextListBoxModel, const CFont *aFont, CColumnListBoxData *aColumnData, CDreamColumnListBoxSub * aListBox)
:CColumnListBoxItemDrawer(aTextListBoxModel,aFont, aColumnData),
iListBox(aListBox)
{
iGc = &CCoeEnv::Static()->SystemGc();
SetGc(iGc);
//iFont=aFont;
iCurPos=0; // starting position for the next column, and at the
// same time total width of the control
iCurOffset=0;
}
CMultiColumnItemDrawer::~CMultiColumnItemDrawer()
{
}
void CMultiColumnItemDrawer::DrawActualItem(TInt aItemIndex,
const TRect& aActualItemRect, TBool /*aItemIsCurrent*/,
TBool /*aViewIsEmphasized*/, TBool /*aViewIsDimmed*/,
TBool aItemIsSelected) const
{
// Sets all the attributes, like font, text color and background color.
const CFont* iFont = CEikonEnv::Static()->NormalFont();
iGc->UseFont(iFont);
iGc->SetPenColor(iTextColor);
iGc->SetPenStyle(CGraphicsContext::ESolidPen);
if(aItemIsSelected)
iGc->SetBrushColor(TRgb(105,215,215));
else
iGc->SetBrushColor(TRgb(215,0,0));
iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
iGc->DrawRect(aActualItemRect);
// Draws the item text.
TPtrC itemText = iListBox->Model()->ItemText(aItemIndex);
TInt tabPosition1 = itemText.Locate('\t');
iGc->SetPenColor(KRgbGray);//itemText.Mid(0,tabPosition1)
// HBufC text=;
// text.Copy(itemText.Mid(0,tabPosition1),itemText.Length());
TInt start=0;
TInt width=20;//font.TextWidthInPixels(text);
TRect textRect1 =TRect(aActualItemRect.iTl.iX,aActualItemRect.iTl.iY+8,width,aActualItemRect.iBr.iY-3);
TInt baseline1 =(textRect1.iBr.iY - textRect1.iTl.iY - iFont->HeightInPixels()) / 2 + iFont->AscentInPixels();
iGc->DrawText(itemText.Mid(0,tabPosition1), textRect1, baseline1,CGraphicsContext::ELeft, 1);
TInt tabPosition2 = itemText.Mid(tabPosition1 + 1).Locate('\t');
iGc->SetPenColor(KRgbBlue);
start=width+2;
width=100;
TRect textRect2 =TRect(aActualItemRect.iTl.iX+start,aActualItemRect.iTl.iY+8,aActualItemRect.iTl.iX+start+width,aActualItemRect.iBr.iY-3);
TInt baseline2 =(textRect2.iBr.iY - textRect2.iTl.iY - iFont->HeightInPixels()) / 2 + iFont->AscentInPixels();
iGc->DrawText(itemText.Mid(tabPosition1+1,tabPosition2), textRect2, baseline2,CGraphicsContext::ELeft, 1);
// if (tabPosition2 >= 0)
// {
// // We need to add tabPosition1 because the return value of
// // Locate() is relative to tabPosition1.
// tabPosition2 += tabPosition1 + 1;
// }
//
//// TInt baseline = (aActualItemRect.Height() - iFont->HeightInPixels()) / 2
// + iFont->AscentInPixels();
// iGc->DrawText(itemText, aActualItemRect, baseline);
}
|
|






?????????????????
Forum posts: 54
Hi giglie
i did not get what is your problem but i customized the list box so i am giving code in attachments, you just follow this format for customizing Listbox for your requirement
Regards
Praveenvlm
Forum posts: 5
Hey I used that one too
but the exception I am getting is from stack is
immediatly after successfull execution of CreateItemDrawerL .
Forum posts: 2009
What is in your CDreamColumnListBoxSub::ConstructL() ?
Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant