mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-05 13:36:17 +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 Align;
|
||||||
property Anchors;
|
property Anchors;
|
||||||
property AutoSize;
|
property AutoSize;
|
||||||
|
property BidiMode;
|
||||||
property BorderSpacing;
|
property BorderSpacing;
|
||||||
property Cancel;
|
property Cancel;
|
||||||
property Caption;
|
property Caption;
|
||||||
@ -228,6 +229,7 @@ type
|
|||||||
property OnResize;
|
property OnResize;
|
||||||
property OnStartDrag;
|
property OnStartDrag;
|
||||||
property OnUTF8KeyPress;
|
property OnUTF8KeyPress;
|
||||||
|
property ParentBidiMode;
|
||||||
property ParentFont;
|
property ParentFont;
|
||||||
property ParentShowHint;
|
property ParentShowHint;
|
||||||
property PopupMenu;
|
property PopupMenu;
|
||||||
@ -352,6 +354,7 @@ type
|
|||||||
property AllowAllUp;
|
property AllowAllUp;
|
||||||
property Anchors;
|
property Anchors;
|
||||||
property AutoSize;
|
property AutoSize;
|
||||||
|
property BidiMode;
|
||||||
property BorderSpacing;
|
property BorderSpacing;
|
||||||
property Constraints;
|
property Constraints;
|
||||||
property Caption;
|
property Caption;
|
||||||
@ -380,6 +383,7 @@ type
|
|||||||
property OnChangeBounds;
|
property OnChangeBounds;
|
||||||
property ShowCaption;
|
property ShowCaption;
|
||||||
property ShowHint;
|
property ShowHint;
|
||||||
|
property ParentBidiMode;
|
||||||
property ParentFont;
|
property ParentFont;
|
||||||
property ParentShowHint;
|
property ParentShowHint;
|
||||||
property PopupMenu;
|
property PopupMenu;
|
||||||
@ -413,6 +417,7 @@ procedure LoadGlyphFromStock(AGlyph: TButtonGlyph; idButton: Integer);
|
|||||||
function GetButtonCaption(idButton: Integer): String;
|
function GetButtonCaption(idButton: Integer): String;
|
||||||
function GetDefaultButtonIcon(idButton: Integer): TCustomBitmap;
|
function GetDefaultButtonIcon(idButton: Integer): TCustomBitmap;
|
||||||
function GetButtonIcon(idButton: Integer): TCustomBitmap;
|
function GetButtonIcon(idButton: Integer): TCustomBitmap;
|
||||||
|
function BidiAdjustButtonLayout(IsRightToLeft: Boolean; Layout: TButtonLayout): TButtonLayout;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
|
|
||||||
@ -542,6 +547,28 @@ begin
|
|||||||
Result := GetDefaultButtonIcon(idButton);
|
Result := GetDefaultButtonIcon(idButton);
|
||||||
end;
|
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;
|
procedure Register;
|
||||||
begin
|
begin
|
||||||
RegisterComponents('Additional',[TBitBtn,TSpeedButton]);
|
RegisterComponents('Additional',[TBitBtn,TSpeedButton]);
|
||||||
|
@ -792,6 +792,7 @@ type
|
|||||||
property Anchors;
|
property Anchors;
|
||||||
property AutoFill;
|
property AutoFill;
|
||||||
property AutoSize;
|
property AutoSize;
|
||||||
|
property BidiMode;
|
||||||
property BorderSpacing;
|
property BorderSpacing;
|
||||||
property Caption;
|
property Caption;
|
||||||
property ChildSizing;
|
property ChildSizing;
|
||||||
@ -826,6 +827,7 @@ type
|
|||||||
property OnResize;
|
property OnResize;
|
||||||
property OnStartDrag;
|
property OnStartDrag;
|
||||||
property OnUTF8KeyPress;
|
property OnUTF8KeyPress;
|
||||||
|
property ParentBidiMode;
|
||||||
property ParentFont;
|
property ParentFont;
|
||||||
property ParentColor;
|
property ParentColor;
|
||||||
property ParentShowHint;
|
property ParentShowHint;
|
||||||
@ -1101,6 +1103,7 @@ type
|
|||||||
property BevelInner;
|
property BevelInner;
|
||||||
property BevelOuter;
|
property BevelOuter;
|
||||||
property BevelWidth;
|
property BevelWidth;
|
||||||
|
property BidiMode;
|
||||||
property BorderWidth;
|
property BorderWidth;
|
||||||
property BorderStyle;
|
property BorderStyle;
|
||||||
property Caption;
|
property Caption;
|
||||||
@ -1116,6 +1119,7 @@ type
|
|||||||
property Enabled;
|
property Enabled;
|
||||||
property Font;
|
property Font;
|
||||||
property FullRepaint;
|
property FullRepaint;
|
||||||
|
property ParentBidiMode;
|
||||||
property ParentColor;
|
property ParentColor;
|
||||||
property ParentFont;
|
property ParentFont;
|
||||||
property ParentShowHint;
|
property ParentShowHint;
|
||||||
|
@ -499,6 +499,7 @@ var
|
|||||||
M, S : integer;
|
M, S : integer;
|
||||||
SIndex : Longint;
|
SIndex : Longint;
|
||||||
TMP : String;
|
TMP : String;
|
||||||
|
TextFlags: Integer;
|
||||||
begin
|
begin
|
||||||
UpdateState(false);
|
UpdateState(false);
|
||||||
if FGlyph = nil then exit;
|
if FGlyph = nil then exit;
|
||||||
@ -567,7 +568,7 @@ begin
|
|||||||
M:= Margin;
|
M:= Margin;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
case Layout of
|
case BidiAdjustButtonLayout(UseRightToLeftReading, Layout) of
|
||||||
blGlyphLeft : begin
|
blGlyphLeft : begin
|
||||||
Offset.X:= M;
|
Offset.X:= M;
|
||||||
Offset.Y:= (ClientSize.cy - GlyphHeight) div 2;
|
Offset.Y:= (ClientSize.cy - GlyphHeight) div 2;
|
||||||
@ -603,8 +604,12 @@ begin
|
|||||||
Top := Top + Y;
|
Top := Top + Y;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TextFlags := DT_LEFT or DT_TOP;
|
||||||
|
if UseRightToLeftReading then
|
||||||
|
TextFlags := TextFlags or DT_RTLREADING;
|
||||||
|
|
||||||
ThemeServices.DrawText(Canvas, FLastDrawDetails, Caption, PaintRect,
|
ThemeServices.DrawText(Canvas, FLastDrawDetails, Caption, PaintRect,
|
||||||
DT_LEFT or DT_TOP, 0);
|
TextFlags, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
inherited Paint;
|
inherited Paint;
|
||||||
@ -892,6 +897,7 @@ begin
|
|||||||
TXTStyle.ShowPrefix := ShowAccelChar;
|
TXTStyle.ShowPrefix := ShowAccelChar;
|
||||||
TXTStyle.Alignment := taLeftJustify;
|
TXTStyle.Alignment := taLeftJustify;
|
||||||
TXTStyle.Layout := tlTop;
|
TXTStyle.Layout := tlTop;
|
||||||
|
TXTStyle.RightToLeft := UseRightToLeftReading;
|
||||||
TXTStyle.SystemFont := Canvas.Font.IsDefault;//Match System Default Style
|
TXTStyle.SystemFont := Canvas.Font.IsDefault;//Match System Default Style
|
||||||
DeleteAmpersands(TMP);
|
DeleteAmpersands(TMP);
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ type
|
|||||||
WithThemeSpace: Boolean); override;
|
WithThemeSpace: Boolean); override;
|
||||||
class procedure SetBounds(const AWinControl: TWinControl;
|
class procedure SetBounds(const AWinControl: TWinControl;
|
||||||
const ALeft, ATop, AWidth, AHeight: integer); override;
|
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 SetColor(const AWinControl: TWinControl); override;
|
||||||
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
|
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
|
||||||
class procedure SetGlyph(const ABitBtn: TCustomBitBtn; const AValue: TButtonGlyph); override;
|
class procedure SetGlyph(const ABitBtn: TCustomBitBtn; const AValue: TButtonGlyph); override;
|
||||||
@ -178,6 +179,7 @@ var
|
|||||||
TextFlags: DWord; // flags for caption (enabled or disabled)
|
TextFlags: DWord; // flags for caption (enabled or disabled)
|
||||||
glyphWidth, glyphHeight: integer;
|
glyphWidth, glyphHeight: integer;
|
||||||
OldBitmapHandle: HBITMAP; // Handle of the provious bitmap in hdcNewBitmap
|
OldBitmapHandle: HBITMAP; // Handle of the provious bitmap in hdcNewBitmap
|
||||||
|
OldTextAlign: Integer;
|
||||||
AIndex: Integer;
|
AIndex: Integer;
|
||||||
AEffect: TGraphicsDrawEffect;
|
AEffect: TGraphicsDrawEffect;
|
||||||
TmpDC: HDC;
|
TmpDC: HDC;
|
||||||
@ -203,6 +205,7 @@ var
|
|||||||
PaintBuffer := 0;
|
PaintBuffer := 0;
|
||||||
end;
|
end;
|
||||||
OldFontHandle := SelectObject(TmpDC, BitBtn.Font.Reference.Handle);
|
OldFontHandle := SelectObject(TmpDC, BitBtn.Font.Reference.Handle);
|
||||||
|
OldTextAlign := GetTextAlign(TmpDC);
|
||||||
|
|
||||||
// clear background:
|
// clear background:
|
||||||
// for alpha bitmap clear it with $00000000 else make it solid color for
|
// for alpha bitmap clear it with $00000000 else make it solid color for
|
||||||
@ -266,6 +269,8 @@ var
|
|||||||
TextFlags := TextFlags or DSS_HIDEPREFIX;
|
TextFlags := TextFlags or DSS_HIDEPREFIX;
|
||||||
|
|
||||||
SetBkMode(TmpDC, TRANSPARENT);
|
SetBkMode(TmpDC, TRANSPARENT);
|
||||||
|
if BitBtn.UseRightToLeftReading then
|
||||||
|
SetTextAlign(TmpDC, OldTextAlign or TA_RTLREADING);
|
||||||
{$IFDEF WindowsUnicodeSupport}
|
{$IFDEF WindowsUnicodeSupport}
|
||||||
if UnicodeEnabledOS then
|
if UnicodeEnabledOS then
|
||||||
begin
|
begin
|
||||||
@ -300,7 +305,7 @@ var
|
|||||||
Rect(XDestText, YDestText, XDestText + TextSize.cx, YDestText + TextSize.cy),
|
Rect(XDestText, YDestText, XDestText + TextSize.cx, YDestText + TextSize.cy),
|
||||||
TextFlags, @Options);
|
TextFlags, @Options);
|
||||||
end;
|
end;
|
||||||
|
SetTextAlign(TmpDC, OldTextAlign);
|
||||||
SelectObject(TmpDC, OldFontHandle);
|
SelectObject(TmpDC, OldFontHandle);
|
||||||
if PaintBuffer <> 0 then
|
if PaintBuffer <> 0 then
|
||||||
EndBufferedPaint(PaintBuffer, True);
|
EndBufferedPaint(PaintBuffer, True);
|
||||||
@ -323,7 +328,7 @@ begin
|
|||||||
srcWidth := 0;
|
srcWidth := 0;
|
||||||
srcHeight := 0;
|
srcHeight := 0;
|
||||||
end;
|
end;
|
||||||
BitBtnLayout := BitBtn.Layout;
|
BitBtnLayout := BidiAdjustButtonLayout(BitBtn.UseRightToLeftReading, BitBtn.Layout);
|
||||||
BitBtnDC := GetDC(BitBtnHandle);
|
BitBtnDC := GetDC(BitBtnHandle);
|
||||||
hdcNewBitmap := CreateCompatibleDC(BitBtnDC);
|
hdcNewBitmap := CreateCompatibleDC(BitBtnDC);
|
||||||
MeasureText(BitBtn, ButtonCaption, TextSize.cx, TextSize.cy);
|
MeasureText(BitBtn, ButtonCaption, TextSize.cx, TextSize.cy);
|
||||||
@ -596,6 +601,12 @@ begin
|
|||||||
DrawBitBtnImage(TCustomBitBtn(AWinControl), AWinControl.Caption);
|
DrawBitBtnImage(TCustomBitBtn(AWinControl), AWinControl.Caption);
|
||||||
end;
|
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);
|
class procedure TWin32WSBitBtn.SetColor(const AWinControl: TWinControl);
|
||||||
begin
|
begin
|
||||||
if not WSCheckHandleAllocated(AWinControl, 'SetColor') then Exit;
|
if not WSCheckHandleAllocated(AWinControl, 'SetColor') then Exit;
|
||||||
|
Loading…
Reference in New Issue
Block a user