瀏覽代碼

Add special dummy Themes unit which can be used to deactivate inclusion of actual VCL Styles code with a minimum amount of IFDEFs, even if the project does support VCL Styles.

Martijn Laan 2 周之前
父節點
當前提交
2799b653cf

+ 8 - 2
Components/NewCheckListBox.pas

@@ -15,7 +15,7 @@ interface
 
 uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
-  StdCtrls, NewUxTheme;
+  StdCtrls, NewUxTheme, Themes;
 
 const
   WM_UPDATEUISTATE = $0128;
@@ -203,6 +203,7 @@ type
   end;
 
   TNewCheckListBoxStyleHook = class(TScrollingStyleHook)
+{$IFDEF VCLSTYLES}
   strict private
     FStyleColorsChecked: Boolean;
     FStyleColorsCheckedWantTabs: Boolean;
@@ -213,6 +214,7 @@ type
     procedure WMKillFocus(var Message: TMessage); message WM_KILLFOCUS;
   public
     constructor Create(AControl: TWinControl); override;
+{$ENDIF}
   end;
 
 procedure Register;
@@ -220,7 +222,7 @@ procedure Register;
 implementation
 
 uses
-  Themes, NewUxTheme.TmSchema, PathFunc, ActiveX, BidiUtils, UITypes, Types;
+  NewUxTheme.TmSchema, PathFunc, ActiveX, BidiUtils, UITypes, Types;
 
 const
   sRadioCantHaveDisabledChildren = 'Radio item cannot have disabled child items';
@@ -1902,6 +1904,8 @@ begin
     inherited;
 end;
 
+{$IFDEF VCLSTYLES}
+
 { TNewCheckListBoxStyleHook - same as Vcl.StdCtrls' TListBoxStyleHook except that it picks the
   correct colors when WantTabs is True }
 
@@ -1977,6 +1981,8 @@ begin
   Handled := True;
 end;
 
+{$ENDIF}
+
 { TAccObject }
 
 constructor TAccObject.Create(AControl: TNewCheckListBox);

+ 6 - 0
Components/NewProgressBar.pas

@@ -55,6 +55,7 @@ type
   end;
 
   TNewProgressBarStyleHook = class(TStyleHook)
+{$IFDEF VCLSTYLES}
   strict private
     FMarqueeTimer: TTimer;
     FMarqueeStep: Integer;
@@ -80,6 +81,7 @@ type
   public
     constructor Create(AControl: TWinControl); override;
     destructor Destroy; override;
+{$ENDIF}
   end;
 
 procedure Register;
@@ -194,6 +196,8 @@ begin
   DefaultHandler(Message);
 end;
 
+{$IFDEF VCLSTYLES}
+
 { TNewProgressBarStyleHook - same as Vcl.ComCtrls' TProgressBarStyleHook
   except that it accesses the Control property as a TNewProgressBar instead
   of a TProgressBar }
@@ -437,4 +441,6 @@ begin
   Result := 0;
 end;
 
+{$ENDIF}
+
 end.

+ 6 - 0
Components/NewStaticText.pas

@@ -78,10 +78,12 @@ type
   end;
 
   TNewStaticTextStyleHook = class(TStyleHook)
+{$IFDEF VCLSTYLES}
   strict protected
     procedure Paint(Canvas: TCanvas); override;
   public
     constructor Create(AControl: TWinControl); override;
+{$ENDIF}
   end;
 
 procedure Register;
@@ -306,6 +308,8 @@ begin
   end;
 end;
 
