CnSkinStyle.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. {******************************************************************************}
  2. { CnPack For Delphi/C++Builder }
  3. { 中国人自己的开放源码第三方开发包 }
  4. { (C)Copyright 2001-2018 CnPack 开发组 }
  5. { ------------------------------------ }
  6. { }
  7. { 本开发包是开源的自由软件,您可以遵照 CnPack 的发布协议来修 }
  8. { 改和重新发布这一程序。 }
  9. { }
  10. { 发布这一开发包的目的是希望它有用,但没有任何担保。甚至没有 }
  11. { 适合特定目的而隐含的担保。更详细的情况请参阅 CnPack 发布协议。 }
  12. { }
  13. { 您应该已经和开发包一起收到一份 CnPack 发布协议的副本。如果 }
  14. { 还没有,可访问我们的网站: }
  15. { }
  16. { 网站地址:http://www.cnpack.org }
  17. { 电子邮件:master@cnpack.org }
  18. { }
  19. {******************************************************************************}
  20. unit CnSkinStyle;
  21. interface
  22. uses
  23. Windows, Messages, Classes, SysUtils, Graphics, Forms, Controls;
  24. type
  25. ICnSkinParams = interface(IUnknown)
  26. ['{C4FDB92B-AE10-49F9-918E-F4F7DC9CD1E4}']
  27. function GetFaceColor: TColor;
  28. function GetLightColor: TColor;
  29. function GetMenuHotColor: TColor;
  30. function GetShadowColor: TColor;
  31. function GetActiveCaptionColor: TColor;
  32. function GetInActiveCaptionColor: TColor;
  33. function GetCaptionHeight: Integer;
  34. function GetBorderSize: Integer;
  35. function GetButtonSize: Integer;
  36. function GetButtonRight: Integer;
  37. function GetButtonTop: Integer;
  38. function GetCaptionFontSize: Integer;
  39. function GetRgnSize: Integer;
  40. function GetWindowBmp: TBitmap;
  41. function GetWindowBtnBmp: TBitmap;
  42. function GetScrollBarBmp: TBitmap;
  43. function GetButtonBmp: TBitmap;
  44. function GetCheckBmp: TBitmap;
  45. function GetComboBmp: TBitmap;
  46. function GetRadioBmp: TBitmap;
  47. property FaceColor: TColor read GetFaceColor;
  48. {* 窗体表面颜色 }
  49. property LightColor: TColor read GetLightColor;
  50. {* 高亮颜色 }
  51. property ShadowColor: TColor read GetShadowColor;
  52. {* 阴影颜色 }
  53. property MenuHotColor: TColor read GetMenuHotColor;
  54. {* 菜单高亮颜色 }
  55. property ActiveCaptionColor: TColor read GetActiveCaptionColor;
  56. {* 活动窗体的标题颜色 }
  57. property InActiveCaptionColor: TColor read GetInActiveCaptionColor;
  58. {* 非活动窗体的标题颜色 }
  59. property CaptionHeight: Integer read GetCaptionHeight;
  60. {* 标题栏高度 }
  61. property BorderSize: Integer read GetBorderSize;
  62. {* 窗体边框粗细 }
  63. property ButtonSize: Integer read GetButtonSize;
  64. {* 单个标题按钮的尺寸 }
  65. property ButtonTop: Integer read GetButtonTop;
  66. {* 标题按钮距顶端的尺寸 }
  67. property ButtonRight: Integer read GetButtonRight;
  68. {* 标题按钮距右边的尺寸 }
  69. property CaptionFontSize: Integer read GetCaptionFontSize;
  70. {* 标题栏文字尺寸 }
  71. property RgnSize: Integer read GetRgnSize;
  72. {* 区域尺寸 }
  73. property WindowBmp: TBitmap read GetWindowBmp;
  74. {* 标题栏背景图片 }
  75. property WindowBtnBmp: TBitmap read GetWindowBtnBmp;
  76. {* 窗体系统按钮图片 }
  77. property ScrollBarBmp: TBitmap read GetScrollBarBmp;
  78. {* 滚动条的图片 }
  79. property ButtonBmp: TBitmap read GetButtonBmp;
  80. {* 普通按钮图片 }
  81. property CheckBmp: TBitmap read GetCheckBmp;
  82. {* 复选框图片 }
  83. property RadioBmp: TBitmap read GetRadioBmp;
  84. {* 单选钮图片 }
  85. property ComboBmp: TBitmap read GetComboBmp;
  86. {* 下拉框图片 }
  87. end;
  88. TCnSkinStyle = class(TComponent, ICnSkinParams)
  89. private
  90. FWindowBmp: TBitmap;
  91. FWindowBtnBmp: TBitmap;
  92. FScrollBarBmp: TBitmap;
  93. FButtonBmp: TBitmap;
  94. FCheckBmp: TBitmap;
  95. FRadioBmp: TBitmap;
  96. FComboBmp: TBitmap;
  97. FShadowColor: TColor;
  98. FLightColor: TColor;
  99. FMenuHotColor: TColor;
  100. FFaceColor: TColor;
  101. FActiveCaptionColor: TColor;
  102. FInActiveCaptionColor: TColor;
  103. FCaptionHeight: Integer;
  104. FBorderSize: Integer;
  105. FButtonSize: Integer;
  106. FButtonRight: Integer;
  107. FButtonTop: Integer;
  108. FCaptionFontSize: Integer;
  109. FRgnSize: Integer;
  110. function GetFaceColor: TColor;
  111. function GetLightColor: TColor;
  112. function GetMenuHotColor: TColor;
  113. function GetScrollBarBmp: TBitmap;
  114. function GetShadowColor: TColor;
  115. function GetActiveCaptionColor: TColor;
  116. function GetInActiveCaptionColor: TColor;
  117. procedure SetFaceColor(const Value: TColor);
  118. procedure SetLightColor(const Value: TColor);
  119. procedure SetMenuHotColor(const Value: TColor);
  120. procedure SetScrollBarBmp(const Value: TBitmap);
  121. procedure SetShadowColor(const Value: TColor);
  122. procedure SetActiveCaptionColor(const Value: TColor);
  123. procedure SetInActiveCaptionColor(const Value: TColor);
  124. procedure SetCaptionHeight(const Value: Integer);
  125. function GetCaptionHeight: Integer;
  126. procedure SetBorderSize(const Value: Integer);
  127. function GetBorderSize: Integer;
  128. procedure SetButtonSize(const Value: Integer);
  129. function GetButtonSize: Integer;
  130. procedure SetButtonRight(const Value: Integer);
  131. procedure SetButtonTop(const Value: Integer);
  132. function GetButtonRight: Integer;
  133. function GetButtonTop: Integer;
  134. function GetCaptionFontSize: Integer;
  135. procedure SetCaptionFontSize(const Value: Integer);
  136. procedure SetRgnSize(const Value: Integer);
  137. function GetRgnSize: Integer;
  138. function GetButtonBmp: TBitmap;
  139. function GetCheckBmp: TBitmap;
  140. function GetComboBmp: TBitmap;
  141. function GetRadioBmp: TBitmap;
  142. procedure SetButtonBmp(const Value: TBitmap);
  143. procedure SetCheckBmp(const Value: TBitmap);
  144. procedure SetComboBmp(const Value: TBitmap);
  145. procedure SetRadioBmp(const Value: TBitmap);
  146. function GetWindowBmp: TBitmap;
  147. function GetWindowBtnBmp: TBitmap;
  148. procedure SetWindowBmp(const Value: TBitmap);
  149. procedure SetWindowBtnBmp(const Value: TBitmap);
  150. public
  151. constructor Create(AOwner: TComponent); override;
  152. destructor Destroy; override;
  153. procedure Assign(Source: TPersistent); override;
  154. procedure InitConsts; virtual;
  155. procedure InitResources; virtual;
  156. procedure Clear;
  157. published
  158. property FaceColor: TColor read GetFaceColor write SetFaceColor;
  159. {* 窗体表面颜色 }
  160. property LightColor: TColor read GetLightColor write SetLightColor;
  161. {* 高亮颜色 }
  162. property ShadowColor: TColor read GetShadowColor write SetShadowColor;
  163. {* 阴影颜色 }
  164. property MenuHotColor: TColor read GetMenuHotColor write SetMenuHotColor;
  165. {* 菜单高亮颜色 }
  166. property ActiveCaptionColor: TColor read GetActiveCaptionColor write SetActiveCaptionColor;
  167. {* 活动窗体的标题颜色 }
  168. property InActiveCaptionColor: TColor read GetInActiveCaptionColor write SetInActiveCaptionColor;
  169. {* 非活动窗体的标题颜色 }
  170. property CaptionHeight: Integer read GetCaptionHeight write SetCaptionHeight;
  171. {* 标题栏高度 }
  172. property BorderSize: Integer read GetBorderSize write SetBorderSize;
  173. {* 窗体边框粗细 }
  174. property ButtonSize: Integer read GetButtonSize write SetButtonSize;
  175. {* 单个标题按钮的尺寸 }
  176. property ButtonTop: Integer read GetButtonTop write SetButtonTop;
  177. {* 标题按钮距顶端的尺寸 }
  178. property ButtonRight: Integer read GetButtonRight write SetButtonRight;
  179. {* 标题按钮距右边的尺寸 }
  180. property CaptionFontSize: Integer read GetCaptionFontSize write SetCaptionFontSize;
  181. {* 标题栏文字尺寸 }
  182. property RgnSize: Integer read GetRgnSize write SetRgnSize;
  183. {* 区域尺寸 }
  184. property WindowBmp: TBitmap read GetWindowBmp write SetWindowBmp;
  185. {* 标题栏背景图片 }
  186. property WindowBtnBmp: TBitmap read GetWindowBtnBmp write SetWindowBtnBmp;
  187. {* 窗体系统按钮图片 }
  188. property ScrollBarBmp: TBitmap read GetScrollBarBmp write SetScrollBarBmp;
  189. {* 滚动条的图片 }
  190. property ButtonBmp: TBitmap read GetButtonBmp write SetButtonBmp;
  191. {* 普通按钮图片 }
  192. property CheckBmp: TBitmap read GetCheckBmp write SetCheckBmp;
  193. {* 复选框图片 }
  194. property RadioBmp: TBitmap read GetRadioBmp write SetRadioBmp;
  195. {* 单选钮图片 }
  196. property ComboBmp: TBitmap read GetComboBmp write SetComboBmp;
  197. {* 下拉框图片 }
  198. end;
  199. TCnSkinXPStyle = class(TCnSkinStyle)
  200. public
  201. constructor Create(AOwner: TComponent); override;
  202. procedure InitConsts; override;
  203. procedure InitResources; override;
  204. published
  205. end;
  206. procedure CnReadBmpFromResource(Bmp: TBitmap; const ResName: string);
  207. {* 从资源读入需要的图片}
  208. implementation
  209. uses
  210. CnSkinTheme;
  211. procedure CnReadBmpFromResource(Bmp: TBitmap; const ResName: string);
  212. var
  213. Stream: TResourceStream;
  214. begin
  215. if (Bmp <> nil) and (ResName <> '') then
  216. begin
  217. Stream := TResourceStream.Create(HInstance, ResName, 'BMP');
  218. try
  219. Bmp.LoadFromStream(Stream);
  220. finally
  221. Stream.Free;
  222. end;
  223. end;
  224. end;
  225. { TCnSkinStyle }
  226. procedure TCnSkinStyle.Assign(Source: TPersistent);
  227. var
  228. ASkinStyle: TCnSkinStyle;
  229. begin
  230. if Source is TCnSkinStyle then
  231. begin
  232. ASkinStyle := (Source as TCnSkinStyle);
  233. FaceColor := ASkinStyle.FaceColor;
  234. LightColor := ASkinStyle.LightColor;
  235. ShadowColor := ASkinStyle.ShadowColor;
  236. MenuHotColor := ASkinStyle.MenuHotColor;
  237. ActiveCaptionColor := ASkinStyle.ActiveCaptionColor;
  238. InActiveCaptionColor := ASkinStyle.InActiveCaptionColor;
  239. CaptionHeight := ASkinStyle.CaptionHeight;
  240. BorderSize := ASkinStyle.BorderSize;
  241. ButtonSize := ASkinStyle.ButtonSize;
  242. ButtonTop := ASkinStyle.ButtonTop;
  243. ButtonRight := ASkinStyle.ButtonRight;
  244. CaptionFontSize := ASkinStyle.CaptionFontSize;
  245. RgnSize := ASkinStyle.RgnSize;
  246. WindowBmp.Assign(ASkinStyle.WindowBmp);
  247. WindowBtnBmp.Assign(ASkinStyle.WindowBtnBmp);
  248. ScrollBarBmp.Assign(ASkinStyle.ScrollBarBmp);
  249. ButtonBmp.Assign(ASkinStyle.ButtonBmp);
  250. CheckBmp.Assign(ASkinStyle.CheckBmp);
  251. RadioBmp.Assign(ASkinStyle.RadioBmp);
  252. ComboBmp.Assign(ASkinStyle.ComboBmp);
  253. end
  254. else
  255. inherited;
  256. end;
  257. procedure TCnSkinStyle.Clear;
  258. begin
  259. end;
  260. constructor TCnSkinStyle.Create(AOwner: TComponent);
  261. begin
  262. inherited;
  263. FWindowBmp := TBitmap.Create;
  264. FWindowBtnBmp := TBitmap.Create;
  265. FScrollBarBmp := TBitmap.Create;
  266. FButtonBmp := TBitmap.Create;
  267. FCheckBmp := TBitmap.Create;
  268. FRadioBmp := TBitmap.Create;
  269. FComboBmp := TBitmap.Create;
  270. InitConsts;
  271. InitResources;
  272. CnSkinThemes.AddSkin(Self);
  273. end;
  274. destructor TCnSkinStyle.Destroy;
  275. begin
  276. FComboBmp.Free;
  277. FRadioBmp.Free;
  278. FCheckBmp.Free;
  279. FButtonBmp.Free;
  280. FScrollBarBmp.Free;
  281. FWindowBtnBmp.Free;
  282. FWindowBmp.Free;
  283. inherited;
  284. end;
  285. function TCnSkinStyle.GetActiveCaptionColor: TColor;
  286. begin
  287. Result := FActiveCaptionColor;
  288. end;
  289. function TCnSkinStyle.GetBorderSize: Integer;
  290. begin
  291. Result := FBorderSize;
  292. end;
  293. function TCnSkinStyle.GetButtonBmp: TBitmap;
  294. begin
  295. Result := FButtonBmp;
  296. end;
  297. function TCnSkinStyle.GetButtonRight: Integer;
  298. begin
  299. Result := FButtonRight;
  300. end;
  301. function TCnSkinStyle.GetButtonSize: Integer;
  302. begin
  303. Result := FButtonSize;
  304. end;
  305. function TCnSkinStyle.GetButtonTop: Integer;
  306. begin
  307. Result := FButtonTop;
  308. end;
  309. function TCnSkinStyle.GetCaptionFontSize: Integer;
  310. begin
  311. Result := FCaptionFontSize;
  312. end;
  313. function TCnSkinStyle.GetCaptionHeight: Integer;
  314. begin
  315. Result := FCaptionHeight;
  316. end;
  317. function TCnSkinStyle.GetCheckBmp: TBitmap;
  318. begin
  319. Result := FCheckBmp;
  320. end;
  321. function TCnSkinStyle.GetComboBmp: TBitmap;
  322. begin
  323. Result := FComboBmp;
  324. end;
  325. function TCnSkinStyle.GetFaceColor: TColor;
  326. begin
  327. Result := FFaceColor;
  328. end;
  329. function TCnSkinStyle.GetInActiveCaptionColor: TColor;
  330. begin
  331. Result := FInActiveCaptionColor;
  332. end;
  333. function TCnSkinStyle.GetLightColor: TColor;
  334. begin
  335. Result := FLightColor;
  336. end;
  337. function TCnSkinStyle.GetMenuHotColor: TColor;
  338. begin
  339. Result := FMenuHotColor;
  340. end;
  341. function TCnSkinStyle.GetRadioBmp: TBitmap;
  342. begin
  343. Result := FRadioBmp;
  344. end;
  345. function TCnSkinStyle.GetRgnSize: Integer;
  346. begin
  347. Result := FRgnSize;
  348. end;
  349. function TCnSkinStyle.GetScrollBarBmp: TBitmap;
  350. begin
  351. Result := FScrollBarBmp;
  352. end;
  353. function TCnSkinStyle.GetShadowColor: TColor;
  354. begin
  355. Result := FShadowColor;
  356. end;
  357. function TCnSkinStyle.GetWindowBmp: TBitmap;
  358. begin
  359. Result := FWindowBmp;
  360. end;
  361. function TCnSkinStyle.GetWindowBtnBmp: TBitmap;
  362. begin
  363. Result := FWindowBtnBmp;
  364. end;
  365. procedure TCnSkinStyle.InitConsts;
  366. begin
  367. // 初始化变量
  368. FShadowColor := clBtnShadow;
  369. FLightColor := clBtnHighLight;
  370. FFaceColor := clBtnFace;
  371. FMenuHotColor := clMenuHighlight;
  372. FCaptionHeight := 26;
  373. FBorderSize := 0;
  374. FButtonSize := 16;
  375. FButtonRight := 5;
  376. FButtonTop := 3;
  377. FCaptionFontSize := 11;
  378. FRgnSize := 0;
  379. end;
  380. procedure TCnSkinStyle.InitResources;
  381. begin
  382. // 基类啥都不干
  383. end;
  384. procedure TCnSkinStyle.SetActiveCaptionColor(const Value: TColor);
  385. begin
  386. if FActiveCaptionColor <> Value then
  387. begin
  388. FActiveCaptionColor := Value;
  389. end;
  390. end;
  391. procedure TCnSkinStyle.SetBorderSize(const Value: Integer);
  392. begin
  393. FBorderSize := Value;
  394. end;
  395. procedure TCnSkinStyle.SetButtonBmp(const Value: TBitmap);
  396. begin
  397. FButtonBmp.Assign(Value);
  398. end;
  399. procedure TCnSkinStyle.SetButtonRight(const Value: Integer);
  400. begin
  401. FButtonRight := Value;
  402. end;
  403. procedure TCnSkinStyle.SetButtonSize(const Value: Integer);
  404. begin
  405. FButtonSize := Value;
  406. end;
  407. procedure TCnSkinStyle.SetButtonTop(const Value: Integer);
  408. begin
  409. FButtonTop := Value;
  410. end;
  411. procedure TCnSkinStyle.SetCaptionFontSize(const Value: Integer);
  412. begin
  413. FCaptionFontSize := Value;
  414. end;
  415. procedure TCnSkinStyle.SetCaptionHeight(const Value: Integer);
  416. begin
  417. FCaptionHeight := Value;
  418. end;
  419. procedure TCnSkinStyle.SetCheckBmp(const Value: TBitmap);
  420. begin
  421. FCheckBmp.Assign(Value);
  422. end;
  423. procedure TCnSkinStyle.SetComboBmp(const Value: TBitmap);
  424. begin
  425. FComboBmp.Assign(Value);
  426. end;
  427. procedure TCnSkinStyle.SetFaceColor(const Value: TColor);
  428. begin
  429. FFaceColor := Value;
  430. end;
  431. procedure TCnSkinStyle.SetInActiveCaptionColor(const Value: TColor);
  432. begin
  433. if FInActiveCaptionColor <> Value then
  434. begin
  435. FInActiveCaptionColor := Value;
  436. end;
  437. end;
  438. procedure TCnSkinStyle.SetLightColor(const Value: TColor);
  439. begin
  440. FLightColor := Value;
  441. end;
  442. procedure TCnSkinStyle.SetMenuHotColor(const Value: TColor);
  443. begin
  444. FMenuHotColor := Value;
  445. end;
  446. procedure TCnSkinStyle.SetRadioBmp(const Value: TBitmap);
  447. begin
  448. FRadioBmp.Assign(Value);
  449. end;
  450. procedure TCnSkinStyle.SetRgnSize(const Value: Integer);
  451. begin
  452. FRgnSize := Value;
  453. end;
  454. procedure TCnSkinStyle.SetScrollBarBmp(const Value: TBitmap);
  455. begin
  456. FScrollBarBmp.Assign(Value);
  457. end;
  458. procedure TCnSkinStyle.SetShadowColor(const Value: TColor);
  459. begin
  460. FShadowColor := Value;
  461. end;
  462. procedure TCnSkinStyle.SetWindowBmp(const Value: TBitmap);
  463. begin
  464. FWindowBmp.Assign(Value);
  465. end;
  466. procedure TCnSkinStyle.SetWindowBtnBmp(const Value: TBitmap);
  467. begin
  468. FWindowBtnBmp.Assign(Value);
  469. end;
  470. { TCnSkinXPStyle }
  471. constructor TCnSkinXPStyle.Create(AOwner: TComponent);
  472. begin
  473. inherited;
  474. end;
  475. procedure TCnSkinXPStyle.InitConsts;
  476. begin
  477. inherited;
  478. FCaptionHeight := 30;
  479. FBorderSize := 4;
  480. FButtonRight := 5;
  481. FButtonTop := 5;
  482. FRgnSize := 14;
  483. end;
  484. procedure TCnSkinXPStyle.InitResources;
  485. begin
  486. inherited;
  487. end;
  488. end.