Browse Source

Merge branch 'bidiupdate'

Martijn Laan 2 tuần trước cách đây
mục cha
commit
11f8ed740a

+ 23 - 89
Components/BidiCtrls.pas

@@ -2,11 +2,13 @@ unit BidiCtrls;
 
 {
   Inno Setup
-  Copyright (C) 1997-2024 Jordan Russell
+  Copyright (C) 1997-2025 Jordan Russell
   Portions by Martijn Laan
   For conditions of distribution and use, see LICENSE.TXT.
 
-  RTL-capable versions of standard controls
+  Previously this unit had RTL-capable versions of standard controls
+  
+  But now standard controls are RTL-capable already, and there's not much code left here
 }
 
 interface
@@ -16,44 +18,24 @@ uses
   StdCtrls, ExtCtrls;
 
 type
-  TNewEdit = class(TEdit)
-  protected
-    procedure CreateParams(var Params: TCreateParams); override;
-  end;
+  TNewEdit = class(TEdit);
 
-  TNewMemo = class(TMemo)
-  protected
-    procedure CreateParams(var Params: TCreateParams); override;
-  end;
+  TNewMemo = class(TMemo);
 
-  TNewComboBox = class(TComboBox)
-  protected
-    procedure CreateParams(var Params: TCreateParams); override;
-  end;
+  TNewComboBox = class(TComboBox);
 
-  TNewListBox = class(TListBox)
-  protected
-    procedure CreateParams(var Params: TCreateParams); override;
-  end;
+  TNewListBox = class(TListBox);
 
   TNewButton = class(TButton)
-  protected
-    procedure CreateParams(var Params: TCreateParams); override;
+  public
+    function AdjustHeight: Integer;
   end;
 
-  TNewCheckBox = class(TCheckBox)
-  protected
-    procedure CreateParams(var Params: TCreateParams); override;
-  end;
+  TNewCheckBox = class(TCheckBox);
 
-  TNewRadioButton = class(TRadioButton)
-  protected
-    procedure CreateParams(var Params: TCreateParams); override;
-  end;
+  TNewRadioButton = class(TRadioButton);
 
   TNewLinkLabel = class(TLinkLabel)
-  protected
-    procedure CreateParams(var Params: TCreateParams); override;
   public
     function AdjustHeight: Integer;
   end;
@@ -63,7 +45,7 @@ procedure Register;
 implementation
 
 uses
-  CommCtrl, BidiUtils;
+  CommCtrl;
 
 procedure Register;
 begin
@@ -71,71 +53,23 @@ begin
     TNewButton, TNewCheckBox, TNewRadioButton]);
 end;
 
-{ TNewEdit }
-
-procedure TNewEdit.CreateParams(var Params: TCreateParams);
-begin
-  inherited;
-  SetBiDiStyles(Self, Params);
-end;
-
-{ TNewMemo }
-
-procedure TNewMemo.CreateParams(var Params: TCreateParams);
-begin
-  inherited;
-  SetBiDiStyles(Self, Params);
-end;
-
-{ TNewComboBox }
-
-procedure TNewComboBox.CreateParams(var Params: TCreateParams);
-begin
-  inherited;
-  SetBiDiStyles(Self, Params);
-end;
-
-{ TNewListBox }
-
-procedure TNewListBox.CreateParams(var Params: TCreateParams);
-begin
-  inherited;
-  SetBiDiStyles(Self, Params);
-end;
-
 { TNewButton }
 
-procedure TNewButton.CreateParams(var Params: TCreateParams); 
-begin
-  inherited;
-  SetBiDiStyles(Self, Params);
-  Params.ExStyle := Params.ExStyle and not WS_EX_RIGHT;
-end;
-
-{ TNewCheckBox }
-
-procedure TNewCheckBox.CreateParams(var Params: TCreateParams);
+function TNewButton.AdjustHeight: Integer;
 begin
