TBX.pas 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496
  1. unit TBX;
  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: TBX.pas 21 2004-05-29 22:16:01Z Alex@ZEISS
  7. interface
  8. {$I TB2Ver.inc}
  9. uses
  10. Windows, Messages, Classes, SysUtils, Controls, Graphics, ImgList, Forms,
  11. TB2Item, TB2Dock, TB2Toolbar, TB2Anim, TBXUtils, TBXThemes, PasTools;
  12. const
  13. TBXVersion = 2.1;
  14. TBXVersionString = '2.1';
  15. TBXVersionText = 'TBX version ' + TBXVersionString;
  16. { TBX Messages }
  17. const
  18. TBM_THEMECHANGE = WM_USER + 314;
  19. TBM_GETVIEWTYPE = WM_USER + 237;
  20. TBM_GETEFFECTIVECOLOR = WM_USER + 238;
  21. function GetViewType(View: TTBView): Integer;
  22. function GetWinViewType(Window: TControl): Integer;
  23. function IsFloating(ViewType: Integer): Boolean;
  24. type
  25. TTextWrapping = (twNone, twEndEllipsis, twPathEllipsis, twWrap);
  26. TTextTruncation = twNone..twPathEllipsis;
  27. TTriState = (tsDefault, tsTrue, tsFalse);
  28. TFontSize = 25..1000;
  29. TFontSettings = class(TPersistent)
  30. private
  31. FBold: TTriState;
  32. FItalic: TTriState;
  33. FUnderline: TTriState;
  34. FStrikeOut: TTriState;
  35. FSize: TFontSize;
  36. FColor: TColor;
  37. FName: TFontName;
  38. FOnChange: TNotifyEvent;
  39. procedure SetBold(Value: TTriState);
  40. procedure SetColor(Value: TColor);
  41. procedure SetItalic(Value: TTriState);
  42. procedure SetName(const Value: TFontName);
  43. procedure SetSize(Value: TFontSize);
  44. procedure SetStrikeOut(Value: TTriState);
  45. procedure SetUnderline(Value: TTriState);
  46. protected
  47. procedure Modified;
  48. property OnChange: TNotifyEvent read FOnChange write FOnChange;
  49. public
  50. constructor Create;
  51. procedure Apply(Font: TFont); overload;
  52. procedure Apply(var LF: TLogFont; var FontColor: TColor); overload;
  53. procedure Assign(Src: TPersistent); override;
  54. function CreateTransformedFont(Src: HFont; var FontColor: TColor): HFont;
  55. published
  56. property Bold: TTriState read FBold write SetBold default tsDefault;
  57. property Italic: TTriState read FItalic write SetItalic default tsDefault;
  58. property Underline: TTriState read FUnderline write SetUnderline default tsDefault;
  59. property StrikeOut: TTriState read FStrikeOut write SetStrikeOut default tsDefault;
  60. property Size: TFontSize read FSize write SetSize default 100; // percent
  61. property Color: TColor read FColor write SetColor default clNone;
  62. property Name: TFontName read FName write SetName; // default ''
  63. end;
  64. TTBXPopupPositionInfo = record
  65. Item: TTBCustomItem; // this is a tentative type, it will be changed
  66. ParentView: TTBView; // or removed in future versions
  67. ParentViewer: TTBItemViewer;
  68. PositionAsSubmenu: Boolean;
  69. APopupPoint: TPoint;
  70. Alignment: TTBPopupAlignment;
  71. PopupWindow: TTBPopupWindow;
  72. X, Y: Integer;
  73. ParentItemRect: TRect;
  74. AppFlags: Integer; // reserved for extensions
  75. AppData: Integer;
  76. end;
  77. TTBXThemeClass = class of TTBXTheme;
  78. function GetStateFlags(const ItemInfo: TTBXItemInfo): Integer;
  79. function GetTBXTextColor(StateFlags: Integer): TColor;
  80. procedure DrawTBXCaption(Canvas: TCanvas; Rect: TRect; const Text: string;
  81. Format: Cardinal; StateFlags: Integer);
  82. procedure DrawTBXImage(Canvas: TCanvas; Rect: TRect; ImageList: TCustomImageList;
  83. ImageIndex: Integer; StateFlags: Integer);
  84. type
  85. { TTBXItem }
  86. TAdjustFontEvent = procedure(Item: TTBCustomItem; Viewer: TTBItemViewer;
  87. Font: TFont; StateFlags: Integer) of object; // state flags are the combination of ISF_* constants
  88. TDrawImageEvent = procedure(Item: TTBCustomItem; Viewer: TTBItemViewer;
  89. Canvas: TCanvas; ImageRect: TRect; ImageOffset: TPoint; StateFlags: Integer) of object;
  90. TTBXCustomItem = class(TTBCustomItem)
  91. private
  92. FAlwaysSelectFirst: Boolean;
  93. FFontSettings: TFontSettings;
  94. FLayout: TTBXItemLayout;
  95. FMinHeight: Integer;
  96. FMinWidth: Integer;
  97. FToolBoxPopup: Boolean;
  98. FOnAdjustFont: TAdjustFontEvent;
  99. FOnDrawImage: TDrawImageEvent;
  100. procedure FontSettingsChanged(Sender: TObject);
  101. function GetStretch: Boolean;
  102. procedure SetFontSettings(Value: TFontSettings);
  103. procedure SetLayout(Value: TTBXItemLayout);
  104. procedure SetMinHeight(Value: Integer);
  105. procedure SetMinWidth(Value: Integer);
  106. procedure SetStretch(Value: Boolean);
  107. protected
  108. function CreatePopup(const ParentView: TTBView; const ParentViewer: TTBItemViewer;
  109. const PositionAsSubmenu, SelectFirstItem, Customizing: Boolean;
  110. const APopupPoint: TPoint; const Alignment: TTBPopupAlignment): TTBPopupWindow; override;
  111. function GetItemViewerClass(AView: TTBView): TTBItemViewerClass; override;
  112. procedure GetPopupPosition(ParentView: TTBView; PopupWindow: TTBPopupWindow;
  113. var PopupPositionRec: TTBPopupPositionRec); override;
  114. function GetPopupWindowClass: TTBPopupWindowClass; override;
  115. property ToolBoxPopup: Boolean read FToolBoxPopup write FToolBoxPopup default False;
  116. property OnAdjustFont: TAdjustFontEvent read FOnAdjustFont write FOnAdjustFont;
  117. property OnDrawImage: TDrawImageEvent read FOnDrawImage write FOnDrawImage;
  118. public
  119. constructor Create(AOwner: TComponent); override;
  120. destructor Destroy; override;
  121. procedure Invalidate;
  122. property AlwaysSelectFirst: Boolean read FAlwaysSelectFirst write FAlwaysSelectFirst default False;
  123. property FontSettings: TFontSettings read FFontSettings write SetFontSettings;
  124. property Layout: TTBXItemLayout read FLayout write SetLayout default tbxlAuto;
  125. property MinHeight: Integer read FMinHeight write SetMinHeight default 0;
  126. property MinWidth: Integer read FMinWidth write SetMinWidth default 0;
  127. property Stretch: Boolean read GetStretch write SetStretch default False;
  128. end;
  129. TTBXItem = class (TTBXCustomItem)
  130. property Action;
  131. property AutoCheck;
  132. property Caption;
  133. property Checked;
  134. property DisplayMode;
  135. property Enabled;
  136. property FontSettings;
  137. property GroupIndex;
  138. property HelpContext;
  139. { MP }
  140. property HelpKeyword;
  141. property Hint;
  142. property ImageIndex;
  143. property Images;
  144. property InheritOptions;
  145. property Layout;
  146. property MaskOptions;
  147. property MinHeight;
  148. property MinWidth;
  149. property Options;
  150. property RadioItem;
  151. property ShortCut;
  152. property Stretch;
  153. property Visible;
  154. property OnAdjustFont;
  155. property OnDrawImage;
  156. property OnClick;
  157. property OnSelect;
  158. end;
  159. TTBXItemViewer = class(TTBItemViewer)
  160. private
  161. FWide: Boolean;
  162. protected
  163. procedure DoPaintCaption(Canvas: TCanvas; const ClientAreaRect: TRect;
  164. var CaptionRect: TRect; IsTextRotated: Boolean; var PaintDefault: Boolean); virtual;
  165. function GetAccRole: Integer; override;
  166. function GetImageSize: TSize; dynamic;
  167. function GetItemType: Integer; virtual;
  168. function GetTextFlags: Cardinal; dynamic;
  169. function GetTextSize(Canvas: TCanvas; const Text: string; TextFlags: Cardinal; Rotated: Boolean; StateFlags: Integer): TSize; dynamic;
  170. function IsToolbarSize: Boolean; override;
  171. procedure CalcSize(const Canvas: TCanvas; var AWidth, AHeight: Integer); override;
  172. procedure DrawItemImage(Canvas: TCanvas; ARect: TRect; ItemInfo: TTBXItemInfo); virtual;
  173. procedure DoAdjustFont(AFont: TFont; StateFlags: Integer); virtual;
  174. function GetImageShown: Boolean; virtual;
  175. function IsPtInButtonPart(X, Y: Integer): Boolean; override;
  176. procedure MouseUp(X, Y: Integer; MouseWasDownOnMenu: Boolean); override;
  177. procedure Paint(const Canvas: TCanvas; const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean); override;
  178. property Wide: Boolean read FWide write FWide default True;
  179. public
  180. constructor Create(AView: TTBView; AItem: TTBCustomItem; AGroupLevel: Integer); override;
  181. function IsToolbarStyle: Boolean; override;
  182. end;
  183. { TTBXSubmenuItem }
  184. TTBXSubmenuItem = class(TTBXCustomItem)
  185. private
  186. function GetDropdownCombo: Boolean;
  187. procedure SetDropdownCombo(Value: Boolean);
  188. public
  189. constructor Create(AOwner: TComponent); override;
  190. published
  191. property Action;
  192. property AlwaysSelectFirst;
  193. property AutoCheck;
  194. property Caption;
  195. property Checked;
  196. property DisplayMode;
  197. property DropdownCombo: Boolean read GetDropdownCombo write SetDropdownCombo default False;
  198. property Enabled;
  199. property FontSettings;
  200. property GroupIndex;
  201. property HelpContext;
  202. { MP }
  203. property HelpKeyword;
  204. property Hint;
  205. property ImageIndex;
  206. property Images;
  207. property InheritOptions;
  208. property Layout;
  209. property LinkSubitems;
  210. property MaskOptions;
  211. property MinHeight;
  212. property MinWidth;
  213. property Options;
  214. property RadioItem;
  215. property ShortCut;
  216. property Stretch;
  217. property SubMenuImages;
  218. property ToolBoxPopup;
  219. property Visible;
  220. property OnAdjustFont;
  221. property OnDrawImage;
  222. property OnClick;
  223. property OnPopup;
  224. property OnSelect;
  225. end;
  226. { TTBXSeparatorItem }
  227. TTBXSeparatorItem = class(TTBSeparatorItem)
  228. private
  229. FSize: Integer;
  230. procedure SetSize(Value: Integer);
  231. public
  232. constructor Create(AOwner: TComponent); override;
  233. function GetItemViewerClass(AView: TTBView): TTBItemViewerClass; override;
  234. published
  235. property Size: Integer read FSize write SetSize default -1;
  236. property MaskOptions;
  237. property Options;
  238. end;
  239. TTBXSeparatorItemViewer = class(TTBSeparatorItemViewer)
  240. protected
  241. procedure CalcSize(const Canvas: TCanvas; var AWidth, AHeight: Integer); override;
  242. procedure Paint(const Canvas: TCanvas; const ClientAreaRect: TRect;
  243. IsHoverItem, IsPushed, UseDisabledShadow: Boolean); override;
  244. function IsToolbarSize: Boolean; override;
  245. public
  246. function IsToolbarStyle: Boolean; override;
  247. end;
  248. { TTBXPopupWindow }
  249. TTBXPopupWindow = class(TTBPopupWindow)
  250. private
  251. FControlRect: TRect;
  252. FShadows: TShadows;
  253. procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
  254. procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED;
  255. procedure TBMGetViewType(var Message: TMessage); message TBM_GETVIEWTYPE;
  256. procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
  257. procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
  258. procedure WMPrint(var Message: TMessage); message WM_PRINT;
  259. procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
  260. procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;
  261. procedure WMTB2kPopupShowing(var Message: TMessage); message WM_TB2K_POPUPSHOWING;
  262. protected
  263. procedure CreateParams(var Params: TCreateParams); override;
  264. procedure CreateShadow; virtual;
  265. procedure DestroyShadow; virtual;
  266. function GetNCSize: TPoint; override;
  267. function GetShowShadow: Boolean; virtual;
  268. function GetViewClass: TTBViewClass; override;
  269. procedure PaintScrollArrows; override;
  270. public
  271. destructor Destroy; override;
  272. function GetFillColor: TColor;
  273. end;
  274. TTBXPopupView = class(TTBPopupView);
  275. { TTBXToolbarView }
  276. TTBXToolbarView = class(TTBToolbarView)
  277. protected
  278. procedure GetMargins(AOrientation: TTBViewOrientation; var Margins: TRect); override;
  279. end;
  280. { TTBXToolbar }
  281. TTBXItemTransparency = (itAuto, itEnable, itDisable);
  282. TTBXToolbar = class(TTBCustomToolbar)
  283. private
  284. FEffectiveColor: TColor;
  285. FItemTransparency: TTBXItemTransparency;
  286. FSnapDistance: Integer;
  287. procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
  288. procedure CMControlChange(var Message: TCMControlChange); message CM_CONTROLCHANGE;
  289. procedure CMParentColorChanged(var Message: TMessage); message CM_PARENTCOLORCHANGED;
  290. procedure SetItemTransparency(const Value: TTBXItemTransparency);
  291. procedure SetSnapDistance(Value: Integer);
  292. procedure TBMGetViewType(var Message: TMessage); message TBM_GETVIEWTYPE;
  293. procedure TBMGetEffectiveColor(var Message: TMessage); message TBM_GETEFFECTIVECOLOR;
  294. procedure TBMThemeChange(var Message: TMessage); message TBM_THEMECHANGE;
  295. procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
  296. procedure WMDpiChangedBeforeParent(var Message: TMessage); message WM_DPICHANGED_BEFOREPARENT;
  297. procedure WMDpiChangedAfterParent(var Message: TMessage); message WM_DPICHANGED_AFTERPARENT;
  298. protected
  299. procedure DrawNCArea(const DrawToDC: Boolean; const ADC: HDC; const Clip: HRGN); override;
  300. function GetChevronItemClass: TTBChevronItemClass; override;
  301. function GetFloatingWindowParentClass: TTBFloatingWindowParentClass; override;
  302. procedure GetToolbarInfo(out ToolbarInfo: TTBXToolbarInfo); virtual;
  303. function GetViewClass: TTBToolbarViewClass; override;
  304. procedure Loaded; override;
  305. procedure SetParent(AParent: TWinControl); override;
  306. procedure UpdateEffectiveColor;
  307. procedure Rebuild;
  308. public
  309. constructor Create(AOwner: TComponent); override;
  310. destructor Destroy; override;
  311. function Embedded: Boolean;
  312. function GetFloatingBorderSize: TPoint; override;
  313. procedure UpdateChildColors;
  314. property EffectiveColor: TColor read FEffectiveColor;
  315. published
  316. property ActivateParent;
  317. property Align;
  318. property AutoResize;
  319. property BorderStyle;
  320. property Caption;
  321. property ChevronHint;
  322. property ChevronMoveItems;
  323. property ChevronMenu;
  324. property ChevronPriorityForNewItems;
  325. property CloseButton;
  326. property CloseButtonWhenDocked;
  327. property CurrentDock;
  328. property DblClickUndock default False;
  329. property DefaultDock;
  330. property DockableTo;
  331. property DockMode;
  332. property DockPos;
  333. property DockRow;
  334. property DragHandleStyle;
  335. property FloatingMode;
  336. property Font;
  337. property FullSize;
  338. property HideWhenInactive;
  339. property Images;
  340. property Items;
  341. property ItemTransparency: TTBXItemTransparency read FItemTransparency write SetItemTransparency default itAuto;
  342. property LastDock;
  343. property LinkSubitems;
  344. property MenuBar;
  345. property Options;
  346. property ParentFont;
  347. property ParentShowHint;
  348. property PopupMenu;
  349. property ProcessShortCuts;
  350. property Resizable;
  351. property ShowCaption;
  352. property ShowHint;
  353. property ShrinkMode;
  354. property SmoothDrag;
  355. property SnapDistance: Integer read FSnapDistance write SetSnapDistance default 0;
  356. property Stretch;
  357. property SystemFont;
  358. property TabOrder;
  359. property TabStop;
  360. property UpdateActions;
  361. property UseLastDock;
  362. property Visible;
  363. property Color default clNone;
  364. property OnClose;
  365. property OnCloseQuery;
  366. property OnContextPopup;
  367. property OnDragDrop;
  368. property OnDragOver;
  369. property OnMouseDown;
  370. property OnMouseMove;
  371. property OnMouseUp;
  372. property OnMove;
  373. property OnRecreated;
  374. property OnRecreating;
  375. property OnDockChanged;
  376. property OnDockChanging;
  377. property OnDockChangingHidden;
  378. property OnResize;
  379. property OnShortCut;
  380. property OnVisibleChanged;
  381. { MP }
  382. property OnGetBaseSize;
  383. property OnEndModal;
  384. end;
  385. { TTBXChevronItem }
  386. TTBXChevronItem = class(TTBChevronItem)
  387. public
  388. procedure GetPopupPosition(ParentView: TTBView;
  389. PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec); override;
  390. function GetPopupWindowClass: TTBPopupWindowClass; override;
  391. function GetItemViewerClass(AView: TTBView): TTBItemViewerClass; override;
  392. end;
  393. TTBXChevronItemViewer = class(TTBItemViewer)
  394. protected
  395. procedure Paint(const Canvas: TCanvas; const ClientAreaRect: TRect;
  396. IsHoverItem, IsPushed, UseDisabledShadow: Boolean); override;
  397. function CaptionShown: Boolean; override;
  398. end;
  399. TTBXChevronPopupWindow = class(TTBXPopupWindow);
  400. { TTBXPopupMenu }
  401. TTBXRootItem = class(TTBRootItem)
  402. private
  403. FPopupControlRect: TRect;
  404. protected
  405. function CreatePopupEx(SelectFirstItem: Boolean; const AControlRect: TRect;
  406. Alignment: TTBPopupAlignment): TTBPopupWindow; virtual;
  407. function GetPopupWindowClass: TTBPopupWindowClass; override;
  408. procedure GetPopupPosition(ParentView: TTBView; PopupWindow: TTBPopupWindow;
  409. var PopupPositionRec: TTBPopupPositionRec); override;
  410. function OpenPopupEx(const SelectFirstItem, TrackRightButton: Boolean;
  411. const ControlRect: TRect; const Alignment: TTBPopupAlignment;
  412. const ReturnClickedItemOnly: Boolean): TTBCustomItem;
  413. function PopupEx(const ControlRect: TRect; TrackRightButton: Boolean;
  414. Alignment: TTBPopupAlignment = tbpaLeft;
  415. ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
  416. end;
  417. TTBXPopupMenu = class(TTBPopupMenu)
  418. private
  419. FToolBoxPopup: Boolean;
  420. procedure TBMGetViewType(var Message: TMessage); message TBM_GETVIEWTYPE;
  421. protected
  422. function GetRootItemClass: TTBRootItemClass; override;
  423. public
  424. function PopupEx(const ControlRect: TRect;
  425. ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
  426. property ToolBoxPopup: Boolean read FToolBoxPopup write FToolBoxPopup default False;
  427. end;
  428. TTBXFloatingWindowParent = class(TTBFloatingWindowParent)
  429. private
  430. FCloseButtonHover: Boolean;
  431. FSnapDistance: Integer;
  432. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  433. procedure WMEraseBkgnd(var Message: TMessage); message WM_ERASEBKGND;
  434. procedure WMNCMouseLeave(var Message: TMessage); message $2A2 {WM_NCMOUSELEAVE};
  435. procedure WMNCMouseMove(var Message: TWMNCMouseMove); message WM_NCMOUSEMOVE;
  436. procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
  437. protected
  438. procedure CancelNCHover;
  439. procedure DrawNCArea(const DrawToDC: Boolean; const ADC: HDC;
  440. const Clip: HRGN; RedrawWhat: TTBToolWindowNCRedrawWhat); override;
  441. property CloseButtonHover: Boolean read FCloseButtonHover;
  442. public
  443. property SnapDistance: Integer read FSnapDistance write FSnapDistance default 0;
  444. end;
  445. TTBXDock = class(TTBDock)
  446. private
  447. FMoving: Boolean;
  448. FResizing: Boolean;
  449. FUseParentBackground: Boolean;
  450. procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
  451. procedure TBMGetEffectiveColor(var Message: TMessage); message TBM_GETEFFECTIVECOLOR;
  452. procedure TBMThemeChange(var Message: TMessage); message TBM_THEMECHANGE;
  453. procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
  454. procedure WMMove(var Message: TWMMove); message WM_MOVE;
  455. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  456. protected
  457. function ThemedBackground: Boolean; virtual;
  458. procedure DrawBackground(DC: HDC; const DrawRect: TRect); override;
  459. procedure Resize; override;
  460. procedure SetUseParentBackground(Value: Boolean);
  461. function UsingBackground: Boolean; override;
  462. public
  463. constructor Create(AOwner: TComponent); override;
  464. destructor Destroy; override;
  465. published
  466. property Color default clNone;
  467. property UseParentBackground: Boolean read FUseParentBackground write SetUseParentBackground default False;
  468. end;
  469. { TTBXMenuAnimation }
  470. TMenuAnimation = (maNone, maUnfold, maSlide, maFade);
  471. TAnimationMode = (amNone, amSysDefault, amRandom, amUnfold, amSlide, amFade);
  472. TAnimationModes = set of TAnimationMode;
  473. TTBXMenuAnimation = class
  474. private
  475. FAnimationMode: TAnimationMode;
  476. function SysParamEnabled(Param: Cardinal): Boolean;
  477. function GetAvailableModes: TAnimationModes;
  478. function GetMenuAnimation: TMenuAnimation;
  479. procedure SetAnimationMode(Value: TAnimationMode);
  480. property MenuAnimation: TMenuAnimation read GetMenuAnimation;
  481. public
  482. constructor Create(AAnimationMode: TAnimationMode = amSysDefault);
  483. property AnimationMode: TAnimationMode read FAnimationMode write SetAnimationMode;
  484. property AvailableModes: TAnimationModes read GetAvailableModes;
  485. end;
  486. var
  487. CurrentTheme: TTBXTheme;
  488. TBXMenuAnimation: TTBXMenuAnimation;
  489. procedure TBXSetTheme(const AThemeName: string);
  490. function TBXCurrentTheme: string;
  491. procedure AddThemeNotification(AObject: TObject);
  492. procedure RemoveThemeNotification(AObject: TObject);
  493. { Additional system colors }
  494. procedure AddTBXColor(var AColor: TColor; const AName: string);
  495. function TBXIdentToColor(const Ident: string; var Color: Longint): Boolean;
  496. function TBXColorToString(Color: TColor): string;
  497. function TBXStringToColor(S: string): TColor;
  498. procedure TBXGetColorValues(Proc: TGetStrProc);
  499. { Internal routines - do not use }
  500. function GetPopupMargin(ItemViewer: TTBItemViewer): Integer;
  501. function GetEffectiveColor(C: TControl): TColor;
  502. procedure DrawParentBackground(Control: TControl; DC: HDC; R: TRect);
  503. procedure AddToList(var List: TList; Item: Pointer);
  504. procedure RemoveFromList(var List: TList; Item: Pointer);
  505. function CreateTBXPopupMenu(Owner: TComponent): TTBXPopupMenu;
  506. implementation
  507. {$R tbx_glyphs.res}
  508. uses
  509. TBXExtItems, TBXLists, TB2Common, UxTheme, MultiMon, TBXOfficeXPTheme,
  510. ComCtrls, Menus, MMSystem, Types, UITypes;
  511. type
  512. TTBItemAccess = class(TTBCustomItem);
  513. TTBViewAccess = class(TTBView);
  514. TTBItemViewerAccess = class(TTBItemViewer);
  515. TTBFloatingWindowParentAccess = class(TTBFloatingWindowParent);
  516. TTBCustomDockableWindowAccess = class(TTBCustomDockableWindow);
  517. TTBXToolbarAccess = class(TTBXToolbar);
  518. TControlAccess = class(TControl);
  519. TTBXThemeAccess = class(TTBXTheme);
  520. TDockAccess = class(TTBDock);
  521. TTBPopupWindowAccess = class(TTBPopupWindow);
  522. { TTBNexus }
  523. TTBXNexus = class
  524. private
  525. FNotifies: TList;
  526. procedure TBXSysCommand(var Message: TMessage); message TBX_SYSCOMMAND;
  527. protected
  528. procedure Broadcast(Msg: Cardinal; WParam, LParam: Integer);
  529. public
  530. constructor Create(const DefaultTheme: string);
  531. destructor Destroy; override;
  532. procedure SetTheme(const AThemeName: string);
  533. function GetTheme: string;
  534. procedure AddNotifie(AObject: TObject);
  535. procedure RemoveNotifie(AObject: TObject);
  536. end;
  537. var
  538. TBXNexus: TTBXNexus;
  539. procedure AddThemeNotification(AObject: TObject);
  540. begin
  541. TBXNexus.AddNotifie(AObject);
  542. end;
  543. procedure RemoveThemeNotification(AObject: TObject);
  544. begin
  545. TBXNexus.RemoveNotifie(AObject);
  546. end;
  547. function GetEffectiveColor(C: TControl): TColor;
  548. var
  549. Message: TMessage;
  550. begin
  551. if C = nil then Result := clBtnFace
  552. else
  553. begin
  554. Message.Msg := TBM_GETEFFECTIVECOLOR;
  555. Message.WParam := 0;
  556. Message.LParam := 0;
  557. Message.Result := 0;
  558. C.Dispatch(Message);
  559. if Message.Result <> 0 then Result := Message.WParam
  560. else if (C is TForm) and (TForm(C).FormStyle = fsMDIForm) then
  561. Result := clBtnFace
  562. else
  563. Result := TControlAccess(C).Color;
  564. end;
  565. end;
  566. procedure DrawParentBackground(Control: TControl; DC: HDC; R: TRect);
  567. var
  568. Parent: TWinControl;
  569. Theme: HTHEME;
  570. R2: TRect;
  571. Shift: TPoint;
  572. UsingThemes: Boolean;
  573. Msg: TMessage;
  574. begin
  575. Parent := Control.Parent;
  576. if Parent = nil then FillRectEx(DC, R, clBtnFace)
  577. else
  578. begin
  579. Shift.X := 0; Shift.Y := 0;
  580. Shift := Parent.ScreenToClient(Control.ClientToScreen(Shift));
  581. SaveDC(DC);
  582. try
  583. SetWindowOrgEx(DC, Shift.X, Shift.Y, nil);
  584. Msg.Msg := WM_ERASEBKGND;
  585. Msg.WParam := Integer(DC);
  586. Msg.LParam := Integer(DC);
  587. Msg.Result := 0;
  588. Parent.Dispatch(Msg);
  589. finally
  590. RestoreDC(DC, -1);
  591. end;
  592. if Msg.Result <> 0 then Exit;
  593. UsingThemes := USE_THEMES and not (csDesigning in Control.ComponentState);
  594. if Parent is TTBDock then
  595. begin
  596. SaveDC(DC);
  597. SetWindowOrgEx(DC, Control.Left, Control.Top, nil);
  598. TDockAccess(Parent).DrawBackground(DC, R);
  599. RestoreDC(DC, -1);
  600. end
  601. else if not UsingThemes then
  602. FillRectEx(DC, R, GetEffectiveColor(Parent))
  603. else
  604. begin
  605. { Unfortunately, DrawThemeParentBackground does seem to have some problems
  606. with the back buffer. Therefore some sort of workaround is used which
  607. will work for tab sheets }
  608. // if Control is TWinControl then
  609. // DrawThemeParentBackground(TWinControl(Control).Handle, DC, @R);
  610. if Parent is TTabSheet then
  611. begin
  612. Theme := OpenThemeData(Parent.Handle, 'TAB');
  613. R2 := Parent.ClientRect;
  614. R2.TopLeft := Control.ScreenToClient(Parent.ClientToScreen(R2.TopLeft));
  615. R2.BottomRight := Control.ScreenToClient(Parent.ClientToScreen(R2.BottomRight));
  616. DrawThemeBackground(Theme, DC, TABP_BODY, 0, R2, @R);
  617. CloseThemeData(Theme);
  618. end
  619. else FillRectEx(DC, R, GetEffectiveColor(Parent));
  620. end;
  621. end;
  622. end;
  623. function GetViewType(View: TTBView): Integer;
  624. var
  625. Message: TMessage;
  626. begin
  627. Result := VT_UNKNOWN;
  628. if (View <> nil) and (View.Owner <> nil) then
  629. begin
  630. Message.Msg := TBM_GETVIEWTYPE;
  631. Message.WParam := 0;
  632. Message.LParam := 0;
  633. Message.Result := VT_UNKNOWN;
  634. View.Window.Dispatch(Message);
  635. Result := Message.Result;
  636. end;
  637. end;
  638. function GetWinViewType(Window: TControl): Integer;
  639. var
  640. Message: TMessage;
  641. begin
  642. Result := VT_UNKNOWN;
  643. if Window <> nil then
  644. begin
  645. Message.Msg := TBM_GETVIEWTYPE;
  646. Message.WParam := 0;
  647. Message.LParam := 0;
  648. Message.Result := VT_UNKNOWN;
  649. Window.Dispatch(Message);
  650. Result := Message.Result;
  651. end;
  652. end;
  653. function IsFloating(ViewType: Integer): Boolean;
  654. begin
  655. Result := ViewType and TVT_FLOATING <> 0;
  656. end;
  657. procedure UpdateNCArea(Control: TWinControl; ViewType: Integer);
  658. begin
  659. with Control do
  660. begin
  661. ClientWidth := ClientWidth;
  662. ClientHeight := ClientHeight;
  663. end;
  664. SetWindowPos(Control.Handle, 0, 0, 0, 0, 0,
  665. SWP_FRAMECHANGED or SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOMOVE or SWP_NOSIZE);
  666. Control.Invalidate;
  667. end;
  668. function GetPopupMargin(ItemViewer: TTBItemViewer): Integer;
  669. var
  670. ImgList: TCustomImageList;
  671. Sz: TSize;
  672. TextMetric: TTextMetric;
  673. H, M2: Integer;
  674. Margins: TTBXMargins;
  675. begin
  676. Sz.Cx := 0;
  677. Sz.Cy := 0;
  678. if ItemViewer is TTBXItemViewer then
  679. Sz := TTBXItemViewer(ItemViewer).GetImageSize;
  680. if (Sz.Cx = 0) or (Sz.Cy = 0) then
  681. begin
  682. ImgList := TTBItemViewerAccess(ItemViewer).GetImageList;
  683. if ImgList <> nil then
  684. begin
  685. Sz.Cx := ImgList.Width;
  686. Sz.Cy := ImgList.Height;
  687. end;
  688. if (Sz.Cx = 0) or (Sz.Cy = 0) then
  689. begin
  690. Sz.Cx := 16;
  691. Sz.Cy := 16;
  692. end;
  693. end;
  694. StockBitmap1.Canvas.Font := TTBViewAccess(ItemViewer.View).GetFont;
  695. GetTextMetrics(StockBitmap1.Canvas.Handle, TextMetric);
  696. CurrentTheme.GetMargins(MID_MENUITEM, Margins);
  697. M2 := Margins.TopHeight + Margins.BottomHeight;
  698. Result := TextMetric.tmHeight + TextMetric.tmExternalLeading + M2;
  699. H := Sz.CY + M2;
  700. if H > Result then Result := H;
  701. Result := (Sz.Cx + M2) * Result div H;
  702. end;
  703. procedure GetOfficeXPPopupPosition1(var PopupPositionRec: TTBPopupPositionRec);
  704. begin
  705. with PopupPositionRec do
  706. begin
  707. if not PositionAsSubmenu then
  708. begin
  709. NCSizeX := 0;
  710. NCSizeY := 0;
  711. Dec(ParentItemRect.Right);
  712. if X = ParentItemRect.Right + 1 then Dec(X);
  713. if X + W <= ParentItemRect.Left then Inc(X);
  714. Dec(ParentItemRect.Bottom);
  715. if Y = ParentItemRect.Bottom + 1 then Dec(Y);
  716. if Y + H <= ParentItemRect.Top then Inc(Y);
  717. Dec(W);
  718. Dec(H);
  719. end
  720. else
  721. begin
  722. Inc(X, NCSizeX);
  723. Inc(Y, NCSizeY);
  724. NCSizeX := 0;
  725. NCSizeY := 0;
  726. end;
  727. end;
  728. end;
  729. procedure GetOfficeXPPopupPosition2(var PopupPositionRec: TTBPopupPositionRec);
  730. begin
  731. with PopupPositionRec do if not PositionAsSubmenu then
  732. begin
  733. Inc(W);
  734. Inc(H);
  735. end;
  736. end;
  737. procedure AddToList(var List: TList; Item: Pointer);
  738. begin
  739. if List = nil then List := TList.Create;
  740. List.Add(Item)
  741. end;
  742. procedure RemoveFromList(var List: TList; Item: Pointer);
  743. begin
  744. if List <> nil then
  745. begin
  746. List.Remove(Item);
  747. if List.Count = 0 then
  748. begin
  749. List.Free;
  750. List := nil;
  751. end;
  752. end;
  753. end;
  754. //============================================================================//
  755. { Misc. Routines }
  756. procedure InvalidateAll(const Ctl: TWinControl);
  757. begin
  758. if Ctl.HandleAllocated then
  759. RedrawWindow(Ctl.Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
  760. RDW_ERASE);
  761. end;
  762. function GetStateFlags(const ItemInfo: TTBXItemInfo): Integer;
  763. const
  764. CEnabledStates: array [Boolean] of Integer = (ISF_DISABLED, 0);
  765. CHotStates: array [Boolean] of Integer = (0, ISF_HOT);
  766. CPushedStates: array [Boolean] of Integer = (0, ISF_PUSHED);
  767. CSelectedStates: array [Boolean] of Integer = (0, ISF_SELECTED);
  768. begin
  769. with ItemInfo do
  770. Result := CEnabledStates[ItemInfo.Enabled] or CPushedStates[ItemInfo.Pushed] or
  771. CHotStates[ItemInfo.HoverKind = hkMouseHover] or CSelectedStates[ItemInfo.Selected];
  772. end;
  773. function GetTBXTextColor(StateFlags: Integer): TColor;
  774. const
  775. HoverKinds: array [Boolean] of TTBXHoverKind = (hkNone, hkMouseHover);
  776. var
  777. ItemInfo: TTBXItemInfo;
  778. begin
  779. FillChar(ItemInfo, SizeOf(ItemInfo), 0);
  780. case StateFlags and ISF_LOCATIONMASK of
  781. ISF_TOOLBARCOLOR:
  782. begin
  783. ItemInfo.ViewType := VT_TOOLBAR;
  784. ItemInfo.ItemOptions := IO_TOOLBARSTYLE;
  785. end;
  786. ISF_MENUCOLOR:
  787. begin
  788. ItemInfo.ViewType := VT_DOCKPANEL;
  789. end;
  790. ISF_STATUSCOLOR:
  791. begin
  792. ItemInfo.ViewType := VT_STATUSBAR;
  793. end;
  794. else
  795. ItemInfo.ViewType := VT_UNKNOWN;
  796. end;
  797. ItemInfo.Enabled := StateFlags and ISF_DISABLED = 0;
  798. ItemInfo.Pushed := StateFlags and ISF_PUSHED <> 0;
  799. ItemInfo.HoverKind := HoverKinds[StateFlags and ISF_HOT <> 0];
  800. ItemInfo.Selected := StateFlags and ISF_SELECTED <> 0;
  801. Result := CurrentTheme.GetItemTextColor(ItemInfo);
  802. end;
  803. procedure DrawTBXCaption(Canvas: TCanvas; Rect: TRect; const Text: string; Format: Cardinal; StateFlags: Integer);
  804. const
  805. HoverKinds: array [Boolean] of TTBXHoverKind = (hkNone, hkMouseHover);
  806. var
  807. ItemInfo: TTBXItemInfo;
  808. begin
  809. FillChar(ItemInfo, SizeOf(ItemInfo), 0);
  810. case StateFlags and ISF_LOCATIONMASK of
  811. ISF_TOOLBARCOLOR:
  812. begin
  813. ItemInfo.ViewType := VT_TOOLBAR;
  814. ItemInfo.ItemOptions := IO_TOOLBARSTYLE;
  815. end;
  816. ISF_MENUCOLOR:
  817. begin
  818. ItemInfo.ViewType := VT_DOCKPANEL;
  819. end;
  820. ISF_STATUSCOLOR:
  821. begin
  822. ItemInfo.ViewType := VT_STATUSBAR;
  823. end;
  824. end;
  825. ItemInfo.Enabled := StateFlags and ISF_DISABLED = 0;
  826. ItemInfo.Pushed := StateFlags and ISF_PUSHED <> 0;
  827. ItemInfo.HoverKind := HoverKinds[StateFlags and ISF_HOT <> 0];
  828. ItemInfo.Selected := StateFlags and ISF_SELECTED <> 0;
  829. CurrentTheme.PaintCaption(Canvas, Rect, ItemInfo, Text, Format, False);
  830. end;
  831. procedure DrawTBXImage(Canvas: TCanvas; Rect: TRect; ImageList: TCustomImageList;
  832. ImageIndex: Integer; StateFlags: Integer);
  833. const
  834. HoverKinds: array [Boolean] of TTBXHoverKind = (hkNone, hkMouseHover);
  835. var
  836. ItemInfo: TTBXItemInfo;
  837. begin
  838. FillChar(ItemInfo, SizeOf(ItemInfo), 0);
  839. case StateFlags and ISF_LOCATIONMASK of
  840. ISF_TOOLBARCOLOR:
  841. begin
  842. ItemInfo.ViewType := VT_TOOLBAR;
  843. ItemInfo.ItemOptions := IO_TOOLBARSTYLE;
  844. end;
  845. ISF_MENUCOLOR:
  846. begin
  847. ItemInfo.ViewType := VT_DOCKPANEL;
  848. end;
  849. ISF_STATUSCOLOR:
  850. begin
  851. ItemInfo.ViewType := VT_STATUSBAR;
  852. end;
  853. end;
  854. ItemInfo.Enabled := not Boolean(StateFlags and ISF_DISABLED);
  855. ItemInfo.Pushed := Boolean(StateFlags and ISF_PUSHED);
  856. ItemInfo.HoverKind := HoverKinds[Boolean(StateFlags and ISF_HOT)];
  857. ItemInfo.Selected := Boolean(StateFlags and ISF_SELECTED);
  858. CurrentTheme.PaintImage(Canvas, Rect, ItemInfo, ImageList, ImageIndex);
  859. end;
  860. //============================================================================//
  861. { TFontSettings }
  862. procedure TFontSettings.Apply(Font: TFont);
  863. var
  864. FS: TFontStyles;
  865. begin
  866. if Size <> 100 then Font.Size := (Font.Size * FSize + 50) div 100;
  867. if Color <> clNone then Font.Color := Color;
  868. if Name <> '' then Font.Name := Name;
  869. FS := Font.Style;
  870. if Bold = tsTrue then Include(FS, fsBold)
  871. else if Bold = tsFalse then Exclude(FS, fsBold);
  872. if Italic = tsTrue then Include(FS, fsItalic)
  873. else if Italic = tsFalse then Exclude(FS, fsItalic);
  874. if Underline = tsTrue then Include(FS, fsUnderline)
  875. else if Underline = tsFalse then Exclude(FS, fsUnderline);
  876. if StrikeOut = tsTrue then Include(FS, fsStrikeOut)
  877. else if StrikeOut = tsFalse then Exclude(FS, fsStrikeOut);
  878. Font.Style := FS;
  879. end;
  880. procedure TFontSettings.Apply(var LF: TLogFont; var FontColor: TColor);
  881. begin
  882. if Size <> 100 then LF.lfHeight := (LF.lfHeight * Size + 50) div 100;
  883. if Color <> clNone then FontColor := Color;
  884. if Name <> '' then StrPLCopy(LF.lfFaceName, Name, 31);
  885. if Bold = tsTrue then LF.lfWeight := FW_BOLD
  886. else if Bold = tsFalse then LF.lfWeight := FW_NORMAL;
  887. if Italic = tsTrue then LF.lfItalic := 1
  888. else if Italic = tsFalse then LF.lfItalic := 0;
  889. if Underline = tsTrue then LF.lfUnderline := 1
  890. else if Underline = tsFalse then LF.lfUnderline := 0;
  891. if StrikeOut = tsTrue then LF.lfStrikeOut := 1
  892. else if StrikeOut = tsFalse then LF.lfStrikeOut := 0;
  893. end;
  894. procedure TFontSettings.Assign(Src: TPersistent);
  895. var
  896. F: TFontSettings;
  897. begin
  898. if Src is TPersistent then
  899. begin
  900. F := TFontSettings(Src);
  901. if (FBold <> F.Bold) or (FItalic <> F.Italic) or (FUnderline <> F.Underline) or
  902. (FStrikeOut <> F.StrikeOut) or (FSize <> F.Size) or (FColor <> F.Color) or
  903. (FName <> F.Name) then
  904. begin
  905. FBold := F.Bold;
  906. FItalic := F.Italic;
  907. FUnderline := F.Underline;
  908. FStrikeOut := F.StrikeOut;
  909. FSize := F.Size;
  910. FColor := F.Color;
  911. FName := F.Name;
  912. Modified;
  913. end;
  914. end
  915. else inherited;
  916. end;
  917. constructor TFontSettings.Create;
  918. begin
  919. FSize := 100;
  920. FColor := clNone;
  921. end;
  922. function TFontSettings.CreateTransformedFont(Src: HFont; var FontColor: TColor): HFont;
  923. var
  924. LF: TLogFont;
  925. begin
  926. GetObject(Src, SizeOf(LF), @LF);
  927. Apply(LF, FontColor);
  928. Result := CreateFontIndirect(LF);
  929. end;
  930. procedure TFontSettings.Modified;
  931. begin
  932. if Assigned(FOnChange) then FOnChange(Self);
  933. end;
  934. procedure TFontSettings.SetBold(Value: TTriState);
  935. begin
  936. if FBold <> Value then
  937. begin
  938. FBold := Value;
  939. Modified;
  940. end;
  941. end;
  942. procedure TFontSettings.SetColor(Value: TColor);
  943. begin
  944. if FColor <> Value then
  945. begin
  946. FColor := Value;
  947. Modified;
  948. end;
  949. end;
  950. procedure TFontSettings.SetItalic(Value: TTriState);
  951. begin
  952. if FItalic <> Value then
  953. begin
  954. FItalic := Value;
  955. Modified;
  956. end;
  957. end;
  958. procedure TFontSettings.SetName(const Value: TFontName);
  959. begin
  960. if FName <> Value then
  961. begin
  962. FName := Value;
  963. Modified;
  964. end;
  965. end;
  966. procedure TFontSettings.SetSize(Value: TFontSize);
  967. begin
  968. if FSize <> Value then
  969. begin
  970. FSize := Value;
  971. Modified;
  972. end;
  973. end;
  974. procedure TFontSettings.SetStrikeOut(Value: TTriState);
  975. begin
  976. if FStrikeOut <> Value then
  977. begin
  978. FStrikeOut := Value;
  979. Modified;
  980. end;
  981. end;
  982. procedure TFontSettings.SetUnderline(Value: TTriState);
  983. begin
  984. if FUnderline <> Value then
  985. begin
  986. FUnderline := Value;
  987. Modified;
  988. end;
  989. end;
  990. //============================================================================//
  991. { TTBXCustomItem }
  992. constructor TTBXCustomItem.Create(AOwner: TComponent);
  993. begin
  994. inherited;
  995. FFontSettings := TFontSettings.Create;
  996. FFontSettings.OnChange := FontSettingsChanged;
  997. end;
  998. function TTBXCustomItem.CreatePopup(const ParentView: TTBView;
  999. const ParentViewer: TTBItemViewer; const PositionAsSubmenu,
  1000. SelectFirstItem, Customizing: Boolean; const APopupPoint: TPoint;
  1001. const Alignment: TTBPopupAlignment): TTBPopupWindow;
  1002. var
  1003. DoSelectFirstItem: Boolean;
  1004. begin
  1005. if AlwaysSelectFirst then DoSelectFirstItem := True
  1006. else DoSelectFirstItem := SelectFirstItem;
  1007. Result := inherited CreatePopup(ParentView, ParentViewer, PositionAsSubmenu,
  1008. DoSelectFirstItem, Customizing, APopupPoint, Alignment);
  1009. end;
  1010. destructor TTBXCustomItem.Destroy;
  1011. begin
  1012. FFontSettings.Free;
  1013. inherited;
  1014. end;
  1015. procedure TTBXCustomItem.FontSettingsChanged(Sender: TObject);
  1016. begin
  1017. Change(True);
  1018. end;
  1019. function TTBXCustomItem.GetItemViewerClass(AView: TTBView): TTBItemViewerClass;
  1020. begin
  1021. Result := TTBXItemViewer;
  1022. end;
  1023. procedure TTBXCustomItem.GetPopupPosition(ParentView: TTBView;
  1024. PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec);
  1025. var
  1026. VT: Integer;
  1027. begin
  1028. if CurrentTheme.OfficeXPPopupAlignment then with PopupPositionRec do
  1029. begin
  1030. GetOfficeXPPopupPosition1(PopupPositionRec);
  1031. inherited GetPopupPosition(ParentView, PopupWindow, PopupPositionRec);
  1032. GetOfficeXPPopupPosition2(PopupPositionRec);
  1033. VT := GetWinViewType(PopupWindow);
  1034. PopupPositionRec.PlaySound := not (VT and PVT_LISTBOX = PVT_LISTBOX);
  1035. end
  1036. else inherited;
  1037. end;
  1038. function TTBXCustomItem.GetPopupWindowClass: TTBPopupWindowClass;
  1039. begin
  1040. Result := TTBXPopupWindow;
  1041. end;
  1042. function TTBXCustomItem.GetStretch: Boolean;
  1043. begin
  1044. Result := tbisStretch in ItemStyle;
  1045. end;
  1046. procedure TTBXCustomItem.Invalidate;
  1047. begin
  1048. Change(False);
  1049. end;
  1050. procedure TTBXCustomItem.SetFontSettings(Value: TFontSettings);
  1051. begin
  1052. FFontSettings.Assign(Value);
  1053. end;
  1054. procedure TTBXCustomItem.SetLayout(Value: TTBXItemLayout);
  1055. begin
  1056. if Value <> FLayout then
  1057. begin
  1058. FLayout := Value;
  1059. Change(True);
  1060. end;
  1061. end;
  1062. procedure TTBXCustomItem.SetMinHeight(Value: Integer);
  1063. begin
  1064. if Value <> FMinHeight then
  1065. begin
  1066. FMinHeight := Value;
  1067. Change(True);
  1068. end;
  1069. end;
  1070. procedure TTBXCustomItem.SetMinWidth(Value: Integer);
  1071. begin
  1072. if Value <> FMinWidth then
  1073. begin
  1074. FMinWidth := Value;
  1075. Change(True);
  1076. end;
  1077. end;
  1078. procedure TTBXCustomItem.SetStretch(Value: Boolean);
  1079. begin
  1080. if Value xor (tbisStretch in ItemStyle) then
  1081. begin
  1082. if Value then ItemStyle := ItemStyle + [tbisStretch]
  1083. else ItemStyle := ItemStyle - [tbisStretch];
  1084. Change(True);
  1085. end;
  1086. end;
  1087. //============================================================================//
  1088. { TTBXItemViewer }
  1089. procedure TTBXItemViewer.CalcSize(const Canvas: TCanvas; var AWidth, AHeight: Integer);
  1090. const
  1091. CMarginIDs: array [Boolean] of Integer = (MID_MENUITEM, MID_TOOLBARITEM);
  1092. CStartSize: array [Boolean] of Integer = (0, 6);
  1093. var
  1094. W, H: Integer;
  1095. ImgSize: TSize;
  1096. Item: TTBCustomItem;
  1097. ItemLayout, SaveLayout: TTBXItemLayout;
  1098. IsCaptionShown: Boolean;
  1099. IsTextRotated: Boolean;
  1100. ToolbarStyle: Boolean;
  1101. S: string;
  1102. TextFlags: Cardinal;
  1103. TextMetric: TTextMetric;
  1104. TextSize: TSize;
  1105. Margins: TTBXMargins;
  1106. Two, Three: Integer;
  1107. begin
  1108. Item := TTBCustomItem(Self.Item);
  1109. ToolbarStyle := IsToolbarStyle;
  1110. ImgSize := GetImageSize;
  1111. if (ImgSize.CX <= 0) or (ImgSize.CY <= 0) then
  1112. begin
  1113. ImgSize.CX := 0;
  1114. ImgSize.CY := 0;
  1115. end;
  1116. if Item is TTBXCustomItem then ItemLayout := TTBXCustomItem(Item).Layout
  1117. else ItemLayout := tbxlAuto;
  1118. SaveLayout := ItemLayout;
  1119. if ItemLayout = tbxlAuto then
  1120. begin
  1121. if tboImageAboveCaption in Item.EffectiveOptions then ItemLayout := tbxlGlyphTop
  1122. else
  1123. begin
  1124. if View.Orientation <> tbvoVertical then ItemLayout := tbxlGlyphLeft
  1125. else ItemLayout := tbxlGlyphTop;
  1126. end;
  1127. end;
  1128. { Setup font }
  1129. TextFlags := 0;
  1130. IsCaptionShown := CaptionShown;
  1131. IsTextRotated := (View.Orientation = tbvoVertical) and ToolbarStyle;
  1132. if IsCaptionShown then
  1133. begin
  1134. S := GetCaptionText;
  1135. if not (SaveLayout = tbxlAuto) or (tboImageAboveCaption in Item.EffectiveOptions) then IsTextRotated := False;
  1136. if IsTextRotated or not ToolbarStyle then TextFlags := DT_SINGLELINE;
  1137. TextSize := GetTextSize(Canvas, S, TextFlags, IsTextRotated, 0);
  1138. end
  1139. else
  1140. begin
  1141. SetLength(S, 0);
  1142. TextSize.CX := 0;
  1143. TextSize.CY := 0;
  1144. IsTextRotated := False;
  1145. end;
  1146. { Measure size }
  1147. if ToolbarStyle then
  1148. begin
  1149. if not IsTextRotated then
  1150. begin
  1151. AWidth := 3;
  1152. AHeight := 6;
  1153. end
  1154. else
  1155. begin
  1156. AWidth := 6;
  1157. AHeight := 3;
  1158. end;
  1159. if CaptionShown then
  1160. begin
  1161. Three := ScaleByPixelsPerInch(3, View.GetMonitor);
  1162. Inc(AWidth, TextSize.CX);
  1163. Inc(AHeight, TextSize.CY);
  1164. if not IsTextRotated then Inc(AWidth, 2 * Three)
  1165. else Inc(AHeight, 2 * Three);
  1166. end;
  1167. if GetImageShown and (ImgSize.CX > 0) and (ImgSize.CY > 0) then
  1168. begin
  1169. if ItemLayout = tbxlGlyphLeft then
  1170. begin
  1171. Inc(AWidth, ImgSize.CX + 3);
  1172. if Wide then Inc(AWidth);
  1173. if AHeight < ImgSize.CY + 6 then AHeight := ImgSize.CY + 6;
  1174. end
  1175. else
  1176. begin
  1177. Inc(AHeight, ImgSize.CY + 3);
  1178. if AWidth < ImgSize.CX + 7 then AWidth := ImgSize.CX + 7;
  1179. end;
  1180. end;
  1181. if tbisSubmenu in TTBItemAccess(Item).ItemStyle then with CurrentTheme do
  1182. begin
  1183. if tbisCombo in TTBItemAccess(Item).ItemStyle then Inc(AWidth, GetIntegerMetrics(Self, TMI_SPLITBTN_ARROWWIDTH))
  1184. else if tboDropdownArrow in Item.EffectiveOptions then
  1185. begin
  1186. if (ItemLayout <> tbxlGlyphTop) or (ImgSize.CX = 0) or IsTextRotated then
  1187. begin
  1188. Two := ScaleByPixelsPerInch(2, View.GetMonitor);
  1189. if View.Orientation <> tbvoVertical then
  1190. begin
  1191. Inc(AWidth, Two + GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH))
  1192. end
  1193. else
  1194. begin
  1195. Inc(AHeight,
  1196. GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH) + Two +
  1197. GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWMARGIN));
  1198. end;
  1199. end
  1200. else
  1201. begin
  1202. if (ItemLayout = tbxlGlyphTop) and (IsTextRotated xor (View.Orientation <> tbvoVertical)) then
  1203. begin
  1204. W := ImgSize.CX + GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH) + 2;
  1205. if W > AWidth - 7 then AWidth := W + 7;
  1206. end
  1207. else
  1208. begin
  1209. H := ImgSize.CY + GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH) + 2;
  1210. if H > AHeight - 7 then AHeight := H + 7;
  1211. end;
  1212. end
  1213. end;
  1214. end;
  1215. end
  1216. else // Not a ToolbarStyle
  1217. with CurrentTheme do
  1218. begin
  1219. GetTextMetrics(Canvas.Handle, TextMetric);
  1220. Inc(TextSize.CY, TextMetric.tmExternalLeading);
  1221. AWidth := TextSize.CX;
  1222. AHeight := TextSize.CY;
  1223. if ImgSize.CY = 0 then ImgSize.CY := 16;
  1224. if AHeight < ImgSize.CY then AHeight := ImgSize.CY;
  1225. GetMargins(MID_MENUITEM, Margins);
  1226. Inc(AWidth, Margins.LeftWidth + Margins.RightWidth);
  1227. Inc(AHeight, Margins.TopHeight + Margins.BottomHeight);
  1228. Inc(AWidth,
  1229. GetPopupMargin(Self) + GetIntegerMetrics(Self, TMI_MENU_IMGTEXTSPACE) +
  1230. GetIntegerMetrics(Self, TMI_MENU_LCAPTIONMARGIN) + GetIntegerMetrics(Self, TMI_MENU_RCAPTIONMARGIN));
  1231. S := Item.GetShortCutText;
  1232. if Length(S) > 0 then Inc(AWidth, (AHeight - 6) + GetTextWidth(Canvas.Handle, S, True));
  1233. Inc(AWidth, AHeight); { Note: maybe this should be controlled by the theme }
  1234. end;
  1235. if Item is TTBXCustomItem then with TTBXCustomItem(Item) do
  1236. begin
  1237. if AWidth < MinWidth then AWidth := MinWidth;
  1238. if AHeight < MinHeight then AHeight := MinHeight;
  1239. end;
  1240. end;
  1241. constructor TTBXItemViewer.Create(AView: TTBView; AItem: TTBCustomItem; AGroupLevel: Integer);
  1242. begin
  1243. inherited;
  1244. FWide := True;
  1245. end;
  1246. procedure TTBXItemViewer.DoAdjustFont(AFont: TFont; StateFlags: Integer);
  1247. begin
  1248. if tboDefault in Item.EffectiveOptions then with AFont do Style := Style + [fsBold];
  1249. if Item is TTBXCustomItem then
  1250. with TTBXCustomItem(Item) do
  1251. begin
  1252. FontSettings.Apply(AFont);
  1253. if Assigned(FOnAdjustFont) then FOnAdjustFont(Item, Self, AFont, StateFlags);
  1254. end
  1255. else if Item is TTBXEditItem then
  1256. with TTBXEditItem(Item) do
  1257. begin
  1258. FontSettings.Apply(AFont);
  1259. end;
  1260. end;
  1261. procedure TTBXItemViewer.DoPaintCaption(Canvas: TCanvas; const ClientAreaRect: TRect;
  1262. var CaptionRect: TRect; IsTextRotated: Boolean; var PaintDefault: Boolean);
  1263. begin
  1264. // do nothing
  1265. end;
  1266. procedure TTBXItemViewer.DrawItemImage(Canvas: TCanvas; ARect: TRect; ItemInfo: TTBXItemInfo);
  1267. var
  1268. ImgList: TCustomImageList;
  1269. I: TTBXCustomItem;
  1270. begin
  1271. ImgList := GetImageList;
  1272. if (ImgList <> nil) and (Item.ImageIndex >= 0) and (Item.ImageIndex < ImgList.Count) then
  1273. begin
  1274. CurrentTheme.PaintImage(Canvas, ARect, ItemInfo, ImgList, Item.ImageIndex);
  1275. if Item is TTBXCustomItem then
  1276. begin
  1277. I := TTBXCustomItem(Item);
  1278. if Assigned(I.FOnDrawImage) then
  1279. I.FOnDrawImage(I, Self, Canvas, ARect,
  1280. CurrentTheme.GetImageOffset(Canvas, ItemInfo, ImgList),
  1281. GetStateFlags(ItemInfo));
  1282. end;
  1283. end;
  1284. end;
  1285. function TTBXItemViewer.GetAccRole: Integer;
  1286. { Returns the MSAA "role" of the viewer. }
  1287. const
  1288. { Constants from OleAcc.h }
  1289. ROLE_SYSTEM_BUTTONDROPDOWNGRID = $3A;
  1290. begin
  1291. Result := inherited GetAccRole;
  1292. if (Item is TTBXCustomItem) and TTBXCustomItem(Item).ToolBoxPopup and
  1293. (tbisSubmenu in TTBXCustomItem(Item).ItemStyle) then
  1294. Result := ROLE_SYSTEM_BUTTONDROPDOWNGRID;
  1295. end;
  1296. function TTBXItemViewer.GetImageShown: Boolean;
  1297. begin
  1298. Result := (Item.ImageIndex >= 0) and
  1299. ((Item.DisplayMode in [nbdmDefault, nbdmImageAndText]) or
  1300. (IsToolbarStyle and (Item.DisplayMode = nbdmTextOnlyInMenus)));
  1301. end;
  1302. function TTBXItemViewer.GetImageSize: TSize;
  1303. var
  1304. ImgList: TCustomImageList;
  1305. begin
  1306. ImgList := GetImageList;
  1307. with Result do if ImgList <> nil then
  1308. begin
  1309. CX := ImgList.Width;
  1310. CY := ImgList.Height;
  1311. end
  1312. else
  1313. begin
  1314. CX := 0;
  1315. CY := 0;
  1316. end;
  1317. end;
  1318. function TTBXItemViewer.GetItemType: Integer;
  1319. begin
  1320. if IsToolbarStyle then Result := IT_TOOLBARBUTTON
  1321. else Result := IT_MENUITEM;
  1322. end;
  1323. function TTBXItemViewer.GetTextFlags: Cardinal;
  1324. begin
  1325. Result := 0;
  1326. if not AreKeyboardCuesEnabled and (vsUseHiddenAccels in View.Style) and
  1327. not (vsShowAccels in View.State) then Result := DT_HIDEPREFIX;
  1328. end;
  1329. function TTBXItemViewer.GetTextSize(Canvas: TCanvas; const Text: string;
  1330. TextFlags: Cardinal; Rotated: Boolean; StateFlags: Integer): TSize;
  1331. var
  1332. DC: HDC;
  1333. R: TRect;
  1334. RotatedFont, SaveFont: HFONT;
  1335. TextMetric: TTextMetric;
  1336. begin
  1337. { note: rotated font size is consistent only for single-line captions! }
  1338. if Length(Text) = 0 then with Result do
  1339. begin
  1340. CX := 0;
  1341. CY := 0;
  1342. Exit;
  1343. end;
  1344. { Select proper font }
  1345. Canvas.Font := TTBViewAccess(View).GetFont;
  1346. DoAdjustFont(Canvas.Font, StateFlags);
  1347. if not Rotated then with R, Result do
  1348. begin
  1349. Left := 0; Right := 1;
  1350. Top := 0; Bottom := 0;
  1351. DrawText(Canvas.Handle, PChar(Text), Length(Text), R, TextFlags or DT_CALCRECT);
  1352. CX := Right;
  1353. CY := Bottom;
  1354. end
  1355. else
  1356. begin
  1357. DC := Canvas.Handle;
  1358. RotatedFont := CreateRotatedFont(DC);
  1359. SaveFont := SelectObject(DC, RotatedFont);
  1360. GetTextMetrics(DC, TextMetric);
  1361. Result.CX := TextMetric.tmHeight;
  1362. Result.CY := GetTextWidth(DC, Text, True);
  1363. SelectObject(DC, SaveFont);
  1364. DeleteObject(RotatedFont);
  1365. end;
  1366. end;
  1367. function TTBXItemViewer.IsPtInButtonPart(X, Y: Integer): Boolean;
  1368. var
  1369. W: Integer;
  1370. begin
  1371. Result := not (tbisSubmenu in TTBItemAccess(Item).ItemStyle);
  1372. if (tbisCombo in TTBItemAccess(Item).ItemStyle) then
  1373. begin
  1374. if IsToolbarStyle then W := CurrentTheme.GetIntegerMetrics(Self, TMI_SPLITBTN_ARROWWIDTH)
  1375. else W := GetSystemMetricsForControl(View.Window, SM_CXMENUCHECK);
  1376. Result := X < (BoundsRect.Right - BoundsRect.Left) - W;
  1377. end;
  1378. end;
  1379. function TTBXItemViewer.IsToolbarSize: Boolean;
  1380. begin
  1381. Result := inherited IsToolbarSize;
  1382. Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
  1383. end;
  1384. function TTBXItemViewer.IsToolbarStyle: Boolean;
  1385. begin
  1386. Result := inherited IsToolbarStyle;
  1387. Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
  1388. end;
  1389. procedure TTBXItemViewer.MouseUp(X, Y: Integer; MouseWasDownOnMenu: Boolean);
  1390. begin
  1391. inherited;
  1392. { Force the item to behave as a 'normal' menu item
  1393. That is make it respond to mouse as an item with IsToolbarStyle = False }
  1394. if Item.Enabled and not ((tbisSubmenu in TTBItemAccess(Item).ItemStyle) and
  1395. not IsPtInButtonPart(X, Y)) then
  1396. begin
  1397. if View.MouseOverSelected then
  1398. begin
  1399. Execute(True);
  1400. end;
  1401. end;
  1402. end;
  1403. procedure TTBXItemViewer.Paint(const Canvas: TCanvas;
  1404. const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean);
  1405. const
  1406. CToolbarStyle: array [Boolean] of Integer = (0, IO_TOOLBARSTYLE);
  1407. CCombo: array [Boolean] of Integer = (0, IO_COMBO);
  1408. CSubmenuItem: array [Boolean] of Integer = (0, IO_SUBMENUITEM);
  1409. CDesigning: array [Boolean] of Integer = (0, IO_DESIGNING);
  1410. CAppActive: array [Boolean] of Integer = (0, IO_APPACTIVE);
  1411. var
  1412. Item: TTBXCustomItem;
  1413. View: TTBViewAccess;
  1414. ItemInfo: TTBXItemInfo;
  1415. R: TRect;
  1416. ComboRect: TRect;
  1417. CaptionRect: TRect;
  1418. ImageRect: TRect;
  1419. C: TColor;
  1420. ToolbarStyle: Boolean;
  1421. HasArrow: Boolean;
  1422. IsSplit: Boolean;
  1423. ImageIsShown: Boolean;
  1424. ImageOrCheckShown: Boolean;
  1425. ImgAndArrowWidth: Integer;
  1426. ImgSize: TSize;
  1427. IsComboPushed: Boolean;
  1428. IsCaptionShown: Boolean;
  1429. IsTextRotated: Boolean;
  1430. ItemLayout: TTBXItemLayout;
  1431. PaintDefault: Boolean;
  1432. S: string;
  1433. StateFlags: Integer;
  1434. IsSpecialDropDown: Boolean;
  1435. TextFlags: Cardinal;
  1436. TextMetrics: TTextMetric;
  1437. TextSize: TSize;
  1438. Margins: TTBXMargins;
  1439. Three: Integer;
  1440. begin
  1441. Item := TTBXCustomItem(Self.Item);
  1442. View := TTBViewAccess(Self.View);
  1443. ToolbarStyle := IsToolbarStyle;
  1444. IsSplit := tbisCombo in Item.ItemStyle;
  1445. IsComboPushed := IsSplit and IsPushed and not View.Capture;
  1446. if IsComboPushed then IsPushed := False;
  1447. if GetImageShown then
  1448. begin
  1449. ImgSize := GetImageSize;
  1450. with ImgSize do if (CX <= 0) or (CY <= 0) then
  1451. begin
  1452. CX := 0;
  1453. CY := 0;
  1454. ImageIsShown := False;
  1455. end
  1456. else ImageIsShown := True;
  1457. end
  1458. else
  1459. begin
  1460. ImgSize.CX := 0;
  1461. ImgSize.CY := 0;
  1462. ImageIsShown := False;
  1463. end;
  1464. IsSplit := tbisCombo in Item.ItemStyle;
  1465. FillChar(ItemInfo, SizeOf(ItemInfo), 0);
  1466. ItemInfo.Control := View.Window;
  1467. ItemInfo.ViewType := GetViewType(View);
  1468. ItemInfo.ItemOptions := CToolbarStyle[ToolbarStyle] or CCombo[IsSplit] or
  1469. CDesigning[csDesigning in Item.ComponentState] or CSubmenuItem[tbisSubmenu in Item.ItemStyle] or
  1470. CAppActive[Application.Active];
  1471. ItemInfo.Enabled := Item.Enabled or View.Customizing;
  1472. ItemInfo.Pushed := IsPushed;
  1473. ItemInfo.Selected := Item.Checked;
  1474. ItemInfo.ImageShown := ImageIsShown;
  1475. ItemInfo.ImageWidth := ImgSize.CX;
  1476. ItemInfo.ImageHeight := ImgSize.CY;
  1477. if IsHoverItem then
  1478. begin
  1479. if not ItemInfo.Enabled and not View.MouseOverSelected then ItemInfo.HoverKind := hkKeyboardHover
  1480. else if ItemInfo.Enabled then ItemInfo.HoverKind := hkMouseHover;
  1481. end
  1482. else ItemInfo.HoverKind := hkNone;
  1483. ItemInfo.IsPopupParent := ToolbarStyle and
  1484. (((vsModal in View.State) and Assigned(View.OpenViewer)) or (tbisSubmenu in Item.ItemStyle)) and
  1485. ((IsSplit and IsComboPushed) or (not IsSplit and IsPushed));
  1486. ItemInfo.IsVertical := (View.Orientation = tbvoVertical) and not IsSplit;
  1487. ItemInfo.PopupMargin := GetPopupMargin(Self);
  1488. ItemLayout := Item.Layout;
  1489. if ItemLayout = tbxlAuto then
  1490. begin
  1491. if tboImageAboveCaption in Item.EffectiveOptions then ItemLayout := tbxlGlyphTop
  1492. else if View.Orientation <> tbvoVertical then ItemLayout := tbxlGlyphLeft
  1493. else ItemLayout := tbxlGlyphTop;
  1494. end;
  1495. HasArrow := (tbisSubmenu in Item.ItemStyle) and
  1496. ((tbisCombo in Item.ItemStyle) or (tboDropdownArrow in Item.EffectiveOptions));
  1497. if GetImageShown then
  1498. begin
  1499. ImgSize := GetImageSize;
  1500. with ImgSize do if (CX <= 0) or (CY <= 0) then
  1501. begin
  1502. CX := 0;
  1503. CY := 0;
  1504. ImageIsShown := False;
  1505. end
  1506. else ImageIsShown := True;
  1507. end
  1508. else
  1509. begin
  1510. ImgSize.CX := 0;
  1511. ImgSize.CY := 0;
  1512. ImageIsShown := False;
  1513. end;
  1514. ImageOrCheckShown := ImageIsShown or (not ToolbarStyle and Item.Checked);
  1515. StateFlags := GetStateFlags(ItemInfo);
  1516. Canvas.Font := TTBViewAccess(View).GetFont;
  1517. Canvas.Font.Color := CurrentTheme.GetItemTextColor(ItemInfo);
  1518. DoAdjustFont(Canvas.Font, StateFlags);
  1519. C := Canvas.Font.Color;
  1520. { Setup font }
  1521. TextFlags := GetTextFlags;
  1522. IsCaptionShown := CaptionShown;
  1523. IsTextRotated := (View.Orientation = tbvoVertical) and ToolbarStyle;
  1524. if IsCaptionShown then
  1525. begin
  1526. S := GetCaptionText;
  1527. if (Item.Layout <> tbxlAuto) or (tboImageAboveCaption in Item.EffectiveOptions) then
  1528. IsTextRotated := False;
  1529. if IsTextRotated or not ToolbarStyle then TextFlags := TextFlags or DT_SINGLELINE;
  1530. TextSize := GetTextSize(Canvas, S, TextFlags, IsTextRotated, StateFlags);
  1531. end
  1532. else
  1533. begin
  1534. StateFlags := 0;
  1535. SetLength(S, 0);
  1536. IsTextRotated := False;
  1537. TextSize.CX := 0;
  1538. TextSize.CY := 0;
  1539. end;
  1540. IsSpecialDropDown := HasArrow and not IsSplit and ToolbarStyle and
  1541. ((Item.Layout = tbxlGlyphTop) or (Item.Layout = tbxlAuto) and (tboImageAboveCaption in Item.EffectiveOptions)) and
  1542. (ImgSize.CX > 0) and not (IsTextRotated) and (TextSize.CX > 0);
  1543. { Border & Arrows }
  1544. R := ClientAreaRect;
  1545. with CurrentTheme do if ToolbarStyle then
  1546. begin
  1547. GetMargins(MID_TOOLBARITEM, Margins);
  1548. if HasArrow then with R do
  1549. begin
  1550. ItemInfo.ComboPart := cpCombo;
  1551. if IsSplit then
  1552. begin
  1553. ItemInfo.ComboPart := cpSplitLeft;
  1554. ComboRect := R;
  1555. Dec(Right, GetIntegerMetrics(Self, TMI_SPLITBTN_ARROWWIDTH));
  1556. ComboRect.Left := Right;
  1557. end
  1558. else if not IsSpecialDropDown then
  1559. begin
  1560. if View.Orientation <> tbvoVertical then
  1561. begin
  1562. ComboRect :=
  1563. Rect(
  1564. Right - GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH) -
  1565. GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWMARGIN), 0,
  1566. Right - GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWMARGIN), Bottom);
  1567. end
  1568. else
  1569. begin
  1570. ComboRect :=
  1571. Rect(0,
  1572. Bottom - GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH) -
  1573. GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWMARGIN),
  1574. Right, Bottom - GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWMARGIN));
  1575. end;
  1576. end
  1577. else
  1578. begin
  1579. ImgAndArrowWidth := ImgSize.CX + GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH) + 2;
  1580. ComboRect.Right := (R.Left + R.Right + ImgAndArrowWidth + 2) div 2;
  1581. ComboRect.Left := ComboRect.Right - GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH);
  1582. ComboRect.Top := (R.Top + R.Bottom - ImgSize.cy - 2 - TextSize.CY) div 2;
  1583. ComboRect.Bottom := ComboRect.Top + ImgSize.CY;
  1584. end;
  1585. end
  1586. else SetRectEmpty(ComboRect);
  1587. if not IsSplit then
  1588. begin
  1589. PaintButton(Canvas, R, ItemInfo);
  1590. if HasArrow then
  1591. begin
  1592. PaintDropDownArrow(Canvas, ComboRect, ItemInfo);
  1593. if not IsSpecialDropDown then
  1594. begin
  1595. if View.Orientation <> tbvoVertical then Dec(R.Right, GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH))
  1596. else Dec(R.Bottom, GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH));
  1597. end;
  1598. end;
  1599. end
  1600. else // IsSplit
  1601. begin
  1602. CurrentTheme.PaintButton(Canvas, R, ItemInfo);
  1603. ItemInfo.Pushed := IsComboPushed;
  1604. ItemInfo.Selected := False;
  1605. ItemInfo.ComboPart := cpSplitRight;
  1606. CurrentTheme.PaintButton(Canvas, ComboRect, ItemInfo);
  1607. ItemInfo.ComboPart := cpSplitLeft;
  1608. ItemInfo.Pushed := IsPushed;
  1609. ItemInfo.Selected := Item.Checked;
  1610. end;
  1611. InflateRect(R, -2, -2);
  1612. end
  1613. else // not toolbar style
  1614. begin
  1615. GetMargins(MID_MENUITEM, Margins);
  1616. PaintMenuItem(Canvas, R, ItemInfo);
  1617. Inc(R.Left, Margins.LeftWidth);
  1618. Dec(R.Right, Margins.RightWidth);
  1619. Inc(R.Top, Margins.TopHeight);
  1620. Dec(R.Bottom, Margins.BottomHeight);
  1621. end;
  1622. { Caption }
  1623. if IsCaptionShown then
  1624. begin
  1625. if ToolbarStyle then
  1626. begin
  1627. CaptionRect := R;
  1628. TextFlags := TextFlags or DT_CENTER or DT_VCENTER;
  1629. Three := ScaleByPixelsPerInch(3, View.GetMonitor);
  1630. if ImageIsShown then with CaptionRect do
  1631. case ItemLayout of
  1632. tbxlGlyphLeft:
  1633. begin
  1634. Inc(Left, ImgSize.CX + Three + 1);
  1635. Top := (Top + Bottom - TextSize.CY) div 2;
  1636. Bottom := Top + TextSize.CY;
  1637. Left := (Left + Right - TextSize.CX) div 2;
  1638. Right := Left + TextSize.CX;
  1639. TextFlags := TextFlags and not DT_CENTER;
  1640. end;
  1641. tbxlGlyphTop:
  1642. begin
  1643. Inc(Top, ImgSize.CY + 1);
  1644. if IsTextRotated then Inc(CaptionRect.Top, 3);
  1645. Top := (Top + Bottom - TextSize.CY) div 2;
  1646. Bottom := Top + TextSize.CY;
  1647. Left := (Left + Right - TextSize.CX) div 2;
  1648. Right := Left + TextSize.CX;
  1649. TextFlags := TextFlags and not DT_VCENTER;
  1650. end;
  1651. end
  1652. else
  1653. begin
  1654. with CaptionRect, TextSize do
  1655. begin
  1656. Left := (Left + R.Right - CX) div 2;
  1657. Top := (Top + R.Bottom - CY) div 2;
  1658. Right := Left + CX;
  1659. Bottom := Top + CY;
  1660. end;
  1661. end;
  1662. Canvas.Font.Color := C;
  1663. PaintDefault := True;
  1664. DoPaintCaption(Canvas, ClientAreaRect, CaptionRect, IsTextRotated, PaintDefault);
  1665. if PaintDefault then
  1666. CurrentTheme.PaintCaption(Canvas, CaptionRect, ItemInfo, S, TextFlags, IsTextRotated);
  1667. end
  1668. else with CurrentTheme do
  1669. begin
  1670. TextFlags := DT_LEFT or DT_VCENTER or TextFlags;
  1671. TextSize := GetTextSize(Canvas, S, TextFlags, False, StateFlags); { TODO : Check if this line is required }
  1672. GetTextMetrics(Canvas.Handle, TextMetrics);
  1673. CaptionRect := R;
  1674. Inc(CaptionRect.Left,
  1675. ItemInfo.PopupMargin + GetIntegerMetrics(Self, TMI_MENU_IMGTEXTSPACE) +
  1676. GetIntegerMetrics(Self, TMI_MENU_LCAPTIONMARGIN));
  1677. with TextMetrics, CaptionRect do
  1678. if (Bottom - Top) - (tmHeight + tmExternalLeading) = Margins.BottomHeight then Dec(Bottom);
  1679. Inc(CaptionRect.Top, TextMetrics.tmExternalLeading);
  1680. CaptionRect.Right := CaptionRect.Left + TextSize.CX;
  1681. Canvas.Font.Color := C;
  1682. PaintDefault := True;
  1683. DoPaintCaption(Canvas, ClientAreaRect, CaptionRect, IsTextRotated, PaintDefault);
  1684. if PaintDefault then
  1685. CurrentTheme.PaintCaption(Canvas, CaptionRect, ItemInfo, S, TextFlags, IsTextRotated);
  1686. end;
  1687. end;
  1688. { Shortcut and/or submenu arrow (menus only) }
  1689. if not ToolbarStyle then
  1690. begin
  1691. S := Item.GetShortCutText;
  1692. if Length(S) > 0 then
  1693. begin
  1694. CaptionRect := R;
  1695. with CaptionRect, TextMetrics do
  1696. begin
  1697. Left := Right - (Bottom - Top) - GetTextWidth(Canvas.Handle, S, True);
  1698. if (Bottom - Top) - (tmHeight + tmExternalLeading) = Margins.BottomHeight then Dec(Bottom);
  1699. Inc(Top, TextMetrics.tmExternalLeading);
  1700. end;
  1701. Canvas.Font.Color := C;
  1702. PaintDefault := True;
  1703. DoPaintCaption(Canvas, ClientAreaRect, CaptionRect, IsTextRotated, PaintDefault);
  1704. if PaintDefault then
  1705. CurrentTheme.PaintCaption(Canvas, CaptionRect, ItemInfo, S, TextFlags, False);
  1706. end;
  1707. end;
  1708. { Image, or check box }
  1709. if ImageOrCheckShown then
  1710. begin
  1711. ImageRect := R;
  1712. if ToolBarStyle then
  1713. begin
  1714. if IsSpecialDropDown then
  1715. OffsetRect(ImageRect, (-CurrentTheme.GetIntegerMetrics(Self, TMI_DROPDOWN_ARROWWIDTH) + 1) div 2, 0);
  1716. if ItemLayout = tbxlGlyphLeft then ImageRect.Right := ImageRect.Left + ImgSize.CX + 2
  1717. else
  1718. begin
  1719. ImageRect.Top := (ImageRect.Top + ImageRect.Bottom - ImgSize.cy - 2 - TextSize.cy) div 2;
  1720. ImageRect.Bottom := ImageRect.Top + ImgSize.CY;
  1721. end;
  1722. end
  1723. else ImageRect.Right := ImageRect.Left + ClientAreaRect.Bottom - ClientAreaRect.Top;
  1724. if ImageIsShown then with ImageRect, ImgSize do
  1725. begin
  1726. Left := Left + ((Right - Left) - CX) div 2;
  1727. ImageRect.Top := Top + ((Bottom - Top) - CY) div 2;
  1728. Right := Left + CX;
  1729. Bottom := Top + CY;
  1730. DrawItemImage(Canvas, ImageRect, ItemInfo);
  1731. end
  1732. else
  1733. if not ToolbarStyle and Item.Checked then
  1734. begin
  1735. if Item.RadioItem then
  1736. with ItemInfo do ItemOptions := ItemOptions or IO_RADIO;
  1737. CurrentTheme.PaintCheckMark(Canvas, ImageRect, ItemInfo);
  1738. end;
  1739. end;
  1740. end;
  1741. //============================================================================//
  1742. { TTBXSubmenuItem }
  1743. constructor TTBXSubmenuItem.Create(AOwner: TComponent);
  1744. begin
  1745. inherited;
  1746. ItemStyle := ItemStyle + [tbisSubMenu, tbisSubitemsEditable];
  1747. end;
  1748. function TTBXSubmenuItem.GetDropdownCombo: Boolean;
  1749. begin
  1750. Result := tbisCombo in ItemStyle;
  1751. end;
  1752. procedure TTBXSubmenuItem.SetDropdownCombo(Value: Boolean);
  1753. begin
  1754. if (tbisCombo in ItemStyle) <> Value then begin
  1755. if Value then ItemStyle := ItemStyle + [tbisCombo]
  1756. else ItemStyle := ItemStyle - [tbisCombo];
  1757. Change (True);
  1758. end;
  1759. end;
  1760. //============================================================================//
  1761. { TTBXSeparatorItem }
  1762. constructor TTBXSeparatorItem.Create(AOwner: TComponent);
  1763. begin
  1764. inherited;
  1765. FSize := -1; // use default from as in TTBSeparatorItem
  1766. end;
  1767. function TTBXSeparatorItem.GetItemViewerClass(AView: TTBView): TTBItemViewerClass;
  1768. begin
  1769. Result := TTBXSeparatorItemViewer;
  1770. end;
  1771. procedure TTBXSeparatorItem.SetSize(Value: Integer);
  1772. begin
  1773. if Value < -1 then Value := -1;
  1774. if Value <> FSize then
  1775. begin
  1776. FSize := Value;
  1777. Change(True);
  1778. end;
  1779. end;
  1780. //============================================================================//
  1781. { TTBXSeparatorItemViewer }
  1782. procedure TTBXSeparatorItemViewer.CalcSize(const Canvas: TCanvas;
  1783. var AWidth, AHeight: Integer);
  1784. var
  1785. SZ: Integer;
  1786. begin
  1787. SZ := TTBXSeparatorItem(Item).Size;
  1788. if SZ < 0 then
  1789. begin
  1790. if not IsToolbarStyle then SZ := CurrentTheme.GetIntegerMetrics(Self, TMI_MENU_SEPARATORSIZE)
  1791. else SZ := CurrentTheme.GetIntegerMetrics(Self, TMI_TLBR_SEPARATORSIZE);
  1792. if SZ < 0 then inherited CalcSize(Canvas, AWidth, AHeight)
  1793. else
  1794. begin
  1795. AWidth := SZ;
  1796. AHeight := SZ;
  1797. end;
  1798. end
  1799. else if not IsToolbarStyle then
  1800. begin
  1801. AHeight := SZ;
  1802. AWidth := 0;
  1803. end
  1804. else
  1805. begin
  1806. AWidth := SZ;
  1807. AHeight := SZ;
  1808. end;
  1809. end;
  1810. function TTBXSeparatorItemViewer.IsToolbarSize: Boolean;
  1811. begin
  1812. Result := inherited IsToolbarSize;
  1813. Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
  1814. end;
  1815. function TTBXSeparatorItemViewer.IsToolbarStyle: Boolean;
  1816. begin
  1817. Result := inherited IsToolbarStyle;
  1818. Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
  1819. end;
  1820. procedure TTBXSeparatorItemViewer.Paint(const Canvas: TCanvas;
  1821. const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean);
  1822. const
  1823. CToolbarStyle: array [Boolean] of Integer = (0, IO_TOOLBARSTYLE);
  1824. CDesigning: array [Boolean] of Integer = (0, IO_DESIGNING);
  1825. var
  1826. Item: TTBXSeparatorItem;
  1827. ItemInfo: TTBXItemInfo;
  1828. R: TRect;
  1829. LineSep, HorzLine: Boolean;
  1830. begin
  1831. Item := TTBXSeparatorItem(Self.Item);
  1832. if Item.Size = 0 then Exit;
  1833. FillChar(ItemInfo, SizeOf(TTBXItemInfo), 0);
  1834. ItemInfo.ViewType := GetViewType(View);
  1835. ItemInfo.ItemOptions := CToolbarStyle[IsToolbarStyle] or
  1836. CDesigning[csDesigning in Item.ComponentState];
  1837. ItemInfo.Enabled := not Item.Blank;
  1838. ItemInfo.Pushed := IsPushed;
  1839. ItemInfo.Selected := False;
  1840. ItemInfo.ImageShown := False;
  1841. ItemInfo.ImageWidth := 0;
  1842. ItemInfo.ImageHeight := 0;
  1843. ItemInfo.IsVertical := View.Orientation = tbvoVertical;
  1844. if not IsToolbarStyle then ItemInfo.PopupMargin := GetPopupMargin(Self);
  1845. R := ClientAreaRect;
  1846. LineSep := tbisLineSep in State;
  1847. with ItemInfo do
  1848. begin
  1849. HorzLine := (IsVertical xor LineSep) or View.IsPopup;
  1850. if (((ViewType and VT_POPUP) = VT_POPUP) and
  1851. ((ViewType and PVT_CHEVRONMENU) = PVT_CHEVRONMENU)) then
  1852. begin
  1853. if (not (Item.GetTopComponent is TTBCustomToolbar)) or
  1854. (not TTBCustomToolbar(Item.GetTopComponent).ChevronMenu) then
  1855. begin
  1856. HorzLine := (HorzLine and LineSep);
  1857. end;
  1858. end;
  1859. end;
  1860. CurrentTheme.PaintSeparator(Canvas, R, ItemInfo, HorzLine, LineSep);
  1861. end;
  1862. //============================================================================//
  1863. //============================================================================//
  1864. { TTBXPopupWindow }
  1865. procedure TTBXPopupWindow.CMHintShow(var Message: TCMHintShow);
  1866. begin
  1867. with Message.HintInfo^ do
  1868. begin
  1869. HintStr := '';
  1870. if Assigned(View.Selected) then
  1871. begin
  1872. CursorRect := View.Selected.BoundsRect;
  1873. HintStr := View.Selected.GetHintText;
  1874. View.Selected.Dispatch(Message);
  1875. end;
  1876. end;
  1877. end;
  1878. procedure TTBXPopupWindow.CMShowingChanged(var Message: TMessage);
  1879. const
  1880. ShowFlags: array[Boolean] of UINT = (
  1881. SWP_NOSIZE or SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_HIDEWINDOW,
  1882. SWP_NOSIZE or SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_SHOWWINDOW);
  1883. var
  1884. MenuAni: TMenuAnimation;
  1885. AniDir: TTBAnimationDirection;
  1886. begin
  1887. { Must override TCustomForm/TForm's CM_SHOWINGCHANGED handler so that the
  1888. form doesn't get activated when Visible is set to True. }
  1889. { Handle animation. NOTE: I do not recommend trying to enable animation on
  1890. Windows 95 and NT 4.0 because there's a difference in the way the
  1891. SetWindowPos works on those versions. See the comment in the
  1892. TBStartAnimation function of TB2Anim.pas. }
  1893. if ((View.ParentView = nil) or not(vsNoAnimation in View.ParentView.State)) and
  1894. Showing and (View.Selected = nil) and not IsWindowVisible(WindowHandle) and
  1895. (TBXMenuAnimation.AnimationMode <> amNone) then
  1896. begin
  1897. { Start animation only if WM_TB2K_POPUPSHOWING returns zero (or not handled) }
  1898. if SendMessage(WindowHandle, WM_TB2K_POPUPSHOWING, TPS_ANIMSTART, 0) = 0 then
  1899. begin
  1900. MenuAni := TBXMenuAnimation.MenuAnimation;
  1901. { MP (do not animate if disallowed by system-wide config) }
  1902. if MenuAni <> maNone then
  1903. begin
  1904. AniDir := TTBPopupWindowAccess(Self).AnimationDirection;
  1905. if MenuAni = maUnfold then
  1906. if [tbadDown, tbadUp] * AniDir <> []
  1907. then Include(AniDir, tbadRight)
  1908. else Include(AniDir, tbadDown);
  1909. TBStartAnimation(WindowHandle, MenuAni = maFade, AniDir);
  1910. Exit;
  1911. end;
  1912. end;
  1913. end;
  1914. { No animation... }
  1915. if not Showing then begin
  1916. { Call TBEndAnimation to ensure WS_EX_LAYERED style is removed before
  1917. hiding, otherwise windows under the popup window aren't repainted
  1918. properly. }
  1919. TBEndAnimation(WindowHandle);
  1920. end;
  1921. SetWindowPos(WindowHandle, 0, 0, 0, 0, 0, ShowFlags[Showing]);
  1922. if Showing then SendNotifyMessage(WindowHandle, WM_TB2K_POPUPSHOWING, TPS_NOANIM, 0);
  1923. end;
  1924. procedure TTBXPopupWindow.CreateParams(var Params: TCreateParams);
  1925. const
  1926. CS_DROPSHADOW = $00020000;
  1927. begin
  1928. inherited CreateParams(Params);
  1929. with Params do
  1930. begin
  1931. WindowClass.Style := WindowClass.Style and not (CS_DROPSHADOW or CS_DBLCLKS);
  1932. if GetShowShadow and (CurrentTheme.GetPopupShadowType = PST_WINDOWSXP) then
  1933. begin
  1934. WindowClass.Style := WindowClass.Style or CS_DROPSHADOW;
  1935. StrPCopy(WinClassName, ClassName + 'S');
  1936. end;
  1937. end;
  1938. end;
  1939. procedure TTBXPopupWindow.CreateShadow;
  1940. var
  1941. PR: TRect;
  1942. ParentViewer: TTBItemViewer;
  1943. VT: Integer;
  1944. ChevronParent: Boolean;
  1945. begin
  1946. PR := Rect(0, 0, 0, 0);
  1947. if CurrentTheme.GetPopupShadowType = PST_OFFICEXP then
  1948. begin
  1949. if (View <> nil) and (View.ParentView <> nil) then
  1950. begin
  1951. ParentViewer := TTBViewAccess(View.ParentView).OpenViewer;
  1952. ChevronParent := Self is TTBXChevronPopupWindow;
  1953. if ((ParentViewer is TTBXItemViewer) or ChevronParent) then
  1954. begin
  1955. VT := GetViewType(ParentViewer.View);
  1956. if ((VT and PVT_POPUPMENU) <> PVT_POPUPMENU) or ChevronParent then
  1957. begin
  1958. PR := ParentViewer.BoundsRect;
  1959. PR.TopLeft := View.ParentView.Window.ClientToScreen(PR.TopLeft);
  1960. PR.BottomRight := View.ParentView.Window.ClientToScreen(PR.BottomRight);
  1961. end;
  1962. end;
  1963. end
  1964. else if not IsRectEmpty(FControlRect) then
  1965. begin
  1966. PR := FControlRect;
  1967. end;
  1968. end;
  1969. FShadows := TShadows.Create(PR, BoundsRect, 4, 61, TBXLoColor);
  1970. FShadows.Show(Handle);
  1971. end;
  1972. destructor TTBXPopupWindow.Destroy;
  1973. begin
  1974. DestroyShadow;
  1975. inherited;
  1976. end;
  1977. procedure TTBXPopupWindow.DestroyShadow;
  1978. var
  1979. SaveShadows: TObject;
  1980. begin
  1981. SaveShadows := FShadows;
  1982. FShadows := nil;
  1983. SaveShadows.Free;
  1984. end;
  1985. function TTBXPopupWindow.GetFillColor: TColor;
  1986. begin
  1987. Result := CurrentTheme.GetViewColor(GetViewType(View));
  1988. View.BackgroundColor := Result;
  1989. end;
  1990. function TTBXPopupWindow.GetNCSize: TPoint;
  1991. begin
  1992. Result := inherited GetNCSize;
  1993. CurrentTheme.GetViewBorder(Self, GetViewType(View), Result);
  1994. end;
  1995. function TTBXPopupWindow.GetShowShadow: Boolean;
  1996. begin
  1997. Result := ((GetViewType(View) and PVT_LISTBOX) <> PVT_LISTBOX );
  1998. end;
  1999. function TTBXPopupWindow.GetViewClass: TTBViewClass;
  2000. begin
  2001. Result := TTBXPopupView;
  2002. end;
  2003. procedure TTBXPopupWindow.PaintScrollArrows;
  2004. function _GetPopupMargin: Integer;
  2005. begin
  2006. if View.ParentView <> nil then
  2007. Result := GetPopupMargin(TTBViewAccess(View.ParentView).OpenViewer)
  2008. else if View.ViewerCount > 0 then
  2009. Result := GetPopupMargin(View.Viewers[0])
  2010. else Result := -1;
  2011. end;
  2012. procedure DrawArrows;
  2013. var
  2014. ItemInfo: TTBXItemInfo;
  2015. Index: Integer;
  2016. begin
  2017. FillChar(ItemInfo, SizeOf(ItemInfo), 0);
  2018. ItemInfo.ViewType := PVT_POPUPMENU;
  2019. ItemInfo.Enabled := True;
  2020. ItemInfo.PopupMargin := _GetPopupMargin;
  2021. if ItemInfo.PopupMargin > 0 then
  2022. begin
  2023. if TTBViewAccess(View).ShowUpArrow then
  2024. for Index := 0 to View.ViewerCount- 1 do
  2025. if View.Viewers[Index].Show then
  2026. begin
  2027. CurrentTheme.PaintMenuItemFrame(Canvas, Rect(0, 0, ClientWidth,
  2028. View.Viewers[Index].BoundsRect.Top), ItemInfo);
  2029. Break;
  2030. end;
  2031. if TTBViewAccess(View).ShowDownArrow then
  2032. for Index := View.ViewerCount- 1 downto 0 do
  2033. if View.Viewers[Index].Show then
  2034. begin
  2035. CurrentTheme.PaintMenuItemFrame(Canvas, Rect(0,
  2036. View.Viewers[Index].BoundsRect.Bottom, ClientWidth,
  2037. ClientHeight), ItemInfo);
  2038. Break;
  2039. end;
  2040. end;
  2041. end;
  2042. begin
  2043. with TTBViewAccess(View) do
  2044. if ShowUpArrow or ShowDownArrow then
  2045. DrawArrows;
  2046. inherited;
  2047. end;
  2048. procedure TTBXPopupWindow.TBMGetViewType(var Message: TMessage);
  2049. var
  2050. PI: TTBCustomItem;
  2051. begin
  2052. Message.Result := PVT_POPUPMENU;
  2053. if View <> nil then
  2054. if Self is TTBXChevronPopupWindow then
  2055. Message.Result := PVT_CHEVRONMENU
  2056. else
  2057. begin
  2058. PI := View.ParentItem;
  2059. if PI <> nil then
  2060. begin
  2061. if (PI.Count = 1) and (PI.Items[0] is TTBXCustomList) then
  2062. Message.Result := PVT_LISTBOX
  2063. else if PI is TTBXEditItem then
  2064. begin
  2065. Message.Result := PVT_TOOLBOX;
  2066. end
  2067. else if (PI is TTBXCustomItem) and (TTBXCustomItem(PI).ToolBoxPopup) then
  2068. Message.Result := PVT_TOOLBOX
  2069. end;
  2070. end;
  2071. end;
  2072. procedure TTBXPopupWindow.WMEraseBkgnd(var Message: TWmEraseBkgnd);
  2073. var
  2074. Canvas: TCanvas;
  2075. R: TRect;
  2076. begin
  2077. TBEndAnimation(WindowHandle);
  2078. Canvas := TCanvas.Create;
  2079. Canvas.Handle := Message.DC;
  2080. R := ClientRect;
  2081. CurrentTheme.PaintBackgnd(Canvas, R, R, R, GetFillColor, False, GetViewType(View));
  2082. Canvas.Handle := 0;
  2083. Canvas.Free;
  2084. Message.Result := 1;
  2085. end;
  2086. procedure TTBXPopupWindow.WMNCCalcSize(var Message: TWMNCCalcSize);
  2087. var
  2088. Sz: TPoint;
  2089. begin
  2090. CurrentTheme.GetViewBorder(Self, GetViewType(View), Sz);
  2091. with Message.CalcSize_Params^.rgrc[0], Sz do
  2092. begin
  2093. Inc(Left, X);
  2094. Inc(Top, Y);
  2095. Dec(Right, X);
  2096. Dec(Bottom, Y);
  2097. end;
  2098. Message.Result := 1;
  2099. end;
  2100. procedure TBXPopupNCPaintProc(Control: TControl; Wnd: HWND; DC: HDC; AppData: Longint);
  2101. var
  2102. R, R2: TRect;
  2103. Canvas: TCanvas;
  2104. View: TTBPopupView;
  2105. PopupInfo: TTBXPopupInfo;
  2106. ParentViewer: TTBItemViewer;
  2107. begin
  2108. Assert(DC <> 0, 'TBXPopupNCPaintProc');
  2109. Canvas := TCanvas.Create;
  2110. try
  2111. Canvas.Handle := DC;
  2112. FillChar(PopupInfo, SizeOf(PopupInfo), 0);
  2113. View := TTBPopupView(AppData);
  2114. PopupInfo.WindowHandle := View.Window.Handle;
  2115. PopupInfo.ViewType := GetViewType(View);
  2116. if View.ParentView <> nil then
  2117. begin
  2118. ParentViewer := TTBViewAccess(View.ParentView).OpenViewer;
  2119. if ((ParentViewer is TTBXItemViewer) or (View.Window is TTBXChevronPopupWindow))
  2120. and TTBItemViewerAccess(ParentViewer).IsToolbarStyle then
  2121. begin
  2122. R := ParentViewer.BoundsRect;
  2123. R.TopLeft := View.ParentView.Window.ClientToScreen(R.TopLeft);
  2124. R.BottomRight := View.ParentView.Window.ClientToScreen(R.BottomRight);
  2125. GetWindowRect(Wnd, R2);
  2126. OffsetRect(R, -R2.Left, -R2.Top);
  2127. PopupInfo.ParentRect := R;
  2128. end;
  2129. end
  2130. else if View.ParentItem is TTBXRootItem then
  2131. begin
  2132. R := TTBXRootItem(View.ParentItem).FPopupControlRect;
  2133. if not IsRectEmpty(R) then
  2134. begin
  2135. GetWindowRect(Wnd, R2);
  2136. OffsetRect(R, -R2.Left, -R2.Top);
  2137. PopupInfo.ParentRect := R;
  2138. end;
  2139. end;
  2140. GetWindowRect(Wnd, R);
  2141. OffsetRect(R, -R.Left, -R.Top);
  2142. CurrentTheme.GetViewBorder(Control, PopupInfo.ViewType, PopupInfo.BorderSize);
  2143. R2 := R;
  2144. with PopupInfo.BorderSize do InflateRect(R2, -X, -Y);
  2145. with R2 do ExcludeClipRect(Canvas.Handle, Left, Top, Right, Bottom);
  2146. CurrentTheme.PaintPopupNCArea(Canvas, R, PopupInfo);
  2147. finally
  2148. Canvas.Handle := 0;
  2149. Canvas.Free;
  2150. end;
  2151. end;
  2152. procedure TTBXPopupWindow.WMNCPaint(var Message: TMessage);
  2153. var
  2154. DC: HDC;
  2155. begin
  2156. DC := GetWindowDC(Handle);
  2157. try
  2158. Assert(DC <> 0, 'TTBXPopupWindow.WMNCPaint');
  2159. SelectNCUpdateRgn(Handle, DC, HRGN(Message.WParam));
  2160. TBXPopupNCPaintProc(Self, Handle, DC, LongInt(Self.View));
  2161. finally
  2162. ReleaseDC(Handle, DC);
  2163. end;
  2164. end;
  2165. procedure TTBXPopupWindow.WMPrint(var Message: TMessage);
  2166. begin
  2167. HandleWMPrint(Self, Handle, Message, TBXPopupNCPaintProc, LongInt(Self.View));
  2168. end;
  2169. procedure TTBXPopupWindow.WMTB2kPopupShowing(var Message: TMessage);
  2170. begin
  2171. if Message.WParam in [TPS_ANIMFINISHED, TPS_NOANIM] then
  2172. begin
  2173. if not (csDestroying in ComponentState) and GetShowShadow and
  2174. (CurrentTheme.GetPopupShadowType in [PST_OFFICEXP, PST_WINDOWS2K]) then CreateShadow;
  2175. end;
  2176. end;
  2177. procedure TTBXPopupWindow.WMWindowPosChanged(var Message: TWMWindowPosChanged);
  2178. begin
  2179. inherited;
  2180. with Message.WindowPos^ do
  2181. if ((flags and SWP_SHOWWINDOW) = 0) and ((flags and SWP_HIDEWINDOW) = 0) then
  2182. begin
  2183. if FShadows <> nil then
  2184. begin
  2185. DestroyShadow;
  2186. CreateShadow;
  2187. end;
  2188. end;
  2189. end;
  2190. //============================================================================//
  2191. { TTBXToolbarView }
  2192. procedure TTBXToolbarView.GetMargins(AOrientation: TTBViewOrientation; var Margins: TRect);
  2193. var
  2194. VT: Integer;
  2195. M: TTBXMargins;
  2196. begin
  2197. VT := GetWinViewType(TTBXToolbar(Owner));
  2198. if (VT and VT_TOOLBAR) = VT_TOOLBAR then
  2199. begin
  2200. if AOrientation = tbvoFloating then VT := VT or TVT_FLOATING
  2201. else VT := VT and not TVT_FLOATING
  2202. end
  2203. else if (VT and VT_DOCKPANEL) = VT_DOCKPANEL then
  2204. begin
  2205. if AOrientation = tbvoFloating then VT := VT or DPVT_FLOATING
  2206. else VT := VT and not DPVT_FLOATING
  2207. end;
  2208. CurrentTheme.GetViewMargins(VT, M);
  2209. Margins.Left := M.LeftWidth;
  2210. Margins.Top := M.TopHeight;
  2211. Margins.Right := M.RightWidth;
  2212. Margins.Bottom := M.BottomHeight;
  2213. end;
  2214. //============================================================================//
  2215. { TTBXToolbar }
  2216. procedure TTBXToolbar.CMColorChanged(var Message: TMessage);
  2217. begin
  2218. UpdateEffectiveColor;
  2219. if Docked and HandleAllocated then
  2220. begin
  2221. RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
  2222. RDW_ERASE or RDW_UPDATENOW or RDW_ALLCHILDREN);
  2223. end;
  2224. UpdateChildColors;
  2225. Invalidate;
  2226. end;
  2227. procedure TTBXToolbar.CMControlChange(var Message: TCMControlChange);
  2228. begin
  2229. inherited;
  2230. if Message.Inserting and (Color = clNone) then
  2231. Message.Control.Perform(CM_PARENTCOLORCHANGED, 1, EffectiveColor);
  2232. end;
  2233. procedure TTBXToolbar.CMParentColorChanged(var Message: TMessage);
  2234. begin
  2235. if Embedded and (Color = clNone) then
  2236. begin
  2237. UpdateEffectiveColor;
  2238. if (Message.WParam = 0) then
  2239. begin
  2240. Message.WParam := 1;
  2241. Message.LParam := EffectiveColor;
  2242. end;
  2243. end;
  2244. inherited;
  2245. Invalidate;
  2246. end;
  2247. constructor TTBXToolbar.Create(AOwner: TComponent);
  2248. begin
  2249. inherited;
  2250. AddThemeNotification(Self);
  2251. FEffectiveColor := Color;
  2252. Color := clNone;
  2253. ControlStyle := ControlStyle - [csOpaque];
  2254. DblClickUndock := False;
  2255. end;
  2256. destructor TTBXToolbar.Destroy;
  2257. begin
  2258. RemoveThemeNotification(Self);
  2259. inherited;
  2260. end;
  2261. procedure TTBXToolbar.DrawNCArea(const DrawToDC: Boolean; const ADC: HDC; const Clip: HRGN);
  2262. var
  2263. DC: HDC;
  2264. R, CR, R2: TRect;
  2265. ACanvas: TCanvas;
  2266. ToolbarInfo: TTBXToolbarInfo;
  2267. UsingBackground: Boolean;
  2268. begin
  2269. if not Docked or not HandleAllocated then Exit;
  2270. if not DrawToDC then DC := GetWindowDC(Handle)
  2271. else DC := ADC;
  2272. UsingBackground := TDockAccess(CurrentDock).UsingBackground;
  2273. try
  2274. GetToolbarInfo(ToolbarInfo);
  2275. GetWindowRect(Handle, R);
  2276. OffsetRect(R, -R.Left, -R.Top);
  2277. if not DrawToDC then
  2278. begin
  2279. SelectNCUpdateRgn(Handle, DC, Clip);
  2280. CR := R;
  2281. with ToolbarInfo.BorderSize, CR do
  2282. begin
  2283. InflateRect(CR, -X, -Y);
  2284. if ToolbarInfo.IsVertical then Inc(Top, GetTBXDragHandleSize(ToolbarInfo))
  2285. else Inc(Left, GetTBXDragHandleSize(ToolbarInfo));
  2286. ExcludeClipRect(DC, Left, Top, Right, Bottom);
  2287. end;
  2288. end;
  2289. ACanvas := TCanvas.Create;
  2290. try
  2291. ACanvas.Handle := DC;
  2292. if CurrentTheme.SolidToolbarNCArea then
  2293. begin
  2294. ACanvas.Brush.Color := EffectiveColor;
  2295. ACanvas.Brush.Style := bsSolid;
  2296. end
  2297. else if UsingBackground then
  2298. begin
  2299. ACanvas.Brush.Color := EffectiveColor;
  2300. R2 := CurrentDock.ClientRect;
  2301. OffsetRect(R2, -Left, -Top);
  2302. TDockAccess(CurrentDock).DrawBackground(DC, R2);
  2303. end
  2304. else
  2305. begin
  2306. ACanvas.Brush.Color := GetEffectiveColor(CurrentDock);
  2307. ACanvas.FillRect(R);
  2308. ACanvas.Brush.Color := EffectiveColor;
  2309. ACanvas.Brush.Style := bsSolid;
  2310. end;
  2311. CurrentTheme.PaintToolbarNCArea(GetMonitorFromControl(Self), ACanvas, R, ToolbarInfo);
  2312. finally
  2313. ACanvas.Handle := 0;
  2314. ACanvas.Free;
  2315. end;
  2316. finally
  2317. if not DrawToDC then ReleaseDC(Handle, DC);
  2318. end;
  2319. end;
  2320. function TTBXToolbar.Embedded: Boolean;
  2321. begin
  2322. Result := not (Floating or Docked);
  2323. end;
  2324. function TTBXToolbar.GetChevronItemClass: TTBChevronItemClass;
  2325. begin
  2326. Result := TTBXChevronItem;
  2327. end;
  2328. function TTBXToolbar.GetFloatingBorderSize: TPoint;
  2329. begin
  2330. CurrentTheme.GetViewBorder(Self, GetViewType(View) or TVT_FLOATING, Result);
  2331. end;
  2332. function TTBXToolbar.GetFloatingWindowParentClass: TTBFloatingWindowParentClass;
  2333. begin
  2334. Result := TTBXFloatingWindowParent;
  2335. end;
  2336. procedure TTBXToolbar.GetToolbarInfo(out ToolbarInfo: TTBXToolbarInfo);
  2337. begin
  2338. FillChar(ToolbarInfo, SizeOf(ToolbarInfo), 0);
  2339. ToolbarInfo.WindowHandle := Handle;
  2340. ToolbarInfo.ViewType := GetWinViewType(Self);
  2341. if CurrentDock <> nil then
  2342. ToolbarInfo.IsVertical := CurrentDock.Position in [dpLeft,dpRight];
  2343. ToolbarInfo.AllowDrag := CurrentDock.AllowDrag;
  2344. ToolbarInfo.DragHandleStyle := Ord(DragHandleStyle);
  2345. ToolbarInfo.ClientWidth := ClientWidth;
  2346. ToolbarInfo.ClientHeight := ClientHeight;
  2347. if ToolbarInfo.AllowDrag and CloseButtonWhenDocked then
  2348. begin
  2349. ToolbarInfo.CloseButtonState := CDBS_VISIBLE;
  2350. if CloseButtonDown then ToolbarInfo.CloseButtonState := ToolbarInfo.CloseButtonState or CDBS_PRESSED
  2351. else if CloseButtonHover then ToolbarInfo.CloseButtonState := ToolbarInfo.CloseButtonState or CDBS_HOT;
  2352. end;
  2353. ToolbarInfo.BorderStyle := BorderStyle;
  2354. CurrentTheme.GetViewBorder(Self, ToolbarInfo.ViewType, ToolbarInfo.BorderSize);
  2355. ToolbarInfo.EffectiveColor := EffectiveColor;
  2356. end;
  2357. function TTBXToolbar.GetViewClass: TTBToolbarViewClass;
  2358. begin
  2359. Result := TTBXToolbarView;
  2360. end;
  2361. procedure TTBXToolbar.SetItemTransparency(const Value: TTBXItemTransparency);
  2362. begin
  2363. FItemTransparency := Value;
  2364. Invalidate;
  2365. end;
  2366. procedure TTBXToolbar.Loaded;
  2367. begin
  2368. inherited;
  2369. UpdateEffectiveColor;
  2370. end;
  2371. procedure TTBXToolbar.SetParent(AParent: TWinControl);
  2372. begin
  2373. inherited;
  2374. if AParent is TTBXFloatingWindowParent then
  2375. begin
  2376. TTBXFloatingWindowParent(AParent).SnapDistance := SnapDistance;
  2377. // See the comment in TTBXToolbar.Rebuild
  2378. Rebuild;
  2379. end;
  2380. end;
  2381. procedure TTBXToolbar.SetSnapDistance(Value: Integer);
  2382. begin
  2383. if Value < 0 then Value := 0;
  2384. FSnapDistance := Value;
  2385. if (Parent <> nil) and (Parent is TTBXFloatingWindowParent) then
  2386. TTBXFloatingWindowParent(Parent).SnapDistance := Value;
  2387. end;
  2388. procedure TTBXToolbar.TBMGetEffectiveColor(var Message: TMessage);
  2389. begin
  2390. Message.WParam := EffectiveColor;
  2391. Message.Result := 1;
  2392. end;
  2393. procedure TTBXToolbar.TBMGetViewType(var Message: TMessage);
  2394. begin
  2395. if MenuBar then Message.Result := TVT_MENUBAR
  2396. else Message.Result := TVT_NORMALTOOLBAR;
  2397. if Floating then Message.Result := Message.Result or TVT_FLOATING;
  2398. if Resizable then Message.Result := Message.Result or TVT_RESIZABLE;
  2399. case ItemTransparency of
  2400. itAuto:
  2401. if not (Floating or Docked) then Message.Result := Message.Result or TVT_EMBEDDED;
  2402. itDisable:
  2403. Message.Result := Message.Result or TVT_EMBEDDED;
  2404. end;
  2405. end;
  2406. procedure TTBXToolbar.Rebuild;
  2407. begin
  2408. if Floating then
  2409. begin
  2410. // Is not set yet, when called from within SetParent > WMDpiChangedAfterParent while undocking on
  2411. // per-monitor-DPI system. We will call Rebuild again at the end of the SetParent
  2412. if Assigned(Parent) then
  2413. UpdateNCArea(TTBXFloatingWindowParent(Parent), GetWinViewType(Self));
  2414. end
  2415. else
  2416. begin
  2417. UpdateNCArea(Self, GetWinViewType(Self));
  2418. end;
  2419. Invalidate;
  2420. Arrange;
  2421. end;
  2422. procedure TTBXToolbar.TBMThemeChange(var Message: TMessage);
  2423. begin
  2424. case Message.WParam of
  2425. TSC_BEFOREVIEWCHANGE: BeginUpdate;
  2426. TSC_AFTERVIEWCHANGE:
  2427. begin
  2428. EndUpdate;
  2429. UpdateEffectiveColor;
  2430. Rebuild;
  2431. UpdateChildColors;
  2432. end;
  2433. TSC_APPACTIVATE, TSC_APPDEACTIVATE:
  2434. if MenuBar then Invalidate;
  2435. end;
  2436. end;
  2437. procedure TTBXToolbar.WMDpiChangedBeforeParent(var Message: TMessage);
  2438. begin
  2439. BeginUpdate;
  2440. end;
  2441. procedure TTBXToolbar.WMDpiChangedAfterParent(var Message: TMessage);
  2442. begin
  2443. EndUpdate;
  2444. Rebuild;
  2445. end;
  2446. procedure TTBXToolbar.UpdateChildColors;
  2447. var
  2448. M: TMessage;
  2449. begin
  2450. M.Msg := CM_PARENTCOLORCHANGED;
  2451. M.WParam := 1;
  2452. M.LParam := EffectiveColor;
  2453. M.Result := 0;
  2454. Broadcast(M);
  2455. end;
  2456. procedure TTBXToolbar.UpdateEffectiveColor;
  2457. begin
  2458. if Color = clNone then
  2459. begin
  2460. if Embedded and (Parent <> nil) then
  2461. FEffectiveColor := GetEffectiveColor(Parent)
  2462. else
  2463. FEffectiveColor := CurrentTheme.GetViewColor(GetViewType(View));
  2464. end
  2465. else FEffectiveColor := Color;
  2466. end;
  2467. procedure TTBXToolbar.WMEraseBkgnd(var Message: TWmEraseBkgnd);
  2468. var
  2469. Canvas: TCanvas;
  2470. R, CR: TRect;
  2471. Transparent: Boolean;
  2472. begin
  2473. Transparent := False;
  2474. CR := ClientRect;
  2475. if Color = clNone then
  2476. if Embedded then
  2477. begin
  2478. Transparent := True;
  2479. DrawParentBackground(Self, Message.DC, CR);
  2480. end;
  2481. Canvas := TCanvas.Create;
  2482. Canvas.Handle := Message.DC;
  2483. try
  2484. if Docked then
  2485. begin
  2486. R := CurrentDock.ClientRect;
  2487. R.TopLeft := ScreenToClient(CurrentDock.ClientToScreen(R.TopLeft));
  2488. R.BottomRight := ScreenToClient(CurrentDock.ClientToScreen(R.BottomRight));
  2489. end
  2490. else R := Rect(0, 0, 0, 0);
  2491. CurrentTheme.PaintBackgnd(Canvas, R, CR, CR, EffectiveColor, Transparent, GetWinViewType(Self));
  2492. Message.Result := 1;
  2493. finally
  2494. Canvas.Handle := 0;
  2495. Canvas.Free;
  2496. end;
  2497. end;
  2498. //============================================================================//
  2499. { TTBXChevronItem }
  2500. function TTBXChevronItem.GetItemViewerClass(AView: TTBView): TTBItemViewerClass;
  2501. begin
  2502. Result := TTBXChevronItemViewer;
  2503. end;
  2504. procedure TTBXChevronItem.GetPopupPosition(ParentView: TTBView;
  2505. PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec);
  2506. begin
  2507. if CurrentTheme.OfficeXPPopupAlignment then with PopupPositionRec do
  2508. begin
  2509. GetOfficeXPPopupPosition1(PopupPositionRec);
  2510. inherited GetPopupPosition(ParentView, PopupWindow, PopupPositionRec);
  2511. GetOfficeXPPopupPosition2(PopupPositionRec);
  2512. end
  2513. else inherited;
  2514. end;
  2515. function TTBXChevronItem.GetPopupWindowClass: TTBPopupWindowClass;
  2516. begin
  2517. Result := TTBXChevronPopupWindow;
  2518. end;
  2519. //============================================================================//
  2520. { TTBXChevronItemViewer }
  2521. procedure TTBXChevronItemViewer.Paint(const Canvas: TCanvas;
  2522. const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean);
  2523. const
  2524. CDesigning: array [Boolean] of Integer = (0, IO_DESIGNING);
  2525. var
  2526. ItemInfo: TTBXItemInfo;
  2527. begin
  2528. FillChar(ItemInfo, SizeOf(TTBXItemInfo), 0);
  2529. ItemInfo.ViewType := GetViewType(View);
  2530. ItemInfo.ItemOptions := IO_TOOLBARSTYLE or CDesigning[csDesigning in Item.ComponentState];
  2531. ItemInfo.Enabled := Item.Enabled or View.Customizing;
  2532. ItemInfo.Pushed := IsPushed;
  2533. ItemInfo.Selected := False;
  2534. ItemInfo.ImageShown := False;
  2535. ItemInfo.ImageWidth := 0;
  2536. ItemInfo.ImageHeight := 0;
  2537. ItemInfo.IsPopupParent := IsPushed;
  2538. if IsHoverItem then
  2539. begin
  2540. if not ItemInfo.Enabled and not TTBViewAccess(View).MouseOverSelected then ItemInfo.HoverKind := hkKeyboardHover
  2541. else if ItemInfo.Enabled then ItemInfo.HoverKind := hkMouseHover;
  2542. end
  2543. else ItemInfo.HoverKind := hkNone;
  2544. ItemInfo.IsVertical := View.Orientation = tbvoVertical;
  2545. CurrentTheme.PaintChevron(Canvas, ClientAreaRect, ItemInfo);
  2546. end;
  2547. function TTBXChevronItemViewer.CaptionShown: Boolean;
  2548. begin
  2549. Result := False;
  2550. end;
  2551. //============================================================================//
  2552. { TTBXRootItem }
  2553. function TTBXRootItem.CreatePopupEx(SelectFirstItem: Boolean;
  2554. const AControlRect: TRect; Alignment: TTBPopupAlignment): TTBPopupWindow;
  2555. var
  2556. SavePopupRect: TRect;
  2557. Pt: TPoint;
  2558. begin
  2559. SavePopupRect := FPopupControlRect;
  2560. try
  2561. FPopupControlRect := AControlRect;
  2562. Pt.X := AControlRect.Left;
  2563. Pt.Y := AControlRect.Bottom;
  2564. Result := inherited CreatePopup(nil, nil, False, SelectFirstItem, False, Pt, Alignment);
  2565. if Result is TTBXPopupWindow then TTBXPopupWindow(Result).FControlRect := FPopupControlRect;
  2566. finally
  2567. FPopupControlRect := SavePopupRect;
  2568. end;
  2569. end;
  2570. procedure TTBXRootItem.GetPopupPosition(ParentView: TTBView;
  2571. PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec);
  2572. var
  2573. Y2: Integer;
  2574. VT: Integer;
  2575. begin
  2576. if IsRectEmpty(FPopupControlRect) then inherited
  2577. else with PopupPositionRec do
  2578. begin
  2579. ParentItemRect := FPopupControlRect;
  2580. if Y + H > MonitorRect.Bottom then
  2581. begin
  2582. Y2 := FPopupControlRect.Top - H;
  2583. if Y2 >= MonitorRect.Top then Y := Y2;
  2584. end;
  2585. if Y < MonitorRect.Top then Y := MonitorRect.Top
  2586. else if Y + H > MonitorRect.Bottom then Y := MonitorRect.Bottom - H;
  2587. if Alignment = tbpaRight then X := FPopupControlRect.Right - W;
  2588. if X + W > MonitorRect.Right then X := MonitorRect.Right - W;
  2589. if X < MonitorRect.Left then X := MonitorRect.Left;
  2590. end;
  2591. if CurrentTheme.OfficeXPPopupAlignment then with PopupPositionRec do
  2592. begin
  2593. GetOfficeXPPopupPosition1(PopupPositionRec);
  2594. inherited GetPopupPosition(ParentView, PopupWindow, PopupPositionRec);
  2595. GetOfficeXPPopupPosition2(PopupPositionRec);
  2596. VT := GetWinViewType(PopupWindow);
  2597. PopupPositionRec.PlaySound := not (VT and PVT_LISTBOX = PVT_LISTBOX);
  2598. end
  2599. else inherited;
  2600. end;
  2601. function TTBXRootItem.GetPopupWindowClass: TTBPopupWindowClass;
  2602. begin
  2603. Result := TTBXPopupWindow;
  2604. end;
  2605. function TTBXRootItem.OpenPopupEx(const SelectFirstItem, TrackRightButton: Boolean;
  2606. const ControlRect: TRect; const Alignment: TTBPopupAlignment;
  2607. const ReturnClickedItemOnly: Boolean): TTBCustomItem;
  2608. var
  2609. ModalHandler: TTBModalHandler;
  2610. Popup: TTBPopupWindow;
  2611. DoneActionData: TTBDoneActionData;
  2612. State: TTBViewState;
  2613. {MP}
  2614. I: Integer;
  2615. MinWidth: Integer;
  2616. Border: TPoint;
  2617. Control: TControl;
  2618. begin
  2619. ModalHandler := TTBModalHandler.Create(0);
  2620. try
  2621. {MP BEGIN}
  2622. // Make sure menu is not narrower than its popup control (button)
  2623. if not IsRectEmpty(ControlRect) then
  2624. begin
  2625. // see TTBPopupView.AutoSize and TTBXPopupWindow.GetNCSize
  2626. Control := FindVCLWindow(Point(ControlRect.Left, ControlRect.Top));
  2627. CurrentTheme.GetViewBorder(Control, PVT_POPUPMENU, Border);
  2628. MinWidth := ControlRect.Width - (2*Border.X);
  2629. for I := 0 to Count - 1 do
  2630. begin
  2631. if Items[I] is TTBXCustomItem then
  2632. if TTBXCustomItem(Items[I]).MinWidth < MinWidth then
  2633. TTBXCustomItem(Items[I]).MinWidth := MinWidth;
  2634. end
  2635. end;
  2636. {MP END}
  2637. Popup := CreatePopupEx(SelectFirstItem, ControlRect, Alignment);
  2638. try
  2639. State := Popup.View.State;
  2640. Include(State, vsIgnoreFirstMouseUp);
  2641. TTBViewAccess(Popup.View).SetState(State);
  2642. ModalHandler.Loop(Popup.View, False, False, False, TrackRightButton);
  2643. DoneActionData := TTBViewAccess(Popup.View).DoneActionData;
  2644. finally
  2645. { Remove vsModal state from the root view before any TTBView.Destroy
  2646. methods get called, so that NotifyFocusEvent becomes a no-op }
  2647. State := Popup.View.State;
  2648. Exclude(State, vsModal);
  2649. TTBViewAccess(Popup.View).SetState(State);
  2650. Popup.Free;
  2651. end;
  2652. finally
  2653. ModalHandler.Free;
  2654. end;
  2655. Result := ProcessDoneAction(DoneActionData, ReturnClickedItemOnly);
  2656. end;
  2657. function TTBXRootItem.PopupEx(const ControlRect: TRect;
  2658. TrackRightButton: Boolean; Alignment: TTBPopupAlignment = tbpaLeft;
  2659. ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
  2660. begin
  2661. Result := OpenPopupEx(False, TrackRightButton, ControlRect,
  2662. Alignment, ReturnClickedItemOnly);
  2663. end;
  2664. //============================================================================//
  2665. { TTBXPopupMenu }
  2666. function TTBXPopupMenu.GetRootItemClass: TTBRootItemClass;
  2667. begin
  2668. Result := TTBXRootItem;
  2669. end;
  2670. function TTBXPopupMenu.PopupEx(const ControlRect: TRect;
  2671. ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
  2672. begin
  2673. SetPopupPoint(Point(ControlRect.Left, ControlRect.Bottom));
  2674. Result := TTBXRootItem(Items).PopupEx(ControlRect, TrackButton = tbRightButton,
  2675. TTBPopupAlignment(Alignment), ReturnClickedItemOnly);
  2676. end;
  2677. procedure TTBXPopupMenu.TBMGetViewType(var Message: TMessage);
  2678. begin
  2679. Message.Result := PVT_POPUPMENU;
  2680. end;
  2681. //============================================================================//
  2682. { TTBXFloatingWindowParent }
  2683. procedure TTBXFloatingWindowParent.CancelNCHover;
  2684. begin
  2685. if FCloseButtonHover then
  2686. begin
  2687. FCloseButtonHover := False;
  2688. if HandleAllocated and IsWindowVisible(Handle) then
  2689. DrawNCArea(False, 0, 0, [twrdCloseButton]);
  2690. end;
  2691. end;
  2692. procedure TTBXFloatingWindowParent.CMMouseLeave(var Message: TMessage);
  2693. begin
  2694. inherited;
  2695. CancelNCHover;
  2696. end;
  2697. procedure TTBXFloatingWindowParent.DrawNCArea(const DrawToDC: Boolean;
  2698. const ADC: HDC; const Clip: HRGN; RedrawWhat: TTBToolWindowNCRedrawWhat);
  2699. const
  2700. CDown: array [Boolean] of Integer = (0, CDBS_PRESSED);
  2701. CHover: array [Boolean] of Integer = (0, CDBS_HOT);
  2702. CBord: array [Boolean] of Integer = (0, WRP_BORDER);
  2703. CCapt: array [Boolean] of Integer = (0, WRP_CAPTION);
  2704. CBtn: array [Boolean] of Integer = (0, WRP_CLOSEBTN);
  2705. var
  2706. DC: HDC;
  2707. R: TRect;
  2708. Canvas: TCanvas;
  2709. WindowInfo: TTBXWindowInfo;
  2710. DockWindow: TTBCustomDockableWindowAccess;
  2711. begin
  2712. if not HandleAllocated then Exit;
  2713. if not DrawToDC then DC := GetWindowDC(Handle)
  2714. else DC := ADC;
  2715. try
  2716. if not DrawToDC then SelectNCUpdateRgn(Handle, DC, Clip);
  2717. GetWindowRect(Handle, R);
  2718. OffsetRect(R, -R.Left, -R.Top);
  2719. with R do IntersectClipRect(DC, Left, Top, Right, Bottom);
  2720. Canvas := TCanvas.Create;
  2721. try
  2722. Canvas.Handle := DC;
  2723. GetWindowRect(Handle, R);
  2724. OffsetRect(R, -R.Left, -R.Top);
  2725. DockWindow := TTBCustomDockableWindowAccess(DockableWindow);
  2726. FillChar(WindowInfo, SizeOf(WindowInfo), 0);
  2727. WindowInfo.ParentControl := Self;
  2728. WindowInfo.ParentHandle := Handle;
  2729. WindowInfo.WindowHandle := DockWindow.Handle;
  2730. WindowInfo.ViewType := GetWinViewType(DockWindow);
  2731. WindowInfo.ClientWidth := ClientWidth;
  2732. WindowInfo.ClientHeight := ClientHeight;
  2733. WindowInfo.ShowCaption := DockWindow.ShowCaption;
  2734. WindowInfo.FloatingBorderSize := DockWindow.GetFloatingBorderSize;
  2735. if DockWindow.CloseButton and DockWindow.ShowCaption then
  2736. begin
  2737. WindowInfo.CloseButtonState := CDBS_VISIBLE;
  2738. if CloseButtonDown then WindowInfo.CloseButtonState := WindowInfo.CloseButtonState or CDBS_PRESSED
  2739. else if CloseButtonHover then WindowInfo.CloseButtonState := WindowInfo.CloseButtonState or CDBS_HOT;
  2740. end;
  2741. WindowInfo.RedrawPart :=
  2742. CBord[twrdBorder in RedrawWhat] or
  2743. CCapt[twrdCaption in RedrawWhat] or
  2744. CBtn[twrdCloseButton in RedrawWhat];
  2745. WindowInfo.Caption := PChar(Caption);
  2746. WindowInfo.EffectiveColor := GetEffectiveColor(DockWindow);
  2747. WindowInfo.Active := not DockWindow.InactiveCaption;
  2748. Canvas.Brush.Color := WindowInfo.EffectiveColor;
  2749. CurrentTheme.PaintFloatingBorder(Canvas, R, WindowInfo);
  2750. finally
  2751. Canvas.Handle := 0;
  2752. Canvas.Free;
  2753. end;
  2754. finally
  2755. if not DrawToDC then ReleaseDC(Handle, DC);
  2756. end;
  2757. end;
  2758. procedure TTBXFloatingWindowParent.WMEraseBkgnd(var Message: TMessage);
  2759. begin
  2760. Message.Result := 1;
  2761. end;
  2762. procedure TTBXFloatingWindowParent.WMNCMouseLeave(var Message: TMessage);
  2763. begin
  2764. if not MouseCapture then CancelNCHover;
  2765. inherited;
  2766. end;
  2767. procedure TTBXFloatingWindowParent.WMNCMouseMove(var Message: TWMNCMouseMove);
  2768. var
  2769. InArea: Boolean;
  2770. begin
  2771. inherited;
  2772. { Note: TME_NONCLIENT was introduced in Windows 98 and 2000 }
  2773. CallTrackMouseEvent (Handle, TME_LEAVE or $10 {TME_NONCLIENT});
  2774. InArea := Message.HitTest = 2001; {HT_TB2k_Close}
  2775. if FCloseButtonHover <> InArea then
  2776. begin
  2777. FCloseButtonHover := InArea;
  2778. if HandleAllocated and IsWindowVisible(Handle) then
  2779. DrawNCArea(False, 0, 0, [twrdCloseButton]);
  2780. end;
  2781. end;
  2782. procedure TTBXFloatingWindowParent.WMWindowPosChanging(var Message: TWMWindowPosChanging);
  2783. var
  2784. R: TRect;
  2785. MonInfo: TMonitorInfo;
  2786. begin
  2787. if SnapDistance > 0 then with Message.WindowPos^ do
  2788. begin
  2789. if (cx = Width) and (cy = Height) then
  2790. begin
  2791. MonInfo.cbSize := SizeOf(MonInfo);
  2792. GetMonitorInfo(Monitor.Handle, @MonInfo);
  2793. R := MonInfo.rcWork;
  2794. if Abs(x + Width - R.Right) < SnapDistance then x := R.Right - Width;
  2795. if Abs(y + Height - R.Bottom) < SnapDistance then y := R.Bottom - Height;
  2796. if Abs(x - R.Left) < SnapDistance then x := R.Left;
  2797. if Abs(y - R.Top) < SnapDistance then y := R.Top;
  2798. end;
  2799. end;
  2800. inherited;
  2801. end;
  2802. //============================================================================//
  2803. { Additional system colors }
  2804. type
  2805. TColorEntry = packed record
  2806. ColorPtr: ^TColor;
  2807. Name: string;
  2808. end;
  2809. var
  2810. ColorRegistry: array of TColorEntry;
  2811. procedure AddTBXColor(var AColor: TColor; const AName: string);
  2812. var
  2813. L: Integer;
  2814. begin
  2815. L := Length(ColorRegistry);
  2816. SetLength(ColorRegistry, L + 1);
  2817. with ColorRegistry[L] do
  2818. begin
  2819. ColorPtr := @AColor;
  2820. Name := AName;
  2821. end;
  2822. end;
  2823. function TBXColorToString(Color: TColor): string;
  2824. var
  2825. I: Integer;
  2826. begin
  2827. if not ColorToIdent(Color, Result) then
  2828. begin
  2829. for I := 0 to Length(ColorRegistry) - 1 do
  2830. if ColorRegistry[I].ColorPtr^ = Color then
  2831. begin
  2832. Result := ColorRegistry[I].Name;
  2833. Exit;
  2834. end;
  2835. FmtStr(Result, '%s%.8x', [HexDisplayPrefix, Color]);
  2836. end;
  2837. end;
  2838. function TBXIdentToColor(const Ident: string; var Color: Longint): Boolean;
  2839. var
  2840. I: Integer;
  2841. begin
  2842. for I := 0 to Length(ColorRegistry) - 1 do
  2843. if CompareText(ColorRegistry[I].Name, Ident) = 0 then
  2844. begin
  2845. Color := ColorRegistry[I].ColorPtr^;
  2846. Result := True;
  2847. Exit;
  2848. end;
  2849. Result := IdentToColor(Ident, Color);
  2850. end;
  2851. function TBXStringToColor(S: string): TColor;
  2852. begin
  2853. if not TBXIdentToColor(S, Longint(Result)) then Result := StringToColor(S);
  2854. end;
  2855. procedure TBXGetColorValues(Proc: TGetStrProc);
  2856. var
  2857. I: Integer;
  2858. begin
  2859. GetColorValues(Proc);
  2860. for I := 0 to Length(ColorRegistry) - 1 do Proc(ColorRegistry[I].Name);
  2861. end;
  2862. procedure TBXSetTheme(const AThemeName: string);
  2863. begin
  2864. TBXNexus.SetTheme(AThemeName);
  2865. end;
  2866. function TBXCurrentTheme: string;
  2867. begin
  2868. Result := TBXNexus.GetTheme;
  2869. end;
  2870. //============================================================================//
  2871. { TTBXNexus }
  2872. procedure TTBXNexus.AddNotifie(AObject: TObject);
  2873. begin
  2874. if FNotifies.IndexOf(AObject) < 0 then FNotifies.Add(AObject);
  2875. Exit; asm db 0,'TBX (C) 2001-2003 Alex Denisov',0 end;
  2876. end;
  2877. procedure TTBXNexus.Broadcast(Msg: Cardinal; WParam, LParam: Integer);
  2878. var
  2879. M: TMessage;
  2880. I: Integer;
  2881. begin
  2882. if FNotifies.Count > 0 then
  2883. begin
  2884. M.Msg := Msg;
  2885. M.WParam := WParam;
  2886. M.LParam := LParam;
  2887. M.Result := 0;
  2888. for I := 0 to FNotifies.Count - 1 do TObject(FNotifies[I]).Dispatch(M);
  2889. end;
  2890. end;
  2891. constructor TTBXNexus.Create(const DefaultTheme: string);
  2892. begin
  2893. FNotifies := TList.Create;
  2894. CurrentTheme := GetTBXTheme(DefaultTheme);
  2895. AddTBXSysChangeNotification(Self);
  2896. end;
  2897. destructor TTBXNexus.Destroy;
  2898. begin
  2899. RemoveTBXSysChangeNotification(Self);
  2900. ReleaseTBXTheme(CurrentTheme);
  2901. FNotifies.Free;
  2902. inherited;
  2903. end;
  2904. function TTBXNexus.GetTheme: string;
  2905. begin
  2906. Result := CurrentTheme.Name;
  2907. end;
  2908. procedure TTBXNexus.RemoveNotifie(AObject: TObject);
  2909. begin
  2910. FNotifies.Remove(AObject);
  2911. end;
  2912. procedure TTBXNexus.SetTheme(const AThemeName: string);
  2913. begin
  2914. if IsTBXThemeAvailable(AThemeName) then
  2915. begin
  2916. ReleaseTBXTheme(CurrentTheme);
  2917. CurrentTheme := GetTBXTheme(AThemeName);
  2918. Broadcast(TBM_THEMECHANGE, TSC_BEFOREVIEWCHANGE, 1);
  2919. Broadcast(TBM_THEMECHANGE, TSC_VIEWCHANGE, 1);
  2920. Broadcast(TBM_THEMECHANGE, TSC_AFTERVIEWCHANGE, 1);
  2921. end;
  2922. end;
  2923. procedure TTBXNexus.TBXSysCommand(var Message: TMessage);
  2924. begin
  2925. { Retranslate TBX_SYSCOMMAND to TBM_THEMECHANGE }
  2926. if Message.Msg = TBX_SYSCOMMAND then
  2927. Broadcast(TBM_THEMECHANGE, Message.WParam, 0);
  2928. end;
  2929. { TTBXDock }
  2930. procedure TTBXDock.CMColorChanged(var Message: TMessage);
  2931. var
  2932. I: Integer;
  2933. begin
  2934. inherited;
  2935. for I := 0 to Self.ControlCount - 1 do
  2936. if Controls[I] is TWinControl then
  2937. InvalidateAll(TWinControl(Controls[I]));
  2938. end;
  2939. constructor TTBXDock.Create(AOwner: TComponent);
  2940. begin
  2941. inherited;
  2942. Color := clNone;
  2943. AddThemeNotification(Self);
  2944. end;
  2945. destructor TTBXDock.Destroy;
  2946. begin
  2947. RemoveThemeNotification(Self);
  2948. inherited;
  2949. end;
  2950. procedure TTBXDock.DrawBackground(DC: HDC; const DrawRect: TRect);
  2951. const
  2952. DOCK_POSITIONS: array [TTBDockPosition] of Integer = (DP_TOP, DP_BOTTOM, DP_LEFT, DP_RIGHT);
  2953. var
  2954. Canvas: TCanvas;
  2955. begin
  2956. if UseParentBackground then DrawParentBackground(Self, DC, ClientRect)
  2957. else if ThemedBackground then
  2958. begin
  2959. Canvas := TCanvas.Create;
  2960. Canvas.Handle := DC;
  2961. CurrentTheme.PaintDock(Canvas, ClientRect, DrawRect, DOCK_POSITIONS[Position]);
  2962. Canvas.Handle := 0;
  2963. Canvas.Free;
  2964. end
  2965. else inherited;
  2966. end;
  2967. procedure TTBXDock.Resize;
  2968. var
  2969. I, J: Integer;
  2970. V: TTBItemViewer;
  2971. R: TRect;
  2972. begin
  2973. inherited Resize;
  2974. if UsingBackground then
  2975. begin
  2976. for J := 0 to ToolbarCount - 1 do
  2977. begin
  2978. Invalidate;
  2979. if Toolbars[J] is TTBXToolbar then with TTBXToolbar(Toolbars[J]) do
  2980. begin
  2981. for I := 0 to View.ViewerCount - 1 do
  2982. begin
  2983. V := View.Viewers[I];
  2984. if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
  2985. then View.Invalidate(V);
  2986. end;
  2987. Update;
  2988. if HandleAllocated then
  2989. RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or RDW_ERASE);
  2990. for I := 0 to View.ViewerCount - 1 do
  2991. begin
  2992. V := View.Viewers[I];
  2993. if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
  2994. then
  2995. begin
  2996. R := V.BoundsRect;
  2997. ValidateRect(Handle, @R);
  2998. end;
  2999. end;
  3000. end
  3001. end;
  3002. end;
  3003. end;
  3004. procedure TTBXDock.SetUseParentBackground(Value: Boolean);
  3005. begin
  3006. if Value <> FUseParentBackground then
  3007. begin
  3008. FUseParentBackground := Value;
  3009. if HandleAllocated then
  3010. RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
  3011. RDW_ERASE or RDW_ALLCHILDREN);
  3012. end;
  3013. end;
  3014. procedure TTBXDock.TBMGetEffectiveColor(var Message: TMessage);
  3015. begin
  3016. if Color <> clNone then Message.WParam := Color
  3017. else if Parent <> nil then Message.WParam := GetEffectiveColor(Parent)
  3018. else Message.WParam := WPARAM(clBtnFace);
  3019. Message.Result := 1;
  3020. end;
  3021. procedure TTBXDock.TBMThemeChange(var Message: TMessage);
  3022. begin
  3023. case Message.WParam of
  3024. TSC_AFTERVIEWCHANGE:
  3025. begin
  3026. Invalidate;
  3027. end;
  3028. end;
  3029. end;
  3030. function TTBXDock.ThemedBackground: Boolean;
  3031. begin
  3032. Result := (Color = clNone) and CurrentTheme.PaintDockBackground;
  3033. end;
  3034. function TTBXDock.UsingBackground: Boolean;
  3035. begin
  3036. Result := UseParentBackground or (ThemedBackground and not FMoving) or
  3037. inherited UsingBackground;
  3038. end;
  3039. procedure TTBXDock.WMEraseBkgnd(var Message: TWMEraseBkgnd);
  3040. var
  3041. R: TRect;
  3042. C: TColor;
  3043. begin
  3044. R := Self.ClientRect;
  3045. if UsingBackground then
  3046. begin
  3047. DrawBackground(Message.DC, R);
  3048. Message.Result := 1;
  3049. end
  3050. else
  3051. begin
  3052. C := Color;
  3053. if C = clNone then C := GetEffectiveColor(Parent);
  3054. FillRectEx(Message.DC, R, C);
  3055. Message.Result := 1;
  3056. end;
  3057. end;
  3058. procedure TTBXDock.WMMove(var Message: TWMMove);
  3059. begin
  3060. FMoving := True;
  3061. inherited;
  3062. FMoving := False;
  3063. end;
  3064. procedure TTBXDock.WMSize(var Message: TWMSize);
  3065. begin
  3066. FResizing := True;
  3067. inherited;
  3068. FResizing := False;
  3069. end;
  3070. { TTBXMenuAnimation }
  3071. constructor TTBXMenuAnimation.Create(AAnimationMode: TAnimationMode = amSysDefault);
  3072. begin
  3073. AnimationMode := AAnimationMode;
  3074. end;
  3075. function TTBXMenuAnimation.GetAvailableModes: TAnimationModes;
  3076. begin
  3077. Result := [amNone, amSysDefault, amRandom, amUnfold, amSlide, amFade];
  3078. end;
  3079. function TTBXMenuAnimation.GetMenuAnimation: TMenuAnimation;
  3080. function GetSysDefault: TMenuAnimation;
  3081. const
  3082. SPI_GETMENUFADE = $1012;
  3083. SysDefAni: array[Boolean] of TMenuAnimation = (maSlide, maFade);
  3084. begin
  3085. if SysParamEnabled(SPI_GETMENUANIMATION)
  3086. then Result := SysDefAni[SysParamEnabled(SPI_GETMENUFADE)]
  3087. else Result := maNone;
  3088. end;
  3089. function GetRandom: TMenuAnimation;
  3090. var Max: Integer;
  3091. begin
  3092. Max := Ord(High(TMenuAnimation));
  3093. if not (amFade in AvailableModes) then
  3094. Dec(Max);
  3095. Result := Succ(TMenuAnimation(Random(Max)));
  3096. end;
  3097. begin
  3098. case AnimationMode of
  3099. amSysDefault: Result := GetSysDefault;
  3100. amRandom: Result := GetRandom;
  3101. amUnfold: Result := maUnfold;
  3102. amSlide: Result := maSlide;
  3103. amFade: Result := maFade;
  3104. else
  3105. Result := maNone;
  3106. end;
  3107. end;
  3108. procedure TTBXMenuAnimation.SetAnimationMode(Value: TAnimationMode);
  3109. var AvailModes: TAnimationModes;
  3110. begin
  3111. AvailModes := AvailableModes;
  3112. while not (Value in AvailModes) do
  3113. Value := Pred(Value);
  3114. FAnimationMode := Value;
  3115. end;
  3116. function TTBXMenuAnimation.SysParamEnabled(Param: Cardinal): Boolean;
  3117. var B: BOOL;
  3118. begin
  3119. Result := SystemParametersInfo(Param, 0, @B, 0) and B;
  3120. end;
  3121. { Work around delayed menu showing in Windows 2000+ }
  3122. var
  3123. FixPlaySoundThreadHandle: Cardinal;
  3124. function FixPlaySoundThreadFunc(Param: Pointer): Integer; stdcall;
  3125. begin
  3126. Sleep(250);
  3127. PlaySound(nil, 0, 0);
  3128. CloseHandle(FixPlaySoundThreadHandle); { Harakiri :~| }
  3129. Result := $4E494150; { :) }
  3130. end;
  3131. procedure FixPlaySoundDelay;
  3132. var ThreadId: TThreadID;
  3133. begin
  3134. if (FixPlaySoundThreadHandle = 0) then
  3135. FixPlaySoundThreadHandle := CreateThread(nil, $1000,
  3136. @FixPlaySoundThreadFunc, nil, 0, ThreadId);
  3137. end;
  3138. function CreateTBXPopupMenu(Owner: TComponent): TTBXPopupMenu;
  3139. begin
  3140. Result := TTBXPopupMenu.Create(Owner);
  3141. end;
  3142. initialization
  3143. FixPlaySoundDelay;
  3144. RegisterTBXTheme('OfficeXP', TTBXOfficeXPTheme);
  3145. RegisterTBXTheme('DarkOfficeXP', TTBXDarkOfficeXPTheme);
  3146. TBXNexus := TTBXNexus.Create('OfficeXP');
  3147. TBXMenuAnimation := TTBXMenuAnimation.Create;
  3148. finalization
  3149. TBXNexus.Free;
  3150. FreeAndNil(TBXMenuAnimation);
  3151. ColorRegistry := nil;
  3152. end.