View Issue Details

IDProjectCategoryView StatusLast Update
0035085LazarusLCLpublic2019-03-03 22:52
ReporterZoran VučenovićAssigned ToZoran Vučenović 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version2.0.2Product Build60420 
Target VersionFixed in Version 
Summary0035085: Regression - TStringGrid event OnUserCheckboxBitmap shows no check boxes
DescriptionWhen TStringGrid.OnUserCheckboxBitmap is assigned, no check box is shown at all, just blank fields in grid.
Steps To ReproduceI am uploading the test application which shows the problem.
Additional InformationThis is regression from Lazarus 1.8.

I tracked the problem in trunk and this is what I found out:

- since rev. 57746 (30. april 2018) OnUserCheckboxBitmap does not work correctly. However, then the CheckBoxes didn't disappear fully, but the grid shows default CheckBox bitmaps, ignoring the event.

- since rev. 57927 (13. may 2018) CheckBoxes disappear totally!
TagsNo tags attached.
Fixed in Revision
LazTarget-
Widgetset
Attached Files

Relationships

related to 0035097 resolvedwp Grids - add OnUserCheckboxImage event 

Activities

Zoran Vučenović

2019-02-14 13:06

developer  

GridChkIcons.zip (128,907 bytes)

Zoran Vučenović

2019-02-14 13:14

developer  

InvisibleCheckBox.png (14,051 bytes)
InvisibleCheckBox.png (14,051 bytes)

Zoran Vučenović

2019-02-14 13:14

developer  

Rev59726.png (15,055 bytes)
Rev59726.png (15,055 bytes)

Zoran Vučenović

2019-02-14 13:15

developer  

Rev57745.png (15,339 bytes)
Rev57745.png (15,339 bytes)

Zoran Vučenović

2019-02-14 13:18

developer   ~0114107

I am uploading three screenshots which show the same application (the one I attached to this bugreport), compiled with different versions of Lazarus:

- InvisibleCheckBox.png - this is how the application looks now (2.0 or trunk), since trunk rev. 57927

- Rev59726 - this is how the application looks between revisions 57746 and 57926.

- Rev57745 - this is how it looks before the bug got introduced.

Zoran Vučenović

2019-02-14 13:35

developer   ~0114108

The original tests and screenshots were taken on Linux Mint 19.1 xfce, gtk2 widgetset, but then I tested on Windows too (with 2.0-fixes branch, win widgetset) and the bug is there as well.

Juha Manninen

2019-02-14 13:56

developer   ~0114110

r57746 is by Ondrej:
  LCL: grids: use LCLBtnGlyphs for checkbox images

r57927 is by Ondrej:
  LCL: grids: remove checkbox images

Zoran Vučenović

2019-02-14 14:53

developer   ~0114111

Yes, Juha. Ondrej's intention was obviously to improve the native (themed) looks of the checkboxes in grid.

And, by looking in the bottom grid in the screenshots, we can see that he did it well, when native appearance is wanted.
However, he obviously overlooked the StrigGrid's feature of user-provided bitmaps, so this is broken now.

Ondrej Pokorny

2019-02-14 18:39

reporter   ~0114117

Sorry - it should be easy to fix. I'll look at it.

Zoran Vučenović

2019-02-15 12:16

developer   ~0114139

Thank you, Ondrej!

Ondrej Pokorny

2019-02-15 13:16

reporter   ~0114141

Last edited: 2019-02-15 13:19

View 2 revisions

You have to change your code. The ABitmap parameter in OnUserCheckboxBitmap is VAR. In 1.8 it was pre-assigned with the default bitmap. Since 1.9 it is nil. You have to assign a valid bitmap to ABitmap - you cannot just use the original value from ABitmap.

IMO this was also the original idea how to use the parameter and your use case is a hack.

Use this approach:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    ImageListCheck: TImageList;
    Label1: TLabel;
    Label2: TLabel;
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1UserCheckboxBitmap(Sender: TObject; const aCol,
      aRow: Integer; const CheckedState: TCheckboxState; var ABitmap: TBitmap);
  private
    FBmpUnchecked: TBitmap;
    FBmpChecked: TBitmap;
  public
    destructor Destroy; override;
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.StringGrid1UserCheckboxBitmap(Sender: TObject; const aCol,
  aRow: Integer; const CheckedState: TCheckboxState; var ABitmap: TBitmap);
begin
  if CheckedState = cbUnchecked then
  begin
    if FBmpUnchecked=nil then
    begin
      FBmpUnchecked := TBitmap.Create;
      ImageListCheck.GetBitmap(0, FBmpUnchecked);
    end;
    ABitmap := FBmpUnchecked;
  end
  else
  begin
    if FBmpChecked=nil then
    begin
      FBmpChecked := TBitmap.Create;
      ImageListCheck.GetBitmap(1, FBmpChecked);
    end;
    ABitmap := FBmpChecked;
  end;

end;

destructor TForm1.Destroy;
begin
  FBmpUnchecked.Free;
  FBmpChecked.Free;

  inherited Destroy;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  for I := StringGrid1.FixedRows to StringGrid1.RowCount - 1 do begin
    StringGrid1.Cells[1, I] := IntToStr(I mod 2);
  end;
  for I := StringGrid2.FixedRows to StringGrid2.RowCount - 1 do begin
    StringGrid2.Cells[1, I] := IntToStr(I mod 2);
  end;
end;

end.

---

This works both in 1.8 and 2.0 and IMO this was also the right way to use OnUserCheckboxBitmap in 1.8.

The change should be documented, though.

Ondrej Pokorny

2019-02-15 13:23

reporter   ~0114142

