NiceSideBar: Fix crash when an image list used several times in the component is deleted in the form designer. Beginning to support high-dpi.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8856 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-06-26 09:36:47 +00:00
parent b2f0c3f051
commit 45880ce30c
2 changed files with 64 additions and 18 deletions

View File

@ -9,7 +9,7 @@ object Form1: TForm1
ClientWidth = 623
Color = clWhite
Position = poDesktopCenter
LCLVersion = '2.3.0.0'
LCLVersion = '3.99.0.0'
object Shape1: TShape
Left = 0
Height = 113
@ -271,6 +271,7 @@ object Form1: TForm1
TabOrder = 8
end
object ImageList1: TImageList
Scaled = True
Left = 240
Top = 136
Bitmap = {
@ -297,6 +298,7 @@ object Form1: TForm1
}
end
object ImageList2: TImageList
Scaled = True
Left = 320
Top = 136
Bitmap = {

View File

@ -39,7 +39,7 @@ interface
uses
{$IFDEF FPC}
LCLIntf, LCLType, LMessages,
LCLIntf, LCLType, LMessages, LazLoggerBase,
{$ELSE}
Windows, Messages,
{$ENDIF}
@ -322,11 +322,19 @@ type
procedure DrawNonItem(ACanvas: TCanvas; Rc: TRect); virtual;
procedure DrawScroller(ACanvas: TCanvas; Rc: TRect; Up: Boolean; Hover: Boolean); virtual;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
{$IFDEF FPC}
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy; const AXProportion, AYProportion: Double); override;
{$ENDIF}
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure BeginUpdate;
procedure EndUpdate;
{$IFDEF FPC}
procedure FixDesignFontsPPI(const ADesignTimePPI: Integer); override;
procedure ScaleFontsPPI(const AToPPI: Integer; const AProportion: Double); override;
{$ENDIF}
published
property ItemStyle: TSideBarItemStyle read FItemStyle write SetItemStyle;
property SubItemStyle: TSideBarItemStyle read FSubItemStyle write SetSubItemStyle;
@ -701,6 +709,53 @@ begin
inherited Destroy;
end;
{$IFDEF FPC}
// Handle Lazarus' High-DPI scaling
procedure TNiceSidebar.DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double);
begin
inherited;
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin
FItemHeight := round(FItemHeight * AYProportion);
FSubItemHeight := round(FSubItemHeight * AYProportion);
FMargin := round(FMargin * AXProportion);
FIndent := round(FIndent * AXProportion);
FGroupSeparator := round(FGroupSeparator * AYProportion);
end;
end;
procedure TNiceSidebar.FixDesignFontsPPI(const ADesignTimePPI: Integer);
begin
inherited;
DoFixDesignFontPPI(FItemStyle.NormalFont, ADesignTimePPI);
DoFixDesignFontPPI(FItemStyle.HoverFont, ADesignTimePPI);
DoFixDesignFontPPI(FItemStyle.SelectedFont, ADesignTimePPI);
DoFixDesignFontPPI(FItemStyle.DisabledFont, ADesignTimePPI);
DoFixDesignFontPPI(FSubItemStyle.NormalFont, ADesignTimePPI);
DoFixDesignFontPPI(FSubItemStyle.HoverFont, ADesignTimePPI);
DoFixDesignFontPPI(FSubItemStyle.SelectedFont, ADesignTimePPI);
DoFixDesignFontPPI(FSubItemStyle.DisabledFont, ADesignTimePPI);
end;
procedure TNiceSidebar.ScaleFontsPPI(const AToPPI: Integer; const AProportion: Double);
begin
inherited;
DoScaleFontPPI(FItemStyle.NormalFont, AToPPI, AProportion);
DoScaleFontPPI(FItemStyle.HoverFont, AToPPI, AProportion);
DoScaleFontPPI(FItemStyle.SelectedFont, AToPPI, AProportion);
DoScaleFontPPI(FItemStyle.DisabledFont, AToPPI, AProportion);
DoScaleFontPPI(FSubItemStyle.NormalFont, AToPPI, AProportion);
DoScaleFontPPI(FSubItemStyle.HoverFont, AToPPI, AProportion);
DoScaleFontPPI(FSubItemStyle.SelectedFont, AToPPI, AProportion);
DoScaleFontPPI(FSubItemStyle.DisabledFont, AToPPI, AProportion);
end;
{$ENDIF}
procedure TNiceSidebar.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
@ -708,9 +763,7 @@ var
P: PSBInfo;
Str: string;
Changed: Boolean;
begin
{$IFDEF FPC}
LCLIntf.SetFocus(Handle);
{$ELSE}
@ -1466,33 +1519,24 @@ procedure TNiceSideBar.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (AComponent = FImages) then
if (Operation = opRemove) then
begin
if (Operation = opRemove) then
if (AComponent = FImages) then
begin
FImages := nil;
Invalidate;
end;
end else
if (AComponent = FHoverImages) then
begin
if (Operation = opRemove) then
if (AComponent = FHoverImages) then
begin
FHoverImages := nil;
Invalidate;
end;
end else
if (AComponent = FSelectedImages) then
begin
if (Operation = opRemove) then
if (AComponent = FSelectedImages) then
begin
FSelectedImages := nil;
Invalidate;
end;
end else
if (AComponent = FDisabledImages) then
begin
if (Operation = opRemove) then
if (AComponent = FDisabledImages) then
begin
FDisabledImages := nil;
Invalidate;