mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-28 10:02:14 +00:00
FIX: Memory leaks with bitmaps.
This commit is contained in:
parent
917c493185
commit
4cac366dde
4 changed files with 1160 additions and 1074 deletions
|
|
@ -93,25 +93,24 @@ function TKASBarMenu.LoadBtnIcon(IconPath: String): TBitMap;
|
|||
var
|
||||
PNG : TPortableNetworkGraphic;
|
||||
begin
|
||||
Result := nil;
|
||||
if IconPath <> '' then
|
||||
if FileExists(IconPath) then
|
||||
Result := Graphics.TBitmap.Create;
|
||||
if (IconPath <> '') and FileExists(IconPath) then
|
||||
begin
|
||||
if CompareFileExt(IconPath, 'png', false) = 0 then
|
||||
begin
|
||||
PNG := TPortableNetworkGraphic.Create;
|
||||
PNG.LoadFromFile(IconPath);
|
||||
Result := TBitMap(PNG);
|
||||
exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result := TBitMap.Create;
|
||||
Result.LoadFromFile(IconPath);
|
||||
exit;
|
||||
end;
|
||||
if CompareFileExt(IconPath, 'png', false) = 0 then
|
||||
begin
|
||||
PNG := TPortableNetworkGraphic.Create;
|
||||
try
|
||||
PNG.LoadFromFile(IconPath);
|
||||
Result.Assign(PNG);
|
||||
finally
|
||||
FreeAndNil(PNG);
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result.LoadFromFile(IconPath);
|
||||
end;
|
||||
end;
|
||||
Result := TBitMap.Create;
|
||||
end;
|
||||
|
||||
procedure TKASBarMenu.MenuOnClick(Sender: TObject);
|
||||
|
|
|
|||
|
|
@ -204,7 +204,8 @@ if (index>=XButtons.Count) or (Index<0) then Exit;
|
|||
end;
|
||||
|
||||
procedure TKAStoolBar.SetButtonX(Index: integer; What: Tinfor; Value: string);
|
||||
//var
|
||||
var
|
||||
BitmapTmp: TBitmap = nil;
|
||||
// PNG : TPortableNetworkGraphic;
|
||||
begin
|
||||
//if Index<0 then Exit;
|
||||
|
|
@ -214,10 +215,20 @@ If Index>=XButtons.Count then XButtons.Add(TKButton.Create);
|
|||
case What of
|
||||
ButtonX: begin
|
||||
with TSpeedButton(FButtonsList.Items[Index]) do
|
||||
if Assigned(FOnLoadButtonGlyph) then
|
||||
Glyph := FOnLoadButtonGlyph(Value, FIconSize, Color)
|
||||
else
|
||||
Glyph := LoadBtnIcon(Value);
|
||||
begin
|
||||
try
|
||||
if Assigned(FOnLoadButtonGlyph) then
|
||||
BitmapTmp := FOnLoadButtonGlyph(Value, FIconSize, Color)
|
||||
else
|
||||
BitmapTmp := LoadBtnIcon(Value);
|
||||
|
||||
Glyph := BitmapTmp; // Copy bitmap.
|
||||
|
||||
finally
|
||||
if Assigned(BitmapTmp) then
|
||||
FreeAndNil(BitmapTmp);
|
||||
end;
|
||||
end;
|
||||
TKButton(XButtons.Items[Index]).ButtonX:=Value;
|
||||
end;
|
||||
cmdX:TKButton(XButtons.Items[Index]).cmdX:=Value;
|
||||
|
|
@ -316,8 +327,13 @@ begin
|
|||
if CompareFileExt(IconPath, 'png', false) = 0 then
|
||||
begin
|
||||
PNG := TPortableNetworkGraphic.Create;
|
||||
PNG.LoadFromFile(IconPath);
|
||||
Result := TBitMap(PNG);
|
||||
try
|
||||
PNG.LoadFromFile(IconPath);
|
||||
Result := Graphics.TBitmap.Create;
|
||||
Result.Assign(PNG);
|
||||
finally
|
||||
FreeAndNil(PNG);
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
|
|
@ -584,6 +600,7 @@ function TKAStoolBar.AddButton(sCaption, Cmd, BtnHint, IconPath : String) : Inte
|
|||
var
|
||||
ToolButton: TSpeedButton;
|
||||
I:Integer;
|
||||
Bitmap: TBitmap = nil;
|
||||
begin
|
||||
// lock on resize handler
|
||||
FLockResize := True;
|
||||
|
|
@ -628,11 +645,15 @@ begin
|
|||
|
||||
ToolButton.Flat := FFlatButtons;
|
||||
|
||||
with ToolButton do
|
||||
if Assigned(FOnLoadButtonGlyph) then
|
||||
Glyph := FOnLoadButtonGlyph(IconPath, FIconSize, Color)
|
||||
Bitmap := FOnLoadButtonGlyph(IconPath, FIconSize, ToolButton.Color)
|
||||
else
|
||||
Glyph := LoadBtnIcon(IconPath);
|
||||
Bitmap := LoadBtnIcon(IconPath);
|
||||
|
||||
ToolButton.Glyph := Bitmap;
|
||||
|
||||
if Assigned(Bitmap) then
|
||||
FreeAndNil(Bitmap);
|
||||
|
||||
ToolButton.OnClick:=TNotifyEvent(@ToolButtonClick);
|
||||
|
||||
|
|
|
|||
|
|
@ -1005,6 +1005,7 @@ var
|
|||
dskPanel : TKASToolBar;
|
||||
FrameFilePanel : TFrameFilePanel;
|
||||
btnDrive : TSpeedButton;
|
||||
BitmapTmp: Graphics.TBitmap;
|
||||
begin
|
||||
dskPanel := (Sender as TKASToolBar);
|
||||
|
||||
|
|
@ -1054,7 +1055,10 @@ begin
|
|||
dskPanel.Tag := NumberOfButton;
|
||||
btnDrive.Tag:= NumberOfButton;
|
||||
|
||||
btnDrive.Glyph := PixMapManager.GetDriveIcon(PDrive(DrivesList[NumberOfButton]), btnDrive.Height - 4, btnDrive.Color);
|
||||
BitmapTmp := PixMapManager.GetDriveIcon(PDrive(DrivesList[NumberOfButton]), btnDrive.Height - 4, btnDrive.Color);
|
||||
btnDrive.Glyph := BitmapTmp;
|
||||
if Assigned(BitmapTmp) then
|
||||
FreeAndNil(BitmapTmp);
|
||||
btnDrive.Caption := dskRight.Buttons[NumberOfButton].Caption;
|
||||
end
|
||||
else
|
||||
|
|
@ -2666,7 +2670,7 @@ begin
|
|||
begin
|
||||
if MatchesMaskList(PDrive(DrivesList.Items[I])^.Name, gDriveBlackList) then
|
||||
DrivesList.Delete(I);
|
||||
end;
|
||||
end;
|
||||
// create drives drop down menu
|
||||
CreateDrivesMenu;
|
||||
// delete all disk buttons
|
||||
|
|
@ -2682,6 +2686,7 @@ var
|
|||
I, Count : Integer;
|
||||
Drive : PDrive;
|
||||
miTmp : TMenuItem;
|
||||
BitmapTmp: Graphics.TBitmap;
|
||||
begin
|
||||
pmDrivesMenu.Items.Clear;
|
||||
btnLeftDrive.Caption := '';
|
||||
|
|
@ -2702,7 +2707,10 @@ begin
|
|||
begin
|
||||
if Pos(LowerCase(Path), LowerCase(FrameLeft.pnlFile.ActiveDir)) = 1 then
|
||||
begin
|
||||
btnLeftDrive.Glyph := PixMapManager.GetDriveIcon(Drive, btnLeftDrive.Height - 4, btnLeftDrive.Color);
|
||||
BitmapTmp := PixMapManager.GetDriveIcon(Drive, btnLeftDrive.Height - 4, btnLeftDrive.Color);
|
||||
btnLeftDrive.Glyph := BitmapTmp;
|
||||
if Assigned(BitmapTmp) then
|
||||
FreeAndNil(BitmapTmp);
|
||||
btnLeftDrive.Caption := Name;
|
||||
btnLeftDrive.Width := btnLeftDrive.Glyph.Width + btnLeftDrive.Canvas.TextWidth(btnLeftDrive.Caption) + 16;
|
||||
btnLeftDrive.Tag:= I;
|
||||
|
|
@ -2710,7 +2718,10 @@ begin
|
|||
end;
|
||||
if Pos(LowerCase(Path), LowerCase(FrameRight.pnlFile.ActiveDir)) = 1 then
|
||||
begin
|
||||
btnRightDrive.Glyph := PixMapManager.GetDriveIcon(Drive, btnRightDrive.Height - 4, btnRightDrive.Color);
|
||||
BitmapTmp := PixMapManager.GetDriveIcon(Drive, btnRightDrive.Height - 4, btnRightDrive.Color);
|
||||
btnRightDrive.Glyph := BitmapTmp;
|
||||
if Assigned(BitmapTmp) then
|
||||
FreeAndNil(BitmapTmp);
|
||||
btnRightDrive.Caption := Name;
|
||||
btnRightDrive.Width := btnRightDrive.Glyph.Width + btnRightDrive.Canvas.TextWidth(btnRightDrive.Caption) + 16;
|
||||
btnRightDrive.Tag:= I;
|
||||
|
|
@ -2719,7 +2730,11 @@ begin
|
|||
end;
|
||||
|
||||
// get disk icon
|
||||
miTmp.Bitmap := PixMapManager.GetDriveIcon(Drive, 16, clMenu);
|
||||
BitmapTmp := PixMapManager.GetDriveIcon(Drive, 16, clMenu);
|
||||
miTmp.Bitmap := BitmapTmp;
|
||||
if Assigned(BitmapTmp) then
|
||||
FreeAndNil(BitmapTmp);
|
||||
|
||||
miTmp.RadioItem := True;
|
||||
miTmp.AutoCheck := True;
|
||||
miTmp.GroupIndex := 1;
|
||||
|
|
@ -2730,6 +2745,8 @@ begin
|
|||
end;
|
||||
|
||||
procedure TfrmMain.DrivesMenuClick(Sender: TObject);
|
||||
var
|
||||
BitmapTmp: Graphics.TBitmap;
|
||||
begin
|
||||
with Sender as TMenuItem do
|
||||
begin
|
||||
|
|
@ -2744,7 +2761,10 @@ begin
|
|||
dskLeft.Tag := Tag;
|
||||
FrameLeft.pnlFile.LoadPanel;
|
||||
SetActiveFrame(fpLeft);
|
||||
btnLeftDrive.Glyph := PixMapManager.GetDriveIcon(PDrive(DrivesList[Tag]), btnLeftDrive.Height - 4, btnLeftDrive.Color);
|
||||
BitmapTmp := PixMapManager.GetDriveIcon(PDrive(DrivesList[Tag]), btnLeftDrive.Height - 4, btnLeftDrive.Color);
|
||||
btnLeftDrive.Glyph := BitmapTmp;
|
||||
if Assigned(BitmapTmp) then
|
||||
FreeAndNil(BitmapTmp);
|
||||
btnLeftDrive.Caption := Caption;
|
||||
btnLeftDrive.Width := btnLeftDrive.Glyph.Width + btnLeftDrive.Canvas.TextWidth(btnLeftDrive.Caption) + 16;
|
||||
btnLeftDrive.Tag:= Tag;
|
||||
|
|
@ -2757,7 +2777,10 @@ begin
|
|||
dskRight.Tag := Tag;
|
||||
FrameRight.pnlFile.LoadPanel;
|
||||
SetActiveFrame(fpRight);
|
||||
btnRightDrive.Glyph := PixMapManager.GetDriveIcon(PDrive(DrivesList[Tag]), btnRightDrive.Height - 4, btnRightDrive.Color);
|
||||
BitmapTmp := PixMapManager.GetDriveIcon(PDrive(DrivesList[Tag]), btnRightDrive.Height - 4, btnRightDrive.Color);
|
||||
btnRightDrive.Glyph := BitmapTmp;
|
||||
if Assigned(BitmapTmp) then
|
||||
FreeAndNil(BitmapTmp);
|
||||
btnRightDrive.Caption := Caption;
|
||||
btnRightDrive.Width := btnRightDrive.Glyph.Width + btnRightDrive.Canvas.TextWidth(btnRightDrive.Caption) + 16;
|
||||
btnRightDrive.Tag:= Tag;
|
||||
|
|
@ -2791,6 +2814,7 @@ procedure TfrmMain.CreateDiskPanel(dskPanel: TKASToolBar);
|
|||
var
|
||||
I, Count : Integer;
|
||||
Drive : PDrive;
|
||||
BitmapTmp: Graphics.TBitmap;
|
||||
begin
|
||||
//dskPanel.InitBounds; // Update information
|
||||
|
||||
|
|
@ -2823,7 +2847,10 @@ begin
|
|||
{/Set chosen drive}
|
||||
|
||||
// get drive icon
|
||||
dskPanel.Buttons[I].Glyph := PixMapManager.GetDriveIcon(Drive, dskPanel.ButtonGlyphSize, dskPanel.Buttons[I].Color);
|
||||
BitmapTmp := PixMapManager.GetDriveIcon(Drive, dskPanel.ButtonGlyphSize, dskPanel.Buttons[I].Color);
|
||||
dskPanel.Buttons[I].Glyph := BitmapTmp;
|
||||
if Assigned(BitmapTmp) then
|
||||
FreeAndNil(BitmapTmp);
|
||||
{Set Buttons Transparent. Is need? }
|
||||
dskPanel.Buttons[I].Glyph.Transparent := True;
|
||||
dskPanel.Buttons[I].Transparent := True;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue