SpkToolbar: Implement RTL for TSpkSmallButton.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8954 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-10-12 22:48:11 +00:00
parent 9dc50e13f7
commit c9940f44bf

View File

@ -756,6 +756,10 @@ begin
if Assigned(FDropdownMenu) then if Assigned(FDropdownMenu) then
begin begin
DropPoint := FToolbarDispatch.ClientToScreen(GetDropdownPoint); DropPoint := FToolbarDispatch.ClientToScreen(GetDropdownPoint);
if IsRightToLeft then
FDropDownMenu.BiDiMode := bdRightToLeft
else
FDropDownMenu.BiDiMode := bdLeftToRight;
FDropdownMenu.Popup(DropPoint.x, DropPoint.y); FDropdownMenu.Popup(DropPoint.x, DropPoint.y);
FButtonState := bsBtnHottrack; FButtonState := bsBtnHottrack;
if Assigned(FToolbarDispatch) then if Assigned(FToolbarDispatch) then
@ -773,6 +777,10 @@ begin
if Assigned(FDropdownMenu) then if Assigned(FDropdownMenu) then
begin begin
DropPoint := FToolbarDispatch.ClientToScreen(GetDropdownPoint); DropPoint := FToolbarDispatch.ClientToScreen(GetDropdownPoint);
if IsRightToLeft then
FDropDownMenu.BiDiMode := bdRightToLeft
else
FDropDownMenu.BiDiMode := bdLeftToRight;
FDropdownMenu.Popup(DropPoint.x, DropPoint.y); FDropdownMenu.Popup(DropPoint.x, DropPoint.y);
FButtonState := bsBtnHottrack; FButtonState := bsBtnHottrack;
if Assigned(FToolbarDispatch) then if Assigned(FToolbarDispatch) then
@ -1477,6 +1485,7 @@ var
Bitmap: TBitmap; Bitmap: TBitmap;
TextWidth: Integer; TextWidth: Integer;
AdditionalPadding: Boolean; AdditionalPadding: Boolean;
isRTL: Boolean;
begin begin
{$IFDEF EnhancedRecordSupport} {$IFDEF EnhancedRecordSupport}
BtnRect := T2DIntRect.Create(0, 0, 0, 0); BtnRect := T2DIntRect.Create(0, 0, 0, 0);
@ -1495,6 +1504,8 @@ begin
if not Assigned(Bitmap) then if not Assigned(Bitmap) then
exit; exit;
isRTL := IsRightToLeft;
// *** Regardless of the type, there must be room for the icon and / or text *** // *** Regardless of the type, there must be room for the icon and / or text ***
BtnWidth := 0; BtnWidth := 0;
@ -1569,14 +1580,26 @@ begin
else else
DropdownWidth := DropdownWidth + SmallButtonBorderWidth; DropdownWidth := DropdownWidth + SmallButtonBorderWidth;
if isRTL then
begin
{$IFDEF EnhancedRecordSupport} {$IFDEF EnhancedRecordSupport}
BtnRect := T2DIntRect.Create(0, 0, BtnWidth - 1, PaneRowHeightT - 1); DropRect := T2DIntRect.Create(0, 0, DropdownWidth - 1, PaneRowHeight - 1);
BtnRect := T2DIntRect.Create(DropRect.Right+1, 0, DropRect.Right + BtnWidth, PaneRowHeight - 1);
{$ELSE}
DropRect.Create(0, 0, DropdownWidth - 1, PaneRowHeight - 1);
BtnRect.Create(DropRect.Right+1, 0, DropRect.Right + BtnWidth, PaneRowHeight - 1);
{$ENDIF}
end else
begin
{$IFDEF EnhancedRecordSupport}
BtnRect := T2DIntRect.Create(0, 0, BtnWidth - 1, PaneRowHeight - 1);
DropRect := T2DIntRect.Create(BtnRect.Right+1, 0, BtnRect.Right+DropdownWidth, PaneRowHeight - 1); DropRect := T2DIntRect.Create(BtnRect.Right+1, 0, BtnRect.Right+DropdownWidth, PaneRowHeight - 1);
{$ELSE} {$ELSE}
BtnRect.Create(0, 0, BtnWidth - 1, PaneRowHeight - 1); BtnRect.Create(0, 0, BtnWidth - 1, PaneRowHeight - 1);
DropRect.Create(BtnRect.Right+1, 0, BtnRect.Right+DropdownWidth, PaneRowHeight - 1); DropRect.Create(BtnRect.Right+1, 0, BtnRect.Right+DropdownWidth, PaneRowHeight - 1);
{$ENDIF} {$ENDIF}
end; end;
end;
bkDropdown: bkDropdown:
begin begin
@ -1614,18 +1637,19 @@ var
gradientFromColor, gradientToColor: TColor; gradientFromColor, gradientToColor: TColor;
gradientKind: TBackgroundKind; gradientKind: TBackgroundKind;
P: T2DIntPoint; P: T2DIntPoint;
x, y: Integer; x, dx, y, w: Integer;
delta: Integer; delta: Integer;
cornerRadius: Integer; cornerRadius: Integer;
ppi, sgn: Integer;
imgList: TImageList; imgList: TImageList;
imgSize: TSize; imgSize: TSize;
drawBtn: Boolean; drawBtn: Boolean;
R: TRect; R: TRect;
dx: Integer;
ppi: Integer;
SeparatorRect: TRect; SeparatorRect: TRect;
SeparatorLineColor: TColor; SeparatorLineColor: TColor;
leftEdgeOpen, rightEdgeOpen: Boolean;
drawImgEnabled: Boolean = true; drawImgEnabled: Boolean = true;
isRTL: Boolean;
begin begin
if (FToolbarDispatch = nil) or (FAppearance = nil) then if (FToolbarDispatch = nil) or (FAppearance = nil) then
exit; exit;
@ -1649,6 +1673,9 @@ begin
if (FRect.Width < 2*SmallButtonRadius) or (FRect.Height < 2*SmallButtonRadius) then if (FRect.Width < 2*SmallButtonRadius) or (FRect.Height < 2*SmallButtonRadius) then
exit; exit;
isRTL := IsRightToLeft;
sgn := IfThen(isRTL, -1, +1);
delta := FAppearance.Element.HotTrackBrightnessChange; delta := FAppearance.Element.HotTrackBrightnessChange;
case FAppearance.Element.Style of case FAppearance.Element.Style of
esRounded: esRounded:
@ -1692,6 +1719,14 @@ begin
if drawBtn then if drawBtn then
begin begin
if isRTL then begin
rightEdgeOpen := (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]);
leftEdgeOpen := (FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown);
end else
begin
leftEdgeOpen := (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]);
rightEdgeOpen := (FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown);
end;
TButtonTools.DrawButton( TButtonTools.DrawButton(
ABuffer, ABuffer,
FButtonRect, // draw button part only FButtonRect, // draw button part only
@ -1701,8 +1736,8 @@ begin
gradientFromColor, gradientFromColor,
gradientToColor, gradientToColor,
gradientKind, gradientKind,
(FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]), leftEdgeOpen,
(FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown), rightEdgeOpen,
false, false,
false, false,
cornerRadius, cornerRadius,
@ -1728,10 +1763,11 @@ begin
imgSize := Size(imgList.Width, imgList.Height); imgSize := Size(imgList.Width, imgList.Height);
{$ENDIF} {$ENDIF}
x := IfThen(isRTL, FButtonRect.Right - imgSize.CX, FButtonRect.Left);
if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then
x := FButtonRect.Left + SmallButtonHalfBorderWidth + SmallButtonPadding inc(x, sgn * (SmallButtonHalfBorderWidth + SmallButtonPadding))
else else
x := FButtonRect.Left + SmallButtonBorderWidth + SmallButtonPadding; inc(x, sgn * (SmallButtonBorderWidth + SmallButtonPadding));
y := FButtonRect.top + (FButtonRect.height - imgSize.CY) div 2; y := FButtonRect.top + (FButtonRect.height - imgSize.CY) div 2;
P := {$IFDEF EnhancedRecordSupport}T2DIntPoint.Create{$ELSE}Create2DIntPoint{$ENDIF}(x, y); P := {$IFDEF EnhancedRecordSupport}T2DIntPoint.Create{$ELSE}Create2DIntPoint{$ENDIF}(x, y);
TGUITools.DrawImage( TGUITools.DrawImage(
@ -1767,15 +1803,19 @@ begin
ABuffer.Canvas.Font.Assign(FAppearance.Element.CaptionFont); ABuffer.Canvas.Font.Assign(FAppearance.Element.CaptionFont);
ABuffer.Canvas.Font.Color := fontColor; ABuffer.Canvas.Font.Color := fontColor;
if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then if isRTL then
x := FButtonRect.Left + SmallButtonHalfBorderWidth x := FButtonRect.Right - ABuffer.Canvas.TextWidth(FCaption)
else else
x := FButtonRect.Left + SmallButtonBorderWidth; x := FButtonRect.Left;
if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then
inc(x, sgn * SmallButtonHalfBorderWidth)
else
inc(x, sgn * SmallButtonBorderWidth);
if FImageIndex <> -1 then if FImageIndex <> -1 then
x := x + 2 * SmallButtonPadding + SmallButtonGlyphWidth inc(x, sgn * (2 * SmallButtonPadding + SmallButtonGlyphWidth))
else else
x := x + SmallButtonPadding; inc(x, sgn * SmallButtonPadding);
y := FButtonRect.Top + (FButtonRect.Height - ABuffer.Canvas.TextHeight('Wy')) div 2; y := FButtonRect.Top + (FButtonRect.Height - ABuffer.Canvas.TextHeight('Wy')) div 2;
TGUITools.DrawText(ABuffer.Canvas, x, y, FCaption, fontColor, ClipRect); TGUITools.DrawText(ABuffer.Canvas, x, y, FCaption, fontColor, ClipRect);
@ -1816,7 +1856,17 @@ begin
end else end else
drawBtn := false; drawBtn := false;
// Dropdown button
if drawBtn then begin if drawBtn then begin
if isRTL then
begin
leftEdgeOpen := (FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]);
rightEdgeOpen := true;
end else
begin
leftEdgeOpen := true;
rightEdgeOpen := (FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]);
end;
TButtonTools.DrawButton( TButtonTools.DrawButton(
ABuffer, ABuffer,
FDropdownRect, FDropdownRect,
@ -1826,8 +1876,8 @@ begin
gradientFromColor, gradientFromColor,
gradientToColor, gradientToColor,
gradientKind, gradientKind,
true, leftEdgeOpen,
(FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]), rightEdgeOpen,
false, false,
false, false,
cornerRadius, cornerRadius,
@ -1844,10 +1894,19 @@ begin
else else
inc(dx, SmallButtonBorderWidth); inc(dx, SmallButtonBorderWidth);
if FButtonKind = bkDropdown then if FButtonKind = bkDropdown then
R := Classes.Rect(FButtonRect.Right-dx, FButtonRect.Top, FButtonRect.Right, FButtonRect.Bottom) begin
if isRTL then
R := Classes.Rect(FButtonRect.Left+1, FButtonRect.Top, FButtonRect.Left+dx, FButtonRect.Bottom)
else
R := Classes.Rect(FButtonRect.Right-dx, FButtonRect.Top, FButtonRect.Right, FButtonRect.Bottom);
end else
begin
if isRTL then
R := Classes.Rect(FDropDownRect.Left+1, FDropDownRect.Top, FDropDownRect.Left+dx, FDropDownRect.Bottom)
else else
R := Classes.Rect(FDropdownRect.Right-dx, FDropdownRect.Top, FDropdownRect.Right, FDropdownRect.Bottom); R := Classes.Rect(FDropdownRect.Right-dx, FDropdownRect.Top, FDropdownRect.Right, FDropdownRect.Bottom);
DrawdropdownArrow(ABuffer, R, fontcolor); end;
DrawDropdownArrow(ABuffer, R, fontcolor);
end; end;
end; end;
@ -1901,8 +1960,12 @@ begin
ConstructRects(BtnRect, DropRect); ConstructRects(BtnRect, DropRect);
if FButtonKind = bkButtonDropdown then if FButtonKind = bkButtonDropdown then
Result := DropRect.Right+1 begin
if IsRightToLeft then
Result := BtnRect.Right + 1
else else
Result := DropRect.Right + 1;
end else
Result := BtnRect.Right+1; Result := BtnRect.Right+1;
end; end;