Btw. the grid uses now imagelist & imageindex - so it would be appropriate to add a new event "OnUserCheckboxImage" where you could define custom ImageList and ImageIndex - see procedure TCustomGrid.GetImageForCheckBox, it has already the "var ImageList: TCustomImageList; var ImageIndex: TImageIndex;" parameters.

Zoran Vučenović

2019-02-15 16:17

developer   ~0114152

> You have to change your code.

I see. Thank you, it works.

> The change should be documented, though.

Yes. I added a few lines in release notes: http://wiki.lazarus.freepascal.org/Lazarus_2.0.0_release_notes#TCustomGrid:_The_var_parameter_ABitmap_in_event_OnUserCheckBoxBitmap_used_to_be_preassigned_with_default_bitmap.2C_but_now_it_is_nil.

> Btw. the grid uses now imagelist & imageindex - so it would be appropriate to add a new event "OnUserCheckboxImage" where you could define custom ImageList and ImageIndex - see procedure TCustomGrid.GetImageForCheckBox, it has already the "var ImageList: TCustomImageList; var ImageIndex: TImageIndex;" parameters.

Yes, the implementation seems unfinished, if I didn't miss something, currently there is no place where a user can provide the ImageList and the index. I'll see to make a patch (in new bugreport, for trunk only, not to go in fixes).

Thanks a lot, Ondrej, I am resolving this with "no change required".

Ondrej Pokorny

2019-02-15 18:12

reporter   ~0114157

> Yes. I added a few lines in release notes:

Thank you for this.

> if I didn't miss something, currently there is no place where a user can provide the ImageList and the index.

The user can override the virtual method TCustomGrid.GetImageForCheckBox. But an event handler called in this method would be good.

Zoran Vučenović

2019-02-15 21:34

developer   ~0114160

Last edited: 2019-02-15 21:37

View 2 revisions

> The user can override the virtual method TCustomGrid.GetImageForCheckBox

Notice that, as currently implemented that is actually not enough - the OnUserCheckboxBitmap must be assigned, at least with empty body, otherwise GetImageForCheckBox never gets called. :)

Anyway, I created the patch which adds OnUserCheckboxImage event - issue 35097.

Ondrej Pokorny

2019-02-16 19:43

reporter   ~0114195

> the OnUserCheckboxBitmap must be assigned, at least with empty body, otherwise GetImageForCheckBox never gets called

Huh, that was definitely not my intension. Thanks for finding this.

wp

2019-03-03 21:26

developer   ~0114604

The code does not work for TDBGrid because it uses its own event type for OnUserCheckboxBitmap - when I assign a handler to TDGrid.OnUserCheckboxBitmap the handler to the original TCustomGrid.OnUserCheckboxBitmap remains unassigned. In the checkbox drawing code, TCustomGrid.DrawGridCheckboxBitmaps, the CustomGrid checks whether it has an onUserCheckboxBitmap handler. In case of the TDBGrid, however, the handler is empty and thus never calls the virtual GetImageForCheckBox where the TDBGrid.OnUserCheckboxBitmap handler would be called.

Ondrej Pokorny

2019-03-03 22:01

reporter   ~0114605

Isn't this solved with the (not yet applied) patch in 0035097?

wp

2019-03-03 22:39

developer   ~0114606

Yes, I just did not know of this report. I'll apply that patch.

I guess that the OnUserCheckboxImage event should be published for DBGrid as well.

Issue History

Date Modified Username Field Change
2019-02-14 13:06 Zoran Vučenović New Issue
2019-02-14 13:06 Zoran Vučenović File Added: GridChkIcons.zip
2019-02-14 13:14 Zoran Vučenović File Added: InvisibleCheckBox.png
2019-02-14 13:14 Zoran Vučenović File Added: Rev59726.png
2019-02-14 13:15 Zoran Vučenović File Added: Rev57745.png
2019-02-14 13:18 Zoran Vučenović Note Added: 0114107
2019-02-14 13:35 Zoran Vučenović Note Added: 0114108
2019-02-14 13:56 Juha Manninen Note Added: 0114110
2019-02-14 14:53 Zoran Vučenović Note Added: 0114111
2019-02-14 18:39 Ondrej Pokorny Note Added: 0114117
2019-02-15 12:16 Zoran Vučenović Note Added: 0114139
2019-02-15 13:16 Ondrej Pokorny Note Added: 0114141
2019-02-15 13:19 Ondrej Pokorny Note Edited: 0114141 View Revisions
2019-02-15 13:23 Ondrej Pokorny Note Added: 0114142
2019-02-15 16:17 Zoran Vučenović Note Added: 0114152
2019-02-15 16:17 Zoran Vučenović Status new => resolved
2019-02-15 16:17 Zoran Vučenović Resolution open => no change required
2019-02-15 16:17 Zoran Vučenović Assigned To => Zoran Vučenović
2019-02-15 18:12 Ondrej Pokorny Note Added: 0114157
2019-02-15 21:29 Zoran Vučenović Relationship added related to 0035097
2019-02-15 21:34 Zoran Vučenović Note Added: 0114160
2019-02-15 21:37 Zoran Vučenović Note Edited: 0114160 View Revisions
2019-02-16 19:43 Ondrej Pokorny Note Added: 0114195
2019-03-03 21:26 wp Note Added: 0114604
2019-03-03 21:26 wp Status resolved => assigned
2019-03-03 21:26 wp Resolution no change required => reopened
2019-03-03 22:01 Ondrej Pokorny Note Added: 0114605
2019-03-03 22:39 wp Note Added: 0114606
2019-03-03 22:52 wp Status assigned => resolved
2019-03-03 22:52 wp Resolution reopened => fixed