| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869 |
- unit TBX;
- // TBX Package
- // Copyright 2001-2004 Alex A. Denisov. All Rights Reserved
- // See TBX.chm for license and installation instructions
- //
- // Id: TBX.pas 21 2004-05-29 22:16:01Z Alex@ZEISS
- interface
- {$I TB2Ver.inc}
- {$I TBX.inc}
- {x$DEFINE TBX_NO_ANIMATION}
- { Enabling the above define disables all menu animation. For debugging
- purpose only. } {vb+}
- uses
- Windows, Messages, Classes, SysUtils, Controls, Graphics, ImgList, Forms,
- TB2Item, TB2Dock, TB2Toolbar, {$IFNDEF MPEXCLUDE}TB2ToolWindow,{$ENDIF} TB2Anim, TBXUtils, TBXThemes;
- const
- TBXVersion = 2.1;
- TBXVersionString = '2.1';
- TBXVersionText = 'TBX version ' + TBXVersionString;
- { TBX Messages }
- const
- TBM_THEMECHANGE = WM_USER + 314;
- TBM_GETVIEWTYPE = WM_USER + 237;
- TBM_GETEFFECTIVECOLOR = WM_USER + 238;
- function GetViewType(View: TTBView): Integer;
- function GetWinViewType(Window: TControl): Integer;
- function IsFloating(ViewType: Integer): Boolean;
- type
- TTextWrapping = (twNone, twEndEllipsis, twPathEllipsis, twWrap);
- TTextTruncation = twNone..twPathEllipsis;
- TTriState = (tsDefault, tsTrue, tsFalse);
- TFontSize = 25..1000;
- TFontSettings = class(TPersistent)
- private
- FBold: TTriState;
- FItalic: TTriState;
- FUnderline: TTriState;
- FStrikeOut: TTriState;
- FSize: TFontSize;
- FColor: TColor;
- FName: TFontName;
- FOnChange: TNotifyEvent;
- procedure SetBold(Value: TTriState);
- procedure SetColor(Value: TColor);
- procedure SetItalic(Value: TTriState);
- procedure SetName(const Value: TFontName);
- procedure SetSize(Value: TFontSize);
- procedure SetStrikeOut(Value: TTriState);
- procedure SetUnderline(Value: TTriState);
- protected
- procedure Modified;
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- public
- constructor Create;
- procedure Apply(Font: TFont); overload;
- procedure Apply(var LF: TLogFont; var FontColor: TColor); overload;
- procedure Assign(Src: TPersistent); override;
- function CreateTransformedFont(Src: HFont; var FontColor: TColor): HFont;
- published
- property Bold: TTriState read FBold write SetBold default tsDefault;
- property Italic: TTriState read FItalic write SetItalic default tsDefault;
- property Underline: TTriState read FUnderline write SetUnderline default tsDefault;
- property StrikeOut: TTriState read FStrikeOut write SetStrikeOut default tsDefault;
- property Size: TFontSize read FSize write SetSize default 100; // percent
- property Color: TColor read FColor write SetColor default clNone;
- property Name: TFontName read FName write SetName; // default ''
- end;
- TTBXPopupPositionInfo = record
- Item: TTBCustomItem; // this is a tentative type, it will be changed
- ParentView: TTBView; // or removed in future versions
- ParentViewer: TTBItemViewer;
- PositionAsSubmenu: Boolean;
- APopupPoint: TPoint;
- Alignment: TTBPopupAlignment;
- PopupWindow: TTBPopupWindow;
- X, Y: Integer;
- ParentItemRect: TRect;
- AppFlags: Integer; // reserved for extensions
- AppData: Integer;
- end;
- TTBXThemeClass = class of TTBXTheme;
- function GetStateFlags(const ItemInfo: TTBXItemInfo): Integer;
- function GetTBXTextColor(StateFlags: Integer): TColor;
- procedure DrawTBXCaption(Canvas: TCanvas; Rect: TRect; const Text: string;
- Format: Cardinal; StateFlags: Integer);
- procedure DrawTBXImage(Canvas: TCanvas; Rect: TRect; ImageList: TCustomImageList;
- ImageIndex: Integer; StateFlags: Integer);
- type
- { TTBXItem }
- TAdjustFontEvent = procedure(Item: TTBCustomItem; Viewer: TTBItemViewer;
- Font: TFont; StateFlags: Integer) of object; // state flags are the combination of ISF_* constants
- TDrawImageEvent = procedure(Item: TTBCustomItem; Viewer: TTBItemViewer;
- Canvas: TCanvas; ImageRect: TRect; ImageOffset: TPoint; StateFlags: Integer) of object;
- TTBXCustomItem = class(TTBCustomItem)
- private
- FAlwaysSelectFirst: Boolean;
- FFontSettings: TFontSettings;
- FLayout: TTBXItemLayout;
- FMinHeight: Integer;
- FMinWidth: Integer;
- FToolBoxPopup: Boolean;
- FOnAdjustFont: TAdjustFontEvent;
- FOnDrawImage: TDrawImageEvent;
- procedure FontSettingsChanged(Sender: TObject);
- function GetStretch: Boolean;
- procedure SetFontSettings(Value: TFontSettings);
- procedure SetLayout(Value: TTBXItemLayout);
- procedure SetMinHeight(Value: Integer);
- procedure SetMinWidth(Value: Integer);
- procedure SetStretch(Value: Boolean);
- protected
- function CreatePopup(const ParentView: TTBView; const ParentViewer: TTBItemViewer;
- const PositionAsSubmenu, SelectFirstItem, Customizing: Boolean;
- const APopupPoint: TPoint; const Alignment: TTBPopupAlignment): TTBPopupWindow; override;
- function GetItemViewerClass(AView: TTBView): TTBItemViewerClass; override;
- procedure GetPopupPosition(ParentView: TTBView; PopupWindow: TTBPopupWindow;
- var PopupPositionRec: TTBPopupPositionRec); override;
- function GetPopupWindowClass: TTBPopupWindowClass; override;
- property ToolBoxPopup: Boolean read FToolBoxPopup write FToolBoxPopup default False;
- property OnAdjustFont: TAdjustFontEvent read FOnAdjustFont write FOnAdjustFont;
- property OnDrawImage: TDrawImageEvent read FOnDrawImage write FOnDrawImage;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Invalidate;
- property AlwaysSelectFirst: Boolean read FAlwaysSelectFirst write FAlwaysSelectFirst default False;
- property FontSettings: TFontSettings read FFontSettings write SetFontSettings;
- property Layout: TTBXItemLayout read FLayout write SetLayout default tbxlAuto;
- property MinHeight: Integer read FMinHeight write SetMinHeight default 0;
- property MinWidth: Integer read FMinWidth write SetMinWidth default 0;
- property Stretch: Boolean read GetStretch write SetStretch default False;
- end;
- TTBXItem = class (TTBXCustomItem)
- property Action;
- property AutoCheck;
- property Caption;
- property Checked;
- property DisplayMode;
- property Enabled;
- property FontSettings;
- property GroupIndex;
- property HelpContext;
- { MP }
- property HelpKeyword;
- property Hint;
- property ImageIndex;
- property Images;
- property InheritOptions;
- property Layout;
- property MaskOptions;
- property MinHeight;
- property MinWidth;
- property Options;
- property RadioItem;
- property ShortCut;
- property Stretch;
- property Visible;
- property OnAdjustFont;
- property OnDrawImage;
- property OnClick;
- property OnSelect;
- end;
- TTBXItemViewer = class(TTBItemViewer)
- private
- FWide: Boolean;
- protected
- procedure DoPaintCaption(Canvas: TCanvas; const ClientAreaRect: TRect;
- var CaptionRect: TRect; IsTextRotated: Boolean; var PaintDefault: Boolean); virtual;
- function GetAccRole: Integer; override;
- function GetImageSize: TSize; dynamic;
- function GetItemType: Integer; virtual;
- function GetTextFlags: Cardinal; dynamic;
- function GetTextSize(Canvas: TCanvas; const Text: string; TextFlags: Cardinal; Rotated: Boolean; StateFlags: Integer): TSize; dynamic;
- function IsToolbarSize: Boolean; override;
- procedure CalcSize(const Canvas: TCanvas; var AWidth, AHeight: Integer); override;
- procedure DrawItemImage(Canvas: TCanvas; ARect: TRect; ItemInfo: TTBXItemInfo); virtual;
- procedure DoAdjustFont(AFont: TFont; StateFlags: Integer); virtual;
- function GetImageShown: Boolean; virtual;
- function IsPtInButtonPart(X, Y: Integer): Boolean; override;
- procedure MouseUp(X, Y: Integer; MouseWasDownOnMenu: Boolean); override;
- procedure Paint(const Canvas: TCanvas; const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean); override;
- property Wide: Boolean read FWide write FWide default True;
- public
- constructor Create(AView: TTBView; AItem: TTBCustomItem; AGroupLevel: Integer); override;
- function IsToolbarStyle: Boolean; override;
- end;
- { TTBXSubmenuItem }
- TTBXSubmenuItem = class(TTBXCustomItem)
- private
- function GetDropdownCombo: Boolean;
- procedure SetDropdownCombo(Value: Boolean);
- public
- constructor Create(AOwner: TComponent); override;
- published
- property Action;
- property AlwaysSelectFirst;
- property AutoCheck;
- property Caption;
- property Checked;
- property DisplayMode;
- property DropdownCombo: Boolean read GetDropdownCombo write SetDropdownCombo default False;
- property Enabled;
- property FontSettings;
- property GroupIndex;
- property HelpContext;
- { MP }
- property HelpKeyword;
- property Hint;
- property ImageIndex;
- property Images;
- property InheritOptions;
- property Layout;
- property LinkSubitems;
- property MaskOptions;
- property MinHeight;
- property MinWidth;
- property Options;
- property RadioItem;
- property ShortCut;
- property Stretch;
- property SubMenuImages;
- property ToolBoxPopup;
- property Visible;
- property OnAdjustFont;
- property OnDrawImage;
- property OnClick;
- property OnPopup;
- property OnSelect;
- end;
- { TTBXSeparatorItem }
- TTBXSeparatorItem = class(TTBSeparatorItem)
- private
- FSize: Integer;
- procedure SetSize(Value: Integer);
- public
- constructor Create(AOwner: TComponent); override;
- function GetItemViewerClass(AView: TTBView): TTBItemViewerClass; override;
- published
- property Size: Integer read FSize write SetSize default -1;
- property MaskOptions;
- property Options;
- end;
- TTBXSeparatorItemViewer = class(TTBSeparatorItemViewer)
- protected
- procedure CalcSize(const Canvas: TCanvas; var AWidth, AHeight: Integer); override;
- procedure Paint(const Canvas: TCanvas; const ClientAreaRect: TRect;
- IsHoverItem, IsPushed, UseDisabledShadow: Boolean); override;
- function IsToolbarSize: Boolean; override;
- public
- function IsToolbarStyle: Boolean; override;
- end;
- {$IFNDEF MPEXCLUDE}
- TTBXVisibilityToggleItem = class(TTBXCustomItem)
- private
- FControl: TControl;
- procedure SetControl (Value: TControl);
- procedure UpdateProps;
- protected
- procedure Notification (AComponent: TComponent; Operation: TOperation); override;
- public
- procedure Click; override;
- procedure InitiateAction; override;
- published
- property Caption;
- property Control: TControl read FControl write SetControl;
- property DisplayMode;
- property Enabled;
- property FontSettings;
- property HelpContext;
- { MP }
- property HelpKeyword;
- property Hint;
- property ImageIndex;
- property Images;
- property InheritOptions;
- property Layout;
- property MaskOptions;
- property MinHeight;
- property MinWidth;
- property Options;
- property ShortCut;
- property Stretch;
- property Visible;
- property OnAdjustFont;
- property OnClick;
- property OnSelect;
- end;
- {$ENDIF}
- { TTBXPopupWindow }
- TTBXPopupWindow = class(TTBPopupWindow)
- private
- FControlRect: TRect;
- FShadows: TShadows;
- procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
- procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED; {vb+}
- procedure TBMGetViewType(var Message: TMessage); message TBM_GETVIEWTYPE;
- procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
- procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
- procedure WMPrint(var Message: TMessage); message WM_PRINT;
- procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
- procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;
- procedure WMTB2kPopupShowing(var Message: TMessage); message WM_TB2K_POPUPSHOWING;
- protected
- procedure CreateParams(var Params: TCreateParams); override;
- procedure CreateShadow; virtual;
- procedure DestroyShadow; virtual;
- function GetNCSize: TPoint; override;
- function GetShowShadow: Boolean; virtual;
- function GetViewClass: TTBViewClass; override;
- procedure PaintScrollArrows; override; {vb+}
- public
- destructor Destroy; override;
- function GetFillColor: TColor;
- end;
- TTBXPopupView = class(TTBPopupView);
- { TTBXToolbarView }
- TTBXToolbarView = class(TTBToolbarView)
- protected
- procedure GetMargins(AOrientation: TTBViewOrientation; var Margins: TRect); override;
- end;
- { TTBXToolbar }
- TTBXItemTransparency = (itAuto, itEnable, itDisable);
- TTBXToolbar = class(TTBCustomToolbar)
- private
- FEffectiveColor: TColor;
- FItemTransparency: TTBXItemTransparency;
- FSnapDistance: Integer;
- procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
- procedure CMControlChange(var Message: TCMControlChange); message CM_CONTROLCHANGE;
- procedure CMParentColorChanged(var Message: TMessage); message CM_PARENTCOLORCHANGED;
- procedure SetItemTransparency(const Value: TTBXItemTransparency);
- procedure SetSnapDistance(Value: Integer);
- procedure TBMGetViewType(var Message: TMessage); message TBM_GETVIEWTYPE;
- procedure TBMGetEffectiveColor(var Message: TMessage); message TBM_GETEFFECTIVECOLOR;
- procedure TBMThemeChange(var Message: TMessage); message TBM_THEMECHANGE;
- procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
- procedure WMSize(var Message: TWMSize); message WM_SIZE;
- protected
- procedure DrawNCArea(const DrawToDC: Boolean; const ADC: HDC; const Clip: HRGN); override;
- function GetChevronItemClass: TTBChevronItemClass; override;
- function GetFloatingWindowParentClass: TTBFloatingWindowParentClass; override;
- procedure GetToolbarInfo(out ToolbarInfo: TTBXToolbarInfo); virtual;
- function GetViewClass: TTBToolbarViewClass; override;
- procedure Loaded; override; {vb+}
- procedure SetParent(AParent: TWinControl); override;
- procedure UpdateEffectiveColor;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- function Embedded: Boolean;
- function GetFloatingBorderSize: TPoint; override;
- procedure UpdateChildColors;
- property EffectiveColor: TColor read FEffectiveColor;
- published
- property ActivateParent;
- property Align;
- property AutoResize;
- property BorderStyle;
- property Caption;
- property ChevronHint;
- property ChevronMoveItems;
- property ChevronPriorityForNewItems;
- property CloseButton;
- property CloseButtonWhenDocked;
- property CurrentDock;
- property DblClickUndock default False;
- property DefaultDock;
- property DockableTo;
- property DockMode;
- property DockPos;
- property DockRow;
- property DragHandleStyle;
- property FloatingMode;
- property Font;
- property FullSize;
- property HideWhenInactive;
- property Images;
- property Items;
- property ItemTransparency: TTBXItemTransparency read FItemTransparency write SetItemTransparency default itAuto;
- property LastDock;
- property LinkSubitems;
- property MenuBar;
- property Options;
- property ParentFont;
- property ParentShowHint;
- property PopupMenu;
- property ProcessShortCuts;
- property Resizable;
- property ShowCaption;
- property ShowHint;
- property ShrinkMode;
- property SmoothDrag;
- property SnapDistance: Integer read FSnapDistance write SetSnapDistance default 0;
- property Stretch;
- property SystemFont;
- property TabOrder;
- property TabStop;
- property UpdateActions;
- property UseLastDock;
- property Visible;
- property Color default clNone;
- property OnClose;
- property OnCloseQuery;
- {$IFDEF JR_D5}
- property OnContextPopup;
- {$ENDIF}
- property OnDragDrop;
- property OnDragOver;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- property OnMove;
- property OnRecreated;
- property OnRecreating;
- property OnDockChanged;
- property OnDockChanging;
- property OnDockChangingHidden;
- property OnResize;
- property OnShortCut;
- property OnVisibleChanged;
- { MP }
- property OnGetBaseSize;
- end;
- { TTBXChevronItem }
- TTBXChevronItem = class(TTBChevronItem)
- public
- procedure GetPopupPosition(ParentView: TTBView;
- PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec); override;
- function GetPopupWindowClass: TTBPopupWindowClass; override;
- function GetItemViewerClass(AView: TTBView): TTBItemViewerClass; override;
- end;
- TTBXChevronItemViewer = class(TTBItemViewer)
- protected
- procedure Paint(const Canvas: TCanvas; const ClientAreaRect: TRect;
- IsHoverItem, IsPushed, UseDisabledShadow: Boolean); override;
- end;
- TTBXChevronPopupWindow = class(TTBXPopupWindow);
- { TTBXPopupMenu }
- TTBXRootItem = class(TTBRootItem)
- private
- FPopupControlRect: TRect;
- protected
- function CreatePopupEx(SelectFirstItem: Boolean; const AControlRect: TRect;
- Alignment: TTBPopupAlignment): TTBPopupWindow; virtual;
- function GetPopupWindowClass: TTBPopupWindowClass; override;
- procedure GetPopupPosition(ParentView: TTBView; PopupWindow: TTBPopupWindow;
- var PopupPositionRec: TTBPopupPositionRec); override;
- function OpenPopupEx(const SelectFirstItem, TrackRightButton: Boolean;
- const ControlRect: TRect; const Alignment: TTBPopupAlignment;
- const ReturnClickedItemOnly: Boolean): TTBCustomItem;
- function PopupEx(const ControlRect: TRect; TrackRightButton: Boolean;
- Alignment: TTBPopupAlignment = tbpaLeft;
- ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
- end;
- TTBXPopupMenu = class(TTBPopupMenu)
- private
- FToolBoxPopup: Boolean;
- procedure TBMGetViewType(var Message: TMessage); message TBM_GETVIEWTYPE;
- protected
- function GetRootItemClass: TTBRootItemClass; override;
- public
- function PopupEx(const ControlRect: TRect;
- ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
- property ToolBoxPopup: Boolean read FToolBoxPopup write FToolBoxPopup default False;
- end;
- TTBXFloatingWindowParent = class(TTBFloatingWindowParent)
- private
- FCloseButtonHover: Boolean;
- FSnapDistance: Integer;
- procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
- procedure WMEraseBkgnd(var Message: TMessage); message WM_ERASEBKGND;
- procedure WMNCMouseLeave(var Message: TMessage); message $2A2 {WM_NCMOUSELEAVE};
- procedure WMNCMouseMove(var Message: TWMNCMouseMove); message WM_NCMOUSEMOVE;
- procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
- protected
- procedure CancelNCHover;
- procedure DrawNCArea(const DrawToDC: Boolean; const ADC: HDC;
- const Clip: HRGN; RedrawWhat: TTBToolWindowNCRedrawWhat); override;
- property CloseButtonHover: Boolean read FCloseButtonHover;
- public
- property SnapDistance: Integer read FSnapDistance write FSnapDistance default 0;
- end;
- {$IFNDEF MPEXCLUDE}
- TTBXToolWindow = class(TTBToolWindow)
- private
- FEffectiveColor: TColor;
- FSnapDistance: Integer;
- procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
- procedure CMControlChange(var Message: TCMControlChange); message CM_CONTROLCHANGE;
- procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
- procedure SetSnapDistance(Value: Integer);
- procedure TBMGetEffectiveColor(var Message: TMessage); message TBM_GETEFFECTIVECOLOR;
- procedure TBMGetViewType(var Message: TMessage); message TBM_GETVIEWTYPE;
- procedure TBMThemeChange(var Message: TMessage); message TBM_THEMECHANGE;
- procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND;
- protected
- procedure DrawNCArea(const DrawToDC: Boolean; const ADC: HDC; const Clip: HRGN); override;
- function GetFloatingWindowParentClass: TTBFloatingWindowParentClass; override;
- procedure GetToolbarInfo(out ToolbarInfo: TTBXToolbarInfo); virtual;
- procedure SetParent(AParent: TWinControl); override;
- procedure UpdateEffectiveColor;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- function GetFloatingBorderSize: TPoint; override;
- procedure UpdateChildColors;
- property EffectiveColor: TColor read FEffectiveColor;
- published
- property Color default clNone;
- property DblClickUndock default False;
- property SnapDistance: Integer read FSnapDistance write SetSnapDistance default 0;
- end;
- {$ENDIF}
- TTBXDock = class(TTBDock)
- private
- FMoving: Boolean;
- FResizing: Boolean;
- FUseParentBackground: Boolean;
- procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
- procedure TBMGetEffectiveColor(var Message: TMessage); message TBM_GETEFFECTIVECOLOR;
- procedure TBMThemeChange(var Message: TMessage); message TBM_THEMECHANGE;
- procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
- procedure WMMove(var Message: TWMMove); message WM_MOVE;
- procedure WMSize(var Message: TWMSize); message WM_SIZE;
- protected
- function ThemedBackground: Boolean; virtual;
- procedure DrawBackground(DC: HDC; const DrawRect: TRect); override;
- procedure Resize; override;
- procedure SetUseParentBackground(Value: Boolean);
- function UsingBackground: Boolean; override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property Color default clNone;
- property UseParentBackground: Boolean read FUseParentBackground write SetUseParentBackground default False;
- end;
- { TTBXMenuAnimation } {vb+}
- TMenuAnimation = (maNone, maUnfold, maSlide, maFade);
- TAnimationMode = (amNone, amSysDefault, amRandom, amUnfold, amSlide, amFade);
- TAnimationModes = set of TAnimationMode;
- TTBXMenuAnimation = class
- private
- FAnimationMode: TAnimationMode;
- function SysParamEnabled(Param: Cardinal): Boolean;
- function GetAvailableModes: TAnimationModes;
- function GetMenuAnimation: TMenuAnimation;
- procedure SetAnimationMode(Value: TAnimationMode);
- property MenuAnimation: TMenuAnimation read GetMenuAnimation;
- public
- constructor Create(AAnimationMode: TAnimationMode = amSysDefault);
- property AnimationMode: TAnimationMode read FAnimationMode write SetAnimationMode;
- property AvailableModes: TAnimationModes read GetAvailableModes;
- end;
- var
- CurrentTheme: TTBXTheme;
- TBXMenuAnimation: TTBXMenuAnimation; { vb+ }
- {$IFNDEF JR_D6}
- var
- clMoneyGreen: TColor = TColor($C0DCC0);
- clSkyBlue: TColor = TColor($F0CAA6);
- clCream: TColor = TColor($F0FBFF);
- clMedGray: TColor = TColor($A4A0A0);
- {$ENDIF}
- procedure TBXSetTheme(const AThemeName: string);
- function TBXCurrentTheme: string;
- procedure AddThemeNotification(AObject: TObject);
- procedure RemoveThemeNotification(AObject: TObject);
- { Additional system colors }
- procedure AddTBXColor(var AColor: TColor; const AName: string);
- function TBXIdentToColor(const Ident: string; var Color: Longint): Boolean;
- function TBXColorToString(Color: TColor): string;
- function TBXStringToColor(S: string): TColor;
- procedure TBXGetColorValues(Proc: TGetStrProc);
- { Internal routines - do not use }
- function GetPopupMargin(ItemViewer: TTBItemViewer): Integer;
- function GetEffectiveColor(C: TControl): TColor;
- procedure DrawParentBackground(Control: TControl; DC: HDC; R: TRect);
- procedure AddToList(var List: TList; Item: Pointer);
- procedure RemoveFromList(var List: TList; Item: Pointer);
- function CreateTBXPopupMenu(Owner: TComponent): TTBXPopupMenu;
- implementation
- {$R tbx_glyphs.res}
- uses
- TBXExtItems, TBXLists, TB2Common, UxTheme, MultiMon, TBXDefaultTheme,
- {ComCtrls, Menus;} {vb-}
- ComCtrls, Menus, MMSystem; {vb+}
- type
- TTBItemAccess = class(TTBCustomItem);
- TTBViewAccess = class(TTBView);
- TTBItemViewerAccess = class(TTBItemViewer);
- TTBFloatingWindowParentAccess = class(TTBFloatingWindowParent);
- TTBCustomDockableWindowAccess = class(TTBCustomDockableWindow);
- TTBXToolbarAccess = class(TTBXToolbar);
- {$IFNDEF MPEXCLUDE}
- TTBBackgroundAccess = class(TTBBackground);
- {$ENDIF}
- TControlAccess = class(TControl);
- TTBXThemeAccess = class(TTBXTheme);
- TDockAccess = class(TTBDock);
- TTBPopupWindowAccess = class(TTBPopupWindow); {vb+}
- { TTBNexus }
- TTBXNexus = class
- private
- FNotifies: TList;
- procedure TBXSysCommand(var Message: TMessage); message TBX_SYSCOMMAND;
- protected
- procedure Broadcast(Msg: Cardinal; WParam, LParam: Integer);
- public
- constructor Create(const DefaultTheme: string);
- destructor Destroy; override;
- procedure SetTheme(const AThemeName: string);
- function GetTheme: string;
- procedure AddNotifie(AObject: TObject);
- procedure RemoveNotifie(AObject: TObject);
- end;
- var
- TBXNexus: TTBXNexus;
- procedure AddThemeNotification(AObject: TObject);
- begin
- TBXNexus.AddNotifie(AObject);
- end;
- procedure RemoveThemeNotification(AObject: TObject);
- begin
- TBXNexus.RemoveNotifie(AObject);
- end;
- function GetEffectiveColor(C: TControl): TColor;
- var
- Message: TMessage;
- begin
- if C = nil then Result := clBtnFace
- else
- begin
- Message.Msg := TBM_GETEFFECTIVECOLOR;
- Message.WParam := 0;
- Message.LParam := 0;
- Message.Result := 0;
- C.Dispatch(Message);
- if Message.Result <> 0 then Result := Message.WParam
- else if (C is TForm) and (TForm(C).FormStyle = fsMDIForm) then
- Result := clBtnFace
- else
- Result := TControlAccess(C).Color;
- end;
- end;
- procedure DrawParentBackground(Control: TControl; DC: HDC; R: TRect);
- var
- Parent: TWinControl;
- Theme: HTHEME;
- R2: TRect;
- Shift: TPoint;
- UsingThemes: Boolean;
- Msg: TMessage;
- begin
- Parent := Control.Parent;
- if Parent = nil then FillRectEx(DC, R, clBtnFace)
- else
- begin
- Shift.X := 0; Shift.Y := 0;
- Shift := Parent.ScreenToClient(Control.ClientToScreen(Shift));
- SaveDC(DC);
- try
- SetWindowOrgEx(DC, Shift.X, Shift.Y, nil);
- Msg.Msg := WM_ERASEBKGND;
- Msg.WParam := Integer(DC); {vb+}
- Msg.LParam := Integer(DC); {vb+}
- Msg.Result := 0;
- Parent.Dispatch(Msg);
- finally
- RestoreDC(DC, -1);
- end;
- if Msg.Result <> 0 then Exit;
- UsingThemes := USE_THEMES and not (csDesigning in Control.ComponentState);
- if Parent is TTBDock then
- begin
- SaveDC(DC);
- SetWindowOrgEx(DC, Control.Left, Control.Top, nil);
- TDockAccess(Parent).DrawBackground(DC, R);
- RestoreDC(DC, -1);
- end
- else if not UsingThemes then
- FillRectEx(DC, R, GetEffectiveColor(Parent))
- else
- begin
- { Unfortunately, DrawThemeParentBackground does seem to have some problems
- with the back buffer. Therefore some sort of workaround is used which
- will work for tab sheets }
- // if Control is TWinControl then
- // DrawThemeParentBackground(TWinControl(Control).Handle, DC, @R);
- if Parent is TTabSheet then
- begin
- Theme := OpenThemeData(Parent.Handle, 'TAB');
- R2 := Parent.ClientRect;
- R2.TopLeft := Control.ScreenToClient(Parent.ClientToScreen(R2.TopLeft));
- R2.BottomRight := Control.ScreenToClient(Parent.ClientToScreen(R2.BottomRight));
- DrawThemeBackground(Theme, DC, TABP_BODY, 0, R2, @R);
- CloseThemeData(Theme);
- end
- else FillRectEx(DC, R, GetEffectiveColor(Parent));
- end;
- end;
- end;
- function GetViewType(View: TTBView): Integer;
- var
- Message: TMessage;
- begin
- Result := VT_UNKNOWN;
- if (View <> nil) and (View.Owner <> nil) then
- begin
- Message.Msg := TBM_GETVIEWTYPE;
- Message.WParam := 0;
- Message.LParam := 0;
- Message.Result := VT_UNKNOWN;
- View.Window.Dispatch(Message);
- Result := Message.Result;
- end;
- end;
- function GetWinViewType(Window: TControl): Integer;
- var
- Message: TMessage;
- begin
- Result := VT_UNKNOWN;
- if Window <> nil then
- begin
- Message.Msg := TBM_GETVIEWTYPE;
- Message.WParam := 0;
- Message.LParam := 0;
- Message.Result := VT_UNKNOWN;
- Window.Dispatch(Message);
- Result := Message.Result;
- end;
- end;
- function IsFloating(ViewType: Integer): Boolean;
- begin
- Result := ViewType and TVT_FLOATING <> 0;
- end;
- procedure UpdateNCArea(Control: TWinControl; ViewType: Integer);
- begin
- with Control do
- begin
- ClientWidth := ClientWidth;
- ClientHeight := ClientHeight;
- end;
- SetWindowPos(Control.Handle, 0, 0, 0, 0, 0,
- SWP_FRAMECHANGED or SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOMOVE or SWP_NOSIZE);
- Control.Invalidate;
- end;
- function GetPopupMargin(ItemViewer: TTBItemViewer): Integer;
- var
- ImgList: TCustomImageList;
- Sz: TSize;
- TextMetric: TTextMetric;
- H, M2: Integer;
- Margins: TTBXMargins;
- begin
- Sz.Cx := 0;
- Sz.Cy := 0;
- if ItemViewer is TTBXItemViewer then
- Sz := TTBXItemViewer(ItemViewer).GetImageSize;
- if (Sz.Cx = 0) or (Sz.Cy = 0) then
- begin
- ImgList := TTBItemViewerAccess(ItemViewer).GetImageList;
- if ImgList <> nil then
- begin
- Sz.Cx := ImgList.Width;
- Sz.Cy := ImgList.Height;
- end;
- if (Sz.Cx = 0) or (Sz.Cy = 0) then
- begin
- Sz.Cx := 16;
- Sz.Cy := 16;
- end;
- end;
- StockBitmap1.Canvas.Font := TTBViewAccess(ItemViewer.View).GetFont;
- GetTextMetrics(StockBitmap1.Canvas.Handle, TextMetric);
- CurrentTheme.GetMargins(MID_MENUITEM, Margins);
- M2 := Margins.TopHeight + Margins.BottomHeight;
- Result := TextMetric.tmHeight + TextMetric.tmExternalLeading + M2;
- H := Sz.CY + M2;
- if H > Result then Result := H;
- Result := (Sz.Cx + M2) * Result div H;
- end;
- procedure GetOfficeXPPopupPosition1(var PopupPositionRec: TTBPopupPositionRec);
- begin
- with PopupPositionRec do
- begin
- if not PositionAsSubmenu then
- begin
- NCSizeX := 0;
- NCSizeY := 0;
- Dec(ParentItemRect.Right);
- if X = ParentItemRect.Right + 1 then Dec(X);
- if X + W <= ParentItemRect.Left then Inc(X);
- Dec(ParentItemRect.Bottom);
- if Y = ParentItemRect.Bottom + 1 then Dec(Y);
- if Y + H <= ParentItemRect.Top then Inc(Y);
- Dec(W);
- Dec(H);
- end
- else
- begin
- Inc(X, NCSizeX);
- Inc(Y, NCSizeY);
- NCSizeX := 0;
- NCSizeY := 0;
- end;
- end;
- end;
- procedure GetOfficeXPPopupPosition2(var PopupPositionRec: TTBPopupPositionRec);
- begin
- with PopupPositionRec do if not PositionAsSubmenu then
- begin
- Inc(W);
- Inc(H);
- end;
- end;
- procedure AddToList(var List: TList; Item: Pointer);
- begin
- if List = nil then List := TList.Create;
- List.Add(Item)
- end;
- procedure RemoveFromList(var List: TList; Item: Pointer);
- begin
- if List <> nil then
- begin
- List.Remove(Item);
- if List.Count = 0 then
- begin
- List.Free;
- List := nil;
- end;
- end;
- end;
- //============================================================================//
- { Misc. Routines }
- procedure InvalidateAll(const Ctl: TWinControl);
- begin
- if Ctl.HandleAllocated then
- RedrawWindow(Ctl.Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
- RDW_ERASE);
- end;
- function GetStateFlags(const ItemInfo: TTBXItemInfo): Integer;
- const
- CEnabledStates: array [Boolean] of Integer = (ISF_DISABLED, 0);
- CHotStates: array [Boolean] of Integer = (0, ISF_HOT);
- CPushedStates: array [Boolean] of Integer = (0, ISF_PUSHED);
- CSelectedStates: array [Boolean] of Integer = (0, ISF_SELECTED);
- begin
- with ItemInfo do
- Result := CEnabledStates[ItemInfo.Enabled] or CPushedStates[ItemInfo.Pushed] or
- CHotStates[ItemInfo.HoverKind = hkMouseHover] or CSelectedStates[ItemInfo.Selected];
- end;
- function GetTBXTextColor(StateFlags: Integer): TColor;
- const
- HoverKinds: array [Boolean] of TTBXHoverKind = (hkNone, hkMouseHover);
- var
- ItemInfo: TTBXItemInfo;
- begin
- FillChar(ItemInfo, SizeOf(ItemInfo), 0);
- case StateFlags and ISF_LOCATIONMASK of
- ISF_TOOLBARCOLOR:
- begin
- ItemInfo.ViewType := VT_TOOLBAR;
- ItemInfo.ItemOptions := IO_TOOLBARSTYLE;
- end;
- ISF_MENUCOLOR:
- begin
- ItemInfo.ViewType := VT_DOCKPANEL;
- end;
- ISF_STATUSCOLOR:
- begin
- ItemInfo.ViewType := VT_STATUSBAR;
- end;
- else
- ItemInfo.ViewType := VT_UNKNOWN;
- end;
- ItemInfo.Enabled := StateFlags and ISF_DISABLED = 0;
- ItemInfo.Pushed := StateFlags and ISF_PUSHED <> 0;
- ItemInfo.HoverKind := HoverKinds[StateFlags and ISF_HOT <> 0];
- ItemInfo.Selected := StateFlags and ISF_SELECTED <> 0;
- Result := CurrentTheme.GetItemTextColor(ItemInfo);
- end;
- procedure DrawTBXCaption(Canvas: TCanvas; Rect: TRect; const Text: string; Format: Cardinal; StateFlags: Integer);
- const
- HoverKinds: array [Boolean] of TTBXHoverKind = (hkNone, hkMouseHover);
- var
- ItemInfo: TTBXItemInfo;
- begin
- FillChar(ItemInfo, SizeOf(ItemInfo), 0);
- case StateFlags and ISF_LOCATIONMASK of
- ISF_TOOLBARCOLOR:
- begin
- ItemInfo.ViewType := VT_TOOLBAR;
- ItemInfo.ItemOptions := IO_TOOLBARSTYLE;
- end;
- ISF_MENUCOLOR:
- begin
- ItemInfo.ViewType := VT_DOCKPANEL;
- end;
- ISF_STATUSCOLOR:
- begin
- ItemInfo.ViewType := VT_STATUSBAR;
- end;
- end;
- ItemInfo.Enabled := StateFlags and ISF_DISABLED = 0;
- ItemInfo.Pushed := StateFlags and ISF_PUSHED <> 0;
- ItemInfo.HoverKind := HoverKinds[StateFlags and ISF_HOT <> 0];
- ItemInfo.Selected := StateFlags and ISF_SELECTED <> 0;
- CurrentTheme.PaintCaption(Canvas, Rect, ItemInfo, Text, Format, False);
- end;
- procedure DrawTBXImage(Canvas: TCanvas; Rect: TRect; ImageList: TCustomImageList;
- ImageIndex: Integer; StateFlags: Integer);
- const
- HoverKinds: array [Boolean] of TTBXHoverKind = (hkNone, hkMouseHover);
- var
- ItemInfo: TTBXItemInfo;
- begin
- FillChar(ItemInfo, SizeOf(ItemInfo), 0);
- case StateFlags and ISF_LOCATIONMASK of
- ISF_TOOLBARCOLOR:
- begin
- ItemInfo.ViewType := VT_TOOLBAR;
- ItemInfo.ItemOptions := IO_TOOLBARSTYLE;
- end;
- ISF_MENUCOLOR:
- begin
- ItemInfo.ViewType := VT_DOCKPANEL;
- end;
- ISF_STATUSCOLOR:
- begin
- ItemInfo.ViewType := VT_STATUSBAR;
- end;
- end;
- ItemInfo.Enabled := not Boolean(StateFlags and ISF_DISABLED);
- ItemInfo.Pushed := Boolean(StateFlags and ISF_PUSHED);
- ItemInfo.HoverKind := HoverKinds[Boolean(StateFlags and ISF_HOT)];
- ItemInfo.Selected := Boolean(StateFlags and ISF_SELECTED);
- CurrentTheme.PaintImage(Canvas, Rect, ItemInfo, ImageList, ImageIndex);
- end;
- //============================================================================//
- { TFontSettings }
- procedure TFontSettings.Apply(Font: TFont);
- var
- FS: TFontStyles;
- begin
- if Size <> 100 then Font.Size := (Font.Size * FSize + 50) div 100;
- if Color <> clNone then Font.Color := Color;
- if Name <> '' then Font.Name := Name;
- FS := Font.Style;
- if Bold = tsTrue then Include(FS, fsBold)
- else if Bold = tsFalse then Exclude(FS, fsBold);
- if Italic = tsTrue then Include(FS, fsItalic)
- else if Italic = tsFalse then Exclude(FS, fsItalic);
- if Underline = tsTrue then Include(FS, fsUnderline)
- else if Underline = tsFalse then Exclude(FS, fsUnderline);
- if StrikeOut = tsTrue then Include(FS, fsStrikeOut)
- else if StrikeOut = tsFalse then Exclude(FS, fsStrikeOut);
- Font.Style := FS;
- end;
- procedure TFontSettings.Apply(var LF: TLogFont; var FontColor: TColor);
- begin
- if Size <> 100 then LF.lfHeight := (LF.lfHeight * Size + 50) div 100;
- if Color <> clNone then FontColor := Color;
- if Name <> '' then StrPLCopy(LF.lfFaceName, Name, 31);
- if Bold = tsTrue then LF.lfWeight := FW_BOLD
- else if Bold = tsFalse then LF.lfWeight := FW_NORMAL;
- if Italic = tsTrue then LF.lfItalic := 1
- else if Italic = tsFalse then LF.lfItalic := 0;
- if Underline = tsTrue then LF.lfUnderline := 1
- else if Underline = tsFalse then LF.lfUnderline := 0;
- if StrikeOut = tsTrue then LF.lfStrikeOut := 1
- else if StrikeOut = tsFalse then LF.lfStrikeOut := 0;
- end;
- procedure TFontSettings.Assign(Src: TPersistent);
- var
- F: TFontSettings;
- begin
- if Src is TPersistent then
- begin
- F := TFontSettings(Src);
- if (FBold <> F.Bold) or (FItalic <> F.Italic) or (FUnderline <> F.Underline) or
- (FStrikeOut <> F.StrikeOut) or (FSize <> F.Size) or (FColor <> F.Color) or
- (FName <> F.Name) then
- begin
- FBold := F.Bold;
- FItalic := F.Italic;
- FUnderline := F.Underline;
- FStrikeOut := F.StrikeOut;
- FSize := F.Size;
- FColor := F.Color;
- FName := F.Name;
- Modified;
- end;
- end
- else inherited;
- end;
- constructor TFontSettings.Create;
- begin
- FSize := 100;
- FColor := clNone;
- end;
- function TFontSettings.CreateTransformedFont(Src: HFont; var FontColor: TColor): HFont;
- var
- LF: TLogFont;
- begin
- GetObject(Src, SizeOf(LF), @LF);
- Apply(LF, FontColor);
- Result := CreateFontIndirect(LF);
- end;
- procedure TFontSettings.Modified;
- begin
- if Assigned(FOnChange) then FOnChange(Self);
- end;
- procedure TFontSettings.SetBold(Value: TTriState);
- begin
- if FBold <> Value then
- begin
- FBold := Value;
- Modified;
- end;
- end;
- procedure TFontSettings.SetColor(Value: TColor);
- begin
- if FColor <> Value then
- begin
- FColor := Value;
- Modified;
- end;
- end;
- procedure TFontSettings.SetItalic(Value: TTriState);
- begin
- if FItalic <> Value then
- begin
- FItalic := Value;
- Modified;
- end;
- end;
- procedure TFontSettings.SetName(const Value: TFontName);
- begin
- if FName <> Value then
- begin
- FName := Value;
- Modified;
- end;
- end;
- procedure TFontSettings.SetSize(Value: TFontSize);
- begin
- if FSize <> Value then
- begin
- FSize := Value;
- Modified;
- end;
- end;
- procedure TFontSettings.SetStrikeOut(Value: TTriState);
- begin
- if FStrikeOut <> Value then
- begin
- FStrikeOut := Value;
- Modified;
- end;
- end;
- procedure TFontSettings.SetUnderline(Value: TTriState);
- begin
- if FUnderline <> Value then
- begin
- FUnderline := Value;
- Modified;
- end;
- end;
- //============================================================================//
- { TTBXCustomItem }
- constructor TTBXCustomItem.Create(AOwner: TComponent);
- begin
- inherited;
- FFontSettings := TFontSettings.Create;
- FFontSettings.OnChange := FontSettingsChanged;
- end;
- function TTBXCustomItem.CreatePopup(const ParentView: TTBView;
- const ParentViewer: TTBItemViewer; const PositionAsSubmenu,
- SelectFirstItem, Customizing: Boolean; const APopupPoint: TPoint;
- const Alignment: TTBPopupAlignment): TTBPopupWindow;
- var
- DoSelectFirstItem: Boolean;
- begin
- if AlwaysSelectFirst then DoSelectFirstItem := True
- else DoSelectFirstItem := SelectFirstItem;
- Result := inherited CreatePopup(ParentView, ParentViewer, PositionAsSubmenu,
- DoSelectFirstItem, Customizing, APopupPoint, Alignment);
- end;
- destructor TTBXCustomItem.Destroy;
- begin
- FFontSettings.Free;
- inherited;
- end;
- procedure TTBXCustomItem.FontSettingsChanged(Sender: TObject);
- begin
- Change(True);
- end;
- function TTBXCustomItem.GetItemViewerClass(AView: TTBView): TTBItemViewerClass;
- begin
- Result := TTBXItemViewer;
- end;
- procedure TTBXCustomItem.GetPopupPosition(ParentView: TTBView;
- PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec);
- var
- VT: Integer;
- begin
- if CurrentTheme.OfficeXPPopupAlignment then with PopupPositionRec do
- begin
- GetOfficeXPPopupPosition1(PopupPositionRec);
- inherited GetPopupPosition(ParentView, PopupWindow, PopupPositionRec);
- GetOfficeXPPopupPosition2(PopupPositionRec);
- VT := GetWinViewType(PopupWindow);
- PopupPositionRec.PlaySound := not (VT and PVT_LISTBOX = PVT_LISTBOX);
- end
- else inherited;
- end;
- function TTBXCustomItem.GetPopupWindowClass: TTBPopupWindowClass;
- begin
- Result := TTBXPopupWindow;
- end;
- function TTBXCustomItem.GetStretch: Boolean;
- begin
- Result := tbisStretch in ItemStyle;
- end;
- procedure TTBXCustomItem.Invalidate;
- begin
- Change(False);
- end;
- procedure TTBXCustomItem.SetFontSettings(Value: TFontSettings);
- begin
- FFontSettings.Assign(Value);
- end;
- procedure TTBXCustomItem.SetLayout(Value: TTBXItemLayout);
- begin
- if Value <> FLayout then
- begin
- FLayout := Value;
- Change(True);
- end;
- end;
- procedure TTBXCustomItem.SetMinHeight(Value: Integer);
- begin
- if Value <> FMinHeight then
- begin
- FMinHeight := Value;
- Change(True);
- end;
- end;
- procedure TTBXCustomItem.SetMinWidth(Value: Integer);
- begin
- if Value <> FMinWidth then
- begin
- FMinWidth := Value;
- Change(True);
- end;
- end;
- procedure TTBXCustomItem.SetStretch(Value: Boolean);
- begin
- if Value xor (tbisStretch in ItemStyle) then
- begin
- if Value then ItemStyle := ItemStyle + [tbisStretch]
- else ItemStyle := ItemStyle - [tbisStretch];
- Change(True);
- end;
- end;
- //============================================================================//
- { TTBXItemViewer }
- procedure TTBXItemViewer.CalcSize(const Canvas: TCanvas; var AWidth, AHeight: Integer);
- const
- CMarginIDs: array [Boolean] of Integer = (MID_MENUITEM, MID_TOOLBARITEM);
- CStartSize: array [Boolean] of Integer = (0, 6);
- var
- W, H: Integer;
- ImgSize: TSize;
- Item: TTBCustomItem;
- ItemLayout, SaveLayout: TTBXItemLayout;
- IsCaptionShown: Boolean;
- IsTextRotated: Boolean;
- ToolbarStyle: Boolean;
- S: string;
- TextFlags: Cardinal;
- TextMetric: TTextMetric;
- TextSize: TSize;
- Margins: TTBXMargins;
- begin
- Item := TTBCustomItem(Self.Item);
- ToolbarStyle := IsToolbarStyle;
- ImgSize := GetImageSize;
- if (ImgSize.CX <= 0) or (ImgSize.CY <= 0) then
- begin
- ImgSize.CX := 0;
- ImgSize.CY := 0;
- end;
- if Item is TTBXCustomItem then ItemLayout := TTBXCustomItem(Item).Layout
- else ItemLayout := tbxlAuto;
- SaveLayout := ItemLayout;
- if ItemLayout = tbxlAuto then
- begin
- if tboImageAboveCaption in Item.EffectiveOptions then ItemLayout := tbxlGlyphTop
- else
- begin
- if View.Orientation <> tbvoVertical then ItemLayout := tbxlGlyphLeft
- else ItemLayout := tbxlGlyphTop;
- end;
- end;
- { Setup font }
- TextFlags := 0;
- IsCaptionShown := CaptionShown;
- IsTextRotated := (View.Orientation = tbvoVertical) and ToolbarStyle;
- if IsCaptionShown then
- begin
- S := GetCaptionText;
- if not (SaveLayout = tbxlAuto) or (tboImageAboveCaption in Item.EffectiveOptions) then IsTextRotated := False;
- if IsTextRotated or not ToolbarStyle then TextFlags := DT_SINGLELINE;
- TextSize := GetTextSize(Canvas, S, TextFlags, IsTextRotated, 0);
- end
- else
- begin
- SetLength(S, 0);
- TextSize.CX := 0;
- TextSize.CY := 0;
- IsTextRotated := False;
- end;
- { Measure size }
- if ToolbarStyle then
- begin
- AWidth := 6;
- AHeight := 6;
- if CaptionShown then
- begin
- Inc(AWidth, TextSize.CX);
- Inc(AHeight, TextSize.CY);
- if not IsTextRotated then Inc(AWidth, 4)
- else Inc(AHeight, 4);
- end;
- if GetImageShown and (ImgSize.CX > 0) and (ImgSize.CY > 0) then
- begin
- if ItemLayout = tbxlGlyphLeft then
- begin
- Inc(AWidth, ImgSize.CX);
- if Wide then Inc(AWidth);
- if AHeight < ImgSize.CY + 6 then AHeight := ImgSize.CY + 6;
- end
- else
- begin
- Inc(AHeight, ImgSize.CY);
- if AWidth < ImgSize.CX + 7 then AWidth := ImgSize.CX + 7;
- end;
- end;
- if tbisSubmenu in TTBItemAccess(Item).ItemStyle then with CurrentTheme do
- begin
- if tbisCombo in TTBItemAccess(Item).ItemStyle then Inc(AWidth, SplitBtnArrowWidth)
- else if tboDropdownArrow in Item.EffectiveOptions then
- begin
- if (ItemLayout <> tbxlGlyphTop) or (ImgSize.CX = 0) or IsTextRotated then
- begin
- if View.Orientation <> tbvoVertical then Inc(AWidth, DropdownArrowWidth)
- else Inc(AHeight, DropdownArrowWidth);
- end
- else
- begin
- if (ItemLayout = tbxlGlyphTop) and (IsTextRotated xor (View.Orientation <> tbvoVertical)) then
- begin
- W := ImgSize.CX + DropDownArrowWidth + 2;
- if W > AWidth - 7 then AWidth := W + 7;
- end
- else
- begin
- H := ImgSize.CY + DropDownArrowWidth + 2;
- if H > AHeight - 7 then AHeight := H + 7;
- end;
- end
- end;
- end;
- end
- else // Not a ToolbarStyle
- with CurrentTheme do
- begin
- GetTextMetrics(Canvas.Handle, TextMetric);
- Inc(TextSize.CY, TextMetric.tmExternalLeading);
- AWidth := TextSize.CX;
- AHeight := TextSize.CY;
- if ImgSize.CY = 0 then ImgSize.CY := 16;
- if AHeight < ImgSize.CY then AHeight := ImgSize.CY;
- GetMargins(MID_MENUITEM, Margins);
- Inc(AWidth, Margins.LeftWidth + Margins.RightWidth);
- Inc(AHeight, Margins.TopHeight + Margins.BottomHeight);
- Inc(AWidth, GetPopupMargin(Self) + MenuImageTextSpace + MenuLeftCaptionMargin + MenuRightCaptionMargin);
- S := Item.GetShortCutText;
- if Length(S) > 0 then Inc(AWidth, (AHeight - 6) + GetTextWidth(Canvas.Handle, S, True));
- Inc(AWidth, AHeight); { Note: maybe this should be controlled by the theme }
- end;
- if Item is TTBXCustomItem then with TTBXCustomItem(Item) do
- begin
- if AWidth < MinWidth then AWidth := MinWidth;
- if AHeight < MinHeight then AHeight := MinHeight;
- end;
- end;
- constructor TTBXItemViewer.Create(AView: TTBView; AItem: TTBCustomItem; AGroupLevel: Integer);
- begin
- inherited;
- FWide := True;
- end;
- procedure TTBXItemViewer.DoAdjustFont(AFont: TFont; StateFlags: Integer);
- begin
- if tboDefault in Item.EffectiveOptions then with AFont do Style := Style + [fsBold];
- if Item is TTBXCustomItem then
- with TTBXCustomItem(Item) do
- begin
- FontSettings.Apply(AFont);
- if Assigned(FOnAdjustFont) then FOnAdjustFont(Item, Self, AFont, StateFlags);
- end
- else if Item is TTBXEditItem then
- with TTBXEditItem(Item) do
- begin
- FontSettings.Apply(AFont);
- end;
- end;
- procedure TTBXItemViewer.DoPaintCaption(Canvas: TCanvas; const ClientAreaRect: TRect;
- var CaptionRect: TRect; IsTextRotated: Boolean; var PaintDefault: Boolean);
- begin
- // do nothing
- end;
- procedure TTBXItemViewer.DrawItemImage(Canvas: TCanvas; ARect: TRect; ItemInfo: TTBXItemInfo);
- var
- ImgList: TCustomImageList;
- I: TTBXCustomItem;
- begin
- ImgList := GetImageList;
- if (ImgList <> nil) and (Item.ImageIndex >= 0) and (Item.ImageIndex < ImgList.Count) then
- begin
- CurrentTheme.PaintImage(Canvas, ARect, ItemInfo, ImgList, Item.ImageIndex);
- if Item is TTBXCustomItem then
- begin
- I := TTBXCustomItem(Item);
- if Assigned(I.FOnDrawImage) then
- I.FOnDrawImage(I, Self, Canvas, ARect,
- CurrentTheme.GetImageOffset(Canvas, ItemInfo, ImgList),
- GetStateFlags(ItemInfo));
- end;
- end;
- end;
- function TTBXItemViewer.GetAccRole: Integer;
- { Returns the MSAA "role" of the viewer. }
- const
- { Constants from OleAcc.h }
- ROLE_SYSTEM_BUTTONDROPDOWNGRID = $3A;
- begin
- Result := inherited GetAccRole;
- if (Item is TTBXCustomItem) and TTBXCustomItem(Item).ToolBoxPopup and
- (tbisSubmenu in TTBXCustomItem(Item).ItemStyle) then
- Result := ROLE_SYSTEM_BUTTONDROPDOWNGRID;
- end;
- function TTBXItemViewer.GetImageShown: Boolean;
- begin
- Result := (Item.ImageIndex >= 0) and
- ((Item.DisplayMode in [nbdmDefault, nbdmImageAndText]) or
- (IsToolbarStyle and (Item.DisplayMode = nbdmTextOnlyInMenus)));
- end;
- function TTBXItemViewer.GetImageSize: TSize;
- var
- ImgList: TCustomImageList;
- begin
- ImgList := GetImageList;
- with Result do if ImgList <> nil then
- begin
- CX := ImgList.Width;
- CY := ImgList.Height;
- end
- else
- begin
- CX := 0;
- CY := 0;
- end;
- end;
- function TTBXItemViewer.GetItemType: Integer;
- begin
- if IsToolbarStyle then Result := IT_TOOLBARBUTTON
- else Result := IT_MENUITEM;
- end;
- function TTBXItemViewer.GetTextFlags: Cardinal;
- begin
- Result := 0;
- if not AreKeyboardCuesEnabled and (vsUseHiddenAccels in View.Style) and
- not (vsShowAccels in View.State) then Result := DT_HIDEPREFIX;
- end;
- function TTBXItemViewer.GetTextSize(Canvas: TCanvas; const Text: string;
- TextFlags: Cardinal; Rotated: Boolean; StateFlags: Integer): TSize;
- var
- DC: HDC;
- R: TRect;
- RotatedFont, SaveFont: HFONT;
- TextMetric: TTextMetric;
- begin
- { note: rotated font size is consistent only for single-line captions! }
- if Length(Text) = 0 then with Result do
- begin
- CX := 0;
- CY := 0;
- Exit;
- end;
- { Select proper font }
- Canvas.Font := TTBViewAccess(View).GetFont;
- DoAdjustFont(Canvas.Font, StateFlags);
- if not Rotated then with R, Result do
- begin
- Left := 0; Right := 1;
- Top := 0; Bottom := 0;
- DrawText(Canvas.Handle, PChar(Text), Length(Text), R, TextFlags or DT_CALCRECT);
- CX := Right;
- CY := Bottom;
- end
- else
- begin
- DC := Canvas.Handle;
- RotatedFont := CreateRotatedFont(DC);
- SaveFont := SelectObject(DC, RotatedFont);
- GetTextMetrics(DC, TextMetric);
- Result.CX := TextMetric.tmHeight;
- Result.CY := GetTextWidth(DC, Text, True);
- SelectObject(DC, SaveFont);
- DeleteObject(RotatedFont);
- end;
- end;
- function TTBXItemViewer.IsPtInButtonPart(X, Y: Integer): Boolean;
- var
- W: Integer;
- begin
- Result := not (tbisSubmenu in TTBItemAccess(Item).ItemStyle);
- if (tbisCombo in TTBItemAccess(Item).ItemStyle) then
- begin
- if IsToolbarStyle then W := CurrentTheme.SplitBtnArrowWidth
- else W := GetSystemMetrics(SM_CXMENUCHECK);
- Result := X < (BoundsRect.Right - BoundsRect.Left) - W;
- end;
- end;
- function TTBXItemViewer.IsToolbarSize: Boolean;
- begin
- Result := inherited IsToolbarSize;
- Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
- end;
- function TTBXItemViewer.IsToolbarStyle: Boolean;
- begin
- Result := inherited IsToolbarStyle;
- Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
- end;
- procedure TTBXItemViewer.MouseUp(X, Y: Integer; MouseWasDownOnMenu: Boolean);
- begin
- inherited;
- { Force the item to behave as a 'normal' menu item
- That is make it respond to mouse as an item with IsToolbarStyle = False }
- if Item.Enabled and not ((tbisSubmenu in TTBItemAccess(Item).ItemStyle) and
- not IsPtInButtonPart(X, Y)) then
- begin
- if View.MouseOverSelected then
- begin
- Execute(True);
- end;
- end;
- end;
- procedure TTBXItemViewer.Paint(const Canvas: TCanvas;
- const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean);
- const
- CToolbarStyle: array [Boolean] of Integer = (0, IO_TOOLBARSTYLE);
- CCombo: array [Boolean] of Integer = (0, IO_COMBO);
- CSubmenuItem: array [Boolean] of Integer = (0, IO_SUBMENUITEM);
- CDesigning: array [Boolean] of Integer = (0, IO_DESIGNING);
- CAppActive: array [Boolean] of Integer = (0, IO_APPACTIVE);
- var
- Item: TTBXCustomItem;
- View: TTBViewAccess;
- ItemInfo: TTBXItemInfo;
- {M: Integer;} {vb-}
- R: TRect;
- ComboRect: TRect;
- CaptionRect: TRect;
- ImageRect: TRect;
- C: TColor;
- ToolbarStyle: Boolean;
- HasArrow: Boolean;
- IsSplit: Boolean;
- ImageIsShown: Boolean;
- ImageOrCheckShown: Boolean;
- ImgAndArrowWidth: Integer;
- ImgSize: TSize;
- IsComboPushed: Boolean;
- IsCaptionShown: Boolean;
- IsTextRotated: Boolean;
- ItemLayout: TTBXItemLayout;
- PaintDefault: Boolean;
- S: string;
- StateFlags: Integer;
- IsSpecialDropDown: Boolean;
- TextFlags: Cardinal;
- TextMetrics: TTextMetric;
- TextSize: TSize;
- Margins: TTBXMargins;
- begin
- Item := TTBXCustomItem(Self.Item);
- View := TTBViewAccess(Self.View);
- ToolbarStyle := IsToolbarStyle;
- IsSplit := tbisCombo in Item.ItemStyle;
- IsComboPushed := IsSplit and IsPushed and not View.Capture;
- if IsComboPushed then IsPushed := False;
- if GetImageShown then
- begin
- ImgSize := GetImageSize;
- with ImgSize do if (CX <= 0) or (CY <= 0) then
- begin
- CX := 0;
- CY := 0;
- ImageIsShown := False;
- end
- else ImageIsShown := True;
- end
- else
- begin
- ImgSize.CX := 0;
- ImgSize.CY := 0;
- ImageIsShown := False;
- end;
- IsSplit := tbisCombo in Item.ItemStyle;
- FillChar(ItemInfo, SizeOf(ItemInfo), 0);
- ItemInfo.ViewType := GetViewType(View);
- ItemInfo.ItemOptions := CToolbarStyle[ToolbarStyle] or CCombo[IsSplit] or
- CDesigning[csDesigning in Item.ComponentState] or CSubmenuItem[tbisSubmenu in Item.ItemStyle] or
- CAppActive[Application.Active];
- ItemInfo.Enabled := Item.Enabled or View.Customizing;
- ItemInfo.Pushed := IsPushed;
- ItemInfo.Selected := Item.Checked;
- ItemInfo.ImageShown := ImageIsShown;
- ItemInfo.ImageWidth := ImgSize.CX;
- ItemInfo.ImageHeight := ImgSize.CY;
- if IsHoverItem then
- begin
- if not ItemInfo.Enabled and not View.MouseOverSelected then ItemInfo.HoverKind := hkKeyboardHover
- else if ItemInfo.Enabled then ItemInfo.HoverKind := hkMouseHover;
- end
- else ItemInfo.HoverKind := hkNone;
- ItemInfo.IsPopupParent := ToolbarStyle and
- (((vsModal in View.State) and Assigned(View.OpenViewer)) or (tbisSubmenu in Item.ItemStyle)) and
- ((IsSplit and IsComboPushed) or (not IsSplit and IsPushed));
- ItemInfo.IsVertical := (View.Orientation = tbvoVertical) and not IsSplit;
- ItemInfo.PopupMargin := GetPopupMargin(Self);
- ItemLayout := Item.Layout;
- if ItemLayout = tbxlAuto then
- begin
- if tboImageAboveCaption in Item.EffectiveOptions then ItemLayout := tbxlGlyphTop
- else if View.Orientation <> tbvoVertical then ItemLayout := tbxlGlyphLeft
- else ItemLayout := tbxlGlyphTop;
- end;
- HasArrow := (tbisSubmenu in Item.ItemStyle) and
- ((tbisCombo in Item.ItemStyle) or (tboDropdownArrow in Item.EffectiveOptions));
- if GetImageShown then
- begin
- ImgSize := GetImageSize;
- with ImgSize do if (CX <= 0) or (CY <= 0) then
- begin
- CX := 0;
- CY := 0;
- ImageIsShown := False;
- end
- else ImageIsShown := True;
- end
- else
- begin
- ImgSize.CX := 0;
- ImgSize.CY := 0;
- ImageIsShown := False;
- end;
- ImageOrCheckShown := ImageIsShown or (not ToolbarStyle and Item.Checked);
- StateFlags := GetStateFlags(ItemInfo);
- Canvas.Font := TTBViewAccess(View).GetFont;
- Canvas.Font.Color := CurrentTheme.GetItemTextColor(ItemInfo);
- DoAdjustFont(Canvas.Font, StateFlags);
- C := Canvas.Font.Color;
- { Setup font }
- TextFlags := GetTextFlags;
- IsCaptionShown := CaptionShown;
- IsTextRotated := (View.Orientation = tbvoVertical) and ToolbarStyle;
- if IsCaptionShown then
- begin
- S := GetCaptionText;
- if (Item.Layout <> tbxlAuto) or (tboImageAboveCaption in Item.EffectiveOptions) then
- IsTextRotated := False;
- if IsTextRotated or not ToolbarStyle then TextFlags := TextFlags or DT_SINGLELINE;
- TextSize := GetTextSize(Canvas, S, TextFlags, IsTextRotated, StateFlags);
- end
- else
- begin
- StateFlags := 0;
- SetLength(S, 0);
- IsTextRotated := False;
- TextSize.CX := 0;
- TextSize.CY := 0;
- end;
- IsSpecialDropDown := HasArrow and not IsSplit and ToolbarStyle and
- ((Item.Layout = tbxlGlyphTop) or (Item.Layout = tbxlAuto) and (tboImageAboveCaption in Item.EffectiveOptions)) and
- (ImgSize.CX > 0) and not (IsTextRotated) and (TextSize.CX > 0);
- { Border & Arrows }
- R := ClientAreaRect;
- with CurrentTheme do if ToolbarStyle then
- begin
- GetMargins(MID_TOOLBARITEM, Margins);
- if HasArrow then with R do
- begin
- ItemInfo.ComboPart := cpCombo;
- if IsSplit then
- begin
- ItemInfo.ComboPart := cpSplitLeft;
- ComboRect := R;
- Dec(Right, SplitBtnArrowWidth);
- ComboRect.Left := Right;
- end
- else if not IsSpecialDropDown then
- begin
- if View.Orientation <> tbvoVertical then
- ComboRect := Rect(Right - DropdownArrowWidth - DropdownArrowMargin, 0,
- Right - DropdownArrowMargin, Bottom)
- else
- ComboRect := Rect(0, Bottom - DropdownArrowWidth - DropdownArrowMargin,
- Right, Bottom - DropdownArrowMargin);
- end
- else
- begin
- ImgAndArrowWidth := ImgSize.CX + DropdownArrowWidth + 2;
- ComboRect.Right := (R.Left + R.Right + ImgAndArrowWidth + 2) div 2;
- ComboRect.Left := ComboRect.Right - DropdownArrowWidth;
- ComboRect.Top := (R.Top + R.Bottom - ImgSize.cy - 2 - TextSize.CY) div 2;
- ComboRect.Bottom := ComboRect.Top + ImgSize.CY;
- end;
- end
- else SetRectEmpty(ComboRect);
- if not IsSplit then
- begin
- PaintButton(Canvas, R, ItemInfo);
- if HasArrow then
- begin
- PaintDropDownArrow(Canvas, ComboRect, ItemInfo);
- if not IsSpecialDropDown then
- begin
- if View.Orientation <> tbvoVertical then Dec(R.Right, DropdownArrowWidth)
- else Dec(R.Bottom, DropdownArrowWidth);
- end;
- end;
- end
- else // IsSplit
- begin
- CurrentTheme.PaintButton(Canvas, R, ItemInfo);
- ItemInfo.Pushed := IsComboPushed;
- ItemInfo.Selected := False;
- ItemInfo.ComboPart := cpSplitRight;
- CurrentTheme.PaintButton(Canvas, ComboRect, ItemInfo);
- ItemInfo.ComboPart := cpSplitLeft;
- ItemInfo.Pushed := IsPushed;
- ItemInfo.Selected := Item.Checked;
- end;
- InflateRect(R, -2, -2);
- end
- else // not toolbar style
- begin
- GetMargins(MID_MENUITEM, Margins);
- PaintMenuItem(Canvas, R, ItemInfo);
- Inc(R.Left, Margins.LeftWidth);
- Dec(R.Right, Margins.RightWidth);
- Inc(R.Top, Margins.TopHeight);
- Dec(R.Bottom, Margins.BottomHeight);
- end;
- { Caption }
- if IsCaptionShown then
- begin
- if ToolbarStyle then
- begin
- CaptionRect := R;
- TextFlags := TextFlags or DT_CENTER or DT_VCENTER;
- if ImageIsShown then with CaptionRect do
- case ItemLayout of
- tbxlGlyphLeft:
- begin
- Inc(Left, ImgSize.CX + 3);
- Top := (Top + Bottom - TextSize.CY) div 2;
- Bottom := Top + TextSize.CY;
- Left := (Left + Right - TextSize.CX) div 2;
- Right := Left + TextSize.CX;
- TextFlags := TextFlags and not DT_CENTER;
- end;
- tbxlGlyphTop:
- begin
- Inc(Top, ImgSize.CY + 1);
- if IsTextRotated then Inc(CaptionRect.Top, 3);
- Top := (Top + Bottom - TextSize.CY) div 2;
- Bottom := Top + TextSize.CY;
- Left := (Left + Right - TextSize.CX) div 2;
- Right := Left + TextSize.CX;
- TextFlags := TextFlags and not DT_VCENTER;
- end;
- end
- else
- begin
- with CaptionRect, TextSize do
- begin
- Left := (Left + R.Right - CX) div 2;
- Top := (Top + R.Bottom - CY) div 2;
- Right := Left + CX;
- Bottom := Top + CY;
- end;
- end;
- Canvas.Font.Color := C;
- PaintDefault := True;
- DoPaintCaption(Canvas, ClientAreaRect, CaptionRect, IsTextRotated, PaintDefault);
- if PaintDefault then
- CurrentTheme.PaintCaption(Canvas, CaptionRect, ItemInfo, S, TextFlags, IsTextRotated);
- end
- else with CurrentTheme do
- begin
- TextFlags := DT_LEFT or DT_VCENTER or TextFlags;
- TextSize := GetTextSize(Canvas, S, TextFlags, False, StateFlags); { TODO : Check if this line is required }
- GetTextMetrics(Canvas.Handle, TextMetrics);
- CaptionRect := R;
- Inc(CaptionRect.Left, ItemInfo.PopupMargin + MenuImageTextSpace + MenuLeftCaptionMargin);
- with TextMetrics, CaptionRect do
- if (Bottom - Top) - (tmHeight + tmExternalLeading) = Margins.BottomHeight then Dec(Bottom);
- Inc(CaptionRect.Top, TextMetrics.tmExternalLeading);
- CaptionRect.Right := CaptionRect.Left + TextSize.CX;
- Canvas.Font.Color := C;
- PaintDefault := True;
- DoPaintCaption(Canvas, ClientAreaRect, CaptionRect, IsTextRotated, PaintDefault);
- if PaintDefault then
- CurrentTheme.PaintCaption(Canvas, CaptionRect, ItemInfo, S, TextFlags, IsTextRotated);
- end;
- end;
- { Shortcut and/or submenu arrow (menus only) }
- if not ToolbarStyle then
- begin
- S := Item.GetShortCutText;
- if Length(S) > 0 then
- begin
- CaptionRect := R;
- with CaptionRect, TextMetrics do
- begin
- Left := Right - (Bottom - Top) - GetTextWidth(Canvas.Handle, S, True);
- if (Bottom - Top) - (tmHeight + tmExternalLeading) = Margins.BottomHeight then Dec(Bottom);
- Inc(Top, TextMetrics.tmExternalLeading);
- end;
- Canvas.Font.Color := C;
- PaintDefault := True;
- DoPaintCaption(Canvas, ClientAreaRect, CaptionRect, IsTextRotated, PaintDefault);
- if PaintDefault then
- CurrentTheme.PaintCaption(Canvas, CaptionRect, ItemInfo, S, TextFlags, False);
- end;
- end;
- { Image, or check box }
- if ImageOrCheckShown then
- begin
- ImageRect := R;
- if ToolBarStyle then
- begin
- if IsSpecialDropDown then OffsetRect(ImageRect, (-CurrentTheme.DropdownArrowWidth + 1) div 2, 0);
- if ItemLayout = tbxlGlyphLeft then ImageRect.Right := ImageRect.Left + ImgSize.CX + 2
- else
- begin
- ImageRect.Top := (ImageRect.Top + ImageRect.Bottom - ImgSize.cy - 2 - TextSize.cy) div 2;
- ImageRect.Bottom := ImageRect.Top + ImgSize.CY;
- end;
- end
- else ImageRect.Right := ImageRect.Left + ClientAreaRect.Bottom - ClientAreaRect.Top;
- if ImageIsShown then with ImageRect, ImgSize do
- begin
- Left := Left + ((Right - Left) - CX) div 2;
- ImageRect.Top := Top + ((Bottom - Top) - CY) div 2;
- Right := Left + CX;
- Bottom := Top + CY;
- DrawItemImage(Canvas, ImageRect, ItemInfo);
- end
- {else if not ToolbarStyle and Item.Checked then
- CurrentTheme.PaintCheckMark(Canvas, ImageRect, ItemInfo);} {vb-}
- else {vb+}
- if not ToolbarStyle and Item.Checked then
- begin
- if Item.RadioItem then
- with ItemInfo do ItemOptions := ItemOptions or IO_RADIO;
- CurrentTheme.PaintCheckMark(Canvas, ImageRect, ItemInfo);
- end;
- end;
- end;
- //============================================================================//
- { TTBXSubmenuItem }
- constructor TTBXSubmenuItem.Create(AOwner: TComponent);
- begin
- inherited;
- ItemStyle := ItemStyle + [tbisSubMenu, tbisSubitemsEditable];
- end;
- function TTBXSubmenuItem.GetDropdownCombo: Boolean;
- begin
- Result := tbisCombo in ItemStyle;
- end;
- procedure TTBXSubmenuItem.SetDropdownCombo(Value: Boolean);
- begin
- if (tbisCombo in ItemStyle) <> Value then begin
- if Value then ItemStyle := ItemStyle + [tbisCombo]
- else ItemStyle := ItemStyle - [tbisCombo];
- Change (True);
- end;
- end;
- //============================================================================//
- { TTBXSeparatorItem }
- constructor TTBXSeparatorItem.Create(AOwner: TComponent);
- begin
- inherited;
- FSize := -1; // use default from as in TTBSeparatorItem
- end;
- function TTBXSeparatorItem.GetItemViewerClass(AView: TTBView): TTBItemViewerClass;
- begin
- Result := TTBXSeparatorItemViewer;
- end;
- procedure TTBXSeparatorItem.SetSize(Value: Integer);
- begin
- if Value < -1 then Value := -1;
- if Value <> FSize then
- begin
- FSize := Value;
- Change(True);
- end;
- end;
- //============================================================================//
- { TTBXSeparatorItemViewer }
- procedure TTBXSeparatorItemViewer.CalcSize(const Canvas: TCanvas;
- var AWidth, AHeight: Integer);
- var
- SZ: Integer;
- begin
- SZ := TTBXSeparatorItem(Item).Size;
- if SZ < 0 then
- begin
- if not IsToolbarStyle then SZ := CurrentTheme.MenuSeparatorSize
- else SZ := CurrentTheme.TlbrSeparatorSize;
- if SZ < 0 then inherited CalcSize(Canvas, AWidth, AHeight)
- else
- begin
- AWidth := SZ;
- AHeight := SZ;
- end;
- end
- else if not IsToolbarStyle then
- begin
- AHeight := SZ;
- AWidth := 0;
- end
- else
- begin
- AWidth := SZ;
- AHeight := SZ;
- end;
- end;
- function TTBXSeparatorItemViewer.IsToolbarSize: Boolean;
- begin
- Result := inherited IsToolbarSize;
- Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
- end;
- function TTBXSeparatorItemViewer.IsToolbarStyle: Boolean;
- begin
- Result := inherited IsToolbarStyle;
- Result := Result or ((GetViewType(View) and PVT_TOOLBOX) = PVT_TOOLBOX);
- end;
- procedure TTBXSeparatorItemViewer.Paint(const Canvas: TCanvas;
- const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean);
- const
- CToolbarStyle: array [Boolean] of Integer = (0, IO_TOOLBARSTYLE);
- CDesigning: array [Boolean] of Integer = (0, IO_DESIGNING);
- var
- Item: TTBXSeparatorItem;
- ItemInfo: TTBXItemInfo;
- R: TRect;
- LineSep, HorzLine: Boolean;
- begin
- Item := TTBXSeparatorItem(Self.Item);
- if Item.Size = 0 then Exit;
- FillChar(ItemInfo, SizeOf(TTBXItemInfo), 0);
- ItemInfo.ViewType := GetViewType(View);
- ItemInfo.ItemOptions := CToolbarStyle[IsToolbarStyle] or
- CDesigning[csDesigning in Item.ComponentState];
- ItemInfo.Enabled := not Item.Blank;
- ItemInfo.Pushed := IsPushed;
- ItemInfo.Selected := False;
- ItemInfo.ImageShown := False;
- ItemInfo.ImageWidth := 0;
- ItemInfo.ImageHeight := 0;
- ItemInfo.IsVertical := View.Orientation = tbvoVertical;
- if not IsToolbarStyle then ItemInfo.PopupMargin := GetPopupMargin(Self);
- R := ClientAreaRect;
- LineSep := tbisLineSep in State;
- with ItemInfo do
- begin
- HorzLine := (IsVertical xor LineSep) or View.IsPopup;
- if (((ViewType and VT_POPUP) = VT_POPUP) and
- ((ViewType and PVT_CHEVRONMENU) = PVT_CHEVRONMENU)) then
- HorzLine := (HorzLine and LineSep);
- end;
- CurrentTheme.PaintSeparator(Canvas, R, ItemInfo, HorzLine, LineSep);
- end;
- //============================================================================//
- {$IFNDEF MPEXCLUDE}
- { TTBXVisibilityToggleItem }
- procedure TTBXVisibilityToggleItem.Click;
- begin
- if Assigned(FControl) then FControl.Visible := not FControl.Visible;
- inherited;
- end;
- procedure TTBXVisibilityToggleItem.InitiateAction;
- begin
- UpdateProps;
- end;
- procedure TTBXVisibilityToggleItem.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited;
- if (Operation = opRemove) and (AComponent = FControl) then Control := nil;
- end;
- procedure TTBXVisibilityToggleItem.SetControl(Value: TControl);
- begin
- if FControl <> Value then
- begin
- FControl := Value;
- if Assigned(Value) then
- begin
- Value.FreeNotification(Self);
- if (Length(Caption) = 0) and not (csLoading in ComponentState) then
- Caption := TControlAccess(Value).Caption;
- end;
- UpdateProps;
- end;
- end;
- procedure TTBXVisibilityToggleItem.UpdateProps;
- begin
- if (ComponentState * [csDesigning, csLoading, csDestroying] = []) then
- Checked := Assigned(FControl) and FControl.Visible;
- end;
- {$ENDIF}
- //============================================================================//
- { TTBXPopupWindow }
- procedure TTBXPopupWindow.CMHintShow(var Message: TCMHintShow);
- begin
- with Message.HintInfo^ do
- begin
- HintStr := '';
- if Assigned(View.Selected) then
- begin
- CursorRect := View.Selected.BoundsRect;
- HintStr := View.Selected.GetHintText;
- View.Selected.Dispatch(Message);
- end;
- end;
- end;
- procedure TTBXPopupWindow.CMShowingChanged(var Message: TMessage); {vb+}
- const
- ShowFlags: array[Boolean] of UINT = (
- SWP_NOSIZE or SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_HIDEWINDOW,
- SWP_NOSIZE or SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_SHOWWINDOW);
- var
- MenuAni: TMenuAnimation;
- AniDir: TTBAnimationDirection;
- begin
- { Must override TCustomForm/TForm's CM_SHOWINGCHANGED handler so that the
- form doesn't get activated when Visible is set to True. }
- { Handle animation. NOTE: I do not recommend trying to enable animation on
- Windows 95 and NT 4.0 because there's a difference in the way the
- SetWindowPos works on those versions. See the comment in the
- TBStartAnimation function of TB2Anim.pas. }
- {$IFNDEF TBX_NO_ANIMATION}
- if ((View.ParentView = nil) or not(vsNoAnimation in View.ParentView.State)) and
- Showing and (View.Selected = nil) and not IsWindowVisible(WindowHandle) and
- (TBXMenuAnimation.AnimationMode <> amNone) then
- begin
- { Start animation only if WM_TB2K_POPUPSHOWING returns zero (or not handled) }
- if SendMessage(WindowHandle, WM_TB2K_POPUPSHOWING, TPS_ANIMSTART, 0) = 0 then
- begin
- MenuAni := TBXMenuAnimation.MenuAnimation;
- { MP (do not animate if disallowed by system-wide config) }
- if MenuAni <> maNone then
- begin
- AniDir := TTBPopupWindowAccess(Self).AnimationDirection;
- if MenuAni = maUnfold then
- if [tbadDown, tbadUp] * AniDir <> []
- then Include(AniDir, tbadRight)
- else Include(AniDir, tbadDown);
- TBStartAnimation(WindowHandle, MenuAni = maFade, AniDir);
- Exit;
- end;
- end;
- end;
- {$ENDIF}
- { No animation... }
- if not Showing then begin
- { Call TBEndAnimation to ensure WS_EX_LAYERED style is removed before
- hiding, otherwise windows under the popup window aren't repainted
- properly. }
- TBEndAnimation(WindowHandle);
- end;
- SetWindowPos(WindowHandle, 0, 0, 0, 0, 0, ShowFlags[Showing]);
- if Showing then SendNotifyMessage(WindowHandle, WM_TB2K_POPUPSHOWING, TPS_NOANIM, 0);
- end;
- procedure TTBXPopupWindow.CreateParams(var Params: TCreateParams);
- const
- CS_DROPSHADOW = $00020000;
- begin
- inherited CreateParams(Params);
- with Params do
- begin
- WindowClass.Style := WindowClass.Style and not (CS_DROPSHADOW or CS_DBLCLKS);
- if GetShowShadow and (CurrentTheme.GetPopupShadowType = PST_WINDOWSXP) then
- begin
- WindowClass.Style := WindowClass.Style or CS_DROPSHADOW;
- StrPCopy(WinClassName, ClassName + 'S');
- end;
- end;
- end;
- procedure TTBXPopupWindow.CreateShadow;
- var
- PR: TRect;
- ParentViewer: TTBItemViewer;
- VT: Integer;
- ChevronParent: Boolean;
- begin
- PR := Rect(0, 0, 0, 0);
- if CurrentTheme.GetPopupShadowType = PST_OFFICEXP then
- begin
- if (View <> nil) and (View.ParentView <> nil) then
- begin
- ParentViewer := TTBViewAccess(View.ParentView).OpenViewer;
- ChevronParent := Self is TTBXChevronPopupWindow;
- if ((ParentViewer is TTBXItemViewer) or ChevronParent) then
- begin
- VT := GetViewType(ParentViewer.View);
- if ((VT and PVT_POPUPMENU) <> PVT_POPUPMENU) or ChevronParent then
- begin
- PR := ParentViewer.BoundsRect;
- PR.TopLeft := View.ParentView.Window.ClientToScreen(PR.TopLeft);
- PR.BottomRight := View.ParentView.Window.ClientToScreen(PR.BottomRight);
- end;
- end;
- end
- else if not IsRectEmpty(FControlRect) then
- begin
- PR := FControlRect;
- end;
- end;
- FShadows := TShadows.Create(PR, BoundsRect, 4, 61, TBXLoColor);
- FShadows.Show(Handle);
- end;
- destructor TTBXPopupWindow.Destroy;
- begin
- DestroyShadow;
- inherited;
- end;
- procedure TTBXPopupWindow.DestroyShadow;
- var
- SaveShadows: TObject;
- begin
- SaveShadows := FShadows;
- FShadows := nil;
- SaveShadows.Free;
- end;
- function TTBXPopupWindow.GetFillColor: TColor;
- begin
- Result := CurrentTheme.GetViewColor(GetViewType(View));
- View.BackgroundColor := Result;
- end;
- function TTBXPopupWindow.GetNCSize: TPoint;
- begin
- Result := inherited GetNCSize;
- CurrentTheme.GetViewBorder(GetViewType(View), Result);
- end;
- function TTBXPopupWindow.GetShowShadow: Boolean;
- begin
- Result := ((GetViewType(View) and PVT_LISTBOX) <> PVT_LISTBOX );
- end;
- function TTBXPopupWindow.GetViewClass: TTBViewClass;
- begin
- Result := TTBXPopupView;
- end;
- procedure TTBXPopupWindow.PaintScrollArrows; {vb+}
- function _GetPopupMargin: Integer;
- begin
- if View.ParentView <> nil then
- Result := GetPopupMargin(TTBViewAccess(View.ParentView).OpenViewer)
- else if View.ViewerCount > 0 then
- Result := GetPopupMargin(View.Viewers[0])
- else Result := -1;
- end;
- procedure DrawArrows;
- var
- ItemInfo: TTBXItemInfo;
- Index: Integer;
- begin
- FillChar(ItemInfo, SizeOf(ItemInfo), 0);
- ItemInfo.ViewType := PVT_POPUPMENU;
- ItemInfo.Enabled := True;
- ItemInfo.PopupMargin := _GetPopupMargin;
- if ItemInfo.PopupMargin > 0 then
- begin
- if TTBViewAccess(View).ShowUpArrow then
- for Index := 0 to View.ViewerCount- 1 do
- if View.Viewers[Index].Show then
- begin
- CurrentTheme.PaintMenuItemFrame(Canvas, Rect(0, 0, ClientWidth,
- View.Viewers[Index].BoundsRect.Top), ItemInfo);
- Break;
- end;
- if TTBViewAccess(View).ShowDownArrow then
- for Index := View.ViewerCount- 1 downto 0 do
- if View.Viewers[Index].Show then
- begin
- CurrentTheme.PaintMenuItemFrame(Canvas, Rect(0,
- View.Viewers[Index].BoundsRect.Bottom, ClientWidth,
- ClientHeight), ItemInfo);
- Break;
- end;
- end;
- end;
- begin
- with TTBViewAccess(View) do
- if ShowUpArrow or ShowDownArrow then
- DrawArrows;
- inherited;
- end;
- procedure TTBXPopupWindow.TBMGetViewType(var Message: TMessage);
- var
- PI: TTBCustomItem;
- begin
- Message.Result := PVT_POPUPMENU;
- if View <> nil then
- if Self is TTBXChevronPopupWindow then
- Message.Result := PVT_CHEVRONMENU
- else
- begin
- PI := View.ParentItem;
- if PI <> nil then
- begin
- if (PI.Count = 1) and (PI.Items[0] is TTBXCustomList) then
- Message.Result := PVT_LISTBOX
- else if PI is TTBXEditItem then
- begin
- Message.Result := PVT_TOOLBOX;
- end
- else if (PI is TTBXCustomItem) and (TTBXCustomItem(PI).ToolBoxPopup) then
- Message.Result := PVT_TOOLBOX
- end;
- end;
- end;
- procedure TTBXPopupWindow.WMEraseBkgnd(var Message: TWmEraseBkgnd);
- var
- Canvas: TCanvas;
- R: TRect;
- begin
- TBEndAnimation(WindowHandle);
- Canvas := TCanvas.Create;
- Canvas.Handle := Message.DC;
- R := ClientRect;
- CurrentTheme.PaintBackgnd(Canvas, R, R, R, GetFillColor, False, GetViewType(View));
- Canvas.Handle := 0;
- Canvas.Free;
- Message.Result := 1;
- end;
- procedure TTBXPopupWindow.WMNCCalcSize(var Message: TWMNCCalcSize);
- var
- Sz: TPoint;
- begin
- CurrentTheme.GetViewBorder(GetViewType(View), Sz);
- with Message.CalcSize_Params^.rgrc[0], Sz do
- begin
- Inc(Left, X);
- Inc(Top, Y);
- Dec(Right, X);
- Dec(Bottom, Y);
- end;
- Message.Result := 1;
- end;
- procedure TBXPopupNCPaintProc(Wnd: HWND; DC: HDC; AppData: Longint);
- var
- R, R2: TRect;
- Canvas: TCanvas;
- View: TTBPopupView;
- PopupInfo: TTBXPopupInfo;
- ParentViewer: TTBItemViewer;
- begin
- Assert(DC <> 0, 'TBXPopupNCPaintProc');
- Canvas := TCanvas.Create;
- try
- Canvas.Handle := DC;
- FillChar(PopupInfo, SizeOf(PopupInfo), 0);
- View := TTBPopupView(AppData);
- PopupInfo.WindowHandle := View.Window.Handle;
- PopupInfo.ViewType := GetViewType(View);
- if View.ParentView <> nil then
- begin
- ParentViewer := TTBViewAccess(View.ParentView).OpenViewer;
- if ((ParentViewer is TTBXItemViewer) or (View.Window is TTBXChevronPopupWindow))
- and TTBItemViewerAccess(ParentViewer).IsToolbarStyle then
- begin
- R := ParentViewer.BoundsRect;
- R.TopLeft := View.ParentView.Window.ClientToScreen(R.TopLeft);
- R.BottomRight := View.ParentView.Window.ClientToScreen(R.BottomRight);
- GetWindowRect(Wnd, R2);
- OffsetRect(R, -R2.Left, -R2.Top);
- PopupInfo.ParentRect := R;
- end;
- end
- else if View.ParentItem is TTBXRootItem then
- begin
- R := TTBXRootItem(View.ParentItem).FPopupControlRect;
- if not IsRectEmpty(R) then
- begin
- GetWindowRect(Wnd, R2);
- OffsetRect(R, -R2.Left, -R2.Top);
- PopupInfo.ParentRect := R;
- end;
- end;
- GetWindowRect(Wnd, R);
- OffsetRect(R, -R.Left, -R.Top);
- CurrentTheme.GetViewBorder(PopupInfo.ViewType, PopupInfo.BorderSize);
- R2 := R;
- with PopupInfo.BorderSize do InflateRect(R2, -X, -Y);
- with R2 do ExcludeClipRect(Canvas.Handle, Left, Top, Right, Bottom);
- CurrentTheme.PaintPopupNCArea(Canvas, R, PopupInfo);
- finally
- Canvas.Handle := 0;
- Canvas.Free;
- end;
- end;
- procedure TTBXPopupWindow.WMNCPaint(var Message: TMessage);
- var
- DC: HDC;
- begin
- DC := GetWindowDC(Handle);
- try
- Assert(DC <> 0, 'TTBXPopupWindow.WMNCPaint');
- SelectNCUpdateRgn(Handle, DC, HRGN(Message.WParam));
- TBXPopupNCPaintProc(Handle, DC, LongInt(Self.View));
- finally
- ReleaseDC(Handle, DC);
- end;
- end;
- procedure TTBXPopupWindow.WMPrint(var Message: TMessage);
- begin
- HandleWMPrint(Handle, Message, TBXPopupNCPaintProc, LongInt(Self.View));
- end;
- procedure TTBXPopupWindow.WMTB2kPopupShowing(var Message: TMessage);
- begin
- if Message.WParam in [TPS_ANIMFINISHED, TPS_NOANIM] then
- begin
- if not (csDestroying in ComponentState) and GetShowShadow and
- (CurrentTheme.GetPopupShadowType in [PST_OFFICEXP, PST_WINDOWS2K]) then CreateShadow;
- end;
- end;
- procedure TTBXPopupWindow.WMWindowPosChanged(var Message: TWMWindowPosChanged);
- begin
- inherited;
- with Message.WindowPos^ do
- if ((flags and SWP_SHOWWINDOW) = 0) and ((flags and SWP_HIDEWINDOW) = 0) then
- begin
- if FShadows <> nil then
- begin
- DestroyShadow;
- CreateShadow;
- end;
- end;
- end;
- //============================================================================//
- { TTBXToolbarView }
- procedure TTBXToolbarView.GetMargins(AOrientation: TTBViewOrientation; var Margins: TRect);
- var
- VT: Integer;
- M: TTBXMargins;
- begin
- VT := GetWinViewType(TTBXToolbar(Owner));
- if (VT and VT_TOOLBAR) = VT_TOOLBAR then
- begin
- if AOrientation = tbvoFloating then VT := VT or TVT_FLOATING
- else VT := VT and not TVT_FLOATING
- end
- else if (VT and VT_DOCKPANEL) = VT_DOCKPANEL then
- begin
- if AOrientation = tbvoFloating then VT := VT or DPVT_FLOATING
- else VT := VT and not DPVT_FLOATING
- end;
- CurrentTheme.GetViewMargins(VT, M);
- Margins.Left := M.LeftWidth;
- Margins.Top := M.TopHeight;
- Margins.Right := M.RightWidth;
- Margins.Bottom := M.BottomHeight;
- end;
- //============================================================================//
- { TTBXToolbar }
- procedure TTBXToolbar.CMColorChanged(var Message: TMessage);
- begin
- UpdateEffectiveColor;
- if Docked and HandleAllocated then
- begin
- RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
- RDW_ERASE or RDW_UPDATENOW or RDW_ALLCHILDREN);
- end;
- UpdateChildColors;
- Invalidate;
- end;
- procedure TTBXToolbar.CMControlChange(var Message: TCMControlChange);
- begin
- inherited;
- if Message.Inserting and (Color = clNone) then
- Message.Control.Perform(CM_PARENTCOLORCHANGED, 1, EffectiveColor);
- end;
- procedure TTBXToolbar.CMParentColorChanged(var Message: TMessage);
- begin
- if Embedded and (Color = clNone) then
- begin
- UpdateEffectiveColor;
- if (Message.WParam = 0) then
- begin
- Message.WParam := 1;
- Message.LParam := EffectiveColor;
- end;
- end;
- inherited;
- Invalidate;
- end;
- constructor TTBXToolbar.Create(AOwner: TComponent);
- begin
- inherited;
- AddThemeNotification(Self);
- FEffectiveColor := Color;
- Color := clNone;
- ControlStyle := ControlStyle - [csOpaque];
- DblClickUndock := False;
- end;
- destructor TTBXToolbar.Destroy;
- begin
- RemoveThemeNotification(Self);
- inherited;
- end;
- procedure TTBXToolbar.DrawNCArea(const DrawToDC: Boolean; const ADC: HDC; const Clip: HRGN);
- var
- DC: HDC;
- R, CR, R2: TRect;
- ACanvas: TCanvas;
- ToolbarInfo: TTBXToolbarInfo;
- UsingBackground: Boolean;
- begin
- if not Docked or not HandleAllocated then Exit;
- if not DrawToDC then DC := GetWindowDC(Handle)
- else DC := ADC;
- UsingBackground := TDockAccess(CurrentDock).UsingBackground;
- try
- GetToolbarInfo(ToolbarInfo);
- GetWindowRect(Handle, R);
- OffsetRect(R, -R.Left, -R.Top);
- if not DrawToDC then
- begin
- SelectNCUpdateRgn(Handle, DC, Clip);
- CR := R;
- with ToolbarInfo.BorderSize, CR do
- begin
- InflateRect(CR, -X, -Y);
- if ToolbarInfo.IsVertical then Inc(Top, GetTBXDragHandleSize(ToolbarInfo))
- else Inc(Left, GetTBXDragHandleSize(ToolbarInfo));
- ExcludeClipRect(DC, Left, Top, Right, Bottom);
- end;
- end;
- ACanvas := TCanvas.Create;
- try
- ACanvas.Handle := DC;
- if CurrentTheme.SolidToolbarNCArea then
- begin
- ACanvas.Brush.Color := EffectiveColor;
- ACanvas.Brush.Style := bsSolid;
- end
- else if UsingBackground then
- begin
- ACanvas.Brush.Color := EffectiveColor;
- R2 := CurrentDock.ClientRect;
- OffsetRect(R2, -Left, -Top);
- TDockAccess(CurrentDock).DrawBackground(DC, R2);
- {$IFNDEF MPEXCLUDE}
- if (Color = clNone) and CurrentDock.BackgroundOnToolbars then
- ACanvas.Brush.Style := bsClear;
- {$ENDIF}
- end
- else
- begin
- ACanvas.Brush.Color := GetEffectiveColor(CurrentDock);
- ACanvas.FillRect(R);
- ACanvas.Brush.Color := EffectiveColor;
- ACanvas.Brush.Style := bsSolid;
- end;
- CurrentTheme.PaintToolbarNCArea(ACanvas, R, ToolbarInfo);
- finally
- ACanvas.Handle := 0;
- ACanvas.Free;
- end;
- finally
- if not DrawToDC then ReleaseDC(Handle, DC);
- end;
- end;
- function TTBXToolbar.Embedded: Boolean;
- begin
- Result := not (Floating or Docked);
- end;
- function TTBXToolbar.GetChevronItemClass: TTBChevronItemClass;
- begin
- Result := TTBXChevronItem;
- end;
- function TTBXToolbar.GetFloatingBorderSize: TPoint;
- begin
- CurrentTheme.GetViewBorder(GetViewType(View) or TVT_FLOATING, Result);
- end;
- function TTBXToolbar.GetFloatingWindowParentClass: TTBFloatingWindowParentClass;
- begin
- Result := TTBXFloatingWindowParent;
- end;
- procedure TTBXToolbar.GetToolbarInfo(out ToolbarInfo: TTBXToolbarInfo);
- begin
- FillChar(ToolbarInfo, SizeOf(ToolbarInfo), 0);
- ToolbarInfo.WindowHandle := Handle;
- ToolbarInfo.ViewType := GetWinViewType(Self);
- if CurrentDock <> nil then
- ToolbarInfo.IsVertical := CurrentDock.Position in [dpLeft,dpRight];
- ToolbarInfo.AllowDrag := CurrentDock.AllowDrag;
- ToolbarInfo.DragHandleStyle := Ord(DragHandleStyle);
- ToolbarInfo.ClientWidth := ClientWidth;
- ToolbarInfo.ClientHeight := ClientHeight;
- if ToolbarInfo.AllowDrag and CloseButtonWhenDocked then
- begin
- ToolbarInfo.CloseButtonState := CDBS_VISIBLE;
- if CloseButtonDown then ToolbarInfo.CloseButtonState := ToolbarInfo.CloseButtonState or CDBS_PRESSED
- else if CloseButtonHover then ToolbarInfo.CloseButtonState := ToolbarInfo.CloseButtonState or CDBS_HOT;
- end;
- ToolbarInfo.BorderStyle := BorderStyle;
- CurrentTheme.GetViewBorder(ToolbarInfo.ViewType, ToolbarInfo.BorderSize);
- ToolbarInfo.EffectiveColor := EffectiveColor;
- end;
- function TTBXToolbar.GetViewClass: TTBToolbarViewClass;
- begin
- Result := TTBXToolbarView;
- end;
- procedure TTBXToolbar.SetItemTransparency(const Value: TTBXItemTransparency);
- begin
- FItemTransparency := Value;
- Invalidate;
- end;
- procedure TTBXToolbar.Loaded; {vb+}
- begin
- inherited;
- UpdateEffectiveColor;
- end;
- procedure TTBXToolbar.SetParent(AParent: TWinControl);
- begin
- inherited;
- if AParent is TTBXFloatingWindowParent then
- TTBXFloatingWindowParent(AParent).SnapDistance := SnapDistance;
- end;
- procedure TTBXToolbar.SetSnapDistance(Value: Integer);
- begin
- if Value < 0 then Value := 0;
- FSnapDistance := Value;
- if (Parent <> nil) and (Parent is TTBXFloatingWindowParent) then
- TTBXFloatingWindowParent(Parent).SnapDistance := Value;
- end;
- procedure TTBXToolbar.TBMGetEffectiveColor(var Message: TMessage);
- begin
- Message.WParam := EffectiveColor;
- Message.Result := 1;
- end;
- procedure TTBXToolbar.TBMGetViewType(var Message: TMessage);
- begin
- if MenuBar then Message.Result := TVT_MENUBAR
- else Message.Result := TVT_NORMALTOOLBAR;
- if Floating then Message.Result := Message.Result or TVT_FLOATING;
- if Resizable then Message.Result := Message.Result or TVT_RESIZABLE;
- case ItemTransparency of
- itAuto:
- if not (Floating or Docked) then Message.Result := Message.Result or TVT_EMBEDDED;
- itDisable:
- Message.Result := Message.Result or TVT_EMBEDDED;
- end;
- end;
- procedure TTBXToolbar.TBMThemeChange(var Message: TMessage);
- begin
- case Message.WParam of
- TSC_BEFOREVIEWCHANGE: BeginUpdate;
- TSC_AFTERVIEWCHANGE:
- begin
- EndUpdate;
- UpdateEffectiveColor;
- if Floating then UpdateNCArea(TTBXFloatingWindowParent(Parent), GetWinViewType(Self))
- else UpdateNCArea(Self, GetWinViewType(Self));
- Invalidate;
- Arrange;
- UpdateChildColors;
- end;
- TSC_APPACTIVATE, TSC_APPDEACTIVATE:
- if MenuBar then Invalidate;
- end;
- end;
- procedure TTBXToolbar.UpdateChildColors;
- var
- M: TMessage;
- begin
- M.Msg := CM_PARENTCOLORCHANGED;
- M.WParam := 1;
- M.LParam := EffectiveColor;
- M.Result := 0;
- Broadcast(M);
- end;
- procedure TTBXToolbar.UpdateEffectiveColor;
- begin
- if Color = clNone then
- begin
- if Embedded and (Parent <> nil) then
- FEffectiveColor := GetEffectiveColor(Parent)
- else
- FEffectiveColor := CurrentTheme.GetViewColor(GetViewType(View));
- end
- else FEffectiveColor := Color;
- end;
- procedure TTBXToolbar.WMEraseBkgnd(var Message: TWmEraseBkgnd);
- var
- Canvas: TCanvas;
- R, CR: TRect;
- Transparent: Boolean;
- begin
- Transparent := False;
- CR := ClientRect;
- if Color = clNone then
- {$IFNDEF MPEXCLUDE}
- if Docked and (TDockAccess(CurrentDock).UsingBackground) and CurrentDock.BackgroundOnToolbars
- and not CurrentTheme.SolidToolbarClientArea then
- begin
- R := CurrentDock.ClientRect;
- R.TopLeft := ScreenToClient(CurrentDock.ClientToScreen(R.TopLeft));
- R.BottomRight := ScreenToClient(CurrentDock.ClientToScreen(R.BottomRight));
- TDockAccess(CurrentDock).DrawBackground(Message.DC, R);
- Message.Result := 1;
- Transparent := True;
- end
- else {$ENDIF} if Embedded then
- begin
- Transparent := True;
- DrawParentBackground(Self, Message.DC, CR);
- end;
- Canvas := TCanvas.Create;
- Canvas.Handle := Message.DC;
- try
- if Docked then
- begin
- R := CurrentDock.ClientRect;
- R.TopLeft := ScreenToClient(CurrentDock.ClientToScreen(R.TopLeft));
- R.BottomRight := ScreenToClient(CurrentDock.ClientToScreen(R.BottomRight));
- end
- else R := Rect(0, 0, 0, 0);
- CurrentTheme.PaintBackgnd(Canvas, R, CR, CR, EffectiveColor, Transparent, GetWinViewType(Self));
- Message.Result := 1;
- finally
- Canvas.Handle := 0;
- Canvas.Free;
- end;
- end;
- procedure TTBXToolbar.WMSize(var Message: TWMSize);
- {$IFNDEF MPEXCLUDE}
- var
- I: Integer;
- V: TTBItemViewer;
- R: TRect;
- {$ENDIF}
- begin
- inherited;
- {$IFNDEF MPEXCLUDE}
- if Docked and TDockAccess(CurrentDock).UsingBackground and
- TDockAccess(CurrentDock).BackgroundOnToolbars and
- ((CurrentDock is TTBXDock) and not TTBXDock(CurrentDock).FResizing) then
- begin
- for I := 0 to View.ViewerCount - 1 do
- begin
- V := View.Viewers[I];
- if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
- then View.Invalidate(V);
- end;
- Self.Update;
- InvalidateRect(Handle, nil, True);
- for I := 0 to View.ViewerCount - 1 do
- begin
- V := View.Viewers[I];
- if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
- then
- begin
- R := V.BoundsRect;
- ValidateRect(Handle, @R);
- end;
- end;
- end;
- {$ENDIF}
- end;
- //============================================================================//
- { TTBXChevronItem }
- function TTBXChevronItem.GetItemViewerClass(AView: TTBView): TTBItemViewerClass;
- begin
- Result := TTBXChevronItemViewer;
- end;
- procedure TTBXChevronItem.GetPopupPosition(ParentView: TTBView;
- PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec);
- begin
- if CurrentTheme.OfficeXPPopupAlignment then with PopupPositionRec do
- begin
- GetOfficeXPPopupPosition1(PopupPositionRec);
- inherited GetPopupPosition(ParentView, PopupWindow, PopupPositionRec);
- GetOfficeXPPopupPosition2(PopupPositionRec);
- end
- else inherited;
- end;
- function TTBXChevronItem.GetPopupWindowClass: TTBPopupWindowClass;
- begin
- Result := TTBXChevronPopupWindow;
- end;
- //============================================================================//
- { TTBXChevronItemViewer }
- procedure TTBXChevronItemViewer.Paint(const Canvas: TCanvas;
- const ClientAreaRect: TRect; IsHoverItem, IsPushed, UseDisabledShadow: Boolean);
- const
- CDesigning: array [Boolean] of Integer = (0, IO_DESIGNING);
- var
- ItemInfo: TTBXItemInfo;
- begin
- FillChar(ItemInfo, SizeOf(TTBXItemInfo), 0);
- ItemInfo.ViewType := GetViewType(View);
- ItemInfo.ItemOptions := IO_TOOLBARSTYLE or CDesigning[csDesigning in Item.ComponentState];
- ItemInfo.Enabled := Item.Enabled or View.Customizing;
- ItemInfo.Pushed := IsPushed;
- ItemInfo.Selected := False;
- ItemInfo.ImageShown := False;
- ItemInfo.ImageWidth := 0;
- ItemInfo.ImageHeight := 0;
- ItemInfo.IsPopupParent := IsPushed;
- if IsHoverItem then
- begin
- if not ItemInfo.Enabled and not TTBViewAccess(View).MouseOverSelected then ItemInfo.HoverKind := hkKeyboardHover
- else if ItemInfo.Enabled then ItemInfo.HoverKind := hkMouseHover;
- end
- else ItemInfo.HoverKind := hkNone;
- ItemInfo.IsVertical := View.Orientation = tbvoVertical;
- CurrentTheme.PaintChevron(Canvas, ClientAreaRect, ItemInfo);
- end;
- //============================================================================//
- { TTBXRootItem }
- function TTBXRootItem.CreatePopupEx(SelectFirstItem: Boolean;
- const AControlRect: TRect; Alignment: TTBPopupAlignment): TTBPopupWindow;
- var
- SavePopupRect: TRect;
- Pt: TPoint;
- begin
- SavePopupRect := FPopupControlRect;
- try
- FPopupControlRect := AControlRect;
- Pt.X := AControlRect.Left;
- Pt.Y := AControlRect.Bottom;
- Result := inherited CreatePopup(nil, nil, False, SelectFirstItem, False, Pt, Alignment);
- if Result is TTBXPopupWindow then TTBXPopupWindow(Result).FControlRect := FPopupControlRect;
- finally
- FPopupControlRect := SavePopupRect;
- end;
- end;
- procedure TTBXRootItem.GetPopupPosition(ParentView: TTBView;
- PopupWindow: TTBPopupWindow; var PopupPositionRec: TTBPopupPositionRec);
- var
- Y2: Integer;
- VT: Integer;
- begin
- if IsRectEmpty(FPopupControlRect) then inherited
- else with PopupPositionRec do
- begin
- ParentItemRect := FPopupControlRect;
- if Y + H > MonitorRect.Bottom then
- begin
- Y2 := FPopupControlRect.Top - H;
- if Y2 >= MonitorRect.Top then Y := Y2;
- end;
- if Y < MonitorRect.Top then Y := MonitorRect.Top
- else if Y + H > MonitorRect.Bottom then Y := MonitorRect.Bottom - H;
- if Alignment = tbpaRight then X := FPopupControlRect.Right - W;
- if X + W > MonitorRect.Right then X := MonitorRect.Right - W;
- if X < MonitorRect.Left then X := MonitorRect.Left;
- end;
- if CurrentTheme.OfficeXPPopupAlignment then with PopupPositionRec do
- begin
- GetOfficeXPPopupPosition1(PopupPositionRec);
- inherited GetPopupPosition(ParentView, PopupWindow, PopupPositionRec);
- GetOfficeXPPopupPosition2(PopupPositionRec);
- VT := GetWinViewType(PopupWindow);
- PopupPositionRec.PlaySound := not (VT and PVT_LISTBOX = PVT_LISTBOX);
- end
- else inherited;
- end;
- function TTBXRootItem.GetPopupWindowClass: TTBPopupWindowClass;
- begin
- Result := TTBXPopupWindow;
- end;
- function TTBXRootItem.OpenPopupEx(const SelectFirstItem, TrackRightButton: Boolean;
- const ControlRect: TRect; const Alignment: TTBPopupAlignment;
- const ReturnClickedItemOnly: Boolean): TTBCustomItem;
- var
- ModalHandler: TTBModalHandler;
- Popup: TTBPopupWindow;
- DoneActionData: TTBDoneActionData;
- State: TTBViewState;
- begin
- ModalHandler := TTBModalHandler.Create(0);
- try
- Popup := CreatePopupEx(SelectFirstItem, ControlRect, Alignment);
- try
- State := Popup.View.State;
- Include(State, vsIgnoreFirstMouseUp);
- TTBViewAccess(Popup.View).SetState(State);
- ModalHandler.Loop(Popup.View, False, False, False, TrackRightButton);
- DoneActionData := TTBViewAccess(Popup.View).DoneActionData;
- finally
- { Remove vsModal state from the root view before any TTBView.Destroy
- methods get called, so that NotifyFocusEvent becomes a no-op }
- State := Popup.View.State;
- Exclude(State, vsModal);
- TTBViewAccess(Popup.View).SetState(State);
- Popup.Free;
- end;
- finally
- ModalHandler.Free;
- end;
- Result := ProcessDoneAction(DoneActionData, ReturnClickedItemOnly);
- end;
- function TTBXRootItem.PopupEx(const ControlRect: TRect;
- TrackRightButton: Boolean; Alignment: TTBPopupAlignment = tbpaLeft;
- ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
- begin
- Result := OpenPopupEx(False, TrackRightButton, ControlRect,
- Alignment, ReturnClickedItemOnly);
- end;
- //============================================================================//
- { TTBXPopupMenu }
- function TTBXPopupMenu.GetRootItemClass: TTBRootItemClass;
- begin
- Result := TTBXRootItem;
- end;
- function TTBXPopupMenu.PopupEx(const ControlRect: TRect;
- ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
- begin
- {$IFDEF JR_D5}
- {$IFDEF JR_D9}
- SetPopupPoint(Point(ControlRect.Left, ControlRect.Bottom));
- {$ELSE}
- PPoint(@PopupPoint)^ := Point(ControlRect.Left, ControlRect.Bottom);
- {$ENDIF}
- {$ENDIF}
- Result := TTBXRootItem(Items).PopupEx(ControlRect, TrackButton = tbRightButton,
- TTBPopupAlignment(Alignment), ReturnClickedItemOnly);
- end;
- procedure TTBXPopupMenu.TBMGetViewType(var Message: TMessage);
- begin
- Message.Result := PVT_POPUPMENU;
- end;
- //============================================================================//
- { TTBXFloatingWindowParent }
- procedure TTBXFloatingWindowParent.CancelNCHover;
- begin
- if FCloseButtonHover then
- begin
- FCloseButtonHover := False;
- if HandleAllocated and IsWindowVisible(Handle) then
- DrawNCArea(False, 0, 0, [twrdCloseButton]);
- end;
- end;
- procedure TTBXFloatingWindowParent.CMMouseLeave(var Message: TMessage);
- begin
- inherited;
- CancelNCHover;
- end;
- procedure TTBXFloatingWindowParent.DrawNCArea(const DrawToDC: Boolean;
- const ADC: HDC; const Clip: HRGN; RedrawWhat: TTBToolWindowNCRedrawWhat);
- const
- CDown: array [Boolean] of Integer = (0, CDBS_PRESSED);
- CHover: array [Boolean] of Integer = (0, CDBS_HOT);
- CBord: array [Boolean] of Integer = (0, WRP_BORDER);
- CCapt: array [Boolean] of Integer = (0, WRP_CAPTION);
- CBtn: array [Boolean] of Integer = (0, WRP_CLOSEBTN);
- var
- DC: HDC;
- R: TRect;
- Canvas: TCanvas;
- WindowInfo: TTBXWindowInfo;
- DockWindow: TTBCustomDockableWindowAccess;
- begin
- if not HandleAllocated then Exit;
- if not DrawToDC then DC := GetWindowDC(Handle)
- else DC := ADC;
- try
- if not DrawToDC then SelectNCUpdateRgn(Handle, DC, Clip);
- GetWindowRect(Handle, R);
- OffsetRect(R, -R.Left, -R.Top);
- with R do IntersectClipRect(DC, Left, Top, Right, Bottom);
- Canvas := TCanvas.Create;
- try
- Canvas.Handle := DC;
- GetWindowRect(Handle, R);
- OffsetRect(R, -R.Left, -R.Top);
- DockWindow := TTBCustomDockableWindowAccess(DockableWindow);
- FillChar(WindowInfo, SizeOf(WindowInfo), 0);
- WindowInfo.ParentHandle := Handle;
- WindowInfo.WindowHandle := DockWindow.Handle;
- WindowInfo.ViewType := GetWinViewType(DockWindow);
- WindowInfo.ClientWidth := ClientWidth;
- WindowInfo.ClientHeight := ClientHeight;
- WindowInfo.ShowCaption := DockWindow.ShowCaption;
- WindowInfo.FloatingBorderSize := DockWindow.GetFloatingBorderSize;
- if DockWindow.CloseButton and DockWindow.ShowCaption then
- begin
- WindowInfo.CloseButtonState := CDBS_VISIBLE;
- if CloseButtonDown then WindowInfo.CloseButtonState := WindowInfo.CloseButtonState or CDBS_PRESSED
- else if CloseButtonHover then WindowInfo.CloseButtonState := WindowInfo.CloseButtonState or CDBS_HOT;
- end;
- WindowInfo.RedrawPart :=
- CBord[twrdBorder in RedrawWhat] or
- CCapt[twrdCaption in RedrawWhat] or
- CBtn[twrdCloseButton in RedrawWhat];
- WindowInfo.Caption := PChar(Caption);
- WindowInfo.EffectiveColor := GetEffectiveColor(DockWindow);
- WindowInfo.Active := not DockWindow.InactiveCaption;
- Canvas.Brush.Color := WindowInfo.EffectiveColor;
- CurrentTheme.PaintFloatingBorder(Canvas, R, WindowInfo);
- finally
- Canvas.Handle := 0;
- Canvas.Free;
- end;
- finally
- if not DrawToDC then ReleaseDC(Handle, DC);
- end;
- end;
- procedure TTBXFloatingWindowParent.WMEraseBkgnd(var Message: TMessage);
- begin
- Message.Result := 1;
- end;
- procedure TTBXFloatingWindowParent.WMNCMouseLeave(var Message: TMessage);
- begin
- if not MouseCapture then CancelNCHover;
- inherited;
- end;
- procedure TTBXFloatingWindowParent.WMNCMouseMove(var Message: TWMNCMouseMove);
- var
- InArea: Boolean;
- begin
- inherited;
- { Note: TME_NONCLIENT was introduced in Windows 98 and 2000 }
- CallTrackMouseEvent (Handle, TME_LEAVE or $10 {TME_NONCLIENT});
- InArea := Message.HitTest = 2001; {HT_TB2k_Close}
- if FCloseButtonHover <> InArea then
- begin
- FCloseButtonHover := InArea;
- if HandleAllocated and IsWindowVisible(Handle) then
- DrawNCArea(False, 0, 0, [twrdCloseButton]);
- end;
- end;
- procedure TTBXFloatingWindowParent.WMWindowPosChanging(var Message: TWMWindowPosChanging);
- var
- R: TRect;
- MonInfo: TMonitorInfo;
- begin
- if SnapDistance > 0 then with Message.WindowPos^ do
- begin
- if (cx = Width) and (cy = Height) then
- begin
- MonInfo.cbSize := SizeOf(MonInfo);
- GetMonitorInfo(Monitor.Handle, @MonInfo);
- R := MonInfo.rcWork;
- if Abs(x + Width - R.Right) < SnapDistance then x := R.Right - Width;
- if Abs(y + Height - R.Bottom) < SnapDistance then y := R.Bottom - Height;
- if Abs(x - R.Left) < SnapDistance then x := R.Left;
- if Abs(y - R.Top) < SnapDistance then y := R.Top;
- end;
- end;
- inherited;
- end;
- //============================================================================//
- {$IFNDEF MPEXCLUDE}
- { TTBXToolWindow }
- procedure TTBXToolWindow.CMColorChanged(var Message: TMessage);
- begin
- UpdateEffectiveColor;
- if Docked and HandleAllocated then
- RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
- RDW_ERASE or RDW_UPDATENOW or RDW_ALLCHILDREN);
- UpdateChildColors;
- Invalidate;
- end;
- procedure TTBXToolWindow.CMControlChange(var Message: TCMControlChange);
- begin
- inherited;
- if Message.Inserting and (Color = clNone) then
- Message.Control.Perform(CM_PARENTCOLORCHANGED, 1, EffectiveColor);
- end;
- procedure TTBXToolWindow.CMTextChanged(var Message: TMessage);
- begin
- inherited;
- if HandleAllocated then
- begin
- if Docked then RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE)
- else RedrawWindow(TTBXFloatingWindowParent(Parent).Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE);
- end;
- end;
- constructor TTBXToolWindow.Create(AOwner: TComponent);
- begin
- inherited;
- AddThemeNotification(Self);
- DblClickUndock := False;
- FEffectiveColor := Color;
- Color := clNone;
- end;
- destructor TTBXToolWindow.Destroy;
- begin
- RemoveThemeNotification(Self);
- inherited;
- end;
- procedure TTBXToolWindow.DrawNCArea(const DrawToDC: Boolean;
- const ADC: HDC; const Clip: HRGN);
- var
- DC: HDC;
- R, CR, R2: TRect;
- ACanvas: TCanvas;
- ToolbarInfo: TTBXToolbarInfo;
- UsingBackground: Boolean;
- begin
- if not Docked or not HandleAllocated then Exit;
- if not DrawToDC then DC := GetWindowDC(Handle)
- else DC := ADC;
- UsingBackground := TDockAccess(CurrentDock).UsingBackground;
- try
- GetToolbarInfo(ToolbarInfo);
- GetWindowRect(Handle, R);
- OffsetRect(R, -R.Left, -R.Top);
- if not DrawToDC then
- begin
- SelectNCUpdateRgn(Handle, DC, Clip);
- CR := R;
- with ToolbarInfo.BorderSize, CR do
- begin
- InflateRect(CR, -X, -Y);
- if ToolbarInfo.IsVertical then Inc(Top, GetTBXDragHandleSize(ToolbarInfo))
- else Inc(Left, GetTBXDragHandleSize(ToolbarInfo));
- ExcludeClipRect(DC, Left, Top, Right, Bottom);
- end;
- end;
- ACanvas := TCanvas.Create;
- try
- ACanvas.Handle := DC;
- ACanvas.Brush.Color := EffectiveColor;
- if CurrentTheme.SolidToolbarNCArea then
- begin
- ACanvas.Brush.Color := EffectiveColor;
- ACanvas.Brush.Style := bsSolid;
- end
- else if UsingBackground then
- begin
- ACanvas.Brush.Color := EffectiveColor;
- R2 := CurrentDock.ClientRect;
- OffsetRect(R2, -Left, -Top);
- TDockAccess(CurrentDock).DrawBackground(DC, R2);
- {$IFNDEF MPEXCLUDE}
- if (Color = clNone) and CurrentDock.BackgroundOnToolbars then
- ACanvas.Brush.Style := bsClear;
- {$ENDIF}
- end
- else
- begin
- ACanvas.Brush.Color := GetEffectiveColor(CurrentDock);
- ACanvas.FillRect(R);
- ACanvas.Brush.Color := EffectiveColor;
- ACanvas.Brush.Style := bsSolid;
- end;
- CurrentTheme.PaintToolbarNCArea(ACanvas, R, ToolbarInfo);
- finally
- ACanvas.Handle := 0;
- ACanvas.Free;
- end;
- finally
- if not DrawToDC then ReleaseDC(Handle, DC);
- end;
- end;
- function TTBXToolWindow.GetFloatingBorderSize: TPoint;
- begin
- CurrentTheme.GetViewBorder(GetWinViewType(Self) or TVT_FLOATING, Result);
- end;
- function TTBXToolWindow.GetFloatingWindowParentClass: TTBFloatingWindowParentClass;
- begin
- Result := TTBXFloatingWindowParent;
- end;
- procedure TTBXToolWindow.GetToolbarInfo(out ToolbarInfo: TTBXToolbarInfo);
- begin
- FillChar(ToolbarInfo, SizeOf(ToolbarInfo), 0);
- ToolbarInfo.WindowHandle := WindowHandle;
- ToolbarInfo.ViewType := GetWinViewType(Self);
- if CurrentDock <> nil then
- ToolbarInfo.IsVertical := CurrentDock.Position in [dpLeft,dpRight];
- ToolbarInfo.AllowDrag := CurrentDock.AllowDrag;
- ToolbarInfo.DragHandleStyle := Ord(DragHandleStyle);
- ToolbarInfo.ClientWidth := ClientWidth;
- ToolbarInfo.ClientHeight := ClientHeight;
- if ToolbarInfo.AllowDrag and CloseButtonWhenDocked then
- begin
- ToolbarInfo.CloseButtonState := CDBS_VISIBLE;
- if CloseButtonDown then ToolbarInfo.CloseButtonState := ToolbarInfo.CloseButtonState or CDBS_PRESSED;
- if CloseButtonHover then ToolbarInfo.CloseButtonState := ToolbarInfo.CloseButtonState or CDBS_HOT;
- end;
- ToolbarInfo.BorderStyle := BorderStyle;
- ToolbarInfo.EffectiveColor := EffectiveColor;
- CurrentTheme.GetViewBorder(ToolbarInfo.ViewType, ToolbarInfo.BorderSize);
- end;
- procedure TTBXToolWindow.SetParent(AParent: TWinControl);
- begin
- inherited;
- if AParent is TTBXFloatingWindowParent then
- TTBXFloatingWindowParent(AParent).SnapDistance := SnapDistance;
- end;
- procedure TTBXToolWindow.SetSnapDistance(Value: Integer);
- begin
- if Value < 0 then Value := 0;
- FSnapDistance := Value;
- if (Parent <> nil) and (Parent is TTBXFloatingWindowParent) then
- TTBXFloatingWindowParent(Parent).SnapDistance := Value;
- end;
- procedure TTBXToolWindow.TBMGetEffectiveColor(var Message: TMessage);
- begin
- Message.WParam := EffectiveColor;
- Message.Result := 1;
- end;
- procedure TTBXToolWindow.TBMGetViewType(var Message: TMessage);
- begin
- Message.Result := TVT_TOOLWINDOW;
- if Floating then Message.Result := Message.Result or TVT_FLOATING;
- if Resizable then Message.Result := Message.Result or TVT_RESIZABLE;
- end;
- procedure TTBXToolWindow.TBMThemeChange(var Message: TMessage);
- begin
- case Message.WParam of
- TSC_BEFOREVIEWCHANGE: BeginUpdate;
- TSC_AFTERVIEWCHANGE:
- begin
- EndUpdate;
- UpdateEffectiveColor;
- if HandleAllocated and not (csDestroying in ComponentState) then
- if Parent is TTBXFloatingWindowParent then
- UpdateNCArea(TTBXFloatingWindowParent(Parent), GetWinViewType(Self))
- else
- UpdateNCArea(Self, GetWinViewType(Self));
- UpdateChildColors;
- Invalidate;
- end;
- end;
- end;
- procedure TTBXToolWindow.UpdateChildColors;
- var
- M: TMessage;
- begin
- M.Msg := CM_PARENTCOLORCHANGED;
- M.WParam := 1;
- M.LParam := EffectiveColor;
- M.Result := 0;
- Broadcast(M);
- end;
- procedure TTBXToolWindow.UpdateEffectiveColor;
- begin
- if Color = clNone then FEffectiveColor := CurrentTheme.GetViewColor(GetWinViewType(Self))
- else FEffectiveColor := Color;
- end;
- procedure TTBXToolWindow.WMEraseBkgnd(var Message: TWmEraseBkgnd);
- var
- Canvas: TCanvas;
- R, CR: TRect;
- Transparent: Boolean;
- begin
- Transparent := False;
- CR := ClientRect;
- {$IFNDEF MPEXCLUDE}
- if Color = clNone then
- if Docked and (TDockAccess(CurrentDock).UsingBackground) and CurrentDock.BackgroundOnToolbars
- and not CurrentTheme.SolidToolbarClientArea then
- begin
- R := CurrentDock.ClientRect;
- R.TopLeft := ScreenToClient(CurrentDock.ClientToScreen(R.TopLeft));
- R.BottomRight := ScreenToClient(CurrentDock.ClientToScreen(R.BottomRight));
- SaveDC(Message.DC);
- with CR do IntersectClipRect(Message.DC, Left, Top, Right, Bottom);
- TDockAccess(CurrentDock).DrawBackground(Message.DC, R);
- RestoreDC(Message.DC, -1);
- Message.Result := 1;
- Transparent := True;
- end;
- {$ENDIF}
- Canvas := TCanvas.Create;
- Canvas.Handle := Message.DC;
- try
- if Docked then
- begin
- R := CurrentDock.ClientRect;
- R.TopLeft := ScreenToClient(CurrentDock.ClientToScreen(R.TopLeft));
- R.BottomRight := ScreenToClient(CurrentDock.ClientToScreen(R.BottomRight));
- end
- else R := Rect(0, 0, 0, 0);
- CurrentTheme.PaintBackgnd(Canvas, R, CR, CR, EffectiveColor, Transparent, GetWinViewType(Self));
- Message.Result := 1;
- finally
- Canvas.Handle := 0;
- Canvas.Free;
- end;
- end;
- {$ENDIF}
- //============================================================================//
- { Additional system colors }
- type
- TColorEntry = packed record
- ColorPtr: ^TColor;
- Name: string;
- end;
- var
- ColorRegistry: array of TColorEntry;
- procedure AddTBXColor(var AColor: TColor; const AName: string);
- var
- L: Integer;
- begin
- L := Length(ColorRegistry);
- SetLength(ColorRegistry, L + 1);
- with ColorRegistry[L] do
- begin
- ColorPtr := @AColor;
- Name := AName;
- end;
- end;
- function TBXColorToString(Color: TColor): string;
- var
- I: Integer;
- begin
- if not ColorToIdent(Color, Result) then
- begin
- for I := 0 to Length(ColorRegistry) - 1 do
- if ColorRegistry[I].ColorPtr^ = Color then
- begin
- Result := ColorRegistry[I].Name;
- Exit;
- end;
- FmtStr(Result, '%s%.8x', [HexDisplayPrefix, Color]);
- end;
- end;
- function TBXIdentToColor(const Ident: string; var Color: Longint): Boolean;
- var
- I: Integer;
- begin
- for I := 0 to Length(ColorRegistry) - 1 do
- if CompareText(ColorRegistry[I].Name, Ident) = 0 then
- begin
- Color := ColorRegistry[I].ColorPtr^;
- Result := True;
- Exit;
- end;
- Result := IdentToColor(Ident, Color);
- end;
- function TBXStringToColor(S: string): TColor;
- begin
- if not TBXIdentToColor(S, Longint(Result)) then Result := StringToColor(S);
- end;
- procedure TBXGetColorValues(Proc: TGetStrProc);
- var
- I: Integer;
- begin
- GetColorValues(Proc);
- for I := 0 to Length(ColorRegistry) - 1 do Proc(ColorRegistry[I].Name);
- end;
- procedure TBXSetTheme(const AThemeName: string);
- begin
- TBXNexus.SetTheme(AThemeName);
- end;
- function TBXCurrentTheme: string;
- begin
- Result := TBXNexus.GetTheme;
- end;
- //============================================================================//
- { TTBXNexus }
- procedure TTBXNexus.AddNotifie(AObject: TObject);
- begin
- if FNotifies.IndexOf(AObject) < 0 then FNotifies.Add(AObject);
- Exit; asm db 0,'TBX (C) 2001-2003 Alex Denisov',0 end;
- end;
- procedure TTBXNexus.Broadcast(Msg: Cardinal; WParam, LParam: Integer);
- var
- M: TMessage;
- I: Integer;
- begin
- if FNotifies.Count > 0 then
- begin
- M.Msg := Msg;
- M.WParam := WParam;
- M.LParam := LParam;
- M.Result := 0;
- for I := 0 to FNotifies.Count - 1 do TObject(FNotifies[I]).Dispatch(M);
- end;
- end;
- constructor TTBXNexus.Create(const DefaultTheme: string);
- begin
- FNotifies := TList.Create;
- CurrentTheme := GetTBXTheme(DefaultTheme);
- AddTBXSysChangeNotification(Self);
- end;
- destructor TTBXNexus.Destroy;
- begin
- RemoveTBXSysChangeNotification(Self);
- ReleaseTBXTheme(CurrentTheme);
- FNotifies.Free;
- inherited;
- end;
- function TTBXNexus.GetTheme: string;
- begin
- Result := CurrentTheme.Name;
- end;
- procedure TTBXNexus.RemoveNotifie(AObject: TObject);
- begin
- FNotifies.Remove(AObject);
- end;
- procedure TTBXNexus.SetTheme(const AThemeName: string);
- begin
- if IsTBXThemeAvailable(AThemeName) then
- begin
- ReleaseTBXTheme(CurrentTheme);
- CurrentTheme := GetTBXTheme(AThemeName);
- Broadcast(TBM_THEMECHANGE, TSC_BEFOREVIEWCHANGE, 1);
- Broadcast(TBM_THEMECHANGE, TSC_VIEWCHANGE, 1);
- Broadcast(TBM_THEMECHANGE, TSC_AFTERVIEWCHANGE, 1);
- end;
- end;
- procedure TTBXNexus.TBXSysCommand(var Message: TMessage);
- begin
- { Retranslate TBX_SYSCOMMAND to TBM_THEMECHANGE }
- if Message.Msg = TBX_SYSCOMMAND then
- Broadcast(TBM_THEMECHANGE, Message.WParam, 0);
- end;
- procedure InitAdditionalSysColors;
- begin
- {$IFNDEF JR_D7} {vb+}
- AddTBXColor(clHotLight, 'clHotLight');
- {$ENDIF} {vb+}
- {$IFNDEF JR_D6}
- AddTBXColor(clMoneyGreen, 'clMoneyGreen');
- AddTBXColor(clSkyBlue, 'clSkyBlue');
- AddTBXColor(clCream, 'clCream');
- AddTBXColor(clMedGray, 'clMedGray');
- {$ENDIF}
- end;
- { TTBXDock }
- procedure TTBXDock.CMColorChanged(var Message: TMessage);
- var
- I: Integer;
- begin
- inherited;
- for I := 0 to Self.ControlCount - 1 do
- if Controls[I] is TWinControl then
- InvalidateAll(TWinControl(Controls[I]));
- end;
- constructor TTBXDock.Create(AOwner: TComponent);
- begin
- inherited;
- Color := clNone;
- AddThemeNotification(Self);
- end;
- destructor TTBXDock.Destroy;
- begin
- RemoveThemeNotification(Self);
- inherited;
- end;
- procedure TTBXDock.DrawBackground(DC: HDC; const DrawRect: TRect);
- const
- DOCK_POSITIONS: array [TTBDockPosition] of Integer = (DP_TOP, DP_BOTTOM, DP_LEFT, DP_RIGHT);
- var
- Canvas: TCanvas;
- begin
- if UseParentBackground then DrawParentBackground(Self, DC, ClientRect)
- else if ThemedBackground then
- begin
- Canvas := TCanvas.Create;
- Canvas.Handle := DC;
- CurrentTheme.PaintDock(Canvas, ClientRect, DrawRect, DOCK_POSITIONS[Position]);
- Canvas.Handle := 0;
- Canvas.Free;
- end
- else inherited;
- end;
- procedure TTBXDock.Resize;
- var
- I, J: Integer;
- V: TTBItemViewer;
- R: TRect;
- begin
- inherited Resize;
- if UsingBackground then
- begin
- for J := 0 to ToolbarCount - 1 do
- begin
- Invalidate;
- if Toolbars[J] is TTBXToolbar then with TTBXToolbar(Toolbars[J]) do
- begin
- for I := 0 to View.ViewerCount - 1 do
- begin
- V := View.Viewers[I];
- if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
- then View.Invalidate(V);
- end;
- Update;
- if HandleAllocated then
- RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or RDW_ERASE);
- for I := 0 to View.ViewerCount - 1 do
- begin
- V := View.Viewers[I];
- if V.Show and not IsRectEmpty(V.BoundsRect) and not (V.Item is TTBControlItem)
- then
- begin
- R := V.BoundsRect;
- ValidateRect(Handle, @R);
- end;
- end;
- end
- {$IFNDEF MPEXCLUDE}
- else if Toolbars[J] is TTBXToolWindow then with TTBXToolWindow(Toolbars[J]) do
- begin
- if HandleAllocated then
- RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or RDW_ERASE);
- end;
- {$ENDIF}
- end;
- end;
- end;
- procedure TTBXDock.SetUseParentBackground(Value: Boolean);
- begin
- if Value <> FUseParentBackground then
- begin
- FUseParentBackground := Value;
- if HandleAllocated then
- RedrawWindow(Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or
- RDW_ERASE or RDW_ALLCHILDREN);
- end;
- end;
- procedure TTBXDock.TBMGetEffectiveColor(var Message: TMessage);
- begin
- if Color <> clNone then Message.WParam := Color
- else if Parent <> nil then Message.WParam := GetEffectiveColor(Parent)
- else Message.WParam := WPARAM(clBtnFace);
- Message.Result := 1;
- end;
- procedure TTBXDock.TBMThemeChange(var Message: TMessage);
- begin
- case Message.WParam of
- TSC_AFTERVIEWCHANGE:
- begin
- Invalidate;
- end;
- end;
- end;
- function TTBXDock.ThemedBackground: Boolean;
- begin
- Result := {$IFNDEF MPEXCLUDE}(Background = nil) and{$ENDIF} (Color = clNone) and CurrentTheme.PaintDockBackground;
- end;
- function TTBXDock.UsingBackground: Boolean;
- begin
- Result := UseParentBackground or (ThemedBackground and not FMoving) or
- inherited UsingBackground;
- end;
- procedure TTBXDock.WMEraseBkgnd(var Message: TWMEraseBkgnd);
- var
- R: TRect;
- C: TColor;
- begin
- R := Self.ClientRect;
- if UsingBackground then
- begin
- DrawBackground(Message.DC, R);
- Message.Result := 1;
- end
- else
- begin
- C := Color;
- if C = clNone then C := GetEffectiveColor(Parent);
- FillRectEx(Message.DC, R, C);
- Message.Result := 1;
- end;
- end;
- procedure TTBXDock.WMMove(var Message: TWMMove);
- begin
- FMoving := True;
- inherited;
- FMoving := False;
- end;
- procedure TTBXDock.WMSize(var Message: TWMSize);
- begin
- FResizing := True;
- inherited;
- FResizing := False;
- end;
- { TTBXMenuAnimation } {vb+}
- constructor TTBXMenuAnimation.Create(AAnimationMode: TAnimationMode = amSysDefault);
- begin
- AnimationMode := AAnimationMode;
- end;
- function TTBXMenuAnimation.GetAvailableModes: TAnimationModes;
- begin
- Result := [amNone, amSysDefault, amRandom, amUnfold, amSlide, amFade];
- end;
- function TTBXMenuAnimation.GetMenuAnimation: TMenuAnimation;
- function GetSysDefault: TMenuAnimation;
- const
- SPI_GETMENUFADE = $1012;
- SysDefAni: array[Boolean] of TMenuAnimation = (maSlide, maFade);
- begin
- if SysParamEnabled(SPI_GETMENUANIMATION)
- then Result := SysDefAni[SysParamEnabled(SPI_GETMENUFADE)]
- else Result := maNone;
- end;
- function GetRandom: TMenuAnimation;
- var Max: Integer;
- begin
- Max := Ord(High(TMenuAnimation));
- if not (amFade in AvailableModes) then
- Dec(Max);
- Result := Succ(TMenuAnimation(Random(Max)));
- end;
- begin
- case AnimationMode of
- amSysDefault: Result := GetSysDefault;
- amRandom: Result := GetRandom;
- amUnfold: Result := maUnfold;
- amSlide: Result := maSlide;
- amFade: Result := maFade;
- else
- Result := maNone;
- end;
- end;
- procedure TTBXMenuAnimation.SetAnimationMode(Value: TAnimationMode);
- var AvailModes: TAnimationModes;
- begin
- AvailModes := AvailableModes;
- while not (Value in AvailModes) do
- Value := Pred(Value);
- FAnimationMode := Value;
- end;
- function TTBXMenuAnimation.SysParamEnabled(Param: Cardinal): Boolean;
- var B: BOOL;
- begin
- Result := SystemParametersInfo(Param, 0, @B, 0) and B;
- end;
- { Work around delayed menu showing in Windows 2000+ } {vb+}
- var
- FixPlaySoundThreadHandle: Cardinal;
- function FixPlaySoundThreadFunc(Param: Pointer): Integer; stdcall;
- begin
- Sleep(250);
- PlaySound(nil, 0, 0);
- CloseHandle(FixPlaySoundThreadHandle); { Harakiri :~| }
- Result := $4E494150; { :) }
- end;
- procedure FixPlaySoundDelay;
- var ThreadId: TThreadID;
- begin
- if (FixPlaySoundThreadHandle = 0) then
- FixPlaySoundThreadHandle := CreateThread(nil, $1000,
- @FixPlaySoundThreadFunc, nil, 0, ThreadId);
- end;
- function CreateTBXPopupMenu(Owner: TComponent): TTBXPopupMenu;
- begin
- Result := TTBXPopupMenu.Create(Owner);
- end;
- initialization
- FixPlaySoundDelay; {vb+}
- {CurrentTheme := nil;} {vb-}
- RegisterTBXTheme('Default', TTBXDefaultTheme);
- TBXNexus := TTBXNexus.Create('Default');
- TBXMenuAnimation := TTBXMenuAnimation.Create; {vb+}
- {$IFNDEF JR_D7} {vb+}
- InitAdditionalSysColors;
- {$ENDIF} {vb+}
- finalization
- TBXNexus.Free;
- FreeAndNil(TBXMenuAnimation); {vb+}
- ColorRegistry := nil;
- end.
|