Themes.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 DrawParentBackground(Window: HWND; Target: HDC;
  112. Details: TThemedElementDetails; OnlyIfTransparent: Boolean; const Bounds: TRect): Boolean;
  113. function Enabled: Boolean;
  114. function GetElementColor(Details: TThemedElementDetails; ElementColor: TElementColor; out Color: TColor): Boolean;
  115. function GetElementDetails(Detail: TThemedButton): TThemedElementDetails; overload;
  116. function GetElementDetails(Detail: TThemedCheckListBox): TThemedElementDetails; overload;
  117. function GetStyleColor(Font: TStyleColor): TColor;
  118. function GetStyleFontColor(Font: TStyleFont): TColor;
  119. function GetSystemColor(Color: TColor): TColor;
  120. function IsSystemStyle: Boolean;
  121. end;
  122. TSystemHook = (shMenus, shDialogs, shToolTips);
  123. TSystemHooks = set of TSystemHook;
  124. TFormBorderStyle = (fbsCurrentStyle, fbsSystemStyle);
  125. TStyleManager = class
  126. type TStyleServicesHandle = type Pointer;
  127. class var AutoDiscoverStyleResources: Boolean;
  128. class var SystemHooks: TSystemHooks;
  129. class var SystemStyleName: String;
  130. class var FormBorderStyle: TFormBorderStyle;
  131. class constructor Create;
  132. class procedure SetStyle(Handle: TStyleServicesHandle);
  133. class function TryLoadFromResource(Instance: HINST; const ResourceName: string;
  134. ResourceType: PChar; var Handle: TStyleServicesHandle): Boolean;
  135. class function TrySetStyle(const Name: string; ShowErrorDialog: Boolean = True): Boolean;
  136. end;
  137. { Override ComCtrls }
  138. TTabControlStyleHook = TStyleHook;
  139. TDateTimePickerStyleHook = TStyleHook;
  140. TTreeViewStyleHook = TStyleHook;
  141. TListViewStyleHook = TStyleHook;
  142. TProgressBarStyleHook = TStyleHook;
  143. TTrackBarStyleHook = TStyleHook;
  144. TStatusBarStyleHook = TStyleHook;
  145. TToolBarStyleHook = TStyleHook;
  146. TCoolBarStyleHook = TStyleHook;
  147. TUpDownStyleHook = TStyleHook;
  148. THeaderStyleHook = TStyleHook;
  149. TPageScrollerStyleHook = TStyleHook;
  150. TComboBoxExStyleHook = TStyleHook;
  151. TRichEditStyleHook = TStyleHook;
  152. { OVerride Forms }
  153. TScrollingStyleHook = TStyleHook;
  154. TFormStyleHook = TStyleHook;
  155. TScrollBoxStyleHook = TStyleHook;
  156. function StyleServices(AControl: TControl = nil): TCustomStyleServices;
  157. implementation
  158. var
  159. CustomStyleServices: TCustomStyleServices;
  160. function StyleServices(AControl: TControl = nil): TCustomStyleServices;
  161. begin
  162. if CustomStyleServices = nil then
  163. CustomStyleServices := TCustomStyleServices.Create;
  164. Result := CustomStyleServices;
  165. end;
  166. { TCustomStyleEngine }
  167. class procedure TCustomStyleEngine.RegisterStyleHook(ControlClass: TClass;
  168. StyleHookClass: TStyleHookClass);
  169. begin
  170. end;
  171. class procedure TCustomStyleEngine.UnRegisterStyleHook(ControlClass: TClass;
  172. StyleHookClass: TStyleHookClass);
  173. begin
  174. end;
  175. { TCustomStyleServices }
  176. function TCustomStyleServices.DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect;
  177. ClipRect: PRect = nil; DPI: Integer = 0): Boolean;
  178. begin
  179. Result := False;
  180. end;
  181. function TCustomStyleServices.DrawParentBackground(Window: HWND; Target: HDC;
  182. Details: TThemedElementDetails; OnlyIfTransparent: Boolean; const Bounds: TRect): Boolean;
  183. begin
  184. Result := False;
  185. end;
  186. function TCustomStyleServices.Enabled: Boolean;
  187. begin
  188. Result := False;
  189. end;
  190. function TCustomStyleServices.GetElementDetails(Detail: TThemedCheckListBox): TThemedElementDetails;
  191. begin
  192. Result := nil;
  193. end;
  194. function TCustomStyleServices.GetElementColor(Details: TThemedElementDetails;
  195. ElementColor: TElementColor; out Color: TColor): Boolean;
  196. begin
  197. Result := False;
  198. end;
  199. function TCustomStyleServices.GetElementDetails(Detail: TThemedButton): TThemedElementDetails;
  200. begin
  201. Result := nil;
  202. end;
  203. function TCustomStyleServices.GetStyleColor(Font: TStyleColor): TColor;
  204. begin
  205. Result := clNone;
  206. end;
  207. function TCustomStyleServices.GetStyleFontColor(Font: TStyleFont): TColor;
  208. begin
  209. Result := clNone;
  210. end;
  211. function TCustomStyleServices.GetSystemColor(Color: TColor): TColor;
  212. begin
  213. Result := clNone;
  214. end;
  215. function TCustomStyleServices.IsSystemStyle: Boolean;
  216. begin
  217. Result := True;
  218. end;
  219. { TStyleManager }
  220. class constructor TStyleManager.Create;
  221. begin
  222. FormBorderStyle := fbsSystemStyle;
  223. end;
  224. class procedure TStyleManager.SetStyle(Handle: TStyleServicesHandle);
  225. begin
  226. end;
  227. class function TStyleManager.TryLoadFromResource(Instance: HINST; const ResourceName: string;
  228. ResourceType: PChar; var Handle: TStyleServicesHandle): Boolean;
  229. begin
  230. Result := False;
  231. end;
  232. class function TStyleManager.TrySetStyle(const Name: string; ShowErrorDialog: Boolean): Boolean;
  233. begin
  234. Result := False;
  235. end;
  236. initialization
  237. finalization
  238. CustomStyleServices.Free;
  239. end.