×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    36

    formatting text in a listbox

    hi, i have a question for the experts, or yucca, or anyone else:

    is it possible to have certain characters on a line in a listbox have a different formatting from other characters on that same line. by different formatting, i mean bolding, underlining, italics, different color, highlighting, or anything else that would make certain characters look different from others.

    for example, if this were my simple listbox, where each line represents a different entry in the listbox:

    Mary
    Jane
    John


    is it possible to have only "Ma" in the first entry to be of different formatting than the "ry" (and of different formatting than "Jane" and "John", as well)?

    thanks for your help.

    (i realize that there is probably an easy way to have the entire entry "Mary" formatted differently than the entry "Jane", but that's not what i'm asking)

    (what does the class CFormattedCellListBoxData do?)

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037
    Hi,

    yes it is possible. Derive your listbox from CEikTextListBox. Than you must provide you own CTextListItemDrawer derived class to draw the lines in the listbox. In the item drawer class is method DrawActualItem(), which should be implemeted to draw. it is called once for each line. To write text or draw images, rects you use a CWindowGc, so it is upon you in which style you will draw the texts. If you will have some problems with implementation, write here, and i will manage some example source code during saturday.

    Bye STeN

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    36

    my code

    thanks very much for your help, it works well. here is my example code in case others have the same question.



    // MySingleStyleListBox.h: interface for the CMySingleStyleListBox class.
    //
    //////////////////////////////////////////////////////////////////////

    #include <aknlists.h>
    #include <eikclbd.h>

    class CMySingleStyleListBox : public CAknSingleStyleListBox
    {
    public:
    CMySingleStyleListBox();
    virtual ~CMySingleStyleListBox();
    protected:
    virtual void CreateItemDrawerL();
    };

    class CMyColumnListBoxItemDrawer : public CColumnListBoxItemDrawer
    {
    public:
    CMyColumnListBoxItemDrawer(MTextListBoxModel* aTextListBoxModel, const CFont* aFont, CColumnListBoxData* aColumnData);
    virtual ~CMyColumnListBoxItemDrawer();

    virtual void DrawActualItem(TInt aItemIndex, const TRect& aActualItemRect, TBool aItemIsCurrent, TBool aViewIsEmphasized, TBool, TBool aItemIsSelected) const;

    void SetFindBox(CAknSearchField* aFindBox);
    CAknSearchField* iFindBox;
    };


    // MySingleStyleListBox.cpp: implementation of the CMySingleStyleListBox class.
    //
    //////////////////////////////////////////////////////////////////////

    #include "MySingleStyleListBox.h"

    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////

    CMySingleStyleListBox::CMySingleStyleListBox()
    {

    }

    void CMySingleStyleListBox::CreateItemDrawerL()
    {
    CColumnListBoxData* columnData = CColumnListBoxData::NewL(); // looks like CColumnListBoxItemDrawer owns columnData

    const CFont* myFont;
    myFont = CEikonEnv::Static()->DenseFont();

    iItemDrawer = new(ELeave) CMyColumnListBoxItemDrawer(Model(), myFont, columnData);

    }


    CMySingleStyleListBox::~CMySingleStyleListBox()
    {

    }

    // MySingleStyleListBox.cpp: implementation of the CMyColumnListBoxItemDrawer class.
    //
    //////////////////////////////////////////////////////////////////////


    CMyColumnListBoxItemDrawer::CMyColumnListBoxItemDrawer(MTextListBoxModel* aTextListBoxModel, const CFont* aFont, CColumnListBoxData* aColumnData)
    :CColumnListBoxItemDrawer(aTextListBoxModel, aFont, aColumnData){
    }

    void CMyColumnListBoxItemDrawer::DrawActualItem(TInt aItemIndex, const TRect& aActualItemRect, TBool aItemIsCurrent, TBool aViewIsEmphasized, TBool, TBool aItemIsSelected) const
    {

    iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
    iGc->SetBrushColor(KRgbWhite);

    TBuf<128> text;
    text.Append(iModel->ItemText(aItemIndex));
    TInt stringbegin = text.Locate(';') + 1;
    text.Delete(0,stringbegin);

    iGc->SetBrushColor(KRgbYellow);


    if(aItemIsCurrent)
    {

    TListItemProperties bold;
    bold.SetBold(ETrue);
    bold.SetColor(KRgbBlack);
    bold.SetDimmed(EFalse);
    bold.SetItalics(ETrue);
    CFont* fontUsed = ColumnData()->Font(bold,0);

    iGc->UseFont(fontUsed);

    TInt highlightwidth = fontUsed->TextWidthInPixels(text.Left(numchars));
    TRect highlighted = aActualItemRect;
    highlighted.SetWidth(highlightwidth);
    TPoint topleft(aActualItemRect.iTl.iX + highlightwidth, aActualItemRect.iTl.iY);
    TRect unhighlighted(topleft, aActualItemRect.iBr);

    iGc->DrawText(text.Left(numchars),highlighted,(fontUsed->AscentInPixels() + aActualItemRect.Height())/2);
    iGc->SetBrushColor(KRgbWhite);
    iGc->DrawText(text.Mid(numchars),unhighlighted,(fontUsed->AscentInPixels() + aActualItemRect.Height())/2);
    iGc->DiscardFont();
    iGc->UseFont(iFont);
    }
    else
    {

    TInt highlightwidth = iFont->TextWidthInPixels(text.Left(numchars));
    TRect highlighted = aActualItemRect;
    highlighted.SetWidth(highlightwidth);
    TPoint topleft(aActualItemRect.iTl.iX + highlightwidth, aActualItemRect.iTl.iY);
    TRect unhighlighted(topleft, aActualItemRect.iBr);

    iGc->DrawText(text.Left(numchars),highlighted,(iFont->AscentInPixels() + aActualItemRect.Height())/2);
    iGc->SetBrushColor(KRgbWhite);
    iGc->DrawText(text.Mid(numchars),unhighlighted,(iFont->AscentInPixels() + aActualItemRect.Height())/2);


    }

    }


    CMyColumnListBoxItemDrawer::~CMyColumnListBoxItemDrawer()
    {

    }

  4. #4
    Regular Contributor
    Join Date
    Apr 2005
    Location
    Indonesia
    Posts
    73

    Re: formatting text in a listbox

    Have U try to use difference Size for each item list? or just the selected item???
    Can we do this??

    Thanks
    osla

  5. #5
    Regular Contributor
    Join Date
    Jul 2004
    Posts
    273

    Re: formatting text in a listbox

    Thanks for your code

    is it possible to change aActualItemRect dynamicly?

    what i want to do is :The item text is much longer than the screen width, i want all the text to be shown when the item selected.

    thanks

  6. #6
    Regular Contributor
    Join Date
    Apr 2005
    Location
    Indonesia
    Posts
    73

    Re: formatting text in a listbox

    Yas, U can use DrawItem:

    Code:
    void CCustomListItemDrawer::DrawItem(TInt aItemIndex, TPoint aItemRectPos,
         	TBool aSelected, TBool aItemIsCurrent, TBool aViewIsEmphasized, 
    		TBool aViewIsDimmed) const
    	{
    	TRect itemRect;
    	
    	TInt selectedIndex(iListBox.CurrentItemIndex());
    	
    	if(aItemIndex>selectedIndex)
    		{
    		TSize SizeAdded(0,50);
    		aItemRectPos+=SizeAdded;
    		itemRect = TRect(aItemRectPos,TSize(iItemCellSize.iWidth,iItemCellSize.iHeight));
    		}
    	else
    		{
    		if(aItemIsCurrent)
    			{
    			itemRect = TRect(aItemRectPos,TSize(iItemCellSize.iWidth,iItemCellSize.iHeight));
    			}
    		else
    			itemRect = TRect(aItemRectPos,TSize(iItemCellSize.iWidth,iItemCellSize.iHeight));
    		}
    		
    	
    	DrawActualItem(aItemIndex, itemRect, aItemIsCurrent, aViewIsEmphasized, aViewIsDimmed, aSelected);
    	}
    But, when I use this, I get some problem. I cant see the full rect on the selected item, if the selected item is on the bottom of the list box.
    If U can manage this problem. Please reply this forum.

    Thanks
    osla

  7. #7
    Regular Contributor
    Join Date
    Jul 2004
    Posts
    273

    Re: formatting text in a listbox

    i get the same problem when the selected index is the botton index and this rect is heigher than the default rect height.


    do you get a solution.


    regards

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    35

    Re: formatting text in a listbox

    hi,

    i want to change the row's height for all rows...is it possible?
    i want to use more space for each rows.....

    thanks
    ABC

  9. #9
    Regular Contributor
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    103

    Re: formatting text in a listbox

    Hi
    you can use

    iListBox->SetItemHeightL(TInt a Height);

    regards
    Rafeeq

  10. #10
    Registered User
    Join Date
    Oct 2007
    Posts
    1

    Re: formatting text in a listbox

    Has anyone figured out a solution to the problem where the last item gets cut off?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×