TBX.pas 117 KB

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