TBX.pas 105 KB

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