I use a custom list control. Inherits caknsinglestylelistbox.
// ------------------------------------------------------ Header file ------------------------------------------------
# Ifndef _ cmysinglestylelistbox __
# DEFINE _ cmysinglestylelistbox __
# Include <aknlists. h>
# Include <eikclbd. h>
Class cControl;
Class cfbsbitmap;
Class cmaxicon; // It is a custom image class.
Class cmysinglestylelistbox: Public caknsinglestylelistbox
{
Public:
Cmysinglestylelistbox (cControl * acontrol );
Virtual ~ Cmysinglestylelistbox ();
Protected:
Virtual void createitemdrawerl ();
CControl * iControl;
Rarray <tint> iselectrecordid; // the ID of the record displayed in the list
Cmaxicon * iback; // background color
Cmaxicon * iselectedback; // selected background
};
Class cmycolumnlistboxitemdrawer: Public ccolumnlistboxitemdrawer
{
Public:
Cmycolumnlistboxitemdrawer (mtextlistboxmodel * atextlistboxmodel,
Const cfont * afont, ccolumnlistboxdata * acolumndata,
Ceiklistbox * alistbox, cControl * acontrol, cmaxicon * aback,
Cmaxicon * aselback );
Virtual ~ Cmycolumnlistboxitemdrawer ();
Virtual void drawactualitem (tint aitemindex, const trect & aactualitemrect,
Tbool aitemiscurrent, tbool aviewisemphasized, tbool,
Tbool aitemisselected) const;
Void setfindbox (caknsearchfield * afindbox );
Caknsearchfield * ifindbox;
Ceiklistbox * iowner;
CControl * iControl;
Rarray <tint> iselectrecordid; // the ID of the record displayed in the list
Maknsskininstance * skin;
// Image
Cmaxicon * iback; // background color
Cmaxicon * iselectedback; // selected background
};
# Endif
// ------------------------------------------------------ Definition file ------------------------------------------------
# Include <aknsutils. h>
# Include <aknsskininstance. h>
//
# Include "Manager/control. H"
# Include "Manager/helper. H"
# Include "Manager/maxicon. H"
# Include "control/mysinglestylelistbox. H"
//////////////////////////////////////// //////////////////////////////
// Construction/destruction
//////////////////////////////////////// //////////////////////////////
# Define mem_free (A) if (a) {Delete A; A = NULL ;}
Cmysinglestylelistbox: cmysinglestylelistbox (cControl * acontrol)
{
IControl = acontrol;
Iback = NULL;
Iselectedback = NULL;
}
Void cmysinglestylelistbox: createitemdrawerl ()
{
Ccolumnlistboxdata * columndata = ccolumnlistboxdata: newl ();
Enabledragevents ();
Const cfont * myfont;
Myfont = ceikonenv: static ()-> densefont ();
Ceiklistbox * alistbox = this;
// Load the image
Cmaxiconmanager * piconmgr = iControl-> iiconmanager;
// Background
Iback = piconmgr-> getmaxicon (cmaxiconmanager: elistback );
Iselectedback = piconmgr-> getmaxicon (cmaxiconmanager: elistcur );
Iitemdrawer = new (eleave) cmycolumnlistboxitemdrawer (model (), myfont,
Columndata, alistbox, iControl, iback, iselectedback );
// Iitemdrawer-> setitemcellsize (tpoint (100,100 ));
// The iitemdrawer-> setitemcellsize (tsize (360,100 ));
Iitemdrawer-> setitemcellsize (tsize (360,100 ));
// View ()-> setitemheight (100 );
}
Cmysinglestylelistbox ::~ Cmysinglestylelistbox ()
{
}
// Mysinglestylelistbox. cpp: Implementation of the cmycolumnlistboxitemdrawer class.
//
//////////////////////////////////////// //////////////////////////////
Cmycolumnlistboxitemdrawer: cmycolumnlistboxitemdrawer (
Mtextlistboxmodel * atextlistboxmodel, const cfont * afont,
Ccolumnlistboxdata * acolumndata, ceiklistbox * alistbox,
CControl * acontrol, cmaxicon * aback, cmaxicon * aselback ):
Ccolumnlistboxitemdrawer (atextlistboxmodel, afont, acolumndata), iowner (
Alistbox)
{
IControl = acontrol;
Iback = aback;
Iselectedback = aselback;
// Setitemcellsize (tsize (360,150 ));
}
Void cmycolumnlistboxitemdrawer: drawactualitem (tint aitemindex,
Const trect & aactualitemrect, tbool aitemiscurrent,
Tbool aviewisemphasized, tbool, tbool aitemisselected) const
{
// You need to modify the highlight
/*
Maknsskininstance * Skin = aknsutils: skininstance ();
Maknscontrolcontext * Cc = aknsdrawutils: controlcontext (iowner );
If (Skin & CC)
{
Aknsdrawutils: background (skin, CC, iowner, * IGC, aactualitemrect );
}
*/
Trect arect = aactualitemrect;
Arect. IBR. IX + = 30;
Trgb rselected (trgb (228,100, 41); // The selected color.
Trgb runselected (trgb (255,255,255); // No selected color
Trect outer_rect (arect );
Outer_rect.shrink (2, 2 );
Trect inner_rect (outer_rect );
Inner_rect.shrink (3, 3 );
/*
// Draw a background image
Nhelper: drawmaxicon (* IGC, aactualitemrect, iback );
*/
/*
If (aitemiscurrent)
{
Nhelper: drawmaxicon (* IGC, aactualitemrect, iselectedback );
}
Else
{
Nhelper: drawmaxicon (* IGC, aactualitemrect, iback );
}
*/
If (aitemiscurrent)
{
// Nhelper: drawmaxicon (* IGC, aactualitemrect, iselectedback );
IGC-> drawbitmap (arect, iselectedback-> m_pbitmap );
}
Else
{
// Nhelper: drawmaxicon (* IGC, aactualitemrect, iback );
IGC-> drawbitmap (arect, iback-> m_pbitmap );
}
// Initial black
Const cfont * font = ceikonenv: static ()-> normalfont ();
IGC-> usefont (font );
IGC-> setpenstyle (cgraphicscontext: esolidpen );
IGC-> setpencolor (ihighlightedtextcolor );
Tptrc itemtext = imodel-> itemtext (aitemindex );
Tint Baseline = (arect. Height ()-font-> heightinpixels ()/2
+ Font-> ascentinpixels ();
// Calculate the length of each string segment
Tint highlightwidth = font-> textwidthinpixels (itemtext );
Trect highlighted = arect;
Highlighted. setwidth (highlightwidth );
// Draw each string itextcolor
IGC-> setpencolor (runselected );
IGC-> setpenstyle (cgraphicscontext: esolidpen );
IGC-> drawtext (itemtext, highlighted, baseline );
// Release the font
IGC-> discardfont ();
}
Cmycolumnlistboxitemdrawer ::~ Cmycolumnlistboxitemdrawer ()
{
}
// -------------------------------------------------------- Precautions ------------------------------------------------
I finally found a solution. The method is as follows:
1. Set the size when creating the list element.
// Data operations
Ilistshopboxarray = new (eleave) cdescarrayflat (10 );
Ctextlistboxmodel * model = ilistshopbox-> model ();
Model-> setitemtextarray (ilistshopboxarray );
Model-> setownershiptype (elbmownsitemarray );
// Add a scroll bar
Ilistshopbox-> createscrollbarframel (etrue );
Ilistshopbox-> scrollbarframe ()-> setscrollbarvisibilityl (
Ceikscrollbarframe: Eon, ceikscrollbarframe: eauto );
// Ilistshopbox-> setitemheightl (klistitemhieght );
Ilistshopbox-> setfocus (etrue );
Ilistshopbox-> makevisible (etrue );
Ilistshopbox-> setrect (itlist );
// Setitemheight () is valid only at the end. I don't know why ......
Ilistshopbox-> View ()-> setitemheight (102 );
2. Add in createitemdrawerl ()
Void cmysinglestylelistbox: createitemdrawerl ()
{
Ccolumnlistboxdata * columndata = ccolumnlistboxdata: newl ();
Enabledragevents ();
Const cfont * myfont;
Myfont = ceikonenv: static ()-> densefont ();
Ceiklistbox * alistbox = this;
Iitemdrawer = new (eleave) cmycolumnlistboxitemdrawer (model (), myfont,
Columndata, alistbox, iControl );
Iitemdrawer-> setitemcellsize (tsize (360,102 ));
}
OK ......