TBXOfficeXPTheme.pas 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. unit TBXOfficeXPTheme;
  2. // TBX Package
  3. // Copyright 2001-2004 Alex A. Denisov. All Rights Reserved
  4. // See TBX.chm for license and installation instructions
  5. //
  6. // Id: TBXOfficeXPTheme.pas 16 2004-05-26 02:02:55Z Alex@ZEISS
  7. interface
  8. {$I TB2Ver.inc}
  9. uses
  10. Windows, Messages, Graphics, TBXThemes, ImgList, Controls, TB2Item, Forms;
  11. type
  12. TItemPart = (ipBody, ipText, ipFrame);
  13. TBtnItemState = (bisNormal, bisDisabled, bisSelected, bisPressed, bisHot,
  14. bisDisabledHot, bisSelectedHot, bisPopupParent);
  15. TMenuItemState = (misNormal, misDisabled, misHot, misDisabledHot);
  16. TWinFramePart = (wfpBorder, wfpCaption, wfpCaptionText);
  17. TWinFrameState = (wfsActive, wfsInactive);
  18. TTBXOfficeXPTheme = class(TTBXTheme)
  19. private
  20. procedure TBXSysCommand(var Message: TMessage); message TBX_SYSCOMMAND;
  21. protected
  22. { View/Window Colors }
  23. MenubarColor: TColor;
  24. ToolbarColor: TColor;
  25. PopupColor: TColor;
  26. DockPanelColor: TColor;
  27. PopupFrameColor: TColor;
  28. WinFrameColors: array [TWinFrameState, TWinFramePart] of TColor;
  29. PnlFrameColors: array [TWinFrameState, TWinFramePart] of TColor;
  30. MenuItemColors: array [TMenuItemState, TItemPart] of TColor;
  31. BtnItemColors: array [TBtnItemState, TItemPart] of TColor;
  32. { Other Colors }
  33. DragHandleColor: TColor;
  34. PopupSeparatorColor: TColor;
  35. ToolbarSeparatorColor: TColor;
  36. IconShadowColor: TColor;
  37. StatusPanelFrameColor: TColor;
  38. FDark: Boolean;
  39. procedure SetupColorCache; virtual;
  40. protected
  41. { Internal Methods }
  42. function GetPartColor(const ItemInfo: TTBXItemInfo; ItemPart: TItemPart): TColor;
  43. function GetBtnColor(const ItemInfo: TTBXItemInfo; ItemPart: TItemPart): TColor;
  44. function GetStandardColor(Color: TColor): TColor;
  45. procedure Init;
  46. constructor CreateEx(const AName: string; Dark: Boolean); overload;
  47. public
  48. constructor Create(const AName: string); overload; override;
  49. destructor Destroy; override;
  50. { Metrics access}
  51. function GetBooleanMetrics(Index: Integer): Boolean; override;
  52. function GetIntegerMetrics(Monitor: TMonitor; Index: Integer): Integer; override;
  53. procedure GetMargins(MarginID: Integer; out Margins: TTBXMargins); override;
  54. function GetImageOffset(Canvas: TCanvas; const ItemInfo: TTBXItemInfo; ImageList: TCustomImageList): TPoint; override;
  55. function GetItemColor(const ItemInfo: TTBXItemInfo): TColor; override;
  56. function GetItemTextColor(const ItemInfo: TTBXItemInfo): TColor; override;
  57. function GetItemImageBackground(const ItemInfo: TTBXItemInfo): TColor; override;
  58. function GetPopupShadowType: Integer; override;
  59. procedure GetViewBorder(Control: TControl; ViewType: Integer; out Border: TPoint); override;
  60. function GetViewColor(AViewType: Integer): TColor; override;
  61. procedure GetViewMargins(ViewType: Integer; out Margins: TTBXMargins); override;
  62. function GetSysColor(nIndex: Integer): DWORD; override;
  63. { Painting routines }
  64. procedure PaintBackgnd(Canvas: TCanvas; const ADockRect, ARect, AClipRect: TRect; AColor: TColor; Transparent: Boolean; AViewType: Integer); override;
  65. procedure PaintButton(Canvas: TCanvas; const ARect: TRect; const ItemInfo: TTBXItemInfo); override;
  66. procedure PaintCaption(Canvas: TCanvas; const ARect: TRect; const ItemInfo: TTBXItemInfo; const ACaption: string; AFormat: Cardinal; Rotated: Boolean); override;
  67. procedure PaintCheckMark(Canvas: TCanvas; ARect: TRect; const ItemInfo: TTBXItemInfo); override;
  68. procedure PaintChevron(Canvas: TCanvas; ARect: TRect; const ItemInfo: TTBXItemInfo); override;
  69. procedure PaintDock(Canvas: TCanvas; const ClientRect, DockRect: TRect; DockPosition: Integer); override;
  70. procedure PaintDropDownArrow(Canvas: TCanvas; const ARect: TRect; const ItemInfo: TTBXItemInfo); override;
  71. procedure PaintEditButton(Canvas: TCanvas; const ARect: TRect; var ItemInfo: TTBXItemInfo; ButtonInfo: TTBXEditBtnInfo); override;
  72. procedure PaintEditFrame(Monitor: TMonitor; Canvas: TCanvas; const ARect: TRect; var ItemInfo: TTBXItemInfo; const EditInfo: TTBXEditInfo); override;
  73. procedure PaintFloatingBorder(Canvas: TCanvas; const ARect: TRect; const WindowInfo: TTBXWindowInfo); override;
  74. procedure PaintFrame(Canvas: TCanvas; const ARect: TRect; const ItemInfo: TTBXItemInfo); override;
  75. procedure PaintImage(Canvas: TCanvas; ARect: TRect; const ItemInfo: TTBXItemInfo; ImageList: TCustomImageList; ImageIndex: Integer); override;
  76. procedure PaintMenuItem(Canvas: TCanvas; const ARect: TRect; var ItemInfo: TTBXItemInfo); override;
  77. procedure PaintMenuItemFrame(Canvas: TCanvas; const ARect: TRect; const ItemInfo: TTBXItemInfo); override;
  78. procedure PaintPopupNCArea(Canvas: TCanvas; R: TRect; const PopupInfo: TTBXPopupInfo); override;
  79. procedure PaintSeparator(Canvas: TCanvas; ARect: TRect; ItemInfo: TTBXItemInfo; Horizontal, LineSeparator: Boolean); override;
  80. procedure PaintToolbarNCArea(Monitor: TMonitor; Canvas: TCanvas; R: TRect; const ToolbarInfo: TTBXToolbarInfo); override;
  81. procedure PaintStatusBar(Control: TWinControl; Canvas: TCanvas; R: TRect; Part: Integer); override;
  82. end;
  83. type
  84. TTBXDarkOfficeXPTheme = class(TTBXOfficeXPTheme)
  85. public
  86. constructor Create(const AName: string); override;
  87. end;
  88. function GetSelectedBodyColor: TColor;
  89. implementation
  90. uses
  91. TBXUtils, TB2Common, Classes, Commctrl, SysUtils,
  92. Types, UITypes, UxTheme, PasTools;
  93. var
  94. StockImgList: TImageList;
  95. CounterLock: Integer;
  96. procedure InitializeStock;
  97. begin
  98. StockImgList := TImageList.Create(nil);
  99. StockImgList.Handle := ImageList_LoadBitmap(HInstance, 'TBXGLYPHS', 16, 0, clWhite);
  100. end;
  101. procedure FinalizeStock;
  102. begin
  103. StockImgList.Free;
  104. end;
  105. { TTBXOfficeXPTheme }
  106. function TTBXOfficeXPTheme.GetBooleanMetrics(Index: Integer): Boolean;
  107. begin
  108. case Index of
  109. TMB_OFFICEXPPOPUPALIGNMENT: Result := True;
  110. TMB_EDITMENUFULLSELECT: Result := True;
  111. TMB_EDITHEIGHTEVEN: Result := False;
  112. TMB_SOLIDTOOLBARNCAREA: Result := False;
  113. else
  114. Result := False;
  115. end;
  116. end;
  117. function TTBXOfficeXPTheme.GetIntegerMetrics(Monitor: TMonitor; Index: Integer): Integer;
  118. const
  119. DEFAULT = -1;
  120. begin
  121. case Index of
  122. TMI_SPLITBTN_ARROWWIDTH: Result := 12;
  123. TMI_DROPDOWN_ARROWWIDTH: Result := 8;
  124. TMI_DROPDOWN_ARROWMARGIN: Result := 3;
  125. TMI_MENU_IMGTEXTSPACE: Result := 5;
  126. TMI_MENU_LCAPTIONMARGIN: Result := 3;
  127. TMI_MENU_RCAPTIONMARGIN: Result := 3;
  128. TMI_MENU_SEPARATORSIZE: Result := 3;
  129. TMI_TLBR_SEPARATORSIZE: Result := 6;
  130. TMI_EDIT_FRAMEWIDTH: Result := 1;
  131. TMI_EDIT_TEXTMARGINHORZ: Result := 2;
  132. TMI_EDIT_TEXTMARGINVERT: Result := 2;
  133. TMI_EDIT_BTNWIDTH: Result := 14;
  134. TMI_EDIT_MENURIGHTINDENT: Result := 1;
  135. else
  136. Result := DEFAULT;
  137. end;
  138. if Result > 0 then
  139. begin
  140. Result := ScaleByPixelsPerInch(Result, Monitor);
  141. end;
  142. end;
  143. function TTBXOfficeXPTheme.GetViewColor(AViewType: Integer): TColor;
  144. begin
  145. Result := clBtnFace;
  146. if (AViewType and VT_TOOLBAR) = VT_TOOLBAR then
  147. begin
  148. if (AViewType and TVT_MENUBAR) = TVT_MENUBAR then Result := MenubarColor
  149. else Result := ToolbarColor;
  150. end
  151. else if (AViewType and VT_POPUP) = VT_POPUP then
  152. begin
  153. if (AViewType and PVT_LISTBOX) = PVT_LISTBOX then Result := GetStandardColor(clWindow)
  154. else Result := PopupColor;
  155. end
  156. else if (AViewType and VT_DOCKPANEL) = VT_DOCKPANEL then Result := DockPanelColor
  157. else if (AViewType and VT_SECTIONHEADER) = VT_SECTIONHEADER then Result := ToolbarColor;
  158. end;
  159. function TTBXOfficeXPTheme.GetBtnColor(const ItemInfo: TTBXItemInfo; ItemPart: TItemPart): TColor;
  160. const
  161. BFlags1: array [Boolean] of TBtnItemState = (bisDisabled, bisDisabledHot);
  162. BFlags2: array [Boolean] of TBtnItemState = (bisSelected, bisSelectedHot);
  163. BFlags3: array [Boolean] of TBtnItemState = (bisNormal, bisHot);
  164. var
  165. B: TBtnItemState;
  166. Embedded: Boolean;
  167. begin
  168. with ItemInfo do
  169. begin
  170. Embedded := (ViewType and VT_TOOLBAR = VT_TOOLBAR) and
  171. (ViewType and TVT_EMBEDDED = TVT_EMBEDDED);
  172. if not Enabled then B := BFlags1[HoverKind = hkKeyboardHover]
  173. else if ItemInfo.IsPopupParent then B := bisPopupParent
  174. else if Pushed then B := bisPressed
  175. else if Selected then B := BFlags2[HoverKind <> hkNone]
  176. else B := BFlags3[HoverKind <> hkNone];
  177. Result := BtnItemColors[B, ItemPart];
  178. if Embedded then
  179. begin
  180. if (ItemPart = ipBody) and (Result = clNone) then Result := ToolbarColor;
  181. if ItemPart = ipFrame then
  182. begin
  183. if Selected then Result := clWindowFrame
  184. else if (Result = clNone) then Result := clBtnShadow;
  185. end;
  186. end;
  187. end;
  188. end;
  189. function TTBXOfficeXPTheme.GetPartColor(const ItemInfo: TTBXItemInfo; ItemPart: TItemPart): TColor;
  190. const
  191. MFlags1: array [Boolean] of TMenuItemState = (misDisabled, misDisabledHot);
  192. MFlags2: array [Boolean] of TMenuItemState = (misNormal, misHot);
  193. BFlags1: array [Boolean] of TBtnItemState = (bisDisabled, bisDisabledHot);
  194. BFlags2: array [Boolean] of TBtnItemState = (bisSelected, bisSelectedHot);
  195. BFlags3: array [Boolean] of TBtnItemState = (bisNormal, bisHot);
  196. var
  197. IsMenuItem, Embedded: Boolean;
  198. M: TMenuItemState;
  199. B: TBtnItemState;
  200. begin
  201. with ItemInfo do
  202. begin
  203. IsMenuItem := ((ViewType and PVT_POPUPMENU) = PVT_POPUPMENU) and
  204. ((ItemOptions and IO_TOOLBARSTYLE) = 0);
  205. Embedded := ((ViewType and VT_TOOLBAR) = VT_TOOLBAR) and
  206. ((ViewType and TVT_EMBEDDED) = TVT_EMBEDDED);
  207. if IsMenuItem then
  208. begin
  209. if not Enabled then M := MFlags1[HoverKind = hkKeyboardHover]
  210. else M := MFlags2[HoverKind <> hkNone];
  211. Result := MenuItemColors[M, ItemPart];
  212. end
  213. else
  214. begin
  215. if not Enabled then B := BFlags1[HoverKind = hkKeyboardHover]
  216. else if ItemInfo.IsPopupParent then B := bisPopupParent
  217. else if Pushed then B := bisPressed
  218. else if Selected then B := BFlags2[HoverKind <> hkNone]
  219. else B := BFlags3[HoverKind <> hkNone];
  220. Result := BtnItemColors[B, ItemPart];
  221. if Embedded and (Result = clNone) then
  222. begin
  223. if ItemPart = ipBody then Result := ToolbarColor;
  224. if ItemPart = ipFrame then Result := clBtnShadow;
  225. end;
  226. end;
  227. end;
  228. end;
  229. function TTBXOfficeXPTheme.GetItemColor(const ItemInfo: TTBXItemInfo): TColor;
  230. begin
  231. Result := GetPartColor(ItemInfo, ipBody);
  232. if Result = clNone then Result := GetViewColor(ItemInfo.ViewType);
  233. end;
  234. function TTBXOfficeXPTheme.GetItemTextColor(const ItemInfo: TTBXItemInfo): TColor;
  235. begin
  236. Result := GetPartColor(ItemInfo, ipText);
  237. end;
  238. function TTBXOfficeXPTheme.GetItemImageBackground(const ItemInfo: TTBXItemInfo): TColor;
  239. begin
  240. Result := GetBtnColor(ItemInfo, ipBody);
  241. if Result = clNone then Result := GetViewColor(ItemInfo.ViewType);
  242. end;
  243. procedure TTBXOfficeXPTheme.GetViewBorder(Control: TControl; ViewType: Integer; out Border: TPoint);
  244. const
  245. XMetrics: array [Boolean] of Integer = (SM_CXDLGFRAME, SM_CXFRAME);
  246. YMetrics: array [Boolean] of Integer = (SM_CYDLGFRAME, SM_CYFRAME);
  247. var
  248. Resizable: Boolean;
  249. procedure SetBorder(X, Y: Integer);
  250. begin
  251. Border.X := X;
  252. Border.Y := Y;
  253. end;
  254. begin
  255. if (ViewType and VT_TOOLBAR) = VT_TOOLBAR then
  256. begin
  257. if (ViewType and TVT_FLOATING) = TVT_FLOATING then
  258. begin
  259. Resizable := (ViewType and TVT_RESIZABLE) = TVT_RESIZABLE;
  260. Border.X := GetSystemMetricsForControl(Control, XMetrics[Resizable]) - 1;
  261. Border.Y := GetSystemMetricsForControl(Control, YMetrics[Resizable]) - 1;
  262. end
  263. else SetBorder(2, 2);
  264. end
  265. else if (ViewType and VT_POPUP) = VT_POPUP then
  266. begin
  267. if (ViewType and PVT_POPUPMENU) = PVT_POPUPMENU then Border.X := 1
  268. else Border.X := 2;
  269. Border.Y := 2;
  270. end
  271. else if (ViewType and VT_DOCKPANEL) = VT_DOCKPANEL then
  272. begin
  273. if (ViewType and DPVT_FLOATING) = DPVT_FLOATING then
  274. begin
  275. Resizable := (ViewType and DPVT_RESIZABLE) = DPVT_RESIZABLE;
  276. Border.X := GetSystemMetricsForControl(Control, XMetrics[Resizable]) - 1;
  277. Border.Y := GetSystemMetricsForControl(Control, YMetrics[Resizable]) - 1;
  278. end
  279. else SetBorder(2, 2);
  280. end
  281. else SetBorder(0, 0);
  282. end;
  283. procedure TTBXOfficeXPTheme.GetMargins(MarginID: Integer; out Margins: TTBXMargins);
  284. begin
  285. with Margins do
  286. case MarginID of
  287. MID_TOOLBARITEM:
  288. begin
  289. LeftWidth := 2; RightWidth := 2;
  290. TopHeight := 2; BottomHeight := 2;
  291. end;
  292. MID_MENUITEM:
  293. begin
  294. LeftWidth := 1; RightWidth := 1;
  295. TopHeight := 3; BottomHeight := 3;
  296. end;
  297. MID_STATUSPANE:
  298. begin
  299. LeftWidth := 1; RightWidth := 3;
  300. TopHeight := 1; BottomHeight := 1;
  301. end;
  302. else
  303. LeftWidth := 0;
  304. RightWidth := 0;
  305. TopHeight := 0;
  306. BottomHeight := 0;
  307. end;
  308. end;
  309. procedure TTBXOfficeXPTheme.PaintBackgnd(Canvas: TCanvas; const ADockRect, ARect, AClipRect: TRect;
  310. AColor: TColor; Transparent: Boolean; AViewType: Integer);
  311. var
  312. DC: HDC;
  313. R: TRect;
  314. begin
  315. DC := Canvas.Handle;
  316. if not Transparent then
  317. begin
  318. IntersectRect(R, ARect, AClipRect);
  319. FillRectEx(DC, R, AColor);
  320. end;
  321. end;
  322. procedure TTBXOfficeXPTheme.PaintCaption(Canvas: TCanvas;
  323. const ARect: TRect; const ItemInfo: TTBXItemInfo; const ACaption: string;
  324. AFormat: Cardinal; Rotated: Boolean);
  325. var
  326. R: TRect;
  327. begin
  328. with ItemInfo, Canvas do
  329. begin
  330. R := ARect;
  331. Brush.Style := bsClear;
  332. if Font.Color = clNone then Font.Color := GetPartColor(ItemInfo, ipText);
  333. if not Rotated then Windows.DrawText(Handle, PChar(ACaption), Length(ACaption), R, AFormat)
  334. else DrawRotatedText(Handle, ACaption, R, AFormat);
  335. Brush.Style := bsSolid;
  336. end;
  337. end;
  338. procedure TTBXOfficeXPTheme.PaintCheckMark(Canvas: TCanvas; ARect: TRect; const ItemInfo: TTBXItemInfo);
  339. var
  340. DC: HDC;
  341. X, Y: Integer;
  342. C: TColor;
  343. Two, Three, Four: Integer;
  344. Diag: Integer;
  345. I: Integer;
  346. begin
  347. Two := TBXScaleByTextHeightRunTime(Canvas, 2);
  348. Three := TBXScaleByTextHeightRunTime(Canvas, 3);
  349. Four := TBXScaleByTextHeightRunTime(Canvas, 4);
  350. DC := Canvas.Handle;
  351. X := (ARect.Left + ARect.Right) div 2 - 1;
  352. Y := (ARect.Top + ARect.Bottom) div 2 + 1;
  353. C := GetBtnColor(ItemInfo, ipText);
  354. if ItemInfo.ItemOptions and IO_RADIO > 0 then
  355. begin
  356. // Should we use SM_CXMENUCHECK to determine the size?
  357. // 10 div 14 is approximation of division by square root of 2 (pythagorean theorem)
  358. Diag := (Three * 10 div 14) + 1;
  359. RoundRectEx(DC, X-Diag+1, Y-Diag-1, X+Diag+1, Y+Diag-1, Four div 2, Four div 2,
  360. MixColors(C, ToolbarColor, 200), C);
  361. // Using Ellipse instead of RoundRect to draw circle was an attempt to draw it nicely on
  362. // high DPI. It didn't work. But using ellipse seems better anyway, so we kept it.
  363. EllipseEx(DC, X-Three+1, Y-Three-1, X+Three+1, Y+Three-1,
  364. C, C);
  365. end
  366. else
  367. begin
  368. for I := 1 to Two do
  369. begin
  370. PolyLineEx(DC, [Point(X-Two, Y-Two+I), Point(X, Y+I), Point(X+Four+1, Y-Four-1+I)], C);
  371. end;
  372. end;
  373. end;
  374. procedure TTBXOfficeXPTheme.PaintChevron(Canvas: TCanvas; ARect: TRect; const ItemInfo: TTBXItemInfo);
  375. const
  376. Pattern: array[Boolean, 0..15] of Byte = (
  377. ($CC, 0, $66, 0, $33, 0, $66, 0, $CC, 0, 0, 0, 0, 0, 0, 0),
  378. ($88, 0, $D8, 0, $70, 0, $20, 0, $88, 0, $D8, 0, $70, 0, $20, 0));
  379. var
  380. R2: TRect;
  381. W, H: Integer;
  382. begin
  383. R2 := ARect;
  384. PaintButton(Canvas, ARect, ItemInfo);
  385. if not ItemInfo.IsVertical then
  386. begin
  387. Inc(R2.Top, 4);
  388. R2.Bottom := R2.Top + 5;
  389. W := 8;
  390. H := 5;
  391. end
  392. else
  393. begin
  394. R2.Left := R2.Right - 9;
  395. R2.Right := R2.Left + 5;
  396. W := 5;
  397. H := 8;
  398. end;
  399. DrawGlyph(Canvas.Handle, R2, W, H, Pattern[ItemInfo.IsVertical][0], GetPartColor(ItemInfo, ipText));
  400. end;
  401. procedure TTBXOfficeXPTheme.PaintEditButton(Canvas: TCanvas; const ARect: TRect;
  402. var ItemInfo: TTBXItemInfo; ButtonInfo: TTBXEditBtnInfo);
  403. var
  404. DC: HDC;
  405. BtnDisabled, BtnHot, BtnPressed, Embedded: Boolean;
  406. R, BR: TRect;
  407. X, Y: Integer;
  408. SaveItemInfoPushed: Boolean;
  409. C: TColor;
  410. begin
  411. DC := Canvas.Handle;
  412. R := ARect;
  413. Embedded := ((ItemInfo.ViewType and VT_TOOLBAR) = VT_TOOLBAR) and
  414. ((ItemInfo.ViewType and TVT_EMBEDDED) = TVT_EMBEDDED);
  415. InflateRect(R, 1, 1);
  416. Inc(R.Left);
  417. with Canvas do
  418. if ButtonInfo.ButtonType = EBT_DROPDOWN then
  419. begin
  420. BtnDisabled := (ButtonInfo.ButtonState and EBDS_DISABLED) <> 0;
  421. BtnHot := (ButtonInfo.ButtonState and EBDS_HOT) <> 0;
  422. BtnPressed := (ButtonInfo.ButtonState and EBDS_PRESSED) <> 0;
  423. if not BtnDisabled then
  424. begin
  425. if BtnPressed or BtnHot or Embedded then PaintButton(Canvas, R, ItemInfo)
  426. else if (ItemInfo.ViewType and VT_TOOLBAR) = VT_TOOLBAR then
  427. begin
  428. R := ARect;
  429. if not Embedded then
  430. begin
  431. FrameRectEx(DC, R, GetStandardColor(clWindow), False);
  432. C := GetStandardColor(clWindow);
  433. end
  434. else C := GetBtnColor(ItemInfo, ipFrame);
  435. DrawLineEx(DC, R.Left - 1, R.Top, R.Left - 1, R.Bottom, C);
  436. end;
  437. end;
  438. PaintDropDownArrow(Canvas, R, ItemInfo);
  439. end
  440. else if ButtonInfo.ButtonType = EBT_SPIN then
  441. begin
  442. BtnDisabled := (ButtonInfo.ButtonState and EBSS_DISABLED) <> 0;
  443. BtnHot := (ButtonInfo.ButtonState and EBSS_HOT) <> 0;
  444. { Upper button }
  445. BR := R;
  446. BR.Bottom := (R.Top + R.Bottom + 1) div 2;
  447. BtnPressed := (ButtonInfo.ButtonState and EBSS_UP) <> 0;
  448. SaveItemInfoPushed := ItemInfo.Pushed;
  449. ItemInfo.Pushed := BtnPressed;
  450. if not BtnDisabled then
  451. begin
  452. if BtnPressed or BtnHot or Embedded then PaintButton(Canvas, BR, ItemInfo)
  453. else if (ItemInfo.ViewType and VT_TOOLBAR) = VT_TOOLBAR then
  454. begin
  455. BR.Left := ARect.Left; BR.Top := ARect.Top; BR.Right := ARect.Right;
  456. if not Embedded then
  457. begin
  458. FrameRectEx(DC, BR, GetStandardColor(clWindow), False);
  459. C := GetStandardColor(clWindow);
  460. end
  461. else C := GetBtnColor(ItemInfo, ipFrame);
  462. DrawLineEx(DC, BR.Left - 1, BR.Top, BR.Left - 1, BR.Bottom, C);
  463. end;
  464. end;
  465. X := (BR.Left + BR.Right) div 2;
  466. Y := (BR.Top + BR.Bottom - 1) div 2;
  467. Pen.Color := GetPartColor(ItemInfo, ipText);
  468. Brush.Color := Pen.Color;
  469. Polygon([Point(X - 2, Y + 1), Point(X + 2, Y + 1), Point(X, Y - 1)]);
  470. { Lower button }
  471. BR := R;
  472. BR.Top := (R.Top + R.Bottom) div 2;
  473. BtnPressed := (ButtonInfo.ButtonState and EBSS_DOWN) <> 0;
  474. ItemInfo.Pushed := BtnPressed;
  475. if not BtnDisabled then
  476. begin
  477. if BtnPressed or BtnHot or Embedded then PaintButton(Canvas, BR, ItemInfo)
  478. else if (ItemInfo.ViewType and VT_TOOLBAR) = VT_TOOLBAR then
  479. begin
  480. BR.Left := ARect.Left; BR.Bottom := ARect.Bottom; BR.Right := ARect.Right;
  481. if not Embedded then
  482. begin
  483. FrameRectEx(DC, BR, GetStandardColor(clWindow), False);
  484. C := GetStandardColor(clWindow);
  485. end
  486. else C := GetBtnColor(ItemInfo, ipFrame);
  487. DrawLineEx(DC, BR.Left - 1, BR.Top, BR.Left - 1, BR.Bottom, C);
  488. end;
  489. end;
  490. X := (BR.Left + BR.Right) div 2;
  491. Y := (BR.Top + BR.Bottom) div 2;
  492. C := GetPartColor(ItemInfo, ipText);
  493. PolygonEx(DC, [Point(X - 2, Y - 1), Point(X + 2, Y - 1), Point(X, Y + 1)], C, C);
  494. ItemInfo.Pushed := SaveItemInfoPushed;
  495. end;
  496. end;
  497. procedure TTBXOfficeXPTheme.PaintEditFrame(Monitor: TMonitor; Canvas: TCanvas;
  498. const ARect: TRect; var ItemInfo: TTBXItemInfo; const EditInfo: TTBXEditInfo);
  499. var
  500. DC: HDC;
  501. R: TRect;
  502. W: Integer;
  503. Embedded: Boolean;
  504. begin
  505. DC := Canvas.Handle;
  506. R := ARect;
  507. PaintFrame(Canvas, R, ItemInfo);
  508. W := GetIntegerMetrics(Monitor, TMI_EDIT_FRAMEWIDTH);
  509. InflateRect(R, -W, -W);
  510. Embedded := ((ItemInfo.ViewType and VT_TOOLBAR) = VT_TOOLBAR) and
  511. ((ItemInfo.ViewType and TVT_EMBEDDED) = TVT_EMBEDDED);
  512. if not (ItemInfo.Enabled or Embedded) then
  513. FrameRectEx(DC, R, BtnItemColors[bisDisabled, ipText], False);
  514. with EditInfo do if RightBtnWidth > 0 then Dec(R.Right, RightBtnWidth - 2);
  515. if ItemInfo.Enabled then
  516. begin
  517. if ((ItemInfo.ViewType and VT_TOOLBAR) <> VT_TOOLBAR) and (GetPartColor(ItemInfo, ipFrame) = clNone) then
  518. FrameRectEx(DC, R, ToolbarColor, False)
  519. else
  520. FrameRectEx(DC, R, GetStandardColor(clWindow), False);
  521. InflateRect(R, -1, -1);
  522. FillRectEx(DC, R, GetStandardColor(clWindow));
  523. if ((ItemInfo.ViewType and VT_TOOLBAR) <> VT_TOOLBAR) and (GetPartColor(ItemInfo, ipFrame) = clNone) then
  524. begin
  525. R := ARect;
  526. InflateRect(R, -1, -1);
  527. FrameRectEx(DC, R, ToolbarColor, False);
  528. end;
  529. end
  530. else InflateRect(R, -1, -1);
  531. with EditInfo do if LeftBtnWidth > 0 then Inc(R.Left, LeftBtnWidth - 2);
  532. if EditInfo.RightBtnWidth > 0 then
  533. begin
  534. R := ARect;
  535. InflateRect(R, -W, -W);
  536. R.Left := R.Right - EditInfo.RightBtnWidth;
  537. PaintEditButton(Canvas, R, ItemInfo, EditInfo.RightBtnInfo);
  538. end;
  539. end;
  540. procedure TTBXOfficeXPTheme.PaintDropDownArrow(Canvas: TCanvas;
  541. const ARect: TRect; const ItemInfo: TTBXItemInfo);
  542. var
  543. X, Y: Integer;
  544. Two: Integer;
  545. begin
  546. // See TThemePageControl::DrawTabItem with ttbDropDown
  547. with ARect, Canvas do
  548. begin
  549. X := (Left + Right) div 2;
  550. Y := (Top + Bottom) div 2 - 1;
  551. Pen.Color := GetPartColor(ItemInfo, ipText);
  552. Brush.Color := Pen.Color;
  553. Two := TBXScaleByTextHeightRunTime(Canvas, 2);
  554. if ItemInfo.IsVertical then Polygon([Point(X, Y + Two), Point(X, Y - Two), Point(X - Two, Y)])
  555. else Polygon([Point(X - Two, Y), Point(X + Two, Y), Point(X, Y + Two)]);
  556. end;
  557. end;
  558. procedure TTBXOfficeXPTheme.PaintButton(Canvas: TCanvas; const ARect: TRect; const ItemInfo: TTBXItemInfo);
  559. var
  560. DC: HDC;
  561. R: TRect;
  562. begin
  563. DC := Canvas.Handle;
  564. with ItemInfo do
  565. begin
  566. R := ARect;
  567. if ((ItemOptions and IO_DESIGNING) <> 0) and not Selected then
  568. begin
  569. if ComboPart = cpSplitRight then Dec(R.Left);
  570. FrameRectEx(DC, R, GetNearestColor(DC, MixColors(clBtnShadow, clBtnFace, 100)), False);
  571. end
  572. else
  573. begin
  574. FrameRectEx(DC, R, GetBtnColor(ItemInfo, ipFrame), True);
  575. if (ComboPart = cpSplitLeft) and IsPopupParent then Inc(R.Right);
  576. if ComboPart = cpSplitRight then Dec(R.Left);
  577. FillRectEx(DC, R, GetBtnColor(ItemInfo, ipBody));
  578. end;
  579. if ComboPart = cpSplitRight then PaintDropDownArrow(Canvas, R, ItemInfo);
  580. end;
  581. end;
  582. procedure TTBXOfficeXPTheme.PaintFloatingBorder(Canvas: TCanvas; const ARect: TRect;
  583. const WindowInfo: TTBXWindowInfo);
  584. const
  585. WinStates: array [Boolean] of TWinFramestate = (wfsInactive, wfsActive);
  586. function GetBtnItemState(BtnState: Integer): TBtnItemState;
  587. begin
  588. if not WindowInfo.Active then Result := bisDisabled
  589. else if (BtnState and CDBS_PRESSED) <> 0 then Result := bisPressed
  590. else if (BtnState and CDBS_HOT) <> 0 then Result := bisHot
  591. else Result := bisNormal;
  592. end;
  593. var
  594. WinState: TWinFrameState;
  595. BtnItemState: TBtnItemState;
  596. SaveIndex, X, Y: Integer;
  597. Sz: TPoint;
  598. R: TRect;
  599. BodyColor, CaptionColor, CaptionText: TColor;
  600. IsDockPanel: Boolean;
  601. begin
  602. with Canvas do
  603. begin
  604. WinState := WinStates[WindowInfo.Active];
  605. IsDockPanel := (WindowInfo.ViewType and VT_DOCKPANEL) = VT_DOCKPANEL;
  606. BodyColor := Brush.Color;
  607. if (WRP_BORDER and WindowInfo.RedrawPart) <> 0 then
  608. begin
  609. R := ARect;
  610. if not IsDockPanel then Brush.Color := WinFrameColors[WinState, wfpBorder]
  611. else Brush.Color := PnlFrameColors[WinState, wfpBorder];
  612. SaveIndex := SaveDC(Canvas.Handle);
  613. Sz := WindowInfo.FloatingBorderSize;
  614. with R, Sz do ExcludeClipRect(Canvas.Handle, Left + X, Top + Y, Right - X, Bottom - Y);
  615. FillRect(R);
  616. RestoreDC(Canvas.Handle, SaveIndex);
  617. InflateRect(R, -Sz.X, -Sz.Y);
  618. Pen.Color := BodyColor;
  619. with R do
  620. if not IsDockPanel then
  621. Canvas.Polyline([
  622. Point(Left, Top - 1), Point(Right - 1, Top - 1),
  623. Point(Right, Top), Point(Right, Bottom - 1),
  624. Point(Right - 1, Bottom),
  625. Point(Left, Bottom), Point(Left - 1, Bottom - 1),
  626. Point(Left - 1, Top), Point(Left, Top - 1)
  627. ])
  628. else
  629. Canvas.Polyline([
  630. Point(Left, Top - 1), Point(Right - 1, Top - 1),
  631. Point(Right, Top), Point(Right, Bottom),
  632. Point(Left - 1, Bottom),
  633. Point(Left - 1, Top), Point(Left, Top - 1)
  634. ]);
  635. end;
  636. if not WindowInfo.ShowCaption then Exit;
  637. if (WindowInfo.ViewType and VT_TOOLBAR) = VT_TOOLBAR then
  638. begin
  639. CaptionColor := WinFrameColors[WinState, wfpCaption];
  640. CaptionText := WinFrameColors[WinState, wfpCaptionText];
  641. end
  642. else
  643. begin
  644. CaptionColor := PnlFrameColors[WinState, wfpCaption];
  645. CaptionText := PnlFrameColors[WinState, wfpCaptionText];
  646. end;
  647. { Caption }
  648. if (WRP_CAPTION and WindowInfo.RedrawPart) <> 0 then
  649. begin
  650. R := Rect(0, 0, WindowInfo.ClientWidth, GetSystemMetricsForControl(WindowInfo.ParentControl, SM_CYSMCAPTION) - 1);
  651. with WindowInfo.FloatingBorderSize do OffsetRect(R, X, Y);
  652. DrawLineEx(Canvas.Handle, R.Left, R.Bottom, R.Right, R.Bottom, BodyColor);
  653. if ((CDBS_VISIBLE and WindowInfo.CloseButtonState) <> 0) and
  654. ((WRP_CLOSEBTN and WindowInfo.RedrawPart) <> 0) then
  655. Dec(R.Right, GetSystemMetricsForControl(WindowInfo.ParentControl, SM_CYSMCAPTION) - 1);
  656. Brush.Color := CaptionColor;
  657. FillRect(R);
  658. InflateRect(R, -2, 0);
  659. Font.Assign(SmCaptionFont);
  660. Font.Color := CaptionText;
  661. DrawText(Canvas.Handle, WindowInfo.Caption, -1, R,
  662. DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS or DT_NOPREFIX);
  663. end;
  664. { Close button }
  665. if (CDBS_VISIBLE and WindowInfo.CloseButtonState) <> 0 then
  666. begin
  667. R := Rect(0, 0, WindowInfo.ClientWidth, GetSystemMetricsForControl(WindowInfo.ParentControl, SM_CYSMCAPTION) - 1);
  668. with WindowInfo.FloatingBorderSize do OffsetRect(R, X, Y);
  669. R.Left := R.Right - (R.Bottom - R.Top);
  670. DrawLineEx(Canvas.Handle, R.Left - 1, R.Bottom, R.Right, R.Bottom, BodyColor);
  671. Brush.Color := CaptionColor;
  672. FillRect(R);
  673. with R do
  674. begin
  675. X := (Left + Right - StockImgList.Width + 1) div 2;
  676. Y := (Top + Bottom - StockImgList.Height) div 2;
  677. end;
  678. BtnItemState := GetBtnItemState(WindowInfo.CloseButtonState);
  679. FrameRectEx(Canvas.Handle, R, BtnItemColors[BtnItemState, ipFrame], True);
  680. if FillRectEx(Canvas.Handle, R, BtnItemColors[BtnItemState, ipBody]) then
  681. DrawGlyph(Canvas.Handle, X, Y, StockImgList, 0, BtnItemColors[BtnItemState, ipText])
  682. else
  683. DrawGlyph(Canvas.Handle, X, Y, StockImgList, 0, CaptionText);
  684. end;
  685. end;
  686. end;
  687. procedure TTBXOfficeXPTheme.PaintFrame(Canvas: TCanvas; const ARect: TRect;
  688. const ItemInfo: TTBXItemInfo);
  689. var
  690. DC: HDC;
  691. R: TRect;
  692. begin
  693. DC := Canvas.Handle;
  694. R := ARect;
  695. FrameRectEx(DC, R, GetPartColor(ItemInfo, ipFrame), True);
  696. FillRectEx(DC, R, GetPartColor(ItemInfo, ipBody));
  697. end;
  698. function TTBXOfficeXPTheme.GetImageOffset(Canvas: TCanvas;
  699. const ItemInfo: TTBXItemInfo; ImageList: TCustomImageList): TPoint;
  700. begin
  701. Result.X := 0;
  702. if not (ImageList is TTBCustomImageList) then
  703. with ItemInfo do
  704. if Enabled and (HoverKind <> hkNone) and
  705. not (Selected or Pushed and not IsPopupParent) then
  706. Result.X := -1;
  707. Result.Y := Result.X
  708. end;
  709. procedure TTBXOfficeXPTheme.PaintImage(Canvas: TCanvas; ARect: TRect;
  710. const ItemInfo: TTBXItemInfo; ImageList: TCustomImageList; ImageIndex: Integer);
  711. var
  712. HiContrast: Boolean;
  713. begin
  714. with ItemInfo do
  715. begin
  716. if ImageList is TTBCustomImageList then
  717. begin
  718. TTBCustomImageList(ImageList).DrawState(Canvas, ARect.Left, ARect.Top,
  719. ImageIndex, Enabled, (HoverKind <> hkNone), Selected);
  720. Exit;
  721. end;
  722. if not Enabled then
  723. begin
  724. HiContrast := (not FDark) and (ColorIntensity(GetItemImageBackground(ItemInfo)) < 80);
  725. if not HiContrast then
  726. DrawTBXIconShadow(Canvas, ARect, ImageList, ImageIndex, 0)
  727. else
  728. DrawTBXIconFlatShadow(Canvas, ARect, ImageList, ImageIndex, clBtnShadow);
  729. end
  730. else if Selected or Pushed or (HoverKind <> hkNone) then
  731. begin
  732. if not (Selected or Pushed and not IsPopupParent) then
  733. begin
  734. DrawTBXIconShadow(Canvas, ARect, ImageList, ImageIndex, 1);
  735. OffsetRect(ARect, 1, 1);
  736. DrawTBXIconShadow(Canvas, ARect, ImageList, ImageIndex, 1);
  737. OffsetRect(ARect, -2, -2);
  738. end;
  739. DrawTBXIcon(Canvas, ARect, ImageList, ImageIndex);
  740. end
  741. else
  742. DrawTBXIcon(Canvas, ARect, ImageList, ImageIndex)
  743. end;
  744. end;
  745. procedure TTBXOfficeXPTheme.PaintMenuItemFrame(Canvas: TCanvas;
  746. const ARect: TRect; const ItemInfo: TTBXItemInfo);
  747. var
  748. R: TRect;
  749. begin
  750. R := ARect;
  751. if (ItemInfo.ViewType and PVT_TOOLBOX) <> PVT_TOOLBOX then with Canvas do
  752. begin
  753. R.Right := R.Left + ItemInfo.PopupMargin + 2;
  754. Brush.Color := ToolbarColor;
  755. FillRect(R);
  756. Inc(R.Left);
  757. R.Right := ARect.Right - 1;
  758. end;
  759. PaintFrame(Canvas, R, ItemInfo);
  760. end;
  761. procedure TTBXOfficeXPTheme.PaintMenuItem(Canvas: TCanvas; const ARect: TRect; var ItemInfo: TTBXItemInfo);
  762. var
  763. DC: HDC;
  764. R: TRect;
  765. X, Y: Integer;
  766. ArrowWidth: Integer;
  767. C, ClrText: TColor;
  768. begin
  769. DC := Canvas.Handle;
  770. with ItemInfo do
  771. begin
  772. ArrowWidth := GetSystemMetricsForControl(ItemInfo.Control, SM_CXMENUCHECK);
  773. PaintMenuItemFrame(Canvas, ARect, ItemInfo);
  774. ClrText := GetPartColor(ItemInfo, ipText);
  775. R := ARect;
  776. if (ItemOptions and IO_COMBO) <> 0 then
  777. begin
  778. // WinSCP: One pixel to the right (+ 1) to make combos with keyboard accelerator look better.
  779. // This moves the line into hitarea of the arrow (while it was in hitarea of the command originally)
  780. // Further move would require changes in hitarea testing.
  781. X := R.Right - ArrowWidth - 1 + 1;
  782. if not ItemInfo.Enabled then C := ClrText
  783. else if HoverKind = hkMouseHover then C := GetPartColor(ItemInfo, ipFrame)
  784. else C := PopupSeparatorColor;
  785. DrawLineEx(DC, X, R.Top + 1, X, R.Bottom - 1, C);
  786. end;
  787. if (ItemOptions and IO_SUBMENUITEM) <> 0 then
  788. begin
  789. Y := ARect.Bottom div 2;
  790. X := ARect.Right - ArrowWidth * 2 div 3 - 1;
  791. PolygonEx(DC, [Point(X, Y - (ArrowWidth div 5)), Point(X, Y + (ArrowWidth div 5)), Point(X + (ArrowWidth div 5), Y)], ClrText, ClrText);
  792. end;
  793. if Selected and Enabled then
  794. begin
  795. R := ARect;
  796. R.Left := ARect.Left + 1;
  797. R.Right := R.Left + ItemInfo.PopupMargin;
  798. InflateRect(R, -1, -1);
  799. FrameRectEx(DC, R, GetBtnColor(ItemInfo, ipFrame), True);
  800. FillRectEx(DC, R, GetBtnColor(ItemInfo, ipBody));
  801. end;
  802. end;
  803. end;
  804. procedure TTBXOfficeXPTheme.PaintPopupNCArea(Canvas: TCanvas; R: TRect; const PopupInfo: TTBXPopupInfo);
  805. var
  806. PR: TRect;
  807. begin
  808. with Canvas do
  809. begin
  810. Brush.Color := PopupFrameColor;
  811. FrameRect(R);
  812. InflateRect(R, -1, -1);
  813. Brush.Color := PopupColor;
  814. FillRect(R);
  815. if not IsRectEmpty(PopupInfo.ParentRect) then
  816. begin
  817. PR := PopupInfo.ParentRect;
  818. if not IsRectEmpty(PR) then with PR do
  819. begin
  820. Pen.Color := ToolbarColor;
  821. if Bottom = R.Top then
  822. begin
  823. if Left <= R.Left then Left := R.Left - 1;
  824. if Right >= R.Right then Right := R.Right + 1;
  825. MoveTo(Left + 1, Bottom - 1); LineTo(Right - 1, Bottom- 1);
  826. end
  827. else if Top = R.Bottom then
  828. begin
  829. if Left <= R.Left then Left := R.Left - 1;
  830. if Right >= R.Right then Right := R.Right + 1;
  831. MoveTo(Left + 1, Top); LineTo(Right - 1, Top);
  832. end;
  833. if Right = R.Left then
  834. begin
  835. if Top <= R.Top then Top := R.Top - 1;
  836. if Bottom >= R.Bottom then Bottom := R.Bottom + 1;
  837. MoveTo(Right - 1, Top + 1); LineTo(Right - 1, Bottom - 1);
  838. end
  839. else if Left = R.Right then
  840. begin
  841. if Top <= R.Top then Top := R.Top - 1;
  842. if Bottom >= R.Bottom then Bottom := R.Bottom + 1;
  843. MoveTo(Left, Top + 1); LineTo(Left, Bottom - 1);
  844. end;
  845. end;
  846. end;
  847. end;
  848. end;
  849. procedure TTBXOfficeXPTheme.PaintSeparator(Canvas: TCanvas; ARect: TRect;
  850. ItemInfo: TTBXItemInfo; Horizontal, LineSeparator: Boolean);
  851. var
  852. DC: HDC;
  853. IsToolbox: Boolean;
  854. R: TRect;
  855. C: TColor;
  856. begin
  857. { Note: for blank separators, Enabled = False }
  858. DC := Canvas.Handle;
  859. with ItemInfo, ARect do
  860. begin
  861. if Horizontal then
  862. begin
  863. IsToolbox := (ViewType and PVT_TOOLBOX) = PVT_TOOLBOX;
  864. if ((ItemOptions and IO_TOOLBARSTYLE) = 0) and not IsToolBox then
  865. begin
  866. R := ARect;
  867. R.Right := ItemInfo.PopupMargin + 2;
  868. FillRectEx(DC, R, ToolbarColor);
  869. Inc(Left, ItemInfo.PopupMargin + 9);
  870. C := PopupSeparatorColor;
  871. end
  872. else
  873. C := ToolbarSeparatorColor;
  874. Top := (Top + Bottom) div 2;
  875. if Enabled then DrawLineEx(DC, Left, Top, Right, Top, C);
  876. end
  877. else if Enabled then
  878. begin
  879. Left := (Left + Right) div 2;
  880. DrawLineEx(DC, Left, Top, Left, Bottom, ToolbarSeparatorColor);
  881. end;
  882. end;
  883. end;
  884. procedure DrawButtonBitmap(DC: HDC; R: TRect; Color: TColor);
  885. const
  886. {$IFNDEF SMALL_CLOSE_BUTTON}
  887. Pattern: array [0..15] of Byte =
  888. ($C3, 0, $66, 0, $3C, 0, $18, 0, $3C, 0, $66, 0, $C3, 0, 0, 0);
  889. {$ELSE}
  890. Pattern: array [0..15] of Byte =
  891. (0, 0, $63, 0, $36, 0, $1C, 0, $1C, 0, $36, 0, $63, 0, 0, 0);
  892. {$ENDIF}
  893. begin
  894. DrawGlyph(DC, R, 8, 7, Pattern[0], Color);
  895. end;
  896. procedure TTBXOfficeXPTheme.PaintToolbarNCArea(Monitor: TMonitor; Canvas: TCanvas; R: TRect; const ToolbarInfo: TTBXToolbarInfo);
  897. const
  898. DragHandleOffsets: array [Boolean, DHS_DOUBLE..DHS_SINGLE] of Integer = ((2, 0, 1), (5, 0, 5));
  899. function GetBtnItemState(BtnState: Integer): TBtnItemState;
  900. begin
  901. if (BtnState and CDBS_PRESSED) <> 0 then Result := bisPressed
  902. else if (BtnState and CDBS_HOT) <> 0 then Result := bisHot
  903. else Result := bisNormal;
  904. end;
  905. var
  906. DC: HDC;
  907. Sz: Integer;
  908. R2: TRect;
  909. SaveColor: TColor;
  910. SaveStyle: TBrushStyle;
  911. I: Integer;
  912. BtnVisible, Horz: Boolean;
  913. BtnItemState: TBtnItemState;
  914. Two, Three: Integer;
  915. begin
  916. DC := Canvas.Handle;
  917. with Canvas do
  918. begin
  919. SaveColor := Brush.Color;
  920. SaveStyle := Brush.Style;
  921. if ToolbarInfo.BorderStyle = bsSingle then
  922. begin
  923. I := ColorIntensity(clBtnFace);
  924. if not (TBXLoColor or not (I in [50..254])) or
  925. ((ToolbarInfo.ViewType and TVT_MENUBAR) = TVT_MENUBAR) then
  926. begin
  927. InflateRect(R, -1, -1);
  928. Dec(R.Right); Dec(R.Bottom);
  929. Pen.Color := SaveColor;
  930. Pen.Style := psSolid;
  931. Brush.Color := SaveColor;
  932. Brush.Style := SaveStyle; // should be either bsSolid or bsClear
  933. with R do
  934. Polygon([Point(Left + 1, Top), Point(Right - 1, Top), Point(Right, Top + 1),
  935. Point(Right, Bottom - 1), Point(Right - 1, Bottom), Point(Left + 1, Bottom),
  936. Point(Left, Bottom - 1), Point(Left, Top + 1)]);
  937. Brush.Style := bsSolid;
  938. Inc(R.Left);
  939. Inc(R.Top);
  940. end
  941. else
  942. begin
  943. Brush.Bitmap := AllocPatternBitmap(ToolbarColor, BtnItemColors[bisDisabled, ipText]);
  944. with R do
  945. begin
  946. FillRect(Rect(Left + 1, Top, Right - 1, Top + 1));
  947. FillRect(Rect(Left + 1, Bottom - 1, Right - 1, Bottom));
  948. FillRect(Rect(Left, Top + 1, Left + 1, Bottom - 1));
  949. FillRect(Rect(Right - 1, Top + 1, Right, Bottom - 1));
  950. end;
  951. InflateRect(R, -1, -1);
  952. Brush.Color := SaveColor;
  953. FillRect(R);
  954. end;
  955. end
  956. else
  957. InflateRect(R, -1, -1);
  958. InflateRect(R, -1, -1);
  959. if not ToolbarInfo.AllowDrag then Exit;
  960. BtnVisible := (ToolbarInfo.CloseButtonState and CDBS_VISIBLE) <> 0;
  961. Sz := GetTBXDragHandleSize(ToolbarInfo);
  962. Horz := not ToolbarInfo.IsVertical;
  963. if Horz then R.Right := R.Left + Sz
  964. else R.Bottom := R.Top + Sz;
  965. { Drag Handle }
  966. if ToolbarInfo.DragHandleStyle <> DHS_NONE then
  967. begin
  968. R2 := R;
  969. // Using DPI scaling instead of text-height scaling because
  970. // toolbar NC area pieces are already DPI-scaled in
  971. // TB2Dock initialization section
  972. Two := ScaleByPixelsPerInch(2, Monitor);
  973. Three := ScaleByPixelsPerInch(3, Monitor);
  974. if Horz then
  975. begin
  976. Inc(R2.Left, DragHandleOffsets[BtnVisible, ToolbarInfo.DragHandleStyle]);
  977. if BtnVisible then Inc(R2.Top, Sz - 2);
  978. R2.Right := R2.Left + Three;
  979. end
  980. else
  981. begin
  982. Inc(R2.Top, DragHandleOffsets[BtnVisible, ToolbarInfo.DragHandleStyle]);
  983. if BtnVisible then Dec(R2.Right, Sz - 2);
  984. R2.Bottom := R2.Top + Three;
  985. end;
  986. Pen.Color := DragHandleColor;
  987. if Horz then
  988. begin
  989. I := R2.Top + Three;
  990. while I < R2.Bottom - Three do
  991. begin
  992. MoveTo(R2.Left, I); LineTo(R2.Right, I);
  993. Inc(I, Two);
  994. end;
  995. end
  996. else
  997. begin
  998. I := R2.Left + Three;
  999. while I < R2.Right - Three do
  1000. begin
  1001. MoveTo(I, R2.Top); LineTo(I, R2.Bottom);
  1002. Inc(I, Two);
  1003. end;
  1004. end;
  1005. end;
  1006. { Close button }
  1007. if BtnVisible then
  1008. begin
  1009. R2 := R;
  1010. if Horz then
  1011. begin
  1012. Dec(R2.Right);
  1013. R2.Bottom := R2.Top + R2.Right - R2.Left;
  1014. end
  1015. else
  1016. begin
  1017. Dec(R2.Bottom);
  1018. R2.Left := R2.Right - R2.Bottom + R2.Top;
  1019. end;
  1020. BtnItemState := GetBtnItemState(ToolbarInfo.CloseButtonState);
  1021. FrameRectEx(DC, R2, BtnItemColors[BtnItemState, ipFrame], True);
  1022. FillRectEx(DC, R2, BtnItemColors[BtnItemState, ipBody]);
  1023. DrawButtonBitmap(DC, R2, BtnItemColors[BtnItemState, ipText]);
  1024. end;
  1025. end;
  1026. end;
  1027. procedure TTBXOfficeXPTheme.PaintDock(Canvas: TCanvas; const ClientRect,
  1028. DockRect: TRect; DockPosition: Integer);
  1029. begin
  1030. // this theme does not support dock painting
  1031. end;
  1032. procedure TTBXOfficeXPTheme.SetupColorCache;
  1033. var
  1034. DC: HDC;
  1035. HotBtnFace, DisabledText: TColor;
  1036. procedure Undither(var C: TColor);
  1037. begin
  1038. if C <> clNone then C := GetNearestColor(DC, ColorToRGB(C));
  1039. end;
  1040. begin
  1041. DC := StockCompatibleBitmap.Canvas.Handle;
  1042. if TBXLoColor then
  1043. begin
  1044. { View/Window Colors }
  1045. MenubarColor := clBtnFace;
  1046. ToolbarColor := clBtnFace;
  1047. PopupColor := clWindow;
  1048. DockPanelColor := clWindow;
  1049. StatusPanelFrameColor := clBtnShadow;
  1050. PopupFrameColor := clBtnText;
  1051. WinFrameColors[wfsActive, wfpBorder] := clBtnShadow;
  1052. WinFrameColors[wfsActive, wfpCaption] := clBtnShadow;
  1053. WinFrameColors[wfsActive, wfpCaptionText] := clBtnHighlight;
  1054. WinFrameColors[wfsInactive, wfpBorder] := clBtnShadow;
  1055. WinFrameColors[wfsInactive, wfpCaption] := clBtnShadow;
  1056. WinFrameColors[wfsInactive, wfpCaptionText] := clBtnHighlight;
  1057. PnlFrameColors[wfsActive, wfpBorder] := clBtnShadow;
  1058. PnlFrameColors[wfsActive, wfpCaption] := clBtnFace;
  1059. PnlFrameColors[wfsActive, wfpCaptionText] := clBtnText;
  1060. PnlFrameColors[wfsInactive, wfpBorder] := clBtnShadow;
  1061. PnlFrameColors[wfsInactive, wfpCaption] := clBtnFace;
  1062. PnlFrameColors[wfsInactive, wfpCaptionText] := clBtnText;
  1063. MenuItemColors[misNormal, ipBody] := clNone;
  1064. MenuItemColors[misNormal, ipText] := clWindowText;
  1065. MenuItemColors[misNormal, ipFrame] := clNone;
  1066. MenuItemColors[misDisabled, ipBody] := clNone;
  1067. MenuItemColors[misDisabled, ipText] := clGrayText;
  1068. MenuItemColors[misDisabled, ipFrame] := clNone;
  1069. MenuItemColors[misHot, ipBody] := clWindow;
  1070. MenuItemColors[misHot, ipText] := clWindowtext;
  1071. MenuItemColors[misHot, ipFrame] := clHighlight;
  1072. MenuItemColors[misDisabledHot, ipBody] := clWindow;
  1073. MenuItemColors[misDisabledHot, ipText] := clGrayText;
  1074. MenuItemColors[misDisabledHot, ipFrame] := clHighlight;
  1075. BtnItemColors[bisNormal, ipBody] := clNone;
  1076. BtnItemColors[bisNormal, ipText] := clBtnText;
  1077. BtnItemColors[bisNormal, ipFrame] := clNone;
  1078. BtnItemColors[bisDisabled, ipBody] := clNone;
  1079. BtnItemColors[bisDisabled, ipText] := clBtnShadow;
  1080. BtnItemColors[bisDisabled, ipFrame] := clNone;
  1081. BtnItemColors[bisSelected, ipBody] := clWindow;
  1082. BtnItemColors[bisSelected, ipText] := clWindowText;
  1083. BtnItemColors[bisSelected, ipFrame] := clHighlight;
  1084. BtnItemColors[bisPressed, ipBody] := clHighlight;
  1085. BtnItemColors[bisPressed, ipText] := clHighlightText;
  1086. BtnItemColors[bisPressed, ipFrame] := clHighlight;
  1087. BtnItemColors[bisHot, ipBody] := clWindow;
  1088. BtnItemColors[bisHot, ipText] := clWindowText;
  1089. BtnItemColors[bisHot, ipFrame] := clHighlight;
  1090. BtnItemColors[bisDisabledHot, ipBody] := clWindow;
  1091. BtnItemColors[bisDisabledHot, ipText] := clBtnShadow;
  1092. BtnItemColors[bisDisabledHot, ipFrame] := clHighlight;
  1093. BtnItemColors[bisSelectedHot, ipBody] := clHighlight;
  1094. BtnItemColors[bisSelectedHot, ipText] := clHighlightText;
  1095. BtnItemColors[bisSelectedHot, ipFrame] := clHighlight;
  1096. BtnItemColors[bisPopupParent, ipBody] := clBtnFace;
  1097. BtnItemColors[bisPopupParent, ipText] := clBtnText;
  1098. BtnItemColors[bisPopupParent, ipFrame] := PopupFrameColor;
  1099. { Other Colors }
  1100. DragHandleColor := clBtnText;
  1101. IconShadowColor := clBtnFace;
  1102. PopupSeparatorColor := clBtnShadow;
  1103. ToolbarSeparatorColor := clBtnShadow;
  1104. end
  1105. else
  1106. begin
  1107. { View/Window Colors }
  1108. if not FDark then
  1109. begin
  1110. MenubarColor := clBtnFace;
  1111. ToolbarColor := Blend(clWindow, clBtnFace, 165);
  1112. PopupColor := Blend(clBtnFace, clWindow, 143);
  1113. end
  1114. else
  1115. begin
  1116. MenubarColor := clBlack;
  1117. ToolbarColor := RGB(32, 32, 32);
  1118. PopupColor := RGB(43, 43, 43);
  1119. end;
  1120. DockPanelColor := PopupColor;
  1121. PopupFrameColor := Blend(clBtnText, clBtnShadow, 20);
  1122. SetContrast(PopupFrameColor, PopupColor, 100);
  1123. HotBtnFace := Blend(clHighlight, clWindow, 30);
  1124. SetContrast(HotBtnFace, ToolbarColor, 50);
  1125. DisabledText := Blend(clBtnshadow, clWindow, 90);
  1126. WinFrameColors[wfsActive, wfpBorder] := Blend(clBtnText, clBtnShadow, 15);
  1127. SetContrast(WinFrameColors[wfsActive, wfpBorder], ToolbarColor, 120);
  1128. WinFrameColors[wfsActive, wfpCaption] := clBtnShadow;
  1129. WinFrameColors[wfsActive, wfpCaptionText] := clBtnHighlight;
  1130. SetContrast(WinFrameColors[wfsActive, wfpCaptionText], clBtnShadow, 180);
  1131. WinFrameColors[wfsInactive, wfpBorder] := WinFrameColors[wfsActive, wfpBorder];
  1132. WinFrameColors[wfsInactive, wfpCaption] := clBtnFace;
  1133. WinFrameColors[wfsInactive, wfpCaptionText] := DisabledText;
  1134. SetContrast(WinFrameColors[wfsInactive, wfpCaptionText], clBtnFace, 120);
  1135. PnlFrameColors[wfsActive, wfpBorder] := clBtnShadow;
  1136. PnlFrameColors[wfsActive, wfpCaption] := clBtnFace;
  1137. PnlFrameColors[wfsActive, wfpCaptionText] := clBtnText;
  1138. PnlFrameColors[wfsInactive, wfpBorder] := clBtnShadow;
  1139. PnlFrameColors[wfsInactive, wfpCaption] := clBtnFace;
  1140. PnlFrameColors[wfsInactive, wfpCaptionText] := DisabledText;
  1141. SetContrast(PnlFrameColors[wfsInactive, wfpCaptionText], clBtnFace, 120);
  1142. BtnItemColors[bisNormal, ipBody] := clNone;
  1143. if not FDark then
  1144. BtnItemColors[bisNormal, ipText] := clBtnText
  1145. else
  1146. BtnItemColors[bisNormal, ipText] := clWhite;
  1147. SetContrast(BtnItemColors[bisNormal, ipText], ToolbarColor, 180);
  1148. BtnItemColors[bisNormal, ipFrame] := clNone;
  1149. BtnItemColors[bisDisabled, ipBody] := clNone;
  1150. BtnItemColors[bisDisabled, ipText] := DisabledText;
  1151. SetContrast(BtnItemColors[bisDisabled, ipText], ToolbarColor, 80);
  1152. BtnItemColors[bisDisabled, ipFrame] := clNone;
  1153. if not FDark then
  1154. begin
  1155. BtnItemColors[bisSelected, ipBody] := GetSelectedBodyColor;
  1156. SetContrast(BtnItemColors[bisSelected, ipBody], ToolbarColor, 5);
  1157. end
  1158. else
  1159. begin
  1160. BtnItemColors[bisSelected, ipBody] := clBlack;
  1161. end;
  1162. BtnItemColors[bisSelected, ipText] := BtnItemColors[bisNormal, ipText];
  1163. BtnItemColors[bisSelected, ipFrame] := clHighlight;
  1164. BtnItemColors[bisPressed, ipBody] := Blend(clHighlight, clWindow, 50);
  1165. BtnItemColors[bisPressed, ipText] := clHighlightText;
  1166. BtnItemColors[bisPressed, ipFrame] := clHighlight;
  1167. BtnItemColors[bisHot, ipBody] := HotBtnFace;
  1168. BtnItemColors[bisHot, ipText] := clMenuText;
  1169. SetContrast(BtnItemColors[bisHot, ipText], BtnItemColors[bisHot, ipBody], 180);
  1170. BtnItemColors[bisHot, ipFrame] := clHighlight;
  1171. SetContrast(BtnItemColors[bisHot, ipFrame], ToolbarColor, 100);
  1172. BtnItemColors[bisDisabledHot, ipBody] := HotBtnFace;
  1173. BtnItemColors[bisDisabledHot, ipText] := DisabledText;
  1174. BtnItemColors[bisDisabledHot, ipFrame] := clHighlight;
  1175. BtnItemColors[bisSelectedHot, ipBody] := Blend(clHighlight, clWindow, 50);
  1176. SetContrast(BtnItemColors[bisSelectedHot, ipBody], ToolbarColor, 30);
  1177. BtnItemColors[bisSelectedHot, ipText] := clHighlightText;
  1178. SetContrast(BtnItemColors[bisSelectedHot, ipText], BtnItemColors[bisSelectedHot, ipBody], 180);
  1179. BtnItemColors[bisSelectedHot, ipFrame] := clHighlight;
  1180. SetContrast(BtnItemColors[bisSelectedHot, ipFrame], BtnItemColors[bisSelectedHot, ipBody], 100);
  1181. BtnItemColors[bisPopupParent, ipBody] := ToolbarColor;
  1182. BtnItemColors[bisPopupParent, ipText] := BtnItemColors[bisNormal, ipText];
  1183. BtnItemColors[bisPopupParent, ipFrame] := PopupFrameColor;
  1184. MenuItemColors[misNormal, ipBody] := clNone;
  1185. if not FDark then
  1186. begin
  1187. MenuItemColors[misNormal, ipText] := clWindowText;
  1188. SetContrast(MenuItemColors[misNormal, ipText], PopupColor, 180);
  1189. end
  1190. else
  1191. begin
  1192. MenuItemColors[misNormal, ipText] := clWhite;
  1193. end;
  1194. MenuItemColors[misNormal, ipFrame] := clNone;
  1195. MenuItemColors[misDisabled, ipBody] := clNone;
  1196. MenuItemColors[misDisabled, ipText] := Blend(clGrayText, clWindow, 70);
  1197. SetContrast(MenuItemColors[misDisabled, ipText], PopupColor, 80); // 145?
  1198. MenuItemColors[misDisabled, ipFrame] := clNone;
  1199. MenuItemColors[misHot, ipBody] := BtnItemColors[bisHot, ipBody];
  1200. MenuItemColors[misHot, ipText] := BtnItemColors[bisHot, ipText];
  1201. MenuItemColors[misHot, ipFrame] := BtnItemColors[bisHot, ipFrame];
  1202. MenuItemColors[misDisabledHot, ipBody] := PopupColor;
  1203. MenuItemColors[misDisabledHot, ipText] := Blend(clGrayText, clWindow, 70);
  1204. MenuItemColors[misDisabledHot, ipFrame] := clHighlight;
  1205. { Other Colors }
  1206. if not FDark then
  1207. begin
  1208. DragHandleColor := Blend(clBtnShadow, clWindow, 75);
  1209. ToolbarSeparatorColor := Blend(clBtnShadow, clWindow, 70);
  1210. StatusPanelFrameColor := Blend(clWindow, clBtnFace, 30);
  1211. SetContrast(StatusPanelFrameColor, clBtnFace, 30);
  1212. end
  1213. else
  1214. begin
  1215. DragHandleColor := RGB(65, 65, 65);
  1216. ToolbarSeparatorColor := DragHandleColor;
  1217. StatusPanelFrameColor := DragHandleColor;
  1218. end;
  1219. SetContrast(DragHandleColor, ToolbarColor, 85);
  1220. IconShadowColor := Blend(clBlack, HotBtnFace, 25);
  1221. SetContrast(ToolbarSeparatorColor, ToolbarColor, 50);
  1222. PopupSeparatorColor := ToolbarSeparatorColor;
  1223. Undither(MenubarColor);
  1224. Undither(ToolbarColor);
  1225. Undither(PopupColor);
  1226. Undither(DockPanelColor);
  1227. Undither(PopupFrameColor);
  1228. Undither(WinFrameColors[wfsActive, wfpBorder]);
  1229. Undither(WinFrameColors[wfsActive, wfpCaption]);
  1230. Undither(WinFrameColors[wfsActive, wfpCaptionText]);
  1231. Undither(WinFrameColors[wfsInactive, wfpBorder]);
  1232. Undither(WinFrameColors[wfsInactive, wfpCaption]);
  1233. Undither(WinFrameColors[wfsInactive, wfpCaptionText]);
  1234. Undither(PnlFrameColors[wfsActive, wfpBorder]);
  1235. Undither(PnlFrameColors[wfsActive, wfpCaption]);
  1236. Undither(PnlFrameColors[wfsActive, wfpCaptionText]);
  1237. Undither(PnlFrameColors[wfsInactive, wfpBorder]);
  1238. Undither(PnlFrameColors[wfsInactive, wfpCaption]);
  1239. Undither(PnlFrameColors[wfsInactive, wfpCaptionText]);
  1240. Undither(BtnItemColors[bisNormal, ipBody]);
  1241. Undither(BtnItemColors[bisNormal, ipText]);
  1242. Undither(BtnItemColors[bisNormal, ipFrame]);
  1243. Undither(BtnItemColors[bisDisabled, ipBody]);
  1244. Undither(BtnItemColors[bisDisabled, ipText]);
  1245. Undither(BtnItemColors[bisDisabled, ipFrame]);
  1246. Undither(BtnItemColors[bisSelected, ipBody]);
  1247. Undither(BtnItemColors[bisSelected, ipText]);
  1248. Undither(BtnItemColors[bisSelected, ipFrame]);
  1249. Undither(BtnItemColors[bisPressed, ipBody]);
  1250. Undither(BtnItemColors[bisPressed, ipText]);
  1251. Undither(BtnItemColors[bisPressed, ipFrame]);
  1252. Undither(BtnItemColors[bisHot, ipBody]);
  1253. Undither(BtnItemColors[bisHot, ipText]);
  1254. Undither(BtnItemColors[bisHot, ipFrame]);
  1255. Undither(BtnItemColors[bisDisabledHot, ipBody]);
  1256. Undither(BtnItemColors[bisDisabledHot, ipText]);
  1257. Undither(BtnItemColors[bisDisabledHot, ipFrame]);
  1258. Undither(BtnItemColors[bisSelectedHot, ipBody]);
  1259. Undither(BtnItemColors[bisSelectedHot, ipText]);
  1260. Undither(BtnItemColors[bisSelectedHot, ipFrame]);
  1261. Undither(BtnItemColors[bisPopupParent, ipBody]);
  1262. Undither(BtnItemColors[bisPopupParent, ipText]);
  1263. Undither(BtnItemColors[bisPopupParent, ipFrame]);
  1264. Undither(MenuItemColors[misNormal, ipBody]);
  1265. Undither(MenuItemColors[misNormal, ipText]);
  1266. Undither(MenuItemColors[misNormal, ipFrame]);
  1267. Undither(MenuItemColors[misDisabled, ipBody]);
  1268. Undither(MenuItemColors[misDisabled, ipText]);
  1269. Undither(MenuItemColors[misDisabled, ipFrame]);
  1270. Undither(MenuItemColors[misHot, ipBody]);
  1271. Undither(MenuItemColors[misHot, ipText]);
  1272. Undither(MenuItemColors[misHot, ipFrame]);
  1273. Undither(MenuItemColors[misDisabledHot, ipBody]);
  1274. Undither(MenuItemColors[misDisabledHot, ipText]);
  1275. Undither(MenuItemColors[misDisabledHot, ipFrame]);
  1276. Undither(DragHandleColor);
  1277. Undither(IconShadowColor);
  1278. Undither(ToolbarSeparatorColor);
  1279. Undither(PopupSeparatorColor);
  1280. Undither(StatusPanelFrameColor);
  1281. end;
  1282. end;
  1283. function TTBXOfficeXPTheme.GetPopupShadowType: Integer;
  1284. begin
  1285. Result := PST_OFFICEXP;
  1286. end;
  1287. constructor TTBXOfficeXPTheme.Create(const AName: string);
  1288. begin
  1289. CreateEx(AName, False);
  1290. end;
  1291. constructor TTBXOfficeXPTheme.CreateEx(const AName: string; Dark: Boolean);
  1292. begin
  1293. inherited;
  1294. FDark := Dark;
  1295. Init;
  1296. end;
  1297. procedure TTBXOfficeXPTheme.Init;
  1298. begin
  1299. if CounterLock = 0 then InitializeStock;
  1300. Inc(CounterLock);
  1301. AddTBXSysChangeNotification(Self);
  1302. SetupColorCache;
  1303. end;
  1304. destructor TTBXOfficeXPTheme.Destroy;
  1305. begin
  1306. RemoveTBXSysChangeNotification(Self);
  1307. Dec(CounterLock);
  1308. if CounterLock = 0 then FinalizeStock;
  1309. inherited;
  1310. end;
  1311. procedure TTBXOfficeXPTheme.GetViewMargins(ViewType: Integer; out Margins: TTBXMargins);
  1312. begin
  1313. Margins.LeftWidth := 0;
  1314. Margins.TopHeight := 0;
  1315. Margins.RightWidth := 0;
  1316. Margins.BottomHeight := 0;
  1317. end;
  1318. function TTBXOfficeXPTheme.GetSysColor(nIndex: Integer): DWORD;
  1319. begin
  1320. if FDark and (nIndex = COLOR_WINDOWTEXT) then
  1321. Result := clWhite
  1322. else
  1323. Result := Windows.GetSysColor(nIndex);
  1324. end;
  1325. function TTBXOfficeXPTheme.GetStandardColor(Color: TColor): TColor;
  1326. begin
  1327. if FDark then
  1328. begin
  1329. if Color = clWindow then
  1330. begin
  1331. Color := RGB(65, 65, 65);
  1332. end;
  1333. end;
  1334. Result := Color;
  1335. end;
  1336. procedure TTBXOfficeXPTheme.PaintStatusBar(Control: TWinControl; Canvas: TCanvas; R: TRect; Part: Integer);
  1337. var
  1338. D: Integer;
  1339. DC: HDC;
  1340. procedure DiagLine(C: TColor);
  1341. begin
  1342. with R do
  1343. DrawLineEx(DC, Right - 1 - D, Bottom - 1, Right, Bottom - D - 2, C);
  1344. Inc(D);
  1345. end;
  1346. var
  1347. Theme: THandle;
  1348. C: TColor;
  1349. begin
  1350. DC := Canvas.Handle;
  1351. case Part of
  1352. SBP_BODY:
  1353. begin
  1354. if not FDark then C := clBtnFace
  1355. else C := ToolbarColor;
  1356. FillRectEx(DC, R, C);
  1357. end;
  1358. SBP_PANE, SBP_LASTPANE:
  1359. begin
  1360. if Part = SBP_PANE then Dec(R.Right, 2);
  1361. FrameRectEx(DC, R, StatusPanelFrameColor, False);
  1362. end;
  1363. SBP_GRIPPER:
  1364. begin
  1365. Inc(R.Right);
  1366. Theme := OpenThemeData(Control.Handle, 'STATUS');
  1367. DrawThemeBackground(Theme, DC, SP_GRIPPER, 0, R, nil);
  1368. CloseThemeData(Theme);
  1369. end;
  1370. end;
  1371. end;
  1372. procedure TTBXOfficeXPTheme.TBXSysCommand(var Message: TMessage);
  1373. begin
  1374. if Message.WParam = TSC_VIEWCHANGE then SetupColorCache;
  1375. end;
  1376. function GetSelectedBodyColor: TColor;
  1377. begin
  1378. Result := Blend(clHighlight, Blend(clBtnFace, clWindow, 50), 10);
  1379. end;
  1380. { TTBXDarkOfficeXPTheme }
  1381. constructor TTBXDarkOfficeXPTheme.Create(const AName: string);
  1382. begin
  1383. inherited CreateEx(AName, True);
  1384. end;
  1385. end.