CnDockTree.pas 135 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265
  1. {******************************************************************************}
  2. { CnPack For Delphi/C++Builder }
  3. { 中国人自己的开放源码第三方开发包 }
  4. { (C)Copyright 2001-2018 CnPack 开发组 }
  5. { ------------------------------------ }
  6. { }
  7. { 本开发包是开源的自由软件,您可以遵照 CnPack 的发布协议来修 }
  8. { 改和重新发布这一程序。 }
  9. { }
  10. { 发布这一开发包的目的是希望它有用,但没有任何担保。甚至没有 }
  11. { 适合特定目的而隐含的担保。更详细的情况请参阅 CnPack 发布协议。 }
  12. { }
  13. { 您应该已经和开发包一起收到一份 CnPack 发布协议的副本。如果 }
  14. { 还没有,可访问我们的网站: }
  15. { }
  16. { 网站地址:http://www.cnpack.org }
  17. { 电子邮件:master@cnpack.org }
  18. { }
  19. {******************************************************************************}
  20. {*******************************************************}
  21. { }
  22. { 管理停靠控件的管理器 }
  23. { CnDockTree 单元 }
  24. { }
  25. { 版权 (C) 2002,2003 鲁小班 }
  26. { }
  27. {*******************************************************}
  28. unit CnDockTree;
  29. {* |<PRE>
  30. ================================================================================
  31. * 软件名称:不可视工具组件包停靠单元
  32. * 单元名称:管理停靠控件的管理器
  33. * 单元作者:CnPack开发组 周益波(鲁小班)
  34. * 备 注:本单元由原作者授权CnPack开发组移植,已保留原作者版权信息
  35. * 开发平台:
  36. * 兼容测试:PWin9X/2000/XP + Delphi 5/6/7
  37. * 本 地 化:该单元中的字符串均符合本地化处理方式
  38. * 单元标识:$Id$
  39. * 修改记录:2007.07.13 V1.0
  40. * 移植单元
  41. ================================================================================
  42. |</PRE>}
  43. interface
  44. {$I CnPack.inc}
  45. uses
  46. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  47. Consts, CnDockSupportClass;
  48. const
  49. { 鼠标位置在分割条上面 }
  50. HTSPLITTER = 30;
  51. { 没有在特定的位置上 }
  52. HTNONE = 31;
  53. type
  54. TCnDockTree = class;
  55. // ICnDockManager接口继承自IDockManager,用户可以在ICnDockManager中再定义一些方法,函数或属性。
  56. ICnDockManager = interface(IDockManager)
  57. ['{7B0AACBC-E9BF-42F8-9629-E551067090B2}']
  58. function GetActiveControl: TControl; //获得焦点的控件
  59. procedure SetActiveControl(const Value: TControl); //设置某个控件获得焦点
  60. function GetGrabberSize: Integer; //获得把手的大小
  61. procedure SetGrabberSize(const Value: Integer); //设置把手的大小
  62. function GetSplitterWidth: Integer; //获得分割条的宽度
  63. procedure SetSplitterWidth(const Value: Integer); //设置分割条的宽度
  64. function GetBorderWidth: Integer; //获得边框的宽度
  65. procedure SetBorderWidth(const Value: Integer); //设置边框的宽度
  66. function GetDockRect: TRect; //获得停靠矩形
  67. procedure SetDockRect(const Value: TRect); //设置停靠矩形
  68. function GetDockSiteSize: Integer; //获得停靠服务器的宽度或者高度
  69. procedure SetDockSiteSize(const Value: Integer); //设置停靠服务器的宽度或者高度
  70. function GetMinSize: Integer; //获得停靠客户之间的最小距离
  71. procedure BeginResizeDockSite;
  72. procedure EndResizeDockSite;
  73. function GetDockEdge(DockRect: TRect; MousePos: TPoint;
  74. var DropAlign: TAlign; Control: TControl): TControl; //获得停靠预览矩形下面的Control;
  75. function GetHTFlag(MousePos: TPoint): Integer;
  76. procedure GetSiteInfo(Client: TControl;
  77. var InfluenceRect: TRect; MousePos: TPoint; var CanDock: Boolean);
  78. procedure ShowControl(Control: TControl); //显示Control
  79. procedure HideControl(Control: TControl); //隐藏Control
  80. procedure ShowAllControl; // 显示所有的Control
  81. procedure HideAllControl; // 隐藏所有的Control
  82. procedure ShowSingleControl(Control: TControl); // 只显示一个Control,其他的都隐藏
  83. procedure HideSingleControl(Control: TControl); // 只隐藏一个Control,其他的都显示
  84. { 用新的NewControl替换老的OldControl }
  85. procedure ReplaceZoneChild(OldControl, NewControl: TControl);
  86. { 根据输入的Control参数查找Zone,如果找到就返回True,否则返回False }
  87. function HasZoneWithControl(Control: TControl): Boolean;
  88. { 获得停靠服务器上的停靠客户的极限, 相对于DockSite }
  89. function GetDockClientLimit(Orient: TDockOrientation; IsMin: Boolean): Integer;
  90. function GetFrameRect(Control: TControl): TRect; //获得停靠控件的矩形大小,相对于DockSite。
  91. function GetFrameRectEx(Control: TControl): TRect; //获得停靠控件的矩形大小,相对于屏幕。
  92. property ActiveControl: TControl read GetActiveControl
  93. write SetActiveControl;
  94. property GrabberSize: Integer read GetGrabberSize
  95. write SetGrabberSize;
  96. property SplitterWidth: Integer read GetSplitterWidth
  97. write SetSplitterWidth;
  98. property BorderWidth: Integer read GetBorderWidth
  99. write SetBorderWidth;
  100. property DockSiteSize: Integer read GetDockSiteSize write SetDockSiteSize;
  101. property DockRect: TRect read GetDockRect write SetDockRect;
  102. property MinSize: Integer read GetMinSize;
  103. end;
  104. TCnDockZone = class
  105. private
  106. FChildControl: TWinControl; //上面的控件
  107. FChildZones: TCnDockZone; //左子女
  108. FNextSibling: TCnDockZone; //右兄弟
  109. FOrientation: TDockOrientation; //停靠的方式,是水平还是垂直,或者没有
  110. FParentZone: TCnDockZone; //父亲
  111. FPrevSibling: TCnDockZone; //上一个兄弟
  112. FTree: TCnDockTree; //属于哪棵树
  113. FZoneLimit: Integer; //节点的下边或者右边的坐标
  114. //如果FOrientation是水平的,就表示下边的坐标,
  115. //如果FOrientation是垂直的,就表示右边的坐标。
  116. FVisibleSize: Integer; //存储上当Zone可见的时候的ZoneSize的值,
  117. FVisibled: Boolean; //是否可见
  118. FControlVisibled: Boolean; //ChildControl是否可见
  119. FIsInside: Boolean; //是否在DockSite的里面
  120. function GetFirstSibling: TCnDockZone;//获得最前一个兄弟
  121. function GetLastSibling: TCnDockZone; //获得最后一个兄弟
  122. function GetFirstChild: TCnDockZone; //获得最前一个子女
  123. function GetLastChild: TCnDockZone; //获得最后一个子女
  124. function GetTopLeftArr(Orient: TDockOrientation): Integer;
  125. function GetHeightWidthArr(Orient: TDockOrientation): Integer;
  126. function GetAfterClosestVisibleZone: TCnDockZone;
  127. function GetBeforeClosestVisibleZone: TCnDockZone;
  128. function GetAfterApoapsisVisibleZone: TCnDockZone;
  129. function GetBeforeApoapsisVisibleZone: TCnDockZone;
  130. function GetNextSiblingCount: Integer;
  131. function GetPrevSiblingCount: Integer;
  132. procedure SetVisibled(const Value: Boolean);
  133. procedure SetZoneLimit(const Value: Integer);
  134. function GetVisibleNextSiblingCount: Integer;
  135. function GetVisibleNextSiblingTotal: Integer;
  136. function GetVisiblePrevSiblingCount: Integer;
  137. function GetVisiblePrevSiblingTotal: Integer;
  138. function GetFirstVisibleChildZone: TCnDockZone;
  139. function GetLastVisibleChildZone: TCnDockZone;
  140. procedure SetIsInside(const Value: Boolean);
  141. protected
  142. procedure AdjustZoneLimit(Value: Integer); virtual;//改变FZoneLimit值并且调整她的兄弟
  143. procedure LButtonDbClkMothed; virtual; // 当鼠标左键双击的时候,判断Zone上的ChildControl如何动作
  144. function GetChildCount: Integer; //获得子女的个数
  145. function GetVisibleChildCount: Integer; //获得可见子女的个数
  146. function GetChildTotal: Integer; //获得末段子女的总数
  147. function GetVisibleChildTotal: Integer; //获得末段可见子女的个数
  148. function GetLimitBegin: Integer; //获得节点的上边或者左边的坐标
  149. function GetLimitSize: Integer; //获得节点的高度或者宽度
  150. function GetTopLeft(Orient: Integer{TDockOrientation}): Integer;
  151. function GetHeightWidth(Orient: Integer{TDockOrientation}): Integer;
  152. function GetControlName: string;//获得控件的名称,如果没有控件就返回空字符串
  153. { 获得当前的节点内的子节点的分割条的ZoneLimit, 如果IsMin为True, 说明是取最小值,反之就取最大值 }
  154. function GetSplitterLimit(IsMin: Boolean): Integer; virtual;
  155. function DoGetSplitterLimit(Orientation: TDockOrientation;
  156. IsMin: Boolean; var LimitResult: Integer): Integer; virtual;
  157. {查找名字为Value的控件,如果找到就把她停靠进FTree中}
  158. function SetControlName(const Value: string): Boolean;
  159. procedure DoCustomSetControlName; virtual;
  160. procedure SetChildControlVisible(Client: TControl; AViisible: Boolean); virtual;
  161. public
  162. constructor Create(Tree: TCnDockTree); virtual;
  163. { 插入一个大小为DockSize的节点 }
  164. procedure Insert(DockSize: Integer; Hide: Boolean); virtual;
  165. { 去掉一个大小为DockSize的节点 }
  166. procedure Remove(DockSize: Integer; Hide: Boolean); virtual;
  167. { 当有一个控件停靠进来的时候,调用InsertOrRemove重新调整ParentZone上的子节点,
  168. 其中Insert指示是否是插入操作,如果Insert=True就是插入操作,否者就是删除操作 }
  169. procedure InsertOrRemove(DockSize: Integer; Insert: Boolean; Hide: Boolean); virtual;
  170. procedure ResetChildren(Exclude: TCnDockZone); virtual;//重新设置子女的属性,如坐标等
  171. { 更新当前节点(不包括子节点),调整当前的ChildControl的位置和大小 }
  172. procedure Update; virtual;
  173. { 获得这个节点的矩形位置 }
  174. function GetFrameRect: TRect; virtual;
  175. { 设置节点的大小 }
  176. procedure SetZoneSize(Size: Integer; Show: Boolean); virtual;
  177. { 离本节点最近的可见的前兄弟节点 }
  178. property BeforeClosestVisibleZone: TCnDockZone read GetBeforeClosestVisibleZone;
  179. { 离本节点最近的可见的后兄弟节点 }
  180. property AfterClosestVisibleZone: TCnDockZone read GetAfterClosestVisibleZone;
  181. { 离本节点最远的可见的前兄弟节点 }
  182. property BeforeApoapsisVisibleZone: TCnDockZone read GetBeforeApoapsisVisibleZone;
  183. { 离本节点最远的可见的后兄弟节点 }
  184. property AfterApoapsisVisibleZone: TCnDockZone read GetAfterApoapsisVisibleZone;
  185. { 第一个可见的子女节点 }
  186. property FirstVisibleChildZone: TCnDockZone read GetFirstVisibleChildZone;
  187. { 第一个可见的子女节点 }
  188. property LastVisibleChildZone: TCnDockZone read GetLastVisibleChildZone;
  189. { 子女个数 }
  190. property ChildCount: Integer read GetChildCount;
  191. { 末端子女个数 }
  192. property ChildTotal: Integer read GetChildTotal;
  193. { 第一个子女 }
  194. property ChildZones: TCnDockZone read FChildZones write FChildZones;
  195. { 在节点上的Control控件 }
  196. property ChildControl: TWinControl read FChildControl write FChildControl;
  197. { 第一个子女 }
  198. property FirstChild: TCnDockZone read GetFirstChild;
  199. { 第一个兄弟 }
  200. property FirstSibling: TCnDockZone read GetFirstSibling;
  201. { 高度 }
  202. property Height: Integer index Ord(doHorizontal) read GetHeightWidth;
  203. { 根据停靠方向来获得高度和宽度 }
  204. property HeightWidth[Orient: TDockOrientation]: Integer read GetHeightWidthArr;
  205. { 最后一个子女 }
  206. property LastChild: TCnDockZone read GetLastChild;
  207. { 最后一个兄弟 }
  208. property LastSibling: TCnDockZone read GetLastSibling;
  209. { 左边位置 }
  210. property Left: Integer index Ord(doVertical) read GetTopLeft;
  211. { 开始位置的坐标 }
  212. property LimitBegin: Integer read GetLimitBegin;
  213. { 大小 }
  214. property LimitSize: Integer read GetLimitSize;
  215. { 下一个兄弟 }
  216. property NextSibling: TCnDockZone read FNextSibling write FNextSibling;
  217. { 获得后兄弟的个数 }
  218. property NextSiblingCount: Integer read GetNextSiblingCount;
  219. { 停靠方向 }
  220. property Orientation: TDockOrientation read FOrientation write FOrientation;
  221. { 父节点 }
  222. property ParentZone: TCnDockZone read FParentZone write FParentZone;
  223. { 上一个兄弟 }
  224. property PrevSibling: TCnDockZone read FPrevSibling write FPrevSibling;
  225. { 获得前兄弟的个数 }
  226. property PrevSiblingCount: Integer read GetPrevSiblingCount;
  227. { 上边位置 }
  228. property Top: Integer index Ord(doHorizontal) read GetTopLeft;
  229. { 根据停靠方向来获得左边和上边位置 }
  230. property TopLeft[Orient: TDockOrientation]: Integer read GetTopLeftArr;
  231. { 属于哪个树 }
  232. property Tree: TCnDockTree read FTree write FTree;
  233. { 可见子女节点的个数 }
  234. property VisibleChildCount: Integer read GetVisibleChildCount;
  235. { 可见末端节点的个数 }
  236. property VisibleChildTotal: Integer read GetVisibleChildTotal;
  237. { 可见的上兄弟的个数 }
  238. property VisiblePrevSiblingCount: Integer read GetVisiblePrevSiblingCount;
  239. { 可见的上兄弟的末端节点的个数 }
  240. property VisiblePrevSiblingTotal: Integer read GetVisiblePrevSiblingTotal;
  241. { 可见的下兄弟的个数 }
  242. property VisibleNextSiblingCount: Integer read GetVisibleNextSiblingCount;
  243. { 可见的下兄弟的末端节点的个数 }
  244. property VisibleNextSiblingTotal: Integer read GetVisibleNextSiblingTotal;
  245. { 可见的大小 }
  246. property VisibleSize: Integer read FVisibleSize write FVisibleSize;
  247. { 宽度 }
  248. property Width: Integer index Ord(doVertical) read GetHeightWidth;
  249. { 相对于DockSite的绝对位置 }
  250. property ZoneLimit: Integer read FZoneLimit write SetZoneLimit;
  251. { 是否可见 }
  252. property Visibled: Boolean read FVisibled write SetVisibled;
  253. { 是否在里面 }
  254. property IsInside: Boolean read FIsInside write SetIsInside;
  255. end;
  256. TCnAdvDockZone = class(TCnDockZone)
  257. private
  258. FCloseBtnDown: Boolean;
  259. FMouseDown: Boolean;
  260. protected
  261. procedure LButtonDbClkMothed; override;
  262. public
  263. constructor Create(Tree: TCnDockTree); override;
  264. destructor Destroy; override;
  265. procedure Insert(DockSize: Integer; Hide: Boolean); override;
  266. procedure Remove(DockSize: Integer; Hide: Boolean); override;
  267. property CloseBtnDown: Boolean read FCloseBtnDown write FCloseBtnDown;
  268. property MouseDown: Boolean read FMouseDown write FMouseDown;
  269. end;
  270. { 树的遍历方式,分别是前序,中序和后序遍历 }
  271. TTreeScanKind = (tskForward, tskMiddle, tskBackward);
  272. { 树的遍历优先级别,分别是先遍历兄弟,先遍历子女 }
  273. TTreeScanPriority = (tspSibling, tspChild);
  274. TCnForEachZoneProc = procedure(Zone: TCnDockZone) of object;
  275. { 把手的位置,可以有四个位置,分别是上下左右 }
  276. TGrabbersPosition = (gpTop, gpBottom, gpLeft, gpRight);
  277. TCnDockZoneClass = class of TCnDockZone;
  278. TCnDockTree = class(TInterfacedObject, ICnDockManager)
  279. private
  280. {节点类的引用}
  281. FCnDockZoneClass: TCnDockZoneClass;
  282. {在树中哪个控件获得了焦点}
  283. FActiveControl: TControl;
  284. FBorderWidth: Integer; //边框的宽度
  285. FSplitterWidth: Integer; //分割条的宽度
  286. FBrush: TBrush; //用来画把手的刷子
  287. FDockSite: TWinControl; //停靠的服务控件
  288. FGrabberSize: Integer; //把手的大小
  289. FOldRect: TRect; //当DockSite的大小调整的时候,
  290. //这个值存储最后一次的DockSite的大小
  291. FDockRect: TRect;
  292. FOldWndProc: TWndMethod;
  293. FReplacementZone: TCnDockZone;
  294. FResizeCount: Integer; //调整DockSite大小的计数器
  295. FScaleBy: Double; //比例的大小
  296. { 当进行偏移量调整的时候,用来指示到底是什么停靠方向的Zone需要调整 }
  297. FShiftScaleOrient: TDockOrientation;
  298. FShiftBy: Integer; //偏移量
  299. FSizePos: TPoint; //当鼠标点击分割条时,记录下鼠标的坐标
  300. FSizingDC: HDC; //画分割条的设备上下文
  301. FSizingWnd: HWND;
  302. FSizingZone: TCnDockZone; //分割条属于哪个节点
  303. FTopZone: TCnDockZone; //根节点
  304. FTopXYLimit: Integer;
  305. FUpdateCount: Integer; //更新计数器
  306. FVersion: Integer; //版本
  307. FOldHTFlag: Integer; //老的鼠标的位置
  308. FParentLimit: Integer; //这个值是用来在调整ZoneLimit的时候用的,
  309. //具体公式见ScaleChildZone函数
  310. FMinSize: Integer; //停靠控件之间的最小距离
  311. FCanvas: TControlCanvas; //用来画DockSite的画布
  312. procedure SetTopZone(const Value: TCnDockZone);
  313. procedure SetTopXYLimit(const Value: Integer);
  314. { 设置TCnDockZone的类引用 }
  315. procedure SetCnDockZoneClass(const Value: TCnDockZoneClass);
  316. { 获得分割条的宽度 }
  317. function GetSplitterWidth: Integer;
  318. { 获得边框的宽度 }
  319. function GetBorderWidth: Integer;
  320. { 设置分割条的宽度 }
  321. procedure SetSplitterWidth(const Value: Integer);
  322. { 设置边框的宽度 }
  323. procedure SetBorderWidth(const Value: Integer);
  324. function GetDockSiteOrient: TDockOrientation;
  325. function GetDockSiteSize: Integer;
  326. procedure SetDockSiteSize(const Value: Integer);
  327. procedure SetMinSize(const Value: Integer);
  328. function GetDockSiteBegin: Integer;
  329. procedure SetDockSiteBegin(const Value: Integer);
  330. function GetDockSiteSizeA: Integer;
  331. procedure SetDockSiteSizeA(const Value: Integer);
  332. procedure SetVersion(const Value: Integer);
  333. function GetDockSiteSizeWithOrient(Orient: TDockOrientation): Integer;
  334. procedure SetDockSiteSizeWithOrient(Orient: TDockOrientation;
  335. const Value: Integer);
  336. function GetDockRect: TRect; //获得停靠矩形
  337. procedure SetDockRect(const Value: TRect); //设置停靠矩形
  338. function GetMinSize: Integer;
  339. protected
  340. function HasZoneWithControl(Control: TControl): Boolean;
  341. { 捕获的DockSite的窗口消息 }
  342. procedure WindowProc(var Message: TMessage); virtual;
  343. { ------------------------------------------------------------------------ }
  344. procedure BeginDrag(Control: TControl;
  345. Immediate: Boolean; Threshold: Integer = -1); virtual;
  346. { ------------------------------------------------------------------------ }
  347. function DoMouseEvent(var Message: TWMMouse;
  348. var Zone: TCnDockZone; out HTFlag: Integer): TWMNCHitMessage; virtual;
  349. { ------------------------------------------------------------------------ }
  350. { 当DockSite上有鼠标移动的时候调用DoMouseMove方法 }
  351. procedure DoMouseMove(var Message: TWMMouse;
  352. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  353. { 当DockSite上有鼠标左键按下的时候调用DoLButtonDown函数 }
  354. function DoLButtonDown(var Message: TWMMouse;
  355. var Zone: TCnDockZone; out HTFlag: Integer): Boolean; virtual;
  356. { 当DockSite上有鼠标左键释放的时候调用DoLButtonUp方法 }
  357. procedure DoLButtonUp(var Message: TWMMouse;
  358. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  359. { 当DockSite上有鼠标左键双击的时候调用DoLButtonDbClk方法 }
  360. procedure DoLButtonDbClk(var Message: TWMMouse;
  361. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  362. { 当DockSite上有鼠标中键按下的时候调用DoLButtonDown函数 }
  363. procedure DoMButtonDown(var Message: TWMMouse;
  364. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  365. { 当DockSite上有鼠标中键释放的时候调用DoLButtonUp方法 }
  366. procedure DoMButtonUp(var Message: TWMMouse;
  367. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  368. { 当DockSite上有鼠标左键双击的时候调用DoMButtonDbClk方法 }
  369. procedure DoMButtonDbClk(var Message: TWMMouse;
  370. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  371. { 当DockSite上有鼠标右键按下的时候调用DoLButtonDown函数 }
  372. procedure DoRButtonDown(var Message: TWMMouse;
  373. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  374. { 当DockSite上有鼠标右键释放的时候调用DoLButtonUp方法 }
  375. procedure DoRButtonUp(var Message: TWMMouse;
  376. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  377. { 当DockSite上有鼠标左键双击的时候调用DoRButtonDbClk方法 }
  378. procedure DoRButtonDbClk(var Message: TWMMouse;
  379. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  380. { ------------------------------------------------------------------------ }
  381. { 隐藏AZone中的ChildControl }
  382. procedure DoHideZoneChild(AZone: TCnDockZone); virtual;
  383. { ------------------------------------------------------------------------ }
  384. { 当DockSite上要设置光标形状的时候调用DoSetCursor方法 }
  385. procedure DoSetCursor(var Message: TWMSetCursor;
  386. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  387. { 当DockSite上出现提示框的时候调用DoHintShow方法 }
  388. procedure DoHintShow(var Message: TCMHintShow;
  389. var Zone: TCnDockZone; out HTFlag: Integer); virtual;
  390. { 其他的提示信息 }
  391. procedure DoOtherHint(Zone: TCnDockZone;
  392. HTFlag: Integer; var HintStr: string); virtual;
  393. { ------------------------------------------------------------------------ }
  394. procedure CustomSaveZone(Stream: TStream;
  395. Zone: TCnDockZone); virtual;
  396. procedure CustomLoadZone(Stream: TStream;
  397. var Zone: TCnDockZone); virtual;
  398. procedure DoSaveZone(Stream: TStream;
  399. Zone: TCnDockZone; Level: Integer); virtual;
  400. procedure DoLoadZone(Stream: TStream); virtual;
  401. { ------------------------------------------------------------------------ }
  402. { 调整Control控件的大小 }
  403. procedure AdjustDockRect(Control: TControl; var ARect: TRect); virtual;
  404. { 开始调整DockSite的大小,简单的使FResizeCount加一 }
  405. procedure BeginResizeDockSite;
  406. { 开始更新,简单的使FUpdateCount加一 }
  407. procedure BeginUpdate;
  408. { 计算并且限制分割条的位置 }
  409. procedure CalcSplitterPos; virtual;
  410. { 当Control控件的Visible属性改变的时候,调用ControlVisibilityChanged方法 }
  411. procedure ControlVisibilityChanged(Control: TControl; Visible: Boolean); virtual;
  412. { 获得Client在DropCtl中的位置 }
  413. function GetDockAlign(Client: TControl; var DropCtl: TControl): TAlign; virtual;
  414. { 这个函数是确定光标是在DockSite的什么位置 }
  415. function DoFindZone(const MousePos: TPoint;
  416. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone; virtual;
  417. { 画分割条移动的时候的外形 }
  418. procedure DrawSizeSplitter; virtual;
  419. { 结束调整DockSite的大小,把FResizeCount减一 }
  420. procedure EndResizeDockSite;
  421. { 结束更新,把FUpdateCount减一,如果FUpdateCount小于等于零的时候,就调用UpdateAll方法更新 }
  422. procedure EndUpdate;
  423. ////////////////////////////////////////////////////////////////////////////
  424. { 根据输入的Control参数查找到对应的Zone }
  425. function FindControlZone(Control: TControl; IncludeHide: Boolean = False): TCnDockZone; virtual;
  426. { 根据输入的Control参数查找到对应的Zone,并且返回这个Zone的Level }
  427. function FindControlZoneAndLevel(Control: TControl;
  428. var CtlLevel: Integer; IncludeHide: Boolean = False): TCnDockZone; virtual;
  429. ////////////////////////////////////////////////////////////////////////////
  430. { 对整棵树进行遍历 }
  431. procedure ForEachAt(Zone: TCnDockZone; Proc: TCnForEachZoneProc;
  432. ScanKind: TTreeScanKind = tskForward; ScanPriority: TTreeScanPriority = tspSibling); virtual;
  433. { 获得在DockSite中的活动的Control控件 }
  434. function GetActiveControl: TControl; virtual;
  435. { 获得把手的大小 }
  436. function GetGrabberSize: Integer; virtual;
  437. ////////////////////////////////////////////////////////////////////////////
  438. function GetBorderHTFlag(const MousePos: TPoint;
  439. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone; virtual;
  440. function GetLeftGrabbersHTFlag(const MousePos: TPoint;
  441. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone; virtual;
  442. function GetRightGrabbersHTFlag(const MousePos: TPoint;
  443. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone; virtual;
  444. function GetTopGrabbersHTFlag(const MousePos: TPoint;
  445. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone; virtual;
  446. function GetBottomGrabbersHTFlag(const MousePos: TPoint;
  447. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone; virtual;
  448. ////////////////////////////////////////////////////////////////////////////
  449. { 获得停靠预览矩形下面的Control }
  450. function GetDockEdge(DockRect: TRect; MousePos: TPoint;
  451. var DropAlign: TAlign; Control: TControl): TControl; virtual;
  452. ////////////////////////////////////////////////////////////////////////////
  453. { 获得停靠服务器上的停靠客户的极限, 相对于DockSite }
  454. function GetDockClientLimit(Orient: TDockOrientation; IsMin: Boolean): Integer; virtual;
  455. { 获得把手的矩形大小 }
  456. function GetFrameRect(Control: TControl): TRect; virtual;
  457. function GetFrameRectEx(Control: TControl): TRect; virtual;
  458. { 获得分割条的矩形大小 }
  459. function GetSpiltterRect(Zone: TCnDockZone): TRect; virtual;
  460. { 设置把手在什么位置 }
  461. function GetGrabbersPosition: TGrabbersPosition; virtual;
  462. { 获得Control控件的大小 }
  463. procedure GetControlBounds(Control: TControl; out CtlBounds: TRect); virtual;
  464. { 获得分割条的Limit }
  465. function GetSplitterLimit(AZone: TCnDockZone; IsCurrent, IsMin: Boolean): Integer; virtual;
  466. procedure DoGetNextLimit(Zone, AZone: TCnDockZone; var LimitResult: Integer); virtual;
  467. { 获得MousePos位置的HTFlag }
  468. function GetHTFlag(MousePos: TPoint): Integer; virtual;
  469. procedure GetSiteInfo(Client: TControl;
  470. var InfluenceRect: TRect; MousePos: TPoint; var CanDock: Boolean); virtual;
  471. { 根据输入的鼠标位置判断它下面的Control控件 }
  472. function HitTest(const MousePos: TPoint; out HTFlag: Integer): TControl; virtual;
  473. { 根据输入的鼠标位置判断它下面的Zone }
  474. function InternalHitTest(const MousePos: TPoint;
  475. out HTFlag: Integer): TCnDockZone; virtual;
  476. { 插入一个控件,其中InsertAt是插入的位置 }
  477. procedure InsertControl(Control: TControl; InsertAt: TAlign;
  478. DropCtl: TControl); virtual;
  479. { ------------------------------------------------------------------------ }
  480. { 创建一个新的Zone,然后把NewZone和SiblingZone作为它的ChildZones }
  481. procedure InsertNewParent(NewZone, SiblingZone: TCnDockZone;
  482. ParentOrientation: TDockOrientation; InsertLast, Update: Boolean); virtual;
  483. { 把NewZone作为SiblingZone的兄弟 }
  484. procedure InsertSibling(NewZone, SiblingZone: TCnDockZone;
  485. InsertLast, Update: Boolean); virtual;
  486. { ------------------------------------------------------------------------ }
  487. { 从流中装载停靠信息 }
  488. procedure LoadFromStream(Stream: TStream); virtual;
  489. { 把停靠信息存储到流中 }
  490. procedure SaveToStream(Stream: TStream); virtual;
  491. { 以下函数是画图函数 }
  492. {==========================================================================}
  493. { 重画整个区域 }
  494. procedure PaintDockSite; virtual;
  495. { 重画HostDockSite的矩形外形 }
  496. procedure DrawDockSiteRect; virtual;
  497. { 重画每一个节点 }
  498. procedure DrawZone(Zone: TCnDockZone); virtual;
  499. { 重画把手 }
  500. procedure DrawZoneGrabber(Zone: TCnDockZone); virtual;
  501. procedure DrawDockGrabber(Control: TControl; const ARect: TRect); virtual;
  502. { 重画分割条 }
  503. procedure DrawZoneSplitter(Zone: TCnDockZone); virtual;
  504. procedure DrawSplitterRect(const ARect: TRect); virtual;
  505. { 重画边框 }
  506. procedure DrawZoneBorder(Zone: TCnDockZone); virtual;
  507. { R1为内框大小,R2为外框大小 }
  508. procedure DrawDockBorder(DockControl: TControl; R1, R2: TRect); virtual;
  509. {==========================================================================}
  510. { 得到标题栏的大小 }
  511. procedure GetCaptionRect(var Rect: TRect); virtual;
  512. { 定位停靠位置 }
  513. procedure PositionDockRect(Client, DropCtl: TControl;
  514. DropAlign: TAlign; var DockRect: TRect); virtual;
  515. ////////////////////////////////////////////////////////////////////////////
  516. { 删除全部Zone }
  517. procedure PruneZone(Zone: TCnDockZone); virtual;
  518. { 删除单个Zone }
  519. procedure RemoveZone(Zone: TCnDockZone; Hide: Boolean = True); virtual;
  520. { 设置Zone的比例 }
  521. procedure ScaleZone(Zone: TCnDockZone); virtual;
  522. procedure ScaleChildZone(Zone: TCnDockZone); virtual; //遍历的时候调用这个函数调整
  523. //子女Zone的ZoneLimit的值
  524. procedure ScaleSiblingZone(Zone: TCnDockZone); virtual; //遍历的时候调用这个函数调整
  525. //兄弟Zone子女Zone的ZoneLimit的值
  526. { 调整Zone的偏移量 }
  527. procedure ShiftZone(Zone: TCnDockZone); virtual;
  528. { 更新Zone }
  529. procedure UpdateZone(Zone: TCnDockZone); virtual;
  530. { 画分割条 }
  531. procedure DrawSplitter(Zone: TCnDockZone); virtual;
  532. ////////////////////////////////////////////////////////////////////////////
  533. { 删除Control控件 }
  534. procedure RemoveControl(Control: TControl); virtual;
  535. { 设置DockSite中的活动Control控件 }
  536. procedure SetActiveControl(const Value: TControl); virtual;
  537. { 设置把手的大小 }
  538. procedure SetGrabberSize(const Value: Integer); virtual;
  539. { 设置Zone中ChildControl的大小,包括Zone的ChildZones }
  540. procedure SetNewBounds(Zone: TCnDockZone); virtual;
  541. procedure SetReplacingControl(Control: TControl);
  542. { 当鼠标点击分割条的时候调用SplitterMouseDown方法 }
  543. procedure SplitterMouseDown(OnZone: TCnDockZone; MousePos: TPoint); virtual;
  544. { 当鼠标释放分割条的时候调用SplitterMouseUp方法 }
  545. procedure SplitterMouseUp; virtual;
  546. { 重新设置范围 }
  547. procedure ResetBounds(Force: Boolean); virtual;
  548. { 把控件的名称写到流Stream里面 }
  549. procedure WriteControlName(Stream: TStream; ControlName: string);
  550. { 流Stream里面读出控件的名称 }
  551. procedure ReadControlName(Stream: TStream; var ControlName: string);
  552. ////////////////////////////////////////////////////////////////////////////
  553. procedure ShowControl(Control: TControl); //显示Control
  554. procedure HideControl(Control: TControl); //隐藏Control
  555. procedure ShowAllControl; // 显示所有的Control
  556. procedure HideAllControl; // 隐藏所有的Control
  557. procedure ShowSingleControl(Control: TControl); // 只显示一个Control,其他的都隐藏
  558. procedure HideSingleControl(Control: TControl); // 只隐藏一个Control,其他的都显示
  559. ////////////////////////////////////////////////////////////////////////////
  560. { 用新的NewControl替换老的OldControl }
  561. procedure ReplaceZoneChild(OldControl, NewControl: TControl);
  562. ////////////////////////////////////////////////////////////////////////////
  563. property BorderWidth: Integer read GetBorderWidth write SetBorderWidth;
  564. property Canvas: TControlCanvas read FCanvas;
  565. property DockSiteSize: Integer read GetDockSiteSize write SetDockSiteSize;
  566. property DockSiteSizeA: Integer read GetDockSiteSizeA write SetDockSiteSizeA;
  567. property DockSiteBegin: Integer read GetDockSiteBegin write SetDockSiteBegin;
  568. property DockSiteSizeWithOrient[Orient: TDockOrientation]: Integer
  569. read GetDockSiteSizeWithOrient write SetDockSiteSizeWithOrient;
  570. property GrabberSize: Integer read FGrabberSize write SetGrabberSize;
  571. property GrabbersPosition: TGrabbersPosition read GetGrabbersPosition;
  572. property MinSize: Integer read GetMinSize write SetMinSize;
  573. property DockRect: TRect read GetDockRect write SetDockRect;
  574. property OldRect: TRect read FOldRect write FOldRect;
  575. property ParentLimit: Integer read FParentLimit write FParentLimit;
  576. property ReplacementZone: TCnDockZone read FReplacementZone write FReplacementZone;
  577. property ResizeCount: Integer read FResizeCount write FResizeCount;
  578. property ScaleBy: Double read FScaleBy write FScaleBy;
  579. property ShiftBy: Integer read FShiftBy write FShiftBy;
  580. property ShiftScaleOrient: TDockOrientation read FShiftScaleOrient write FShiftScaleOrient;
  581. property SizePos: TPoint read FSizePos write FSizePos;
  582. property SizingDC: HDC read FSizingDC;
  583. property SizingWnd: HWND read FSizingWnd;
  584. property SizingZone: TCnDockZone read FSizingZone write FSizingZone;
  585. property SplitterWidth: Integer read GetSplitterWidth write SetSplitterWidth;
  586. property UpdateCount: Integer read FUpdateCount write FUpdateCount;
  587. property Version: Integer read FVersion write SetVersion;
  588. public
  589. SplitterCanvas: TControlCanvas;
  590. constructor Create(DockSite: TWinControl;
  591. CnDockZoneClass: TCnDockZoneClass); virtual;
  592. destructor Destroy; override;
  593. property DockSite: TWinControl read FDockSite write FDockSite;
  594. property DockSiteOrient: TDockOrientation read GetDockSiteOrient;
  595. { 设置分割条的鼠标形状,用户可以重载这个函数来改变鼠标的形状 }
  596. procedure SetSplitterCursor(CursorIndex: TDockOrientation); virtual;
  597. { 重画DockSite的界面 }
  598. procedure PaintSite(DC: HDC); virtual;
  599. property TopXYLimit: Integer read FTopXYLimit write SetTopXYLimit;
  600. property TopZone: TCnDockZone read FTopZone write SetTopZone;
  601. { 更新全部 }
  602. procedure UpdateAll;
  603. { 更新当前Zone的子女 }
  604. procedure UpdateChild(Zone: TCnDockZone);
  605. property CnDockZoneClass: TCnDockZoneClass read FCnDockZoneClass
  606. write SetCnDockZoneClass;
  607. end;
  608. TCnDockTreeClass = class of TCnDockTree;
  609. TCnAdvDockTree = class(TCnDockTree)
  610. private
  611. FButtonHeight, //关闭按钮的高度
  612. FButtonWidth, //关闭按钮的宽度
  613. FLeftOffset, //关闭按钮的左边偏移量
  614. FRightOffset, //关闭按钮的右边偏移量
  615. FTopOffset, //关闭按钮的上边偏移量
  616. FBottomOffset: Integer; //关闭按钮的下边偏移量
  617. FButtonSplitter: Integer; //按钮之间的间隔
  618. FCloseBtnZone: TCnAdvDockZone;
  619. FDropDockSize: Integer;
  620. FDockHeightWidth: array[TDockOrientation] of Integer;
  621. FDockRectArr: array[TDockOrientation, Boolean] of Integer;
  622. procedure SetBottomOffset(const Value: Integer);
  623. procedure SetButtonHeight(const Value: Integer);
  624. procedure SetButtonSplitter(const Value: Integer);
  625. procedure SetButtonWidth(const Value: Integer);
  626. procedure SetLeftOffset(const Value: Integer);
  627. procedure SetRightOffset(const Value: Integer);
  628. procedure SetTopOffset(const Value: Integer);
  629. function GetDockHeightWidth(Orient: TDockOrientation): Integer;
  630. procedure SetDockHeightWidth(Orient: TDockOrientation;
  631. const Value: Integer);
  632. function GetDockRectFromArr(Orient: TDockOrientation;
  633. AtLast: Boolean): Integer;
  634. procedure SetDockRectToArr(Orient: TDockOrientation; AtLast: Boolean;
  635. const Value: Integer);
  636. procedure SetDropDockSize(const Value: Integer);
  637. protected
  638. function DoLButtonDown(var Message: TWMMouse;
  639. var Zone: TCnDockZone; out HTFlag: Integer): Boolean; override;
  640. procedure DoLButtonUp(var Message: TWMMouse;
  641. var Zone: TCnDockZone; out HTFlag: Integer); override;
  642. procedure DoMouseMove(var Message: TWMMouse;
  643. var Zone: TCnDockZone; out HTFlag: Integer); override;
  644. procedure InsertSibling(NewZone, SiblingZone: TCnDockZone;
  645. InsertLast, Update: Boolean); override;
  646. procedure InsertNewParent(NewZone, SiblingZone: TCnDockZone;
  647. ParentOrientation: TDockOrientation; InsertLast, Update: Boolean); override;
  648. procedure SetDockHeightWidthArr(NoOrValue, HorValue, VerValue: Integer);
  649. procedure SetDockRectArr(ARect: TRect);
  650. procedure ScaleZone(Zone: TCnDockZone); override;
  651. procedure ScaleChildZone(Zone: TCnDockZone); override;
  652. procedure ScaleSiblingZone(Zone: TCnDockZone); override;
  653. procedure ShiftZone(Zone: TCnDockZone); override;
  654. procedure RemoveZone(Zone: TCnDockZone; Hide: Boolean); override;
  655. public
  656. constructor Create(DockSite: TWinControl;
  657. CnDockZoneClass: TCnDockZoneClass); override;
  658. property BottomOffset: Integer read FBottomOffset write SetBottomOffset;
  659. property ButtonHeight: Integer read FButtonHeight write SetButtonHeight;
  660. property ButtonSplitter: Integer read FButtonSplitter write SetButtonSplitter;
  661. property ButtonWidth: Integer read FButtonWidth write SetButtonWidth;
  662. property LeftOffset: Integer read FLeftOffset write SetLeftOffset;
  663. property RightOffset: Integer read FRightOffset write SetRightOffset;
  664. property TopOffset: Integer read FTopOffset write SetTopOffset;
  665. property CloseBtnZone: TCnAdvDockZone read FCloseBtnZone write FCloseBtnZone;
  666. property DockHeightWidth[Orient: TDockOrientation]: Integer read GetDockHeightWidth write SetDockHeightWidth;
  667. property DockRectArr[Orient: TDockOrientation; AtLast: Boolean]: Integer read GetDockRectFromArr write SetDockRectToArr;
  668. property DropDockSize: Integer read FDropDockSize write SetDropDockSize;
  669. end;
  670. var
  671. //存储树信息的流的结束标志
  672. TreeStreamEndFlag: Integer = -1;
  673. implementation
  674. uses
  675. Math, CnDockFormControl, CnDockSupportProc, CnDockGlobal, CnVSNETDockStyle;
  676. type
  677. TCnWinControlAccess = class(TWinControl);
  678. { TCnDockZone }
  679. constructor TCnDockZone.Create(Tree: TCnDockTree);
  680. begin
  681. // FVisibleSize := 0;
  682. ParentZone := nil;
  683. PrevSibling := nil;
  684. NextSibling := nil;
  685. ChildZones := nil;
  686. ChildControl := nil;
  687. FTree := Tree;
  688. FVisibled := True;
  689. end;
  690. function TCnDockZone.GetChildCount: Integer;
  691. var
  692. Zone: TCnDockZone;
  693. begin
  694. Result := 0;
  695. Zone := ChildZones;
  696. while Zone <> nil do
  697. begin
  698. Zone := Zone.NextSibling;
  699. Inc(Result);
  700. end;
  701. end;
  702. function TCnDockZone.GetLimitBegin: Integer;
  703. var
  704. CheckZone: TCnDockZone;
  705. begin
  706. if FTree.FTopZone = Self then CheckZone := Self
  707. else CheckZone := FParentZone;
  708. if CheckZone.Orientation = doHorizontal then Result := Top
  709. else if CheckZone.Orientation = doVertical then Result := Left
  710. else Result := 0;//raise Exception.Create('');
  711. end;
  712. function TCnDockZone.GetLimitSize: Integer;
  713. var
  714. CheckZone: TCnDockZone;
  715. begin
  716. if FTree.FTopZone = Self then CheckZone := Self
  717. else CheckZone := FParentZone;
  718. if CheckZone.Orientation = doHorizontal then Result := Height
  719. else if CheckZone.Orientation = doVertical then Result := Width
  720. else Result := Tree.TopXYLimit; //raise Exception.Create('');
  721. end;
  722. function TCnDockZone.GetTopLeft(Orient: Integer{TDockOrientation}): Integer;
  723. var
  724. Zone: TCnDockZone;
  725. R: TRect;
  726. begin
  727. Zone := Self;
  728. while Zone <> FTree.FTopZone do
  729. begin
  730. // 找到可见的上兄弟。
  731. if (Zone.VisiblePrevSiblingCount > 0) and (Zone.ParentZone.Orientation = TDockOrientation(Orient)) then
  732. begin
  733. Result := Zone.BeforeClosestVisibleZone.ZoneLimit;
  734. Exit;
  735. end else Zone := Zone.ParentZone;
  736. end;
  737. R := FTree.FDockSite.ClientRect;
  738. TCnWinControlAccess(FTree.FDockSite).AdjustClientRect(R);
  739. case TDockOrientation(Orient) of
  740. doVertical: Result := R.Left;
  741. doHorizontal: Result := R.Top;
  742. else
  743. Result := 0;
  744. end;
  745. end;
  746. function TCnDockZone.GetHeightWidth(Orient: Integer{TDockOrientation}): Integer;
  747. var
  748. Zone: TCnDockZone;
  749. R: TRect;
  750. begin
  751. if (Self = FTree.FTopZone) or ((FParentZone = FTree.FTopZone) and
  752. (ChildControl <> nil) and (FTree.FTopZone.ChildCount = 1)) then
  753. begin
  754. R := FTree.FDockSite.ClientRect;
  755. TCnWinControlAccess(FTree.FDockSite).AdjustClientRect(R);
  756. if TDockOrientation(Orient) = doHorizontal then
  757. Result := R.Bottom - R.Top
  758. else
  759. Result := R.Right - R.Left;
  760. end
  761. else begin
  762. Zone := Self;
  763. while (Zone <> FTree.FTopZone) and (Zone.ParentZone <> nil) do
  764. begin
  765. // 存储
  766. // BeginLimit := Zone.LimitBegin;
  767. // while (Zone.NextSibling <> nil) and (not Zone.NextSibling.Visibled) do
  768. // Zone := Zone.NextSibling;
  769. if {(Zone.VisiblePrevSiblingCount > 0) and }(Zone.ParentZone.Orientation = TDockOrientation(Orient)) then
  770. begin
  771. Result := Zone.ZoneLimit - Zone.LimitBegin;
  772. Exit;
  773. end
  774. else
  775. Zone := Zone.ParentZone;
  776. end;
  777. if FTree.FTopZone.Orientation = TDockOrientation(Orient) then
  778. Result := FTree.TopXYLimit
  779. else
  780. Result := FTree.FTopZone.ZoneLimit;
  781. end;
  782. end;
  783. procedure TCnDockZone.ResetChildren(Exclude: TCnDockZone);
  784. var
  785. SumLimit,
  786. NewLimit,
  787. FirstChildBegin,
  788. OldPrevLimit: Integer;
  789. ChildNode: TCnDockZone; // 当前的子女节点(可见的)
  790. PrevNode: TCnDockZone; // 当前的子女节点的前兄弟(可见的)
  791. begin
  792. //
  793. case Orientation of
  794. doHorizontal: NewLimit := Height;
  795. doVertical: NewLimit := Width;
  796. else
  797. Exit;
  798. end;
  799. // 得到第一个可见的子女节点,并且确保它是存在的。
  800. ChildNode := FirstVisibleChildZone;
  801. if ChildNode = nil then Exit;
  802. // 得到平分的ZoneLimit的值
  803. SumLimit := NewLimit;
  804. NewLimit := NewLimit div VisibleChildCount;
  805. FirstChildBegin := ChildNode.LimitBegin;
  806. Tree.ShiftScaleOrient := Orientation;
  807. Tree.ParentLimit := 0;
  808. if ChildNode.ZoneLimit - FirstChildBegin > 0 then
  809. Tree.ScaleBy := NewLimit / (ChildNode.ZoneLimit - FirstChildBegin)
  810. else Tree.ScaleBy := 1;
  811. if (Tree.ScaleBy <> 1) and (ChildNode.VisibleChildCount > 0) then
  812. Tree.ForEachAt(ChildNode.ChildZones, Tree.ScaleChildZone, tskMiddle, tspChild);
  813. if ChildNode <> Exclude then
  814. OldPrevLimit := ChildNode.ZoneLimit
  815. else OldPrevLimit := FirstChildBegin;
  816. // 给第一个可见的子女节点的ZoneLimit赋值
  817. ChildNode.ZoneLimit := FirstChildBegin + NewLimit;
  818. ChildNode.Update;
  819. // 保存ChildNode,因为在后面的程序中要用到
  820. PrevNode := ChildNode;
  821. ChildNode := ChildNode.AfterClosestVisibleZone;
  822. // 一直不断的循环,直到最后一个可见的可见的子女节点为止。
  823. while ChildNode <> nil do
  824. begin
  825. if ChildNode.ZoneLimit - OldPrevLimit > 0 then
  826. Tree.ScaleBy := NewLimit / (ChildNode.ZoneLimit - OldPrevLimit)
  827. else Tree.ScaleBy := 1;
  828. Tree.ShiftBy := PrevNode.ZoneLimit - OldPrevLimit;
  829. if (Tree.ShiftBy <> 0) and (ChildNode.VisibleChildCount > 0){ and (PrevNode <> Exclude) }then
  830. Tree.ForEachAt(ChildNode.ChildZones, Tree.ShiftZone, tskForward);
  831. Tree.ParentLimit := PrevNode.ZoneLimit;
  832. if (Tree.ScaleBy <> 1) and (ChildNode.VisibleChildCount > 0) then
  833. Tree.ForEachAt(ChildNode.ChildZones, Tree.ScaleChildZone, tskForward);
  834. if ChildNode <> Exclude then
  835. OldPrevLimit := ChildNode.ZoneLimit;
  836. // else OldPrevLimit := PrevNode.ZoneLimit;
  837. ChildNode.ZoneLimit := PrevNode.ZoneLimit + NewLimit;
  838. if ChildNode.AfterClosestVisibleZone = nil then
  839. begin
  840. // 取消除零错误
  841. if NewLimit = 0 then
  842. NewLimit := 1;
  843. ChildNode.ZoneLimit := ChildNode.ZoneLimit + (SumLimit mod NewLimit);
  844. end;
  845. ChildNode.Update;
  846. PrevNode := ChildNode;
  847. ChildNode := ChildNode.AfterClosestVisibleZone;
  848. end;
  849. end;
  850. function TCnDockZone.GetControlName: string;
  851. begin
  852. Result := '';
  853. if ChildControl <> nil then
  854. begin
  855. if ChildControl.Name = '' then
  856. raise Exception.CreateRes(@SDockedCtlNeedsName);
  857. Result := ChildControl.Name;
  858. end;
  859. end;
  860. function TCnDockZone.SetControlName(const Value: string): Boolean;
  861. var
  862. Client: TControl;
  863. begin
  864. Client := nil;
  865. with FTree do
  866. begin
  867. TCnWinControlAccess(FDockSite).ReloadDockedControl(Value, Client);
  868. Result := Client <> nil;
  869. if Result then
  870. begin
  871. FReplacementZone := Self;
  872. ChildControl := TWinControl(Client);
  873. DoCustomSetControlName;
  874. try
  875. if IsInside then
  876. begin
  877. Client.ManualDock(FDockSite, nil, alNone);
  878. // CnGlobalDockPresident.CalcDockSizes(Client);
  879. end;
  880. // ResetBounds(True);
  881. finally
  882. SetChildControlVisible(Client, FControlVisibled);
  883. FReplacementZone := nil;
  884. end;
  885. end;
  886. end;
  887. end;
  888. procedure TCnDockZone.Update;
  889. function ParentNotLast: Boolean;
  890. var
  891. Parent: TCnDockZone;
  892. begin
  893. Result := False;
  894. Parent := FParentZone;
  895. while Parent <> nil do
  896. begin
  897. if (Parent.VisibleNextSiblingCount > 0) and (Parent.Orientation = ParentZone.Orientation) then
  898. begin
  899. Result := True;
  900. Exit;
  901. end;
  902. Parent := Parent.FParentZone;
  903. end;
  904. end;
  905. var
  906. NewWidth, NewHeight: Integer;
  907. R: TRect;
  908. begin
  909. if Visibled and (ChildControl <> nil) and (FTree.FUpdateCount = 0) then
  910. begin
  911. ChildControl.DockOrientation := FParentZone.Orientation;
  912. NewWidth := Width;
  913. NewHeight := Height;
  914. if ParentNotLast then
  915. begin
  916. if FParentZone.Orientation = doHorizontal then
  917. Dec(NewWidth, FTree.SplitterWidth)
  918. else
  919. Dec(NewHeight, FTree.SplitterWidth);
  920. end;
  921. if ((NextSibling <> nil) and (VisibleNextSiblingTotal > 0)) or ((FParentZone <> FTree.FTopZone) and
  922. ((FParentZone.Orientation = FTree.FTopZone.Orientation) and
  923. (FZoneLimit < FTree.TopXYLimit)) or
  924. ((FParentZone.Orientation <> FTree.FTopZone.Orientation) and
  925. (FZoneLimit < FTree.FTopZone.ZoneLimit))) then
  926. begin
  927. if FParentZone.Orientation = doHorizontal then
  928. Dec(NewHeight, FTree.SplitterWidth)
  929. else
  930. Dec(NewWidth, FTree.SplitterWidth);
  931. end;
  932. R := Bounds(Left, Top, NewWidth, NewHeight);
  933. FTree.AdjustDockRect(ChildControl, R);
  934. ChildControl.BoundsRect := R;
  935. end;
  936. end;
  937. function TCnDockZone.GetFrameRect: TRect;
  938. var
  939. ALeft, ATop, ARight, ABottom, BorderWidth: Integer;
  940. begin
  941. ALeft := Left;
  942. ATop := Top;
  943. if NextSibling <> nil then
  944. BorderWidth := Tree.BorderWidth
  945. else
  946. BorderWidth := 0;
  947. ARight := ALeft + Width - BorderWidth;
  948. ABottom := ATop + Height - BorderWidth;
  949. Result := Rect(ALeft, ATop, ARight, ABottom);
  950. end;
  951. function TCnDockZone.GetFirstSibling: TCnDockZone;
  952. begin
  953. Result := Self;
  954. while Result.PrevSibling <> nil do
  955. Result := Result.PrevSibling;
  956. end;
  957. function TCnDockZone.GetLastSibling: TCnDockZone;
  958. begin
  959. Result := Self;
  960. while (Result <> nil) and (Result.NextSibling <> nil) do
  961. Result := Result.NextSibling;
  962. end;
  963. function TCnDockZone.GetFirstChild: TCnDockZone;
  964. begin
  965. Result := ChildZones;
  966. end;
  967. function TCnDockZone.GetLastChild: TCnDockZone;
  968. begin
  969. Result := ChildZones;
  970. if Result <> nil then
  971. Result := Result.LastSibling;
  972. end;
  973. function TCnDockZone.GetTopLeftArr(Orient: TDockOrientation): Integer;
  974. begin
  975. Result := 0;
  976. case Orient of
  977. doHorizontal: Result := Top;
  978. doVertical: Result := Left;
  979. else
  980. // raise Exception.Create('');
  981. end;
  982. end;
  983. function TCnDockZone.GetHeightWidthArr(Orient: TDockOrientation): Integer;
  984. begin
  985. Result := 0;
  986. case Orient of
  987. doHorizontal: Result := Height;
  988. doVertical: Result := Width;
  989. else
  990. // raise Exception.Create('');
  991. end;
  992. end;
  993. procedure TCnDockZone.AdjustZoneLimit(Value: Integer);
  994. begin
  995. FZoneLimit := Value;
  996. if PrevSibling <> nil then
  997. PrevSibling.ZoneLimit := PrevSibling.ZoneLimit + Value;
  998. // else if NextSibling <> nil then
  999. // NextSibling.ZoneLimit := NextSibling.ZoneLimit
  1000. end;
  1001. procedure TCnDockZone.SetZoneSize(Size: Integer; Show: Boolean);
  1002. begin
  1003. InsertOrRemove(Size, Show, False);
  1004. end;
  1005. procedure TCnDockZone.InsertOrRemove(DockSize: Integer; Insert: Boolean; Hide: Boolean);
  1006. begin
  1007. end;
  1008. procedure TCnDockZone.Insert(DockSize: Integer; Hide: Boolean);
  1009. begin
  1010. InsertOrRemove(DockSize, True, Hide);
  1011. // 如果ParentZone的VisibleChildCount等于0,
  1012. // 说明父节点也是隐藏的,就要调用父节点的Insert函数,
  1013. // 注意,这是一个递归函数,一直调用到父节点可见为止。
  1014. if (ParentZone <> nil) and (ParentZone.VisibleChildCount = 0) then
  1015. ParentZone.Insert(ParentZone.VisibleSize, Hide);
  1016. Visibled := True;
  1017. if ParentZone <> nil then
  1018. ParentZone.ResetChildren(Self);
  1019. // 重新更新ParentZone上的子女节点的位置
  1020. Tree.SetNewBounds(ParentZone);
  1021. Tree.UpdateChild(ParentZone);
  1022. end;
  1023. procedure TCnDockZone.Remove(DockSize: Integer; Hide: Boolean);
  1024. var Zone: TCnDockZone;
  1025. begin
  1026. InsertOrRemove(DockSize, False, Hide);
  1027. // 首先设置Visibled。
  1028. Visibled := not Hide;
  1029. // 如果有ParentZone,并且这个ParentZone上没有可见的子女,就把ParentZone也Remove,
  1030. // 这是一个递归函数,目的是使调整从最上层的Zone开始。
  1031. if (ParentZone <> Tree.TopZone) and (ParentZone.VisibleChildCount = 0) then
  1032. ParentZone.Remove(ParentZone.LimitSize, Hide);
  1033. // 如果已经没有可见的后面的兄弟,就把前兄弟的ZoneLimit设成当前Zone的ZoneLimit。
  1034. if AfterClosestVisibleZone = nil then
  1035. begin
  1036. // 找到离当前Zone最近的可见的前兄弟。
  1037. Zone := BeforeClosestVisibleZone;
  1038. if Zone <> nil then
  1039. begin
  1040. // 如果有可见的前兄弟,就调整这个兄弟的所有子女的位置。
  1041. Zone.ZoneLimit := ZoneLimit;
  1042. Tree.SetNewBounds(Zone);
  1043. end;
  1044. end;
  1045. // 因为当前的Zone将被撤消,所以ZoneLimit被设成和LimitBegin一样的。
  1046. ZoneLimit := LimitBegin;
  1047. end;
  1048. function TCnDockZone.GetVisibleChildCount: Integer;
  1049. var
  1050. Zone: TCnDockZone;
  1051. begin
  1052. Result := 0;
  1053. Zone := ChildZones;
  1054. while Zone <> nil do
  1055. begin
  1056. if Zone.Visibled then
  1057. Inc(Result);
  1058. Zone := Zone.NextSibling;
  1059. end;
  1060. end;
  1061. function TCnDockZone.GetChildTotal: Integer;
  1062. procedure DoFindChildCount(Zone: TCnDockZone);
  1063. begin
  1064. if Zone <> nil then
  1065. begin
  1066. DoFindChildCount(Zone.NextSibling);
  1067. DoFindChildCount(Zone.ChildZones);
  1068. {if Zone.Orientation = doNoOrient then}
  1069. Inc(Result);
  1070. end;
  1071. end;
  1072. begin
  1073. Result := 0;
  1074. DoFindChildCount(ChildZones);
  1075. end;
  1076. function TCnDockZone.GetVisibleChildTotal: Integer;
  1077. procedure DoFindVisibleChildCount(Zone: TCnDockZone);
  1078. begin
  1079. if Zone <> nil then
  1080. begin
  1081. DoFindVisibleChildCount(Zone.NextSibling);
  1082. DoFindVisibleChildCount(Zone.ChildZones);
  1083. if {(Zone.Orientation = doNoOrient) and }(Zone.Visibled) then
  1084. Inc(Result);
  1085. end;
  1086. end;
  1087. begin
  1088. Result := 0;
  1089. DoFindVisibleChildCount(ChildZones);
  1090. end;
  1091. function TCnDockZone.GetAfterClosestVisibleZone: TCnDockZone;
  1092. begin
  1093. Result := NextSibling;
  1094. while Result <> nil do
  1095. begin
  1096. if Result.Visibled then
  1097. Exit;
  1098. Result := Result.NextSibling;
  1099. end;
  1100. end;
  1101. function TCnDockZone.GetBeforeClosestVisibleZone: TCnDockZone;
  1102. begin
  1103. Result := PrevSibling;
  1104. while Result <> nil do
  1105. begin
  1106. if Result.Visibled then
  1107. Exit;
  1108. Result := Result.PrevSibling;
  1109. end;
  1110. end;
  1111. function TCnDockZone.GetAfterApoapsisVisibleZone: TCnDockZone;
  1112. begin
  1113. Result := LastSibling;
  1114. if Result <> nil then
  1115. Result := Result.BeforeClosestVisibleZone;
  1116. if Self = Result then
  1117. Result := nil;
  1118. end;
  1119. function TCnDockZone.GetBeforeApoapsisVisibleZone: TCnDockZone;
  1120. begin
  1121. Result := ParentZone.ChildZones;
  1122. if Result <> Self then
  1123. Result := Result.AfterClosestVisibleZone;
  1124. if Self = Result then
  1125. Result := nil;
  1126. end;
  1127. function TCnDockZone.GetNextSiblingCount: Integer;
  1128. var AZone: TCnDockZone;
  1129. begin
  1130. Result := 0;
  1131. AZone := NextSibling;
  1132. while AZone <> nil do
  1133. begin
  1134. Inc(Result);
  1135. AZone := AZone.NextSibling;
  1136. end;
  1137. end;
  1138. function TCnDockZone.GetPrevSiblingCount: Integer;
  1139. var AZone: TCnDockZone;
  1140. begin
  1141. Result := 0;
  1142. AZone := PrevSibling;
  1143. while AZone <> nil do
  1144. begin
  1145. Inc(Result);
  1146. AZone := AZone.PrevSibling;
  1147. end;
  1148. end;
  1149. procedure TCnDockZone.SetVisibled(const Value: Boolean);
  1150. begin
  1151. FVisibled := Value;
  1152. if (not FVisibled) and (Self <> Tree.TopZone) then
  1153. begin
  1154. if ParentZone.Orientation = doNoOrient then
  1155. VisibleSize := Tree.TopXYLimit
  1156. else VisibleSize := LimitSize;
  1157. end else
  1158. begin
  1159. end;
  1160. end;
  1161. function TCnDockZone.GetVisibleNextSiblingCount: Integer;
  1162. var
  1163. Zone: TCnDockZone;
  1164. begin
  1165. Result := 0;
  1166. Zone := NextSibling;
  1167. while Zone <> nil do
  1168. begin
  1169. if Zone.Visibled then
  1170. Inc(Result);
  1171. Zone := Zone.NextSibling;
  1172. end;
  1173. end;
  1174. function TCnDockZone.GetVisibleNextSiblingTotal: Integer;
  1175. procedure DoFindVisibleNextSiblingCount(Zone: TCnDockZone);
  1176. begin
  1177. if Zone <> nil then
  1178. begin
  1179. DoFindVisibleNextSiblingCount(Zone.NextSibling);
  1180. DoFindVisibleNextSiblingCount(Zone.ChildZones);
  1181. if {(Zone.Orientation = doNoOrient) and }(Zone.Visibled) then
  1182. Inc(Result);
  1183. end;
  1184. end;
  1185. begin
  1186. Result := 0;
  1187. DoFindVisibleNextSiblingCount(NextSibling);
  1188. end;
  1189. function TCnDockZone.GetVisiblePrevSiblingCount: Integer;
  1190. var
  1191. Zone: TCnDockZone;
  1192. begin
  1193. Result := 0;
  1194. Zone := PrevSibling;
  1195. while Zone <> nil do
  1196. begin
  1197. if Zone.Visibled then
  1198. Inc(Result);
  1199. Zone := Zone.PrevSibling;
  1200. end;
  1201. end;
  1202. function TCnDockZone.GetVisiblePrevSiblingTotal: Integer;
  1203. procedure DoFindVisibleNextSiblingCount(Zone: TCnDockZone);
  1204. begin
  1205. if (Zone <> nil) and (Zone <> Self) then
  1206. begin
  1207. DoFindVisibleNextSiblingCount(Zone.NextSibling);
  1208. DoFindVisibleNextSiblingCount(Zone.ChildZones);
  1209. if {(Zone.Orientation = doNoOrient) and }(Zone.Visibled) then
  1210. Inc(Result);
  1211. end;
  1212. end;
  1213. begin
  1214. Result := 0;
  1215. DoFindVisibleNextSiblingCount(ParentZone);
  1216. end;
  1217. procedure TCnDockZone.SetZoneLimit(const Value: Integer);
  1218. begin
  1219. FZoneLimit := Value;
  1220. end;
  1221. function TCnDockZone.GetFirstVisibleChildZone: TCnDockZone;
  1222. begin
  1223. Result := ChildZones;
  1224. while (Result <> nil) and (not Result.Visibled) do
  1225. Result := Result.NextSibling;
  1226. end;
  1227. function TCnDockZone.GetSplitterLimit(IsMin: Boolean): Integer;
  1228. begin
  1229. if IsMin then
  1230. Result := ZoneLimit
  1231. else Result := LimitBegin;
  1232. if ChildZones <> nil then
  1233. ChildZones.DoGetSplitterLimit(ParentZone.Orientation, IsMin, Result);
  1234. end;
  1235. function TCnDockZone.DoGetSplitterLimit(Orientation: TDockOrientation;
  1236. IsMin: Boolean; var LimitResult: Integer): Integer;
  1237. begin
  1238. Result := 0;
  1239. if (ParentZone <> nil) and (ParentZone.Orientation = Orientation) and Visibled then
  1240. begin
  1241. if IsMin then
  1242. LimitResult := Min(LimitResult, ZoneLimit)
  1243. else
  1244. begin
  1245. if AfterClosestVisibleZone <> nil then
  1246. LimitResult := Max(LimitResult, ZoneLimit);
  1247. end;
  1248. end;
  1249. if NextSibling <> nil then
  1250. NextSibling.DoGetSplitterLimit(Orientation, IsMin, LimitResult);
  1251. if ChildZones <> nil then
  1252. ChildZones.DoGetSplitterLimit(Orientation, IsMin, LimitResult);
  1253. end;
  1254. function TCnDockZone.GetLastVisibleChildZone: TCnDockZone;
  1255. var Zone: TCnDockZone;
  1256. begin
  1257. Result := nil;
  1258. Zone := ChildZones;
  1259. while (Zone <> nil) and Zone.Visibled do
  1260. begin
  1261. Result := Zone;
  1262. Zone := Zone.NextSibling;
  1263. end;
  1264. end;
  1265. procedure TCnDockZone.DoCustomSetControlName;
  1266. begin
  1267. { 没事做 }
  1268. end;
  1269. procedure TCnDockZone.LButtonDbClkMothed;
  1270. begin
  1271. if ChildControl <> nil then
  1272. ChildControl.ManualDock(nil, nil, alTop);
  1273. end;
  1274. procedure TCnDockZone.SetIsInside(const Value: Boolean);
  1275. begin
  1276. FIsInside := Value;
  1277. end;
  1278. procedure TCnDockZone.SetChildControlVisible(Client: TControl; AViisible: Boolean);
  1279. begin
  1280. if Client <> nil then
  1281. begin
  1282. Client.Visible := {(not IsInside) or }FControlVisibled;
  1283. end;
  1284. end;
  1285. { TCnDockTree }
  1286. constructor TCnDockTree.Create(DockSite: TWinControl;
  1287. CnDockZoneClass: TCnDockZoneClass);
  1288. var
  1289. I: Integer;
  1290. begin
  1291. FCnDockZoneClass := CnDockZoneClass;
  1292. FBorderWidth := 0;
  1293. FSplitterWidth := 4;
  1294. FDockSite := TWinControl(DockSite);
  1295. FDockSite.ShowHint := True;
  1296. FVersion := gs_BaseDockTreeVersion;
  1297. GrabberSize := 12;
  1298. FMinSize := 12;
  1299. FTopZone := FCnDockZoneClass.Create(Self);
  1300. FBrush := TBrush.Create;
  1301. FBrush.Bitmap := AllocPatternBitmap(clBlack, clWhite);
  1302. // 插入已经存在的控件到树中
  1303. BeginUpdate;
  1304. try
  1305. for I := 0 to DockSite.ControlCount - 1 do
  1306. InsertControl(DockSite.Controls[I], alLeft, nil);
  1307. FTopZone.ResetChildren(nil);
  1308. finally
  1309. EndUpdate;
  1310. end;
  1311. if not (csDesigning in DockSite.ComponentState) then
  1312. begin
  1313. FOldWndProc := FDockSite.WindowProc;
  1314. FDockSite.WindowProc := WindowProc;
  1315. end;
  1316. end;
  1317. destructor TCnDockTree.Destroy;
  1318. begin
  1319. if @FOldWndProc <> nil then
  1320. FDockSite.WindowProc := FOldWndProc;
  1321. PruneZone(FTopZone);
  1322. FBrush.Free;
  1323. inherited Destroy;
  1324. end;
  1325. procedure TCnDockTree.AdjustDockRect(Control: TControl; var ARect: TRect);
  1326. begin
  1327. { 为控件分配空间 }
  1328. { 首先减去边框的宽度 }
  1329. InflateRect(ARect, -BorderWidth, -BorderWidth);
  1330. { 然后再减去把手的宽度 }
  1331. case GrabbersPosition of
  1332. gpTop:
  1333. Inc(ARect.Top, GrabberSize);
  1334. gpBottom:
  1335. Dec(ARect.Bottom, GrabberSize);
  1336. gpLeft:
  1337. Inc(ARect.Left, GrabberSize);
  1338. gpRight:
  1339. Dec(ARect.Right, GrabberSize);
  1340. end;
  1341. end;
  1342. procedure TCnDockTree.BeginUpdate;
  1343. begin
  1344. Inc(FUpdateCount);
  1345. end;
  1346. procedure TCnDockTree.EndUpdate;
  1347. begin
  1348. Dec(FUpdateCount);
  1349. if FUpdateCount <= 0 then
  1350. begin
  1351. FUpdateCount := 0;
  1352. UpdateAll;
  1353. end;
  1354. end;
  1355. function TCnDockTree.FindControlZone(Control: TControl; IncludeHide: Boolean): TCnDockZone;
  1356. var
  1357. CtlZone: TCnDockZone;
  1358. procedure DoFindControlZone(StartZone: TCnDockZone);
  1359. begin
  1360. if (StartZone.ChildControl = Control) and (StartZone.Visibled or IncludeHide) then
  1361. CtlZone := StartZone
  1362. else begin
  1363. // 遍历右兄弟
  1364. if (CtlZone = nil) and (StartZone.NextSibling <> nil) then
  1365. DoFindControlZone(StartZone.NextSibling);
  1366. // 遍历左子女
  1367. if (CtlZone = nil) and (StartZone.ChildZones <> nil) then
  1368. DoFindControlZone(StartZone.ChildZones);
  1369. end;
  1370. end;
  1371. begin
  1372. CtlZone := nil;
  1373. if (Control <> nil) and (FTopZone <> nil) then DoFindControlZone(FTopZone);
  1374. Result := CtlZone;
  1375. end;
  1376. procedure TCnDockTree.ForEachAt(Zone: TCnDockZone; Proc: TCnForEachZoneProc;
  1377. ScanKind: TTreeScanKind; ScanPriority: TTreeScanPriority);
  1378. { 前序遍历 }
  1379. procedure DoForwardForEach(Zone: TCnDockZone);
  1380. begin
  1381. Proc(Zone);
  1382. if ScanPriority = tspSibling then
  1383. begin
  1384. // 遍历右兄弟
  1385. if Zone.NextSibling <> nil then DoForwardForEach(Zone.NextSibling);
  1386. // 遍历左子女
  1387. if Zone.ChildZones <> nil then DoForwardForEach(Zone.ChildZones);
  1388. end else
  1389. begin
  1390. // 遍历左子女
  1391. if Zone.ChildZones <> nil then DoForwardForEach(Zone.ChildZones);
  1392. // 遍历右兄弟
  1393. if Zone.NextSibling <> nil then DoForwardForEach(Zone.NextSibling);
  1394. end;
  1395. end;
  1396. { 中序遍历 }
  1397. procedure DoMiddleForEach(Zone: TCnDockZone);
  1398. begin
  1399. if ScanPriority = tspSibling then
  1400. begin
  1401. // 遍历右兄弟
  1402. if Zone.NextSibling <> nil then DoMiddleForEach(Zone.NextSibling);
  1403. end else
  1404. begin
  1405. // 遍历左子女
  1406. if Zone.ChildZones <> nil then DoMiddleForEach(Zone.ChildZones);
  1407. end;
  1408. Proc(Zone);
  1409. if ScanPriority = tspSibling then
  1410. begin
  1411. // 遍历左子女
  1412. if Zone.ChildZones <> nil then DoMiddleForEach(Zone.ChildZones);
  1413. end else
  1414. // 遍历右兄弟
  1415. if Zone.NextSibling <> nil then DoMiddleForEach(Zone.NextSibling);
  1416. end;
  1417. { 后序遍历 }
  1418. procedure DoBackwardForEach(Zone: TCnDockZone);
  1419. begin
  1420. if ScanPriority = tspSibling then
  1421. begin
  1422. // 遍历右兄弟
  1423. if Zone.NextSibling <> nil then DoBackwardForEach(Zone.NextSibling);
  1424. // 遍历左子女
  1425. if Zone.ChildZones <> nil then DoBackwardForEach(Zone.ChildZones);
  1426. end else
  1427. begin
  1428. // 遍历左子女
  1429. if Zone.ChildZones <> nil then DoForwardForEach(Zone.ChildZones);
  1430. // 遍历右兄弟
  1431. if Zone.NextSibling <> nil then DoForwardForEach(Zone.NextSibling);
  1432. end;
  1433. Proc(Zone);
  1434. end;
  1435. begin
  1436. { 如果传过来的参数Zone是nil,就从根目录开始遍历 }
  1437. if Zone = nil then
  1438. begin
  1439. if FTopZone = nil then
  1440. FTopZone := FCnDockZoneClass.Create(Self);
  1441. Zone := FTopZone;
  1442. end;
  1443. { 根据ScanKind参数进行各自的遍历 }
  1444. case ScanKind of
  1445. tskForward: DoForwardForEach(Zone);
  1446. tskMiddle: DoMiddleForEach(Zone);
  1447. tskBackward:DoBackwardForEach(Zone);
  1448. end;
  1449. end;
  1450. procedure TCnDockTree.GetControlBounds(Control: TControl; out CtlBounds: TRect);
  1451. var
  1452. Z: TCnDockZone;
  1453. begin
  1454. Z := FindControlZone(Control);
  1455. if Z = nil then
  1456. FillChar(CtlBounds, SizeOf(CtlBounds), 0)
  1457. else
  1458. with Z do
  1459. begin
  1460. CtlBounds := Bounds(Left, Top, Width, Height);
  1461. // AdjustRect(
  1462. end;
  1463. end;
  1464. function TCnDockTree.HitTest(const MousePos: TPoint; out HTFlag: Integer): TControl;
  1465. var
  1466. Zone: TCnDockZone;
  1467. begin
  1468. Zone := InternalHitTest(MousePos, HTFlag);
  1469. if Zone <> nil then Result := Zone.ChildControl
  1470. else Result := nil;
  1471. end;
  1472. procedure TCnDockTree.InsertControl(Control: TControl; InsertAt: TAlign;
  1473. DropCtl: TControl);
  1474. const
  1475. { Delphi6.0 }
  1476. {$IFDEF COMPILER6_UP}
  1477. OrientArray: array[TAlign] of TDockOrientation = (doNoOrient, doHorizontal,
  1478. doHorizontal, doVertical, doVertical, doNoOrient, doNoOrient); { alCustom }
  1479. MakeLast: array[TAlign] of Boolean = (False, False, True, False, True, False, False); { alCustom }
  1480. {$ELSE}
  1481. { Delphi5.0 OR LAST }
  1482. OrientArray: array[TAlign] of TDockOrientation = (doNoOrient, doHorizontal,
  1483. doHorizontal, doVertical, doVertical, doNoOrient);
  1484. MakeLast: array[TAlign] of Boolean = (False, False, True, False, True, False);
  1485. {$ENDIF}
  1486. var
  1487. Sibling, // 下一个兄弟
  1488. Me: TCnDockZone; // 当前正要被创建的节点
  1489. InsertOrientation, // 插入的方向
  1490. CurrentOrientation: TDockOrientation;// 当前的方向
  1491. NewWidth, NewHeight: Integer;
  1492. R: TRect; // 控件的矩形大小
  1493. begin
  1494. // if not Control.Visible then Exit;
  1495. if FReplacementZone <> nil then
  1496. begin
  1497. { 如果FReplacementZone <> nil,说明正好在执行装载停靠信息的操作 }
  1498. FReplacementZone.ChildControl := TWinControl(Control);
  1499. FReplacementZone.Update;
  1500. Exit;
  1501. end
  1502. else if FTopZone <> nil then
  1503. begin
  1504. if FTopZone.ChildZones = nil then
  1505. begin
  1506. // 如果树是空的,就要添加第一个子女
  1507. R := FDockSite.ClientRect;
  1508. TCnWinControlAccess(FDockSite).AdjustClientRect(R);
  1509. NewWidth := R.Right - R.Left;
  1510. NewHeight := R.Bottom - R.Top;
  1511. if TCnWinControlAccess(FDockSite).AutoSize then
  1512. begin
  1513. if NewWidth = 0 then NewWidth := Control.UndockWidth;
  1514. if NewHeight = 0 then NewHeight := Control.UndockHeight;
  1515. end;
  1516. R := Bounds(R.Left, R.Top, NewWidth, NewHeight);
  1517. AdjustDockRect(Control, R);
  1518. Control.BoundsRect := R;
  1519. Me := FCnDockZoneClass.Create(Self);
  1520. FTopZone.ChildZones := Me;
  1521. Me.FParentZone := FTopZone;
  1522. Me.ChildControl := TWinControl(Control);
  1523. end
  1524. else begin
  1525. // 默认是停靠到右边
  1526. if InsertAt in [alClient, alNone] then InsertAt := alRight;
  1527. { 查找Control是否已经被停靠进了DockSite中,
  1528. 如果是的话就删除这个节点 }
  1529. Me := FindControlZone(Control, True);
  1530. if Me <> nil then RemoveZone(Me, False);
  1531. { 查找到DropCtl所在的节点 }
  1532. Sibling := FindControlZone(DropCtl);
  1533. { 设置插入的方向 }
  1534. InsertOrientation := OrientArray[InsertAt];
  1535. if FTopZone.ChildCount = 1 then
  1536. begin
  1537. // 如果树只有一个子女,并且第二个正在被添加进去,
  1538. // 所以方向和位置必须被重新设置
  1539. FTopZone.Orientation := InsertOrientation;
  1540. case InsertOrientation of
  1541. doHorizontal:
  1542. begin
  1543. FTopZone.ZoneLimit := FTopZone.ChildZones.Width;
  1544. TopXYLimit := FTopZone.ChildZones.Height;
  1545. end;
  1546. doVertical:
  1547. begin
  1548. FTopZone.ZoneLimit := FTopZone.ChildZones.Height;
  1549. TopXYLimit := FTopZone.ChildZones.Width;
  1550. end;
  1551. end;
  1552. end;
  1553. { 创建一个节点,并且把Control赋值给这个节点的ChildControl }
  1554. Me := FCnDockZoneClass.Create(Self);
  1555. Me.ChildControl := TWinControl(Control);
  1556. { 设置CurrentOrientation的方向 }
  1557. if Sibling <> nil then
  1558. { 是DropCtl所在的节点的父节点的方向 }
  1559. CurrentOrientation := Sibling.FParentZone.Orientation
  1560. { 是根节点的方向 }
  1561. else CurrentOrientation := FTopZone.Orientation;
  1562. if InsertOrientation = doNoOrient then
  1563. InsertOrientation := CurrentOrientation;
  1564. // 控件正在被停靠进一个和她相同方向的节点的时候,
  1565. // 需要将自己添加到兄弟的前面或后面
  1566. if InsertOrientation = CurrentOrientation then
  1567. InsertSibling(Me, Sibling, MakeLast[InsertAt], True)
  1568. else
  1569. // 控件正在被停靠进一个和她不同方向的节点的时候,
  1570. // 需要创建一个父节点,并且将自己和兄弟作为这个父节点的子女。
  1571. // 这个父节点的方向和插入方向(InsertOrientation)相同
  1572. InsertNewParent(Me, Sibling, InsertOrientation, MakeLast[InsertAt], True);
  1573. end;
  1574. { 重新画客户区的停靠框架 }
  1575. FDockSite.Invalidate;
  1576. end;
  1577. (* if FTopStoreZone <> nil then
  1578. begin
  1579. if FTopStoreZone.ChildZones = nil then
  1580. begin
  1581. Store := TCnDockZone.Create(Self, True);
  1582. FTopStoreZone.ChildZones := Store;
  1583. Store.FParentZone := FTopStoreZone;
  1584. Store.ChildControl := TWinControl(Control);
  1585. end else
  1586. begin
  1587. // 默认是停靠到右边
  1588. if InsertAt in [alClient, alNone] then InsertAt := alRight;
  1589. { 查找Control是否已经被停靠进了DockSite中,
  1590. 如果是的话就删除这个节点 }
  1591. Store := FindControlZone(Control, True);
  1592. if Store <> nil then RemoveZone(Store, True);
  1593. { 查找到DropCtl所在的节点 }
  1594. Sibling := FindControlZone(DropCtl, True);
  1595. { 设置插入的方向 }
  1596. InsertOrientation := OrientArray[InsertAt];
  1597. if FTopStoreZone.ChildCount = 1 then
  1598. begin
  1599. // 如果树只有一个子女,并且第二个正在被添加进去,
  1600. // 所以方向和位置必须被重新设置
  1601. FTopStoreZone.Orientation := InsertOrientation;
  1602. end;
  1603. { 创建一个节点,并且把Control赋值给这个节点的ChildControl }
  1604. Store := TCnDockZone.Create(Self, True);
  1605. Store.ChildControl := TWinControl(Control);
  1606. { 设置CurrentOrientation的方向 }
  1607. if Sibling <> nil then
  1608. { 是DropCtl所在的节点的父节点的方向 }
  1609. CurrentOrientation := Sibling.FParentZone.Orientation
  1610. { 是根节点的方向 }
  1611. else CurrentOrientation := FTopStoreZone.Orientation;
  1612. if InsertOrientation = doNoOrient then
  1613. InsertOrientation := CurrentOrientation;
  1614. // 控件正在被停靠进一个和她相同方向的节点的时候,
  1615. // 需要将自己添加到兄弟的前面或后面
  1616. if InsertOrientation = CurrentOrientation then
  1617. InsertSibling(Store, Sibling, MakeLast[InsertAt], False, True)
  1618. else
  1619. // 控件正在被停靠进一个和她不同方向的节点的时候,
  1620. // 需要创建一个父节点,并且将自己和兄弟作为这个父节点的子女。
  1621. // 这个父节点的方向和插入方向(InsertOrientation)相同
  1622. InsertNewParent(Store, Sibling, InsertOrientation, MakeLast[InsertAt], False, True);
  1623. end;
  1624. end;*)
  1625. end;
  1626. procedure TCnDockTree.InsertNewParent(NewZone, SiblingZone: TCnDockZone;
  1627. ParentOrientation: TDockOrientation; InsertLast, Update: Boolean);
  1628. var
  1629. NewParent: TCnDockZone;
  1630. begin
  1631. NewParent := FCnDockZoneClass.Create(Self);
  1632. NewParent.Orientation := ParentOrientation;
  1633. if SiblingZone = nil then
  1634. begin
  1635. // 如果SiblingZone是空的话,我们需要把这个节点作为根节点的子女插入树中
  1636. NewParent.ZoneLimit := TopXYLimit;
  1637. TopXYLimit := FTopZone.ZoneLimit;
  1638. ShiftScaleOrient := ParentOrientation;
  1639. ScaleBy := 0.5;
  1640. if InsertLast then
  1641. begin
  1642. FTopZone.Visibled := FTopZone.VisibleChildCount > 0;
  1643. NewParent.ChildZones := FTopZone;
  1644. FTopZone.ParentZone := NewParent;
  1645. FTopZone.NextSibling := NewZone;
  1646. NewZone.PrevSibling := FTopZone;
  1647. NewZone.ParentZone := NewParent;
  1648. FTopZone := NewParent;
  1649. ForEachAt(NewParent.ChildZones, ScaleZone, tskForward);
  1650. end
  1651. else begin
  1652. NewParent.ChildZones := NewZone;
  1653. FTopZone.ParentZone := NewParent;
  1654. FTopZone.PrevSibling := NewZone;
  1655. NewZone.NextSibling := FTopZone;
  1656. NewZone.ParentZone := NewParent;
  1657. FTopZone := NewParent;
  1658. if ParentOrientation <> FTopZone.Orientation then
  1659. NewZone.ZoneLimit := FTopZone.ZoneLimit div 2
  1660. else NewZone.ZoneLimit := TopXYLimit div 2;
  1661. ForEachAt(NewZone.NextSibling, ScaleZone, tskForward);
  1662. if ParentOrientation <> FTopZone.Orientation then
  1663. ShiftBy := FTopZone.ZoneLimit div 2
  1664. else ShiftBy := TopXYLimit div 2;
  1665. ForEachAt(NewZone.NextSibling, ShiftZone, tskForward);
  1666. end;
  1667. ForEachAt(nil, UpdateZone, tskForward);
  1668. end
  1669. else begin
  1670. // 如果SiblingZone不是空的,我们就要创建一个节点,
  1671. // 这个节点是Me和SiblingZone共同的父亲
  1672. NewParent.ZoneLimit := SiblingZone.ZoneLimit;
  1673. NewParent.ParentZone := SiblingZone.ParentZone;
  1674. NewParent.PrevSibling := SiblingZone.PrevSibling;
  1675. if NewParent.PrevSibling <> nil then
  1676. NewParent.PrevSibling.NextSibling := NewParent;
  1677. NewParent.NextSibling := SiblingZone.NextSibling;
  1678. if NewParent.NextSibling <> nil then
  1679. NewParent.NextSibling.PrevSibling := NewParent;
  1680. if NewParent.ParentZone.ChildZones = SiblingZone then
  1681. NewParent.ParentZone.ChildZones := NewParent;
  1682. NewZone.ParentZone := NewParent;
  1683. SiblingZone.ParentZone := NewParent;
  1684. if InsertLast then
  1685. begin
  1686. // 插入到SiblingZone的后面
  1687. NewParent.ChildZones := SiblingZone;
  1688. SiblingZone.ZoneLimit := NewParent.ParentZone.ZoneLimit;
  1689. SiblingZone.PrevSibling := nil;
  1690. SiblingZone.NextSibling := NewZone;
  1691. NewZone.PrevSibling := SiblingZone;
  1692. end
  1693. else begin
  1694. // 插入到SiblingZone的前面
  1695. NewParent.ChildZones := NewZone;
  1696. SiblingZone.PrevSibling := NewZone;
  1697. SiblingZone.NextSibling := nil;
  1698. NewZone.NextSibling := SiblingZone;
  1699. end;
  1700. end;
  1701. if Update then
  1702. begin
  1703. // 重新设置新子女的范围
  1704. NewParent.ResetChildren(nil);
  1705. ForEachAt(nil, UpdateZone, tskForward);
  1706. end;
  1707. end;
  1708. procedure TCnDockTree.InsertSibling(NewZone, SiblingZone: TCnDockZone;
  1709. InsertLast, Update: Boolean);
  1710. begin
  1711. if (NewZone <> nil) and (SiblingZone <> nil) and
  1712. (NewZone.ChildControl = SiblingZone.ChildControl) then
  1713. SiblingZone := nil;
  1714. if SiblingZone = nil then
  1715. begin
  1716. SiblingZone := FTopZone.ChildZones;
  1717. if InsertLast then
  1718. SiblingZone := SiblingZone.LastSibling;
  1719. end;
  1720. if InsertLast then
  1721. begin
  1722. // 把NewZone插入到SiblingZone后
  1723. NewZone.ParentZone := SiblingZone.ParentZone;
  1724. NewZone.PrevSibling := SiblingZone;
  1725. NewZone.NextSibling := SiblingZone.NextSibling;
  1726. if NewZone.NextSibling <> nil then
  1727. NewZone.NextSibling.PrevSibling := NewZone;
  1728. SiblingZone.NextSibling := NewZone;
  1729. end
  1730. else begin
  1731. // 把NewZone插入到SiblingZone前
  1732. NewZone.NextSibling := SiblingZone;
  1733. NewZone.PrevSibling := SiblingZone.PrevSibling;
  1734. if NewZone.PrevSibling <> nil then
  1735. NewZone.PrevSibling.NextSibling := NewZone;
  1736. SiblingZone.PrevSibling := NewZone;
  1737. NewZone.ParentZone := SiblingZone.ParentZone;
  1738. if NewZone.ParentZone.ChildZones = SiblingZone then
  1739. NewZone.ParentZone.ChildZones := NewZone;
  1740. end;
  1741. if Update then
  1742. begin
  1743. // 重新设置所有的兄弟
  1744. SiblingZone.ParentZone.ResetChildren(nil);
  1745. UpDateChild(SiblingZone.ParentZone);
  1746. end;
  1747. end;
  1748. function TCnDockTree.DoFindZone(const MousePos: TPoint;
  1749. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone;
  1750. const HTFlagArr : array[Boolean] of Integer = (HTCLIENT, HTSPLITTER);
  1751. begin
  1752. Result := nil;
  1753. // 鼠标是否在分割条的底部...
  1754. if (Zone.ParentZone.Orientation = doHorizontal) and
  1755. (Zone.NextSibling <> nil) and
  1756. ((MousePos.Y <= Zone.FZoneLimit) and
  1757. (MousePos.Y >= Zone.FZoneLimit - SplitterWidth)) and
  1758. ((MousePos.X <= Zone.ParentZone.FZoneLimit) and
  1759. (MousePos.X >= Zone.ParentZone.LimitBegin)) then
  1760. begin
  1761. HTFlag := HTFlagArr[Zone.VisibleNextSiblingTotal > 0];
  1762. Result := Zone;
  1763. end
  1764. // 鼠标是否在分割条的左部...
  1765. else if (Zone.FParentZone.Orientation = doVertical) and
  1766. (Zone.NextSibling <> nil) and
  1767. ((MousePos.X <= Zone.FZoneLimit) and
  1768. (MousePos.X >= Zone.FZoneLimit - SplitterWidth)) and
  1769. ((MousePos.Y <= Zone.ParentZone.FZoneLimit) and
  1770. (MousePos.Y >= Zone.ParentZone.LimitBegin)) then
  1771. begin
  1772. HTFlag := HTFlagArr[Zone.VisibleNextSiblingTotal > 0];
  1773. Result := Zone;
  1774. end
  1775. // 鼠标是否在把手内...
  1776. else if Zone.ChildControl <> nil then
  1777. begin
  1778. { 鼠标是否在边框内... }
  1779. case GrabbersPosition of
  1780. gpTop: Result := GetTopGrabbersHTFlag(MousePos, HTFlag, Zone);
  1781. gpLeft: Result := GetLeftGrabbersHTFlag(MousePos, HTFlag, Zone);
  1782. gpBottom: Result := GetBottomGrabbersHTFlag(MousePos, HTFlag, Zone);
  1783. gpRight: Result := GetRightGrabbersHTFlag(MousePos, HTFlag, Zone);
  1784. end;
  1785. { 如果不在把手上,就查找是否在边框内... }
  1786. if Result = nil then
  1787. Result := GetBorderHTFlag(MousePos, HTFlag, Zone);
  1788. end else Result := nil;
  1789. if (Result <> nil) and (not Result.Visibled) then Result := nil;
  1790. // 遍历别的节点...
  1791. if (Result = nil) and (Zone.NextSibling <> nil) then
  1792. Result := DoFindZone(MousePos, HTFlag, Zone.NextSibling);
  1793. if (Result = nil) and (Zone.ChildZones <> nil) then
  1794. Result := DoFindZone(MousePos, HTFlag, Zone.ChildZones);
  1795. end;
  1796. function TCnDockTree.InternalHitTest(const MousePos: TPoint; out HTFlag: Integer): TCnDockZone;
  1797. var
  1798. ResultZone: TCnDockZone;
  1799. function FindControlAtPos(const Pos: TPoint): TControl;
  1800. var
  1801. I: Integer;
  1802. P: TPoint;
  1803. begin
  1804. for I := FDockSite.ControlCount - 1 downto 0 do
  1805. begin
  1806. Result := FDockSite.Controls[I];
  1807. with Result do
  1808. begin
  1809. { 控件必须被显示出来... }
  1810. if not Result.Visible or ((Result is TWinControl) and
  1811. not TWinControl(Result).Showing) then continue;
  1812. P := Point(Pos.X - Left, Pos.Y - Top);
  1813. if PtInRect(ClientRect, P) then Exit;
  1814. end;
  1815. end;
  1816. Result := nil;
  1817. end;
  1818. var
  1819. CtlAtPos: TControl;
  1820. begin
  1821. ResultZone := nil;
  1822. HTFlag := HTNOWHERE;
  1823. CtlAtPos := FindControlAtPos(MousePos);
  1824. if (CtlAtPos <> nil) and (CtlAtPos.HostDockSite = FDockSite) then
  1825. begin
  1826. ResultZone := FindControlZone(CtlAtPos);
  1827. if ResultZone <> nil then HTFlag := HTCLIENT;
  1828. end
  1829. else if (FTopZone <> nil) and (FTopZone.ChildZones <> nil) and (FTopZone.ChildCount >= 1) and
  1830. (CtlAtPos = nil) then
  1831. ResultZone := DoFindZone(MousePos, HTFlag, FTopZone.ChildZones);
  1832. Result := ResultZone;
  1833. end;
  1834. procedure TCnDockTree.LoadFromStream(Stream: TStream);
  1835. var
  1836. // CompName: string;
  1837. // Client: TControl;
  1838. // I, InVisCount: Integer;
  1839. I: Integer;
  1840. begin
  1841. PruneZone(FTopZone);
  1842. // 读版本, 如果版本不同,就退出
  1843. Stream.Read(I, SizeOf(I));
  1844. if I <> Version then
  1845. Exit;
  1846. BeginUpdate;
  1847. try
  1848. // 读根节点的数据
  1849. Stream.Read(FTopXYLimit, SizeOf(FTopXYLimit));
  1850. // 读整棵树的节点
  1851. DoLoadZone(Stream);
  1852. finally
  1853. EndUpdate;
  1854. end;
  1855. end;
  1856. {procedure TCnDockTree.PaintDockGrabber(Canvas: TCanvas; Control: TControl;
  1857. const ARect: TRect);
  1858. procedure DrawCloseButton(Left, Top: Integer);
  1859. begin
  1860. DrawFrameControl(Canvas.Handle, Rect(Left, Top, Left+FGrabberSize-2,
  1861. Top+FGrabberSize-2), DFC_CAPTION, DFCS_CAPTIONCLOSE);
  1862. end;
  1863. procedure DrawGrabberLine(Left, Top, Right, Bottom: Integer);
  1864. begin
  1865. with Canvas do
  1866. begin
  1867. Pen.Color := clBtnHighlight;
  1868. MoveTo(Right, Top);
  1869. LineTo(Left, Top);
  1870. LineTo(Left, Bottom);
  1871. Pen.Color := clBtnShadow;
  1872. LineTo(Right, Bottom);
  1873. LineTo(Right, Top-1);
  1874. end;
  1875. end;
  1876. begin
  1877. with ARect do
  1878. begin
  1879. case GrabbersPosition of
  1880. gpLeft:
  1881. begin
  1882. DrawCloseButton(Left+BorderWidth+BorderWidth+1, Top+BorderWidth+BorderWidth+1);
  1883. DrawGrabberLine(Left+BorderWidth+3, Top+FGrabberSize+BorderWidth+1, Left+BorderWidth+5, Bottom+BorderWidth-2);
  1884. DrawGrabberLine(Left+BorderWidth+6, Top+FGrabberSize+BorderWidth+1, Left+BorderWidth+8, Bottom+BorderWidth-2);
  1885. end;
  1886. gpTop:
  1887. begin
  1888. DrawCloseButton(Right-FGrabberSize+BorderWidth+1, Top+BorderWidth+1);
  1889. DrawGrabberLine(Left+BorderWidth+2, Top+BorderWidth+BorderWidth+3, Right-FGrabberSize+BorderWidth-2, Top+BorderWidth+5);
  1890. DrawGrabberLine(Left+BorderWidth+2, Top+BorderWidth+BorderWidth+6, Right-FGrabberSize+BorderWidth-2, Top+BorderWidth+8);
  1891. end;
  1892. // gpBottom:
  1893. // gpRight:
  1894. end;
  1895. end;
  1896. end;}
  1897. procedure TCnDockTree.PaintSite(DC: HDC);
  1898. (*var
  1899. Canvas: TControlCanvas;
  1900. Control: TControl;
  1901. I: Integer;
  1902. R: TRect;
  1903. DockClient: TCnDockClient;
  1904. begin
  1905. { 创建一个TControlCanvas对象 }
  1906. Canvas := TControlCanvas.Create;
  1907. try
  1908. { 然后把DockSite赋给Canvas的Control属性,这样Canvas就可以在DockSite上画图案了 }
  1909. Canvas.Control := FDockSite;
  1910. Canvas.Lock;
  1911. try
  1912. Canvas.Handle := DC;
  1913. try
  1914. { 开始循环重画DockSite上的Clients }
  1915. for I := 0 to FDockSite.ControlCount - 1 do
  1916. begin
  1917. Control := FDockSite.Controls[I];
  1918. if Control.Visible and (Control.HostDockSite = FDockSite) then
  1919. begin
  1920. { 查找到Control上面的TCnDockClient类 }
  1921. DockClient := FindDockClient(Control);
  1922. { 获得把手的矩形大小 }
  1923. R := GetFrameRect(Control);
  1924. { 画把手 }
  1925. PaintDockGrabber(Canvas, Control, R);
  1926. { 调用用户自定义画事件 }
  1927. if DockClient <> nil then
  1928. DockClient.DoPaintDockGrabber(Canvas, Control, R);
  1929. end;
  1930. end;
  1931. SplitterCanvas := Canvas;
  1932. SplitterCanvas.Brush.Color := TCnWinControlAccess(DockSite).Color;
  1933. { 画分割条 }
  1934. ForEachAt(nil, DrawSplitter, tskBackward);
  1935. SplitterCanvas := nil;
  1936. { 画DockSite的边框 }
  1937. PaintDockSiteRect(Canvas);
  1938. finally
  1939. Canvas.Handle := 0;
  1940. end;
  1941. finally
  1942. Canvas.Unlock;
  1943. end;
  1944. finally
  1945. Canvas.Free;
  1946. end;*)
  1947. begin
  1948. { 创建一个TControlCanvas对象 }
  1949. FCanvas := TControlCanvas.Create;
  1950. try
  1951. { 然后把DockSite赋给Canvas的Control属性,这样Canvas就可以在DockSite上画图案了 }
  1952. FCanvas.Control := FDockSite;
  1953. FCanvas.Lock;
  1954. try
  1955. FCanvas.Handle := DC;
  1956. try
  1957. PaintDockSite;
  1958. finally
  1959. FCanvas.Handle := 0;
  1960. end;
  1961. finally
  1962. FCanvas.Unlock;
  1963. end;
  1964. finally
  1965. FCanvas.Free;
  1966. FCanvas := nil;
  1967. end;
  1968. end;
  1969. procedure TCnDockTree.PositionDockRect(Client, DropCtl: TControl;
  1970. DropAlign: TAlign; var DockRect: TRect);
  1971. var
  1972. VisibleClients,
  1973. NewX, NewY, NewWidth, NewHeight: Integer;
  1974. begin
  1975. VisibleClients := FDockSite.VisibleDockClientCount;
  1976. { 当DockSite小于两个停靠控件在她里面,DockRect就应该作为被设置成DockSite的客户区域 }
  1977. if (DropCtl = nil) or (DropCtl.DockOrientation = doNoOrient) or
  1978. {(DropCtl = Client) or }(VisibleClients < 2) then
  1979. begin
  1980. DockRect := Rect(0, 0, FDockSite.ClientWidth, FDockSite.ClientHeight);
  1981. { 当那里有一个停靠客户我们把DockSite的客户区分成一半 }
  1982. if VisibleClients > 0 then
  1983. with DockRect do
  1984. case DropAlign of
  1985. alLeft: Right := Right div 2;
  1986. alRight: Left := Right div 2;
  1987. alTop: Bottom := Bottom div 2;
  1988. alBottom: Top := Bottom div 2;
  1989. end;
  1990. end
  1991. else begin
  1992. { 否者,如果DockSite包含超过一个客户的时候, 根据鼠标下面的控件设置DockRect的坐标}
  1993. NewX := DropCtl.Left;
  1994. NewY := DropCtl.Top;
  1995. NewWidth := DropCtl.Width;
  1996. NewHeight := DropCtl.Height;
  1997. if DropAlign in [alLeft, alRight] then
  1998. NewWidth := DropCtl.Width div 2
  1999. else if DropAlign in [alTop, alBottom] then
  2000. NewHeight := DropCtl.Height div 2;
  2001. case DropAlign of
  2002. alRight: Inc(NewX, NewWidth);
  2003. alBottom: Inc(NewY, NewHeight);
  2004. end;
  2005. DockRect := Bounds(NewX, NewY, NewWidth, NewHeight);
  2006. if DropAlign = alClient then
  2007. DockRect := Bounds(NewX, NewY, NewWidth, NewHeight);
  2008. end;
  2009. MapWindowPoints(FDockSite.Handle, 0, DockRect, 2);
  2010. end;
  2011. procedure TCnDockTree.PruneZone(Zone: TCnDockZone);
  2012. procedure DoPrune(Zone: TCnDockZone);
  2013. begin
  2014. // 遍历右兄弟
  2015. if Zone.NextSibling <> nil then
  2016. DoPrune(Zone.NextSibling);
  2017. // 遍历左子女
  2018. if Zone.ChildZones <> nil then
  2019. DoPrune(Zone.ChildZones);
  2020. // 删除节点
  2021. Zone.Free;
  2022. end;
  2023. begin
  2024. if Zone = nil then Exit;
  2025. // 首先递归的删除子女
  2026. if Zone.ChildZones <> nil then DoPrune(Zone.ChildZones);
  2027. // 修正这个Zone
  2028. if Zone.FPrevSibling <> nil then
  2029. Zone.FPrevSibling.NextSibling := Zone.NextSibling
  2030. else if Zone.FParentZone <> nil then
  2031. Zone.FParentZone.ChildZones := Zone.NextSibling;
  2032. if Zone.NextSibling <> nil then
  2033. Zone.NextSibling.FPrevSibling := Zone.FPrevSibling;
  2034. // 删除这个Zone
  2035. if Zone = FTopZone then FTopZone := nil;
  2036. Zone.Free;
  2037. end;
  2038. procedure TCnDockTree.RemoveControl(Control: TControl);
  2039. var
  2040. Z: TCnDockZone;
  2041. begin
  2042. Z := FindControlZone(Control, True);
  2043. if (Z <> nil) then
  2044. begin
  2045. if Z = FReplacementZone then
  2046. Z.ChildControl := nil
  2047. else
  2048. begin
  2049. if (Z.ParentZone.Orientation <> doNoOrient) and Z.Visibled then
  2050. Z.Remove(Z.LimitSize, False);
  2051. RemoveZone(Z, False);
  2052. SetNewBounds(nil);
  2053. UpdateAll;
  2054. end;
  2055. Control.DockOrientation := doNoOrient;
  2056. { 重画DockSite }
  2057. FDockSite.Invalidate;
  2058. end;
  2059. end;
  2060. procedure TCnDockTree.RemoveZone(Zone: TCnDockZone; Hide: Boolean);
  2061. var
  2062. Sibling, LastChild: TCnDockZone;
  2063. VisibleZoneChildCount,
  2064. ZoneChildCount: Integer;
  2065. label LOOP;
  2066. begin
  2067. if not Hide then
  2068. begin
  2069. if Zone = nil then
  2070. raise Exception.Create(SDockTreeRemoveError + SDockZoneNotFound);
  2071. if Zone.ChildControl = nil then
  2072. raise Exception.Create(SDockTreeRemoveError + SDockZoneHasNoCtl);
  2073. VisibleZoneChildCount := Zone.ParentZone.VisibleChildCount;
  2074. ZoneChildCount := Zone.ParentZone.ChildCount;
  2075. if VisibleZoneChildCount <= 1 then
  2076. begin
  2077. // 如果当前节点的父节点只有一个可见的节点,就需要把父节点隐藏掉
  2078. // 首先连接前兄弟和后兄弟
  2079. if Zone.PrevSibling = nil then
  2080. begin
  2081. Zone.ParentZone.ChildZones := Zone.NextSibling;
  2082. if Zone.NextSibling <> nil then
  2083. Zone.NextSibling.PrevSibling := nil;
  2084. end else if Zone.NextSibling = nil then
  2085. Zone.PrevSibling.NextSibling := nil
  2086. else
  2087. begin
  2088. Zone.PrevSibling.NextSibling := Zone.NextSibling;
  2089. Zone.NextSibling.PrevSibling := Zone.PrevSibling;
  2090. end;
  2091. // 隐藏掉父节点,注意,这是一个递归函数,如果父节点的父节点的可见子女个数也是0,
  2092. // 就要隐藏掉父节点的父节点
  2093. { if Zone.ParentZone <> TopZone then
  2094. Zone.ParentZone.Remove(Zone.ParentZone.LimitSize, True)
  2095. else}
  2096. // goto LOOP;
  2097. // Exit;
  2098. end;
  2099. if ZoneChildCount = 2 then
  2100. begin
  2101. // 这个节点只有一个兄弟节点
  2102. if Zone.PrevSibling = nil then Sibling := Zone.NextSibling
  2103. else Sibling := Zone.PrevSibling;
  2104. if Sibling.ChildControl <> nil then
  2105. begin
  2106. // 兄弟节点是一个有ChildControl并且没有子节点的节点
  2107. if Zone.ParentZone = FTopZone then
  2108. begin
  2109. // 如果父节点是根节点,就删除这个节点
  2110. FTopZone.ChildZones := Sibling;
  2111. Sibling.PrevSibling := nil;
  2112. Sibling.NextSibling := nil;
  2113. Sibling.ZoneLimit := FTopZone.LimitSize;
  2114. Sibling.Update;
  2115. end
  2116. else begin
  2117. // 否则,就把兄弟节点的ChildControl移动到父节点上,然后删除这个兄弟节点
  2118. Zone.ParentZone.Orientation := doNoOrient;
  2119. Zone.ParentZone.ChildControl := Sibling.ChildControl;
  2120. Zone.ParentZone.ChildZones := nil;
  2121. Sibling.Free;
  2122. end;
  2123. // 更新父节点
  2124. ForEachAt(Zone.ParentZone, UpdateZone, tskForward);
  2125. end
  2126. else begin
  2127. // 兄弟节点是一个有子节点的节点,所以兄弟节点必须被放到根节点上,
  2128. // 或者放到上一级
  2129. if Zone.ParentZone = FTopZone then
  2130. begin
  2131. // 节点是根节点的子节点,所以兄弟节点必须成为根节点
  2132. Sibling.ZoneLimit := TopXYLimit;
  2133. TopXYLimit := FTopZone.ZoneLimit;
  2134. FTopZone.Free;
  2135. FTopZone := Sibling;
  2136. Sibling.NextSibling := nil;
  2137. Sibling.PrevSibling := nil;
  2138. Sibling.ParentZone := nil;
  2139. end
  2140. else
  2141. begin
  2142. // 节点的父节点不是根节点,所以子节点必须被放到父节点上
  2143. Sibling.ChildZones.PrevSibling := Zone.ParentZone.PrevSibling;
  2144. if Sibling.ChildZones.PrevSibling = nil then
  2145. Zone.ParentZone.ParentZone.ChildZones := Sibling.ChildZones
  2146. else
  2147. Sibling.ChildZones.PrevSibling.NextSibling := Sibling.ChildZones;
  2148. LastChild := Sibling.ChildZones;
  2149. LastChild.ParentZone := Zone.ParentZone.ParentZone;
  2150. repeat
  2151. LastChild := LastChild.NextSibling;
  2152. if LastChild <> nil then
  2153. LastChild.ParentZone := Zone.ParentZone.ParentZone
  2154. else
  2155. Break;
  2156. until LastChild.NextSibling = nil;
  2157. if LastChild <> nil then
  2158. begin
  2159. LastChild.NextSibling := Zone.ParentZone.NextSibling;
  2160. if LastChild.NextSibling <> nil then
  2161. LastChild.NextSibling.PrevSibling := LastChild;
  2162. ForEachAt(LastChild.ParentZone, UpdateZone, tskForward);
  2163. end;
  2164. Zone.ParentZone.Free;
  2165. Sibling.Free;
  2166. end;
  2167. end;
  2168. end
  2169. else begin
  2170. // 这个节点有多个兄弟节点
  2171. if Zone.PrevSibling = nil then
  2172. begin
  2173. // 存在父节点的第一个节点,所以使下一个兄弟节点作为父节点的子女,
  2174. // 并且把本身删除掉
  2175. Zone.ParentZone.ChildZones := Zone.NextSibling;
  2176. if Zone.NextSibling <> nil then
  2177. begin
  2178. Zone.NextSibling.PrevSibling := nil;
  2179. Zone.NextSibling.Update;
  2180. end;
  2181. end
  2182. else begin
  2183. // 不存在父节点的第一个节点,所以删除这个节点,并且调整兄弟节点
  2184. Zone.PrevSibling.NextSibling := Zone.NextSibling;
  2185. if Zone.NextSibling <> nil then
  2186. Zone.NextSibling.PrevSibling := Zone.PrevSibling;
  2187. Zone.PrevSibling.ZoneLimit := Zone.ZoneLimit;
  2188. Zone.PrevSibling.Update;
  2189. end;
  2190. ForEachAt(Zone.ParentZone, UpdateZone, tskForward);
  2191. end;
  2192. LOOP:
  2193. Zone.Free;
  2194. end;
  2195. SetNewBounds(nil);
  2196. UpdateAll;
  2197. end;
  2198. procedure TCnDockTree.ResetBounds(Force: Boolean);
  2199. var
  2200. R: TRect;
  2201. begin
  2202. if not (csLoading in FDockSite.ComponentState) and
  2203. (FTopZone <> nil) and (FDockSite.DockClientCount > 0) then
  2204. begin
  2205. R := FDockSite.ClientRect;
  2206. TCnWinControlAccess(FDockSite).AdjustClientRect(R);
  2207. if Force or (not CompareMem(@R, @FOldRect, SizeOf(TRect))) then
  2208. begin
  2209. FOldRect := R;
  2210. case FTopZone.Orientation of
  2211. doHorizontal:
  2212. begin
  2213. FTopZone.ZoneLimit := R.Right - R.Left;
  2214. // 当R.Bottom = R.Top的时候,说明DockSite的高度为0,
  2215. // 因为程序是在从新设置高度后再调整ZoneLimit的,
  2216. // 所以这条语句是使当高度设置成0的时候不能调整TopXYLimit
  2217. if R.Bottom - R.Top > 0 then
  2218. TopXYLimit := R.Bottom - R.Top;
  2219. end;
  2220. doVertical:
  2221. begin
  2222. FTopZone.ZoneLimit := R.Bottom - R.Top;
  2223. // 当R.Right = R.Left的时候,说明DockSite的宽度为0,
  2224. // 因为程序是在从新设置宽度后再调整ZoneLimit的,
  2225. // 所以这条语句是使当宽度设置成0的时候不能调整TopXYLimit
  2226. if R.Right - R.Left > 0 then
  2227. TopXYLimit := R.Right - R.Left;
  2228. end;
  2229. end;
  2230. SetNewBounds(nil);
  2231. if FUpdateCount = 0 then ForEachAt(nil, UpdateZone, tskForward);
  2232. end;
  2233. end;
  2234. end;
  2235. procedure TCnDockTree.ScaleZone(Zone: TCnDockZone);
  2236. begin
  2237. { ScaleZone的公式是ScaleChildZone公式的特殊情况,
  2238. 当FParentLimit是0的时候,这两个公式相等 }
  2239. FParentLimit := 0;
  2240. ScaleChildZone(Zone);
  2241. end;
  2242. procedure TCnDockTree.SaveToStream(Stream: TStream);
  2243. begin
  2244. // 写流的版本
  2245. Stream.Write(FVersion, SizeOf(FVersion));
  2246. // 写根节点数据
  2247. Stream.Write(FTopXYLimit, SizeOf(FTopXYLimit));
  2248. // 从树上写所有节点的数据
  2249. DoSaveZone(Stream, FTopZone, 0);
  2250. Stream.Write(TreeStreamEndFlag, SizeOf(TreeStreamEndFlag));
  2251. end;
  2252. procedure TCnDockTree.SetNewBounds(Zone: TCnDockZone);
  2253. procedure DoSetNewBounds(Zone: TCnDockZone);
  2254. begin
  2255. if Zone <> nil then
  2256. begin
  2257. if (Zone.VisibleNextSiblingCount = 0) and (Zone <> FTopZone) then
  2258. begin
  2259. if Zone.ParentZone = FTopZone then
  2260. Zone.ZoneLimit := FTopXYLimit
  2261. else
  2262. Zone.ZoneLimit := Zone.ParentZone.ParentZone.FZoneLimit;
  2263. end;
  2264. if Zone.ChildZones <> nil then DoSetNewBounds(Zone.ChildZones);
  2265. if Zone.NextSibling <> nil then DoSetNewBounds(Zone.NextSibling);
  2266. end;
  2267. end;
  2268. begin
  2269. if IsLoading then Exit;
  2270. if Zone = nil then Zone := FTopZone.ChildZones;
  2271. DoSetNewBounds(Zone);
  2272. { 重新画停靠框架 }
  2273. FDockSite.Invalidate;
  2274. end;
  2275. procedure TCnDockTree.SetReplacingControl(Control: TControl);
  2276. begin
  2277. FReplacementZone := FindControlZone(Control);
  2278. end;
  2279. procedure TCnDockTree.ShiftZone(Zone: TCnDockZone);
  2280. begin
  2281. if (Zone <> nil) and (Zone <> FTopZone) and
  2282. (Zone.ParentZone.Orientation = FShiftScaleOrient) then
  2283. begin
  2284. Inc(Zone.FZoneLimit, FShiftBy);
  2285. if Zone.LimitSize < FMinSize then
  2286. Zone.FZoneLimit := Zone.LimitBegin + FMinSize;
  2287. end;
  2288. end;
  2289. procedure TCnDockTree.SplitterMouseDown(OnZone: TCnDockZone; MousePos: TPoint);
  2290. begin
  2291. FSizingZone := OnZone;
  2292. Mouse.Capture := FDockSite.Handle;
  2293. FSizingWnd := FDockSite.Handle;
  2294. FSizingDC := GetDCEx(FSizingWnd, 0, DCX_CACHE or DCX_CLIPSIBLINGS or
  2295. DCX_LOCKWINDOWUPDATE);
  2296. FSizePos := MousePos;
  2297. DrawSizeSplitter;
  2298. end;
  2299. procedure TCnDockTree.SplitterMouseUp;
  2300. procedure SetSiblingZoneSize(PosXY: Integer);
  2301. var AZone: TCnDockZone;
  2302. PrevCount, NextCount: Integer;
  2303. begin
  2304. { 处理PrevSibling }
  2305. PrevCount := FSizingZone.PrevSiblingCount;
  2306. AZone := FSizingZone.ParentZone.ChildZones;
  2307. while (AZone <> nil) and (AZone <> FSizingZone) do
  2308. begin
  2309. if AZone.ZoneLimit >= PosXY - PrevCount * MinSize +
  2310. Integer(AZone.PrevSibling = nil) * (SplitterWidth div 2) then
  2311. begin
  2312. AZone.ZoneLimit := PosXY - PrevCount * MinSize +
  2313. Integer(AZone.PrevSibling = nil) * (SplitterWidth div 2);
  2314. Break;
  2315. end;
  2316. Dec(PrevCount);
  2317. AZone := AZone.NextSibling;
  2318. end;
  2319. AZone := AZone.NextSibling;
  2320. while PrevCount > 0 do
  2321. begin
  2322. Dec(PrevCount);
  2323. AZone.ZoneLimit := AZone.LimitBegin + MinSize;
  2324. AZone := AZone.NextSibling;
  2325. end;
  2326. { 处理NextSibling }
  2327. NextCount := 1;
  2328. AZone := FSizingZone.NextSibling;
  2329. while (AZone <> nil) do
  2330. begin
  2331. if AZone.ZoneLimit <= PosXY + NextCount * MinSize +
  2332. Integer(AZone.NextSibling <> nil) * (SplitterWidth div 2) then
  2333. AZone.ZoneLimit := PosXY + NextCount * MinSize +
  2334. Integer(AZone.NextSibling <> nil) * (SplitterWidth div 2);
  2335. Inc(NextCount);
  2336. AZone := AZone.NextSibling;
  2337. end;
  2338. end;
  2339. begin
  2340. Mouse.Capture := 0;
  2341. DrawSizeSplitter;
  2342. ReleaseDC(FSizingWnd, FSizingDC);
  2343. if FSizingZone.ParentZone.Orientation = doHorizontal then
  2344. begin
  2345. FSizingZone.ZoneLimit := FSizePos.y + (SplitterWidth div 2);
  2346. SetSiblingZoneSize(FSizePos.y);
  2347. end else
  2348. begin
  2349. FSizingZone.ZoneLimit := FSizePos.x + (SplitterWidth div 2);
  2350. SetSiblingZoneSize(FSizePos.x);
  2351. end;
  2352. SetNewBounds(FSizingZone.ParentZone);
  2353. ForEachAt(FSizingZone.ParentZone, UpdateZone, tskForward);
  2354. FSizingZone := nil;
  2355. end;
  2356. procedure TCnDockTree.UpdateAll;
  2357. begin
  2358. if (FUpdateCount = 0) and (FDockSite.DockClientCount > 0) then
  2359. ForEachAt(nil, UpdateZone, tskForward);
  2360. end;
  2361. procedure TCnDockTree.UpdateZone(Zone: TCnDockZone);
  2362. begin
  2363. if (FUpdateCount = 0) then
  2364. Zone.Update;
  2365. end;
  2366. procedure TCnDockTree.DrawSizeSplitter;
  2367. var
  2368. R: TRect;
  2369. PrevBrush: HBrush;
  2370. begin
  2371. if FSizingZone <> nil then
  2372. begin
  2373. with R do
  2374. begin
  2375. if FSizingZone.ParentZone.Orientation = doHorizontal then
  2376. begin
  2377. Left := FSizingZone.Left;
  2378. Top := FSizePos.Y - (SplitterWidth div 2);
  2379. Right := Left + FSizingZone.Width;
  2380. Bottom := Top + SplitterWidth;
  2381. end
  2382. else begin
  2383. Left := FSizePos.X - (SplitterWidth div 2);
  2384. Top := FSizingZone.Top;
  2385. Right := Left + SplitterWidth;
  2386. Bottom := Top + FSizingZone.Height;
  2387. end;
  2388. end;
  2389. PrevBrush := SelectObject(FSizingDC, FBrush.Handle);
  2390. with R do
  2391. PatBlt(FSizingDC, Left, Top, Right - Left, Bottom - Top, PATINVERT);
  2392. SelectObject(FSizingDC, PrevBrush);
  2393. end;
  2394. end;
  2395. function TCnDockTree.GetSplitterLimit(AZone: TCnDockZone; IsCurrent, IsMin: Boolean): Integer;
  2396. begin
  2397. if IsCurrent then
  2398. begin
  2399. Result := AZone.GetSplitterLimit(False);
  2400. end else
  2401. begin
  2402. if AZone.AfterClosestVisibleZone <> nil then
  2403. Result := AZone.AfterClosestVisibleZone.GetSplitterLimit(True)
  2404. else
  2405. Result := AZone.ZoneLimit + AZone.LimitSize;
  2406. end;
  2407. end;
  2408. procedure TCnDockTree.ControlVisibilityChanged(Control: TControl;
  2409. Visible: Boolean);
  2410. begin
  2411. if Visible then
  2412. begin
  2413. ShowControl(Control);
  2414. end else
  2415. HideControl(Control);
  2416. end;
  2417. procedure TCnDockTree.WindowProc(var Message: TMessage);
  2418. var TempZone: TCnDockZone;
  2419. HitTestValue: Integer;
  2420. begin
  2421. case Message.Msg of
  2422. CM_DOCKNOTIFICATION:
  2423. with TCMDockNotification(Message) do
  2424. if (NotifyRec.ClientMsg = CM_VISIBLECHANGED) then
  2425. ControlVisibilityChanged(Client, Boolean(NotifyRec.MsgWParam));
  2426. WM_MOUSEMOVE:
  2427. { 捕获鼠标移动的消息 }
  2428. DoMouseMove(TWMMouse(Message), TempZone, HitTestValue);
  2429. WM_LBUTTONDBLCLK:
  2430. { 捕获到鼠标左键双击的消息 }
  2431. DoLButtonDbClk(TWMMouse(Message), TempZone, HitTestValue);
  2432. WM_LBUTTONDOWN:
  2433. { 捕获到鼠标左键按下的消息 }
  2434. if DoLButtonDown(TWMMouse(Message), TempZone, HitTestValue) then Exit;
  2435. WM_LBUTTONUP:
  2436. { 捕获到鼠标左键放开的消息 }
  2437. DoLButtonUp(TWMMouse(Message), TempZone, HitTestValue);
  2438. WM_MBUTTONDOWN:
  2439. { 捕获到鼠标中键按下的消息 }
  2440. DoMButtonDown(TWMMouse(Message), TempZone, HitTestValue);
  2441. WM_MBUTTONUP:
  2442. { 捕获到鼠标中键放开的消息 }
  2443. DoMButtonUp(TWMMouse(Message), TempZone, HitTestValue);
  2444. WM_RBUTTONDOWN:
  2445. { 捕获到鼠标右键按下的消息 }
  2446. DoRButtonDown(TWMMouse(Message), TempZone, HitTestValue);
  2447. WM_RBUTTONUP:
  2448. { 捕获到鼠标右键放开的消息 }
  2449. DoRButtonUp(TWMMouse(Message), TempZone, HitTestValue);
  2450. WM_SETCURSOR:
  2451. begin
  2452. { 捕获到设置光标的消息 }
  2453. DoSetCursor(TWMSetCursor(Message), TempZone, HitTestValue);
  2454. if Message.Result = 1 then Exit;
  2455. end;
  2456. end;
  2457. { 调用老的WndProc }
  2458. FOldWndProc(Message);
  2459. if Message.Msg = CM_HINTSHOW then
  2460. { 捕获到提示窗体显示的消息 }
  2461. DoHintShow(TCMHintShow(Message), TempZone, HitTestValue);
  2462. end;
  2463. procedure TCnDockTree.SetGrabberSize(const Value: Integer);
  2464. begin
  2465. if FGrabberSize <> Value then
  2466. begin
  2467. FGrabberSize := Value;
  2468. UpdateAll;
  2469. Docksite.Invalidate;
  2470. end;
  2471. end;
  2472. function TCnDockTree.GetGrabbersPosition: TGrabbersPosition;
  2473. begin
  2474. if DockSite.Align in [alTop, alBottom] then
  2475. Result := gpLeft
  2476. else Result := gpTop;
  2477. end;
  2478. function TCnDockTree.GetBottomGrabbersHTFlag(const MousePos: TPoint;
  2479. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone;
  2480. begin
  2481. Result := nil;
  2482. end;
  2483. function TCnDockTree.GetBorderHTFlag(const MousePos: TPoint;
  2484. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone;
  2485. var ARect: TRect;
  2486. begin
  2487. Result := nil;
  2488. { 获得节点的矩形大小 }
  2489. ARect := Zone.GetFrameRect;
  2490. { 如果鼠标的坐标在矩形内 }
  2491. if PtInRect(ARect, MousePos) then
  2492. begin
  2493. { 减去边框的宽度 }
  2494. InflateRect(ARect, -BorderWidth, -BorderWidth);
  2495. if not PtInRect(ARect, MousePos) then
  2496. begin
  2497. Result := Zone;
  2498. HTFlag := HTBORDER;
  2499. end;
  2500. end;
  2501. end;
  2502. function TCnDockTree.GetLeftGrabbersHTFlag(const MousePos: TPoint;
  2503. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone;
  2504. begin
  2505. if (MousePos.X >= Zone.Left + BorderWidth) and (MousePos.X <= Zone.Left + BorderWidth + FGrabberSize) and
  2506. (MousePos.Y >= Zone.Top) and (MousePos.Y <= Zone.Top + Zone.Height) then
  2507. begin
  2508. Result := Zone;
  2509. if MousePos.Y < Zone.ChildControl.Top + FGrabberSize + 3 then HTFlag := HTCLOSE
  2510. else HTFlag := HTCAPTION;
  2511. end else Result := nil;
  2512. end;
  2513. function TCnDockTree.GetRightGrabbersHTFlag(const MousePos: TPoint;
  2514. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone;
  2515. begin
  2516. Result := nil;
  2517. end;
  2518. function TCnDockTree.GetTopGrabbersHTFlag(const MousePos: TPoint;
  2519. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone;
  2520. begin
  2521. if (MousePos.Y >= Zone.Top + BorderWidth) and (MousePos.Y <= Zone.Top + BorderWidth + FGrabberSize) and
  2522. (MousePos.X >= Zone.Left) and (MousePos.X <= Zone.Left + Zone.Width) then
  2523. begin
  2524. Result := Zone;
  2525. with Zone.ChildControl do
  2526. if MousePos.X > Left + Width - FGrabberSize - 3 then HTFlag := HTCLOSE
  2527. else HTFlag := HTCAPTION;
  2528. end else Result := nil;
  2529. end;
  2530. function TCnDockTree.GetActiveControl: TControl;
  2531. begin
  2532. Result := FActiveControl;
  2533. end;
  2534. procedure TCnDockTree.SetActiveControl(const Value: TControl);
  2535. begin
  2536. FActiveControl := Value;
  2537. end;
  2538. function TCnDockTree.GetGrabberSize: Integer;
  2539. begin
  2540. Result := FGrabberSize;
  2541. end;
  2542. function TCnDockTree.FindControlZoneAndLevel(Control: TControl;
  2543. var CtlLevel: Integer; IncludeHide: Boolean): TCnDockZone;
  2544. var
  2545. CtlZone: TCnDockZone;
  2546. procedure DoFindControlZone(StartZone: TCnDockZone; Level: Integer);
  2547. begin
  2548. if (StartZone.ChildControl = Control) and (StartZone.Visibled or IncludeHide) then
  2549. begin
  2550. CtlZone := StartZone;
  2551. CtlLevel := Level;
  2552. end
  2553. else begin
  2554. // 遍历右兄弟
  2555. if (CtlZone = nil) and (StartZone.NextSibling <> nil) then
  2556. DoFindControlZone(StartZone.NextSibling, Level);
  2557. // 遍历左子女
  2558. if (CtlZone = nil) and (StartZone.ChildZones <> nil) then
  2559. DoFindControlZone(StartZone.ChildZones, Level + 1);
  2560. if (CtlZone <> nil) and (not CtlZone.Visibled) then CtlZone := nil;
  2561. end;
  2562. end;
  2563. begin
  2564. CtlZone := nil;
  2565. CtlLevel := 0;
  2566. if (Control <> nil) and (FTopZone <> nil) then DoFindControlZone(FTopZone, 0);
  2567. Result := CtlZone;
  2568. end;
  2569. procedure TCnDockTree.SetSplitterWidth(const Value: Integer);
  2570. begin
  2571. if FSplitterWidth <> Value then
  2572. begin
  2573. FSplitterWidth := Value;
  2574. if FUpdateCount <= 0 then
  2575. UpdateAll;
  2576. end;
  2577. end;
  2578. procedure TCnDockTree.SetTopZone(const Value: TCnDockZone);
  2579. begin
  2580. FTopZone := Value;
  2581. end;
  2582. procedure TCnDockTree.SetTopXYLimit(const Value: Integer);
  2583. begin
  2584. FTopXYLimit := Value;
  2585. end;
  2586. procedure TCnDockTree.DoMouseMove(var Message: TWMMouse;
  2587. var Zone: TCnDockZone; out HTFlag: Integer);
  2588. var Control: TControl;
  2589. DockClient: TCnDockClient;
  2590. begin
  2591. { 如果鼠标按下的地方是分割条的位置上 }
  2592. if FSizingZone <> nil then
  2593. begin
  2594. { 画分割条的形状 }
  2595. DrawSizeSplitter;
  2596. { 把鼠标的位置保存起来 }
  2597. FSizePos := SmallPointToPoint(Message.Pos);
  2598. { 计算鼠标的位置,对其做一些限制 }
  2599. CalcSplitterPos;
  2600. { 画分割条的形状 }
  2601. DrawSizeSplitter;
  2602. end;
  2603. { 返回鼠标的位置 }
  2604. Zone := InternalHitTest(SmallPointToPoint(Message.Pos), HTFlag);
  2605. if Zone <> nil then
  2606. begin
  2607. { 首先调用TCnDockClient中的DoNCMouseMove方法 }
  2608. DockClient := FindDockClient(Zone.ChildControl);
  2609. if DockClient <> nil then
  2610. DockClient.DoNCMouseMove(Cn_CreateNCMessage(
  2611. DockSite, WM_NCMOUSEMOVE, HTFlag, FSizePos), msConjoin);
  2612. Control := Zone.ChildControl;
  2613. end
  2614. else Control := nil;
  2615. if (Control <> nil) and (HTFlag <> FOldHTFlag) then
  2616. begin
  2617. { 如果鼠标的位置和原来的位置不一样,就更新提示窗体 }
  2618. Application.HideHint;
  2619. Application.HintMouseMessage(Control, TMessage(Message));
  2620. Application.ActivateHint(SmallPointToPoint(Message.Pos));
  2621. FOldHTFlag := HTFlag;
  2622. end;
  2623. end;
  2624. function TCnDockTree.DoLButtonDown(var Message: TWMMouse;
  2625. var Zone: TCnDockZone; out HTFlag: Integer): Boolean;
  2626. var P: TPoint;
  2627. Msg: TMsg;
  2628. // DockClient: TCnDockClient;
  2629. begin
  2630. Result := False;
  2631. P := SmallPointToPoint(Message.Pos);
  2632. { 返回鼠标的位置和当前的节点 }
  2633. Zone := InternalHitTest(P, HTFlag);
  2634. if (Zone <> nil) then
  2635. begin
  2636. if HTFlag = HTSPLITTER then
  2637. { 如果鼠标的位置刚好在分割条的位置上,
  2638. 就调用SplitterMouseDown函数进行一些必要的处理 }
  2639. SplitterMouseDown(Zone, P)
  2640. else if (HTFlag = HTCAPTION) or (HTFlag = HTBORDER) then
  2641. begin
  2642. { 如果鼠标的位置是在标题栏上 }
  2643. { 给全局变量GlobalDockClient赋值 }
  2644. GlobalDockClient := FindDockClient(Zone.ChildControl);
  2645. if GlobalDockClient <> nil then
  2646. { 首先调用TCnDockClient中的DoNCButtonDown方法 }
  2647. GlobalDockClient.DoNCButtonDown(Cn_CreateNCMessage(
  2648. DockSite, WM_NCLBUTTONDOWN, HTFlag, P), mbLeft, msConjoin);
  2649. if (not PeekMessage(Msg, FDockSite.Handle, WM_LBUTTONDBLCLK,
  2650. WM_LBUTTONDBLCLK, PM_NOREMOVE)) and
  2651. (Zone.ChildControl is TWinControl) then
  2652. { 使节点上面的控件获得焦点 }
  2653. // if not Zone.ChildControl.Focused then
  2654. // TWinControl(Zone.ChildControl).SetFocus;
  2655. if (GetActiveControl <> Zone.ChildControl) and Zone.ChildControl.CanFocus then
  2656. Zone.ChildControl.SetFocus;
  2657. if (TCnWinControlAccess(Zone.ChildControl).DragKind = dkDock) and
  2658. (TCnWinControlAccess(Zone.ChildControl).DragMode = dmAutomatic)then
  2659. begin
  2660. { 开始拖动 }
  2661. BeginDrag(Zone.ChildControl, True);
  2662. end;
  2663. Result := True;
  2664. end;
  2665. end;
  2666. end;
  2667. procedure TCnDockTree.DoLButtonUp(var Message: TWMMouse;
  2668. var Zone: TCnDockZone; out HTFlag: Integer);
  2669. var P: TPoint;
  2670. DockClient: TCnDockClient;
  2671. begin
  2672. if FSizingZone = nil then
  2673. begin
  2674. { 如果鼠标按下的位置不是在分割条上,
  2675. 也就是说是在标题栏上面,就判断它具体是在标题栏的哪个具体位置 }
  2676. P := SmallPointToPoint(Message.Pos);
  2677. Zone := InternalHitTest(P, HTFlag);
  2678. if (Zone <> nil) then
  2679. begin
  2680. if (HTFlag <> HTSPLITTER) and (Zone.ChildControl <> nil) then
  2681. begin
  2682. DockClient := FindDockClient(Zone.ChildControl);
  2683. if DockClient <> nil then
  2684. { 首先调用TCnDockClient中的DoNCButtonDown方法 }
  2685. DockClient.DoNCButtonUp(Cn_CreateNCMessage(
  2686. DockSite, WM_NCLBUTTONUP, HTFlag, P), mbLeft, msConjoin);
  2687. if (HTFlag = HTCLOSE) then
  2688. begin
  2689. if (DockClient <> nil) and (not DockClient.EnableCloseBtn) then Exit;
  2690. DoHideZoneChild(Zone);
  2691. end;
  2692. end;
  2693. end;
  2694. end
  2695. else
  2696. { 如果鼠标按下的位置是在分割条上,就调用SplitterMouseUp函数进行一些必要的设置}
  2697. SplitterMouseUp;
  2698. end;
  2699. procedure TCnDockTree.DoLButtonDbClk(var Message: TWMMouse;
  2700. var Zone: TCnDockZone; out HTFlag: Integer);
  2701. var //AControl: TWinControl;
  2702. P: TPoint;
  2703. begin
  2704. { 首先判断鼠标的位置是在哪里 }
  2705. P := SmallPointToPoint(Message.Pos);
  2706. Zone := InternalHitTest(P, HTFlag);
  2707. if (Zone <> nil) and (Zone.ChildControl <> nil)
  2708. and (HTFlag = HTCAPTION) or (HTFlag = HTBORDER) then
  2709. begin
  2710. if (HTFlag <> HTSPLITTER) then
  2711. { 首先调用TCnDockClient中的DoNCButtonDown方法 }
  2712. GlobalDockClient.DoNCButtonDblClk(Cn_CreateNCMessage(
  2713. DockSite, WM_NCLBUTTONUP, HTFlag, P), mbLeft, msConjoin);
  2714. if GlobalDockClient.CanFloat then
  2715. begin
  2716. { 如果鼠标的位置是在标题栏上面,就使节点上面的控件浮动 }
  2717. CnGlobalDockPresident.CancelDrag;
  2718. Zone.LButtonDbClkMothed;
  2719. end;
  2720. Zone := nil;
  2721. end;
  2722. end;
  2723. procedure TCnDockTree.DoSetCursor(var Message: TWMSetCursor;
  2724. var Zone: TCnDockZone; out HTFlag: Integer);
  2725. var
  2726. P: TPoint;
  2727. begin
  2728. { 获得鼠标的位置并且进行坐标转换 }
  2729. GetCursorPos(P);
  2730. P := FDockSite.ScreenToClient(P);
  2731. with Message do
  2732. if (Smallint(HitTest) = HTCLIENT) and (CursorWnd = FDockSite.Handle)
  2733. and (FDockSite.VisibleDockClientCount > 0) then
  2734. begin
  2735. { 确定鼠标在哪个位置 }
  2736. Zone := InternalHitTest(P, HTFlag);
  2737. if (Zone <> nil) and (HTFlag = HTSPLITTER) then
  2738. begin
  2739. { 如果鼠标是在分割条上,就调用SetSplitterCursor设置光标的形状 }
  2740. SetSplitterCursor(Zone.ParentZone.Orientation);
  2741. Result := 1;
  2742. end;
  2743. end;
  2744. end;
  2745. procedure TCnDockTree.DoHintShow(var Message: TCMHintShow;
  2746. var Zone: TCnDockZone; out HTFlag: Integer);
  2747. var
  2748. Control: TWinControl;
  2749. R: TRect;
  2750. ADockClient: TCnDockClient;
  2751. CanShow: Boolean;
  2752. begin
  2753. with Message do
  2754. begin
  2755. if Result = 0 then
  2756. begin
  2757. { 确定鼠标在哪个位置 }
  2758. Zone := InternalHitTest(Message.HintInfo.CursorPos, HTFlag);
  2759. if Zone <> nil then
  2760. Control := Zone.ChildControl
  2761. else Control := nil;
  2762. { 查找到Control上面的TCnDockClient,如果她的ShowHint属性为False,就退出 }
  2763. ADockClient := FindDockClient(Control);
  2764. if (ADockClient <> nil) and (not ADockClient.ShowHint) then
  2765. Exit;
  2766. if HTFlag = HTSPLITTER then
  2767. HintInfo^.HintStr := ''
  2768. else if (Control <> nil){ and (HTFlag in [HTCAPTION, HTCLOSE]) }then
  2769. begin
  2770. { 设置提示窗体的大小 }
  2771. R := GetFrameRect(Control);
  2772. if HTFlag = HTCAPTION then
  2773. begin
  2774. { 标题栏的提示信息 }
  2775. HintInfo^.HintStr := TCnWinControlAccess(Control).Caption;
  2776. end else if HTFlag = HTCLOSE then
  2777. { 关闭按钮的提示信息 }
  2778. HintInfo^.HintStr := gs_CnDockTreeCloseBtnHint
  2779. else DoOtherHint(Zone, HTFlag, HintInfo^.HintStr);
  2780. HintInfo^.CursorRect := R;
  2781. { 调用TCnDockClient的DoFormShowHint方法。}
  2782. CanShow := True;
  2783. if ADockClient <> nil then
  2784. ADockClient.DoFormShowHint(HTFlag, HintInfo^.HintStr, CanShow);
  2785. if not CanShow then
  2786. HintInfo^.HintStr := '';
  2787. end;
  2788. end;
  2789. end;
  2790. end;
  2791. procedure TCnDockTree.SetSplitterCursor(CursorIndex: TDockOrientation);
  2792. const
  2793. SizeCursors: array[TDockOrientation] of TCursor = (crDefault, crVSplit, crHSplit);
  2794. begin
  2795. Windows.SetCursor(Screen.Cursors[SizeCursors[CursorIndex]]);
  2796. end;
  2797. procedure TCnDockTree.SetCnDockZoneClass(const Value: TCnDockZoneClass);
  2798. begin
  2799. FCnDockZoneClass := Value;
  2800. end;
  2801. procedure TCnDockTree.DoMButtonDown(var Message: TWMMouse;
  2802. var Zone: TCnDockZone; out HTFlag: Integer);
  2803. var Msg: TWMNCHitMessage;
  2804. DockClient: TCnDockClient;
  2805. begin
  2806. Msg := DoMouseEvent(Message, Zone, HTFlag);
  2807. if Msg.Result > 0 then
  2808. begin
  2809. DockClient := FindDockClient(Zone.ChildControl);
  2810. if DockClient <> nil then
  2811. { 查找到控件上的TCnDockClient,并且调用TCnDockClient的DoNCButtonDown方法 }
  2812. DockClient.DoNCButtonDown(Msg, mbMiddle, msConjoin);
  2813. end;
  2814. end;
  2815. procedure TCnDockTree.DoMButtonUp(var Message: TWMMouse;
  2816. var Zone: TCnDockZone; out HTFlag: Integer);
  2817. var Msg: TWMNCHitMessage;
  2818. DockClient: TCnDockClient;
  2819. begin
  2820. Msg := DoMouseEvent(Message, Zone, HTFlag);
  2821. if Msg.Result > 0 then
  2822. begin
  2823. DockClient := FindDockClient(Zone.ChildControl);
  2824. if DockClient <> nil then
  2825. { 查找到控件上的TCnDockClient,并且调用TCnDockClient的DoNCButtonUp方法 }
  2826. DockClient.DoNCButtonUp(Msg, mbMiddle, msConjoin);
  2827. end;
  2828. end;
  2829. procedure TCnDockTree.DoRButtonDown(var Message: TWMMouse;
  2830. var Zone: TCnDockZone; out HTFlag: Integer);
  2831. var Msg: TWMNCHitMessage;
  2832. DockClient: TCnDockClient;
  2833. begin
  2834. Msg := DoMouseEvent(Message, Zone, HTFlag);
  2835. if Msg.Result > 0 then
  2836. begin
  2837. DockClient := FindDockClient(Zone.ChildControl);
  2838. if DockClient <> nil then
  2839. { 查找到控件上的TCnDockClient,并且调用TCnDockClient的DoNCButtonDown方法 }
  2840. DockClient.DoNCButtonDown(Msg, mbRight, msConjoin);
  2841. end;
  2842. end;
  2843. procedure TCnDockTree.DoRButtonUp(var Message: TWMMouse;
  2844. var Zone: TCnDockZone; out HTFlag: Integer);
  2845. var Msg: TWMNCHitMessage;
  2846. DockClient: TCnDockClient;
  2847. begin
  2848. Msg := DoMouseEvent(Message, Zone, HTFlag);
  2849. if Msg.Result > 0 then
  2850. begin
  2851. DockClient := FindDockClient(Zone.ChildControl);
  2852. if DockClient <> nil then
  2853. { 查找到控件上的TCnDockClient,并且调用TCnDockClient的DoNCButtonUp方法 }
  2854. DockClient.DoNCButtonUp(Msg, mbRight, msConjoin);
  2855. end;
  2856. end;
  2857. function TCnDockTree.DoMouseEvent(var Message: TWMMouse;
  2858. var Zone: TCnDockZone; out HTFlag: Integer): TWMNCHitMessage;
  2859. var APoint: TPoint;
  2860. begin
  2861. Result.Result := 0;
  2862. APoint := SmallPointToPoint(Message.Pos);
  2863. { 首先检测到鼠标的位置是在哪个控件的标题上 }
  2864. Zone := InternalHitTest(APoint, HTFlag);
  2865. if (Zone <> nil) and (Zone.ChildControl <> nil) and (HTFlag <> HTSPLITTER) then
  2866. begin
  2867. { 创建一个TWMNCHitMessage结构,其中'Message.Msg + WM_NCMOUSEFIRST - WM_MOUSEFIRST',
  2868. 这是因为WM_MOUSExxx和WM_NCMOUSExxx是一一对应的,他们相差了WM_NCMOUSEFIRST - WM_MOUSEFIRST。 }
  2869. Result := Cn_CreateNCMessage(DockSite, Message.Msg + WM_NCMOUSEFIRST - WM_MOUSEFIRST, HTFlag, APoint);
  2870. Result.Result := 1;
  2871. end;
  2872. end;
  2873. procedure TCnDockTree.DoMButtonDbClk(var Message: TWMMouse;
  2874. var Zone: TCnDockZone; out HTFlag: Integer);
  2875. var P: TPoint;
  2876. DockClient: TCnDockClient;
  2877. begin
  2878. { 首先判断鼠标的位置是在哪里 }
  2879. P := SmallPointToPoint(Message.Pos);
  2880. Zone := InternalHitTest(P, HTFlag);
  2881. if (Zone <> nil) and (Zone.ChildControl <> nil) and (HTFlag = HTCAPTION) then
  2882. begin
  2883. if (HTFlag <> HTSPLITTER) then
  2884. begin
  2885. DockClient := FindDockClient(Zone.ChildControl);
  2886. if DockClient <> nil then
  2887. { 首先调用TCnDockClient中的DoNCButtonDown方法 }
  2888. DockClient.DoNCButtonDblClk(Cn_CreateNCMessage(
  2889. DockSite, WM_NCLBUTTONUP, HTFlag, P), mbMiddle, msConjoin);
  2890. end;
  2891. end;
  2892. end;
  2893. procedure TCnDockTree.DoRButtonDbClk(var Message: TWMMouse;
  2894. var Zone: TCnDockZone; out HTFlag: Integer);
  2895. var P: TPoint;
  2896. DockClient: TCnDockClient;
  2897. begin
  2898. { 首先判断鼠标的位置是在哪里 }
  2899. P := SmallPointToPoint(Message.Pos);
  2900. Zone := InternalHitTest(P, HTFlag);
  2901. if (Zone <> nil) and (Zone.ChildControl <> nil) and (HTFlag = HTCAPTION) then
  2902. begin
  2903. if (HTFlag <> HTSPLITTER) then
  2904. begin
  2905. DockClient := FindDockClient(Zone.ChildControl);
  2906. if DockClient <> nil then
  2907. { 首先调用TCnDockClient中的DoNCButtonDown方法 }
  2908. DockClient.DoNCButtonDblClk(Cn_CreateNCMessage(
  2909. DockSite, WM_NCLBUTTONUP, HTFlag, P), mbRight, msConjoin);
  2910. end;
  2911. end;
  2912. end;
  2913. function TCnDockTree.GetFrameRect(Control: TControl): TRect;
  2914. var ALeft, ATop: Integer;
  2915. begin
  2916. if Control <> nil then
  2917. begin
  2918. Result := Control.BoundsRect;
  2919. ALeft := Result.Left;
  2920. Atop := Result.Top;
  2921. AdjustDockRect(Control, Result);
  2922. Dec(Result.Left, 2 * (Result.Left - Control.Left) + 1);
  2923. Dec(Result.Top, 2 * (Result.Top - Control.Top));
  2924. Dec(Result.Right, 2 * (Result.Right - ALeft - Control.Width));
  2925. Dec(Result.Bottom, 2 * (Result.Bottom - ATop - Control.Height));
  2926. end else raise Exception.Create(gs_ControlCannotIsNil);
  2927. end;
  2928. function TCnDockTree.GetSpiltterRect(Zone: TCnDockZone): TRect;
  2929. var A, B, C, D: Integer;
  2930. begin
  2931. if (Zone <> nil) and Zone.Visibled and (Zone.ParentZone <> nil)
  2932. and (Zone.VisibleNextSiblingCount >= 1)
  2933. and (Zone.ParentZone.Orientation <> doNoOrient) then
  2934. begin
  2935. A := Zone.ParentZone.LimitBegin;
  2936. B := Zone.ParentZone.ZoneLimit;
  2937. C := Zone.ZoneLimit - SplitterWidth;
  2938. D := C + 1 * SplitterWidth;
  2939. if Zone.ParentZone.Orientation = doHorizontal then
  2940. Result := Rect(A, C, B, D)
  2941. else if Zone.ParentZone.Orientation = doVertical then
  2942. Result := Rect(C, A, D, B);
  2943. end else Result := Rect(0, 0, 0, 0);
  2944. end;
  2945. {procedure TCnDockTree.PaintDockSplitter(Canvas: TCanvas; Control: TControl;
  2946. const ARect: TRect);
  2947. begin
  2948. with Canvas do
  2949. begin
  2950. FillRect(ARect);
  2951. end;
  2952. end;}
  2953. procedure TCnDockTree.BeginDrag(Control: TControl;
  2954. Immediate: Boolean; Threshold: Integer);
  2955. var ADockClient: TCnDockClient;
  2956. begin
  2957. ADockClient := FindDockClient(Control);
  2958. { 开始拖动 }
  2959. if ADockClient <> nil then
  2960. CnGlobalDockPresident.BeginDrag(Control, ADockClient.DirectDrag, Threshold);
  2961. end;
  2962. function TCnDockTree.GetFrameRectEx(Control: TControl): TRect;
  2963. begin
  2964. if Control <> nil then
  2965. begin
  2966. Result := GetFrameRect(Control);
  2967. MapWindowPoints(DockSite.Handle, 0, Result, 2);
  2968. end;
  2969. end;
  2970. procedure TCnDockTree.DrawDockSiteRect;
  2971. begin
  2972. { 没事做 }
  2973. end;
  2974. procedure TCnDockTree.SetBorderWidth(const Value: Integer);
  2975. begin
  2976. if FBorderWidth <> Value then
  2977. begin
  2978. FBorderWidth := Value;
  2979. if FUpdateCount <= 0 then
  2980. UpdateAll;
  2981. end;
  2982. end;
  2983. function TCnDockTree.GetBorderWidth: Integer;
  2984. begin
  2985. Result := FBorderWidth;
  2986. end;
  2987. function TCnDockTree.GetSplitterWidth: Integer;
  2988. begin
  2989. Result := FSplitterWidth;
  2990. end;
  2991. procedure TCnDockTree.DrawSplitter(Zone: TCnDockZone);
  2992. var R: TRect;
  2993. begin
  2994. { 获得分割条的矩形大小 }
  2995. R := GetSpiltterRect(Zone);
  2996. { 画分割条 }
  2997. DrawSplitterRect(R);
  2998. end;
  2999. function TCnDockTree.GetDockEdge(DockRect: TRect; MousePos: TPoint;
  3000. var DropAlign: TAlign; Control: TControl): TControl;
  3001. begin
  3002. Result := nil;
  3003. { 没事情做 }
  3004. end;
  3005. function TCnDockTree.GetDockSiteOrient: TDockOrientation;
  3006. begin
  3007. Result := Cn_GetControlOrient(DockSite);
  3008. end;
  3009. procedure TCnDockTree.BeginResizeDockSite;
  3010. begin
  3011. Inc(FResizeCount);
  3012. end;
  3013. procedure TCnDockTree.EndResizeDockSite;
  3014. begin
  3015. Dec(FResizeCount);
  3016. if FResizeCount < 0 then
  3017. FResizeCount := 0;
  3018. end;
  3019. procedure TCnDockTree.ScaleChildZone(Zone: TCnDockZone);
  3020. begin
  3021. // 必须是可见的,停靠方向和ShiftScaleOrient要相同。
  3022. if (Zone <> nil) and (Zone.ParentZone <> nil) and Zone.Visibled and
  3023. (Zone.ParentZone.Orientation = ShiftScaleOrient) then
  3024. begin
  3025. // 根据计算公式得到Zone的ZoneLimit。
  3026. Zone.ZoneLimit := Integer(Round(Zone.ZoneLimit * ScaleBy + FParentLimit * (1 - ScaleBy)));
  3027. // Zone的LimitSize不能小于规定的最小尺寸MinSize。
  3028. (* if (Zone.LimitSize < FMinSize) then
  3029. Zone.FZoneLimit := Zone.LimitBegin + FMinSize;
  3030. // Zone的LimitBegin和前一个可见的节点的ZoneLimit的位置不能小于规定的最小尺寸MinSize
  3031. if (Zone.BeforeClosestVisibleZone <> nil) and (Zone.LimitBegin > DockSiteSizeWithOrient[Zone.ParentZone.Orientation] -
  3032. (Zone.VisibleNextSiblingCount + 1) * MinSize + {Integer(Zone.NextSibling <> nil) * }SplitterWidth div 2) then
  3033. Zone.BeforeClosestVisibleZone.ZoneLimit := DockSiteSizeWithOrient[Zone.ParentZone.Orientation] -
  3034. (Zone.VisibleNextSiblingCount + 1) * MinSize + {Integer(Zone.NextSibling <> nil) * }SplitterWidth div 2;
  3035. *) end;
  3036. end;
  3037. procedure TCnDockTree.ScaleSiblingZone(Zone: TCnDockZone);
  3038. begin
  3039. {和ScaleChildZone的计算公式是一样的}
  3040. ScaleChildZone(Zone);
  3041. { if Zone = nil then Exit;
  3042. if (Zone <> nil) and (Zone.ParentZone <> nil) and
  3043. (Zone.ParentZone.Orientation = ShiftScaleOrient) then
  3044. Zone.ZoneLimit := Integer(Round(Zone.ZoneLimit * ScaleBy + FParentLimit * (1 - ScaleBy)));
  3045. }
  3046. end;
  3047. function TCnDockTree.GetDockSiteSize: Integer;
  3048. begin
  3049. case DockSiteOrient of
  3050. doVertical: Result := DockSite.Width;
  3051. doHorizontal: Result := DockSite.Height;
  3052. else
  3053. raise Exception.Create(gs_CannotGetValueWithNoOrient);
  3054. end;
  3055. end;
  3056. procedure TCnDockTree.SetDockSiteSize(const Value: Integer);
  3057. begin
  3058. DockSite.Parent.DisableAlign;
  3059. try
  3060. // 如果DockSite是在右边或者下边,就要重新设置DockSiteBegin(Top或者Left),
  3061. // 这样不至于打乱控件之间原来固有的次序。
  3062. if DockSite.Align in [alRight, alBottom] then
  3063. DockSiteBegin := DockSiteBegin - (Value - DockSiteSize);
  3064. case DockSiteOrient of
  3065. doVertical: DockSite.Width := Value;
  3066. doHorizontal: DockSite.Height := Value;
  3067. else
  3068. raise Exception.Create(gs_CannotSetValueWithNoOrient);
  3069. end;
  3070. finally
  3071. DockSite.Parent.EnableAlign;
  3072. end;
  3073. end;
  3074. procedure TCnDockTree.SetMinSize(const Value: Integer);
  3075. begin
  3076. FMinSize := Value;
  3077. end;
  3078. function TCnDockTree.GetDockSiteBegin: Integer;
  3079. begin
  3080. case DockSiteOrient of
  3081. doVertical: Result := DockSite.Left;
  3082. doHorizontal: Result := DockSite.Top;
  3083. else
  3084. raise Exception.Create(gs_CannotGetValueWithNoOrient);
  3085. end;
  3086. end;
  3087. procedure TCnDockTree.SetDockSiteBegin(const Value: Integer);
  3088. begin
  3089. case DockSiteOrient of
  3090. doVertical: DockSite.Left := Value;
  3091. doHorizontal: DockSite.Top := Value;
  3092. else
  3093. raise Exception.Create(gs_CannotSetValueWithNoOrient);
  3094. end;
  3095. end;
  3096. function TCnDockTree.GetDockSiteSizeA: Integer;
  3097. begin
  3098. case DockSiteOrient of
  3099. doVertical: Result := DockSite.Height;
  3100. doHorizontal: Result := DockSite.Width;
  3101. else
  3102. raise Exception.Create(gs_CannotGetValueWithNoOrient);
  3103. end;
  3104. end;
  3105. procedure TCnDockTree.SetDockSiteSizeA(const Value: Integer);
  3106. begin
  3107. case DockSiteOrient of
  3108. doVertical: DockSite.Height := Value;
  3109. doHorizontal: DockSite.Width := Value;
  3110. else
  3111. raise Exception.Create(gs_CannotSetValueWithNoOrient);
  3112. end;
  3113. end;
  3114. procedure TCnDockTree.CalcSplitterPos;
  3115. var
  3116. MinWidth,
  3117. TestLimit: Integer;
  3118. begin
  3119. MinWidth := MinSize;
  3120. if (FSizingZone.ParentZone.Orientation = doHorizontal) then
  3121. begin
  3122. TestLimit := GetSplitterLimit(FSizingZone, True, False) + MinWidth;
  3123. if FSizePos.y <= TestLimit then FSizePos.y := TestLimit;
  3124. TestLimit := GetSplitterLimit(FSizingZone, False, True) - MinWidth - SplitterWidth;
  3125. if FSizePos.y >= TestLimit then FSizePos.y := TestLimit;
  3126. end
  3127. else begin
  3128. TestLimit := GetSplitterLimit(FSizingZone, True, False) + MinWidth;
  3129. if FSizePos.x <= TestLimit then FSizePos.x := TestLimit;
  3130. TestLimit := GetSplitterLimit(FSizingZone, False, True) - MinWidth - SplitterWidth;
  3131. if FSizePos.x >= TestLimit then FSizePos.x := TestLimit;
  3132. end;
  3133. end;
  3134. procedure TCnDockTree.SetVersion(const Value: Integer);
  3135. begin
  3136. FVersion := Value;
  3137. end;
  3138. procedure TCnDockTree.DoSaveZone(Stream: TStream;
  3139. Zone: TCnDockZone; Level: Integer);
  3140. begin
  3141. with Stream do
  3142. begin
  3143. { 节点的等级, TopZone为0 }
  3144. Write(Level, SizeOf(Level));
  3145. CustomSaveZone(Stream, Zone);
  3146. end;
  3147. // 遍历左子女
  3148. if Zone.ChildZones <> nil then
  3149. DoSaveZone(Stream, Zone.ChildZones, Level + 1);
  3150. // 遍历右兄弟
  3151. if Zone.NextSibling <> nil then
  3152. DoSaveZone(Stream, Zone.NextSibling, Level);
  3153. end;
  3154. procedure TCnDockTree.WriteControlName(Stream: TStream; ControlName: string);
  3155. var
  3156. NameLen: Integer;
  3157. begin
  3158. NameLen := Length(ControlName);
  3159. Stream.Write(NameLen, SizeOf(NameLen));
  3160. if NameLen > 0 then Stream.Write(Pointer(ControlName)^, NameLen * SizeOf(Char));
  3161. end;
  3162. procedure TCnDockTree.DoLoadZone(Stream: TStream);
  3163. var
  3164. Level, LastLevel, I: Integer;
  3165. Zone, LastZone, NextZone: TCnDockZone;
  3166. begin
  3167. LastLevel := 0;
  3168. LastZone := nil;
  3169. while True do
  3170. begin
  3171. with Stream do
  3172. begin
  3173. Read(Level, SizeOf(Level));
  3174. if Level = TreeStreamEndFlag then Break;
  3175. Zone := FCnDockZoneClass.Create(Self);
  3176. CustomLoadZone(Stream, Zone);
  3177. if Zone = nil then
  3178. Continue;
  3179. end;
  3180. if Level = 0 then FTopZone := Zone
  3181. else if Level = LastLevel then
  3182. begin
  3183. LastZone.NextSibling := Zone;
  3184. Zone.FPrevSibling := LastZone;
  3185. Zone.FParentZone := LastZone.FParentZone;
  3186. end
  3187. else if Level > LastLevel then
  3188. begin
  3189. LastZone.ChildZones := Zone;
  3190. Zone.FParentZone := LastZone;
  3191. end
  3192. else if Level < LastLevel then
  3193. begin
  3194. NextZone := LastZone;
  3195. for I := 1 to LastLevel - Level do NextZone := NextZone.FParentZone;
  3196. NextZone.NextSibling := Zone;
  3197. Zone.FPrevSibling := NextZone;
  3198. Zone.FParentZone := NextZone.FParentZone;
  3199. end;
  3200. LastLevel := Level;
  3201. LastZone := Zone;
  3202. end;
  3203. end;
  3204. procedure TCnDockTree.ReadControlName(Stream: TStream;
  3205. var ControlName: string);
  3206. var
  3207. Size: Integer;
  3208. begin
  3209. ControlName := '';
  3210. Size := 0;
  3211. Stream.Read(Size, SizeOf(Size));
  3212. if Size > 0 then
  3213. begin
  3214. SetLength(ControlName, Size);
  3215. Stream.Read(Pointer(ControlName)^, Size * SizeOf(Char));
  3216. end;
  3217. end;
  3218. procedure TCnDockTree.CustomLoadZone(Stream: TStream; var Zone: TCnDockZone);
  3219. var CompName: string;
  3220. begin
  3221. with Stream do
  3222. begin
  3223. Read(Zone.FOrientation, SizeOf(Zone.Orientation));
  3224. Read(Zone.FZoneLimit, SizeOf(Zone.FZoneLimit));
  3225. Read(Zone.FVisibled, SizeOf(Zone.Visibled));
  3226. Read(Zone.FControlVisibled, SizeOf(Zone.FControlVisibled));
  3227. Read(Zone.FVisibleSize, SizeOf(Zone.VisibleSize));
  3228. Read(Zone.FIsInside, SizeOf(Zone.FIsInside));
  3229. ReadControlName(Stream, CompName);
  3230. if CompName <> '' then
  3231. begin
  3232. if not Zone.SetControlName(CompName) then
  3233. begin
  3234. { 如果没有找到这个控件就把节点删除 }
  3235. Zone.Free;
  3236. Zone := nil;
  3237. Exit;
  3238. end;
  3239. end;
  3240. end;
  3241. end;
  3242. procedure TCnDockTree.CustomSaveZone(Stream: TStream; Zone: TCnDockZone);
  3243. var AVisible: Boolean;
  3244. begin
  3245. with Stream do
  3246. begin
  3247. { 节点的方向 }
  3248. Write(Zone.Orientation, SizeOf(Zone.Orientation));
  3249. { 节点的绝对坐标 }
  3250. Write(Zone.ZoneLimit, SizeOf(Zone.ZoneLimit));
  3251. { 节点是否可见 }
  3252. if Zone.ChildControl <> nil then
  3253. AVisible := Zone.ChildControl.Visible;
  3254. Write(Zone.Visibled, SizeOf(Zone.Visibled));
  3255. { 控件是否可见 }
  3256. AVisible := False;
  3257. if Zone.ChildControl <> nil then
  3258. AVisible := Zone.ChildControl.Visible;
  3259. Write(AVisible, SizeOf(AVisible));
  3260. { 节点在可见的时候的LimitSize }
  3261. Write(Zone.VisibleSize, SizeOf(Zone.VisibleSize));
  3262. { 是否在DockSite的里面 }
  3263. Zone.IsInside := True;
  3264. if (Zone.ChildControl <> nil) and (Zone.ChildControl.HostDockSite <> DockSite)
  3265. and not (DockSite is TCnVSPopupPanel) then
  3266. Zone.IsInside := False;
  3267. Write(Zone.IsInside, SizeOf(Zone.IsInside));
  3268. { 节点所含有的ChildControl的名字 }
  3269. WriteControlName(Stream, Zone.GetControlName);
  3270. end;
  3271. end;
  3272. procedure TCnDockTree.SetDockSiteSizeWithOrient(Orient: TDockOrientation;
  3273. const Value: Integer);
  3274. begin
  3275. case Orient of
  3276. doVertical: DockSite.Width := Value;
  3277. doHorizontal: DockSite.Height := Value;
  3278. else
  3279. raise Exception.Create(gs_CannotSetValueWithNoOrient);
  3280. end;
  3281. end;
  3282. procedure TCnDockTree.DoOtherHint(Zone: TCnDockZone;
  3283. HTFlag: Integer; var HintStr: string);
  3284. begin
  3285. { 没事做 }
  3286. end;
  3287. function TCnDockTree.GetHTFlag(MousePos: TPoint): Integer;
  3288. var Zone: TCnDockZone;
  3289. begin
  3290. Zone := InternalHitTest(MousePos, Result);
  3291. if Zone = nil then Result := HTNONE;
  3292. end;
  3293. procedure TCnDockTree.GetSiteInfo(Client: TControl;
  3294. var InfluenceRect: TRect; MousePos: TPoint; var CanDock: Boolean);
  3295. begin
  3296. GetWindowRect(DockSite.Handle, InfluenceRect);
  3297. InflateRect(InfluenceRect, DefExpandoRect, DefExpandoRect);
  3298. end;
  3299. function TCnDockTree.GetDockRect: TRect;
  3300. begin
  3301. Result := FDockRect;
  3302. end;
  3303. procedure TCnDockTree.SetDockRect(const Value: TRect);
  3304. begin
  3305. FDockRect := Value;
  3306. end;
  3307. function TCnDockTree.GetDockAlign(Client: TControl; var DropCtl: TControl): TAlign;
  3308. var
  3309. CRect, DRect: TRect;
  3310. begin
  3311. Result := alRight;
  3312. if DropCtl <> nil then
  3313. begin
  3314. CRect := Client.BoundsRect;
  3315. DRect := DropCtl.BoundsRect;
  3316. if (CRect.Top <= DRect.Top) and (CRect.Bottom < DRect.Bottom) and
  3317. (CRect.Right >= DRect.Right) then
  3318. Result := alTop
  3319. else if (CRect.Left <= DRect.Left) and (CRect.Right < DRect.Right) and
  3320. (CRect.Bottom >= DRect.Bottom) then
  3321. Result := alLeft
  3322. else if CRect.Top >= ((DRect.Top + DRect.Bottom) div 2) then
  3323. Result := alBottom;
  3324. end;
  3325. end;
  3326. procedure TCnDockTree.HideControl(Control: TControl);
  3327. var
  3328. Z: TCnDockZone;
  3329. begin
  3330. { 如果ReplacementZone <> nil,就说明是在进行Load操作,不用执行下面的操作,直接退出就可以了 }
  3331. if ReplacementZone <> nil then Exit;
  3332. Z := FindControlZone(Control);
  3333. if (Z <> nil) then
  3334. begin
  3335. if Z = FReplacementZone then
  3336. Z.ChildControl := nil
  3337. else
  3338. begin
  3339. if TopZone.VisibleChildTotal = 1 then
  3340. Z.Remove(TopXYLimit, True)
  3341. else Z.Remove(Z.LimitSize, True);
  3342. // UpdateAll;
  3343. end;
  3344. Control.DockOrientation := doNoOrient;
  3345. SetNewBounds(nil);
  3346. UpdateAll;
  3347. { 重画DockSite }
  3348. FDockSite.Invalidate;
  3349. end;
  3350. end;
  3351. procedure TCnDockTree.ShowControl(Control: TControl);
  3352. var Z: TCnDockZone;
  3353. begin
  3354. { 如果ReplacementZone <> nil,就说明是在进行Load操作,不用执行下面的操作,直接退出就可以了 }
  3355. if ReplacementZone <> nil then Exit;
  3356. Z := FindControlZone(Control, True);
  3357. if Z <> nil then
  3358. Z.Insert(Z.VisibleSize, False);
  3359. SetNewBounds(nil);
  3360. UpdateAll;
  3361. DockSite.Invalidate;
  3362. end;
  3363. procedure TCnDockTree.DoGetNextLimit(Zone, AZone: TCnDockZone; var LimitResult: Integer);
  3364. begin
  3365. if (Zone <> AZone) and
  3366. (Zone.ParentZone.Orientation = AZone.ParentZone.Orientation) and
  3367. (Zone.ZoneLimit > AZone.FZoneLimit) and ((Zone.ChildControl = nil) or
  3368. ((Zone.ChildControl <> nil) and (Zone.ChildControl.Visible))) then
  3369. LimitResult := Min(LimitResult, Zone.ZoneLimit);
  3370. if Zone.NextSibling <> nil then DoGetNextLimit(Zone.NextSibling, AZone, LimitResult);
  3371. // 下面这条被注释掉的语句,表示可以忽略掉不是同一个父节点的节点,
  3372. // 使鼠标调节分割条更加自由。
  3373. if (Zone.ChildZones <> nil){ and (Zone = AZone.AfterClosestVisibleZone) }then
  3374. DoGetNextLimit(Zone.ChildZones, AZone, LimitResult);
  3375. end;
  3376. procedure TCnDockTree.UpdateChild(Zone: TCnDockZone);
  3377. begin
  3378. if (FUpdateCount = 0) and (FDockSite.DockClientCount > 0) then
  3379. ForEachAt(Zone, UpdateZone, tskForward);
  3380. end;
  3381. function TCnDockTree.GetDockClientLimit(Orient: TDockOrientation; IsMin: Boolean): Integer;
  3382. var Zone: TCnDockZone;
  3383. begin
  3384. Result := 0;
  3385. if TopZone.ChildCount = 1 then
  3386. Result := Integer(not IsMin) * DockSiteSizeWithOrient[Orient]
  3387. else
  3388. begin
  3389. if IsMin then
  3390. begin
  3391. if TopZone.Orientation = Orient then
  3392. Zone := TopZone.LastVisibleChildZone
  3393. else Zone := TopZone;
  3394. if Zone <> nil then
  3395. Result := Zone.LimitBegin;
  3396. end else
  3397. begin
  3398. if TopZone.Orientation = Orient then
  3399. Zone := TopZone.FirstVisibleChildZone
  3400. else Zone := TopZone;
  3401. if Zone <> nil then
  3402. Result := Zone.ZoneLimit;
  3403. end;
  3404. TopZone.DoGetSplitterLimit(Orient, IsMin, Result);
  3405. end;
  3406. { if TopZone <> nil then
  3407. begin
  3408. if TopZone.ChildCount = 1 then
  3409. Result := Integer(not IsMin) * DockSiteSizeWithOrient[Orient]
  3410. else
  3411. TopZone.DoGetSplitterLimit(Orient, IsMin, Result);
  3412. end;}
  3413. end;
  3414. function TCnDockTree.GetDockSiteSizeWithOrient(
  3415. Orient: TDockOrientation): Integer;
  3416. begin
  3417. case Orient of
  3418. doVertical: Result := DockSite.Width;
  3419. doHorizontal: Result := DockSite.Height;
  3420. else
  3421. raise Exception.Create(gs_CannotGetValueWithNoOrient);
  3422. end;
  3423. end;
  3424. function TCnDockTree.GetMinSize: Integer;
  3425. begin
  3426. Result := FMinSize;
  3427. end;
  3428. procedure TCnDockTree.GetCaptionRect(var Rect: TRect);
  3429. begin
  3430. Rect.Left := 0;
  3431. Rect.Top := 0;
  3432. Rect.Right := 0;
  3433. Rect.Bottom := 0;
  3434. end;
  3435. procedure TCnDockTree.HideAllControl;
  3436. procedure DoHideAllControl(AZone: TCnDockZone);
  3437. begin
  3438. if AZone <> nil then
  3439. begin
  3440. DoHideAllControl(AZone.NextSibling);
  3441. DoHideAllControl(AZone.ChildZones);
  3442. if (AZone.ChildControl <> nil) and (AZone.visibled) then
  3443. AZone.Remove(AZone.LimitSize, True);
  3444. end;
  3445. end;
  3446. begin
  3447. { 如果ReplacementZone <> nil,就说明是在进行Load操作,不用执行下面的操作,直接退出就可以了 }
  3448. if ReplacementZone <> nil then Exit;
  3449. DoHideAllControl(TopZone.ChildZones);
  3450. SetNewBounds(nil);
  3451. UpdateAll;
  3452. DockSite.Invalidate;
  3453. end;
  3454. procedure TCnDockTree.HideSingleControl(Control: TControl);
  3455. procedure DoHideSingleControl(AZone: TCnDockZone);
  3456. begin
  3457. if AZone <> nil then
  3458. begin
  3459. DoHideSingleControl(AZone.NextSibling);
  3460. DoHideSingleControl(AZone.ChildZones);
  3461. if AZone.ChildControl <> nil then
  3462. begin
  3463. if (AZone.ChildControl = Control) then
  3464. begin
  3465. if (AZone.ChildControl.Visible) then
  3466. begin
  3467. AZone.Remove(AZone.LimitSize, True);
  3468. AZone.ChildControl.Visible := False;
  3469. end;
  3470. end else
  3471. begin
  3472. AZone.Insert(AZone.VisibleSize, False);
  3473. AZone.ChildControl.Visible := True;
  3474. end;
  3475. end;
  3476. end;
  3477. end;
  3478. begin
  3479. { 如果ReplacementZone <> nil,就说明是在进行Load操作,不用执行下面的操作,直接退出就可以了 }
  3480. if ReplacementZone <> nil then Exit;
  3481. if Control <> nil then
  3482. begin
  3483. DoHideSingleControl(TopZone.ChildZones);
  3484. SetNewBounds(nil);
  3485. UpdateAll;
  3486. DockSite.Invalidate;
  3487. end;
  3488. end;
  3489. procedure TCnDockTree.ShowAllControl;
  3490. procedure DoShowAllControl(AZone: TCnDockZone);
  3491. begin
  3492. if AZone <> nil then
  3493. begin
  3494. DoShowAllControl(AZone.NextSibling);
  3495. DoShowAllControl(AZone.ChildZones);
  3496. if (AZone.ChildControl <> nil) and (not AZone.visibled) then
  3497. AZone.Insert(AZone.VisibleSize, True);
  3498. end;
  3499. end;
  3500. begin
  3501. { 如果ReplacementZone <> nil,就说明是在进行Load操作,不用执行下面的操作,直接退出就可以了 }
  3502. if ReplacementZone <> nil then Exit;
  3503. DoShowAllControl(TopZone.ChildZones);
  3504. SetNewBounds(nil);
  3505. UpdateAll;
  3506. DockSite.Invalidate;
  3507. end;
  3508. procedure TCnDockTree.ShowSingleControl(Control: TControl);
  3509. procedure DoShowSingleControl(AZone: TCnDockZone);
  3510. begin
  3511. if AZone <> nil then
  3512. begin
  3513. DoShowSingleControl(AZone.NextSibling);
  3514. DoShowSingleControl(AZone.ChildZones);
  3515. if AZone.ChildControl <> nil then
  3516. begin
  3517. if (AZone.ChildControl = Control) then
  3518. begin
  3519. if (not AZone.ChildControl.Visible) then
  3520. begin
  3521. AZone.Insert(AZone.VisibleSize, False);
  3522. AZone.ChildControl.Visible := True;
  3523. end;
  3524. end else
  3525. begin
  3526. AZone.Remove(AZone.LimitSize, True);
  3527. AZone.ChildControl.Visible := False;
  3528. end;
  3529. end;
  3530. end;
  3531. end;
  3532. begin
  3533. { 如果ReplacementZone <> nil,就说明是在进行Load操作,不用执行下面的操作,直接退出就可以了 }
  3534. if ReplacementZone <> nil then Exit;
  3535. if Control <> nil then
  3536. begin
  3537. DoShowSingleControl(TopZone.ChildZones);
  3538. SetNewBounds(nil);
  3539. UpdateAll;
  3540. DockSite.Invalidate;
  3541. end;
  3542. end;
  3543. procedure TCnDockTree.DrawDockBorder(DockControl: TControl; R1, R2: TRect);
  3544. begin
  3545. end;
  3546. procedure TCnDockTree.DrawDockGrabber(Control: TControl;
  3547. const ARect: TRect);
  3548. procedure DrawCloseButton(Left, Top: Integer);
  3549. var ADockClient: TCnDockClient;
  3550. begin
  3551. ADockClient := FindDockClient(Control);
  3552. if (ADockClient <> nil) and (not ADockClient.EnableCloseBtn) then Exit;
  3553. DrawFrameControl(Canvas.Handle, Rect(Left, Top, Left+GrabberSize-2,
  3554. Top+GrabberSize-2), DFC_CAPTION, DFCS_CAPTIONCLOSE);
  3555. end;
  3556. procedure DrawGrabberLine(Left, Top, Right, Bottom: Integer);
  3557. begin
  3558. with Canvas do
  3559. begin
  3560. Pen.Color := clBtnHighlight;
  3561. MoveTo(Right, Top);
  3562. LineTo(Left, Top);
  3563. LineTo(Left, Bottom);
  3564. Pen.Color := clBtnShadow;
  3565. LineTo(Right, Bottom);
  3566. LineTo(Right, Top-1);
  3567. end;
  3568. end;
  3569. begin
  3570. with ARect do
  3571. begin
  3572. case GrabbersPosition of
  3573. gpLeft:
  3574. begin
  3575. DrawCloseButton(Left+BorderWidth+BorderWidth+1, Top+BorderWidth+BorderWidth+1);
  3576. DrawGrabberLine(Left+BorderWidth+3, Top+GrabberSize+BorderWidth+1, Left+BorderWidth+5, Bottom+BorderWidth-2);
  3577. DrawGrabberLine(Left+BorderWidth+6, Top+GrabberSize+BorderWidth+1, Left+BorderWidth+8, Bottom+BorderWidth-2);
  3578. end;
  3579. gpTop:
  3580. begin
  3581. DrawCloseButton(Right-GrabberSize+BorderWidth+1, Top+BorderWidth+1);
  3582. DrawGrabberLine(Left+BorderWidth+2, Top+BorderWidth+BorderWidth+3, Right-GrabberSize+BorderWidth-2, Top+BorderWidth+5);
  3583. DrawGrabberLine(Left+BorderWidth+2, Top+BorderWidth+BorderWidth+6, Right-GrabberSize+BorderWidth-2, Top+BorderWidth+8);
  3584. end;
  3585. // gpBottom:
  3586. // gpRight:
  3587. end;
  3588. end;
  3589. end;
  3590. procedure TCnDockTree.DrawSplitterRect(const ARect: TRect);
  3591. begin
  3592. Canvas.Brush.Color := TCnWinControlAccess(DockSite).Color;
  3593. Canvas.FillRect(ARect);
  3594. end;
  3595. procedure TCnDockTree.DrawZone(Zone: TCnDockZone);
  3596. begin
  3597. { 依次调用DrawZoneBorder,DrawGrabber和DrawSplitter方法,
  3598. 子类可以重载这个方法改变重画的内容 }
  3599. DrawZoneBorder(Zone);
  3600. DrawZoneGrabber(Zone);
  3601. DrawZoneSplitter(Zone);
  3602. DrawDockSiteRect;
  3603. end;
  3604. procedure TCnDockTree.DrawZoneBorder(Zone: TCnDockZone);
  3605. var ChildControl: TControl;
  3606. // R1, R2: TRect;
  3607. begin
  3608. if Zone = nil then Exit;
  3609. ChildControl := Zone.ChildControl;
  3610. if (ChildControl <> nil) and ChildControl.Visible and
  3611. (ChildControl.HostDockSite = DockSite) then
  3612. begin
  3613. // R := GetFrameRect(ChildControl);
  3614. // DrawDockGrabber(ChildControl, R);
  3615. end;
  3616. end;
  3617. procedure TCnDockTree.DrawZoneGrabber(Zone: TCnDockZone);
  3618. var ChildControl: TControl;
  3619. R: TRect;
  3620. begin
  3621. if Zone = nil then Exit;
  3622. ChildControl := Zone.ChildControl;
  3623. if (ChildControl <> nil) and ChildControl.Visible and
  3624. (ChildControl.HostDockSite = DockSite) then
  3625. begin
  3626. R := GetFrameRect(ChildControl);
  3627. DrawDockGrabber(ChildControl, R);
  3628. end;
  3629. end;
  3630. procedure TCnDockTree.DrawZoneSplitter(Zone: TCnDockZone);
  3631. var R: TRect;
  3632. begin
  3633. { 获得分割条的矩形大小 }
  3634. R := GetSpiltterRect(Zone);
  3635. { 画分割条 }
  3636. DrawSplitterRect(R);
  3637. end;
  3638. procedure TCnDockTree.PaintDockSite;
  3639. begin
  3640. ForEachAt(nil, DrawZone, tskBackward);
  3641. end;
  3642. function TCnDockTree.HasZoneWithControl(Control: TControl): Boolean;
  3643. begin
  3644. Result := FindControlZone(Control, True) <> nil;
  3645. end;
  3646. procedure TCnDockTree.ReplaceZoneChild(OldControl, NewControl: TControl);
  3647. var Zone: TCnDockZone;
  3648. begin
  3649. Zone := FindControlZone(OldControl, True);
  3650. if Zone <> nil then
  3651. begin
  3652. Zone.ChildControl := TWinControl(NewControl);
  3653. UpdateAll;
  3654. end;
  3655. end;
  3656. procedure TCnDockTree.DoHideZoneChild(AZone: TCnDockZone);
  3657. var AForm: TCustomForm;
  3658. begin
  3659. if (AZone <> nil) and (AZone.ChildControl <> nil) then
  3660. begin
  3661. if AZone.ChildControl.InheritsFrom(TCustomForm) then
  3662. begin
  3663. { 当调用Close函数后,AZone将被释放 }
  3664. AForm := TCustomForm(AZone.ChildControl);
  3665. AForm.Close;
  3666. end else
  3667. AZone.ChildControl.Visible := False;
  3668. end;
  3669. end;
  3670. { TCnAdvDockZone }
  3671. constructor TCnAdvDockZone.Create(Tree: TCnDockTree);
  3672. begin
  3673. inherited;
  3674. FCloseBtnDown := False;
  3675. FMouseDown := False;
  3676. end;
  3677. destructor TCnAdvDockZone.Destroy;
  3678. begin
  3679. if Self = TCnAdvDockTree(Tree).CloseBtnZone then
  3680. TCnAdvDockTree(Tree).CloseBtnZone := nil;
  3681. inherited Destroy;
  3682. end;
  3683. procedure TCnAdvDockZone.Insert(DockSize: Integer; Hide: Boolean);
  3684. begin
  3685. InsertOrRemove(DockSize, True, Hide);
  3686. end;
  3687. procedure TCnAdvDockZone.LButtonDbClkMothed;
  3688. begin
  3689. if GlobalDockClient <> nil then
  3690. GlobalDockClient.RestoreChild;
  3691. end;
  3692. procedure TCnAdvDockZone.Remove(DockSize: Integer; Hide: Boolean);
  3693. begin
  3694. InsertOrRemove(DockSize, False, Hide);
  3695. end;
  3696. { TCnAdvDockTree }
  3697. constructor TCnAdvDockTree.Create(DockSite: TWinControl;
  3698. CnDockZoneClass: TCnDockZoneClass);
  3699. begin
  3700. inherited Create(DockSite, CnDockZoneClass);
  3701. GrabberSize := 15;
  3702. FButtonHeight := 12;
  3703. FButtonWidth := 12;
  3704. FLeftOffset := 0;
  3705. FRightOffset := 0;
  3706. FTopOffset := 0;
  3707. FBottomOffset := 0;
  3708. FButtonSplitter := 2;
  3709. end;
  3710. function TCnAdvDockTree.DoLButtonDown(var Message: TWMMouse;
  3711. var Zone: TCnDockZone; out HTFlag: Integer): Boolean;
  3712. var TempZone: TCnAdvDockZone;
  3713. begin
  3714. Result := inherited DoLButtonDown(Message, Zone, HTFlag);
  3715. if (Zone <> nil) and (HTFlag = HTCLOSE) then
  3716. begin
  3717. TempZone := TCnAdvDockZone(Zone);
  3718. TempZone.CloseBtnDown := True;
  3719. TempZone.MouseDown := True;
  3720. FCloseBtnZone := TempZone;
  3721. DockSite.Invalidate;
  3722. end;
  3723. end;
  3724. procedure TCnAdvDockTree.DoLButtonUp(var Message: TWMMouse;
  3725. var Zone: TCnDockZone; out HTFlag: Integer);
  3726. //var TempZone: TCnAdvDockZone;
  3727. begin
  3728. inherited DoLButtonUp(Message, Zone, HTFlag);
  3729. if SizingZone = nil then
  3730. begin
  3731. FCloseBtnZone := nil;
  3732. if (Zone <> nil) and (HTFlag = HTCLOSE) then
  3733. begin
  3734. // 在这里会有地址偏差,TCnAdvDockZone(Zone).CloseBtnDown
  3735. // 会莫名其妙的指向一个类的指针,需要注意。
  3736. // TempZone := TCnAdvDockZone(Zone);
  3737. TCnAdvDockZone(Zone).CloseBtnDown := False;
  3738. end;
  3739. end;
  3740. end;
  3741. procedure TCnAdvDockTree.DoMouseMove(var Message: TWMMouse;
  3742. var Zone: TCnDockZone; out HTFlag: Integer);
  3743. var TempZone: TCnAdvDockZone;
  3744. begin
  3745. inherited DoMouseMove(Message, Zone, HTFlag);
  3746. if SizingZone = nil then
  3747. begin
  3748. TempZone := TCnAdvDockZone(Zone);
  3749. if ((TempZone <> nil) and (TempZone.CloseBtnDown <> (HTFlag = HTCLOSE))
  3750. and ((FCloseBtnZone = TempZone) and FCloseBtnZone.MouseDown)) then
  3751. begin
  3752. TempZone.CloseBtnDown := (HTFlag = HTCLOSE) and FCloseBtnZone.MouseDown;
  3753. DockSite.Invalidate;
  3754. end;
  3755. end;
  3756. end;
  3757. procedure TCnAdvDockTree.InsertSibling(NewZone, SiblingZone: TCnDockZone;
  3758. InsertLast, Update: Boolean);
  3759. var
  3760. TempUpdate: Boolean;
  3761. begin
  3762. TempUpdate := Update;
  3763. Update := False;
  3764. try
  3765. inherited;
  3766. if NewZone.ChildControl <> nil then
  3767. SetDockHeightWidthArr(0, NewZone.ChildControl.TBDockHeight + BorderWidth,
  3768. NewZone.ChildControl.LRDockWidth + BorderWidth)
  3769. else SetDockHeightWidthArr(0, 0, 0);
  3770. finally
  3771. Update := TempUpdate;
  3772. end;
  3773. if Update then
  3774. begin
  3775. NewZone.Insert(FDropDockSize, False);
  3776. SetNewBounds(NewZone.ParentZone);
  3777. ForEachAt(NewZone.ParentZone, UpdateZone, tskForward);
  3778. end;
  3779. end;
  3780. procedure TCnAdvDockTree.SetBottomOffset(const Value: Integer);
  3781. begin
  3782. FBottomOffset := Value;
  3783. end;
  3784. procedure TCnAdvDockTree.SetButtonHeight(const Value: Integer);
  3785. begin
  3786. FButtonHeight := Value;
  3787. end;
  3788. procedure TCnAdvDockTree.SetButtonSplitter(const Value: Integer);
  3789. begin
  3790. FButtonSplitter := Value;
  3791. end;
  3792. procedure TCnAdvDockTree.SetButtonWidth(const Value: Integer);
  3793. begin
  3794. FButtonWidth := Value;
  3795. end;
  3796. procedure TCnAdvDockTree.SetLeftOffset(const Value: Integer);
  3797. begin
  3798. FLeftOffset := Value;
  3799. end;
  3800. procedure TCnAdvDockTree.SetRightOffset(const Value: Integer);
  3801. begin
  3802. FRightOffset := Value;
  3803. end;
  3804. procedure TCnAdvDockTree.SetTopOffset(const Value: Integer);
  3805. begin
  3806. FTopOffset := Value;
  3807. end;
  3808. function TCnAdvDockTree.GetDockHeightWidth(
  3809. Orient: TDockOrientation): Integer;
  3810. begin
  3811. Result := FDockHeightWidth[Orient];
  3812. end;
  3813. procedure TCnAdvDockTree.SetDockHeightWidth(Orient: TDockOrientation;
  3814. const Value: Integer);
  3815. begin
  3816. FDockHeightWidth[Orient] := Value;
  3817. end;
  3818. function TCnAdvDockTree.GetDockRectFromArr(Orient: TDockOrientation;
  3819. AtLast: Boolean): Integer;
  3820. begin
  3821. Result := FDockRectArr[Orient, Atlast];
  3822. end;
  3823. procedure TCnAdvDockTree.SetDockRectToArr(Orient: TDockOrientation;
  3824. AtLast: Boolean; const Value: Integer);
  3825. begin
  3826. FDockRectArr[Orient, Atlast] := Value;
  3827. end;
  3828. procedure TCnAdvDockTree.SetDockRectArr(ARect: TRect);
  3829. begin
  3830. FDockRectArr[doNoOrient, False] := 0;
  3831. FDockRectArr[doNoOrient, True] := 0;
  3832. FDockRectArr[doHorizontal, False] := ARect.Top;
  3833. FDockRectArr[doHorizontal, True] := ARect.Bottom;
  3834. FDockRectArr[doVertical, False] := ARect.Left;
  3835. FDockRectArr[doVertical, True] := ARect.Right;
  3836. end;
  3837. procedure TCnAdvDockTree.SetDockHeightWidthArr(NoOrValue, HorValue,
  3838. VerValue: Integer);
  3839. begin
  3840. FDockHeightWidth[doNoOrient] := NoOrValue;
  3841. FDockHeightWidth[doHorizontal] := HorValue;
  3842. FDockHeightWidth[doVertical] := VerValue;
  3843. end;
  3844. procedure TCnAdvDockTree.ScaleChildZone(Zone: TCnDockZone);
  3845. begin
  3846. if Zone = ReplacementZone then
  3847. ShiftScaleOrient := doNoOrient;
  3848. inherited ScaleChildZone(Zone);
  3849. end;
  3850. procedure TCnAdvDockTree.ScaleSiblingZone(Zone: TCnDockZone);
  3851. begin
  3852. if Zone = ReplacementZone then
  3853. ShiftScaleOrient := doNoOrient;
  3854. inherited ScaleSiblingZone(Zone);
  3855. end;
  3856. procedure TCnAdvDockTree.ScaleZone(Zone: TCnDockZone);
  3857. begin
  3858. if Zone = ReplacementZone then
  3859. ShiftScaleOrient := doNoOrient;
  3860. inherited ScaleZone(Zone);
  3861. end;
  3862. procedure TCnAdvDockTree.ShiftZone(Zone: TCnDockZone);
  3863. begin
  3864. if Zone = ReplacementZone then
  3865. ShiftScaleOrient := doNoOrient;
  3866. inherited ShiftZone(Zone);
  3867. end;
  3868. procedure TCnAdvDockTree.InsertNewParent(NewZone, SiblingZone: TCnDockZone;
  3869. ParentOrientation: TDockOrientation; InsertLast, Update: Boolean);
  3870. var
  3871. TempUpdate: Boolean;
  3872. begin
  3873. TempUpdate := Update;
  3874. Update := False;
  3875. if NewZone.ChildControl <> nil then
  3876. SetDockHeightWidthArr(0, NewZone.ChildControl.TBDockHeight + BorderWidth,
  3877. NewZone.ChildControl.LRDockWidth + BorderWidth)
  3878. else SetDockHeightWidthArr(0, 0, 0);
  3879. if SiblingZone = nil then
  3880. begin
  3881. if InsertLast then
  3882. ReplacementZone := TopZone
  3883. else ReplacementZone := NewZone;
  3884. end;
  3885. try
  3886. inherited;
  3887. finally
  3888. Update := TempUpdate;
  3889. ReplacementZone := nil;
  3890. end;
  3891. if Update then
  3892. begin
  3893. NewZone.Insert(DropDockSize, False);
  3894. ForEachAt(NewZone.ParentZone, UpdateZone, tskForward);
  3895. SetNewBounds(NewZone.ParentZone);
  3896. end;
  3897. end;
  3898. procedure TCnAdvDockTree.RemoveZone(Zone: TCnDockZone; Hide: Boolean);
  3899. begin
  3900. { 调用默认的RemoveZone函数 }
  3901. inherited;
  3902. end;
  3903. procedure TCnAdvDockTree.SetDropDockSize(const Value: Integer);
  3904. begin
  3905. FDropDockSize := Value;
  3906. end;
  3907. end.