TBX.pas 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901
  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, Three: 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. Three := ScaleByTextHeightRunTime(Canvas, 3);
  1242. Inc(AWidth, TextSize.CX);
  1243. Inc(AHeight, TextSize.CY);
  1244. if not IsTextRotated then Inc(AWidth, 2 * Three)
  1245. else Inc(AHeight, 2 * Three);
  1246. end;
  1247. if GetImageShown and (ImgSize.CX > 0) and (ImgSize.CY > 0) then
  1248. begin
  1249. if ItemLayout = tbxlGlyphLeft then
  1250. begin
  1251. Inc(AWidth, ImgSize.CX + 3);
  1252. if Wide then Inc(AWidth);
  1253. if AHeight < ImgSize.CY + 6 then AHeight := ImgSize.CY + 6;
  1254. end
  1255. else
  1256. begin
  1257. Inc(AHeight, ImgSize.CY + 3);
  1258. if AWidth < ImgSize.CX + 7 then AWidth := ImgSize.CX + 7;
  1259. end;
  1260. end;
  1261. if tbisSubmenu in TTBItemAccess(Item).ItemStyle then with CurrentTheme do
  1262. begin
  1263. if tbisCombo in TTBItemAccess(Item).ItemStyle then Inc(AWidth, SplitBtnArrowWidth)
  1264. else if tboDropdownArrow in Item.EffectiveOptions then
  1265. begin
  1266. if (ItemLayout <> tbxlGlyphTop) or (ImgSize.CX = 0) or IsTextRotated then
  1267. begin
  1268. Two := ScaleByTextHeightRunTime(Canvas, 2);
  1269. if View.Orientation <> tbvoVertical then Inc(AWidth, Two + DropdownArrowWidth)
  1270. else Inc(AHeight, DropdownArrowWidth + Two + DropdownArrowMargin);
  1271. end
  1272. else
  1273. begin
  1274. if (ItemLayout = tbxlGlyphTop) and (IsTextRotated xor (View.Orientation <> tbvoVertical)) then
  1275. begin
  1276. W := ImgSize.CX + DropDownArrowWidth + 2;
  1277. if W > AWidth - 7 then AWidth := W + 7;
  1278. end
  1279. else
  1280. begin
  1281. H := ImgSize.CY + DropDownArrowWidth + 2;
  1282. if H > AHeight - 7 then AHeight := H + 7;
  1283. end;
  1284. end
  1285. end;
  1286. end;
  1287. end
  1288. else // Not a ToolbarStyle
  1289. with CurrentTheme do
  1290. begin
  1291. GetTextMetrics(Canvas.Handle, TextMetric);
  1292. Inc(TextSize.CY, TextMetric.tmExternalLeading);
  1293. AWidth := TextSize.CX;
  1294. AHeight := TextSize.CY;
  1295. if ImgSize.CY = 0 then ImgSize.CY := 16;
  1296. if AHeight < ImgSize.CY then AHeight := ImgSize.CY;
  1297. GetMargins(MID_MENUITEM, Margins);
  1298. Inc(AWidth, Margins.LeftWidth + Margins.RightWidth);
  1299. Inc(AHeight, Margins.TopHeight + Margins.BottomHeight);
  1300. Inc(AWidth, GetPopupMargin(Self) + MenuImageTextSpace + MenuLeftCaptionMargin + MenuRightCaptionMargin);
  1301. S := Item.GetShortCutText;
  1302. if Length(S) > 0 then Inc(AWidth, (AHeight - 6) + GetTextWidth(Canvas.Handle, S, True));
  1303. Inc(AWidth, AHeight); { Note: maybe this should be controlled by the theme }
  1304. end;
  1305. if Item is TTBXCustomItem then with TTBXCustomItem(Item) do
  1306. begin
  1307. if AWidth < MinWidth then AWidth := MinWidth;
  1308. if AHeight < MinHeight then AHeight := MinHeight;
  1309. end;
  1310. end;
  1311. constructor TTBXItemViewer.Create(AView: TTBView; AItem: TTBCustomItem; AGroupLevel: Integer);
  1312. begin
  1313. inherited;
  1314. FWide := True;
  1315. end;
  1316. procedure TTBXItemViewer.DoAdjustFont(AFont: TFont; StateFlags: Integer);
  1317. begin
  1318. if tboDefault in Item.EffectiveOptions then with AFont do Style := Style + [fsBold];
  1319. if Item is TTBXCustomItem then
  1320. with TTBXCustomItem(Item) do
  1321. begin
  1322. FontSettings.Apply(AFont);
  1323. if Assigned(FOnAdjustFont) then FOnAdjustFont(Item, Self, AFont, StateFlags);
  1324. end
  1325. else if Item is TTBXEditItem then
  1326. with TTBXEditItem(Item) do
  1327. begin
  1328. FontSettings.Apply(AFont);
  1329. end;
  1330. end;
  1331. procedure TTBXItemViewer.DoPaintCaption(Canvas: TCanvas; const ClientAreaRect: TRect;
  1332. var CaptionRect: TRect; IsTextRotated: Boolean; var PaintDefault: Boolean);
  1333. begin
  1334. // do nothing
  1335. end;
  1336. procedure TTBXItemViewer.DrawItemImage(Canvas: TCanvas; ARect: TRect; ItemInfo: TTBXItemInfo);
  1337. var
  1338. ImgList: TCustomImageList;
  1339. I: TTBXCustomItem;
  1340. begin
  1341. ImgList := GetImageList;
  1342. if (ImgList <> nil) and (Item.ImageIndex >= 0) and (Item.ImageIndex < ImgList.Count) then
  1343. begin
  1344. CurrentTheme.PaintImage(Canvas, ARect, ItemInfo, ImgList, Item.ImageIndex);
  1345. if Item is TTBXCustomItem then
  1346. begin
  1347. I := TTBXCustomItem(Item);
  1348. if Assigned(I.FOnDrawImage) then
  1349. I.FOnDrawImage(I, Self, Canvas, ARect,
  1350. CurrentTheme.GetImageOffset(Canvas, ItemInfo, ImgList),
  1351. GetStateFlags(ItemInfo));
  1352. end;
  1353. end;
  1354. end;
  1355. function TTBXItemViewer.GetAccRole: Integer;
  1356. { Returns the MSAA "role" of the viewer. }
  1357. const
  1358. { Constants from OleAcc.h }
  1359. ROLE_SYSTEM_BUTTONDROPDOWNGRID = $3A;
  1360. begin
  1361. Result := inherited GetAccRole;
  1362. if (Item is TTBXCustomItem) and TTBXCustomItem(Item).ToolBoxPopup and
  1363. (tbisSubmenu in TTBXCustomItem(Item).ItemStyle) then
  1364. Result := ROLE_SYSTEM_BUTTONDROPDOWNGRID;
  1365. end;
  1366. function TTBXItemViewer.GetImageShown: Boolean;
  1367. begin
  1368. Result := (Item.ImageIndex >= 0) and
  1369. ((Item.DisplayMode in [nbdmDefault, nbdmImageAndText]) or
  1370. (IsToolbarStyle and (Item.DisplayMode = nbdmTextOnlyInMenus)));
  1371. end;
  1372. function TTBXItemViewer.GetImageSize: TSize;
  1373. var
  1374. ImgList: TCustomImageList;
  1375. begin
  1376. ImgList := GetImageList;
  1377. with Result do if ImgList <> nil then
  1378. begin
  1379. CX := ImgList.Width;
  1380. CY := ImgList.Height;
  1381. end
  1382. else
  1383. begin
  1384. CX := 0;
  1385. CY := 0;
  1386. end;
  1387. end;
  1388. function TTBXItemViewer.GetItemType: Integer;
  1389. begin
  1390. if IsToolbarStyle then Result := IT_TOOLBARBUTTON
  1391. else Result := IT_MENUITEM;
  1392. end;
  1393. function TTBXItemViewer.GetTextFlags: Cardinal;
  1394. begin
  1395. Result := 0;
  1396. if not AreKeyboardCuesEnabled and (vsUseHiddenAccels in View.Style) and
  1397. not (vsShowAccels in View.State) then Result := DT_HIDEPREFIX;
  1398. end;
  1399. function TTBXItemViewer.GetTextSize(Canvas: TCanvas; const Text: string;
  1400. TextFlags: Cardinal; Rotated: Boolean; StateFlags: Integer): TSize;
  1401. var
  1402. DC: HDC;
  1403. R: TRect;
  1404. RotatedFont, SaveFont: HFONT;
  1405. TextMetric: TTextMetric;
  1406. begin
  1407. { note: rotated font size is consistent only for single-line captions! }
  1408. if Length(Text) = 0 then with Result do
  1409. begin
  1410. CX := 0;
  1411. CY := 0;
  1412. Exit;
  1413. end;
  1414. { Select proper font }
  1415. Canvas.Font := TTBViewAccess(View).GetFont;
  1416. DoAdjustFont(Canvas.Font, StateFlags);
  1417. if not Rotated then with R, Result do
  1418. begin
  1419. Left := 0; Right := 1;
  1420. Top := 0; Bottom := 0;
  1421. DrawText(Canvas.Handle, PChar(Text), Length(Text), R, TextFlags or DT_CALCRECT);
  1422. CX := Right;
  1423. CY := Bottom;
  1424. end
  1425. else
  1426. begin
  1427. DC := Canvas.Handle;
  1428. RotatedFont := CreateRotatedFont(DC);
  1429. SaveFont := SelectObject(DC, RotatedFont);
  1430. GetTextMetrics(DC, TextMetric);
  1431. Result.CX := TextMetric.tmHeight;
  1432. Result.CY := GetTextWidth(DC, Text, True);
  1433. SelectObject(DC, SaveFont);
  1434. DeleteObject(RotatedFont);
  1435. end;
  1436. end;
  1437. function TTBXItemViewer.IsPtInButtonPart(X, Y: Integer): Boolean;
  1438. var
  1439. W: Integer;
  1440. begin
  1441. Result := not (tbisSubmenu in TTBItemAccess(Item).ItemStyle);
  1442. if (tbisCombo in TTBItemAccess(Item).ItemStyle) then
  1443. begin
  1444. if IsToolbarStyle then W := CurrentTheme.SplitBtnArrowWidth
  1445. else W := GetSystemMetrics(SM_CXMENUCHECK);
  1446. Result := X < (BoundsRect.Right - BoundsRect.Left) - W;
  1447. end;
  1448. end;
  1449. function TTBXItemViewer.IsToolbarSize: Boolean;
  1450. begin
  1451. Result := inherited IsToolbarSize;
  1452. Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
  1453. end;
  1454. function TTBXItemViewer.IsToolbarStyle: Boolean;
  1455. begin
  1456. Result := inherited IsToolbarStyle;
  1457. Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
  1458. end;
  1459. procedure TTBXItemViewer.MouseUp(X, Y: Integer; MouseWasDownOnMenu: Boolean);
  1460. begin
  1461. inherited;
  1462. { Force the item to behave as a 'normal' menu item
  1463. That is make it respond to mouse as an item with IsToolbarStyle = False }
  1464. if Item.Enabled and not ((tbisSubmenu in TTBItemAccess(Item).ItemStyle) and
  1465. not IsPtInButtonPart(X, Y)) then
  1466. begin
  1467. if View.MouseOverSelected then
  1468. begin
  1469. Execute(True);
  1470. end;
  1471. end;
  1472. end;
  1473. procedure TTBXItemViewer.Paint(const Canvas: TCanvas;
  1474. const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean);
  1475. const
  1476. CToolbarStyle: array [Boolean] of Integer = (0, IO_TOOLBARSTYLE);
  1477. CCombo: array [Boolean] of Integer = (0, IO_COMBO);
  1478. CSubmenuItem: array [Boolean] of Integer = (0, IO_SUBMENUITEM);
  1479. CDesigning: array [Boolean] of Integer = (0, IO_DESIGNING);
  1480. CAppActive: array [Boolean] of Integer = (0, IO_APPACTIVE);
  1481. var
  1482. Item: TTBXCustomItem;
  1483. View: TTBViewAccess;
  1484. ItemInfo: TTBXItemInfo;
  1485. {M: Integer;} {vb-}
  1486. R: TRect;
  1487. ComboRect: TRect;
  1488. CaptionRect: TRect;
  1489. ImageRect: TRect;
  1490. C: TColor;
  1491. ToolbarStyle: Boolean;
  1492. HasArrow: Boolean;
  1493. IsSplit: Boolean;
  1494. ImageIsShown: Boolean;
  1495. ImageOrCheckShown: Boolean;
  1496. ImgAndArrowWidth: Integer;
  1497. ImgSize: TSize;
  1498. IsComboPushed: Boolean;
  1499. IsCaptionShown: Boolean;
  1500. IsTextRotated: Boolean;
  1501. ItemLayout: TTBXItemLayout;
  1502. PaintDefault: Boolean;
  1503. S: string;
  1504. StateFlags: Integer;
  1505. IsSpecialDropDown: Boolean;
  1506. TextFlags: Cardinal;
  1507. TextMetrics: TTextMetric;
  1508. TextSize: TSize;
  1509. Margins: TTBXMargins;
  1510. Three: Integer;
  1511. begin
  1512. Item := TTBXCustomItem(Self.Item);
  1513. View := TTBViewAccess(Self.View);
  1514. ToolbarStyle := IsToolbarStyle;
  1515. IsSplit := tbisCombo in Item.ItemStyle;
  1516. IsComboPushed := IsSplit and IsPushed and not View.Capture;
  1517. if IsComboPushed then IsPushed := False;
  1518. if GetImageShown then
  1519. begin
  1520. ImgSize := GetImageSize;
  1521. with ImgSize do if (CX <= 0) or (CY <= 0) then
  1522. begin
  1523. CX := 0;
  1524. CY := 0;
  1525. ImageIsShown := False;
  1526. end
  1527. else ImageIsShown := True;
  1528. end
  1529. else
  1530. begin
  1531. ImgSize.CX := 0;
  1532. ImgSize.CY := 0;
  1533. ImageIsShown := False;
  1534. end;
  1535. IsSplit := tbisCombo in Item.ItemStyle;
  1536. FillChar(ItemInfo, SizeOf(ItemInfo), 0);
  1537. ItemInfo.ViewType := GetViewType(View);
  1538. ItemInfo.ItemOptions := CToolbarStyle[ToolbarStyle] or CCombo[IsSplit] or
  1539. CDesigning[csDesigning in Item.ComponentState] or CSubmenuItem[tbisSubmenu in Item.ItemStyle] or
  1540. CAppActive[Application.Active];
  1541. ItemInfo.Enabled := Item.Enabled or View.Customizing;
  1542. ItemInfo.Pushed := IsPushed;
  1543. ItemInfo.Selected := Item.Checked;
  1544. ItemInfo.ImageShown := ImageIsShown;
  1545. ItemInfo.ImageWidth := ImgSize.CX;
  1546. ItemInfo.ImageHeight := ImgSize.CY;
  1547. if IsHoverItem then
  1548. begin
  1549. if not ItemInfo.Enabled and not View.MouseOverSelected then ItemInfo.HoverKind := hkKeyboardHover
  1550. else if ItemInfo.Enabled then ItemInfo.HoverKind := hkMouseHover;
  1551. end
  1552. else ItemInfo.HoverKind := hkNone;
  1553. ItemInfo.IsPopupParent := ToolbarStyle and
  1554. (((vsModal in View.State) and Assigned(View.OpenViewer)) or (tbisSubmenu in Item.ItemStyle)) and
  1555. ((IsSplit and IsComboPushed) or (not IsSplit and IsPushed));
  1556. ItemInfo.IsVertical := (View.Orientation = tbvoVertical) and not IsSplit;
  1557. ItemInfo.PopupMargin := GetPopupMargin(Self);
  1558. ItemLayout := Item.Layout;
  1559. if ItemLayout = tbxlAuto then
  1560. begin
  1561. if tboImageAboveCaption in Item.EffectiveOptions then ItemLayout := tbxlGlyphTop
  1562. else if View.Orientation <> tbvoVertical then ItemLayout := tbxlGlyphLeft
  1563. else ItemLayout := tbxlGlyphTop;
  1564. end;
  1565. HasArrow := (tbisSubmenu in Item.ItemStyle) and
  1566. ((tbisCombo in Item.ItemStyle) or (tboDropdownArrow in Item.EffectiveOptions));
  1567. if GetImageShown then
  1568. begin
  1569. ImgSize := GetImageSize;
  1570. with ImgSize do if (CX <= 0) or (CY <= 0) then
  1571. begin
  1572. CX := 0;
  1573. CY := 0;
  1574. ImageIsShown := False;
  1575. end
  1576. else ImageIsShown := True;
  1577. end
  1578. else
  1579. begin
  1580. ImgSize.CX := 0;
  1581. ImgSize.CY := 0;
  1582. ImageIsShown := False;
  1583. end;
  1584. ImageOrCheckShown := ImageIsShown or (not ToolbarStyle and Item.Checked);
  1585. StateFlags := GetStateFlags(ItemInfo);
  1586. Canvas.Font := TTBViewAccess(View).GetFont;
  1587. Canvas.Font.Color := CurrentTheme.GetItemTextColor(ItemInfo);
  1588. DoAdjustFont(Canvas.Font, StateFlags);
  1589. C := Canvas.Font.Color;
  1590. { Setup font }
  1591. TextFlags := GetTextFlags;
  1592. IsCaptionShown := CaptionShown;
  1593. IsTextRotated := (View.Orientation = tbvoVertical) and ToolbarStyle;
  1594. if IsCaptionShown then
  1595. begin
  1596. S := GetCaptionText;
  1597. if (Item.Layout <> tbxlAuto) or (tboImageAboveCaption in Item.EffectiveOptions) then
  1598. IsTextRotated := False;
  1599. if IsTextRotated or not ToolbarStyle then TextFlags := TextFlags or DT_SINGLELINE;
  1600. TextSize := GetTextSize(Canvas, S, TextFlags, IsTextRotated, StateFlags);
  1601. end
  1602. else
  1603. begin
  1604. StateFlags := 0;
  1605. SetLength(S, 0);
  1606. IsTextRotated := False;
  1607. TextSize.CX := 0;
  1608. TextSize.CY := 0;
  1609. end;
  1610. IsSpecialDropDown := HasArrow and not IsSplit and ToolbarStyle and
  1611. ((Item.Layout = tbxlGlyphTop) or (Item.Layout = tbxlAuto) and (tboImageAboveCaption in Item.EffectiveOptions)) and
  1612. (ImgSize.CX > 0) and not (IsTextRotated) and (TextSize.CX > 0);
  1613. { Border & Arrows }
  1614. R := ClientAreaRect;
  1615. with CurrentTheme do if ToolbarStyle then
  1616. begin
  1617. GetMargins(MID_TOOLBARITEM, Margins);
  1618. if HasArrow then with R do
  1619. begin
  1620. ItemInfo.ComboPart := cpCombo;
  1621. if IsSplit then
  1622. begin
  1623. ItemInfo.ComboPart := cpSplitLeft;
  1624. ComboRect := R;
  1625. Dec(Right, SplitBtnArrowWidth);
  1626. ComboRect.Left := Right;
  1627. end
  1628. else if not IsSpecialDropDown then
  1629. begin
  1630. if View.Orientation <> tbvoVertical then
  1631. ComboRect := Rect(Right - DropdownArrowWidth - DropdownArrowMargin, 0,
  1632. Right - DropdownArrowMargin, Bottom)
  1633. else
  1634. ComboRect := Rect(0, Bottom - DropdownArrowWidth - DropdownArrowMargin,
  1635. Right, Bottom - DropdownArrowMargin);
  1636. end
  1637. else
  1638. begin
  1639. ImgAndArrowWidth := ImgSize.CX + DropdownArrowWidth + 2;
  1640. ComboRect.Right := (R.Left + R.Right + ImgAndArrowWidth + 2) div 2;
  1641. ComboRect.Left := ComboRect.Right - DropdownArrowWidth;
  1642. ComboRect.Top := (R.Top + R.Bottom - ImgSize.cy - 2 - TextSize.CY) div 2;
  1643. ComboRect.Bottom := ComboRect.Top + ImgSize.CY;
  1644. end;
  1645. end
  1646. else SetRectEmpty(ComboRect);
  1647. if not IsSplit then
  1648. begin
  1649. PaintButton(Canvas, R, ItemInfo);
  1650. if HasArrow then
  1651. begin
  1652. PaintDropDownArrow(Canvas, ComboRect, ItemInfo);
  1653. if not IsSpecialDropDown then
  1654. begin
  1655. if View.Orientation <> tbvoVertical then Dec(R.Right, DropdownArrowWidth)
  1656. else Dec(R.Bottom, DropdownArrowWidth);
  1657. end;
  1658. end;
  1659. end
  1660. else // IsSplit
  1661. begin
  1662. CurrentTheme.PaintButton(Canvas, R, ItemInfo);
  1663. ItemInfo.Pushed := IsComboPushed;
  1664. ItemInfo.Selected := False;
  1665. ItemInfo.ComboPart := cpSplitRight;
  1666. CurrentTheme.PaintButton(Canvas, ComboRect, ItemInfo);
  1667. ItemInfo.ComboPart := cpSplitLeft;
  1668. ItemInfo.Pushed := IsPushed;
  1669. ItemInfo.Selected := Item.Checked;
  1670. end;
  1671. InflateRect(R, -2, -2);
  1672. end
  1673. else // not toolbar style
  1674. begin
  1675. GetMargins(MID_MENUITEM, Margins);
  1676. PaintMenuItem(Canvas, R, ItemInfo);
  1677. Inc(R.Left, Margins.LeftWidth);
  1678. Dec(R.Right, Margins.RightWidth);
  1679. Inc(R.Top, Margins.TopHeight);
  1680. Dec(R.Bottom, Margins.BottomHeight);
  1681. end;
  1682. { Caption }
  1683. if IsCaptionShown then
  1684. begin
  1685. if ToolbarStyle then
  1686. begin
  1687. CaptionRect := R;
  1688. TextFlags := TextFlags or DT_CENTER or DT_VCENTER;
  1689. Three := ScaleByTextHeightRunTime(Canvas, 3);
  1690. if ImageIsShown then with CaptionRect do
  1691. case ItemLayout of
  1692. tbxlGlyphLeft:
  1693. begin
  1694. Inc(Left, ImgSize.CX + Three + 1);
  1695. Top := (Top + Bottom - TextSize.CY) div 2;
  1696. Bottom := Top + TextSize.CY;
  1697. Left := (Left + Right - TextSize.CX) div 2;
  1698. Right := Left + TextSize.CX;
  1699. TextFlags := TextFlags and not DT_CENTER;
  1700. end;
  1701. tbxlGlyphTop:
  1702. begin
  1703. Inc(Top, ImgSize.CY + 1);
  1704. if IsTextRotated then Inc(CaptionRect.Top, 3);
  1705. Top := (Top + Bottom - TextSize.CY) div 2;
  1706. Bottom := Top + TextSize.CY;
  1707. Left := (Left + Right - TextSize.CX) div 2;
  1708. Right := Left + TextSize.CX;
  1709. TextFlags := TextFlags and not DT_VCENTER;
  1710. end;
  1711. end
  1712. else
  1713. begin
  1714. with CaptionRect, TextSize do
  1715. begin
  1716. Left := (Left + R.Right - CX) div 2;
  1717. Top := (Top + R.Bottom - CY) div 2;
  1718. Right := Left + CX;
  1719. Bottom := Top + CY;
  1720. end;
  1721. end;
  1722. Canvas.Font.Color := C;
  1723. PaintDefault := True;
  1724. DoPaintCaption(Canvas, ClientAreaRect, CaptionRect, IsTextRotated, PaintDefault);
  1725. if PaintDefault then
  1726. CurrentTheme.PaintCaption(Canvas, CaptionRect, ItemInfo, S, TextFlags, IsTextRotated);
  1727. end
  1728. else with CurrentTheme do
  1729. begin
  1730. TextFlags := DT_LEFT or DT_VCENTER or TextFlags;
  1731. TextSize := GetTextSize(Canvas, S, TextFlags, False, StateFlags); { TODO : Check if this line is required }
  1732. GetTextMetrics(Canvas.Handle, TextMetrics);
  1733. CaptionRect := R;
  1734. Inc(CaptionRect.Left, ItemInfo.PopupMargin + MenuImageTextSpace + MenuLeftCaptionMargin);
  1735. with TextMetrics, CaptionRect do
  1736. if (Bottom - Top) - (tmHeight + tmExternalLeading) = Margins.BottomHeight then Dec(Bottom);
  1737. Inc(CaptionRect.Top, TextMetrics.tmExternalLeading);
  1738. CaptionRect.Right := CaptionRect.Left + TextSize.CX;
  1739. Canvas.Font.Color := C;
  1740. PaintDefault := True;
  1741. DoPaintCaption(Canvas, ClientAreaRect, CaptionRect, IsTextRotated, PaintDefault);
  1742. if PaintDefault then
  1743. CurrentTheme.PaintCaption(Canvas, CaptionRect, ItemInfo, S, TextFlags, IsTextRotated);
  1744. end;
  1745. end;
  1746. { Shortcut and/or submenu arrow (menus only) }
  1747. if not ToolbarStyle then
  1748. begin
  1749. S := Item.GetShortCutText;
  1750. if Length(S) > 0 then
  1751. begin
  1752. CaptionRect := R;
  1753. with CaptionRect, TextMetrics do
  1754. begin
  1755. Left := Right - (Bottom - Top) - GetTextWidth(Canvas.Handle, S, True);
  1756. if (Bottom - Top) - (tmHeight + tmExternalLeading) = Margins.BottomHeight then Dec(Bottom);
  1757. Inc(Top, TextMetrics.tmExternalLeading);
  1758. end;
  1759. Canvas.Font.Color := C;
  1760. PaintDefault := True;
  1761. DoPaintCaption(Canvas, ClientAreaRect, CaptionRect, IsTextRotated, PaintDefault);
  1762. if PaintDefault then
  1763. CurrentTheme.PaintCaption(Canvas, CaptionRect, ItemInfo, S, TextFlags, False);
  1764. end;
  1765. end;
  1766. { Image, or check box }
  1767. if ImageOrCheckShown then
  1768. begin
  1769. ImageRect := R;
  1770. if ToolBarStyle then
  1771. begin
  1772. if IsSpecialDropDown then OffsetRect(ImageRect, (-CurrentTheme.DropdownArrowWidth + 1) div 2, 0);
  1773. if ItemLayout = tbxlGlyphLeft then ImageRect.Right := ImageRect.Left + ImgSize.CX + 2
  1774. else
  1775. begin
  1776. ImageRect.Top := (ImageRect.Top + ImageRect.Bottom - ImgSize.cy - 2 - TextSize.cy) div 2;
  1777. ImageRect.Bottom := ImageRect.Top + ImgSize.CY;
  1778. end;
  1779. end
  1780. else ImageRect.Right := ImageRect.Left + ClientAreaRect.Bottom - ClientAreaRect.Top;
  1781. if ImageIsShown then with ImageRect, ImgSize do
  1782. begin
  1783. Left := Left + ((Right - Left) - CX) div 2;
  1784. ImageRect.Top := Top + ((Bottom - Top) - CY) div 2;
  1785. Right := Left + CX;
  1786. Bottom := Top + CY;
  1787. DrawItemImage(Canvas, ImageRect, ItemInfo);
  1788. end
  1789. {else if not ToolbarStyle and Item.Checked then
  1790. CurrentTheme.PaintCheckMark(Canvas, ImageRect, ItemInfo);} {vb-}
  1791. else {vb+}
  1792. if not ToolbarStyle and Item.Checked then
  1793. begin
  1794. if Item.RadioItem then
  1795. with ItemInfo do ItemOptions := ItemOptions or IO_RADIO;
  1796. CurrentTheme.PaintCheckMark(Canvas, ImageRect, ItemInfo);
  1797. end;
  1798. end;
  1799. end;
  1800. //============================================================================//
  1801. { TTBXSubmenuItem }
  1802. constructor TTBXSubmenuItem.Create(AOwner: TComponent);
  1803. begin
  1804. inherited;
  1805. ItemStyle := ItemStyle + [tbisSubMenu, tbisSubitemsEditable];
  1806. end;
  1807. function TTBXSubmenuItem.GetDropdownCombo: Boolean;
  1808. begin
  1809. Result := tbisCombo in ItemStyle;
  1810. end;
  1811. procedure TTBXSubmenuItem.SetDropdownCombo(Value: Boolean);
  1812. begin
  1813. if (tbisCombo in ItemStyle) <> Value then begin
  1814. if Value then ItemStyle := ItemStyle + [tbisCombo]
  1815. else ItemStyle := ItemStyle - [tbisCombo];
  1816. Change (True);
  1817. end;
  1818. end;
  1819. //============================================================================//
  1820. { TTBXSeparatorItem }
  1821. constructor TTBXSeparatorItem.Create(AOwner: TComponent);
  1822. begin
  1823. inherited;
  1824. FSize := -1; // use default from as in TTBSeparatorItem
  1825. end;
  1826. function TTBXSeparatorItem.GetItemViewerClass(AView: TTBView): TTBItemViewerClass;
  1827. begin
  1828. Result := TTBXSeparatorItemViewer;
  1829. end;
  1830. procedure TTBXSeparatorItem.SetSize(Value: Integer);
  1831. begin
  1832. if Value < -1 then Value := -1;
  1833. if Value <> FSize then
  1834. begin
  1835. FSize := Value;
  1836. Change(True);
  1837. end;
  1838. end;
  1839. //============================================================================//
  1840. { TTBXSeparatorItemViewer }
  1841. procedure TTBXSeparatorItemViewer.CalcSize(const Canvas: TCanvas;
  1842. var AWidth, AHeight: Integer);
  1843. var
  1844. SZ: Integer;
  1845. begin
  1846. SZ := TTBXSeparatorItem(Item).Size;
  1847. if SZ < 0 then
  1848. begin
  1849. if not IsToolbarStyle then SZ := CurrentTheme.MenuSeparatorSize
  1850. else SZ := CurrentTheme.TlbrSeparatorSize;
  1851. if SZ < 0 then inherited CalcSize(Canvas, AWidth, AHeight)
  1852. else
  1853. begin
  1854. AWidth := SZ;
  1855. AHeight := SZ;
  1856. end;
  1857. end
  1858. else if not IsToolbarStyle then
  1859. begin
  1860. AHeight := SZ;
  1861. AWidth := 0;
  1862. end
  1863. else
  1864. begin
  1865. AWidth := SZ;
  1866. AHeight := SZ;
  1867. end;
  1868. end;
  1869. function TTBXSeparatorItemViewer.IsToolbarSize: Boolean;
  1870. begin
  1871. Result := inherited IsToolbarSize;
  1872. Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
  1873. end;
  1874. function TTBXSeparatorItemViewer.IsToolbarStyle: Boolean;
  1875. begin
  1876. Result := inherited IsToolbarStyle;
  1877. Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
  1878. end;
  1879. procedure TTBXSeparatorItemViewer.Paint(const Canvas: TCanvas;
  1880. const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean);
  1881. const
  1882. CToolbarStyle: array [Boolean] of Integer = (0, IO_TOOLBARSTYLE);
  1883. CDesigning: array [Boolean] of Integer = (0, IO_DESIGNING);
  1884. var
  1885. Item: TTBXSeparatorItem;
  1886. ItemInfo: TTBXItemInfo;
  1887. R: TRect;
  1888. LineSep, HorzLine: Boolean;
  1889. begin
  1890. Item := TTBXSeparatorItem(Self.Item);
  1891. if Item.Size = 0 then Exit;
  1892. FillChar(ItemInfo, SizeOf(TTBXItemInfo), 0);
  1893. ItemInfo.ViewType := GetViewType(View);
  1894. ItemInfo.ItemOptions := CToolbarStyle[IsToolbarStyle] or
  1895. CDesigning[csDesigning in Item.ComponentState];
  1896. ItemInfo.Enabled := not Item.Blank;
  1897. ItemInfo.Pushed := IsPushed;
  1898. ItemInfo.Selected := False;
  1899. ItemInfo.ImageShown := False;
  1900. ItemInfo.ImageWidth := 0;
  1901. ItemInfo.ImageHeight := 0;
  1902. ItemInfo.IsVertical := View.Orientation = tbvoVertical;
  1903. if not IsToolbarStyle then ItemInfo.PopupMargin := GetPopupMargin(Self);
  1904. R := ClientAreaRect;
  1905. LineSep := tbisLineSep in State;
  1906. with ItemInfo do
  1907. begin
  1908. HorzLine := (IsVertical xor LineSep) or View.IsPopup;
  1909. if (((ViewType and VT_POPUP) = VT_POPUP) and
  1910. ((ViewType and PVT_CHEVRONMENU) = PVT_CHEVRONMENU)) then
  1911. HorzLine := (HorzLine and LineSep);
  1912. end;
  1913. CurrentTheme.PaintSeparator(Canvas, R, ItemInfo, HorzLine, LineSep);
  1914. end;
  1915. //============================================================================//
  1916. {$IFNDEF MPEXCLUDE}
  1917. { TTBXVisibilityToggleItem }
  1918. procedure TTBXVisibilityToggleItem.Click;
  1919. begin
  1920. if Assigned(FControl) then FControl.Visible := not FControl.Visible;
  1921. inherited;
  1922. end;
  1923. procedure TTBXVisibilityToggleItem.InitiateAction;
  1924. begin
  1925. UpdateProps;
  1926. end;
  1927. procedure TTBXVisibilityToggleItem.Notification(AComponent: TComponent; Operation: TOperation);
  1928. begin
  1929. inherited;
  1930. if (Operation = opRemove) and (AComponent = FControl) then Control := nil;
  1931. end;
  1932. procedure TTBXVisibilityToggleItem.SetControl(Value: TControl);
  1933. begin
  1934. if FControl <> Value then
  1935. begin
  1936. FControl := Value;
  1937. if Assigned(Value) then
  1938. begin
  1939. Value.FreeNotification(Self);
  1940. if (Length(Caption) = 0) and not (csLoading in ComponentState) then
  1941. Caption := TControlAccess(Value).Caption;
  1942. end;
  1943. UpdateProps;
  1944. end;
  1945. end;
  1946. procedure TTBXVisibilityToggleItem.UpdateProps;
  1947. begin
  1948. if (ComponentState * [csDesigning, csLoading, csDestroying] = []) then
  1949. Checked := Assigned(FControl) and FControl.Visible;
  1950. end;
  1951. {$ENDIF}
  1952. //============================================================================//
  1953. { TTBXPopupWindow }
  1954. procedure TTBXPopupWindow.CMHintShow(var Message: TCMHintShow);
  1955. begin
  1956. with Message.HintInfo^ do
  1957. begin
  1958. HintStr := '';
  1959. if Assigned(View.Selected) then
  1960. begin
  1961. CursorRect := View.Selected.BoundsRect;
  1962. HintStr := View.Selected.GetHintText;
  1963. View.Selected.Dispatch(Message);
  1964. end;
  1965. end;
  1966. end;
  1967. procedure TTBXPopupWindow.CMShowingChanged(var Message: TMessage); {vb+}
  1968. const
  1969. ShowFlags: array[Boolean] of UINT = (
  1970. SWP_NOSIZE or SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_HIDEWINDOW,
  1971. SWP_NOSIZE or SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_SHOWWINDOW);
  1972. var
  1973. MenuAni: TMenuAnimation;
  1974. AniDir: TTBAnimationDirection;
  1975. begin
  1976. { Must override TCustomForm/TForm's CM_SHOWINGCHANGED handler so that the
  1977. form doesn't get activated when Visible is set to True. }
  1978. { Handle animation. NOTE: I do not recommend trying to enable animation on
  1979. Windows 95 and NT 4.0 because there's a difference in the way the
  1980. SetWindowPos works on those versions. See the comment in the
  1981. TBStartAnimation function of TB2Anim.pas. }
  1982. {$IFNDEF TBX_NO_ANIMATION}
  1983. if ((View.ParentView = nil) or not(vsNoAnimation in View.ParentView.State)) and
  1984. Showing and (View.Selected = nil) and not IsWindowVisible(WindowHandle) and
  1985. (TBXMenuAnimation.AnimationMode <> amNone) then
  1986. begin
  1987. { Start animation only if WM_TB2K_POPUPSHOWING returns zero (or not handled) }
  1988. if SendMessage(WindowHandle, WM_TB2K_POPUPSHOWING, TPS_ANIMSTART, 0) = 0 then
  1989. begin
  1990. MenuAni := TBXMenuAnimation.MenuAnimation;
  1991. { MP (do not animate if disallowed by system-wide config) }
  1992. if MenuAni <> maNone then
  1993. begin
  1994. AniDir := TTBPopupWindowAccess(Self).AnimationDirection;
  1995. if MenuAni = maUnfold then
  1996. if [tbadDown, tbadUp] * AniDir <> []
  1997. then Include(AniDir, tbadRight)
  1998. else Include(AniDir, tbadDown);
  1999. TBStartAnimation(WindowHandle, MenuAni = maFade, AniDir);
  2000. Exit;
  2001. end;
  2002. end;
  2003. end;
  2004. {$ENDIF}
  2005. { No animation... }
  2006. if not Showing then begin
  2007. { Call TBEndAnimation to ensure WS_EX_LAYERED style is removed before
  2008. hiding, otherwise windows under the popup window aren't repainted
  2009. properly. }
  2010. TBEndAnimation(WindowHandle);
  2011. end;
  2012. SetWindowPos(WindowHandle, 0, 0, 0, 0, 0, ShowFlags[Showing]);
  2013. if Showing then SendNotifyMessage(WindowHandle, WM_TB2K_POPUPSHOWING, TPS_NOANIM, 0);
  2014. end;
  2015. procedure TTBXPopupWindow.CreateParams(var Params: TCreateParams);
  2016. const
  2017. CS_DROPSHADOW = $00020000;
  2018. begin
  2019. inherited CreateParams(Params);
  2020. with Params do
  2021. begin
  2022. WindowClass.Style := WindowClass.Style and not (CS_DROPSHADOW or CS_DBLCLKS);
  2023. if GetShowShadow and (CurrentTheme.GetPopupShadowType = PST_WINDOWSXP) then
  2024. begin
  2025. WindowClass.Style := WindowClass.Style or CS_DROPSHADOW;
  2026. StrPCopy(WinClassName, ClassName + 'S');
  2027. end;
  2028. end;
  2029. end;
  2030. procedure TTBXPopupWindow.CreateShadow;
  2031. var
  2032. PR: TRect;
  2033. ParentViewer: TTBItemViewer;
  2034. VT: Integer;
  2035. ChevronParent: Boolean;
  2036. begin
  2037. PR := Rect(0, 0, 0, 0);
  2038. if CurrentTheme.GetPopupShadowType = PST_OFFICEXP then
  2039. begin
  2040. if (View <> nil) and (View.ParentView <> nil) then
  2041. begin
  2042. ParentViewer := TTBViewAccess(View.ParentView).OpenViewer;
  2043. ChevronParent := Self is TTBXChevronPopupWindow;
  2044. if ((ParentViewer is TTBXItemViewer) or ChevronParent) then
  2045. begin
  2046. VT := GetViewType(ParentViewer.View);
  2047. if ((VT and PVT_POPUPMENU) <> PVT_POPUPMENU) or ChevronParent then
  2048. begin
  2049. PR := ParentViewer.BoundsRect;
  2050. PR.TopLeft := View.ParentView.Window.ClientToScreen(PR.TopLeft);
  2051. PR.BottomRight := View.ParentView.Window.ClientToScreen(PR.BottomRight);
  2052. end;
  2053. end;
  2054. end
  2055. else if not IsRectEmpty(FControlRect) then
  2056. begin
  2057. PR := FControlRect;
  2058. end;
  2059. end;
  2060. FShadows := TShadows.Create(PR, BoundsRect, 4, 61, TBXLoColor);
  2061. FShadows.Show(Handle);
  2062. end;
  2063. destructor TTBXPopupWindow.Destroy;
  2064. begin
  2065. DestroyShadow;
  2066. inherited;
  2067. end;
  2068. procedure TTBXPopupWindow.DestroyShadow;
  2069. var
  2070. SaveShadows: TObject;
  2071. begin
  2072. SaveShadows := FShadows;
  2073. FShadows := nil;
  2074. SaveShadows.Free;
  2075. end;
  2076. function TTBXPopupWindow.GetFillColor: TColor;
  2077. begin
  2078. Result := CurrentTheme.GetViewColor(GetViewType(View));
  2079. View.BackgroundColor := Result;
  2080. end;
  2081. function TTBXPopupWindow.GetNCSize: TPoint;
  2082. begin
  2083. Result := inherited GetNCSize;
  2084. CurrentTheme.GetViewBorder(GetViewType(View), Result);
  2085. end;
  2086. function TTBXPopupWindow.GetShowShadow: Boolean;
  2087. begin
  2088. Result := ((GetViewType(View) and PVT_LISTBOX) <> PVT_LISTBOX );
  2089. end;
  2090. function TTBXPopupWindow.GetViewClass: TTBViewClass;
  2091. begin
  2092. Result := TTBXPopupView;
  2093. end;
  2094. procedure TTBXPopupWindow.PaintScrollArrows; {vb+}
  2095. function _GetPopupMargin: Integer;
  2096. begin
  2097. if View.ParentView <> nil then
  2098. Result := GetPopupMargin(TTBViewAccess(View.ParentView).OpenViewer)
  2099. else if View.ViewerCount > 0 then
  2100. Result := GetPopupMargin(View.Viewers[0])
  2101. else Result := -1;
  2102. end;
  2103. procedure DrawArrows;
  2104. var
  2105. ItemInfo: TTBXItemInfo;
  2106. Index: Integer;
  2107. begin
  2108. FillChar(ItemInfo, SizeOf(ItemInfo), 0);
  2109. ItemInfo.ViewType := PVT_POPUPMENU;
  2110. ItemInfo.Enabled := True;
  2111. ItemInfo.PopupMargin := _GetPopupMargin;
  2112. if ItemInfo.PopupMargin > 0 then
  2113. begin
  2114. if TTBViewAccess(View).ShowUpArrow then
  2115. for Index := 0 to View.ViewerCount- 1 do
  2116. if View.Viewers[Index].Show then
  2117. begin
  2118. CurrentTheme.PaintMenuItemFrame(Canvas, Rect(0, 0, ClientWidth,
  2119. View.Viewers[Index].BoundsRect.Top), ItemInfo);
  2120. Break;
  2121. end;
  2122. if TTBViewAccess(View).ShowDownArrow then
  2123. for Index := View.ViewerCount- 1 downto 0 do
  2124. if View.Viewers[Index].Show then
  2125. begin
  2126. CurrentTheme.PaintMenuItemFrame(Canvas, Rect(0,
  2127. View.Viewers[Index].BoundsRect.Bottom, ClientWidth,
  2128. ClientHeight), ItemInfo);
  2129. Break;
  2130. end;
  2131. end;
  2132. end;
  2133. begin
  2134. with TTBViewAccess(View) do
  2135. if ShowUpArrow or ShowDownArrow then
  2136. DrawArrows;
  2137. inherited;
  2138. end;
  2139. procedure TTBXPopupWindow.TBMGetViewType(var Message: TMessage);
  2140. var
  2141. PI: TTBCustomItem;
  2142. begin
  2143. Message.Result := PVT_POPUPMENU;
  2144. if View <> nil then
  2145. if Self is TTBXChevronPopupWindow then
  2146. Message.Result := PVT_CHEVRONMENU
  2147. else
  2148. begin
  2149. PI := View.ParentItem;
  2150. if PI <> nil then
  2151. begin
  2152. if (PI.Count = 1) and (PI.Items[0] is TTBXCustomList) then
  2153. Message.Result := PVT_LISTBOX
  2154. else if PI is TTBXEditItem then
  2155. begin
  2156. Message.Result := PVT_TOOLBOX;
  2157. end
  2158. else if (PI is TTBXCustomItem) and (TTBXCustomItem(PI).ToolBoxPopup) then
  2159. Message.Result := PVT_TOOLBOX
  2160. end;
  2161. end;
  2162. end;
  2163. procedure TTBXPopupWindow.WMEraseBkgnd(var Message: TWmEraseBkgnd);
  2164. var
  2165. Canvas: TCanvas;
  2166. R: TRect;
  2167. begin
  2168. TBEndAnimation(WindowHandle);
  2169. Canvas := TCanvas.Create;
  2170. Canvas.Handle := Message.DC;
  2171. R := ClientRect;
  2172. CurrentTheme.PaintBackgnd(Canvas, R, R, R, GetFillColor, False, GetViewType(View));
  2173. Canvas.Handle := 0;
  2174. Canvas.Free;
  2175. Message.Result := 1;
  2176. end;
  2177. procedure TTBXPopupWindow.WMNCCalcSize(var Message: TWMNCCalcSize);
  2178. var
  2179. Sz: TPoint;
  2180. begin
  2181. CurrentTheme.GetViewBorder(GetViewType(View), Sz);
  2182. with Message.CalcSize_Params^.rgrc[0], Sz do
  2183. begin
  2184. Inc(Left, X);
  2185. Inc(Top, Y);
  2186. Dec(Right, X);
  2187. Dec(Bottom, Y);
  2188. end;
  2189. Message.Result := 1;
  2190. end;
  2191. procedure TBXPopupNCPaintProc(Wnd: HWND; DC: HDC; AppData: Longint);
  2192. var
  2193. R, R2: TRect;
  2194. Canvas: TCanvas;
  2195. View: TTBPopupView;
  2196. PopupInfo: TTBXPopupInfo;
  2197. ParentViewer: TTBItemViewer;
  2198. begin
  2199. Assert(DC <> 0, 'TBXPopupNCPaintProc');
  2200. Canvas := TCanvas.Create;
  2201. try
  2202. Canvas.Handle := DC;
  2203. FillChar(PopupInfo, SizeOf(PopupInfo), 0);
  2204. View := TTBPopupView(AppData);
  2205. PopupInfo.WindowHandle := View.Window.Handle;
  2206. PopupInfo.ViewType := GetViewType(View);
  2207. if View.ParentView <> nil then
  2208. begin
  2209. ParentViewer := TTBViewAccess(View.ParentView).OpenViewer;
  2210. if ((ParentViewer is TTBXItemViewer) or (View.Window is TTBXChevronPopupWindow))
  2211. and TTBItemViewerAccess(ParentViewer).IsToolbarStyle then
  2212. begin
  2213. R := ParentViewer.BoundsRect;
  2214. R.TopLeft := View.ParentView.Window.ClientToScreen(R.TopLeft);
  2215. R.BottomRight := View.ParentView.Window.ClientToScreen(R.BottomRight);
  2216. GetWindowRect(Wnd, R2);
  2217. OffsetRect(R, -R2.Left, -R2.Top);
  2218. PopupInfo.ParentRect := R;
  2219. end;
  2220. end
  2221. else if View.ParentItem is TTBXRootItem then
  2222. begin
  2223. R := TTBXRootItem(View.ParentItem).FPopupControlRect;
  2224. if not IsRectEmpty(R) then
  2225. begin
  2226. GetWindowRect(Wnd, R2);
  2227. OffsetRect(R, -R2.Left, -R2.Top);
  2228. PopupInfo.ParentRect := R;
  2229. end;
  2230. end;
  2231. GetWindowRect(Wnd, R);
  2232. OffsetRect(R, -R.Left, -R.Top);
  2233. CurrentTheme.GetViewBorder(PopupInfo.ViewType, PopupInfo.BorderSize);
  2234. R2 := R;
  2235. with PopupInfo.BorderSize do InflateRect(R2, -X, -Y);
  2236. with R2 do ExcludeClipRect(Canvas.Handle, Left, Top, Right, Bottom);
  2237. CurrentTheme.PaintPopupNCArea(Canvas, R, PopupInfo);
  2238. finally
  2239. Canvas.Handle := 0;
  2240. Canvas.Free;
  2241. end;
  2242. end;
  2243. procedure TTBXPopupWindow.WMNCPaint(var Message: TMessage);
  2244. var
  2245. DC: HDC;
  2246. begin
  2247. DC := GetWindowDC(Handle);
  2248. try
  2249. Assert(DC <> 0, 'TTBXPopupWindow.WMNCPaint');
  2250. SelectNCUpdateRgn(Handle, DC, HRGN(Message.WParam));
  2251. TBXPopupNCPaintProc(Handle, DC, LongInt(Self.View));
  2252. finally
  2253. ReleaseDC(Handle, DC);
  2254. end;
  2255. end;
  2256. procedure TTBXPopupWindow.WMPrint(var Message: TMessage);
  2257. begin
  2258. HandleWMPrint(Handle, Message, TBXPopupNCPaintProc, LongInt(Self.View));
  2259. end;
  2260. procedure TTBXPopupWindow.WMTB2kPopupShowing(var Message: TMessage);
  2261. begin
  2262. if Message.WParam in [TPS_ANIMFINISHED, TPS_NOANIM] then
  2263. begin
  2264. if not (csDestroying in ComponentState) and GetShowShadow and
  2265. (CurrentTheme.GetPopupShadowType in [PST_OFFICEXP, PST_WINDOWS2K]) then CreateShadow;
  2266. end;
  2267. end;
  2268. procedure TTBXPopupWindow.WMWindowPosChanged(var Message: TWMWindowPosChanged);
  2269. begin
  2270. inherited;
  2271. with Message.WindowPos^ do
  2272. if ((flags and SWP_SHOWWINDOW) = 0) and ((flags and SWP_HIDEWINDOW) = 0) then
  2273. begin
  2274. if FShadows <> nil then
  2275. begin
  2276. DestroyShadow;
  2277. CreateShadow;
  2278. end;
  2279. end;
  2280. end;
  2281. //============================================================================//
  2282. { TTBXToolbarView }
  2283. procedure TTBXToolbarView.GetMargins(AOrientation: TTBViewOrientation; var Margins: TRect);
  2284. var
  2285. VT: Integer;
  2286. M: TTBXMargins;
  2287. begin
  2288. VT := GetWinViewType(TTBXToolbar(Owner));
  2289. if (VT and VT_TOOLBAR) = VT_TOOLBAR then
  2290. begin
  2291. if AOrientation = tbvoFloating then VT := VT or TVT_FLOATING
  2292. else VT := VT and not TVT_FLOATING
  2293. end
  2294. else if (VT and VT_DOCKPANEL) = VT_DOCKPANEL then
  2295. begin
  2296. if AOrientation = tbvoFloating then VT := VT or DPVT_FLOATING
  2297. else VT := VT and not DPVT_FLOATING
  2298. end;
  2299. CurrentTheme.GetViewMargins(VT, M);
  2300. Margins.Left := M.LeftWidth;
  2301. Margins.Top := M.TopHeight;
  2302. Margins.Right := M.RightWidth;
  2303. Margins.Bottom := M.BottomHeight;
  2304. end;
  2305. //============================================================================//
  2306. { TTBXToolbar }
  2307. procedure TTBXToolbar.CMColorChanged(var Message: TMessage);
  2308. begin
  2309. UpdateEffectiveColor;
  2310. if Docked and HandleAllocated then
  2311. begin
  2312. RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
  2313. RDW_ERASE or RDW_UPDATENOW or RDW_ALLCHILDREN);
  2314. end;
  2315. UpdateChildColors;
  2316. Invalidate;
  2317. end;
  2318. procedure TTBXToolbar.CMControlChange(var Message: TCMControlChange);
  2319. begin
  2320. inherited;
  2321. if Message.Inserting and (Color = clNone) then
  2322. Message.Control.Perform(CM_PARENTCOLORCHANGED, 1, EffectiveColor);
  2323. end;
  2324. procedure TTBXToolbar.CMParentColorChanged(var Message: TMessage);
  2325. begin
  2326. if Embedded and (Color = clNone) then
  2327. begin
  2328. UpdateEffectiveColor;
  2329. if (Message.WParam = 0) then
  2330. begin
  2331. Message.WParam := 1;
  2332. Message.LParam := EffectiveColor;
  2333. end;
  2334. end;
  2335. inherited;
  2336. Invalidate;
  2337. end;
  2338. constructor TTBXToolbar.Create(AOwner: TComponent);
  2339. begin
  2340. inherited;
  2341. AddThemeNotification(Self);
  2342. FEffectiveColor := Color;
  2343. Color := clNone;
  2344. ControlStyle := ControlStyle - [csOpaque];
  2345. DblClickUndock := False;
  2346. end;
  2347. destructor TTBXToolbar.Destroy;
  2348. begin
  2349. RemoveThemeNotification(Self);
  2350. inherited;
  2351. end;
  2352. procedure TTBXToolbar.DrawNCArea(const DrawToDC: Boolean; const ADC: HDC; const Clip: HRGN);
  2353. var
  2354. DC: HDC;
  2355. R, CR, R2: TRect;
  2356. ACanvas: TCanvas;
  2357. ToolbarInfo: TTBXToolbarInfo;
  2358. UsingBackground: Boolean;
  2359. begin
  2360. if not Docked or not HandleAllocated then Exit;
  2361. if not DrawToDC then DC := GetWindowDC(Handle)
  2362. else DC := ADC;
  2363. UsingBackground := TDockAccess(CurrentDock).UsingBackground;
  2364. try
  2365. GetToolbarInfo(ToolbarInfo);
  2366. GetWindowRect(Handle, R);
  2367. OffsetRect(R, -R.Left, -R.Top);
  2368. if not DrawToDC then
  2369. begin
  2370. SelectNCUpdateRgn(Handle, DC, Clip);
  2371. CR := R;
  2372. with ToolbarInfo.BorderSize, CR do
  2373. begin
  2374. InflateRect(CR, -X, -Y);
  2375. if ToolbarInfo.IsVertical then Inc(Top, GetTBXDragHandleSize(ToolbarInfo))
  2376. else Inc(Left, GetTBXDragHandleSize(ToolbarInfo));
  2377. ExcludeClipRect(DC, Left, Top, Right, Bottom);
  2378. end;
  2379. end;
  2380. ACanvas := TCanvas.Create;
  2381. try
  2382. ACanvas.Handle := DC;
  2383. if CurrentTheme.SolidToolbarNCArea then
  2384. begin
  2385. ACanvas.Brush.Color := EffectiveColor;
  2386. ACanvas.Brush.Style := bsSolid;
  2387. end
  2388. else if UsingBackground then
  2389. begin
  2390. ACanvas.Brush.Color := EffectiveColor;
  2391. R2 := CurrentDock.ClientRect;
  2392. OffsetRect(R2, -Left, -Top);
  2393. TDockAccess(CurrentDock).DrawBackground(DC, R2);
  2394. {$IFNDEF MPEXCLUDE}
  2395. if (Color = clNone) and CurrentDock.BackgroundOnToolbars then
  2396. ACanvas.Brush.Style := bsClear;
  2397. {$ENDIF}
  2398. end
  2399. else
  2400. begin
  2401. ACanvas.Brush.Color := GetEffectiveColor(CurrentDock);
  2402. ACanvas.FillRect(R);
  2403. ACanvas.Brush.Color := EffectiveColor;
  2404. ACanvas.Brush.Style := bsSolid;
  2405. end;
  2406. CurrentTheme.PaintToolbarNCArea(ACanvas, R, ToolbarInfo);
  2407. finally
  2408. ACanvas.Handle := 0;
  2409. ACanvas.Free;
  2410. end;
  2411. finally
  2412. if not DrawToDC then ReleaseDC(Handle, DC);
  2413. end;
  2414. end;
  2415. function TTBXToolbar.Embedded: Boolean;
  2416. begin
  2417. Result := not (Floating or Docked);
  2418. end;
  2419. function TTBXToolbar.GetChevronItemClass: TTBChevronItemClass;
  2420. begin
  2421. Result := TTBXChevronItem;
  2422. end;
  2423. function TTBXToolbar.GetFloatingBorderSize: TPoint;
  2424. begin
  2425. CurrentTheme.GetViewBorder(GetViewType(View) or TVT_FLOATING, Result);
  2426. end;
  2427. function TTBXToolbar.GetFloatingWindowParentClass: TTBFloatingWindowParentClass;
  2428. begin
  2429. Result := TTBXFloatingWindowParent;
  2430. end;
  2431. procedure TTBXToolbar.GetToolbarInfo(out ToolbarInfo: TTBXToolbarInfo);
  2432. begin
  2433. FillChar(ToolbarInfo, SizeOf(ToolbarInfo), 0);
  2434. ToolbarInfo.WindowHandle := Handle;
  2435. ToolbarInfo.ViewType := GetWinViewType(Self);
  2436. if CurrentDock <> nil then
  2437. ToolbarInfo.IsVertical := CurrentDock.Position in [dpLeft,dpRight];
  2438. ToolbarInfo.AllowDrag := CurrentDock.AllowDrag;
  2439. ToolbarInfo.DragHandleStyle := Ord(DragHandleStyle);
  2440. ToolbarInfo.ClientWidth := ClientWidth;
  2441. ToolbarInfo.ClientHeight := ClientHeight;
  2442. if ToolbarInfo.AllowDrag and CloseButtonWhenDocked then
  2443. begin
  2444. ToolbarInfo.CloseButtonState := CDBS_VISIBLE;
  2445. if CloseButtonDown then ToolbarInfo.CloseButtonState := ToolbarInfo.CloseButtonState or CDBS_PRESSED
  2446. else if CloseButtonHover then ToolbarInfo.CloseButtonState := ToolbarInfo.CloseButtonState or CDBS_HOT;
  2447. end;
  2448. ToolbarInfo.BorderStyle := BorderStyle;
  2449. CurrentTheme.GetViewBorder(ToolbarInfo.ViewType, ToolbarInfo.BorderSize);
  2450. ToolbarInfo.EffectiveColor := EffectiveColor;
  2451. end;
  2452. function TTBXToolbar.GetViewClass: TTBToolbarViewClass;
  2453. begin
  2454. Result := TTBXToolbarView;
  2455. end;
  2456. procedure TTBXToolbar.SetItemTransparency(const Value: TTBXItemTransparency);
  2457. begin
  2458. FItemTransparency := Value;
  2459. Invalidate;
  2460. end;
  2461. procedure TTBXToolbar.Loaded; {vb+}
  2462. begin
  2463. inherited;
  2464. UpdateEffectiveColor;
  2465. end;
  2466. procedure TTBXToolbar.SetParent(AParent: TWinControl);
  2467. begin
  2468. inherited;
  2469. if AParent is TTBXFloatingWindowParent then
  2470. TTBXFloatingWindowParent(AParent).SnapDistance := SnapDistance;
  2471. end;
  2472. procedure TTBXToolbar.SetSnapDistance(Value: Integer);
  2473. begin
  2474. if Value < 0 then Value := 0;
  2475. FSnapDistance := Value;
  2476. if (Parent <> nil) and (Parent is TTBXFloatingWindowParent) then
  2477. TTBXFloatingWindowParent(Parent).SnapDistance := Value;
  2478. end;
  2479. procedure TTBXToolbar.TBMGetEffectiveColor(var Message: TMessage);
  2480. begin
  2481. Message.WParam := EffectiveColor;
  2482. Message.Result := 1;
  2483. end;
  2484. procedure TTBXToolbar.TBMGetViewType(var Message: TMessage);
  2485. begin
  2486. if MenuBar then Message.Result := TVT_MENUBAR
  2487. else Message.Result := TVT_NORMALTOOLBAR;
  2488. if Floating then Message.Result := Message.Result or TVT_FLOATING;
  2489. if Resizable then Message.Result := Message.Result or TVT_RESIZABLE;
  2490. case ItemTransparency of
  2491. itAuto:
  2492. if not (Floating or Docked) then Message.Result := Message.Result or TVT_EMBEDDED;
  2493. itDisable:
  2494. Message.Result := Message.Result or TVT_EMBEDDED;
  2495. end;
  2496. end;
  2497. procedure TTBXToolbar.TBMThemeChange(var Message: TMessage);
  2498. begin
  2499. case Message.WParam of
  2500. TSC_BEFOREVIEWCHANGE: BeginUpdate;
  2501. TSC_AFTERVIEWCHANGE:
  2502. begin
  2503. EndUpdate;
  2504. UpdateEffectiveColor;
  2505. if Floating then UpdateNCArea(TTBXFloatingWindowParent(Parent), GetWinViewType(Self))
  2506. else UpdateNCArea(Self, GetWinViewType(Self));
  2507. Invalidate;
  2508. Arrange;
  2509. UpdateChildColors;
  2510. end;
  2511. TSC_APPACTIVATE, TSC_APPDEACTIVATE:
  2512. if MenuBar then Invalidate;
  2513. end;
  2514. end;
  2515. procedure TTBXToolbar.UpdateChildColors;
  2516. var
  2517. M: TMessage;
  2518. begin
  2519. M.Msg := CM_PARENTCOLORCHANGED;
  2520. M.WParam := 1;
  2521. M.LParam := EffectiveColor;
  2522. M.Result := 0;
  2523. Broadcast(M);
  2524. end;
  2525. procedure TTBXToolbar.UpdateEffectiveColor;
  2526. begin
  2527. if Color = clNone then
  2528. begin
  2529. if Embedded and (Parent <> nil) then
  2530. FEffectiveColor := GetEffectiveColor(Parent)
  2531. else
  2532. FEffectiveColor := CurrentTheme.GetViewColor(GetViewType(View));
  2533. end
  2534. else FEffectiveColor := Color;
  2535. end;
  2536. procedure TTBXToolbar.WMEraseBkgnd(var Message: TWmEraseBkgnd);
  2537. var
  2538. Canvas: TCanvas;
  2539. R, CR: TRect;
  2540. Transparent: Boolean;
  2541. begin
  2542. Transparent := False;
  2543. CR := ClientRect;
  2544. if Color = clNone then
  2545. {$IFNDEF MPEXCLUDE}
  2546. if Docked and (TDockAccess(CurrentDock).UsingBackground) and CurrentDock.BackgroundOnToolbars
  2547. and not CurrentTheme.SolidToolbarClientArea then
  2548. begin
  2549. R := CurrentDock.ClientRect;
  2550. R.TopLeft := ScreenToClient(CurrentDock.ClientToScreen(R.TopLeft));
  2551. R.BottomRight := ScreenToClient(CurrentDock.ClientToScreen(R.BottomRight));
  2552. TDockAccess(CurrentDock).DrawBackground(Message.DC, R);
  2553. Message.Result := 1;
  2554. Transparent := True;
  2555. end
  2556. else {$ENDIF} if Embedded then
  2557. begin
  2558. Transparent := True;
  2559. DrawParentBackground(Self, Message.DC, CR);
  2560. end;
  2561. Canvas := TCanvas.Create;
  2562. Canvas.Handle := Message.DC;
  2563. try
  2564. if Docked then
  2565. begin
  2566. R := CurrentDock.ClientRect;
  2567. R.TopLeft := ScreenToClient(CurrentDock.ClientToScreen(R.TopLeft));
  2568. R.BottomRight := ScreenToClient(CurrentDock.ClientToScreen(R.BottomRight));
  2569. end
  2570. else R := Rect(0, 0, 0, 0);
  2571. CurrentTheme.PaintBackgnd(Canvas, R, CR, CR, EffectiveColor, Transparent, GetWinViewType(Self));
  2572. Message.Result := 1;
  2573. finally
  2574. Canvas.Handle := 0;
  2575. Canvas.Free;
  2576. end;
  2577. end;
  2578. procedure TTBXToolbar.WMSize(var Message: TWMSize);
  2579. {$IFNDEF MPEXCLUDE}
  2580. var
  2581. I: Integer;
  2582. V: TTBItemViewer;
  2583. R: TRect;
  2584. {$ENDIF}
  2585. begin
  2586. inherited;
  2587. {$IFNDEF MPEXCLUDE}
  2588. if Docked and TDockAccess(CurrentDock).UsingBackground and
  2589. TDockAccess(CurrentDock).BackgroundOnToolbars and
  2590. ((CurrentDock is TTBXDock) and not TTBXDock(CurrentDock).FResizing) then
  2591. begin
  2592. for I := 0 to View.ViewerCount - 1 do
  2593. begin
  2594. V := View.Viewers[I];
  2595. if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
  2596. then View.Invalidate(V);
  2597. end;
  2598. Self.Update;
  2599. InvalidateRect(Handle, nil, True);
  2600. for I := 0 to View.ViewerCount - 1 do
  2601. begin
  2602. V := View.Viewers[I];
  2603. if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
  2604. then
  2605. begin
  2606. R := V.BoundsRect;
  2607. ValidateRect(Handle, @R);
  2608. end;
  2609. end;
  2610. end;
  2611. {$ENDIF}
  2612. end;
  2613. //============================================================================//
  2614. { TTBXChevronItem }
  2615. function TTBXChevronItem.GetItemViewerClass(AView: TTBView): TTBItemViewerClass;
  2616. begin
  2617. Result := TTBXChevronItemViewer;
  2618. end;
  2619. procedure TTBXChevronItem.GetPopupPosition(ParentView: TTBView;
  2620. PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec);
  2621. begin
  2622. if CurrentTheme.OfficeXPPopupAlignment then with PopupPositionRec do
  2623. begin
  2624. GetOfficeXPPopupPosition1(PopupPositionRec);
  2625. inherited GetPopupPosition(ParentView, PopupWindow, PopupPositionRec);
  2626. GetOfficeXPPopupPosition2(PopupPositionRec);
  2627. end
  2628. else inherited;
  2629. end;
  2630. function TTBXChevronItem.GetPopupWindowClass: TTBPopupWindowClass;
  2631. begin
  2632. Result := TTBXChevronPopupWindow;
  2633. end;
  2634. //============================================================================//
  2635. { TTBXChevronItemViewer }
  2636. procedure TTBXChevronItemViewer.Paint(const Canvas: TCanvas;
  2637. const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean);
  2638. const
  2639. CDesigning: array [Boolean] of Integer = (0, IO_DESIGNING);
  2640. var
  2641. ItemInfo: TTBXItemInfo;
  2642. begin
  2643. FillChar(ItemInfo, SizeOf(TTBXItemInfo), 0);
  2644. ItemInfo.ViewType := GetViewType(View);
  2645. ItemInfo.ItemOptions := IO_TOOLBARSTYLE or CDesigning[csDesigning in Item.ComponentState];
  2646. ItemInfo.Enabled := Item.Enabled or View.Customizing;
  2647. ItemInfo.Pushed := IsPushed;
  2648. ItemInfo.Selected := False;
  2649. ItemInfo.ImageShown := False;
  2650. ItemInfo.ImageWidth := 0;
  2651. ItemInfo.ImageHeight := 0;
  2652. ItemInfo.IsPopupParent := IsPushed;
  2653. if IsHoverItem then
  2654. begin
  2655. if not ItemInfo.Enabled and not TTBViewAccess(View).MouseOverSelected then ItemInfo.HoverKind := hkKeyboardHover
  2656. else if ItemInfo.Enabled then ItemInfo.HoverKind := hkMouseHover;
  2657. end
  2658. else ItemInfo.HoverKind := hkNone;
  2659. ItemInfo.IsVertical := View.Orientation = tbvoVertical;
  2660. CurrentTheme.PaintChevron(Canvas, ClientAreaRect, ItemInfo);
  2661. end;
  2662. //============================================================================//
  2663. { TTBXRootItem }
  2664. function TTBXRootItem.CreatePopupEx(SelectFirstItem: Boolean;
  2665. const AControlRect: TRect; Alignment: TTBPopupAlignment): TTBPopupWindow;
  2666. var
  2667. SavePopupRect: TRect;
  2668. Pt: TPoint;
  2669. begin
  2670. SavePopupRect := FPopupControlRect;
  2671. try
  2672. FPopupControlRect := AControlRect;
  2673. Pt.X := AControlRect.Left;
  2674. Pt.Y := AControlRect.Bottom;
  2675. Result := inherited CreatePopup(nil, nil, False, SelectFirstItem, False, Pt, Alignment);
  2676. if Result is TTBXPopupWindow then TTBXPopupWindow(Result).FControlRect := FPopupControlRect;
  2677. finally
  2678. FPopupControlRect := SavePopupRect;
  2679. end;
  2680. end;
  2681. procedure TTBXRootItem.GetPopupPosition(ParentView: TTBView;
  2682. PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec);
  2683. var
  2684. Y2: Integer;
  2685. VT: Integer;
  2686. begin
  2687. if IsRectEmpty(FPopupControlRect) then inherited
  2688. else with PopupPositionRec do
  2689. begin
  2690. ParentItemRect := FPopupControlRect;
  2691. if Y + H > MonitorRect.Bottom then
  2692. begin
  2693. Y2 := FPopupControlRect.Top - H;
  2694. if Y2 >= MonitorRect.Top then Y := Y2;
  2695. end;
  2696. if Y < MonitorRect.Top then Y := MonitorRect.Top
  2697. else if Y + H > MonitorRect.Bottom then Y := MonitorRect.Bottom - H;
  2698. if Alignment = tbpaRight then X := FPopupControlRect.Right - W;
  2699. if X + W > MonitorRect.Right then X := MonitorRect.Right - W;
  2700. if X < MonitorRect.Left then X := MonitorRect.Left;
  2701. end;
  2702. if CurrentTheme.OfficeXPPopupAlignment then with PopupPositionRec do
  2703. begin
  2704. GetOfficeXPPopupPosition1(PopupPositionRec);
  2705. inherited GetPopupPosition(ParentView, PopupWindow, PopupPositionRec);
  2706. GetOfficeXPPopupPosition2(PopupPositionRec);
  2707. VT := GetWinViewType(PopupWindow);
  2708. PopupPositionRec.PlaySound := not (VT and PVT_LISTBOX = PVT_LISTBOX);
  2709. end
  2710. else inherited;
  2711. end;
  2712. function TTBXRootItem.GetPopupWindowClass: TTBPopupWindowClass;
  2713. begin
  2714. Result := TTBXPopupWindow;
  2715. end;
  2716. function TTBXRootItem.OpenPopupEx(const SelectFirstItem, TrackRightButton: Boolean;
  2717. const ControlRect: TRect; const Alignment: TTBPopupAlignment;
  2718. const ReturnClickedItemOnly: Boolean): TTBCustomItem;
  2719. var
  2720. ModalHandler: TTBModalHandler;
  2721. Popup: TTBPopupWindow;
  2722. DoneActionData: TTBDoneActionData;
  2723. State: TTBViewState;
  2724. {MP}
  2725. I: Integer;
  2726. MinWidth: Integer;
  2727. Border: TPoint;
  2728. begin
  2729. ModalHandler := TTBModalHandler.Create(0);
  2730. try
  2731. {MP BEGIN}
  2732. // Make sure menu is not narrower than its popup control (button)
  2733. if not IsRectEmpty(ControlRect) then
  2734. begin
  2735. // see TTBPopupView.AutoSize and TTBXPopupWindow.GetNCSize
  2736. CurrentTheme.GetViewBorder(PVT_POPUPMENU, Border);
  2737. MinWidth := ControlRect.Width - (2*Border.X);
  2738. for I := 0 to Count - 1 do
  2739. begin
  2740. if Items[I] is TTBXCustomItem then
  2741. if TTBXCustomItem(Items[I]).MinWidth < MinWidth then
  2742. TTBXCustomItem(Items[I]).MinWidth := MinWidth;
  2743. end
  2744. end;
  2745. {MP END}
  2746. Popup := CreatePopupEx(SelectFirstItem, ControlRect, Alignment);
  2747. try
  2748. State := Popup.View.State;
  2749. Include(State, vsIgnoreFirstMouseUp);
  2750. TTBViewAccess(Popup.View).SetState(State);
  2751. ModalHandler.Loop(Popup.View, False, False, False, TrackRightButton);
  2752. DoneActionData := TTBViewAccess(Popup.View).DoneActionData;
  2753. finally
  2754. { Remove vsModal state from the root view before any TTBView.Destroy
  2755. methods get called, so that NotifyFocusEvent becomes a no-op }
  2756. State := Popup.View.State;
  2757. Exclude(State, vsModal);
  2758. TTBViewAccess(Popup.View).SetState(State);
  2759. Popup.Free;
  2760. end;
  2761. finally
  2762. ModalHandler.Free;
  2763. end;
  2764. Result := ProcessDoneAction(DoneActionData, ReturnClickedItemOnly);
  2765. end;
  2766. function TTBXRootItem.PopupEx(const ControlRect: TRect;
  2767. TrackRightButton: Boolean; Alignment: TTBPopupAlignment = tbpaLeft;
  2768. ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
  2769. begin
  2770. Result := OpenPopupEx(False, TrackRightButton, ControlRect,
  2771. Alignment, ReturnClickedItemOnly);
  2772. end;
  2773. //============================================================================//
  2774. { TTBXPopupMenu }
  2775. function TTBXPopupMenu.GetRootItemClass: TTBRootItemClass;
  2776. begin
  2777. Result := TTBXRootItem;
  2778. end;
  2779. function TTBXPopupMenu.PopupEx(const ControlRect: TRect;
  2780. ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
  2781. begin
  2782. {$IFDEF JR_D5}
  2783. {$IFDEF JR_D9}
  2784. SetPopupPoint(Point(ControlRect.Left, ControlRect.Bottom));
  2785. {$ELSE}
  2786. PPoint(@PopupPoint)^ := Point(ControlRect.Left, ControlRect.Bottom);
  2787. {$ENDIF}
  2788. {$ENDIF}
  2789. Result := TTBXRootItem(Items).PopupEx(ControlRect, TrackButton = tbRightButton,
  2790. TTBPopupAlignment(Alignment), ReturnClickedItemOnly);
  2791. end;
  2792. procedure TTBXPopupMenu.TBMGetViewType(var Message: TMessage);
  2793. begin
  2794. Message.Result := PVT_POPUPMENU;
  2795. end;
  2796. //============================================================================//
  2797. { TTBXFloatingWindowParent }
  2798. procedure TTBXFloatingWindowParent.CancelNCHover;
  2799. begin
  2800. if FCloseButtonHover then
  2801. begin
  2802. FCloseButtonHover := False;
  2803. if HandleAllocated and IsWindowVisible(Handle) then
  2804. DrawNCArea(False, 0, 0, [twrdCloseButton]);
  2805. end;
  2806. end;
  2807. procedure TTBXFloatingWindowParent.CMMouseLeave(var Message: TMessage);
  2808. begin
  2809. inherited;
  2810. CancelNCHover;
  2811. end;
  2812. procedure TTBXFloatingWindowParent.DrawNCArea(const DrawToDC: Boolean;
  2813. const ADC: HDC; const Clip: HRGN; RedrawWhat: TTBToolWindowNCRedrawWhat);
  2814. const
  2815. CDown: array [Boolean] of Integer = (0, CDBS_PRESSED);
  2816. CHover: array [Boolean] of Integer = (0, CDBS_HOT);
  2817. CBord: array [Boolean] of Integer = (0, WRP_BORDER);
  2818. CCapt: array [Boolean] of Integer = (0, WRP_CAPTION);
  2819. CBtn: array [Boolean] of Integer = (0, WRP_CLOSEBTN);
  2820. var
  2821. DC: HDC;
  2822. R: TRect;
  2823. Canvas: TCanvas;
  2824. WindowInfo: TTBXWindowInfo;
  2825. DockWindow: TTBCustomDockableWindowAccess;
  2826. begin
  2827. if not HandleAllocated then Exit;
  2828. if not DrawToDC then DC := GetWindowDC(Handle)
  2829. else DC := ADC;
  2830. try
  2831. if not DrawToDC then SelectNCUpdateRgn(Handle, DC, Clip);
  2832. GetWindowRect(Handle, R);
  2833. OffsetRect(R, -R.Left, -R.Top);
  2834. with R do IntersectClipRect(DC, Left, Top, Right, Bottom);
  2835. Canvas := TCanvas.Create;
  2836. try
  2837. Canvas.Handle := DC;
  2838. GetWindowRect(Handle, R);
  2839. OffsetRect(R, -R.Left, -R.Top);
  2840. DockWindow := TTBCustomDockableWindowAccess(DockableWindow);
  2841. FillChar(WindowInfo, SizeOf(WindowInfo), 0);
  2842. WindowInfo.ParentHandle := Handle;
  2843. WindowInfo.WindowHandle := DockWindow.Handle;
  2844. WindowInfo.ViewType := GetWinViewType(DockWindow);
  2845. WindowInfo.ClientWidth := ClientWidth;
  2846. WindowInfo.ClientHeight := ClientHeight;
  2847. WindowInfo.ShowCaption := DockWindow.ShowCaption;
  2848. WindowInfo.FloatingBorderSize := DockWindow.GetFloatingBorderSize;
  2849. if DockWindow.CloseButton and DockWindow.ShowCaption then
  2850. begin
  2851. WindowInfo.CloseButtonState := CDBS_VISIBLE;
  2852. if CloseButtonDown then WindowInfo.CloseButtonState := WindowInfo.CloseButtonState or CDBS_PRESSED
  2853. else if CloseButtonHover then WindowInfo.CloseButtonState := WindowInfo.CloseButtonState or CDBS_HOT;
  2854. end;
  2855. WindowInfo.RedrawPart :=
  2856. CBord[twrdBorder in RedrawWhat] or
  2857. CCapt[twrdCaption in RedrawWhat] or
  2858. CBtn[twrdCloseButton in RedrawWhat];
  2859. WindowInfo.Caption := PChar(Caption);
  2860. WindowInfo.EffectiveColor := GetEffectiveColor(DockWindow);
  2861. WindowInfo.Active := not DockWindow.InactiveCaption;
  2862. Canvas.Brush.Color := WindowInfo.EffectiveColor;
  2863. CurrentTheme.PaintFloatingBorder(Canvas, R, WindowInfo);
  2864. finally
  2865. Canvas.Handle := 0;
  2866. Canvas.Free;
  2867. end;
  2868. finally
  2869. if not DrawToDC then ReleaseDC(Handle, DC);
  2870. end;
  2871. end;
  2872. procedure TTBXFloatingWindowParent.WMEraseBkgnd(var Message: TMessage);
  2873. begin
  2874. Message.Result := 1;
  2875. end;
  2876. procedure TTBXFloatingWindowParent.WMNCMouseLeave(var Message: TMessage);
  2877. begin
  2878. if not MouseCapture then CancelNCHover;
  2879. inherited;
  2880. end;
  2881. procedure TTBXFloatingWindowParent.WMNCMouseMove(var Message: TWMNCMouseMove);
  2882. var
  2883. InArea: Boolean;
  2884. begin
  2885. inherited;
  2886. { Note: TME_NONCLIENT was introduced in Windows 98 and 2000 }
  2887. CallTrackMouseEvent (Handle, TME_LEAVE or $10 {TME_NONCLIENT});
  2888. InArea := Message.HitTest = 2001; {HT_TB2k_Close}
  2889. if FCloseButtonHover <> InArea then
  2890. begin
  2891. FCloseButtonHover := InArea;
  2892. if HandleAllocated and IsWindowVisible(Handle) then
  2893. DrawNCArea(False, 0, 0, [twrdCloseButton]);
  2894. end;
  2895. end;
  2896. procedure TTBXFloatingWindowParent.WMWindowPosChanging(var Message: TWMWindowPosChanging);
  2897. var
  2898. R: TRect;
  2899. MonInfo: TMonitorInfo;
  2900. begin
  2901. if SnapDistance > 0 then with Message.WindowPos^ do
  2902. begin
  2903. if (cx = Width) and (cy = Height) then
  2904. begin
  2905. MonInfo.cbSize := SizeOf(MonInfo);
  2906. GetMonitorInfo(Monitor.Handle, @MonInfo);
  2907. R := MonInfo.rcWork;
  2908. if Abs(x + Width - R.Right) < SnapDistance then x := R.Right - Width;
  2909. if Abs(y + Height - R.Bottom) < SnapDistance then y := R.Bottom - Height;
  2910. if Abs(x - R.Left) < SnapDistance then x := R.Left;
  2911. if Abs(y - R.Top) < SnapDistance then y := R.Top;
  2912. end;
  2913. end;
  2914. inherited;
  2915. end;
  2916. //============================================================================//
  2917. {$IFNDEF MPEXCLUDE}
  2918. { TTBXToolWindow }
  2919. procedure TTBXToolWindow.CMColorChanged(var Message: TMessage);
  2920. begin
  2921. UpdateEffectiveColor;
  2922. if Docked and HandleAllocated then
  2923. RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
  2924. RDW_ERASE or RDW_UPDATENOW or RDW_ALLCHILDREN);
  2925. UpdateChildColors;
  2926. Invalidate;
  2927. end;
  2928. procedure TTBXToolWindow.CMControlChange(var Message: TCMControlChange);
  2929. begin
  2930. inherited;
  2931. if Message.Inserting and (Color = clNone) then
  2932. Message.Control.Perform(CM_PARENTCOLORCHANGED, 1, EffectiveColor);
  2933. end;
  2934. procedure TTBXToolWindow.CMTextChanged(var Message: TMessage);
  2935. begin
  2936. inherited;
  2937. if HandleAllocated then
  2938. begin
  2939. if Docked then RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE)
  2940. else RedrawWindow(TTBXFloatingWindowParent(Parent).Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE);
  2941. end;
  2942. end;
  2943. constructor TTBXToolWindow.Create(AOwner: TComponent);
  2944. begin
  2945. inherited;
  2946. AddThemeNotification(Self);
  2947. DblClickUndock := False;
  2948. FEffectiveColor := Color;
  2949. Color := clNone;
  2950. end;
  2951. destructor TTBXToolWindow.Destroy;
  2952. begin
  2953. RemoveThemeNotification(Self);
  2954. inherited;
  2955. end;
  2956. procedure TTBXToolWindow.DrawNCArea(const DrawToDC: Boolean;
  2957. const ADC: HDC; const Clip: HRGN);
  2958. var
  2959. DC: HDC;
  2960. R, CR, R2: TRect;
  2961. ACanvas: TCanvas;
  2962. ToolbarInfo: TTBXToolbarInfo;
  2963. UsingBackground: Boolean;
  2964. begin
  2965. if not Docked or not HandleAllocated then Exit;
  2966. if not DrawToDC then DC := GetWindowDC(Handle)
  2967. else DC := ADC;
  2968. UsingBackground := TDockAccess(CurrentDock).UsingBackground;
  2969. try
  2970. GetToolbarInfo(ToolbarInfo);
  2971. GetWindowRect(Handle, R);
  2972. OffsetRect(R, -R.Left, -R.Top);
  2973. if not DrawToDC then
  2974. begin
  2975. SelectNCUpdateRgn(Handle, DC, Clip);
  2976. CR := R;
  2977. with ToolbarInfo.BorderSize, CR do
  2978. begin
  2979. InflateRect(CR, -X, -Y);
  2980. if ToolbarInfo.IsVertical then Inc(Top, GetTBXDragHandleSize(ToolbarInfo))
  2981. else Inc(Left, GetTBXDragHandleSize(ToolbarInfo));
  2982. ExcludeClipRect(DC, Left, Top, Right, Bottom);
  2983. end;
  2984. end;
  2985. ACanvas := TCanvas.Create;
  2986. try
  2987. ACanvas.Handle := DC;
  2988. ACanvas.Brush.Color := EffectiveColor;
  2989. if CurrentTheme.SolidToolbarNCArea then
  2990. begin
  2991. ACanvas.Brush.Color := EffectiveColor;
  2992. ACanvas.Brush.Style := bsSolid;
  2993. end
  2994. else if UsingBackground then
  2995. begin
  2996. ACanvas.Brush.Color := EffectiveColor;
  2997. R2 := CurrentDock.ClientRect;
  2998. OffsetRect(R2, -Left, -Top);
  2999. TDockAccess(CurrentDock).DrawBackground(DC, R2);
  3000. {$IFNDEF MPEXCLUDE}
  3001. if (Color = clNone) and CurrentDock.BackgroundOnToolbars then
  3002. ACanvas.Brush.Style := bsClear;
  3003. {$ENDIF}
  3004. end
  3005. else
  3006. begin
  3007. ACanvas.Brush.Color := GetEffectiveColor(CurrentDock);
  3008. ACanvas.FillRect(R);
  3009. ACanvas.Brush.Color := EffectiveColor;
  3010. ACanvas.Brush.Style := bsSolid;
  3011. end;
  3012. CurrentTheme.PaintToolbarNCArea(ACanvas, R, ToolbarInfo);
  3013. finally
  3014. ACanvas.Handle := 0;
  3015. ACanvas.Free;
  3016. end;
  3017. finally
  3018. if not DrawToDC then ReleaseDC(Handle, DC);
  3019. end;
  3020. end;
  3021. function TTBXToolWindow.GetFloatingBorderSize: TPoint;
  3022. begin
  3023. CurrentTheme.GetViewBorder(GetWinViewType(Self) or TVT_FLOATING, Result);
  3024. end;
  3025. function TTBXToolWindow.GetFloatingWindowParentClass: TTBFloatingWindowParentClass;
  3026. begin
  3027. Result := TTBXFloatingWindowParent;
  3028. end;
  3029. procedure TTBXToolWindow.GetToolbarInfo(out ToolbarInfo: TTBXToolbarInfo);
  3030. begin
  3031. FillChar(ToolbarInfo, SizeOf(ToolbarInfo), 0);
  3032. ToolbarInfo.WindowHandle := WindowHandle;
  3033. ToolbarInfo.ViewType := GetWinViewType(Self);
  3034. if CurrentDock <> nil then
  3035. ToolbarInfo.IsVertical := CurrentDock.Position in [dpLeft,dpRight];
  3036. ToolbarInfo.AllowDrag := CurrentDock.AllowDrag;
  3037. ToolbarInfo.DragHandleStyle := Ord(DragHandleStyle);
  3038. ToolbarInfo.ClientWidth := ClientWidth;
  3039. ToolbarInfo.ClientHeight := ClientHeight;
  3040. if ToolbarInfo.AllowDrag and CloseButtonWhenDocked then
  3041. begin
  3042. ToolbarInfo.CloseButtonState := CDBS_VISIBLE;
  3043. if CloseButtonDown then ToolbarInfo.CloseButtonState := ToolbarInfo.CloseButtonState or CDBS_PRESSED;
  3044. if CloseButtonHover then ToolbarInfo.CloseButtonState := ToolbarInfo.CloseButtonState or CDBS_HOT;
  3045. end;
  3046. ToolbarInfo.BorderStyle := BorderStyle;
  3047. ToolbarInfo.EffectiveColor := EffectiveColor;
  3048. CurrentTheme.GetViewBorder(ToolbarInfo.ViewType, ToolbarInfo.BorderSize);
  3049. end;
  3050. procedure TTBXToolWindow.SetParent(AParent: TWinControl);
  3051. begin
  3052. inherited;
  3053. if AParent is TTBXFloatingWindowParent then
  3054. TTBXFloatingWindowParent(AParent).SnapDistance := SnapDistance;
  3055. end;
  3056. procedure TTBXToolWindow.SetSnapDistance(Value: Integer);
  3057. begin
  3058. if Value < 0 then Value := 0;
  3059. FSnapDistance := Value;
  3060. if (Parent <> nil) and (Parent is TTBXFloatingWindowParent) then
  3061. TTBXFloatingWindowParent(Parent).SnapDistance := Value;
  3062. end;
  3063. procedure TTBXToolWindow.TBMGetEffectiveColor(var Message: TMessage);
  3064. begin
  3065. Message.WParam := EffectiveColor;
  3066. Message.Result := 1;
  3067. end;
  3068. procedure TTBXToolWindow.TBMGetViewType(var Message: TMessage);
  3069. begin
  3070. Message.Result := TVT_TOOLWINDOW;
  3071. if Floating then Message.Result := Message.Result or TVT_FLOATING;
  3072. if Resizable then Message.Result := Message.Result or TVT_RESIZABLE;
  3073. end;
  3074. procedure TTBXToolWindow.TBMThemeChange(var Message: TMessage);
  3075. begin
  3076. case Message.WParam of
  3077. TSC_BEFOREVIEWCHANGE: BeginUpdate;
  3078. TSC_AFTERVIEWCHANGE:
  3079. begin
  3080. EndUpdate;
  3081. UpdateEffectiveColor;
  3082. if HandleAllocated and not (csDestroying in ComponentState) then
  3083. if Parent is TTBXFloatingWindowParent then
  3084. UpdateNCArea(TTBXFloatingWindowParent(Parent), GetWinViewType(Self))
  3085. else
  3086. UpdateNCArea(Self, GetWinViewType(Self));
  3087. UpdateChildColors;
  3088. Invalidate;
  3089. end;
  3090. end;
  3091. end;
  3092. procedure TTBXToolWindow.UpdateChildColors;
  3093. var
  3094. M: TMessage;
  3095. begin
  3096. M.Msg := CM_PARENTCOLORCHANGED;
  3097. M.WParam := 1;
  3098. M.LParam := EffectiveColor;
  3099. M.Result := 0;
  3100. Broadcast(M);
  3101. end;
  3102. procedure TTBXToolWindow.UpdateEffectiveColor;
  3103. begin
  3104. if Color = clNone then FEffectiveColor := CurrentTheme.GetViewColor(GetWinViewType(Self))
  3105. else FEffectiveColor := Color;
  3106. end;
  3107. procedure TTBXToolWindow.WMEraseBkgnd(var Message: TWmEraseBkgnd);
  3108. var
  3109. Canvas: TCanvas;
  3110. R, CR: TRect;
  3111. Transparent: Boolean;
  3112. begin
  3113. Transparent := False;
  3114. CR := ClientRect;
  3115. {$IFNDEF MPEXCLUDE}
  3116. if Color = clNone then
  3117. if Docked and (TDockAccess(CurrentDock).UsingBackground) and CurrentDock.BackgroundOnToolbars
  3118. and not CurrentTheme.SolidToolbarClientArea then
  3119. begin
  3120. R := CurrentDock.ClientRect;
  3121. R.TopLeft := ScreenToClient(CurrentDock.ClientToScreen(R.TopLeft));
  3122. R.BottomRight := ScreenToClient(CurrentDock.ClientToScreen(R.BottomRight));
  3123. SaveDC(Message.DC);
  3124. with CR do IntersectClipRect(Message.DC, Left, Top, Right, Bottom);
  3125. TDockAccess(CurrentDock).DrawBackground(Message.DC, R);
  3126. RestoreDC(Message.DC, -1);
  3127. Message.Result := 1;
  3128. Transparent := True;
  3129. end;
  3130. {$ENDIF}
  3131. Canvas := TCanvas.Create;
  3132. Canvas.Handle := Message.DC;
  3133. try
  3134. if Docked then
  3135. begin
  3136. R := CurrentDock.ClientRect;
  3137. R.TopLeft := ScreenToClient(CurrentDock.ClientToScreen(R.TopLeft));
  3138. R.BottomRight := ScreenToClient(CurrentDock.ClientToScreen(R.BottomRight));
  3139. end
  3140. else R := Rect(0, 0, 0, 0);
  3141. CurrentTheme.PaintBackgnd(Canvas, R, CR, CR, EffectiveColor, Transparent, GetWinViewType(Self));
  3142. Message.Result := 1;
  3143. finally
  3144. Canvas.Handle := 0;
  3145. Canvas.Free;
  3146. end;
  3147. end;
  3148. {$ENDIF}
  3149. //============================================================================//
  3150. { Additional system colors }
  3151. type
  3152. TColorEntry = packed record
  3153. ColorPtr: ^TColor;
  3154. Name: string;
  3155. end;
  3156. var
  3157. ColorRegistry: array of TColorEntry;
  3158. procedure AddTBXColor(var AColor: TColor; const AName: string);
  3159. var
  3160. L: Integer;
  3161. begin
  3162. L := Length(ColorRegistry);
  3163. SetLength(ColorRegistry, L + 1);
  3164. with ColorRegistry[L] do
  3165. begin
  3166. ColorPtr := @AColor;
  3167. Name := AName;
  3168. end;
  3169. end;
  3170. function TBXColorToString(Color: TColor): string;
  3171. var
  3172. I: Integer;
  3173. begin
  3174. if not ColorToIdent(Color, Result) then
  3175. begin
  3176. for I := 0 to Length(ColorRegistry) - 1 do
  3177. if ColorRegistry[I].ColorPtr^ = Color then
  3178. begin
  3179. Result := ColorRegistry[I].Name;
  3180. Exit;
  3181. end;
  3182. FmtStr(Result, '%s%.8x', [HexDisplayPrefix, Color]);
  3183. end;
  3184. end;
  3185. function TBXIdentToColor(const Ident: string; var Color: Longint): Boolean;
  3186. var
  3187. I: Integer;
  3188. begin
  3189. for I := 0 to Length(ColorRegistry) - 1 do
  3190. if CompareText(ColorRegistry[I].Name, Ident) = 0 then
  3191. begin
  3192. Color := ColorRegistry[I].ColorPtr^;
  3193. Result := True;
  3194. Exit;
  3195. end;
  3196. Result := IdentToColor(Ident, Color);
  3197. end;
  3198. function TBXStringToColor(S: string): TColor;
  3199. begin
  3200. if not TBXIdentToColor(S, Longint(Result)) then Result := StringToColor(S);
  3201. end;
  3202. procedure TBXGetColorValues(Proc: TGetStrProc);
  3203. var
  3204. I: Integer;
  3205. begin
  3206. GetColorValues(Proc);
  3207. for I := 0 to Length(ColorRegistry) - 1 do Proc(ColorRegistry[I].Name);
  3208. end;
  3209. procedure TBXSetTheme(const AThemeName: string);
  3210. begin
  3211. TBXNexus.SetTheme(AThemeName);
  3212. end;
  3213. function TBXCurrentTheme: string;
  3214. begin
  3215. Result := TBXNexus.GetTheme;
  3216. end;
  3217. //============================================================================//
  3218. { TTBXNexus }
  3219. procedure TTBXNexus.AddNotifie(AObject: TObject);
  3220. begin
  3221. if FNotifies.IndexOf(AObject) < 0 then FNotifies.Add(AObject);
  3222. Exit; asm db 0,'TBX (C) 2001-2003 Alex Denisov',0 end;
  3223. end;
  3224. procedure TTBXNexus.Broadcast(Msg: Cardinal; WParam, LParam: Integer);
  3225. var
  3226. M: TMessage;
  3227. I: Integer;
  3228. begin
  3229. if FNotifies.Count > 0 then
  3230. begin
  3231. M.Msg := Msg;
  3232. M.WParam := WParam;
  3233. M.LParam := LParam;
  3234. M.Result := 0;
  3235. for I := 0 to FNotifies.Count - 1 do TObject(FNotifies[I]).Dispatch(M);
  3236. end;
  3237. end;
  3238. constructor TTBXNexus.Create(const DefaultTheme: string);
  3239. begin
  3240. FNotifies := TList.Create;
  3241. CurrentTheme := GetTBXTheme(DefaultTheme);
  3242. AddTBXSysChangeNotification(Self);
  3243. end;
  3244. destructor TTBXNexus.Destroy;
  3245. begin
  3246. RemoveTBXSysChangeNotification(Self);
  3247. ReleaseTBXTheme(CurrentTheme);
  3248. FNotifies.Free;
  3249. inherited;
  3250. end;
  3251. function TTBXNexus.GetTheme: string;
  3252. begin
  3253. Result := CurrentTheme.Name;
  3254. end;
  3255. procedure TTBXNexus.RemoveNotifie(AObject: TObject);
  3256. begin
  3257. FNotifies.Remove(AObject);
  3258. end;
  3259. procedure TTBXNexus.SetTheme(const AThemeName: string);
  3260. begin
  3261. if IsTBXThemeAvailable(AThemeName) then
  3262. begin
  3263. ReleaseTBXTheme(CurrentTheme);
  3264. CurrentTheme := GetTBXTheme(AThemeName);
  3265. Broadcast(TBM_THEMECHANGE, TSC_BEFOREVIEWCHANGE, 1);
  3266. Broadcast(TBM_THEMECHANGE, TSC_VIEWCHANGE, 1);
  3267. Broadcast(TBM_THEMECHANGE, TSC_AFTERVIEWCHANGE, 1);
  3268. end;
  3269. end;
  3270. procedure TTBXNexus.TBXSysCommand(var Message: TMessage);
  3271. begin
  3272. { Retranslate TBX_SYSCOMMAND to TBM_THEMECHANGE }
  3273. if Message.Msg = TBX_SYSCOMMAND then
  3274. Broadcast(TBM_THEMECHANGE, Message.WParam, 0);
  3275. end;
  3276. procedure InitAdditionalSysColors;
  3277. begin
  3278. {$IFNDEF JR_D7} {vb+}
  3279. AddTBXColor(clHotLight, 'clHotLight');
  3280. {$ENDIF} {vb+}
  3281. {$IFNDEF JR_D6}
  3282. AddTBXColor(clMoneyGreen, 'clMoneyGreen');
  3283. AddTBXColor(clSkyBlue, 'clSkyBlue');
  3284. AddTBXColor(clCream, 'clCream');
  3285. AddTBXColor(clMedGray, 'clMedGray');
  3286. {$ENDIF}
  3287. end;
  3288. { TTBXDock }
  3289. procedure TTBXDock.CMColorChanged(var Message: TMessage);
  3290. var
  3291. I: Integer;
  3292. begin
  3293. inherited;
  3294. for I := 0 to Self.ControlCount - 1 do
  3295. if Controls[I] is TWinControl then
  3296. InvalidateAll(TWinControl(Controls[I]));
  3297. end;
  3298. constructor TTBXDock.Create(AOwner: TComponent);
  3299. begin
  3300. inherited;
  3301. Color := clNone;
  3302. AddThemeNotification(Self);
  3303. end;
  3304. destructor TTBXDock.Destroy;
  3305. begin
  3306. RemoveThemeNotification(Self);
  3307. inherited;
  3308. end;
  3309. procedure TTBXDock.DrawBackground(DC: HDC; const DrawRect: TRect);
  3310. const
  3311. DOCK_POSITIONS: array [TTBDockPosition] of Integer = (DP_TOP, DP_BOTTOM, DP_LEFT, DP_RIGHT);
  3312. var
  3313. Canvas: TCanvas;
  3314. begin
  3315. if UseParentBackground then DrawParentBackground(Self, DC, ClientRect)
  3316. else if ThemedBackground then
  3317. begin
  3318. Canvas := TCanvas.Create;
  3319. Canvas.Handle := DC;
  3320. CurrentTheme.PaintDock(Canvas, ClientRect, DrawRect, DOCK_POSITIONS[Position]);
  3321. Canvas.Handle := 0;
  3322. Canvas.Free;
  3323. end
  3324. else inherited;
  3325. end;
  3326. procedure TTBXDock.Resize;
  3327. var
  3328. I, J: Integer;
  3329. V: TTBItemViewer;
  3330. R: TRect;
  3331. begin
  3332. inherited Resize;
  3333. if UsingBackground then
  3334. begin
  3335. for J := 0 to ToolbarCount - 1 do
  3336. begin
  3337. Invalidate;
  3338. if Toolbars[J] is TTBXToolbar then with TTBXToolbar(Toolbars[J]) do
  3339. begin
  3340. for I := 0 to View.ViewerCount - 1 do
  3341. begin
  3342. V := View.Viewers[I];
  3343. if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
  3344. then View.Invalidate(V);
  3345. end;
  3346. Update;
  3347. if HandleAllocated then
  3348. RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or RDW_ERASE);
  3349. for I := 0 to View.ViewerCount - 1 do
  3350. begin
  3351. V := View.Viewers[I];
  3352. if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
  3353. then
  3354. begin
  3355. R := V.BoundsRect;
  3356. ValidateRect(Handle, @R);
  3357. end;
  3358. end;
  3359. end
  3360. {$IFNDEF MPEXCLUDE}
  3361. else if Toolbars[J] is TTBXToolWindow then with TTBXToolWindow(Toolbars[J]) do
  3362. begin
  3363. if HandleAllocated then
  3364. RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or RDW_ERASE);
  3365. end;
  3366. {$ENDIF}
  3367. end;
  3368. end;
  3369. end;
  3370. procedure TTBXDock.SetUseParentBackground(Value: Boolean);
  3371. begin
  3372. if Value <> FUseParentBackground then
  3373. begin
  3374. FUseParentBackground := Value;
  3375. if HandleAllocated then
  3376. RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
  3377. RDW_ERASE or RDW_ALLCHILDREN);
  3378. end;
  3379. end;
  3380. procedure TTBXDock.TBMGetEffectiveColor(var Message: TMessage);
  3381. begin
  3382. if Color <> clNone then Message.WParam := Color
  3383. else if Parent <> nil then Message.WParam := GetEffectiveColor(Parent)
  3384. else Message.WParam := WPARAM(clBtnFace);
  3385. Message.Result := 1;
  3386. end;
  3387. procedure TTBXDock.TBMThemeChange(var Message: TMessage);
  3388. begin
  3389. case Message.WParam of
  3390. TSC_AFTERVIEWCHANGE:
  3391. begin
  3392. Invalidate;
  3393. end;
  3394. end;
  3395. end;
  3396. function TTBXDock.ThemedBackground: Boolean;
  3397. begin
  3398. Result := {$IFNDEF MPEXCLUDE}(Background = nil) and{$ENDIF} (Color = clNone) and CurrentTheme.PaintDockBackground;
  3399. end;
  3400. function TTBXDock.UsingBackground: Boolean;
  3401. begin
  3402. Result := UseParentBackground or (ThemedBackground and not FMoving) or
  3403. inherited UsingBackground;
  3404. end;
  3405. procedure TTBXDock.WMEraseBkgnd(var Message: TWMEraseBkgnd);
  3406. var
  3407. R: TRect;
  3408. C: TColor;
  3409. begin
  3410. R := Self.ClientRect;
  3411. if UsingBackground then
  3412. begin
  3413. DrawBackground(Message.DC, R);
  3414. Message.Result := 1;
  3415. end
  3416. else
  3417. begin
  3418. C := Color;
  3419. if C = clNone then C := GetEffectiveColor(Parent);
  3420. FillRectEx(Message.DC, R, C);
  3421. Message.Result := 1;
  3422. end;
  3423. end;
  3424. procedure TTBXDock.WMMove(var Message: TWMMove);
  3425. begin
  3426. FMoving := True;
  3427. inherited;
  3428. FMoving := False;
  3429. end;
  3430. procedure TTBXDock.WMSize(var Message: TWMSize);
  3431. begin
  3432. FResizing := True;
  3433. inherited;
  3434. FResizing := False;
  3435. end;
  3436. { TTBXMenuAnimation } {vb+}
  3437. constructor TTBXMenuAnimation.Create(AAnimationMode: TAnimationMode = amSysDefault);
  3438. begin
  3439. AnimationMode := AAnimationMode;
  3440. end;
  3441. function TTBXMenuAnimation.GetAvailableModes: TAnimationModes;
  3442. begin
  3443. Result := [amNone, amSysDefault, amRandom, amUnfold, amSlide, amFade];
  3444. end;
  3445. function TTBXMenuAnimation.GetMenuAnimation: TMenuAnimation;
  3446. function GetSysDefault: TMenuAnimation;
  3447. const
  3448. SPI_GETMENUFADE = $1012;
  3449. SysDefAni: array[Boolean] of TMenuAnimation = (maSlide, maFade);
  3450. begin
  3451. if SysParamEnabled(SPI_GETMENUANIMATION)
  3452. then Result := SysDefAni[SysParamEnabled(SPI_GETMENUFADE)]
  3453. else Result := maNone;
  3454. end;
  3455. function GetRandom: TMenuAnimation;
  3456. var Max: Integer;
  3457. begin
  3458. Max := Ord(High(TMenuAnimation));
  3459. if not (amFade in AvailableModes) then
  3460. Dec(Max);
  3461. Result := Succ(TMenuAnimation(Random(Max)));
  3462. end;
  3463. begin
  3464. case AnimationMode of
  3465. amSysDefault: Result := GetSysDefault;
  3466. amRandom: Result := GetRandom;
  3467. amUnfold: Result := maUnfold;
  3468. amSlide: Result := maSlide;
  3469. amFade: Result := maFade;
  3470. else
  3471. Result := maNone;
  3472. end;
  3473. end;
  3474. procedure TTBXMenuAnimation.SetAnimationMode(Value: TAnimationMode);
  3475. var AvailModes: TAnimationModes;
  3476. begin
  3477. AvailModes := AvailableModes;
  3478. while not (Value in AvailModes) do
  3479. Value := Pred(Value);
  3480. FAnimationMode := Value;
  3481. end;
  3482. function TTBXMenuAnimation.SysParamEnabled(Param: Cardinal): Boolean;
  3483. var B: BOOL;
  3484. begin
  3485. Result := SystemParametersInfo(Param, 0, @B, 0) and B;
  3486. end;
  3487. { Work around delayed menu showing in Windows 2000+ } {vb+}
  3488. var
  3489. FixPlaySoundThreadHandle: Cardinal;
  3490. function FixPlaySoundThreadFunc(Param: Pointer): Integer; stdcall;
  3491. begin
  3492. Sleep(250);
  3493. PlaySound(nil, 0, 0);
  3494. CloseHandle(FixPlaySoundThreadHandle); { Harakiri :~| }
  3495. Result := $4E494150; { :) }
  3496. end;
  3497. procedure FixPlaySoundDelay;
  3498. var ThreadId: TThreadID;
  3499. begin
  3500. if (FixPlaySoundThreadHandle = 0) then
  3501. FixPlaySoundThreadHandle := CreateThread(nil, $1000,
  3502. @FixPlaySoundThreadFunc, nil, 0, ThreadId);
  3503. end;
  3504. function CreateTBXPopupMenu(Owner: TComponent): TTBXPopupMenu;
  3505. begin
  3506. Result := TTBXPopupMenu.Create(Owner);
  3507. end;
  3508. initialization
  3509. FixPlaySoundDelay; {vb+}
  3510. {CurrentTheme := nil;} {vb-}
  3511. RegisterTBXTheme('OfficeXP', TTBXOfficeXPTheme);
  3512. TBXNexus := TTBXNexus.Create('OfficeXP');
  3513. TBXMenuAnimation := TTBXMenuAnimation.Create; {vb+}
  3514. {$IFNDEF JR_D7} {vb+}
  3515. InitAdditionalSysColors;
  3516. {$ENDIF} {vb+}
  3517. finalization
  3518. TBXNexus.Free;
  3519. FreeAndNil(TBXMenuAnimation); {vb+}
  3520. ColorRegistry := nil;
  3521. end.