diff --git a/components/nicegrid/demos/Basic Demo/Project_Lazarus/basic_demo.lpi b/components/nicegrid/demos/Basic Demo/Project_Lazarus/basic_demo.lpi
index 15a05ad1c..3699862f3 100644
--- a/components/nicegrid/demos/Basic Demo/Project_Lazarus/basic_demo.lpi
+++ b/components/nicegrid/demos/Basic Demo/Project_Lazarus/basic_demo.lpi
@@ -12,6 +12,10 @@
+
+
+
+
@@ -33,12 +37,12 @@
-
+
-
-
+
+
@@ -96,8 +100,8 @@
-
-
+
+
@@ -105,86 +109,147 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
-
-
+
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/nicegrid/demos/Basic Demo/Project_Lazarus/basic_demo.lpr b/components/nicegrid/demos/Basic Demo/Project_Lazarus/basic_demo.lpr
index 5efbd62c5..b771c938a 100644
--- a/components/nicegrid/demos/Basic Demo/Project_Lazarus/basic_demo.lpr
+++ b/components/nicegrid/demos/Basic Demo/Project_Lazarus/basic_demo.lpr
@@ -10,6 +10,7 @@ uses
{$R *.res}
begin
+ Application.Scaled := true;
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
diff --git a/components/nicegrid/demos/Basic Demo/common/main.lfm b/components/nicegrid/demos/Basic Demo/common/main.lfm
index 39d23b174..51da4e8fb 100644
--- a/components/nicegrid/demos/Basic Demo/common/main.lfm
+++ b/components/nicegrid/demos/Basic Demo/common/main.lfm
@@ -8,7 +8,7 @@ object MainForm: TMainForm
ClientWidth = 638
OnCreate = FormCreate
Position = poDesktopCenter
- LCLVersion = '2.3.0.0'
+ LCLVersion = '3.99.0.0'
object Label1: TLabel
Left = 16
Height = 15
@@ -41,11 +41,7 @@ object MainForm: TMainForm
HeaderLightColor = 16744448
HeaderDarkColor = clBlack
HeaderFont.Color = clWhite
- HeaderFont.Height = -11
- HeaderFont.Name = 'MS Sans Serif'
FooterFont.Color = clRed
- FooterFont.Height = -11
- FooterFont.Name = 'MS Sans Serif'
SelectionColor = 13816575
Columns = <
item
@@ -87,8 +83,6 @@ object MainForm: TMainForm
GutterKind = gkNumber
GutterWidth = 40
GutterFont.Color = clWhite
- GutterFont.Height = -11
- GutterFont.Name = 'MS Sans Serif'
ShowFooter = True
OnDrawHeader = NiceGrid1DrawHeader
OnInsertRow = NiceGrid1InsertRow
diff --git a/components/nicegrid/packages/Lazarus/NiceGridLaz.lpk b/components/nicegrid/packages/Lazarus/NiceGridLaz.lpk
index 37e12bf0f..390b8ae7a 100644
--- a/components/nicegrid/packages/Lazarus/NiceGridLaz.lpk
+++ b/components/nicegrid/packages/Lazarus/NiceGridLaz.lpk
@@ -4,7 +4,7 @@
-
+
diff --git a/components/nicegrid/source/nicegrid.pas b/components/nicegrid/source/nicegrid.pas
index 0f4dc6f62..0c5132ba4 100644
--- a/components/nicegrid/source/nicegrid.pas
+++ b/components/nicegrid/source/nicegrid.pas
@@ -403,6 +403,9 @@ type
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
+ {$IFDEF FPC}
+ procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy; const AXProportion, AYProportion: Double); override;
+ {$ENDIF}
public
constructor Create(AOwner: TComponent); override;
@@ -430,6 +433,10 @@ type
property VertOffset: Integer read FVertOffset write SetVertOffset;
function MergeCells(const X1, Y1, X2, Y2: Integer; ACaption: string): TMergeCell;
procedure ClearMergeCells;
+ {$IFDEF FPC}
+ procedure FixDesignFontsPPI(const ADesignTimePPI: Integer); override;
+ procedure ScaleFontsPPI(const AToPPI: Integer; const AProportion: Double); override;
+ {$ENDIF}
published
property Enabled: Boolean read FEnabled write SetEnabled default True;
@@ -1275,6 +1282,8 @@ procedure TNiceGrid.DrawSelection;
var
R, R1, R2: TRect;
HOffset, VOffset: Integer;
+ boxSize: Integer;
+ boxSize2: Integer;
begin
@@ -1307,11 +1316,25 @@ begin
else Brush.Color := FGridColor;
Pen.Color := clWhite;
+ boxSize2 := 6;
+ {$IFDEF FPC}
+ boxSize2 := Scale96ToFont(boxSize2);
+ {$ENDIF}
+ boxSize := boxSize2 div 2;
+
+ case SmallBoxPos of
+ 0: SmallBox := Rect(R.Right, R.Bottom, R.Right, R.Bottom);
+ 1: SmallBox := Rect(R.Right, R.Top + boxSize2-1, R.Right, R.Top + boxSize2-1);
+ 2: SmallBox := Rect(R.Left + boxSize2-1, R.Bottom, R.Left + boxSize2-1, R.Bottom);
+ end;
+ InflateRect(SmallBox, boxSize, boxSize);
+ {
case SmallBoxPos of
0: SmallBox := Rect(R.Right - 3, R.Bottom - 3, R.Right + 3, R.Bottom + 3);
1: SmallBox := Rect(R.Right - 3, R.Top - 3 + 5, R.Right + 3, R.Top + 3 + 5);
2: SmallBox := Rect(R.Left - 3 + 5, R.Bottom - 3, R.Left + 3 + 5, R.Bottom + 3);
end;
+ }
Rectangle(SmallBox);
SmallBoxPos := 0; // Reset to Right Bottom
@@ -3465,6 +3488,62 @@ begin
end;
end;
+{$IFDEF FPC}
+// Handle Lazarus' High-DPI scaling
+procedure TNiceGrid.DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
+ const AXProportion, AYProportion: Double);
+var
+ i: Integer;
+ col: TNiceColumn;
+begin
+ inherited DoAutoAdjustLayout(AMode, AXProportion, AYProportion);
+ if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
+ begin
+ FDefColWidth := round(FDefColWidth * AYProportion);
+ FDefRowHeight := round(FDefRowHeight * AYProportion);
+ FGutterWidth := round(FGutterWidth * AXProportion);
+ for i := 0 to Columns.Count-1 do
+ begin
+ col := Columns[i];
+ col.Width := round(col.Width * AXProportion);
+ end;
+ end;
+end;
+
+procedure TNiceGrid.FixDesignFontsPPI(const ADesignTimePPI: Integer);
+var
+ i: Integer;
+ col: TNiceColumn;
+begin
+ inherited;
+ DoFixDesignFontPPI(FHeaderFont, ADesignTimePPI);
+ DoFixDesignFontPPI(FGutterFont, ADesignTimePPI);
+ DoFixDesignFontPPI(FFooterFont, ADesignTimePPI);
+ for i := 0 to Columns.Count-1 do
+ begin
+ col := Columns[i];
+ DoFixDesignFontPPI(col.Font, ADesignTimePPI);
+ end;
+end;
+
+procedure TNiceGrid.ScaleFontsPPI(const AToPPI: Integer; const AProportion: Double);
+var
+ i: Integer;
+ col: TNiceColumn;
+begin
+ inherited;
+ DoScaleFontPPI(FHeaderFont, AToPPI, AProportion);
+ DoScaleFontPPI(FGutterFont, AToPPI, AProportion);
+ DoScaleFontPPI(FFooterFont, AToPPI, AProportion);
+ for i := 0 to Columns.Count-1 do
+ begin
+ col := Columns[i];
+ DoScaleFontPPI(col.Font, AToPPI, AProportion);
+ end;
+end;
+{$ENDIF}
+
+
{ TNiceColumn }
constructor TNiceColumn.Create(Collection: TCollection);