-  inherited;
-  SetBiDiStyles(Self, Params);
-end;
-
-{ TNewRadioButton }
-
-procedure TNewRadioButton.CreateParams(var Params: TCreateParams);
-begin
-  inherited;
-  SetBiDiStyles(Self, Params);
+  var OldHeight := Height;
+  var IdealSize: TSize;
+  IdealSize.cx := Width;
+  IdealSize.cy := 0; { Not needed according to docs and tests, but clearing anyway }
+  if SendMessage(Handle, BCM_GETIDEALSIZE, Width, LPARAM(@IdealSize)) <> 0 then begin
+    Height := IdealSize.cy;
+    Result := Height - OldHeight;
+  end else
+    Result := 0;
 end;
 
 { TNewLinkLabel }
 
-procedure TNewLinkLabel.CreateParams(var Params: TCreateParams);
-begin
-  inherited;
-  SetBiDiStyles(Self, Params);
-end;
-
 function TNewLinkLabel.AdjustHeight: Integer;
 begin
   var OldHeight := Height;

+ 2 - 20
Components/BidiUtils.pas

@@ -2,7 +2,7 @@ unit BidiUtils;
 
 {
   Inno Setup
-  Copyright (C) 1997-2024 Jordan Russell
+  Copyright (C) 1997-2025 Jordan Russell
   Portions by Martijn Laan
   For conditions of distribution and use, see LICENSE.TXT.
 
@@ -17,13 +17,10 @@ uses
 procedure FlipControls(const AParentCtl: TWinControl);
 procedure FlipRect(var Rect: TRect; const ParentRect: TRect; const UseRightToLeft: Boolean);
 function IsParentFlipped(const AControl: TControl): Boolean;
-function IsParentRightToLeft(const AControl: TControl): Boolean;
-function SetBiDiStyles(const AControl: TControl; var AParams: TCreateParams): Boolean;
 
 var
-  { These two callbacks should be set by the caller. Inno Setup: set by the Setup.SetupForm unit: }
+  { This callback should be set by the caller. Inno Setup: set by the Setup.SetupForm unit: }
   IsParentFlippedFunc: function(AControl: TControl): Boolean;
-  IsParentRightToLeftFunc: function(AControl: TControl): Boolean;
 
 implementation
 
@@ -46,21 +43,6 @@ begin
     Result := False;
 end;
 
-function IsParentRightToLeft(const AControl: TControl): Boolean;
-begin
-  if Assigned(IsParentRightToLeftFunc) then
-    Result := IsParentRightToLeftFunc(AControl)
-  else
-    Result := False;
-end;
-
-function SetBiDiStyles(const AControl: TControl; var AParams: TCreateParams): Boolean;
-begin
-  Result := IsParentRightToLeft(AControl);
-  if Result then
-    AParams.ExStyle := AParams.ExStyle or (WS_EX_RTLREADING or WS_EX_LEFTSCROLLBAR or WS_EX_RIGHT);
-end;
-
 type
   TControlAccess = class(TControl);
 

+ 14 - 28
Components/NewCheckListBox.pas

@@ -69,7 +69,6 @@ type
     FHotIndex: Integer;
     FDisableItemStateDeletion: Integer;
     FWheelAccum: Integer;
-    FUseRightToLeft: Boolean;
     class constructor Create;
     class destructor Destroy;
     procedure UpdateThemeData(const Close, Open: Boolean);
@@ -107,7 +106,6 @@ type
     procedure WMThemeChanged(var Message: TMessage); message WM_THEMECHANGED;
     procedure WMUpdateUIState(var Message: TMessage); message WM_UPDATEUISTATE;
   protected
-    procedure CreateParams(var Params: TCreateParams); override;
     procedure CreateWnd; override;
     procedure MeasureItem(Index: Integer; var Height: Integer); override;
     procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
@@ -428,12 +426,6 @@ begin
   FCaptureIndex := -1;
 end;
 
-procedure TNewCheckListBox.CreateParams(var Params: TCreateParams);
-begin
-  inherited;
-  FUseRightToLeft := SetBiDiStyles(Self, Params);
-end;
-
 procedure TNewCheckListBox.CreateWnd;
 begin
   { TCustomListBox.CreateWnd causes a LB_RESETCONTENT message to be sent when
@@ -646,7 +638,7 @@ begin
       L := ItemStates[itemID].Level;
       if ItemStates[itemID].ItemType <> itGroup then Inc(L);
       rcItem.Left := rcItem.Left + (FCheckWidth + 2 * FOffset) * L;
-      FlipRect(rcItem, ClientRect, FUseRightToLeft);
+      FlipRect(rcItem, ClientRect, IsRightToLeft);
     end;
     { Don't let TCustomListBox.CNDrawItem draw the focus }
     if FWantTabs or
@@ -695,9 +687,7 @@ begin
     Inc(Rect.Left);
 
     if ItemState.SubItem <> '' then begin
-      DrawTextFormat := DT_CALCRECT or DT_NOCLIP or DT_NOPREFIX or DT_SINGLELINE;
-      if FUseRightToLeft then
-        DrawTextFormat := DrawTextFormat or (DT_RIGHT or DT_RTLREADING);
+      DrawTextFormat := DrawTextBiDiModeFlags(DT_CALCRECT or DT_NOCLIP or DT_NOPREFIX or DT_SINGLELINE);
       SetRectEmpty(SubItemRect);
       DrawText(Canvas.Handle, PChar(ItemState.SubItem), Length(ItemState.SubItem),
         SubItemRect, DrawTextFormat);
@@ -712,8 +702,7 @@ begin
     DrawTextFormat := DT_NOCLIP or DT_CALCRECT or DT_WORDBREAK or DT_WORD_ELLIPSIS;
     if not FWantTabs or (ItemState.ItemType = itGroup) then
       DrawTextFormat := DrawTextFormat or DT_NOPREFIX;
-    if FUseRightToLeft then
-      DrawTextFormat := DrawTextFormat or (DT_RIGHT or DT_RTLREADING);
+    DrawTextFormat := DrawTextBiDiModeFlags(DrawTextFormat);
 
     S := Items[Index]; { Passing Items[Index] directly into DrawText doesn't work on Unicode build. }
     ItemState.MeasuredHeight := DrawText(Canvas.Handle, PChar(S), Length(S), Rect, DrawTextFormat);
@@ -766,7 +755,7 @@ var
 
   function FlipX(const X: Integer): Integer;
   begin
-    if FUseRightToLeft then
+    if IsRightToLeft then
       Result := (SavedClientRect.Right - 1) - X
     else
       Result := X;
@@ -809,7 +798,7 @@ begin
 
   SavedClientRect := ClientRect;
   { Undo flipping performed by TNewCheckListBox.CNDrawItem }
-  FlipRect(Rect, SavedClientRect, FUseRightToLeft);
+  FlipRect(Rect, SavedClientRect, IsRightToLeft);
 
   ItemState := ItemStates[Index];
   UIState := SendMessage(Handle, WM_QUERYUISTATE, 0, 0);
@@ -878,7 +867,7 @@ begin
       CheckRect := Bounds(Rect.Left - (FCheckWidth + FOffset),
         Rect.Top + ((Rect.Bottom - Rect.Top - FCheckHeight) div 2),
         FCheckWidth, FCheckHeight);
-      FlipRect(CheckRect, SavedClientRect, FUseRightToLeft);
+      FlipRect(CheckRect, SavedClientRect, IsRightToLeft);
       if LStyle <> nil then begin
         var Detail: TThemedButton;
         if ItemState.State <> cbGrayed then begin
@@ -936,7 +925,7 @@ begin
           CheckRect := Bounds(Rect.Left - (Size.cx + FOffset),
             Rect.Top + ((Rect.Bottom - Rect.Top - Size.cy) div 2),
             Size.cx, Size.cy);
-          FlipRect(CheckRect, SavedClientRect, FUseRightToLeft);
+          FlipRect(CheckRect, SavedClientRect, IsRightToLeft);
         end;
         //if IsThemeBackgroundPartiallyTransparent(FThemeData, PartId, StateId) then
         //  DrawThemeParentBackground(Self.Handle, Handle, @CheckRect);
@@ -944,16 +933,14 @@ begin
       end;
     end;
     { Draw SubItem }
-    FlipRect(Rect, SavedClientRect, FUseRightToLeft);
+    FlipRect(Rect, SavedClientRect, IsRightToLeft);
     FillRect(Rect);
-    FlipRect(Rect, SavedClientRect, FUseRightToLeft);
+    FlipRect(Rect, SavedClientRect, IsRightToLeft);
     Inc(Rect.Left);
     OldColor := SetTextColor(Handle, ColorToRGB(NewTextColor));
     if ItemState.SubItem <> '' then
     begin
-      DrawTextFormat := DT_NOCLIP or DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER;
-      if FUseRightToLeft then
-        DrawTextFormat := DrawTextFormat or (DT_RIGHT or DT_RTLREADING);
+      DrawTextFormat := DrawTextBiDiModeFlags(DT_NOCLIP or DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER);
       Font.Style := ItemState.SubItemFontStyle;
       SetRectEmpty(SubItemRect);
       InternalDrawText(ItemState.SubItem, SubItemRect, DrawTextFormat or
@@ -961,7 +948,7 @@ begin
       SubItemWidth := SubItemRect.Right + 2 * FOffset;
       SubItemRect := Rect;
       SubItemRect.Left := SubItemRect.Right - SubItemWidth + FOffset;
-      FlipRect(SubItemRect, SavedClientRect, FUseRightToLeft);
+      FlipRect(SubItemRect, SavedClientRect, IsRightToLeft);
       InternalDrawText(ItemState.SubItem, SubItemRect, DrawTextFormat,
         FWantTabs and ItemDisabled);
       Dec(Rect.Right, SubItemWidth);
@@ -977,8 +964,7 @@ begin
       DrawTextFormat := DrawTextFormat or DT_NOPREFIX;
     if (UIState and UISF_HIDEACCEL) <> 0 then
       DrawTextFormat := DrawTextFormat or DT_HIDEPREFIX;
-    if FUseRightToLeft then
-      DrawTextFormat := DrawTextFormat or (DT_RIGHT or DT_RTLREADING);
+    DrawTextFormat := DrawTextBiDiModeFlags(DrawTextFormat);
     Font.Style := ItemState.ItemFontStyle;
     { When you call DrawText with the DT_CALCRECT flag and there's a word wider
       than the rectangle width, it increases the rectangle width and wraps
@@ -990,7 +976,7 @@ begin
       Wrapping at the same place is important because it can affect how many
       lines are drawn -- and we mustn't draw too many. }
     InternalDrawText(Items[Index], Rect, DrawTextFormat or DT_CALCRECT, False);
-    FlipRect(Rect, SavedClientRect, FUseRightToLeft);
+    FlipRect(Rect, SavedClientRect, IsRightToLeft);
     InternalDrawText(Items[Index], Rect, DrawTextFormat, FWantTabs and ItemDisabled and (LStyle = nil));
     { Draw focus rectangle }
     if FWantTabs and not ItemDisabled and (odSelected in State) and Focused and
@@ -1220,7 +1206,7 @@ begin
   IRect := ItemRect(Index);
   Inc(IRect.Left, (FCheckWidth + 2 * Offset) * (ItemLevel[Index]));
   IRect.Right := IRect.Left + (FCheckWidth + 2 * Offset);
-  FlipRect(IRect, ClientRect, FUseRightToLeft);
+  FlipRect(IRect, ClientRect, IsRightToLeft);
   InvalidateRect(Handle, @IRect, FThemeData <> 0);
 end;
 

+ 4 - 4
Components/NewStaticText.pas

@@ -146,7 +146,7 @@ begin
   with Params do
   begin
     Style := Style or SS_NOTIFY;
-    if not SetBiDiStyles(Self, Params) then begin
+    if ExStyle and WS_EX_RIGHT = 0 then begin
       { Quirk: No style is set for WordWrap=False in RTL mode; WS_EX_RIGHT
         overrides SS_LEFTNOWORDWRAP, and there is no SS_RIGHTNOWORDWRAP style.
         WordWrap=False still affects AdjustBounds, though. }
@@ -186,7 +186,7 @@ begin
   inherited;
   { What we're really trapping here is changes to Parent. Recalculate size
     if the new Parent's RTL setting is different. }
-  if IsParentRightToLeft(Self) <> FLastAdjustBoundsRTL then
+  if IsRightToLeft <> FLastAdjustBoundsRTL then
     AdjustBounds;
 end;
 
@@ -208,7 +208,7 @@ begin
   Result := DT_EXPANDTABS or DT_NOCLIP;
   if FWordWrap then Result := Result or DT_WORDBREAK;
   if not FShowAccelChar then Result := Result or DT_NOPREFIX;
-  if IsParentRightToLeft(Self) then begin
+  if IsRightToLeft then begin
     { Note: DT_RTLREADING must be included even when just calculating the
       size, since on certain fonts it can affect the width of characters.
       (Consider the Hebrew string: 'a '#$F9' b'. On 2000 with Lucida Console
@@ -254,7 +254,7 @@ var
 begin
   if not (csLoading in ComponentState) and FAutoSize then
   begin
-    FLastAdjustBoundsRTL := IsParentRightToLeft(Self);
+    FLastAdjustBoundsRTL := IsRightToLeft;
 
     NewBounds := CalcBounds;
 

+ 1 - 5
Components/PasswordEdit.pas

@@ -2,7 +2,7 @@ unit PasswordEdit;
 
 {
   Inno Setup
-  Copyright (C) 1997-2018 Jordan Russell
+  Copyright (C) 1997-2025 Jordan Russell
   Portions by Martijn Laan
   For conditions of distribution and use, see LICENSE.TXT.
 
@@ -71,9 +71,6 @@ procedure Register;
 
 implementation
 
-uses
-  BidiUtils;
-
 procedure Register;
 begin
   RegisterComponents('JR', [TPasswordEdit]);
@@ -92,7 +89,6 @@ begin
   inherited;
   if FPassword then
     Params.Style := Params.Style or ES_PASSWORD;
-  SetBiDiStyles(Self, Params);
 end;
 
 procedure TPasswordEdit.SetPassword(Value: Boolean);

+ 1 - 2
Components/RichEditViewer.pas

@@ -73,7 +73,7 @@ procedure Register;
 implementation
 
 uses
-  ShellApi, BidiUtils, PathFunc, ComObj, ComCtrls, Themes;
+  ShellApi, PathFunc, ComObj, ComCtrls, Themes;
 
 const
   RICHEDIT_CLASSW = 'RichEdit20W';
@@ -276,7 +276,6 @@ begin
       Must have a unique class name since it uses two different classes
       depending on the setting of the UseRichEdit property. }
     StrCat(Params.WinClassName, '/Text');  { don't localize! }
-  SetBiDiStyles(Self, Params);
 end;
 
 procedure TRichEditViewer.CreateWnd;

+ 2 - 12
Projects/Src/Setup.SetupForm.pas

@@ -236,17 +236,6 @@ begin
     Result := False;
 end;
 
-function IsParentSetupFormRightToLeft(AControl: TControl): Boolean;
-var
-  ParentForm: TSetupForm;
-begin
-  ParentForm := GetParentSetupForm(AControl);
-  if Assigned(ParentForm) then
-    Result := ParentForm.RightToLeft
-  else
-    Result := False;
-end;
-
 type
   TControlAnchorsList = TDictionary<TControl, TAnchors>;
   TControlAccess = class(TControl);
@@ -287,6 +276,8 @@ begin
   FFlipControlsOnShow := FRightToLeft;
   FSizeAndCenterOnShow := True;
   inherited;
+  if FRightToLeft then
+    BiDiMode := bdRightToLeft;
   { In Delphi 2005 and later, Position defaults to poDefaultPosOnly, but we
     don't want the form to be changing positions whenever its handle is
     recreated, so change it to the D7 and earlier default of poDesigned. }
@@ -538,6 +529,5 @@ end;
 
 initialization
   BidiUtils.IsParentFlippedFunc := IsParentSetupFormFlipped;
-  BidiUtils.IsParentRightToLeftFunc := IsParentSetupFormRightToLeft;
   WM_QueryCancelAutoPlay := RegisterWindowMessage('QueryCancelAutoPlay');
 end.