From 2e2fcd58fc4a591b22b219ac4029d2f59d41584e Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 5 Nov 2009 14:35:36 +0000 Subject: [PATCH] lcl: bidi mode support for buttons from Zaher Dirkey (#issue #0014933) git-svn-id: trunk@22448 - --- lcl/buttons.pp | 27 ++++++++++++++++++++++++++ lcl/extctrls.pp | 4 ++++ lcl/include/speedbutton.inc | 10 ++++++++-- lcl/interfaces/win32/win32wsbuttons.pp | 15 ++++++++++++-- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/lcl/buttons.pp b/lcl/buttons.pp index 484ec03a66..4df7ecaaed 100644 --- a/lcl/buttons.pp +++ b/lcl/buttons.pp @@ -194,6 +194,7 @@ type property Align; property Anchors; property AutoSize; + property BidiMode; property BorderSpacing; property Cancel; property Caption; @@ -228,6 +229,7 @@ type property OnResize; property OnStartDrag; property OnUTF8KeyPress; + property ParentBidiMode; property ParentFont; property ParentShowHint; property PopupMenu; @@ -352,6 +354,7 @@ type property AllowAllUp; property Anchors; property AutoSize; + property BidiMode; property BorderSpacing; property Constraints; property Caption; @@ -380,6 +383,7 @@ type property OnChangeBounds; property ShowCaption; property ShowHint; + property ParentBidiMode; property ParentFont; property ParentShowHint; property PopupMenu; @@ -413,6 +417,7 @@ procedure LoadGlyphFromStock(AGlyph: TButtonGlyph; idButton: Integer); function GetButtonCaption(idButton: Integer): String; function GetDefaultButtonIcon(idButton: Integer): TCustomBitmap; function GetButtonIcon(idButton: Integer): TCustomBitmap; +function BidiAdjustButtonLayout(IsRightToLeft: Boolean; Layout: TButtonLayout): TButtonLayout; procedure Register; @@ -542,6 +547,28 @@ begin Result := GetDefaultButtonIcon(idButton); end; +const + BtnBidiLayout: array[Boolean, TButtonLayout] of TButtonLayout = + ( + ( + blGlyphLeft, + blGlyphRight, + blGlyphTop, + blGlyphBottom + ), + ( + blGlyphRight, + blGlyphLeft, + blGlyphTop, + blGlyphBottom + ) + ); + +function BidiAdjustButtonLayout(IsRightToLeft: Boolean; Layout: TButtonLayout): TButtonLayout; +begin + Result := BtnBidiLayout[IsRightToLeft, Layout]; +end; + procedure Register; begin RegisterComponents('Additional',[TBitBtn,TSpeedButton]); diff --git a/lcl/extctrls.pp b/lcl/extctrls.pp index 93a6a84465..280e6d8f5e 100644 --- a/lcl/extctrls.pp +++ b/lcl/extctrls.pp @@ -792,6 +792,7 @@ type property Anchors; property AutoFill; property AutoSize; + property BidiMode; property BorderSpacing; property Caption; property ChildSizing; @@ -826,6 +827,7 @@ type property OnResize; property OnStartDrag; property OnUTF8KeyPress; + property ParentBidiMode; property ParentFont; property ParentColor; property ParentShowHint; @@ -1101,6 +1103,7 @@ type property BevelInner; property BevelOuter; property BevelWidth; + property BidiMode; property BorderWidth; property BorderStyle; property Caption; @@ -1116,6 +1119,7 @@ type property Enabled; property Font; property FullRepaint; + property ParentBidiMode; property ParentColor; property ParentFont; property ParentShowHint; diff --git a/lcl/include/speedbutton.inc b/lcl/include/speedbutton.inc index 780a75375e..76515a8d64 100644 --- a/lcl/include/speedbutton.inc +++ b/lcl/include/speedbutton.inc @@ -499,6 +499,7 @@ var M, S : integer; SIndex : Longint; TMP : String; + TextFlags: Integer; begin UpdateState(false); if FGlyph = nil then exit; @@ -567,7 +568,7 @@ begin M:= Margin; end; - case Layout of + case BidiAdjustButtonLayout(UseRightToLeftReading, Layout) of blGlyphLeft : begin Offset.X:= M; Offset.Y:= (ClientSize.cy - GlyphHeight) div 2; @@ -603,8 +604,12 @@ begin Top := Top + Y; end; + TextFlags := DT_LEFT or DT_TOP; + if UseRightToLeftReading then + TextFlags := TextFlags or DT_RTLREADING; + ThemeServices.DrawText(Canvas, FLastDrawDetails, Caption, PaintRect, - DT_LEFT or DT_TOP, 0); + TextFlags, 0); end; inherited Paint; @@ -892,6 +897,7 @@ begin TXTStyle.ShowPrefix := ShowAccelChar; TXTStyle.Alignment := taLeftJustify; TXTStyle.Layout := tlTop; + TXTStyle.RightToLeft := UseRightToLeftReading; TXTStyle.SystemFont := Canvas.Font.IsDefault;//Match System Default Style DeleteAmpersands(TMP); diff --git a/lcl/interfaces/win32/win32wsbuttons.pp b/lcl/interfaces/win32/win32wsbuttons.pp index 3fa4e7d185..3dfbcf0b80 100644 --- a/lcl/interfaces/win32/win32wsbuttons.pp +++ b/lcl/interfaces/win32/win32wsbuttons.pp @@ -53,6 +53,7 @@ type WithThemeSpace: Boolean); override; class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: integer); override; + class procedure SetBiDiMode(const AWinControl: TWinControl; UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean); override; class procedure SetColor(const AWinControl: TWinControl); override; class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override; class procedure SetGlyph(const ABitBtn: TCustomBitBtn; const AValue: TButtonGlyph); override; @@ -178,6 +179,7 @@ var TextFlags: DWord; // flags for caption (enabled or disabled) glyphWidth, glyphHeight: integer; OldBitmapHandle: HBITMAP; // Handle of the provious bitmap in hdcNewBitmap + OldTextAlign: Integer; AIndex: Integer; AEffect: TGraphicsDrawEffect; TmpDC: HDC; @@ -203,6 +205,7 @@ var PaintBuffer := 0; end; OldFontHandle := SelectObject(TmpDC, BitBtn.Font.Reference.Handle); + OldTextAlign := GetTextAlign(TmpDC); // clear background: // for alpha bitmap clear it with $00000000 else make it solid color for @@ -266,6 +269,8 @@ var TextFlags := TextFlags or DSS_HIDEPREFIX; SetBkMode(TmpDC, TRANSPARENT); + if BitBtn.UseRightToLeftReading then + SetTextAlign(TmpDC, OldTextAlign or TA_RTLREADING); {$IFDEF WindowsUnicodeSupport} if UnicodeEnabledOS then begin @@ -300,7 +305,7 @@ var Rect(XDestText, YDestText, XDestText + TextSize.cx, YDestText + TextSize.cy), TextFlags, @Options); end; - + SetTextAlign(TmpDC, OldTextAlign); SelectObject(TmpDC, OldFontHandle); if PaintBuffer <> 0 then EndBufferedPaint(PaintBuffer, True); @@ -323,7 +328,7 @@ begin srcWidth := 0; srcHeight := 0; end; - BitBtnLayout := BitBtn.Layout; + BitBtnLayout := BidiAdjustButtonLayout(BitBtn.UseRightToLeftReading, BitBtn.Layout); BitBtnDC := GetDC(BitBtnHandle); hdcNewBitmap := CreateCompatibleDC(BitBtnDC); MeasureText(BitBtn, ButtonCaption, TextSize.cx, TextSize.cy); @@ -596,6 +601,12 @@ begin DrawBitBtnImage(TCustomBitBtn(AWinControl), AWinControl.Caption); end; +class procedure TWin32WSBitBtn.SetBiDiMode(const AWinControl: TWinControl; + UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar: Boolean); +begin + DrawBitBtnImage(TCustomBitBtn(AWinControl), AWinControl.Caption); +end; + class procedure TWin32WSBitBtn.SetColor(const AWinControl: TWinControl); begin if not WSCheckHandleAllocated(AWinControl, 'SetColor') then Exit;