From c9940f44bf2de6a1c1165b3b84358e9c9b01a935 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 12 Oct 2023 22:48:11 +0000 Subject: [PATCH] SpkToolbar: Implement RTL for TSpkSmallButton. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8954 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../spktoolbar/SpkToolbar/spkt_Buttons.pas | 121 +++++++++++++----- 1 file changed, 92 insertions(+), 29 deletions(-) diff --git a/components/spktoolbar/SpkToolbar/spkt_Buttons.pas b/components/spktoolbar/SpkToolbar/spkt_Buttons.pas index a84dab4fc..d83cd79db 100644 --- a/components/spktoolbar/SpkToolbar/spkt_Buttons.pas +++ b/components/spktoolbar/SpkToolbar/spkt_Buttons.pas @@ -756,6 +756,10 @@ begin if Assigned(FDropdownMenu) then begin DropPoint := FToolbarDispatch.ClientToScreen(GetDropdownPoint); + if IsRightToLeft then + FDropDownMenu.BiDiMode := bdRightToLeft + else + FDropDownMenu.BiDiMode := bdLeftToRight; FDropdownMenu.Popup(DropPoint.x, DropPoint.y); FButtonState := bsBtnHottrack; if Assigned(FToolbarDispatch) then @@ -773,6 +777,10 @@ begin if Assigned(FDropdownMenu) then begin DropPoint := FToolbarDispatch.ClientToScreen(GetDropdownPoint); + if IsRightToLeft then + FDropDownMenu.BiDiMode := bdRightToLeft + else + FDropDownMenu.BiDiMode := bdLeftToRight; FDropdownMenu.Popup(DropPoint.x, DropPoint.y); FButtonState := bsBtnHottrack; if Assigned(FToolbarDispatch) then @@ -1460,14 +1468,14 @@ begin end else begin ConstructRects(FButtonRect, FDropdownRect); - {$IFDEF EnhancedRecordSupport} + {$IFDEF EnhancedRecordSupport} RectVector := T2DIntVector.Create(FRect.Left, FRect.Top); {$ELSE} RectVector.Create(FRect.Left, FRect.Top); {$ENDIF} FButtonRect := FButtonRect + RectVector; FDropdownRect := FDropdownRect + RectVector; - end; + end; end; procedure TSpkSmallButton.ConstructRects(out BtnRect, DropRect: T2DIntRect); @@ -1477,6 +1485,7 @@ var Bitmap: TBitmap; TextWidth: Integer; AdditionalPadding: Boolean; + isRTL: Boolean; begin {$IFDEF EnhancedRecordSupport} BtnRect := T2DIntRect.Create(0, 0, 0, 0); @@ -1495,6 +1504,8 @@ begin if not Assigned(Bitmap) then exit; + isRTL := IsRightToLeft; + // *** Regardless of the type, there must be room for the icon and / or text *** BtnWidth := 0; @@ -1569,13 +1580,25 @@ begin else DropdownWidth := DropdownWidth + SmallButtonBorderWidth; - {$IFDEF EnhancedRecordSupport} - BtnRect := T2DIntRect.Create(0, 0, BtnWidth - 1, PaneRowHeightT - 1); - DropRect := T2DIntRect.Create(BtnRect.Right+1, 0, BtnRect.Right+DropdownWidth, PaneRowHeight - 1); - {$ELSE} - BtnRect.Create(0, 0, BtnWidth - 1, PaneRowHeight - 1); - DropRect.Create(BtnRect.Right+1, 0, BtnRect.Right+DropdownWidth, PaneRowHeight - 1); - {$ENDIF} + if isRTL then + begin + {$IFDEF EnhancedRecordSupport} + 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); + {$ELSE} + BtnRect.Create(0, 0, BtnWidth - 1, PaneRowHeight - 1); + DropRect.Create(BtnRect.Right+1, 0, BtnRect.Right+DropdownWidth, PaneRowHeight - 1); + {$ENDIF} + end; end; bkDropdown: @@ -1614,18 +1637,19 @@ var gradientFromColor, gradientToColor: TColor; gradientKind: TBackgroundKind; P: T2DIntPoint; - x, y: Integer; + x, dx, y, w: Integer; delta: Integer; cornerRadius: Integer; + ppi, sgn: Integer; imgList: TImageList; imgSize: TSize; drawBtn: Boolean; R: TRect; - dx: Integer; - ppi: Integer; SeparatorRect: TRect; SeparatorLineColor: TColor; + leftEdgeOpen, rightEdgeOpen: Boolean; drawImgEnabled: Boolean = true; + isRTL: Boolean; begin if (FToolbarDispatch = nil) or (FAppearance = nil) then exit; @@ -1649,6 +1673,9 @@ begin if (FRect.Width < 2*SmallButtonRadius) or (FRect.Height < 2*SmallButtonRadius) then exit; + isRTL := IsRightToLeft; + sgn := IfThen(isRTL, -1, +1); + delta := FAppearance.Element.HotTrackBrightnessChange; case FAppearance.Element.Style of esRounded: @@ -1692,6 +1719,14 @@ begin if drawBtn then 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( ABuffer, FButtonRect, // draw button part only @@ -1701,8 +1736,8 @@ begin gradientFromColor, gradientToColor, gradientKind, - (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]), - (FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown), + leftEdgeOpen, + rightEdgeOpen, false, false, cornerRadius, @@ -1728,10 +1763,11 @@ begin imgSize := Size(imgList.Width, imgList.Height); {$ENDIF} + x := IfThen(isRTL, FButtonRect.Right - imgSize.CX, FButtonRect.Left); if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then - x := FButtonRect.Left + SmallButtonHalfBorderWidth + SmallButtonPadding + inc(x, sgn * (SmallButtonHalfBorderWidth + SmallButtonPadding)) else - x := FButtonRect.Left + SmallButtonBorderWidth + SmallButtonPadding; + inc(x, sgn * (SmallButtonBorderWidth + SmallButtonPadding)); y := FButtonRect.top + (FButtonRect.height - imgSize.CY) div 2; P := {$IFDEF EnhancedRecordSupport}T2DIntPoint.Create{$ELSE}Create2DIntPoint{$ENDIF}(x, y); TGUITools.DrawImage( @@ -1767,15 +1803,19 @@ begin ABuffer.Canvas.Font.Assign(FAppearance.Element.CaptionFont); ABuffer.Canvas.Font.Color := fontColor; - if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then - x := FButtonRect.Left + SmallButtonHalfBorderWidth + if isRTL then + x := FButtonRect.Right - ABuffer.Canvas.TextWidth(FCaption) 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 - x := x + 2 * SmallButtonPadding + SmallButtonGlyphWidth + inc(x, sgn * (2 * SmallButtonPadding + SmallButtonGlyphWidth)) else - x := x + SmallButtonPadding; + inc(x, sgn * SmallButtonPadding); y := FButtonRect.Top + (FButtonRect.Height - ABuffer.Canvas.TextHeight('Wy')) div 2; TGUITools.DrawText(ABuffer.Canvas, x, y, FCaption, fontColor, ClipRect); @@ -1816,7 +1856,17 @@ begin end else drawBtn := false; + // Dropdown button 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( ABuffer, FDropdownRect, @@ -1826,8 +1876,8 @@ begin gradientFromColor, gradientToColor, gradientKind, - true, - (FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]), + leftEdgeOpen, + rightEdgeOpen, false, false, cornerRadius, @@ -1844,10 +1894,19 @@ begin else inc(dx, SmallButtonBorderWidth); if FButtonKind = bkDropdown then - R := Classes.Rect(FButtonRect.Right-dx, FButtonRect.Top, FButtonRect.Right, FButtonRect.Bottom) - else - R := Classes.Rect(FDropdownRect.Right-dx, FDropdownRect.Top, FDropdownRect.Right, FDropdownRect.Bottom); - DrawdropdownArrow(ABuffer, R, fontcolor); + 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 + R := Classes.Rect(FDropdownRect.Right-dx, FDropdownRect.Top, FDropdownRect.Right, FDropdownRect.Bottom); + end; + DrawDropdownArrow(ABuffer, R, fontcolor); end; end; @@ -1901,8 +1960,12 @@ begin ConstructRects(BtnRect, DropRect); if FButtonKind = bkButtonDropdown then - Result := DropRect.Right+1 - else + begin + if IsRightToLeft then + Result := BtnRect.Right + 1 + else + Result := DropRect.Right + 1; + end else Result := BtnRect.Right+1; end;