Skip to content

Commit 0ec9a81

Browse files
Fixed #65: Caption for StyledBitBtn with wordwrap
1 parent fea5b95 commit 0ec9a81

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

source/Vcl.ButtonStylesAttributes.pas

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,8 @@ procedure CalcImageAndTextRect(const ASurfaceRect: TRect;
16071607
IW, IH, IX, IY: Integer;
16081608
LImageAlignment: TImageAlignment;
16091609
begin
1610+
//Calculate Image and Text Rect for Drawing using ImageAlignment and ImageMargins
1611+
//for StyledButton and StyledGraphicButton
16101612
if ACaption = '' then
16111613
LImageAlignment := iaCenter
16121614
else
@@ -1722,6 +1724,8 @@ procedure CalcImageAndTextRect(const ACanvas: TCanvas;
17221724
LLayout: TButtonLayout;
17231725
LMargin, LSpacing: Integer;
17241726
begin
1727+
//Calculate Image and Text Rect for Drawing using ButtonLayout, Margin and Spacing
1728+
//For StyledSpeedButton and StyledBitBtn
17251729
LLayout := ALayout;
17261730
if (ABiDiFlags and DT_RIGHT) = DT_RIGHT then
17271731
begin
@@ -1835,7 +1839,8 @@ procedure CalcImageAndTextRect(const ACanvas: TCanvas;
18351839
Inc(AGlyphPos.X, ASurfaceRect.Left + AOffset.X);
18361840
Inc(AGlyphPos.Y, ASurfaceRect.Top + AOffset.Y);
18371841

1838-
OffsetRect(ATextBounds, LTextPos.X + ASurfaceRect.Left + AOffset.X, LTextPos.Y + ASurfaceRect.Top + AOffset.Y);
1842+
OffsetRect(ATextBounds, LTextPos.X + ASurfaceRect.Left + AOffset.X,
1843+
LTextPos.Y + ASurfaceRect.Top + AOffset.Y);
18391844
end;
18401845

18411846
procedure DrawIconFromCommandLinkRes(ACanvas: TCanvas; ARect: TRect;
@@ -2044,7 +2049,7 @@ procedure DrawButtonText(const ACanvas: TCanvas;
20442049
const PreserveBorders: Boolean = True);
20452050
var
20462051
R: TRect;
2047-
OldBKMode: Integer;
2052+
LOldBKMode: Integer;
20482053
begin
20492054
(* for test
20502055
ACanvas.Brush.Color := clYellow;
@@ -2065,7 +2070,7 @@ procedure DrawButtonText(const ACanvas: TCanvas;
20652070
else
20662071
OffsetRect(R, (ARect.Width - R.Width) div 2, (ARect.Height - R.Height) div 2);
20672072
end;
2068-
OldBKMode := SetBkMode(ACanvas.Handle, Winapi.Windows.TRANSPARENT);
2073+
LOldBKMode := SetBkMode(ACanvas.Handle, Winapi.Windows.TRANSPARENT);
20692074
try
20702075
if PreserveBorders then
20712076
begin
@@ -2075,13 +2080,13 @@ procedure DrawButtonText(const ACanvas: TCanvas;
20752080
R.Top := ARect.Top + ABorderWidth + ASpacing ;
20762081
if R.Bottom > ARect.Bottom - ABorderWidth - Aspacing then
20772082
R.Bottom := ARect.Bottom - ABorderWidth - Aspacing;
2078-
(* for test
2079-
ACanvas.Brush.Color := clRed;
2080-
ACanvas.FillRect(R);
2081-
ACanvas.Pen.Color := clBlue;
2082-
ACanvas.Pen.Width := 1;
2083-
ACanvas.Rectangle(R);
2084-
*)
2083+
(* for test
2084+
ACanvas.Brush.Color := clRed;
2085+
ACanvas.FillRect(R);
2086+
ACanvas.Pen.Color := clBlue;
2087+
ACanvas.Pen.Width := 1;
2088+
ACanvas.Rectangle(R);
2089+
*)
20852090
Winapi.Windows.DrawText(ACanvas.Handle, PChar(AText),
20862091
Length(AText), R, ABidiFlags or DT_END_ELLIPSIS);
20872092
end
@@ -2097,7 +2102,7 @@ procedure DrawButtonText(const ACanvas: TCanvas;
20972102
Length(AText), R, ABidiFlags);
20982103
end;
20992104
finally
2100-
SetBkMode(ACanvas.Handle, OldBKMode);
2105+
SetBkMode(ACanvas.Handle, LOldBKMode);
21012106
end;
21022107
end;
21032108

source/Vcl.StyledButton.pas

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ TStyledBitBtn = class(TCustomStyledButton)
15061506
property ModalResult;
15071507
property NotificationBadge;
15081508
property NumGlyphs;
1509-
property Style: TButtonStyle read FStyle write FStyle;
1509+
property Style: TButtonStyle read FStyle write FStyle default bsAutoDetect;
15101510
property Spacing default 4;
15111511
property TabOrder;
15121512
property TabStop;
@@ -2654,6 +2654,7 @@ procedure TStyledButtonRender.DrawCaptionAndImage(const ACanvas: TCanvas;
26542654
LUseImageList: Boolean;
26552655
LGlyphPos: TPoint;
26562656
LCaption: TCaption;
2657+
LOldBKMode, LMaxBorderWidth: Integer;
26572658
begin
26582659
if FShowCaption then
26592660
LCaption := GetCaptionToDraw
@@ -2785,8 +2786,24 @@ procedure TStyledButtonRender.DrawCaptionAndImage(const ACanvas: TCanvas;
27852786
end;
27862787
end
27872788
else
2788-
DrawButtonText(ACanvas, LCaption, FCaptionAlignment, FSpacing, CalcMaxBorderWidth,
2789-
LTextRect, LTextFlags);
2789+
begin
2790+
LMaxBorderWidth := CalcMaxBorderWidth;
2791+
if FUseButtonLayout then
2792+
begin
2793+
LOldBKMode := SetBkMode(ACanvas.Handle, Winapi.Windows.TRANSPARENT);
2794+
try
2795+
Winapi.Windows.DrawText(ACanvas.Handle, PChar(LCaption),
2796+
Length(LCaption), LTextRect, LTextFlags or DT_END_ELLIPSIS);
2797+
finally
2798+
SetBkMode(ACanvas.Handle, LOldBKMode);
2799+
end;
2800+
end
2801+
else
2802+
begin
2803+
DrawButtonText(ACanvas, LCaption, FCaptionAlignment, FSpacing, LMaxBorderWidth,
2804+
LTextRect, LTextFlags);
2805+
end;
2806+
end;
27902807
end;
27912808

27922809
procedure TStyledButtonRender.DrawButton(const ACanvas: TCanvas;
@@ -6311,6 +6328,7 @@ procedure TCustomStyledButton.WMPaint(var Message: TMessage);
63116328
constructor TStyledBitBtn.Create(AOwner: TComponent);
63126329
begin
63136330
inherited Create(AOwner);
6331+
FStyle := bsAutoDetect;
63146332
FRender.FUseButtonLayout := True;
63156333
FRender.Spacing := 4;
63166334
end;

0 commit comments

Comments
 (0)