TBX.pas 118 KB

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