+{$IFDEF VCLSTYLES}
+
 { TNewStaticTextStyleHook - same as Vcl.StdCtrls' TStaticTextStyleHook
   except that it accesses the Control property as a TNewStaticText instead
   of a TCustomStaticText or TStaticText, and with code related to the
@@ -353,4 +357,6 @@ begin
   end;
 end;
 
+{$ENDIF}
+
 end.

+ 1 - 1
Components/RichEditViewer.pas

@@ -73,7 +73,7 @@ procedure Register;
 implementation
 
 uses
-  ShellApi, BidiUtils, PathFunc, ComObj, Themes, ComCtrls;
+  ShellApi, BidiUtils, PathFunc, ComObj, ComCtrls, Themes;
 
 const
   RICHEDIT_CLASSW = 'RichEdit20W';

+ 242 - 0
Components/Themes.pas

@@ -0,0 +1,242 @@
+unit Themes;
+
+{
+  Inno Setup
+  Copyright (C) 1997-2025 Jordan Russell
+  Portions by Martijn Laan
+  For conditions of distribution and use, see LICENSE.TXT.
+
+  VCL Styles dummy functions to easily deactivate inclusion of actual VCL Styles code
+
+  Must be included after ComCtrls and Forms
+}
+
+interface
+
+uses
+  Windows, Controls, Graphics, Types;
+
+type
+  TStyleHook = TObject;
+  TStyleHookClass = class of TStyleHook;
+
+  TStyleColor = (scBorder, scButtonDisabled, scButtonFocused, scButtonHot,
+    scButtonNormal, scButtonPressed, scCategoryButtons, scCategoryButtonsGradientBase,
+    scCategoryButtonsGradientEnd, scCategoryPanelGroup, scComboBox,
+    scComboBoxDisabled, scEdit, scEditDisabled, scGrid, scGenericBackground,
+    scGenericGradientBase, scGenericGradientEnd, scHintGradientBase,
+    scHintGradientEnd, scListBox, scListBoxDisabled, scListView, scPanel, scPanelDisabled,
+    scSplitter, scToolBarGradientBase, scToolBarGradientEnd, scTreeView, scWindow);
+
+  TStyleFont = (
+    sfButtonTextDisabled, sfButtonTextFocused, sfButtonTextHot, sfButtonTextNormal, sfButtonTextPressed,
+    sfCaptionTextInactive, sfCaptionTextNormal,
+    sfCategoryPanelGroupHeaderHot, sfCategoryPanelGroupHeaderNormal, sfCategoryButtonsCategoryNormal, sfCategoryButtonsCategorySelected,
+    sfCategoryButtonsHot, sfCategoryButtonsNormal, sfCategoryButtonsSelected,
+    sfCheckBoxTextDisabled, sfCheckBoxTextFocused, sfCheckBoxTextHot, sfCheckBoxTextNormal, sfCheckBoxTextPressed,
+    sfComboBoxItemDisabled, sfComboBoxItemFocused, sfComboBoxItemHot, sfComboBoxItemNormal, sfComboBoxItemSelected,
+    sfEditBoxTextDisabled, sfEditBoxTextFocused, sfEditBoxTextHot, sfEditBoxTextNormal, sfEditBoxTextSelected,
+    sfGridItemFixedHot, sfGridItemFixedNormal, sfGridItemFixedPressed, sfGridItemNormal, sfGridItemSelected,
+    sfGroupBoxTextDisabled, sfGroupBoxTextNormal,
+    sfHeaderSectionTextDisabled, sfHeaderSectionTextHot, sfHeaderSectionTextNormal, sfHeaderSectionTextPressed,
+    sfListItemTextDisabled, sfListItemTextFocused, sfListItemTextHot, sfListItemTextNormal, sfListItemTextSelected,
+    sfMenuItemTextDisabled, sfMenuItemTextHot, sfMenuItemTextNormal, sfMenuItemTextSelected,
+    sfPanelTextDisabled, sfPanelTextNormal,
+    sfPopupMenuItemTextDisabled, sfPopupMenuItemTextHot, sfPopupMenuItemTextNormal, sfPopupMenuItemTextSelected,
+    sfRadioButtonTextDisabled, sfRadioButtonTextFocused, sfRadioButtonTextHot, sfRadioButtonTextNormal, sfRadioButtonTextPressed,
+    sfSmCaptionTextInactive, sfSmCaptionTextNormal,
+    sfStatusPanelTextDisabled, sfStatusPanelTextNormal,
+    sfTabTextActiveDisabled, sfTabTextActiveHot, sfTabTextActiveNormal, sfTabTextInactiveDisabled, sfTabTextInactiveHot, sfTabTextInactiveNormal,
+    sfTextLabelDisabled, sfTextLabelFocused, sfTextLabelHot, sfTextLabelNormal,
+    sfToolItemTextDisabled, sfToolItemTextHot, sfToolItemTextNormal, sfToolItemTextSelected,
+    sfTreeItemTextDisabled, sfTreeItemTextFocused, sfTreeItemTextHot, sfTreeItemTextNormal, sfTreeItemTextSelected,
+    sfWindowTextDisabled, sfWindowTextNormal
+  );
+
+  TThemedButton = (
+    tbButtonDontCare,
+    tbButtonRoot,
+    tbPushButtonNormal, tbPushButtonHot, tbPushButtonPressed, tbPushButtonDisabled, tbPushButtonDefaulted, tbPushButtonDefaultedAnimating {Windows Vista or later},
+    tbRadioButtonUncheckedNormal, tbRadioButtonUncheckedHot, tbRadioButtonUncheckedPressed, tbRadioButtonUncheckedDisabled,
+    tbRadioButtonCheckedNormal, tbRadioButtonCheckedHot, tbRadioButtonCheckedPressed, tbRadioButtonCheckedDisabled,
+    tbCheckBoxUncheckedNormal, tbCheckBoxUncheckedHot, tbCheckBoxUncheckedPressed, tbCheckBoxUncheckedDisabled,
+    tbCheckBoxCheckedNormal, tbCheckBoxCheckedHot, tbCheckBoxCheckedPressed, tbCheckBoxCheckedDisabled,
+    tbCheckBoxMixedNormal, tbCheckBoxMixedHot, tbCheckBoxMixedPressed, tbCheckBoxMixedDisabled,
+    tbCheckBoxImplicitNormal, tbCheckBoxImplicitHot, tbCheckBoxImplicitPressed, tbCheckBoxImplicitDisabled, // Windows Vista or later
+    tbCheckBoxExcludedNormal, tbCheckBoxExcludedHot, tbCheckBoxExcludedPressed, tbCheckBoxExcludedDisabled, // Windows Vista or later
+    tbGroupBoxNormal, tbGroupBoxDisabled,
+    tbUserButton,
+    tbCommandLinkNormal, tbCommandLinkHot, tbCommandLinkPressed, tbCommandLinkDisabled, tbCommandLinkDefaulted, tbCommandLinkDefaultedAnimating,
+    tbCommandLinkGlyphNormal, tbCommandLinkGlyphHot, tbCommandLinkGlyphPressed, tbCommandLinkGlyphDisabled, tbCommandLinkGlyphDefaulted
+  );
+
+  TThemedCheckListBox = (
+    tclCheckListBoxDontCare,
+    tclCheckListBoxRoot,
+    tclListItemNormal, tclListItemDisabled,
+    tclHeaderItemNormal, tclHeaderItemDisabled
+  );
+
+   TElementColor = (
+    ecBorderColor,
+    ecFillColor,
+    ecTextColor,
+    ecEdgeLightColor,
+    ecEdgeHighLightColor,
+    ecEdgeShadowColor,
+    ecEdgeDkShadowColor,
+    ecEdgeFillColor,
+    ecTransparentColor,
+    ecGradientColor1,
+    ecGradientColor2,
+    ecGradientColor3,
+    ecGradientColor4,
+    ecGradientColor5,
+    ecShadowColor,
+    ecGlowColor,
+    ecTextBorderColor,
+    ecTextShadowColor,
+    ecGlyphTextColor,
+    ecGlyphTransparentColor,
+    ecFillColorHint,
+    ecBorderColorHint,
+    ecAccentColorHint,
+    ecTextColorHint,
+    ecHeading1TextColor,
+    ecHeading2TextColor,
+    ecBodyTextColor
+  );
+
+  TCustomStyleEngine = class
+    public
+      class procedure RegisterStyleHook(ControlClass: TClass; StyleHookClass: TStyleHookClass);
+      class procedure UnRegisterStyleHook(ControlClass: TClass; StyleHookClass: TStyleHookClass);
+  end;
+
+  TThemedElementDetails = TObject;
+
+  TCustomStyleServices = class
+  private
+    public
+      function DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect;
+        ClipRect: PRect = nil; DPI: Integer = 0): Boolean;
+      function Enabled: Boolean;
+      function GetElementColor(Details: TThemedElementDetails; ElementColor: TElementColor; out Color: TColor): Boolean;
+      function GetElementDetails(Detail: TThemedButton): TThemedElementDetails; overload;
+      function GetElementDetails(Detail: TThemedCheckListBox): TThemedElementDetails; overload;
+      function GetStyleColor(Font: TStyleColor): TColor;
+      function GetStyleFontColor(Font: TStyleFont): TColor;
+      function GetSystemColor(Color: TColor): TColor;
+      function IsSystemStyle: Boolean;
+  end;
+
+  TSystemHook = (shMenus, shDialogs, shToolTips);
+  TSystemHooks = set of TSystemHook;
+
+  TStyleManager = class
+    class var FSystemHooks: TSystemHooks;
+    class property SystemHooks: TSystemHooks read FSystemHooks write FSystemHooks;
+  end;
+
+  { Override ComCtrls }
+  TTabControlStyleHook = TStyleHook;
+  TDateTimePickerStyleHook = TStyleHook;
+  TTreeViewStyleHook = TStyleHook;
+  TListViewStyleHook = TStyleHook;
+  TProgressBarStyleHook = TStyleHook;
+  TTrackBarStyleHook = TStyleHook;
+  TStatusBarStyleHook = TStyleHook;
+  TToolBarStyleHook = TStyleHook;
+  TCoolBarStyleHook = TStyleHook;
+  TUpDownStyleHook = TStyleHook;
+  THeaderStyleHook = TStyleHook;
+  TPageScrollerStyleHook = TStyleHook;
+  TComboBoxExStyleHook = TStyleHook;
+  TRichEditStyleHook = TStyleHook;
+
+  { OVerride Forms }
+  TScrollingStyleHook = TStyleHook;
+  TFormStyleHook = TStyleHook;
+  TScrollBoxStyleHook = TStyleHook;
+
+function StyleServices(AControl: TControl = nil): TCustomStyleServices;
+
+implementation
+
+var
+  CustomStyleServices: TCustomStyleServices;
+
+function StyleServices(AControl: TControl = nil): TCustomStyleServices;
+begin
+  if CustomStyleServices = nil then
+    CustomStyleServices := TCustomStyleServices.Create;
+  Result := CustomStyleServices;
+end;
+
+{ TCustomStyleEngine }
+
+class procedure TCustomStyleEngine.RegisterStyleHook(ControlClass: TClass;
+  StyleHookClass: TStyleHookClass);
+begin
+end;
+
+class procedure TCustomStyleEngine.UnRegisterStyleHook(ControlClass: TClass;
+  StyleHookClass: TStyleHookClass);
+begin
+end;
+
+{ TCustomStyleServices }
+
+function TCustomStyleServices.DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect;
+  ClipRect: PRect = nil; DPI: Integer = 0): Boolean;
+begin
+  Result := False;
+end;
+
+function TCustomStyleServices.Enabled: Boolean;
+begin
+  Result := False;
+end;
+
+function TCustomStyleServices.GetElementDetails(Detail: TThemedCheckListBox): TThemedElementDetails;
+begin
+  Result := nil;
+end;
+
+function TCustomStyleServices.GetElementColor(Details: TThemedElementDetails;
+  ElementColor: TElementColor; out Color: TColor): Boolean;
+begin
+  Result := False;
+end;
+
+function TCustomStyleServices.GetElementDetails(Detail: TThemedButton): TThemedElementDetails;
+begin
+  Result := nil;
+end;
+
+function TCustomStyleServices.GetStyleColor(Font: TStyleColor): TColor;
+begin
+  Result := clNone;
+end;
+
+function TCustomStyleServices.GetStyleFontColor(Font: TStyleFont): TColor;
+begin
+  Result := clNone;
+end;
+
+function TCustomStyleServices.GetSystemColor(Color: TColor): TColor;
+begin
+  Result := clNone;
+end;
+
+function TCustomStyleServices.IsSystemStyle: Boolean;
+begin
+  Result := True;
+end;
+
+initialization
+
+finalization
+  CustomStyleServices.Free;
+
+end.

