From 4f5800150173eac0eb06903c28cc06e3c13d36c2 Mon Sep 17 00:00:00 2001 From: paul Date: Sun, 4 Oct 2009 13:00:38 +0000 Subject: [PATCH] lcl: add BiDi mode support and Alignment for THintWindow (patch by Luiz Americo, issue #0014719) git-svn-id: trunk@22021 - --- lcl/forms.pp | 16 ++++++++++------ lcl/include/hintwindow.inc | 31 ++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/lcl/forms.pp b/lcl/forms.pp index 2508c16583..ceffaf1b7f 100644 --- a/lcl/forms.pp +++ b/lcl/forms.pp @@ -753,9 +753,11 @@ type THintWindow = class(TCustomForm) private FActivating: Boolean; - FAutoHide : Boolean; - FAutoHideTimer : TComponent; - FHideInterval : Integer; + FAlignment: TAlignment; + FAutoHide: Boolean; + FAutoHideTimer: TComponent; + FHideInterval: Integer; + function GetDrawTextFlags: Cardinal; procedure SetAutoHide(Value : Boolean); procedure AutoHideHint(Sender : TObject); procedure SetHideInterval(Value : Integer); @@ -774,8 +776,10 @@ type procedure Paint; override; class function GetControlClassDefaultSize: TPoint; override; public - property AutoHide : Boolean read FAutoHide write SetAutoHide; - property HideInterval : Integer read FHideInterval write SetHideInterval; + property Alignment: TAlignment read FAlignment write FAlignment; + property AutoHide: Boolean read FAutoHide write SetAutoHide; + property BiDiMode; + property HideInterval: Integer read FHideInterval write SetHideInterval; end; THintWindowClass = class of THintWindow; @@ -1158,7 +1162,7 @@ type procedure FreeIconHandles; procedure IconChanged(Sender: TObject); function GetControlAtMouse: TControl; - procedure SetBidiMode ( const AValue : TBiDiMode ) ; + procedure SetBidiMode(const AValue: TBiDiMode); procedure SetFlags(const AValue: TApplicationFlags); procedure SetNavigation(const AValue: TApplicationNavigationOptions); procedure SetShowButtonGlyphs(const AValue: TApplicationShowGlyphs); diff --git a/lcl/include/hintwindow.inc b/lcl/include/hintwindow.inc index ca989ac9c0..ae58d441de 100644 --- a/lcl/include/hintwindow.inc +++ b/lcl/include/hintwindow.inc @@ -35,6 +35,7 @@ begin Color := clInfoBk; Canvas.Font := Screen.HintFont; Canvas.Brush.Style := bsClear; + FAlignment := taLeftJustify; BorderStyle := bsNone; Caption := 'THintWindow'; SetInitialBounds(0,0,GetControlClassDefaultSize.X,GetControlClassDefaultSize.Y); @@ -78,6 +79,31 @@ begin end; end; +function THintWindow.GetDrawTextFlags: Cardinal; +var + EffectiveAlignment: TAlignment; +begin + Result := DT_NOPREFIX or DT_VCENTER or DT_WORDBREAK; + EffectiveAlignment := FAlignment; + if BiDiMode <> bdLeftToRight then + begin + Result := Result or DT_RTLREADING; + //change alignment if is RTL + if BiDiMode = bdRightToLeft then + begin + case FAlignment of + taLeftJustify: EffectiveAlignment := taRightJustify; + taRightJustify: EffectiveAlignment := taLeftJustify; + end; + end; + end; + case EffectiveAlignment of + taLeftJustify: Result := Result or DT_LEFT; + taCenter: Result := Result or DT_CENTER; + taRightJustify: Result := Result or DT_RIGHT; + end; +end; + procedure THintWindow.SetAutoHide(Value : Boolean); Begin FAutoHide := Value; @@ -113,9 +139,8 @@ begin DrawEdge(Canvas.Handle, ARect, BDR_RAISEDOUTER, BF_RECT); end; InflateRect(ARect, - 2 * HintBorderWidth, - 2 * HintBorderWidth); - DrawText(Canvas.GetUpdatedHandle([csFontValid]), - PChar(Caption), Length(Caption), ARect, - DT_NOPREFIX or DT_VCENTER or DT_WORDBREAK); // no DT_CENTER in Delphi according to Luiz + DrawText(Canvas.GetUpdatedHandle([csFontValid]), PChar(Caption), + Length(Caption), ARect, GetDrawTextFlags); end; class function THintWindow.GetControlClassDefaultSize: TPoint;