Themes.pas 10.0 KB

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