TBX.pas 117 KB

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