View Issue Details

IDProjectCategoryView StatusLast Update
0035097LazarusPatchpublic2019-03-04 12:31
ReporterZoran VučenovićAssigned Towp 
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Product Version2.2Product Build60429 
Target Version2.2Fixed in Version 
Summary0035097: Grids - add OnUserCheckboxImage event
DescriptionAdd OnUserCheckBoxImage event.
User can set ImageList and Image index for custom-drawn CheckBox images in grids.
This functionality was implemented already in TCustomGrid, but the event makes it accessible to the programmer.

I'm attaching the patch.
Additional InformationSee the discussion in bugreport 35085 (Ondrej's comments).
TagsNo tags attached.
Fixed in Revision60571, 60578, 60579
LazTarget2.2
Widgetset
Attached Files
  • UserCheckBoxImage.diff (3,534 bytes)
    Index: lcl/grids.pas
    ===================================================================
    --- lcl/grids.pas	(revision 60429)
    +++ lcl/grids.pas	(working copy)
    @@ -368,6 +368,12 @@
                   const CheckedState: TCheckboxState;
                   var ABitmap: TBitmap) of object;
     
    +  TUserCheckBoxImageEvent =
    +    procedure(Sender: TObject; const aCol, aRow: Integer;
    +              const CheckedState: TCheckBoxState;
    +              var ImageList: TCustomImageList;
    +              var ImageIndex: TImageIndex) of object;
    +
       TValidateEntryEvent =
         procedure(sender: TObject; aCol, aRow: Integer;
                   const OldValue: string; var NewValue: String) of object;
    @@ -728,6 +734,7 @@
         FRangeSelectMode: TRangeSelectMode;
         FSelections: TGridRectArray;
         FOnUserCheckboxBitmap: TUserCheckboxBitmapEvent;
    +    FOnUserCheckboxImage: TUserCheckBoxImageEvent;
         FSortOrder: TSortOrder;
         FSortColumn: Integer;
         FSortLCLImages: TLCLGlyphs;
    @@ -1247,6 +1254,7 @@
         property OnSelectEditor: TSelectEditorEvent read FOnSelectEditor write FOnSelectEditor;
         property OnTopLeftChanged: TNotifyEvent read FOnTopLeftChanged write FOnTopLeftChanged;
         property OnUserCheckboxBitmap: TUserCheckboxBitmapEvent read FOnUserCheckboxBitmap write FOnUserCheckboxBitmap;
    +    property OnUserCheckboxImage: TUserCheckBoxImageEvent read FOnUserCheckboxImage write FOnUserCheckboxImage;
         property OnValidateEntry: TValidateEntryEvent read FOnValidateEntry write FOnValidateEntry;
         // Bidi functions
         function FlipRect(ARect: TRect): TRect;
    @@ -1629,6 +1637,7 @@
         property OnStartDrag;
         property OnTopleftChanged;
         property OnUserCheckboxBitmap;
    +    property OnUserCheckboxImage;
         property OnUTF8KeyPress;
         property OnValidateEntry;
       end;
    @@ -1869,6 +1878,7 @@
         property OnStartDrag;
         property OnTopLeftChanged;
         property OnUserCheckboxBitmap;
    +    property OnUserCheckboxImage;
         property OnUTF8KeyPress;
         property OnValidateEntry;
       end;
    @@ -4598,23 +4608,19 @@
       ChkII := -1;
       ChkBitmap := nil;
     
    -  if not Assigned(OnUserCheckboxBitmap) then
    +  GetImageForCheckBox(aCol, aRow, AState, ChkIL, ChkII, ChkBitmap);
    +  if Assigned(ChkBitmap) then
    +    CSize := Size(ChkBitmap.Width, ChkBitmap.Height)
    +  else if (Assigned(ChkIL) and (ChkII>=0)) then
       begin
    +    ChkILRes := ChkIL.ResolutionForPPI[ChkIL.Width, Font.PixelsPerInch, GetCanvasScaleFactor];
    +    CSize := ChkILRes.Size;
    +  end else
    +  begin
         Details := ThemeServices.GetElementDetails(arrtb[AState]);
         CSize := ThemeServices.GetDetailSize(Details);
         CSize.cx := MulDiv(CSize.cx, Font.PixelsPerInch, Screen.PixelsPerInch);
         CSize.cy := MulDiv(CSize.cy, Font.PixelsPerInch, Screen.PixelsPerInch);
    -  end else
    -  begin
    -    GetImageForCheckBox(aCol, aRow, AState, ChkIL, ChkII, ChkBitmap);
    -    if Assigned(ChkBitmap) then
    -      CSize := Size(ChkBitmap.Width, ChkBitmap.Height)
    -    else if (Assigned(ChkIL) and (ChkII>=0)) then
    -    begin
    -      ChkILRes := ChkIL.ResolutionForPPI[ChkIL.Width, Font.PixelsPerInch, GetCanvasScaleFactor];
    -      CSize := ChkILRes.Size;
    -    end else
    -      Exit;
       end;
     
       case bmpAlign of
    @@ -5525,6 +5531,8 @@
     begin
       if Assigned(OnUserCheckboxBitmap) then
         OnUserCheckboxBitmap(Self, aCol, aRow, CheckBoxView, Bitmap);
    +  if (Bitmap = nil) and Assigned(OnUserCheckBoxImage) then
    +    OnUserCheckboxImage(Self, aCol, aRow, CheckBoxView, ImageList, ImageIndex);
     end;
     
     procedure TCustomGrid.AdjustInnerCellRect(var ARect: TRect);
    
    UserCheckBoxImage.diff (3,534 bytes)
  • GridCheckImage.zip (130,130 bytes)

