TAdvListBox - don't paint selection background on icon

Can probably be done smarter, but this one works. In AdvListBox.PAS, line around 2540 in method TVisualListBox.DrawItem:

  li := FOwner.GetItem(Index);

  Canvas.Pen.Color := Canvas.Brush.Color;
  if not Assigned(li) or not Assigned(FOwner.Images) or (li.ImageIndex<0) then
    Canvas.Rectangle(Rect)
  else begin
    Canvas.Brush.Color:=Color;
    Canvas.Rectangle(Rect);
    if (odSelected in State) then Canvas.Brush.Color := SelectionColor;
    var r := Rect;
    r.Inflate(-FOwner.Images.Width,0,0,0);
    r.Left:=r.Left+2;
    Canvas.Rectangle(r)
  end;

  Rect.Left := Rect.Left + 2;

  //li := FOwner.GetItem(Index);

  if not Assigned(li) then
    Exit;

Should probably be controlled by a property "SelectionBackgroundOnImage" or something...

I'm not sure I understand. Isn't it normal & expected that when an item is selected, the entire item is drawn in selected color and the image , just like the text, is drawn on top of this selected rectangle?

Yes, but if you have an icon set that becomes almost invisible when drawn on top of the selection colour, it would be beneficial to be able to limit the selection background colour to not cover the area of the icon (and thus the icon being drawn upon the normal background colour).

This is how it looked originally:
image
and this is how it looks with my changes:
image

As you can see, the icon is hardly visible in the original case, whereas it is perfectly visible with my modifications...

We'll consider to add this as an option

One way could be to have an

property ImageBackgroundColor: TColor default clNone;

and when clNone it'll take the SelectionColor or BackgroundColor (depending on the Selected State) of the list box, otherwise it'll draw the icon area with this color before drawing the icon (which is presumed to be partially transparent). Actually, I think I'll change my code above to use this concept. It'll give the user more freedom...

I've sent you my updated UNIT in a PM. My changes are marked with

// Change: KRH >>
// <<

It is on the todolist to add property : ShowImageSelected: boolean