Recent

Author Topic: ChartListbox item background color  (Read 8865 times)

wp

  • Hero Member
  • *****
  • Posts: 13431
ChartListbox item background color
« on: October 24, 2011, 08:59:50 am »
When I change the color of a TChartListbox the background of the text items still gets painted in the clWindow color. It should be transparent instead. The legend and LegendPanel are ok.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: ChartListbox item background color
« Reply #1 on: October 24, 2011, 09:34:14 am »
Fixed in r33065

wp

  • Hero Member
  • *****
  • Posts: 13431
Re: ChartListbox item background color
« Reply #2 on: October 24, 2011, 12:37:02 pm »
Thank you for the quick fix. Before posting I had tried to set the Brush.Style of the TCanvasDrawer to bsClear. But this did not compile. Doesn't the TCanvasDrawer have a brush?

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: ChartListbox item background color
« Reply #3 on: October 24, 2011, 04:30:19 pm »
It has SetBrush method, but not Brush property.
In this case, the fix should affect both branches of the following "if" statement,
and only one of those uses drawer interface.

wp

  • Hero Member
  • *****
  • Posts: 13431
Re: ChartListbox item background color
« Reply #4 on: November 24, 2011, 12:08:44 am »
With the Canvas.Brush.Style set to bsClear the selected list box item is hard to read on the default clWindow-colored item background. It is better to use the Listbox color for the item background instead of painting it transparently. Also, the owner-draw state must be checked.

Please the following code in TChartListbox.DrawItem

Code: [Select]
procedure TChartListbox.DrawItem
  ....
  // Unused(AState);  ---- remove, it is no longer unused.
  ....
  //    Canvas.Brush.Style := bsClear;
  if not (odSelected in AState) then
    Canvas.Brush.Color := Color;   
  ....

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: ChartListbox item background color
« Reply #5 on: December 07, 2011, 05:48:39 am »
Should be fixed in r34016.

wp

  • Hero Member
  • *****
  • Posts: 13431
Re: ChartListbox item background color
« Reply #6 on: December 07, 2011, 11:13:35 pm »
Sorry, it's not working. Just set the color of the Listbox to something that is not white -- the items will have a white background, but the rest of the listbox has the new background color. See the attached screen shots.

This code works fine for me (although the selection highlights only the text):
Code: [Select]
procedure TChartListbox.DrawItem(
  AIndex: Integer; ARect: TRect; AState: TOwnerDrawState);
{ draws the listbox item }
const
  UNTHEMED_FLAGS: array [TCheckboxesStyle, Boolean] of Integer = (
    (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED),
    (DFCS_BUTTONRADIO, DFCS_BUTTONRADIO or DFCS_CHECKED)
  );
  THEMED_FLAGS: array [TCheckboxesStyle, Boolean] of TThemedButton = (
    (tbCheckBoxUncheckedNormal, tbCheckBoxCheckedNormal),
    (tbRadioButtonUnCheckedNormal, tbRadioButtonCheckedNormal)
  );
var
  id: IChartDrawer;
  rcb, ricon: TRect;
  te: TThemedElementDetails;
  x: Integer;
  ch: Boolean;
begin
  Unused(AState);

  if FChart = nil then exit;

  CalcRects(ARect, rcb, ricon);

  if cloShowCheckboxes in Options then begin
    ch := Checked[AIndex];
    if ThemeServices.ThemesEnabled then begin
      te := ThemeServices.GetElementDetails(THEMED_FLAGS[FCheckStyle, ch]);
      ThemeServices.DrawElement(Canvas.Handle, te, rcb);
    end
    else
      DrawFrameControl(
        Canvas.Handle, rcb, DFC_BUTTON, UNTHEMED_FLAGS[FCheckStyle, ch]);
    x := rcb.Right;
  end
  else
    x := ARect.Left;

  if not (odSelected in AState) then
    Canvas.Brush.Color := Color;
  if cloShowIcons in Options then begin
    id := TCanvasDrawer.Create(Canvas);
    id.Pen := Chart.Legend.SymbolFrame;
    FLegendItems[AIndex].Draw(id, ricon);
  end
  else
    Canvas.TextOut(x + 2, ARect.Top, FLegendItems.Items[AIndex].Text);
end;

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: ChartListbox item background color
« Reply #7 on: December 08, 2011, 01:19:58 am »
I see. My previous change has only fixed drawing of the selected item.
Now the bug is actually in TCustomListbox code, I have submitted the patch:
http://bugs.freepascal.org/view.php?id=20837

If for some reason the patch will be rejected,
we can work around the problem in the way you suggested.

Edit: patch applied, please test.
« Last Edit: December 08, 2011, 05:06:57 pm by Ask »

wp

  • Hero Member
  • *****
  • Posts: 13431
Re: ChartListbox item background color
« Reply #8 on: December 09, 2011, 09:01:31 pm »
Thank you - it's fine now.

 

TinyPortal © 2005-2018