Relationships

related to 0035085 resolvedZoran Vučenović Regression - TStringGrid event OnUserCheckboxBitmap shows no check boxes 

Activities

Zoran Vučenović

2019-02-15 21:28

developer  

UserCheckBoxImage.diff (3,534 bytes)
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 60429)
+++ lcl/grids.pas	(working copy)
@@ -368,6 +368,12 @@
               const CheckedState: TCheckboxState;
               var ABitmap: TBitmap) of object;
 
+  TUserCheckBoxImageEvent =
+    procedure(Sender: TObject; const aCol, aRow: Integer;
+              const CheckedState: TCheckBoxState;
+              var ImageList: TCustomImageList;
+              var ImageIndex: TImageIndex) of object;
+
   TValidateEntryEvent =
     procedure(sender: TObject; aCol, aRow: Integer;
               const OldValue: string; var NewValue: String) of object;
@@ -728,6 +734,7 @@
     FRangeSelectMode: TRangeSelectMode;
     FSelections: TGridRectArray;
     FOnUserCheckboxBitmap: TUserCheckboxBitmapEvent;
+    FOnUserCheckboxImage: TUserCheckBoxImageEvent;
     FSortOrder: TSortOrder;
     FSortColumn: Integer;
     FSortLCLImages: TLCLGlyphs;
@@ -1247,6 +1254,7 @@
     property OnSelectEditor: TSelectEditorEvent read FOnSelectEditor write FOnSelectEditor;
     property OnTopLeftChanged: TNotifyEvent read FOnTopLeftChanged write FOnTopLeftChanged;
     property OnUserCheckboxBitmap: TUserCheckboxBitmapEvent read FOnUserCheckboxBitmap write FOnUserCheckboxBitmap;
+    property OnUserCheckboxImage: TUserCheckBoxImageEvent read FOnUserCheckboxImage write FOnUserCheckboxImage;
     property OnValidateEntry: TValidateEntryEvent read FOnValidateEntry write FOnValidateEntry;
     // Bidi functions
     function FlipRect(ARect: TRect): TRect;
@@ -1629,6 +1637,7 @@
     property OnStartDrag;
     property OnTopleftChanged;
     property OnUserCheckboxBitmap;
+    property OnUserCheckboxImage;
     property OnUTF8KeyPress;
     property OnValidateEntry;
   end;
@@ -1869,6 +1878,7 @@
     property OnStartDrag;
     property OnTopLeftChanged;
     property OnUserCheckboxBitmap;
+    property OnUserCheckboxImage;
     property OnUTF8KeyPress;
     property OnValidateEntry;
   end;
@@ -4598,23 +4608,19 @@
   ChkII := -1;
   ChkBitmap := nil;
 
