bcdefaultthememanager.pas 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // SPDX-License-Identifier: LGPL-3.0-linking-exception
  2. {******************************* CONTRIBUTOR(S) ******************************
  3. - Edivando S. Santos Brasil | [email protected]
  4. (Compatibility with delphi VCL 11/2018)
  5. ***************************** END CONTRIBUTOR(S) *****************************}
  6. unit BCDefaultThemeManager;
  7. {$I bgracontrols.inc}
  8. interface
  9. uses
  10. Classes, SysUtils, {$IFDEF FPC}LResources, CustomDrawnDrawers,{$ENDIF}
  11. Forms, Controls, Graphics, Dialogs,
  12. {$IFNDEF FPC}BGRAGraphics, GraphType, FPImage, {$ENDIF}
  13. BCButton, BCButtonFocus, BCNumericKeyboard, BCThemeManager,
  14. BCSamples, {$IFDEF FPC}BGRACustomDrawn,{$ENDIF} BCKeyboard;
  15. type
  16. { TBCDefaultThemeManager }
  17. TBCDefaultThemeManager = class(TBCThemeManager)
  18. private
  19. FBCStyle: TBCSampleStyle;
  20. FButton: TBCButton;
  21. FButtonFocus: TBCButtonFocus;
  22. FCDStyle: TCDDrawStyle;
  23. procedure SetFBCStyle(AValue: TBCSampleStyle);
  24. procedure SetFButton(AValue: TBCButton);
  25. procedure SetFButtonFocus(AValue: TBCButtonFocus);
  26. procedure SetFCDStyle(AValue: TCDDrawStyle);
  27. protected
  28. public
  29. constructor Create(AOwner: TComponent); override;
  30. destructor Destroy; override;
  31. public
  32. procedure Apply(AControl: TWinControl); override;
  33. procedure Apply(); override;
  34. published
  35. property Button: TBCButton read FButton write SetFButton;
  36. property ButtonFocus: TBCButtonFocus read FButtonFocus write SetFButtonFocus;
  37. property BCStyle: TBCSampleStyle read FBCStyle write SetFBCStyle;
  38. property CDStyle: TCDDrawStyle read FCDStyle write SetFCDStyle;
  39. end;
  40. {$IFDEF FPC}procedure Register;{$ENDIF}
  41. implementation
  42. {$IFDEF FPC}procedure Register;
  43. begin
  44. RegisterComponents('BGRA Controls', [TBCDefaultThemeManager]);
  45. end;
  46. {$ENDIF}
  47. { TBCDefaultThemeManager }
  48. procedure TBCDefaultThemeManager.SetFButton(AValue: TBCButton);
  49. begin
  50. if FButton = AValue then
  51. Exit;
  52. FButton := AValue;
  53. end;
  54. procedure TBCDefaultThemeManager.SetFBCStyle(AValue: TBCSampleStyle);
  55. begin
  56. if FBCStyle = AValue then
  57. Exit;
  58. FBCStyle := AValue;
  59. end;
  60. procedure TBCDefaultThemeManager.SetFButtonFocus(AValue: TBCButtonFocus);
  61. begin
  62. if FButtonFocus = AValue then
  63. Exit;
  64. FButtonFocus := AValue;
  65. end;
  66. procedure TBCDefaultThemeManager.SetFCDStyle(AValue: TCDDrawStyle);
  67. begin
  68. if FCDStyle = AValue then
  69. Exit;
  70. FCDStyle := AValue;
  71. end;
  72. constructor TBCDefaultThemeManager.Create(AOwner: TComponent);
  73. begin
  74. inherited Create(AOwner);
  75. FBCStyle := ssDefault;
  76. FCDStyle := dsDefault;
  77. end;
  78. destructor TBCDefaultThemeManager.Destroy;
  79. begin
  80. inherited Destroy;
  81. end;
  82. procedure TBCDefaultThemeManager.Apply(AControl: TWinControl);
  83. var
  84. i: integer;
  85. removeTempButton: boolean;
  86. removeTempButtonFocus: boolean;
  87. tempButton: TBCButton;
  88. tempButtonFocus: TBCButtonFocus;
  89. begin
  90. removeTempButton := False;
  91. removeTempButtonFocus := False;
  92. if (Assigned(FButton)) and (FBCStyle = ssDefault) then
  93. tempButton := FButton
  94. else
  95. begin
  96. tempButton := TBCButton.Create(Self);
  97. tempButton.Name := 'BCDefaultThemeManager_tempButton';
  98. removeTempButton := True;
  99. StyleButtonsSample(tempButton, FBCStyle);
  100. end;
  101. if (Assigned(FButton)) and (FBCStyle = ssDefault) then
  102. tempButtonFocus := FButtonFocus
  103. else
  104. begin
  105. tempButtonFocus := TBCButtonFocus.Create(Self);
  106. tempButtonFocus.Name := 'BCDefaultThemeManager_tempButtonFocus';
  107. removeTempButtonFocus := True;
  108. StyleButtonsFocusSample(tempButtonFocus, FBCStyle);
  109. end;
  110. { Controls }
  111. for i := 0 to AControl.ControlCount - 1 do
  112. begin
  113. { BCButton }
  114. if (AControl.Controls[i] is TBCButton) then
  115. with TBCButton(AControl.Controls[i]) do
  116. if (Assigned(ThemeManager)) and
  117. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  118. (tempButton.Name <> AControl.Controls[i].Name) then
  119. begin
  120. Assign(tempButton);
  121. end;
  122. { BCButtonFocus }
  123. if (AControl.Controls[i] is TBCButtonFocus) then
  124. with TBCButtonFocus(AControl.Controls[i]) do
  125. if (Assigned(ThemeManager)) and
  126. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) then
  127. begin
  128. Assign(tempButtonFocus);
  129. end;
  130. { Custom Drawn }
  131. if (AControl.Controls[i] is TBCDButton) then
  132. with TBCDButton(AControl.Controls[i]) do
  133. if (Assigned(ThemeManager)) and
  134. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  135. (tempButtonFocus.Name <> AControl.Controls[i].Name) then
  136. begin
  137. DrawStyle := CDStyle;
  138. end;
  139. if (AControl.Controls[i] is TBCDEdit) then
  140. with TBCDEdit(AControl.Controls[i]) do
  141. if (Assigned(ThemeManager)) and
  142. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  143. (tempButtonFocus.Name <> AControl.Controls[i].Name) then
  144. begin
  145. DrawStyle := CDStyle;
  146. end;
  147. if (AControl.Controls[i] is TBCDStaticText) then
  148. with TBCDStaticText(AControl.Controls[i]) do
  149. if (Assigned(ThemeManager)) and
  150. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  151. (tempButtonFocus.Name <> AControl.Controls[i].Name) then
  152. begin
  153. DrawStyle := CDStyle;
  154. end;
  155. if (AControl.Controls[i] is TBCDProgressBar) then
  156. with TBCDProgressBar(AControl.Controls[i]) do
  157. if (Assigned(ThemeManager)) and
  158. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  159. (tempButtonFocus.Name <> AControl.Controls[i].Name) then
  160. begin
  161. DrawStyle := CDStyle;
  162. end;
  163. if (AControl.Controls[i] is TBCDSpinEdit) then
  164. with TBCDSpinEdit(AControl.Controls[i]) do
  165. if (Assigned(ThemeManager)) and
  166. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  167. (tempButtonFocus.Name <> AControl.Controls[i].Name) then
  168. begin
  169. DrawStyle := CDStyle;
  170. end;
  171. if (AControl.Controls[i] is TBCDCheckBox) then
  172. with TBCDCheckBox(AControl.Controls[i]) do
  173. if (Assigned(ThemeManager)) and
  174. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  175. (tempButtonFocus.Name <> AControl.Controls[i].Name) then
  176. begin
  177. DrawStyle := CDStyle;
  178. end;
  179. if (AControl.Controls[i] is TBCDRadioButton) then
  180. with TBCDRadioButton(AControl.Controls[i]) do
  181. if (Assigned(ThemeManager)) and
  182. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  183. (tempButtonFocus.Name <> AControl.Controls[i].Name) then
  184. begin
  185. DrawStyle := CDStyle;
  186. end;
  187. end;
  188. { Components }
  189. for i := 0 to AControl.ComponentCount - 1 do
  190. begin
  191. { BCNumericKeyboard }
  192. if (AControl.Components[i] is TBCNumericKeyboard) then
  193. with TBCNumericKeyboard(AControl.Components[i]) do
  194. if (Assigned(ThemeManager)) and
  195. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  196. (tempButton.Name <> TBCNumericKeyboard(AControl.Components[i]).ButtonStyle.Name) then
  197. begin
  198. ButtonStyle.Assign(tempButton);
  199. UpdateButtonStyle;
  200. end;
  201. { BCRealNumericKeyboard }
  202. if (AControl.Components[i] is TBCRealNumericKeyboard) then
  203. with TBCRealNumericKeyboard(AControl.Components[i]) do
  204. if (Assigned(ThemeManager)) and
  205. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  206. (tempButton.Name <> TBCRealNumericKeyboard(AControl.Components[i]).ButtonStyle.Name) then
  207. begin
  208. ButtonStyle.Assign(tempButton);
  209. UpdateButtonStyle;
  210. end;
  211. { BCKeyboard }
  212. if (AControl.Components[i] is TBCKeyboard) then
  213. with TBCKeyboard(AControl.Components[i]) do
  214. if (Assigned(ThemeManager)) and
  215. (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
  216. (tempButton.Name <> TBCKeyboard(AControl.Components[i]).ButtonStyle.Name) then
  217. begin
  218. ButtonStyle.Assign(tempButton);
  219. UpdateButtonStyle;
  220. end;
  221. end;
  222. if removeTempButton then
  223. tempButton.Free;
  224. if removeTempButtonFocus then
  225. tempButtonFocus.Free;
  226. end;
  227. procedure TBCDefaultThemeManager.Apply;
  228. begin
  229. if Self.Owner is TWinControl then
  230. Apply(Self.Owner as TWinControl)
  231. else
  232. raise Exception.Create('The parent is not TWinControl descendant.');
  233. end;
  234. end.