custom drawing in ListView colums

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

custom drawing in ListView colums

Jochen Riekhof
Hi...

for a graphical view with coloured elements I have built a list view that
contains the same elements for easy modifications.
In the ListView in #report mode, I defined two columns, one for color and
one for text. The color colum is the one I am stucj with. My intent is to
simply set a custom draw block in the first column and paint the list
element's color property on the canvas myself.
My block now looks like this:

[:nm ||c|
c := nm canvas.
c brush: (Brush color: nm item color).
c fillRectangle: nm boundingRectangle.
true]

Unfortunately, the nm ( instance of NMCUSTOMDRAW) boundingRectangle
deliveres always
0@0 extent: 16@0, regardless of the entry. The canvas I get seems to be the
one of the list background.

Is there any simple way to accomplish a painting in a list column?

Also I would like to add a column containing checkboxes at a later stage. Is
this also possible?

Ciao

...Jochen


Reply | Threaded
Open this post in threaded view
|

Re: custom drawing in ListView colums

Steve Alan Waring
Hi Jochen,

Jochen Riekhof wrote:

<snip>

> Unfortunately, the nm ( instance of NMCUSTOMDRAW) boundingRectangle
> deliveres always
> 0@0 extent: 16@0, regardless of the entry.

You can use ListView>>lvmGetItemRect:bounding: to get a valid
boundingRectangle for a row. If you want the boundingRectangle of a cell,
you will need to add the following method to ListView:

!ListView methodsFor!
lvmGetSubItemRect: index subItem: subIndex bounding: boundingValue
"Private - Retrieves information about the bounding rectangle for a subitem
in a list-view control. "
| rect |
rect := RECT new.
rect
left: boundingValue;
top: subIndex.
"LVM_GETSUBITEMRECT 4152"
(self
sendMessage: 4152
wParam: index
lpParam: rect) == 0
ifTrue: [^self errorInCommonControlCall: index].
^rect asRectangle! !

> Also I would like to add a column containing checkboxes at a later
> stage. Is this also possible?

Not sure, but Chris Uppal's ListTreeView http://www.metagnostic.org/ is a
good example of using state images in a ListView.

Steve

--
Steve Waring
Email: [hidden email]
Journal: http://www.stevewaring.net/blog/home/index.html


Reply | Threaded
Open this post in threaded view
|

Re: custom drawing in ListView colums

Jochen Riekhof
> You can use ListView>>lvmGetItemRect:bounding: to get a valid
> boundingRectangle for a row. If you want the boundingRectangle of a cell,
> you will need to add the following method to ListView:

The additional method is no t necessary, as I have only the y components
missing in the rectangle returned by NMCUSTOMDRAW>>boundingRectangle.

More problematic is that I have no easy way to determine the index of the
currently drawn item. I had to (ulch) look into the views model with the
passed item and obtain the index this way. Maybe I overlooked something?

here is my solution so far:

[:nm ||idx bbox |
    idx := nm view model list indexOf: nm item.
    bbox := nm view lvmGetItemRect: (idx - 1) bounding: 0.
    bbox
        left: nm boundingRectangle left;
        width: nm column width.
    nm canvas
        brush: (Brush color: nm item color);
        fillRectangle: bbox.
    true]

Ciao

...Jochen


Reply | Threaded
Open this post in threaded view
|

Re: custom drawing in ListView colums

Steve Alan Waring
Hi Jochen,

Jochen Riekhof wrote:
>
> More problematic is that I have no easy way to determine the index of
> the currently drawn item.

NMLVCUSTOMDRAW>>itemHandle is the index.

Steve
--
Steve Waring
Email: [hidden email]
Journal: http://www.stevewaring.net/blog/home/index.html


Reply | Threaded
Open this post in threaded view
|

Re: custom drawing in ListView colums

Jochen Riekhof
> NMLVCUSTOMDRAW>>itemHandle is the index.

Great! Thanks!

Ciao

...Jochen