Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: TListView.CustomDrawItem Font Problems

4 views
Skip to first unread message

Roal Zanazzi

unread,
Aug 7, 2004, 3:17:59 PM8/7/04
to
Roal Zanazzi wrote:

> Anthony Frazier wrote:
>
>> If you do a Google Groups for "customdraw leak group:*delphi*", you'll
>> get links to threads that talk about a D5 bug and some solutions.
>> Hopefully that can give you a nudge in the right direction.
>>
> Thank you for your answer, I will check those threads as soon as
> possible. Yet I doubt it's the same problem, because I'm using D7 and it
> seems strange to me that a bug like that in D5 is not yet fixed in D7.
>

I've read every past message in different newsgroups, but most of them
don't seem related to my problem.
It does not seem to be the old resource leak bug of D5 (fixed in D5.01).

I have found only a few newsgroup messages from people having the same
"bold font" problem:
- "CustomDraw for ListView/TreeView" in comp.lang.pascal.delphi.misc in
date 2002-08-20 08:14:35 PST => no answers.
- "Painting a Progress Bar Into A Tlistview Problems..." in
borland.public.delphi.graphics in date 2002-12-08 14:39:45 PST =>
answer: "Maybe you should try Virtual TreeView"


I have also tried some different approaches to find a solution:
- saving and restoring brush, pen and whatsoever other objects for the
ListView.Canvas => does not work.
- using only pure GDI API funtions directly on ListView DC => does not
work perfectly.

The only solution I found is to FORCE the ListView.Canvas.Brush.Color (I
only modify Brush.Color) to the original one for each subitem but the
one I want to custom-draw.
Here is an example:


procedure TForm1.ListView1AdvancedCustomDrawSubItem(
Sender: TCustomListView; Item: TListItem; SubItem: Integer;
State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
var
Rect: TRect;
i: Integer;
begin
if(SubItem = 2) then
begin
Rect := Item.DisplayRect(drBounds);
for i:=0 to SubItem-1 do
Rect.Left := Rect.Left + ListView1.Column[i].Width;
Rect.Right := Rect.Left + ListView1.Column[SubItem].Width;
ListView1.Canvas.Brush.Color := clSilver;
ListView1.Canvas.FillRect(Rect);
DefaultDraw := false;
end
else
begin
// WORKAROUND: Force restoring brush color.
ListView1.Canvas.Brush.Color := clWhite;
ListView1.Canvas.Brush.Color := clWindow;
DefaultDraw := true;
end;
end;


NOTE that Canvas.Brush.Color must be changed to a different color
(clWhite) and THEN restored to the original one (clWindow), else the
workaround will not work.


This is a "stupid" workaround and is not fully tested, but it seems to
work, at least the font of the other subitems is not changed in an
unwanted manner.


I have a little sample program to demonstrate the problem and the
workaround, if anyone is interested (Borland?).

--
Roal Zanazzi

0 new messages