TBX.pas 116 KB

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