-  if not Assigned(OnUserCheckboxBitmap) then
+  GetImageForCheckBox(aCol, aRow, AState, ChkIL, ChkII, ChkBitmap);
+  if Assigned(ChkBitmap) then
+    CSize := Size(ChkBitmap.Width, ChkBitmap.Height)
+  else if (Assigned(ChkIL) and (ChkII>=0)) then
   begin
+    ChkILRes := ChkIL.ResolutionForPPI[ChkIL.Width, Font.PixelsPerInch, GetCanvasScaleFactor];
+    CSize := ChkILRes.Size;
+  end else
+  begin
     Details := ThemeServices.GetElementDetails(arrtb[AState]);
     CSize := ThemeServices.GetDetailSize(Details);
     CSize.cx := MulDiv(CSize.cx, Font.PixelsPerInch, Screen.PixelsPerInch);
     CSize.cy := MulDiv(CSize.cy, Font.PixelsPerInch, Screen.PixelsPerInch);
-  end else
-  begin
-    GetImageForCheckBox(aCol, aRow, AState, ChkIL, ChkII, ChkBitmap);
-    if Assigned(ChkBitmap) then
-      CSize := Size(ChkBitmap.Width, ChkBitmap.Height)
-    else if (Assigned(ChkIL) and (ChkII>=0)) then
-    begin
-      ChkILRes := ChkIL.ResolutionForPPI[ChkIL.Width, Font.PixelsPerInch, GetCanvasScaleFactor];
-      CSize := ChkILRes.Size;
-    end else
-      Exit;
   end;
 
   case bmpAlign of
@@ -5525,6 +5531,8 @@
 begin
   if Assigned(OnUserCheckboxBitmap) then
     OnUserCheckboxBitmap(Self, aCol, aRow, CheckBoxView, Bitmap);
+  if (Bitmap = nil) and Assigned(OnUserCheckBoxImage) then
+    OnUserCheckboxImage(Self, aCol, aRow, CheckBoxView, ImageList, ImageIndex);
 end;
 
 procedure TCustomGrid.AdjustInnerCellRect(var ARect: TRect);
UserCheckBoxImage.diff (3,534 bytes)

Zoran Vučenović

2019-02-15 21:55

developer  

GridCheckImage.zip (130,130 bytes)

Zoran Vučenović

2019-02-15 21:58

developer   ~0114161

I uploaded the application which shows the usage.
You can try the application only after applying the patch and rebuilding the IDE.

Ondrej Pokorny

2019-02-16 19:42

developer   ~0114194

Very nice!

wp

2019-03-03 22:50

developer   ~0114607

I applied it and published the event also for TDBGrid. Thank you.

wp

2019-03-04 12:31

developer   ~0114625

Just for the record:
- r60578 undoes part of the patch to keep the code which fixes the DBGrid issue and which can be back-ported to Fixes.
- r60579 re-adds the removed code to add the OnUserCheckboxImage event again which will remain in trunk only.

Issue History

Date Modified Username Field Change
2019-02-15 21:28 Zoran Vučenović New Issue
2019-02-15 21:28 Zoran Vučenović File Added: UserCheckBoxImage.diff
2019-02-15 21:29 Zoran Vučenović Relationship added related to 0035085
2019-02-15 21:55 Zoran Vučenović File Added: GridCheckImage.zip
2019-02-15 21:58 Zoran Vučenović Note Added: 0114161
2019-02-16 19:42 Ondrej Pokorny Note Added: 0114194
2019-03-03 22:45 wp Assigned To => wp
2019-03-03 22:45 wp Status new => assigned
2019-03-03 22:50 wp Note Added: 0114607
2019-03-03 22:51 wp Fixed in Revision => 60571
2019-03-03 22:51 wp LazTarget - => 2.2
2019-03-03 22:51 wp Status assigned => resolved
2019-03-03 22:51 wp Resolution open => fixed
2019-03-03 22:51 wp Target Version => 2.2
2019-03-04 12:31 wp Note Added: 0114625
2019-03-04 12:31 wp Status resolved => assigned
2019-03-04 12:31 wp Resolution fixed => reopened
2019-03-04 12:31 wp Fixed in Revision 60571 => 60571, 60578, 60579
2019-03-04 12:31 wp Status assigned => resolved
2019-03-04 12:31 wp Resolution reopened => fixed