1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00

PngComponents V1.9.0

Source commit: 53b9aa78730ab3ec06ff8c73dfa0be6d8506c411
This commit is contained in:
Martin Prikryl
2022-06-20 12:13:52 +00:00
parent 69d822193b
commit 38c2b63167
4 changed files with 37 additions and 23 deletions

View File

@@ -51,6 +51,9 @@ implementation
uses
ActnList, Themes, PngButtonFunctions, PngImageList;
const
WordBreakFlag: array[Boolean] of Integer = (DT_SINGLELINE, DT_WORDBREAK);
{$IF RTLVersion < 23.0 }
type
TThemeServicesHelper = class helper for TThemeServices
@@ -178,7 +181,9 @@ var
Flags: Cardinal;
Button: TThemedButton;
Details: TThemedElementDetails;
dtFlags: Integer;
begin
dtFlags := DrawTextBiDiModeFlags(0) or WordBreakFlag[WordWrap];
R := ClientRect;
FCanvas.Handle := Message.DrawItemStruct^.hDC;
FCanvas.Font := Self.Font;
@@ -239,7 +244,7 @@ begin
//Calculate the position of the PNG glyph
CalcButtonLayout(FCanvas, FPngImage, ClientRect, IsDown, False, Caption,
Layout, Margin, Spacing, GlyphPos, TextPos, DrawTextBiDiModeFlags(0));
Layout, Margin, Spacing, GlyphPos, TextPos, dtFlags);
//Draw the image
if (FPngImage <> nil) and (Kind = bkCustom) and not FPngImage.Empty then begin
@@ -258,14 +263,12 @@ begin
if not Enabled then begin
OffsetRect(PaintRect, 1, 1);
FCanvas.Font.Color := clBtnHighlight;
DrawText(FCanvas.Handle, PChar(Caption), -1, PaintRect,
DrawTextBiDiModeFlags(0) or DT_TOP or DT_LEFT or DT_SINGLELINE);
DrawText(FCanvas.Handle, PChar(Caption), -1, PaintRect, DT_TOP or DT_LEFT or dtFlags);
OffsetRect(PaintRect, -1, -1);
FCanvas.Font.Color := clBtnShadow;
end;
DrawText(FCanvas.Handle, PChar(Caption), -1, PaintRect,
DrawTextBiDiModeFlags(0) or DT_TOP or DT_LEFT or DT_SINGLELINE);
DrawText(FCanvas.Handle, PChar(Caption), -1, PaintRect, DT_TOP or DT_LEFT or dtFlags);
end;
//Draw the focus rectangle
@@ -305,18 +308,18 @@ end;
{$IF RTLVersion >= 24.0 }
procedure TPngBitBtnStyleHook.DrawButton(ACanvas: TCanvas;
AMouseInControl: Boolean);
const
WordBreakFlag: array[Boolean] of Integer = (0, DT_WORDBREAK);
var
Details: TThemedElementDetails;
DrawRect, PaintRect, TextRect: TRect;
State: TButtonState;
btn : TPngBitBtn;
dtFlags: Integer;
GlyphPos, TextPos: TPoint;
LColor: TColor;
LFormats: TTextFormat;
begin
dtFlags := btn.DrawTextBiDiModeFlags(0) or WordBreakFlag[btn.WordWrap];
if not (Control is TPngBitBtn) then
begin
inherited;
@@ -343,7 +346,7 @@ begin
//Calculate the position of the PNG glyph
CalcButtonLayout(ACanvas, btn.FPngImage, btn.ClientRect, FPressed, False, btn.Caption,
btn.Layout, btn.Margin, btn.Spacing, GlyphPos, TextPos, btn.DrawTextBiDiModeFlags(0));
btn.Layout, btn.Margin, btn.Spacing, GlyphPos, TextPos, dtFlags);
//Draw the image
if (btn.FPngImage <> nil) and (btn.Kind = bkCustom) and not btn.FPngImage.Empty then begin
@@ -363,13 +366,11 @@ begin
else
LColor := ACanvas.Font.Color;
LFormats := TTextFormatFlags(DT_NOCLIP or DT_CENTER or DT_VCENTER
or btn.DrawTextBiDiModeFlags(0) or WordBreakFlag[btn.WordWrap]);
LFormats := TTextFormatFlags(DT_NOCLIP or DT_CENTER or DT_VCENTER or dtFlags);
if Length(btn.Caption) > 0 then begin
TextRect := Rect(0, 0, btn.ClientRect.Right - btn.ClientRect.Left, 0);
DrawText(ACanvas.Handle, PChar(btn.Caption), Length(btn.Caption), TextRect,
DT_CALCRECT or btn.DrawTextBiDiModeFlags(0));
DrawText(ACanvas.Handle, PChar(btn.Caption), Length(btn.Caption), TextRect, DT_CALCRECT or dtFlags);
end
else begin
TextRect := Rect(0, 0, 0, 0);

View File

@@ -518,6 +518,6 @@ initialization
TPicture.RegisterFileFormat('', '', TPNGObject);
finalization
TPicture.UnregisterGraphicClass(TPNGObject);
{$IFEND}
{$ENDIF}
{$IFEND}
end.

View File