+ 2 - 1
Projects/Setup.dpr

@@ -105,7 +105,8 @@ uses
   StringScanner in '..\Components\StringScanner.pas',
   Compression.SevenZipDLLDecoder in 'Src\Compression.SevenZipDLLDecoder.pas',
   Compression.SevenZipDLLDecoder.Interfaces in 'Src\Compression.SevenZipDLLDecoder.Interfaces.pas',
-  Shared.EncryptionFunc in 'Src\Shared.EncryptionFunc.pas';
+  Shared.EncryptionFunc in 'Src\Shared.EncryptionFunc.pas',
+  Themes in '..\Components\Themes.pas';
 
 {$SETPEOSVERSION 6.1}
 {$SETPESUBSYSVERSION 6.1}

+ 1 - 0
Projects/Setup.dproj

@@ -179,6 +179,7 @@
         <DCCReference Include="Src\Compression.SevenZipDLLDecoder.pas"/>
         <DCCReference Include="Src\Compression.SevenZipDLLDecoder.Interfaces.pas"/>
         <DCCReference Include="Src\Shared.EncryptionFunc.pas"/>
+        <DCCReference Include="..\Components\Themes.pas"/>
         <BuildConfiguration Include="Base">
             <Key>Base</Key>
         </BuildConfiguration>