TBX.pas 119 KB

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