TBX.pas 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476
  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. TTBXFloatingWindowParent(AParent).SnapDistance := SnapDistance;
  2369. end;
  2370. procedure TTBXToolbar.SetSnapDistance(Value: Integer);
  2371. begin
  2372. if Value < 0 then Value := 0;
  2373. FSnapDistance := Value;
  2374. if (Parent <> nil) and (Parent is TTBXFloatingWindowParent) then
  2375. TTBXFloatingWindowParent(Parent).SnapDistance := Value;
  2376. end;
  2377. procedure TTBXToolbar.TBMGetEffectiveColor(var Message: TMessage);
  2378. begin
  2379. Message.WParam := EffectiveColor;
  2380. Message.Result := 1;
  2381. end;
  2382. procedure TTBXToolbar.TBMGetViewType(var Message: TMessage);
  2383. begin
  2384. if MenuBar then Message.Result := TVT_MENUBAR
  2385. else Message.Result := TVT_NORMALTOOLBAR;
  2386. if Floating then Message.Result := Message.Result or TVT_FLOATING;
  2387. if Resizable then Message.Result := Message.Result or TVT_RESIZABLE;
  2388. case ItemTransparency of
  2389. itAuto:
  2390. if not (Floating or Docked) then Message.Result := Message.Result or TVT_EMBEDDED;
  2391. itDisable:
  2392. Message.Result := Message.Result or TVT_EMBEDDED;
  2393. end;
  2394. end;
  2395. procedure TTBXToolbar.Rebuild;
  2396. begin
  2397. if Floating then UpdateNCArea(TTBXFloatingWindowParent(Parent), GetWinViewType(Self))
  2398. else UpdateNCArea(Self, GetWinViewType(Self));
  2399. Invalidate;
  2400. Arrange;
  2401. end;
  2402. procedure TTBXToolbar.TBMThemeChange(var Message: TMessage);
  2403. begin
  2404. case Message.WParam of
  2405. TSC_BEFOREVIEWCHANGE: BeginUpdate;
  2406. TSC_AFTERVIEWCHANGE:
  2407. begin
  2408. EndUpdate;
  2409. UpdateEffectiveColor;
  2410. Rebuild;
  2411. UpdateChildColors;
  2412. end;
  2413. TSC_APPACTIVATE, TSC_APPDEACTIVATE:
  2414. if MenuBar then Invalidate;
  2415. end;
  2416. end;
  2417. procedure TTBXToolbar.WMDpiChangedBeforeParent(var Message: TMessage);
  2418. begin
  2419. BeginUpdate;
  2420. end;
  2421. procedure TTBXToolbar.WMDpiChangedAfterParent(var Message: TMessage);
  2422. begin
  2423. EndUpdate;
  2424. Rebuild;
  2425. end;
  2426. procedure TTBXToolbar.UpdateChildColors;
  2427. var
  2428. M: TMessage;
  2429. begin
  2430. M.Msg := CM_PARENTCOLORCHANGED;
  2431. M.WParam := 1;
  2432. M.LParam := EffectiveColor;
  2433. M.Result := 0;
  2434. Broadcast(M);
  2435. end;
  2436. procedure TTBXToolbar.UpdateEffectiveColor;
  2437. begin
  2438. if Color = clNone then
  2439. begin
  2440. if Embedded and (Parent <> nil) then
  2441. FEffectiveColor := GetEffectiveColor(Parent)
  2442. else
  2443. FEffectiveColor := CurrentTheme.GetViewColor(GetViewType(View));
  2444. end
  2445. else FEffectiveColor := Color;
  2446. end;
  2447. procedure TTBXToolbar.WMEraseBkgnd(var Message: TWmEraseBkgnd);
  2448. var
  2449. Canvas: TCanvas;
  2450. R, CR: TRect;
  2451. Transparent: Boolean;
  2452. begin
  2453. Transparent := False;
  2454. CR := ClientRect;
  2455. if Color = clNone then
  2456. if Embedded then
  2457. begin
  2458. Transparent := True;
  2459. DrawParentBackground(Self, Message.DC, CR);
  2460. end;
  2461. Canvas := TCanvas.Create;
  2462. Canvas.Handle := Message.DC;
  2463. try
  2464. if Docked then
  2465. begin
  2466. R := CurrentDock.ClientRect;
  2467. R.TopLeft := ScreenToClient(CurrentDock.ClientToScreen(R.TopLeft));
  2468. R.BottomRight := ScreenToClient(CurrentDock.ClientToScreen(R.BottomRight));
  2469. end
  2470. else R := Rect(0, 0, 0, 0);
  2471. CurrentTheme.PaintBackgnd(Canvas, R, CR, CR, EffectiveColor, Transparent, GetWinViewType(Self));
  2472. Message.Result := 1;
  2473. finally
  2474. Canvas.Handle := 0;
  2475. Canvas.Free;
  2476. end;
  2477. end;
  2478. //============================================================================//
  2479. { TTBXChevronItem }
  2480. function TTBXChevronItem.GetItemViewerClass(AView: TTBView): TTBItemViewerClass;
  2481. begin
  2482. Result := TTBXChevronItemViewer;
  2483. end;
  2484. procedure TTBXChevronItem.GetPopupPosition(ParentView: TTBView;
  2485. PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec);
  2486. begin
  2487. if CurrentTheme.OfficeXPPopupAlignment then with PopupPositionRec do
  2488. begin
  2489. GetOfficeXPPopupPosition1(PopupPositionRec);
  2490. inherited GetPopupPosition(ParentView, PopupWindow, PopupPositionRec);
  2491. GetOfficeXPPopupPosition2(PopupPositionRec);
  2492. end
  2493. else inherited;
  2494. end;
  2495. function TTBXChevronItem.GetPopupWindowClass: TTBPopupWindowClass;
  2496. begin
  2497. Result := TTBXChevronPopupWindow;
  2498. end;
  2499. //============================================================================//
  2500. { TTBXChevronItemViewer }
  2501. procedure TTBXChevronItemViewer.Paint(const Canvas: TCanvas;
  2502. const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean);
  2503. const
  2504. CDesigning: array [Boolean] of Integer = (0, IO_DESIGNING);
  2505. var
  2506. ItemInfo: TTBXItemInfo;
  2507. begin
  2508. FillChar(ItemInfo, SizeOf(TTBXItemInfo), 0);
  2509. ItemInfo.ViewType := GetViewType(View);
  2510. ItemInfo.ItemOptions := IO_TOOLBARSTYLE or CDesigning[csDesigning in Item.ComponentState];
  2511. ItemInfo.Enabled := Item.Enabled or View.Customizing;
  2512. ItemInfo.Pushed := IsPushed;
  2513. ItemInfo.Selected := False;
  2514. ItemInfo.ImageShown := False;
  2515. ItemInfo.ImageWidth := 0;
  2516. ItemInfo.ImageHeight := 0;
  2517. ItemInfo.IsPopupParent := IsPushed;
  2518. if IsHoverItem then
  2519. begin
  2520. if not ItemInfo.Enabled and not TTBViewAccess(View).MouseOverSelected then ItemInfo.HoverKind := hkKeyboardHover
  2521. else if ItemInfo.Enabled then ItemInfo.HoverKind := hkMouseHover;
  2522. end
  2523. else ItemInfo.HoverKind := hkNone;
  2524. ItemInfo.IsVertical := View.Orientation = tbvoVertical;
  2525. CurrentTheme.PaintChevron(Canvas, ClientAreaRect, ItemInfo);
  2526. end;
  2527. function TTBXChevronItemViewer.CaptionShown: Boolean;
  2528. begin
  2529. Result := False;
  2530. end;
  2531. //============================================================================//
  2532. { TTBXRootItem }
  2533. function TTBXRootItem.CreatePopupEx(SelectFirstItem: Boolean;
  2534. const AControlRect: TRect; Alignment: TTBPopupAlignment): TTBPopupWindow;
  2535. var
  2536. SavePopupRect: TRect;
  2537. Pt: TPoint;
  2538. begin
  2539. SavePopupRect := FPopupControlRect;
  2540. try
  2541. FPopupControlRect := AControlRect;
  2542. Pt.X := AControlRect.Left;
  2543. Pt.Y := AControlRect.Bottom;
  2544. Result := inherited CreatePopup(nil, nil, False, SelectFirstItem, False, Pt, Alignment);
  2545. if Result is TTBXPopupWindow then TTBXPopupWindow(Result).FControlRect := FPopupControlRect;
  2546. finally
  2547. FPopupControlRect := SavePopupRect;
  2548. end;
  2549. end;
  2550. procedure TTBXRootItem.GetPopupPosition(ParentView: TTBView;
  2551. PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec);
  2552. var
  2553. Y2: Integer;
  2554. VT: Integer;
  2555. begin
  2556. if IsRectEmpty(FPopupControlRect) then inherited
  2557. else with PopupPositionRec do
  2558. begin
  2559. ParentItemRect := FPopupControlRect;
  2560. if Y + H > MonitorRect.Bottom then
  2561. begin
  2562. Y2 := FPopupControlRect.Top - H;
  2563. if Y2 >= MonitorRect.Top then Y := Y2;
  2564. end;
  2565. if Y < MonitorRect.Top then Y := MonitorRect.Top
  2566. else if Y + H > MonitorRect.Bottom then Y := MonitorRect.Bottom - H;
  2567. if Alignment = tbpaRight then X := FPopupControlRect.Right - W;
  2568. if X + W > MonitorRect.Right then X := MonitorRect.Right - W;
  2569. if X < MonitorRect.Left then X := MonitorRect.Left;
  2570. end;
  2571. if CurrentTheme.OfficeXPPopupAlignment then with PopupPositionRec do
  2572. begin
  2573. GetOfficeXPPopupPosition1(PopupPositionRec);
  2574. inherited GetPopupPosition(ParentView, PopupWindow, PopupPositionRec);
  2575. GetOfficeXPPopupPosition2(PopupPositionRec);
  2576. VT := GetWinViewType(PopupWindow);
  2577. PopupPositionRec.PlaySound := not (VT and PVT_LISTBOX = PVT_LISTBOX);
  2578. end
  2579. else inherited;
  2580. end;
  2581. function TTBXRootItem.GetPopupWindowClass: TTBPopupWindowClass;
  2582. begin
  2583. Result := TTBXPopupWindow;
  2584. end;
  2585. function TTBXRootItem.OpenPopupEx(const SelectFirstItem, TrackRightButton: Boolean;
  2586. const ControlRect: TRect; const Alignment: TTBPopupAlignment;
  2587. const ReturnClickedItemOnly: Boolean): TTBCustomItem;
  2588. var
  2589. ModalHandler: TTBModalHandler;
  2590. Popup: TTBPopupWindow;
  2591. DoneActionData: TTBDoneActionData;
  2592. State: TTBViewState;
  2593. {MP}
  2594. I: Integer;
  2595. MinWidth: Integer;
  2596. Border: TPoint;
  2597. Control: TControl;
  2598. begin
  2599. ModalHandler := TTBModalHandler.Create(0);
  2600. try
  2601. {MP BEGIN}
  2602. // Make sure menu is not narrower than its popup control (button)
  2603. if not IsRectEmpty(ControlRect) then
  2604. begin
  2605. // see TTBPopupView.AutoSize and TTBXPopupWindow.GetNCSize
  2606. Control := FindVCLWindow(Point(ControlRect.Left, ControlRect.Top));
  2607. CurrentTheme.GetViewBorder(Control, PVT_POPUPMENU, Border);
  2608. MinWidth := ControlRect.Width - (2*Border.X);
  2609. for I := 0 to Count - 1 do
  2610. begin
  2611. if Items[I] is TTBXCustomItem then
  2612. if TTBXCustomItem(Items[I]).MinWidth < MinWidth then
  2613. TTBXCustomItem(Items[I]).MinWidth := MinWidth;
  2614. end
  2615. end;
  2616. {MP END}
  2617. Popup := CreatePopupEx(SelectFirstItem, ControlRect, Alignment);
  2618. try
  2619. State := Popup.View.State;
  2620. Include(State, vsIgnoreFirstMouseUp);
  2621. TTBViewAccess(Popup.View).SetState(State);
  2622. ModalHandler.Loop(Popup.View, False, False, False, TrackRightButton);
  2623. DoneActionData := TTBViewAccess(Popup.View).DoneActionData;
  2624. finally
  2625. { Remove vsModal state from the root view before any TTBView.Destroy
  2626. methods get called, so that NotifyFocusEvent becomes a no-op }
  2627. State := Popup.View.State;
  2628. Exclude(State, vsModal);
  2629. TTBViewAccess(Popup.View).SetState(State);
  2630. Popup.Free;
  2631. end;
  2632. finally
  2633. ModalHandler.Free;
  2634. end;
  2635. Result := ProcessDoneAction(DoneActionData, ReturnClickedItemOnly);
  2636. end;
  2637. function TTBXRootItem.PopupEx(const ControlRect: TRect;
  2638. TrackRightButton: Boolean; Alignment: TTBPopupAlignment = tbpaLeft;
  2639. ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
  2640. begin
  2641. Result := OpenPopupEx(False, TrackRightButton, ControlRect,
  2642. Alignment, ReturnClickedItemOnly);
  2643. end;
  2644. //============================================================================//
  2645. { TTBXPopupMenu }
  2646. function TTBXPopupMenu.GetRootItemClass: TTBRootItemClass;
  2647. begin
  2648. Result := TTBXRootItem;
  2649. end;
  2650. function TTBXPopupMenu.PopupEx(const ControlRect: TRect;
  2651. ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
  2652. begin
  2653. SetPopupPoint(Point(ControlRect.Left, ControlRect.Bottom));
  2654. Result := TTBXRootItem(Items).PopupEx(ControlRect, TrackButton = tbRightButton,
  2655. TTBPopupAlignment(Alignment), ReturnClickedItemOnly);
  2656. end;
  2657. procedure TTBXPopupMenu.TBMGetViewType(var Message: TMessage);
  2658. begin
  2659. Message.Result := PVT_POPUPMENU;
  2660. end;
  2661. //============================================================================//
  2662. { TTBXFloatingWindowParent }
  2663. procedure TTBXFloatingWindowParent.CancelNCHover;
  2664. begin
  2665. if FCloseButtonHover then
  2666. begin
  2667. FCloseButtonHover := False;
  2668. if HandleAllocated and IsWindowVisible(Handle) then
  2669. DrawNCArea(False, 0, 0, [twrdCloseButton]);
  2670. end;
  2671. end;
  2672. procedure TTBXFloatingWindowParent.CMMouseLeave(var Message: TMessage);
  2673. begin
  2674. inherited;
  2675. CancelNCHover;
  2676. end;
  2677. procedure TTBXFloatingWindowParent.DrawNCArea(const DrawToDC: Boolean;
  2678. const ADC: HDC; const Clip: HRGN; RedrawWhat: TTBToolWindowNCRedrawWhat);
  2679. const
  2680. CDown: array [Boolean] of Integer = (0, CDBS_PRESSED);
  2681. CHover: array [Boolean] of Integer = (0, CDBS_HOT);
  2682. CBord: array [Boolean] of Integer = (0, WRP_BORDER);
  2683. CCapt: array [Boolean] of Integer = (0, WRP_CAPTION);
  2684. CBtn: array [Boolean] of Integer = (0, WRP_CLOSEBTN);
  2685. var
  2686. DC: HDC;
  2687. R: TRect;
  2688. Canvas: TCanvas;
  2689. WindowInfo: TTBXWindowInfo;
  2690. DockWindow: TTBCustomDockableWindowAccess;
  2691. begin
  2692. if not HandleAllocated then Exit;
  2693. if not DrawToDC then DC := GetWindowDC(Handle)
  2694. else DC := ADC;
  2695. try
  2696. if not DrawToDC then SelectNCUpdateRgn(Handle, DC, Clip);
  2697. GetWindowRect(Handle, R);
  2698. OffsetRect(R, -R.Left, -R.Top);
  2699. with R do IntersectClipRect(DC, Left, Top, Right, Bottom);
  2700. Canvas := TCanvas.Create;
  2701. try
  2702. Canvas.Handle := DC;
  2703. GetWindowRect(Handle, R);
  2704. OffsetRect(R, -R.Left, -R.Top);
  2705. DockWindow := TTBCustomDockableWindowAccess(DockableWindow);
  2706. FillChar(WindowInfo, SizeOf(WindowInfo), 0);
  2707. WindowInfo.ParentControl := Self;
  2708. WindowInfo.ParentHandle := Handle;
  2709. WindowInfo.WindowHandle := DockWindow.Handle;
  2710. WindowInfo.ViewType := GetWinViewType(DockWindow);
  2711. WindowInfo.ClientWidth := ClientWidth;
  2712. WindowInfo.ClientHeight := ClientHeight;
  2713. WindowInfo.ShowCaption := DockWindow.ShowCaption;
  2714. WindowInfo.FloatingBorderSize := DockWindow.GetFloatingBorderSize;
  2715. if DockWindow.CloseButton and DockWindow.ShowCaption then
  2716. begin
  2717. WindowInfo.CloseButtonState := CDBS_VISIBLE;
  2718. if CloseButtonDown then WindowInfo.CloseButtonState := WindowInfo.CloseButtonState or CDBS_PRESSED
  2719. else if CloseButtonHover then WindowInfo.CloseButtonState := WindowInfo.CloseButtonState or CDBS_HOT;
  2720. end;
  2721. WindowInfo.RedrawPart :=
  2722. CBord[twrdBorder in RedrawWhat] or
  2723. CCapt[twrdCaption in RedrawWhat] or
  2724. CBtn[twrdCloseButton in RedrawWhat];
  2725. WindowInfo.Caption := PChar(Caption);
  2726. WindowInfo.EffectiveColor := GetEffectiveColor(DockWindow);
  2727. WindowInfo.Active := not DockWindow.InactiveCaption;
  2728. Canvas.Brush.Color := WindowInfo.EffectiveColor;
  2729. CurrentTheme.PaintFloatingBorder(Canvas, R, WindowInfo);
  2730. finally
  2731. Canvas.Handle := 0;
  2732. Canvas.Free;
  2733. end;
  2734. finally
  2735. if not DrawToDC then ReleaseDC(Handle, DC);
  2736. end;
  2737. end;
  2738. procedure TTBXFloatingWindowParent.WMEraseBkgnd(var Message: TMessage);
  2739. begin
  2740. Message.Result := 1;
  2741. end;
  2742. procedure TTBXFloatingWindowParent.WMNCMouseLeave(var Message: TMessage);
  2743. begin
  2744. if not MouseCapture then CancelNCHover;
  2745. inherited;
  2746. end;
  2747. procedure TTBXFloatingWindowParent.WMNCMouseMove(var Message: TWMNCMouseMove);
  2748. var
  2749. InArea: Boolean;
  2750. begin
  2751. inherited;
  2752. { Note: TME_NONCLIENT was introduced in Windows 98 and 2000 }
  2753. CallTrackMouseEvent (Handle, TME_LEAVE or $10 {TME_NONCLIENT});
  2754. InArea := Message.HitTest = 2001; {HT_TB2k_Close}
  2755. if FCloseButtonHover <> InArea then
  2756. begin
  2757. FCloseButtonHover := InArea;
  2758. if HandleAllocated and IsWindowVisible(Handle) then
  2759. DrawNCArea(False, 0, 0, [twrdCloseButton]);
  2760. end;
  2761. end;
  2762. procedure TTBXFloatingWindowParent.WMWindowPosChanging(var Message: TWMWindowPosChanging);
  2763. var
  2764. R: TRect;
  2765. MonInfo: TMonitorInfo;
  2766. begin
  2767. if SnapDistance > 0 then with Message.WindowPos^ do
  2768. begin
  2769. if (cx = Width) and (cy = Height) then
  2770. begin
  2771. MonInfo.cbSize := SizeOf(MonInfo);
  2772. GetMonitorInfo(Monitor.Handle, @MonInfo);
  2773. R := MonInfo.rcWork;
  2774. if Abs(x + Width - R.Right) < SnapDistance then x := R.Right - Width;
  2775. if Abs(y + Height - R.Bottom) < SnapDistance then y := R.Bottom - Height;
  2776. if Abs(x - R.Left) < SnapDistance then x := R.Left;
  2777. if Abs(y - R.Top) < SnapDistance then y := R.Top;
  2778. end;
  2779. end;
  2780. inherited;
  2781. end;
  2782. //============================================================================//
  2783. { Additional system colors }
  2784. type
  2785. TColorEntry = packed record
  2786. ColorPtr: ^TColor;
  2787. Name: string;
  2788. end;
  2789. var
  2790. ColorRegistry: array of TColorEntry;
  2791. procedure AddTBXColor(var AColor: TColor; const AName: string);
  2792. var
  2793. L: Integer;
  2794. begin
  2795. L := Length(ColorRegistry);
  2796. SetLength(ColorRegistry, L + 1);
  2797. with ColorRegistry[L] do
  2798. begin
  2799. ColorPtr := @AColor;
  2800. Name := AName;
  2801. end;
  2802. end;
  2803. function TBXColorToString(Color: TColor): string;
  2804. var
  2805. I: Integer;
  2806. begin
  2807. if not ColorToIdent(Color, Result) then
  2808. begin
  2809. for I := 0 to Length(ColorRegistry) - 1 do
  2810. if ColorRegistry[I].ColorPtr^ = Color then
  2811. begin
  2812. Result := ColorRegistry[I].Name;
  2813. Exit;
  2814. end;
  2815. FmtStr(Result, '%s%.8x', [HexDisplayPrefix, Color]);
  2816. end;
  2817. end;
  2818. function TBXIdentToColor(const Ident: string; var Color: Longint): Boolean;
  2819. var
  2820. I: Integer;
  2821. begin
  2822. for I := 0 to Length(ColorRegistry) - 1 do
  2823. if CompareText(ColorRegistry[I].Name, Ident) = 0 then
  2824. begin
  2825. Color := ColorRegistry[I].ColorPtr^;
  2826. Result := True;
  2827. Exit;
  2828. end;
  2829. Result := IdentToColor(Ident, Color);
  2830. end;
  2831. function TBXStringToColor(S: string): TColor;
  2832. begin
  2833. if not TBXIdentToColor(S, Longint(Result)) then Result := StringToColor(S);
  2834. end;
  2835. procedure TBXGetColorValues(Proc: TGetStrProc);
  2836. var
  2837. I: Integer;
  2838. begin
  2839. GetColorValues(Proc);
  2840. for I := 0 to Length(ColorRegistry) - 1 do Proc(ColorRegistry[I].Name);
  2841. end;
  2842. procedure TBXSetTheme(const AThemeName: string);
  2843. begin
  2844. TBXNexus.SetTheme(AThemeName);
  2845. end;
  2846. function TBXCurrentTheme: string;
  2847. begin
  2848. Result := TBXNexus.GetTheme;
  2849. end;
  2850. //============================================================================//
  2851. { TTBXNexus }
  2852. procedure TTBXNexus.AddNotifie(AObject: TObject);
  2853. begin
  2854. if FNotifies.IndexOf(AObject) < 0 then FNotifies.Add(AObject);
  2855. Exit; asm db 0,'TBX (C) 2001-2003 Alex Denisov',0 end;
  2856. end;
  2857. procedure TTBXNexus.Broadcast(Msg: Cardinal; WParam, LParam: Integer);
  2858. var
  2859. M: TMessage;
  2860. I: Integer;
  2861. begin
  2862. if FNotifies.Count > 0 then
  2863. begin
  2864. M.Msg := Msg;
  2865. M.WParam := WParam;
  2866. M.LParam := LParam;
  2867. M.Result := 0;
  2868. for I := 0 to FNotifies.Count - 1 do TObject(FNotifies[I]).Dispatch(M);
  2869. end;
  2870. end;
  2871. constructor TTBXNexus.Create(const DefaultTheme: string);
  2872. begin
  2873. FNotifies := TList.Create;
  2874. CurrentTheme := GetTBXTheme(DefaultTheme);
  2875. AddTBXSysChangeNotification(Self);
  2876. end;
  2877. destructor TTBXNexus.Destroy;
  2878. begin
  2879. RemoveTBXSysChangeNotification(Self);
  2880. ReleaseTBXTheme(CurrentTheme);
  2881. FNotifies.Free;
  2882. inherited;
  2883. end;
  2884. function TTBXNexus.GetTheme: string;
  2885. begin
  2886. Result := CurrentTheme.Name;
  2887. end;
  2888. procedure TTBXNexus.RemoveNotifie(AObject: TObject);
  2889. begin
  2890. FNotifies.Remove(AObject);
  2891. end;
  2892. procedure TTBXNexus.SetTheme(const AThemeName: string);
  2893. begin
  2894. if IsTBXThemeAvailable(AThemeName) then
  2895. begin
  2896. ReleaseTBXTheme(CurrentTheme);
  2897. CurrentTheme := GetTBXTheme(AThemeName);
  2898. Broadcast(TBM_THEMECHANGE, TSC_BEFOREVIEWCHANGE, 1);
  2899. Broadcast(TBM_THEMECHANGE, TSC_VIEWCHANGE, 1);
  2900. Broadcast(TBM_THEMECHANGE, TSC_AFTERVIEWCHANGE, 1);
  2901. end;
  2902. end;
  2903. procedure TTBXNexus.TBXSysCommand(var Message: TMessage);
  2904. begin
  2905. { Retranslate TBX_SYSCOMMAND to TBM_THEMECHANGE }
  2906. if Message.Msg = TBX_SYSCOMMAND then
  2907. Broadcast(TBM_THEMECHANGE, Message.WParam, 0);
  2908. end;
  2909. { TTBXDock }
  2910. procedure TTBXDock.CMColorChanged(var Message: TMessage);
  2911. var
  2912. I: Integer;
  2913. begin
  2914. inherited;
  2915. for I := 0 to Self.ControlCount - 1 do
  2916. if Controls[I] is TWinControl then
  2917. InvalidateAll(TWinControl(Controls[I]));
  2918. end;
  2919. constructor TTBXDock.Create(AOwner: TComponent);
  2920. begin
  2921. inherited;
  2922. Color := clNone;
  2923. AddThemeNotification(Self);
  2924. end;
  2925. destructor TTBXDock.Destroy;
  2926. begin
  2927. RemoveThemeNotification(Self);
  2928. inherited;
  2929. end;
  2930. procedure TTBXDock.DrawBackground(DC: HDC; const DrawRect: TRect);
  2931. const
  2932. DOCK_POSITIONS: array [TTBDockPosition] of Integer = (DP_TOP, DP_BOTTOM, DP_LEFT, DP_RIGHT);
  2933. var
  2934. Canvas: TCanvas;
  2935. begin
  2936. if UseParentBackground then DrawParentBackground(Self, DC, ClientRect)
  2937. else if ThemedBackground then
  2938. begin
  2939. Canvas := TCanvas.Create;
  2940. Canvas.Handle := DC;
  2941. CurrentTheme.PaintDock(Canvas, ClientRect, DrawRect, DOCK_POSITIONS[Position]);
  2942. Canvas.Handle := 0;
  2943. Canvas.Free;
  2944. end
  2945. else inherited;
  2946. end;
  2947. procedure TTBXDock.Resize;
  2948. var
  2949. I, J: Integer;
  2950. V: TTBItemViewer;
  2951. R: TRect;
  2952. begin
  2953. inherited Resize;
  2954. if UsingBackground then
  2955. begin
  2956. for J := 0 to ToolbarCount - 1 do
  2957. begin
  2958. Invalidate;
  2959. if Toolbars[J] is TTBXToolbar then with TTBXToolbar(Toolbars[J]) do
  2960. begin
  2961. for I := 0 to View.ViewerCount - 1 do
  2962. begin
  2963. V := View.Viewers[I];
  2964. if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
  2965. then View.Invalidate(V);
  2966. end;
  2967. Update;
  2968. if HandleAllocated then
  2969. RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or RDW_ERASE);
  2970. for I := 0 to View.ViewerCount - 1 do
  2971. begin
  2972. V := View.Viewers[I];
  2973. if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
  2974. then
  2975. begin
  2976. R := V.BoundsRect;
  2977. ValidateRect(Handle, @R);
  2978. end;
  2979. end;
  2980. end
  2981. end;
  2982. end;
  2983. end;
  2984. procedure TTBXDock.SetUseParentBackground(Value: Boolean);
  2985. begin
  2986. if Value <> FUseParentBackground then
  2987. begin
  2988. FUseParentBackground := Value;
  2989. if HandleAllocated then
  2990. RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
  2991. RDW_ERASE or RDW_ALLCHILDREN);
  2992. end;
  2993. end;
  2994. procedure TTBXDock.TBMGetEffectiveColor(var Message: TMessage);
  2995. begin
  2996. if Color <> clNone then Message.WParam := Color
  2997. else if Parent <> nil then Message.WParam := GetEffectiveColor(Parent)
  2998. else Message.WParam := WPARAM(clBtnFace);
  2999. Message.Result := 1;
  3000. end;
  3001. procedure TTBXDock.TBMThemeChange(var Message: TMessage);
  3002. begin
  3003. case Message.WParam of
  3004. TSC_AFTERVIEWCHANGE:
  3005. begin
  3006. Invalidate;
  3007. end;
  3008. end;
  3009. end;
  3010. function TTBXDock.ThemedBackground: Boolean;
  3011. begin
  3012. Result := (Color = clNone) and CurrentTheme.PaintDockBackground;
  3013. end;
  3014. function TTBXDock.UsingBackground: Boolean;
  3015. begin
  3016. Result := UseParentBackground or (ThemedBackground and not FMoving) or
  3017. inherited UsingBackground;
  3018. end;
  3019. procedure TTBXDock.WMEraseBkgnd(var Message: TWMEraseBkgnd);
  3020. var
  3021. R: TRect;
  3022. C: TColor;
  3023. begin
  3024. R := Self.ClientRect;
  3025. if UsingBackground then
  3026. begin
  3027. DrawBackground(Message.DC, R);
  3028. Message.Result := 1;
  3029. end
  3030. else
  3031. begin
  3032. C := Color;
  3033. if C = clNone then C := GetEffectiveColor(Parent);
  3034. FillRectEx(Message.DC, R, C);
  3035. Message.Result := 1;
  3036. end;
  3037. end;
  3038. procedure TTBXDock.WMMove(var Message: TWMMove);
  3039. begin
  3040. FMoving := True;
  3041. inherited;
  3042. FMoving := False;
  3043. end;
  3044. procedure TTBXDock.WMSize(var Message: TWMSize);
  3045. begin
  3046. FResizing := True;
  3047. inherited;
  3048. FResizing := False;
  3049. end;
  3050. { TTBXMenuAnimation }
  3051. constructor TTBXMenuAnimation.Create(AAnimationMode: TAnimationMode = amSysDefault);
  3052. begin
  3053. AnimationMode := AAnimationMode;
  3054. end;
  3055. function TTBXMenuAnimation.GetAvailableModes: TAnimationModes;
  3056. begin
  3057. Result := [amNone, amSysDefault, amRandom, amUnfold, amSlide, amFade];
  3058. end;
  3059. function TTBXMenuAnimation.GetMenuAnimation: TMenuAnimation;
  3060. function GetSysDefault: TMenuAnimation;
  3061. const
  3062. SPI_GETMENUFADE = $1012;
  3063. SysDefAni: array[Boolean] of TMenuAnimation = (maSlide, maFade);
  3064. begin
  3065. if SysParamEnabled(SPI_GETMENUANIMATION)
  3066. then Result := SysDefAni[SysParamEnabled(SPI_GETMENUFADE)]
  3067. else Result := maNone;
  3068. end;
  3069. function GetRandom: TMenuAnimation;
  3070. var Max: Integer;
  3071. begin
  3072. Max := Ord(High(TMenuAnimation));
  3073. if not (amFade in AvailableModes) then
  3074. Dec(Max);
  3075. Result := Succ(TMenuAnimation(Random(Max)));
  3076. end;
  3077. begin
  3078. case AnimationMode of
  3079. amSysDefault: Result := GetSysDefault;
  3080. amRandom: Result := GetRandom;
  3081. amUnfold: Result := maUnfold;
  3082. amSlide: Result := maSlide;
  3083. amFade: Result := maFade;
  3084. else
  3085. Result := maNone;
  3086. end;
  3087. end;
  3088. procedure TTBXMenuAnimation.SetAnimationMode(Value: TAnimationMode);
  3089. var AvailModes: TAnimationModes;
  3090. begin
  3091. AvailModes := AvailableModes;
  3092. while not (Value in AvailModes) do
  3093. Value := Pred(Value);
  3094. FAnimationMode := Value;
  3095. end;
  3096. function TTBXMenuAnimation.SysParamEnabled(Param: Cardinal): Boolean;
  3097. var B: BOOL;
  3098. begin
  3099. Result := SystemParametersInfo(Param, 0, @B, 0) and B;
  3100. end;
  3101. { Work around delayed menu showing in Windows 2000+ }
  3102. var
  3103. FixPlaySoundThreadHandle: Cardinal;
  3104. function FixPlaySoundThreadFunc(Param: Pointer): Integer; stdcall;
  3105. begin
  3106. Sleep(250);
  3107. PlaySound(nil, 0, 0);
  3108. CloseHandle(FixPlaySoundThreadHandle); { Harakiri :~| }
  3109. Result := $4E494150; { :) }
  3110. end;
  3111. procedure FixPlaySoundDelay;
  3112. var ThreadId: TThreadID;
  3113. begin
  3114. if (FixPlaySoundThreadHandle = 0) then
  3115. FixPlaySoundThreadHandle := CreateThread(nil, $1000,
  3116. @FixPlaySoundThreadFunc, nil, 0, ThreadId);
  3117. end;
  3118. function CreateTBXPopupMenu(Owner: TComponent): TTBXPopupMenu;
  3119. begin
  3120. Result := TTBXPopupMenu.Create(Owner);
  3121. end;
  3122. initialization
  3123. FixPlaySoundDelay;
  3124. RegisterTBXTheme('OfficeXP', TTBXOfficeXPTheme);
  3125. RegisterTBXTheme('DarkOfficeXP', TTBXDarkOfficeXPTheme);
  3126. TBXNexus := TTBXNexus.Create('OfficeXP');
  3127. TBXMenuAnimation := TTBXMenuAnimation.Create;
  3128. finalization
  3129. TBXNexus.Free;
  3130. FreeAndNil(TBXMenuAnimation);
  3131. ColorRegistry := nil;
  3132. end.