@@ -10,9 +10,14 @@ uses
Windows, Classes, SysUtils, Controls, Graphics, ImgList,
{$IF CompilerVersion >= 34.0 Delphi 10.4 }
System.UITypes,
{$ENDIF}
{$IFEND}
PngImage, PngFunctions;
{$IF CompilerVersion < 34.0 Delphi 10.4 }
type
TImageName = type string;
{$IFEND}
type
INameMapping = interface
['{38EECDD8-7440-4EA2-BFD0-424E5BB2C1D5}']
@@ -70,7 +75,7 @@ type
{$IF CompilerVersion >= 34.0 Delphi 10.4 Sydney }
function AddDisabledImage(Value: TCustomImageList; Index: Integer): Integer; virtual;
procedure AddDisabledImages(Value: TCustomImageList); virtual;
{$ENDIF}
{$IFEND}
procedure Assign(Source: TPersistent); override;
procedure BeginUpdate;
procedure Clear; virtual;
@@ -89,12 +94,14 @@ type
procedure ReplaceMasked(Index: Integer; NewImage: TBitmap; MaskColor: TColor); virtual;
{$IF CompilerVersion >= 34.0 Delphi 10.4 }
function IsImageNameAvailable: Boolean; override;
function GetIndexByName(const AName: TImageName): TImageIndex; override;
function GetNameByIndex(AIndex: TImageIndex): TImageName; override;
{$ENDIF}
{$IFEND}
function GetIndexByName(const AName: TImageName): TImageIndex; {$IF CompilerVersion >= 34.0 Delphi 10.4 }override;{$IFEND}
function GetNameByIndex(AIndex: TImageIndex): TImageName; {$IF CompilerVersion >= 34.0 Delphi 10.4 }override;{$IFEND}
property ImageName[Index: Integer]: string read GetImageName;
published
{$IF CompilerVersion >= 20.0 Delphi 2009 }
property ColorDepth default cd32Bit;
{$IFEND}
property EnabledImages: Boolean read FEnabledImages write SetEnabledImages default True;
property Height read GetHeight write SetHeight default 16;
property ImageNameAvailable: Boolean read FImageNameAvailable write FImageNameAvailable default False;
@@ -260,7 +267,7 @@ begin
SetLength(Pointers, 17);
{$ELSE}
SetLength(Pointers, 15);
{$ENDIF}
{$IFEND}
Pointers[0] := Combo(@TCustomImageList.Add, @TPngImageList.Add, 'Add');
Pointers[1] := Combo(@TCustomImageList.AddIcon, @TPngImageList.AddIcon, 'AddIcon');
Pointers[2] := Combo(@TCustomImageList.AddImage, @TPngImageList.AddImage, 'AddImage');
@@ -279,7 +286,7 @@ begin
{$IF CompilerVersion >= 34.0 Delphi 10.4 Sydney }
Pointers[15] := Combo(@TCustomImageList.AddDisabledImage, @TPngImageList.AddDisabledImage, 'AddDisabledImage');
Pointers[16] := Combo(@TCustomImageList.AddDisabledImages, @TPngImageList.AddDisabledImages, 'AddDisabledImages');
{$ENDIF}
{$IFEND}
MethodPatches := TObjectList.Create;
for I := Low(Pointers) to High(Pointers) do begin
@@ -393,9 +400,11 @@ begin
inherited Create(AOwner);
{$IF CompilerVersion >= 33.0 Delphi 10.3 Rio }
StoreBitmap := False;
{$ENDIF}
{$IFEND}
FImageNameAvailable := False;
{$IF CompilerVersion >= 20.0 Delphi 2009 }
ColorDepth := cd32Bit;
{$IFEND}
if ImageListCount = 0 then
ApplyMethodPatches;
Inc(ImageListCount);
@@ -636,7 +645,7 @@ begin
end;
end;
end;
{$ENDIF}
{$IFEND}
function TPngImageList.AddMasked(Image: TBitmap; MaskColor: TColor): Integer;
var
@@ -683,9 +692,11 @@ begin
end;
end;
{$IF CompilerVersion >= 20.0 Delphi 2009 }
if Source is TCustomImageList then begin
ColorDepth := TCustomImageList(Source).ColorDepth;
end;
{$IFEND}
inherited;
end;
@@ -893,6 +904,7 @@ function TPngImageList.IsImageNameAvailable: Boolean;
begin
Result := FImageNameAvailable;
end;
{$IFEND}
function TPngImageList.GetIndexByName(const AName: TImageName): TImageIndex;
begin
@@ -903,7 +915,6 @@ function TPngImageList.GetNameByIndex(AIndex: TImageIndex): TImageName;
begin
Result := ImageName[AIndex];
end;
{$ENDIF}
function TPngImageList.GetWidth: Integer;
begin

View File

@@ -75,6 +75,8 @@ begin
inherited Paint;
if HasValidPng then begin
Canvas.Handle := 0;
Canvas.Font := Font;
//Calculate the position of the PNG glyph
CalcButtonLayout(Canvas, FPngImage, ClientRect, FState = bsDown, Down,
Caption, Layout, Margin, Spacing, GlyphPos, TextPos, DrawTextBiDiModeFlags(0));