Themes.pas 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. unit Themes;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2025 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. VCL Styles dummy functions to easily deactivate inclusion of actual VCL Styles code
  8. Just add it to your .dpr and use Themes instead of Vcl.Themes everywhere. Requires Vcl to
  9. be in the project's unit scope names list to be able to use same code with real Vcl.Themes.
  10. In units it must be used after ComCtrls and Forms.
  11. }
  12. interface
  13. uses
  14. Windows, Controls, Graphics, Types;
  15. type
  16. TStyleHook = TObject;
  17. TStyleHookClass = class of TStyleHook;
  18. TStyleColor = (scBorder, scButtonDisabled, scButtonFocused, scButtonHot,
  19. scButtonNormal, scButtonPressed, scCategoryButtons, scCategoryButtonsGradientBase,
  20. scCategoryButtonsGradientEnd, scCategoryPanelGroup, scComboBox,
  21. scComboBoxDisabled, scEdit, scEditDisabled, scGrid, scGenericBackground,
  22. scGenericGradientBase, scGenericGradientEnd, scHintGradientBase,
  23. scHintGradientEnd, scListBox, scListBoxDisabled, scListView, scPanel, scPanelDisabled,
  24. scSplitter, scToolBarGradientBase, scToolBarGradientEnd, scTreeView, scWindow);
  25. TStyleFont = (
  26. sfButtonTextDisabled, sfButtonTextFocused, sfButtonTextHot, sfButtonTextNormal, sfButtonTextPressed,
  27. sfCaptionTextInactive, sfCaptionTextNormal,
  28. sfCategoryPanelGroupHeaderHot, sfCategoryPanelGroupHeaderNormal, sfCategoryButtonsCategoryNormal, sfCategoryButtonsCategorySelected,
  29. sfCategoryButtonsHot, sfCategoryButtonsNormal, sfCategoryButtonsSelected,
  30. sfCheckBoxTextDisabled, sfCheckBoxTextFocused, sfCheckBoxTextHot, sfCheckBoxTextNormal, sfCheckBoxTextPressed,
  31. sfComboBoxItemDisabled, sfComboBoxItemFocused, sfComboBoxItemHot, sfComboBoxItemNormal, sfComboBoxItemSelected,
  32. sfEditBoxTextDisabled, sfEditBoxTextFocused, sfEditBoxTextHot, sfEditBoxTextNormal, sfEditBoxTextSelected,
  33. sfGridItemFixedHot, sfGridItemFixedNormal, sfGridItemFixedPressed, sfGridItemNormal, sfGridItemSelected,
  34. sfGroupBoxTextDisabled, sfGroupBoxTextNormal,
  35. sfHeaderSectionTextDisabled, sfHeaderSectionTextHot, sfHeaderSectionTextNormal, sfHeaderSectionTextPressed,
  36. sfListItemTextDisabled, sfListItemTextFocused, sfListItemTextHot, sfListItemTextNormal, sfListItemTextSelected,
  37. sfMenuItemTextDisabled, sfMenuItemTextHot, sfMenuItemTextNormal, sfMenuItemTextSelected,
  38. sfPanelTextDisabled, sfPanelTextNormal,
  39. sfPopupMenuItemTextDisabled, sfPopupMenuItemTextHot, sfPopupMenuItemTextNormal, sfPopupMenuItemTextSelected,
  40. sfRadioButtonTextDisabled, sfRadioButtonTextFocused, sfRadioButtonTextHot, sfRadioButtonTextNormal, sfRadioButtonTextPressed,
  41. sfSmCaptionTextInactive, sfSmCaptionTextNormal,
  42. sfStatusPanelTextDisabled, sfStatusPanelTextNormal,
  43. sfTabTextActiveDisabled, sfTabTextActiveHot, sfTabTextActiveNormal, sfTabTextInactiveDisabled, sfTabTextInactiveHot, sfTabTextInactiveNormal,
  44. sfTextLabelDisabled, sfTextLabelFocused, sfTextLabelHot, sfTextLabelNormal,
  45. sfToolItemTextDisabled, sfToolItemTextHot, sfToolItemTextNormal, sfToolItemTextSelected,
  46. sfTreeItemTextDisabled, sfTreeItemTextFocused, sfTreeItemTextHot, sfTreeItemTextNormal, sfTreeItemTextSelected,
  47. sfWindowTextDisabled, sfWindowTextNormal
  48. );
  49. TThemedButton = (
  50. tbButtonDontCare,
  51. tbButtonRoot,
  52. tbPushButtonNormal, tbPushButtonHot, tbPushButtonPressed, tbPushButtonDisabled, tbPushButtonDefaulted, tbPushButtonDefaultedAnimating {Windows Vista or later},
  53. tbRadioButtonUncheckedNormal, tbRadioButtonUncheckedHot, tbRadioButtonUncheckedPressed, tbRadioButtonUncheckedDisabled,
  54. tbRadioButtonCheckedNormal, tbRadioButtonCheckedHot, tbRadioButtonCheckedPressed, tbRadioButtonCheckedDisabled,
  55. tbCheckBoxUncheckedNormal, tbCheckBoxUncheckedHot, tbCheckBoxUncheckedPressed, tbCheckBoxUncheckedDisabled,
  56. tbCheckBoxCheckedNormal, tbCheckBoxCheckedHot, tbCheckBoxCheckedPressed, tbCheckBoxCheckedDisabled,
  57. tbCheckBoxMixedNormal, tbCheckBoxMixedHot, tbCheckBoxMixedPressed, tbCheckBoxMixedDisabled,
  58. tbCheckBoxImplicitNormal, tbCheckBoxImplicitHot, tbCheckBoxImplicitPressed, tbCheckBoxImplicitDisabled, // Windows Vista or later
  59. tbCheckBoxExcludedNormal, tbCheckBoxExcludedHot, tbCheckBoxExcludedPressed, tbCheckBoxExcludedDisabled, // Windows Vista or later
  60. tbGroupBoxNormal, tbGroupBoxDisabled,
  61. tbUserButton,
  62. tbCommandLinkNormal, tbCommandLinkHot, tbCommandLinkPressed, tbCommandLinkDisabled, tbCommandLinkDefaulted, tbCommandLinkDefaultedAnimating,
  63. tbCommandLinkGlyphNormal, tbCommandLinkGlyphHot, tbCommandLinkGlyphPressed, tbCommandLinkGlyphDisabled, tbCommandLinkGlyphDefaulted
  64. );
  65. TThemedCheckListBox = (
  66. tclCheckListBoxDontCare,
  67. tclCheckListBoxRoot,
  68. tclListItemNormal, tclListItemDisabled,
  69. tclHeaderItemNormal, tclHeaderItemDisabled
  70. );
  71. TElementColor = (
  72. ecBorderColor,
  73. ecFillColor,
  74. ecTextColor,
  75. ecEdgeLightColor,
  76. ecEdgeHighLightColor,
  77. ecEdgeShadowColor,
  78. ecEdgeDkShadowColor,
  79. ecEdgeFillColor,
  80. ecTransparentColor,
  81. ecGradientColor1,
  82. ecGradientColor2,
  83. ecGradientColor3,
  84. ecGradientColor4,
  85. ecGradientColor5,
  86. ecShadowColor,
  87. ecGlowColor,
  88. ecTextBorderColor,
  89. ecTextShadowColor,
  90. ecGlyphTextColor,
  91. ecGlyphTransparentColor,
  92. ecFillColorHint,
  93. ecBorderColorHint,
  94. ecAccentColorHint,
  95. ecTextColorHint,
  96. ecHeading1TextColor,
  97. ecHeading2TextColor,
  98. ecBodyTextColor
  99. );
  100. TCustomStyleEngine = class
  101. public
  102. class procedure RegisterStyleHook(ControlClass: TClass; StyleHookClass: TStyleHookClass);
  103. class procedure UnRegisterStyleHook(ControlClass: TClass; StyleHookClass: TStyleHookClass);
  104. end;
  105. TThemedElementDetails = TObject;
  106. TCustomStyleServices = class
  107. private
  108. public
  109. function DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect;
  110. ClipRect: PRect = nil; DPI: Integer = 0): Boolean;
  111. function Enabled: Boolean;
  112. function GetElementColor(Details: TThemedElementDetails; ElementColor: TElementColor; out Color: TColor): Boolean;
  113. function GetElementDetails(Detail: TThemedButton): TThemedElementDetails; overload;
  114. function GetElementDetails(Detail: TThemedCheckListBox): TThemedElementDetails; overload;
  115. function GetStyleColor(Font: TStyleColor): TColor;
  116. function GetStyleFontColor(Font: TStyleFont): TColor;
  117. function GetSystemColor(Color: TColor): TColor;
  118. function IsSystemStyle: Boolean;
  119. end;
  120. TSystemHook = (shMenus, shDialogs, shToolTips);
  121. TSystemHooks = set of TSystemHook;
  122. TStyleManager = class
  123. class var FSystemHooks: TSystemHooks;
  124. class property SystemHooks: TSystemHooks read FSystemHooks write FSystemHooks;
  125. class function TrySetStyle(const Name: string; ShowErrorDialog: Boolean = True): Boolean;
  126. end;
  127. { Override ComCtrls }
  128. TTabControlStyleHook = TStyleHook;
  129. TDateTimePickerStyleHook = TStyleHook;
  130. TTreeViewStyleHook = TStyleHook;
  131. TListViewStyleHook = TStyleHook;
  132. TProgressBarStyleHook = TStyleHook;
  133. TTrackBarStyleHook = TStyleHook;
  134. TStatusBarStyleHook = TStyleHook;
  135. TToolBarStyleHook = TStyleHook;
  136. TCoolBarStyleHook = TStyleHook;
  137. TUpDownStyleHook = TStyleHook;
  138. THeaderStyleHook = TStyleHook;
  139. TPageScrollerStyleHook = TStyleHook;
  140. TComboBoxExStyleHook = TStyleHook;
  141. TRichEditStyleHook = TStyleHook;
  142. { OVerride Forms }
  143. TScrollingStyleHook = TStyleHook;
  144. TFormStyleHook = TStyleHook;
  145. TScrollBoxStyleHook = TStyleHook;
  146. function StyleServices(AControl: TControl = nil): TCustomStyleServices;
  147. implementation
  148. var
  149. CustomStyleServices: TCustomStyleServices;
  150. function StyleServices(AControl: TControl = nil): TCustomStyleServices;
  151. begin
  152. if CustomStyleServices = nil then
  153. CustomStyleServices := TCustomStyleServices.Create;
  154. Result := CustomStyleServices;
  155. end;
  156. { TCustomStyleEngine }
  157. class procedure TCustomStyleEngine.RegisterStyleHook(ControlClass: TClass;
  158. StyleHookClass: TStyleHookClass);
  159. begin
  160. end;
  161. class procedure TCustomStyleEngine.UnRegisterStyleHook(ControlClass: TClass;
  162. StyleHookClass: TStyleHookClass);
  163. begin
  164. end;
  165. { TCustomStyleServices }
  166. function TCustomStyleServices.DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect;
  167. ClipRect: PRect = nil; DPI: Integer = 0): Boolean;
  168. begin
  169. Result := False;
  170. end;
  171. function TCustomStyleServices.Enabled: Boolean;
  172. begin
  173. Result := False;
  174. end;
  175. function TCustomStyleServices.GetElementDetails(Detail: TThemedCheckListBox): TThemedElementDetails;
  176. begin
  177. Result := nil;
  178. end;
  179. function TCustomStyleServices.GetElementColor(Details: TThemedElementDetails;
  180. ElementColor: TElementColor; out Color: TColor): Boolean;
  181. begin
  182. Result := False;
  183. end;
  184. function TCustomStyleServices.GetElementDetails(Detail: TThemedButton): TThemedElementDetails;
  185. begin
  186. Result := nil;
  187. end;
  188. function TCustomStyleServices.GetStyleColor(Font: TStyleColor): TColor;
  189. begin
  190. Result := clNone;
  191. end;
  192. function TCustomStyleServices.GetStyleFontColor(Font: TStyleFont): TColor;
  193. begin
  194. Result := clNone;
  195. end;
  196. function TCustomStyleServices.GetSystemColor(Color: TColor): TColor;
  197. begin
  198. Result := clNone;
  199. end;
  200. function TCustomStyleServices.IsSystemStyle: Boolean;
  201. begin
  202. Result := True;
  203. end;
  204. { TStyleManager }
  205. class function TStyleManager.TrySetStyle(const Name: string; ShowErrorDialog: Boolean): Boolean;
  206. begin
  207. Result := False;
  208. end;
  209. initialization
  210. finalization
  211. CustomStyleServices.Free;
  212. end.