mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-08 19:38:09 +02:00
lcl: bidi mode support for buttons from Zaher Dirkey (#issue #0014933)
git-svn-id: trunk@22448 -
This commit is contained in:
parent
cbe7394663
commit
2e2fcd58fc
@ -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]);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user