TBXOfficeXPTheme.pas 53 KB

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