CnVSNETDockStyle.pas 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090
  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. { 具有类似Visual Studio.NET的停靠风格 }
  23. { CnVSNETDockStyle 单元 }
  24. { }
  25. { 版权 (C) 2002,2003 鲁小班 }
  26. { }
  27. {*******************************************************}
  28. unit CnVSNETDockStyle;
  29. {* |<PRE>
  30. ================================================================================
  31. * 软件名称:不可视工具组件包停靠单元
  32. * 单元名称:具有类似Visual Studio.NET的停靠风格的单元
  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, Classes, Controls, Math, Messages, Graphics, ComCtrls, Extctrls,
  47. ImgList, Forms, CnConsts, CnCompConsts, CnDockFormControl,
  48. CnDockSupportControl, CnDockTree, CnVIDDockStyle;
  49. const
  50. { 自动隐藏按钮 }
  51. HTAUTOHIDE = 40;
  52. { 默认的VSNET风格的把手的大小 }
  53. DefaultVSNETGrabberSize = 19;
  54. { 当一个Block中的Pane获得焦点的时候他允许的最大宽度 }
  55. MaxActivePaneWidth = 100;
  56. { 没有获得焦点的Tab的字体颜色 }
  57. VSNETPageInactiveFontColor = $00525552;
  58. { 没有获得焦点的Tab的颜色 }
  59. VSNETPageInactiveSheetColor = $00EFF3F7;
  60. type
  61. TCnVSNETConjoinServerOption = class(TCnVIDConjoinServerOption)
  62. protected
  63. procedure SetDefaultSystemCaptionInfo; override;
  64. public
  65. constructor Create(ADockStyle: TCnBasicDockStyle); override;
  66. destructor Destroy; override;
  67. end;
  68. TCnVSNETTabServerOption = class(TCnVIDTabServerOption)
  69. public
  70. constructor Create(ADockStyle: TCnBasicDockStyle); override;
  71. end;
  72. { Channel的选项类 }
  73. TCnVSNETChannelOption = class(TCnBasicServerOption)
  74. private
  75. FActivePaneSize: Integer; //获得焦点的Pane的最大值
  76. FShowImage: Boolean; //显示图标
  77. procedure SetActivePaneSize(const Value: Integer);
  78. procedure SetShowImage(const Value: Boolean);
  79. protected
  80. procedure ResetDockControlOption; override;
  81. { 重新设置ADockServer的配置 }
  82. procedure ResetDockServerOption(ADockServer: TCnDockServer); override;
  83. { 重新设置ADockClient的配置 }
  84. procedure ResetDockClientOption(ADockClient: TCnDockClient); override;
  85. public
  86. constructor Create(ADockStyle: TCnBasicDockStyle); override;
  87. published
  88. property ActivePaneSize: Integer read FActivePaneSize write SetActivePaneSize;
  89. property ShowImage: Boolean read FShowImage write SetShowImage;
  90. end;
  91. TCnVSNETChannelOptionClass = class of TCnVSNETChannelOption;
  92. TCnVSBlock = class;
  93. TCnVSChannel = class;
  94. TCnVSNETDockPanel = class;
  95. TCnVSPopupPanel = class;
  96. TCnVSPopupPanelSplitter = class;
  97. TCnVSPane = class(TObject)
  98. public
  99. Block: TCnVSBlock;
  100. DockForm: TForm;
  101. Index: Integer; // 在Block中的索引
  102. Width: Integer; // 宽度
  103. Active: Boolean; // 是否处于激活状态
  104. Visible: Boolean;// 是否可见
  105. constructor Create(ABlock: TCnVSBlock; AForm: TForm; AWidth: Integer; AIndex: Integer); virtual;
  106. destructor Destroy; override;
  107. end;
  108. // 组块的类型,分别是平铺方式,分页方式
  109. TBlockType = (btConjoinBlock, btTabBlock);
  110. // 定义一个结构,用来存储每一个组块的信息
  111. TCnVSBlock = class(TObject)
  112. private
  113. FVSChannel: TCnVSChannel;
  114. // 停靠窗体的列表
  115. FVSPaneList: TList;
  116. // 获得焦点的组块的宽度
  117. FActiveBlockWidth: Integer;
  118. // 失去焦点的组块的宽度
  119. FInactiveBlockWidth: Integer;
  120. // 获得焦点的停靠窗体
  121. FActiveDockControl: TWinControl;
  122. // 组块的类型,平铺或者分页
  123. FBlockType: TBlockType;
  124. // 用来显示图标的TImageList
  125. FImageList: TImageList;
  126. // 组块的开始位置
  127. FBlockStartPos: Integer;
  128. function GetVSPane(Index: Integer): TCnVSPane;
  129. function GetVSPaneCount: Integer;
  130. protected
  131. // 重新设置获得焦点的组块的宽度
  132. procedure ResetActiveBlockWidth;
  133. procedure DeletePane(Index: Integer);
  134. property ActiveBlockWidth: Integer read FActiveBlockWidth write FActiveBlockWidth;
  135. property InactiveBlockWidth: Integer read FInactiveBlockWidth write FInactiveBlockWidth;
  136. property ActiveDockControl: TWinControl read FActiveDockControl write FActiveDockControl;
  137. property BlockType: TBlockType read FBlockType;
  138. property VSChannel: TCnVSChannel read FVSChannel;
  139. public
  140. constructor Create(Owner: TCnVSChannel); virtual;
  141. destructor Destroy; override;
  142. // 添加一个DockForm
  143. procedure AddDockControl(Control: TWinControl);
  144. // 删除一个DockForm
  145. procedure RemoveDockControl(Control: TWinControl);
  146. // 获得组块占用了多长的宽度
  147. function GetTotalWidth: Integer;
  148. property VSPaneCount: Integer read GetVSPaneCount;
  149. property VSPanes[Index: Integer]: TCnVSPane read GetVSPane;
  150. end;
  151. // TCnVSChannel显示的状态
  152. TVSChannelState = (csShow, csHide);
  153. // 动画的类型,分别是显示或者隐藏
  154. TPopupPanelAnimateStyle = (pasShow, pasHide);
  155. // 用来显示VS.NET风格当停靠客户隐藏的时候的沟
  156. TCnVSChannel = class(TCustomControl)
  157. private
  158. // 弹出的停靠窗体
  159. FActiveDockForm: TForm;
  160. // 获得焦点的面板
  161. FActivePane: TCnVSPane;
  162. // 和哪个TCnVSNETDockPanel对应
  163. FVSNETDockPanel: TCnVSNETDockPanel;
  164. // 用来指示当前遍历的组块的开始位置
  165. FCurrentPos: Integer;
  166. // VSChannel是属于哪一个TCnDockServer
  167. FDockServer: TCnDockServer;
  168. // 组块的列表
  169. FBlockList: TList;
  170. // 沟的宽度
  171. FChannelWidth: Integer;
  172. // 组块离Channel开始位置的距离
  173. FBlockStartOffset: Integer;
  174. // 组块离
  175. FBlockUpOffset: Integer;
  176. // 组块之间的间隔距离
  177. FBlockInterval: Integer;
  178. // 显示弹出的停靠窗体的容器
  179. FVSPopupPanel: TCnVSPopupPanel;
  180. // 容器的分割条
  181. FVSPopupPanelSplitter: TCnVSPopupPanelSplitter;
  182. // 获得焦点的Pane的最大值
  183. FActivePaneSize: Integer;
  184. function GetBlockCount: Integer;
  185. function GetBlocks(Index: Integer): TCnVSBlock;
  186. // 得到组块的大小,其中Block为组块,Index为组块中的索引,ARect为得到的矩形大小
  187. procedure GetBlockRect(Block: TCnVSBlock; Index: Integer; var ARect: TRect);
  188. // 根据鼠标的位置MousePos得到指定的停靠窗体
  189. function GetDockFormWithMousePos(MousePos: TPoint): TCnVSPane;
  190. procedure SetVSPopupPanelSplitter(const Value: TCnVSPopupPanelSplitter);
  191. procedure SetBlockStartOffset(const Value: Integer);
  192. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  193. procedure FreeBlockList;
  194. procedure SetActivePaneSize(const Value: Integer);
  195. protected
  196. { 重新设置字体的角度 }
  197. procedure ResetFontAngle; virtual;
  198. procedure ResetBlock; virtual;
  199. procedure Paint; override;
  200. procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  201. X, Y: Integer); override;
  202. procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  203. procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
  204. X, Y: Integer); override;
  205. procedure SetVSPopupPanelSplitterPosition;
  206. property ChannelWidth: Integer read FChannelWidth;
  207. property BlockStartOffset: Integer read FBlockStartOffset write SetBlockStartOffset;
  208. property BlockUpOffset: Integer read FBlockUpOffset;
  209. property BlockInterval: Integer read FBlockInterval;
  210. public
  211. constructor Create(AOwner: TComponent); override;
  212. destructor Destroy; override;
  213. { 根据输入的AControl查找到和他对应的TCnVSPane }
  214. function GetPaneWithControl(AControl: TControl): TCnVSPane;
  215. procedure CreateVSPopupPanel; // 创建弹出的停靠窗体的容器
  216. procedure DestroyVSPopupPanel; // 释放弹出的停靠窗体的容器
  217. procedure ResetPosition;
  218. // 添加一个DockForm
  219. procedure AddDockControl(Control: TWinControl);
  220. // 删除一个DockForm
  221. procedure RemoveDockControl(Control: TWinControl);
  222. // 查找一个DockForm,如果找到就返回它的索引,没有找到就返回-1
  223. function FindDockControl(Control: TWinControl; var BlockIndex: Integer;
  224. var PaneIndex: Integer): Boolean;
  225. function FindPane(Control: TWinControl): TCnVSPane;
  226. procedure PopupDockForm(Pane: TCnVSPane); overload; // 弹出停靠窗体
  227. procedure PopupDockForm(Control: TWinControl); overload; // 弹出停靠窗体
  228. procedure HidePopupPanel(Pane: TCnVSPane); overload; // 隐藏弹出的TCnVSPopupPanel
  229. procedure HidePopupPanel(Control: TWinControl); overload; // 隐藏弹出的TCnVSPopupPanel
  230. procedure HidePopupPanelWithAnimate(Pane: TCnVSPane); // 隐藏TCnVSPopupPanel并且伴随动画效果
  231. procedure ResetActivePaneWidth; // 重新设置获得焦点的面板的宽度
  232. procedure ResetPopupPanelHeight; // 重新设置弹出Panel的高度;
  233. procedure RemoveAllBlock;// 删除所有的Block
  234. procedure DeleteBlock(Index: Integer);
  235. procedure AnimatePopupPanel(AnimateStyle: TPopupPanelAnimateStyle);
  236. property DockServer: TCnDockServer read FDockServer write FDockServer;
  237. property BlockCount: Integer read GetBlockCount;
  238. property Blocks[Index: Integer]: TCnVSBlock read GetBlocks;
  239. property VSPopupPanel: TCnVSPopupPanel read FVSPopupPanel;
  240. property VSPopupPanelSplitter: TCnVSPopupPanelSplitter read FVSPopupPanelSplitter
  241. write SetVSPopupPanelSplitter;
  242. property ActiveDockForm: TForm read FActiveDockForm;
  243. property ActivePaneSize: Integer read FActivePaneSize write SetActivePaneSize;
  244. end;
  245. { TCnVSChannel 的类引用(类元) }
  246. TCnVSChannelClass = class of TCnVSChannel;
  247. TCnVSNETDockStyle = class(TCnVIDDockStyle)
  248. private
  249. FCnChannelOption: TCnVSNETChannelOption;
  250. FCnChannelOptionClass: TCnVSNETChannelOptionClass;
  251. procedure SetChannelOption(const Value: TCnVSNETChannelOption);
  252. function GetChannelOption: TCnVSNETChannelOption;
  253. // FCnVSChannelClass: TCnVSChannelClass;
  254. protected
  255. procedure GetComponentInfo(var AName, Author, Email, Comment: string); override;
  256. procedure CreateConjoinServerOption(var Option: TCnBasicConjoinServerOption); override;
  257. procedure CreateTabServerOption(var Option: TCnBasicTabServerOption); override;
  258. { 捕获TCnDockServer的WindowProc消息,如果要还要执行默认的消息处理就返回False,否则就返回True }
  259. function DockServerWindowProc(DockServer: TCnDockServer; var Message: TMessage): Boolean; override;
  260. { 捕获TCnDockClient的WindowProc消息,如果要还要执行默认的消息处理就返回False,否则就返回True }
  261. function DockClientWindowProc(DockClient: TCnDockClient; var Message: TMessage): Boolean; override;
  262. { ------------------------------------------------------------------------ }
  263. { 把ADockBaseControl添加到FDockBaseControlList中,
  264. 如果已经存在了就不插入,反之插入到列表的结尾处 }
  265. procedure AddDockBaseControl(ADockBaseControl: TCnDockBaseControl); override;
  266. procedure CreateServerOption; override;
  267. procedure FreeServerOption; override;
  268. public
  269. constructor Create(AOwner: TComponent); override;
  270. destructor Destroy; override;
  271. function GetControlName: string; override;
  272. { ------------------------------------------------------------------------ }
  273. { ShowDockForm和HideDockForm都调用这个方法, 用AVisible来判断是显示还是隐藏 }
  274. procedure SetDockFormVisible(ADockClient: TCnDockClient; AVisible: Boolean);
  275. procedure ShowDockForm(ADockClient: TCnDockClient); override;// 显示ADockClient中的ParentForm;
  276. procedure HideDockForm(ADockClient: TCnDockClient); override;// 隐藏ADockClient中的ParentForm;
  277. { 得到ADockClient中的ParentForm是否可见 }
  278. function GetDockFormVisible(ADockClient: TCnDockClient): Boolean; override;
  279. { 还原原先的客户的状态 }
  280. procedure RestoreClient(DockClient: TCnDockClient); override;
  281. // property CnVSChannelClass: TCnVSChannelClass read FCnVSChannelClass write FCnVSChannelClass;
  282. published
  283. property ChannelOption: TCnVSNETChannelOption read GetChannelOption write SetChannelOption;
  284. end;
  285. TCnVSNETDockSplitter = class(TCnVIDDockSplitter);
  286. TCnVSNETDockPanel = class(TCnVIDDockPanel)
  287. private
  288. FVSChannelClass: TCnVSChannelClass;
  289. FVSChannel: TCnVSChannel;
  290. protected
  291. procedure SetDockServer(const Value: TCnDockServer); override;
  292. procedure CustomDockDrop(Source: TCnDragDockObject; X, Y: Integer); override;
  293. procedure Resize; override;
  294. public
  295. constructor Create(AOwner: TComponent); override;
  296. destructor Destroy; override;
  297. procedure CreateVSChannel; // 创建和TCnVSNETDockPanel对应的VS.NET风格中的沟
  298. procedure DestroyVSChannel; // 释放和TCnVSNETDockPanel对应的VS.NET风格中的沟
  299. procedure DoAutoHideControl(Control: TWinControl);
  300. procedure DoHideControl(Control: TWinControl);
  301. procedure DoShowControl(Control: TWinControl);
  302. property VSChannel: TCnVSChannel read FVSChannel;
  303. end;
  304. { 在VS.NET中用来显示弹出的停靠窗体的容器 }
  305. TCnVSPopupPanel = class(TCnVSNETDockPanel)
  306. private
  307. FVSNETDockPanel: TCnVSNETDockPanel;
  308. procedure SetVSNETDockPanel(const Value: TCnVSNETDockPanel);
  309. function GetVSChannel: TCnVSChannel;
  310. protected
  311. function CreateDockManager: IDockManager; override;
  312. procedure SetParent(AParent: TWinControl); override;
  313. public
  314. constructor Create(AOwner: TComponent); override;
  315. destructor Destroy; override;
  316. procedure ShowDockPanel(MakeVisible: Boolean; Client: TControl;
  317. PanelSizeFrom: TSetDockPanelSizeFrom); override;
  318. property VSChannel: TCnVSChannel read GetVSChannel;
  319. property VSNETDockPanel: TCnVSNETDockPanel read FVSNETDockPanel
  320. write SetVSNETDockPanel;
  321. end;
  322. TCnVSNETConjoinPanel = class(TCnVIDConjoinPanel);
  323. { 按钮边框的状态,分别是凸起状态,正常状态,凹下状态 }
  324. TBtnState = (bsUp, bsNormal, bsDown);
  325. TCnVSNETDockZone = class(TCnVIDDockZone)
  326. private
  327. { 自动隐藏按钮是否被按下 }
  328. FAutoHideBtnDown: Boolean;
  329. { 自动隐藏按钮边框的状态 }
  330. FAutoHideBtnState: TBtnState;
  331. { 关闭按钮边框的状态 }
  332. FCloseBtnState: TBtnState;
  333. { 在VSChannel中的Pane是否是可见的 }
  334. FVSPaneVisible: Boolean;
  335. procedure SetAutoHideBtnState(const Value: TBtnState);
  336. procedure SetCloseBtnState(const Value: TBtnState);
  337. procedure SetAutoHideBtnDown(const Value: Boolean);
  338. procedure SetVSPaneVisible(const Value: Boolean);
  339. protected
  340. procedure DoCustomSetControlName; override;
  341. procedure SetChildControlVisible(Client: TControl; AViisible: Boolean); override;
  342. property AutoHideBtnDown: Boolean read FAutoHideBtnDown write SetAutoHideBtnDown;
  343. property AutoHideBtnState: TBtnState read FAutoHideBtnState write SetAutoHideBtnState;
  344. property CloseBtnState: TBtnState read FCloseBtnState write SetCloseBtnState;
  345. property VSPaneVisible: Boolean read FVSPaneVisible write SetVSPaneVisible;
  346. public
  347. constructor Create(Tree: TCnDockTree); override;
  348. end;
  349. TCnVSNETDockTree = class(TCnVIDDockTree)
  350. private
  351. FAutoHideZone: TCnVSNETDockZone;
  352. protected
  353. procedure IgnoreZoneInfor(Stream: TMemoryStream); override;
  354. procedure BeginDrag(Control: TControl;
  355. Immediate: Boolean; Threshold: Integer = -1); override;
  356. function DoLButtonDown(var Message: TWMMouse;
  357. var Zone: TCnDockZone; out HTFlag: Integer): Boolean; override;
  358. procedure DoLButtonUp(var Message: TWMMouse;
  359. var Zone: TCnDockZone; out HTFlag: Integer); override;
  360. procedure DoLButtonDbClk(var Message: TWMMouse;
  361. var Zone: TCnDockZone; out HTFlag: Integer); override;
  362. procedure DoMouseMove(var Message: TWMMouse;
  363. var Zone: TCnDockZone; out HTFlag: Integer); override;
  364. { 隐藏AZone中的ChildControl }
  365. procedure DoHideZoneChild(AZone: TCnDockZone); override;
  366. function GetTopGrabbersHTFlag(const MousePos: TPoint;
  367. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone; override;
  368. procedure DrawDockGrabber(Control: TControl; const ARect: TRect); override;
  369. procedure PaintDockGrabberRect(Canvas: TCanvas; Control: TControl;
  370. const ARect: TRect); override;
  371. procedure DrawCloseButton(Canvas: TCanvas; Zone: TCnDockZone;
  372. Left, Top: Integer); override;
  373. procedure DrawAutoHideButton(Zone: TCnDockZone;
  374. Left, Top: Integer); virtual;
  375. procedure GetCaptionRect(var Rect: TRect); override;
  376. { 其他的提示信息 }
  377. procedure DoOtherHint(Zone: TCnDockZone;
  378. HTFlag: Integer; var HintStr: string); override;
  379. procedure CustomSaveZone(Stream: TStream;
  380. Zone: TCnDockZone); override;
  381. procedure CustomLoadZone(Stream: TStream;
  382. var Zone: TCnDockZone); override;
  383. property AutoHideZone: TCnVSNETDockZone read FAutoHideZone
  384. write FAutoHideZone;
  385. public
  386. constructor Create(DockSite: TWinControl;
  387. CnDockZoneClass: TCnDockZoneClass); override;
  388. destructor Destroy; override;
  389. end;
  390. TCnVSNETDockTabSheet = class(TCnVIDDockTabSheet)
  391. private
  392. FOldVisible: Boolean;
  393. procedure SetOldVisible(const Value: Boolean);
  394. public
  395. constructor Create(AOwner: TComponent); override;
  396. property OldVisible: Boolean read FOldVisible write SetOldVisible;
  397. end;
  398. TCnVSNETTabPanel = class(TCnTabPanel)
  399. public
  400. constructor Create(AOwner: TComponent); override;
  401. end;
  402. TCnVSNETTabPageControl = class(TCnVIDTabPageControl)
  403. protected
  404. procedure CreatePanel; override;
  405. procedure ShowControl(AControl: TControl); override;
  406. public
  407. constructor Create(AOwner: TComponent); override;
  408. end;
  409. TCnVSNETDragDockObject = class(TCnVIDDragDockObject);
  410. TCnVSPopupPanelSplitter = class(TCustomControl)
  411. private
  412. FVSPopupPanel: TCnVSPopupPanel;
  413. FSplitWidth: Integer;
  414. FActiveControl: TWinControl;
  415. FAutoSnap: Boolean;
  416. FBeveled: Boolean;
  417. FBrush: TBrush;
  418. FControl: TControl;
  419. FDownPos: TPoint;
  420. FLineDC: HDC;
  421. FLineVisible: Boolean;
  422. FMinSize: NaturalNumber;
  423. FMaxSize: Integer;
  424. FNewSize: Integer;
  425. FOldKeyDown: TKeyEvent;
  426. FOldSize: Integer;
  427. FPrevBrush: HBrush;
  428. FResizeStyle: TResizeStyle;
  429. FSplit: Integer;
  430. FOnCanResize: TCanResizeEvent;
  431. FOnMoved: TNotifyEvent;
  432. FOnPaint: TNotifyEvent;
  433. procedure AllocateLineDC;
  434. procedure CalcSplitSize(X, Y: Integer; var NewSize, Split: Integer);
  435. procedure DrawLine;
  436. function FindControl: TControl;
  437. procedure FocusKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  438. procedure ReleaseLineDC;
  439. procedure SetBeveled(Value: Boolean);
  440. procedure UpdateControlSize;
  441. procedure UpdateSize(X, Y: Integer);
  442. procedure SetVSPopupPanel(const Value: TCnVSPopupPanel);
  443. function GetVSChannelAlign: TAlign;
  444. procedure SetSplitWidth(const Value: Integer);
  445. protected
  446. function CanResize(var NewSize: Integer): Boolean; reintroduce; virtual;
  447. function DoCanResize(var NewSize: Integer): Boolean; virtual;
  448. procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  449. X, Y: Integer); override;
  450. procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  451. procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
  452. X, Y: Integer); override;
  453. procedure Paint; override;
  454. procedure RequestAlign; override;
  455. procedure StopSizing; dynamic;
  456. public
  457. constructor Create(AOwner: TComponent); override;
  458. destructor Destroy; override;
  459. property Canvas;
  460. property VSPopupPanel: TCnVSPopupPanel read FVSPopupPanel write SetVSPopupPanel;
  461. property SplitWidth: Integer read FSplitWidth write SetSplitWidth;
  462. published
  463. property Align default alLeft;
  464. property VSChannelAlign: TAlign read GetVSChannelAlign;
  465. property AutoSnap: Boolean read FAutoSnap write FAutoSnap default True;
  466. property Beveled: Boolean read FBeveled write SetBeveled default False;
  467. property Color;
  468. property Constraints;
  469. property MinSize: NaturalNumber read FMinSize write FMinSize default 30;
  470. property ParentColor;
  471. property ResizeStyle: TResizeStyle read FResizeStyle write FResizeStyle
  472. default rsPattern;
  473. property Visible;
  474. property OnCanResize: TCanResizeEvent read FOnCanResize write FOnCanResize;
  475. property OnMoved: TNotifyEvent read FOnMoved write FOnMoved;
  476. property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
  477. end;
  478. // 隐藏所有的PopupPanel,但是不包括ExcludeChannel中的PopupPanel
  479. procedure HideAllPopupPanel(ExcludeChannel: TCnVSChannel);
  480. var
  481. { 默认的沟是nil }
  482. DefaultVSChannelClass: TCnVSChannelClass = nil;
  483. implementation
  484. uses SysUtils, CnDockSupportProc, CnDockGlobal, Dialogs, AppEvnts;
  485. type
  486. TAnimateState = (asPopup, asHide);
  487. TPopupPanelAnimate = class(TTimer)
  488. private
  489. FMaxWidth: Integer; // 最大的宽度
  490. FCurrentWidth: Integer; // 当前的宽度
  491. FVSChannel: TCnVSChannel; // 当前处理的TCnVSChannel
  492. FState: TAnimateState;
  493. protected
  494. procedure Timer; override;
  495. procedure OnCustomTimer(Sender: TObject);
  496. public
  497. constructor Create(AOwner: TComponent); override;
  498. destructor Destroy; override;
  499. procedure PopupForm(VSChannel: TCnVSChannel; MaxWidth: Integer); virtual;
  500. procedure HideForm(VSChannel: TCnVSChannel; MaxWidth: Integer); virtual;
  501. end;
  502. TCnAppEvents = class(TApplicationEvents)
  503. private
  504. FOldOnMessage: TMessageEvent;
  505. procedure NewOnMessage(var Msg: TMsg; var Handled: Boolean);
  506. public
  507. constructor Create(AOwner: TComponent); override;
  508. end;
  509. var
  510. PopupPanelAnimate: TPopupPanelAnimate;
  511. ApplicationEvents: TCnAppEvents;
  512. const
  513. { 弹出动画定时的间隔 }
  514. PopupPanelAnimateInterval: Integer = 10;
  515. { 弹出动画每次移动多少宽度 }
  516. PopupPanelAnimateMoveWidth: Integer = 30;
  517. { 弹出动画开始前的暂停时间 }
  518. //AnimateSleepTime: Integer = 500;
  519. // 隐藏所有的PopupPanel,但是不包括ExcludeChannel中的PopupPanel
  520. procedure HideAllPopupPanel(ExcludeChannel: TCnVSChannel);
  521. var i, j: Integer;
  522. Channel: TCnVSChannel;
  523. DockServer: TCnDockServer;
  524. begin
  525. // if ExcludeChannel = nil then Exit;
  526. for i := 0 to CnGlobalDockPresident.DockServersList.Count - 1 do
  527. begin
  528. DockServer := FindDockServer(CnGlobalDockPresident.DockServersList[i]);
  529. if (DockServer <> nil) and (DockServer.DockPanel[0] is TCnVSNETDockPanel) then
  530. for j := 0 to 3 do
  531. begin
  532. Channel := TCnVSNETDockPanel(DockServer.DockPanel[j]).VSChannel;
  533. if (Channel <> nil) and (Channel <> ExcludeChannel) then
  534. Channel.HidePopupPanel(Channel.FActivePane);
  535. end;
  536. end;
  537. end;
  538. // 重新设置Channel中的Block的开始位置
  539. procedure ResetChannelBlockStartOffset(Channel: TCnVSChannel);
  540. var i: Integer;
  541. LeftChannel: TCnVSChannel;
  542. CurrChannel: TCnVSChannel;
  543. OldOffset: Integer;
  544. LeftAlignArea: Integer;
  545. begin
  546. LeftChannel := TCnVSNETDockPanel(Channel.DockServer.LeftDockPanel).VSChannel;
  547. if (LeftChannel <> nil) then
  548. begin
  549. LeftAlignArea := GetClientAlignControlArea(LeftChannel.Parent, alLeft);
  550. for i := 0 to 3 do
  551. begin
  552. CurrChannel := TCnVSNETDockPanel(Channel.DockServer.DockPanel[i]).VSChannel;
  553. if (CurrChannel.Align in [alTop, alBottom]) then
  554. begin
  555. OldOffset := CurrChannel.BlockStartOffset;
  556. CurrChannel.BlockStartOffset := 2 + LeftAlignArea;
  557. if OldOffset <> CurrChannel.BlockStartOffset then
  558. CurrChannel.Invalidate;
  559. end;
  560. end;
  561. end;
  562. end;
  563. { TCnVSNETDockStyle }
  564. procedure TCnVSNETDockStyle.AddDockBaseControl(
  565. ADockBaseControl: TCnDockBaseControl);
  566. begin
  567. if ADockBaseControl = nil then Exit;
  568. if DockBaseControlList.IndexOf(ADockBaseControl) = -1 then
  569. begin
  570. inherited;
  571. ChannelOption.ResetDockControlOption;
  572. end;
  573. end;
  574. constructor TCnVSNETDockStyle.Create(AOwner: TComponent);
  575. begin
  576. inherited;
  577. CnDockPanelClass := TCnVSNETDockPanel;
  578. CnDockSplitterClass := TCnVSNETDockSplitter;
  579. CnConjoinPanelClass := TCnVSNETConjoinPanel;
  580. CnTabDockClass := TCnVSNETTabPageControl;
  581. CnDockPanelTreeClass := TCnVSNETDockTree;
  582. CnDockPanelZoneClass := TCnVSNETDockZone;
  583. CnConjoinPanelTreeClass := TCnVSNETDockTree;
  584. CnConjoinPanelZoneClass := TCnVSNETDockZone;
  585. CnConjoinServerOptionClass := TCnVSNETConjoinServerOption;
  586. CnTabServerOptionClass := TCnVSNETTabServerOption;
  587. FCnChannelOptionClass := TCnVSNETChannelOption;
  588. // CnVSChannelClass := TCnVSChannel;
  589. end;
  590. procedure TCnVSNETDockStyle.CreateConjoinServerOption(
  591. var Option: TCnBasicConjoinServerOption);
  592. begin
  593. Option := TCnVSNETConjoinServerOption.Create(Self);
  594. end;
  595. procedure TCnVSNETDockStyle.CreateServerOption;
  596. begin
  597. inherited;
  598. if FCnChannelOptionClass <> nil then
  599. FCnChannelOption := FCnChannelOptionClass.Create(Self);
  600. end;
  601. procedure TCnVSNETDockStyle.CreateTabServerOption(
  602. var Option: TCnBasicTabServerOption);
  603. begin
  604. Option := TCnVSNETTabServerOption.Create(Self);
  605. end;
  606. destructor TCnVSNETDockStyle.Destroy;
  607. begin
  608. inherited;
  609. end;
  610. function TCnVSNETDockStyle.DockClientWindowProc(DockClient: TCnDockClient;
  611. var Message: TMessage): Boolean;
  612. var Channel: TCnVSChannel;
  613. begin
  614. Result := inherited DockClientWindowProc(DockClient, Message);
  615. if (Message.Msg = CM_ENTER) or (Message.Msg = CM_EXIT){ or ((Message.Msg = WM_ACTIVATE){ and (Message.ResultLo = WA_INACTIVE))} then
  616. begin
  617. Channel := nil;
  618. if (DockClient.ParentForm.HostDockSite is TCnVSPopupPanel) then
  619. Channel := TCnVSPopupPanel(DockClient.ParentForm.HostDockSite).VSChannel
  620. else if DockClient.ParentForm.HostDockSite <> nil then
  621. begin
  622. if (DockClient.ParentForm.HostDockSite.Parent is TCnVSPopupPanel) then
  623. Channel := TCnVSPopupPanel(DockClient.ParentForm.HostDockSite.Parent).VSChannel
  624. else if (DockClient.ParentForm.HostDockSite.Parent <> nil)
  625. and (DockClient.ParentForm.HostDockSite.Parent.Parent is TCnVSPopupPanel) then
  626. Channel := TCnVSPopupPanel(DockClient.ParentForm.HostDockSite.Parent.Parent).VSChannel;
  627. end;
  628. if (Message.Msg = CM_EXIT){ or (Message.Msg = WM_ACTIVATE)} then
  629. begin
  630. if Channel <> nil then
  631. Channel.HidePopupPanelWithAnimate(Channel.FActivePane);
  632. end else if (Message.Msg = CM_ENTER) then
  633. begin
  634. HideAllPopupPanel(Channel);
  635. end;
  636. end;
  637. end;
  638. function TCnVSNETDockStyle.DockServerWindowProc(DockServer: TCnDockServer;
  639. var Message: TMessage): Boolean;
  640. var i: Integer;
  641. Channel: TCnVSChannel;
  642. begin
  643. Result := inherited DockServerWindowProc(DockServer, Message);
  644. if (Message.Msg = WM_SIZE){ or (Message.Msg = CM_EXIT) }then
  645. begin
  646. for i := 0 to 3 do
  647. begin
  648. Channel := nil;
  649. if DockServer.DockPanel[i] <> nil then
  650. Channel := TCnVSNETDockPanel(DockServer.DockPanel[i]).VSChannel;
  651. if Channel <> nil then
  652. Channel.HidePopupPanel(Channel.FActivePane);
  653. end;
  654. end;
  655. end;
  656. procedure TCnVSNETDockStyle.FreeServerOption;
  657. begin
  658. inherited;
  659. if FCnChannelOption <> nil then
  660. FCnChannelOption.Free;
  661. end;
  662. function TCnVSNETDockStyle.GetChannelOption: TCnVSNETChannelOption;
  663. begin
  664. Result := FCnChannelOption;
  665. end;
  666. procedure TCnVSNETDockStyle.GetComponentInfo(var AName, Author, Email,
  667. Comment: string);
  668. begin
  669. AName := SCnVSNETDockStyleName;
  670. Author := SCnPack_LuXiaoban;
  671. Email := SCnPack_LuXiaobanEmail;
  672. Comment := SCnVSNETDockStyleComment;
  673. end;
  674. function TCnVSNETDockStyle.GetControlName: string;
  675. begin
  676. Result := Format(gs_LikeVSNETStyle, [gs_CnDockStyleName]);
  677. end;
  678. function TCnVSNETDockStyle.GetDockFormVisible(
  679. ADockClient: TCnDockClient): Boolean;
  680. var VSChannel: TCnVSChannel;
  681. Pane: TCnVSPane;
  682. begin
  683. Result := True;
  684. if ADockClient <> nil then
  685. begin
  686. if not (ADockClient.ParentForm is TCnTabDockHostForm) and
  687. (ADockClient.ParentForm.HostDockSite is TCnVSPopupPanel) then
  688. begin
  689. // 是TCnVSChannel的平铺方式
  690. VSChannel := TCnVSPopupPanel(ADockClient.ParentForm.HostDockSite).VSChannel;
  691. if VSChannel <> nil then
  692. Pane := VSChannel.FindPane(ADockClient.ParentForm)
  693. else Pane := nil;
  694. if Pane <> nil then
  695. Result := Pane.Visible;
  696. end
  697. else if (ADockClient.ParentForm.HostDockSite <> nil) and (ADockClient.ParentForm.HostDockSite.Parent <> nil) and
  698. (ADockClient.ParentForm.HostDockSite.Parent.HostDockSite is TCnVSPopupPanel) then
  699. begin
  700. // 是TCnVSChannel的分页方式
  701. VSChannel := TCnVSPopupPanel(ADockClient.ParentForm.HostDockSite.Parent.HostDockSite).VSChannel;
  702. if VSChannel <> nil then
  703. Pane := VSChannel.FindPane(ADockClient.ParentForm)
  704. else Pane := nil;
  705. if Pane <> nil then
  706. Result := Pane.Visible;
  707. end else Result := inherited GetDockFormVisible(ADockClient);
  708. end;
  709. end;
  710. procedure TCnVSNETDockStyle.HideDockForm(ADockClient: TCnDockClient);
  711. begin
  712. inherited;
  713. SetDockFormVisible(ADockClient, False);
  714. end;
  715. procedure TCnVSNETDockStyle.RestoreClient(DockClient: TCnDockClient);
  716. begin
  717. { 如果当前的服务器是TCnCSPopupPanel,就不调用父类的ResetDockClient函数 }
  718. if (DockClient.ParentForm.HostDockSite is TCnVSPopupPanel) or
  719. ((DockClient.ParentForm.Parent <> nil) and (DockClient.ParentForm.Parent.HostDockSite is TCnVSPopupPanel)) then
  720. Exit;
  721. inherited;
  722. end;
  723. procedure TCnVSNETDockStyle.SetChannelOption(
  724. const Value: TCnVSNETChannelOption);
  725. begin
  726. FCnChannelOption.Assign(Value);
  727. end;
  728. procedure TCnVSNETDockStyle.SetDockFormVisible(ADockClient: TCnDockClient;
  729. AVisible: Boolean);
  730. var VSChannel: TCnVSChannel;
  731. Pane: TCnVSPane;
  732. { 重新设置激活的客户 }
  733. procedure ResetActiveControl;
  734. var i: Integer;
  735. begin
  736. if AVisible then
  737. // 如果是显示,当前的客户窗体就是激活的客户
  738. Pane.Block.ActiveDockControl := ADockClient.ParentForm
  739. else
  740. begin
  741. // 首先从当前索引向上查找到第一个,如果找到一个属性Visible为True的Pane,
  742. // 就把当前激活的客户设置为这个Pane的DockForm;
  743. for i := Pane.Index downto 0 do
  744. begin
  745. if Pane.Block.VSPanes[i].Visible then
  746. begin
  747. Pane.Block.ActiveDockControl := Pane.Block.VSPanes[i].DockForm;
  748. Exit;
  749. end;
  750. end;
  751. // 同上,只是搜索的方向不同.
  752. for i := Pane.Index + 1 to Pane.Block.VSPaneCount - 1 do
  753. begin
  754. if Pane.Block.VSPanes[i].Visible then
  755. begin
  756. Pane.Block.ActiveDockControl := Pane.Block.VSPanes[i].DockForm;
  757. Exit;
  758. end;
  759. end;
  760. end;
  761. end;
  762. begin
  763. if (ADockClient <> nil) then
  764. begin
  765. VSChannel := nil;
  766. if not (ADockClient.ParentForm is TCnTabDockHostForm) and
  767. (ADockClient.ParentForm.HostDockSite is TCnVSPopupPanel) then
  768. begin
  769. // 平铺方式
  770. VSChannel := TCnVSPopupPanel(ADockClient.ParentForm.HostDockSite).VSChannel;
  771. if VSChannel <> nil then
  772. Pane := VSChannel.FindPane(ADockClient.ParentForm)
  773. else Pane := nil;
  774. Pane := VSChannel.FindPane(ADockClient.ParentForm);
  775. if Pane <> nil then
  776. begin
  777. Pane.Visible := AVisible;
  778. ResetActiveControl;
  779. end;
  780. end else if (ADockClient.ParentForm.HostDockSite <> nil) and (ADockClient.ParentForm.HostDockSite.Parent <> nil) and
  781. (ADockClient.ParentForm.HostDockSite.Parent.HostDockSite is TCnVSPopupPanel) then
  782. begin
  783. // 分页方式
  784. VSChannel := TCnVSPopupPanel(ADockClient.ParentForm.HostDockSite.Parent.HostDockSite).VSChannel;
  785. if VSChannel <> nil then
  786. Pane := VSChannel.FindPane(ADockClient.ParentForm)
  787. else Pane := nil;
  788. Pane := VSChannel.FindPane(ADockClient.ParentForm);
  789. if Pane <> nil then
  790. begin
  791. Pane.Visible := AVisible;
  792. ResetActiveControl;
  793. TCnVSNETDockTabSheet(ADockClient.ParentForm.Parent).OldVisible := AVisible;
  794. end;
  795. end;
  796. if VSChannel <> nil then
  797. begin
  798. VSChannel.ResetPosition;
  799. VSChannel.Invalidate;
  800. end;
  801. end;
  802. end;
  803. procedure TCnVSNETDockStyle.ShowDockForm(ADockClient: TCnDockClient);
  804. begin
  805. inherited;
  806. SetDockFormVisible(ADockClient, True);
  807. end;
  808. { TCnVSNETDockTree }
  809. procedure TCnVSNETDockTree.BeginDrag(Control: TControl; Immediate: Boolean;
  810. Threshold: Integer);
  811. begin
  812. // 如果是弹出Panel就不处理
  813. if not (DockSite is TCnVSPopupPanel) then
  814. inherited;
  815. end;
  816. constructor TCnVSNETDockTree.Create(DockSite: TWinControl;
  817. CnDockZoneClass: TCnDockZoneClass);
  818. begin
  819. inherited;
  820. GrabberSize := DefaultVSNETGrabberSize;
  821. ButtonHeight := 12;
  822. ButtonWidth := 16;
  823. LeftOffset := 2;
  824. RightOffset := 3;
  825. TopOffset := 4;
  826. BottomOffset := 3;
  827. ButtonSplitter := 2;
  828. CaptionLeftOffset := 5;
  829. CaptionRightOffset := 5;
  830. end;
  831. procedure TCnVSNETDockTree.CustomLoadZone(Stream: TStream;
  832. var Zone: TCnDockZone);
  833. var Pane: TCnVSPane;
  834. i: Integer;
  835. procedure SetPaneVisible(ChildControl: TControl; VSPaneVisible: Boolean);
  836. var DockClient: TCnDockClient;
  837. begin
  838. if (Pane <> nil) then
  839. begin
  840. Pane.Visible := VSPaneVisible;
  841. DockClient := FindDockClient(Pane.DockForm);
  842. if DockClient <> nil then
  843. begin
  844. if Pane.Visible then
  845. begin
  846. DockClient.ParentVisible := False;
  847. DockClient.ParentForm.Visible := True;
  848. DockClient.MakeShowEvent;
  849. end
  850. else
  851. DockClient.MakeHideEvent;
  852. end;
  853. end;
  854. end;
  855. var Sheet: TCnVSNETDockTabSheet;
  856. begin
  857. inherited CustomLoadZone(Stream, Zone);
  858. Stream.Read(TCnVSNETDockZone(Zone).FVSPaneVisible, SizeOf(TCnVSNETDockZone(Zone).VSPaneVisible));
  859. if DockSite is TCnVSPopupPanel then
  860. begin
  861. With TCnVSPopupPanel(DockSite).VSChannel, TCnVSNETDockZone(Zone) do
  862. begin
  863. if ChildControl is TCnTabDockHostForm then
  864. begin
  865. for i := 0 to TCnTabDockHostForm(ChildControl).PageControl.PageCount - 1 do
  866. begin
  867. Sheet := TCnVSNETDockTabSheet(TCnTabDockHostForm(ChildControl).PageControl.Pages[i]);
  868. Pane := FindPane(TWinControl(Sheet.Controls[0]));
  869. SetPaneVisible(ChildControl, Sheet.OldVisible);
  870. end;
  871. end
  872. else
  873. begin
  874. Pane := FindPane(ChildControl);
  875. SetPaneVisible(ChildControl, VSPaneVisible);
  876. end;
  877. ResetPosition;
  878. end;
  879. end;
  880. end;
  881. procedure TCnVSNETDockTree.CustomSaveZone(Stream: TStream;
  882. Zone: TCnDockZone);
  883. var Pane: TCnVSPane;
  884. begin
  885. inherited CustomSaveZone(Stream, Zone);
  886. if DockSite is TCnVSPopupPanel then
  887. begin
  888. With TCnVSPopupPanel(DockSite).VSChannel, TCnVSNETDockZone(Zone) do
  889. begin
  890. Pane := FindPane(ChildControl);
  891. if (Pane <> nil) then
  892. VSPaneVisible := Pane.Visible;
  893. end;
  894. end;
  895. Stream.Write(TCnVSNETDockZone(Zone).VSPaneVisible, SizeOf(TCnVSNETDockZone(Zone).VSPaneVisible));
  896. end;
  897. destructor TCnVSNETDockTree.Destroy;
  898. begin
  899. inherited;
  900. end;
  901. function TCnVSNETDockTree.DoLButtonDown(var Message: TWMMouse;
  902. var Zone: TCnDockZone; out HTFlag: Integer): Boolean;
  903. begin
  904. Result := inherited DoLButtonDown(Message, Zone, HTFlag);
  905. if (Zone <> nil) then
  906. begin
  907. if (HTFlag = HTCLOSE) then
  908. TCnVSNETDockZone(Zone).CloseBtnState := bsDown
  909. else if HTFlag = HTAUTOHIDE then
  910. begin
  911. AutoHideZone := TCnVSNETDockZone(Zone);
  912. AutoHideZone.AutoHideBtnDown := True;
  913. AutoHideZone.AutoHideBtnState := bsDown;
  914. end;
  915. end;
  916. end;
  917. procedure TCnVSNETDockTree.DoLButtonUp(var Message: TWMMouse;
  918. var Zone: TCnDockZone; out HTFlag: Integer);
  919. begin
  920. if CloseBtnZone <> nil then
  921. begin
  922. TCnVSNETDockZone(CloseBtnZone).CloseBtnState := bsNormal;
  923. end;
  924. inherited;
  925. if (AutoHideZone <> nil) then
  926. begin
  927. AutoHideZone.AutoHideBtnDown := False;
  928. AutoHideZone.AutoHideBtnState := bsNormal;
  929. if HTFlag = HTAUTOHIDE then
  930. begin
  931. if DockSite is TCnVSNETDockPanel then
  932. TCnVSNETDockPanel(DockSite).DoAutoHideControl(AutoHideZone.ChildControl);
  933. end;
  934. AutoHideZone := nil;
  935. end;
  936. end;
  937. procedure TCnVSNETDockTree.DoMouseMove(var Message: TWMMouse;
  938. var Zone: TCnDockZone; out HTFlag: Integer);
  939. var
  940. AZone: TCnVSNETDockZone;
  941. begin
  942. inherited;
  943. if Zone <> nil then
  944. begin
  945. AZone := TCnVSNETDockZone(Zone);
  946. if AZone.AutoHideBtnDown then
  947. begin
  948. if HTFlag = HTAUTOHIDE then
  949. AZone.AutoHideBtnState := bsDown
  950. else
  951. AZone.AutoHideBtnState := bsUp;
  952. end else if (HTFlag = HTAUTOHIDE) and not AZone.CloseBtnDown then
  953. AZone.AutoHideBtnState := bsUp
  954. else
  955. AZone.AutoHideBtnState := bsNormal;
  956. if AZone.CloseBtnDown then
  957. begin
  958. if HTFlag = HTCLOSE then
  959. AZone.CloseBtnState := bsDown
  960. else AZone.CloseBtnState := bsUp;
  961. end else if (HTFlag = HTCLOSE) and not AZone.AutoHideBtnDown then
  962. AZone.CloseBtnState := bsUp
  963. else
  964. AZone.CloseBtnState := bsNormal;
  965. end;
  966. end;
  967. procedure TCnVSNETDockTree.DoOtherHint(Zone: TCnDockZone; HTFlag: Integer;
  968. var HintStr: string);
  969. begin
  970. inherited;
  971. if (HTFlag = HTAUTOHIDE) then
  972. HintStr := gs_CnVSNETDockTreeAutoHideBtnHint;
  973. end;
  974. procedure TCnVSNETDockTree.DrawAutoHideButton(
  975. Zone: TCnDockZone; Left, Top: Integer);
  976. var
  977. AZone: TCnVSNETDockZone;
  978. ColorArr: array[1..2] of TColor;
  979. begin
  980. if Zone <> nil then
  981. begin
  982. AZone := TCnVSNETDockZone(Zone);
  983. { 画自动隐藏按钮的边框 }
  984. if AZone.AutoHideBtnState <> bsNormal then
  985. begin
  986. if AZone.AutoHideBtnState = bsUp then
  987. begin
  988. ColorArr[1] := clBlack;
  989. if GetActiveControl = AZone.ChildControl then
  990. ColorArr[2] := clBtnface
  991. else ColorArr[2] := clWhite;
  992. end else if AZone.AutoHideBtnState = bsDown then
  993. begin
  994. ColorArr[1] := clBtnface;
  995. ColorArr[2] := clBlack;
  996. end;
  997. Canvas.Pen.Color := ColorArr[1];
  998. Canvas.MoveTo(Left, Top + ButtonHeight);
  999. Canvas.LineTo(Left + ButtonWidth, Top + ButtonHeight);
  1000. Canvas.LineTo(Left + ButtonWidth, Top);
  1001. Canvas.Pen.Color := ColorArr[2];
  1002. Canvas.LineTo(Left, Top);
  1003. Canvas.LineTo(Left, Top + ButtonHeight);
  1004. end;
  1005. { 如果自动隐藏按钮是按下的,图钉的位置就要向右下角移动一个象素的单位 }
  1006. if AZone.AutoHideBtnState = bsDown then
  1007. begin
  1008. Inc(Left);
  1009. Inc(Top);
  1010. end;
  1011. { 画自动隐藏按钮的图钉 }
  1012. if AZone.ChildControl = GetActiveControl then
  1013. Canvas.Pen.Color := clWhite
  1014. else
  1015. Canvas.Pen.Color := clBlack;
  1016. if DockSite.Align in [alLeft, alRight, alTop, alBottom] then
  1017. begin
  1018. Canvas.MoveTo(Left + 9, Top + 10);
  1019. Canvas.LineTo(Left + 9, Top + 7);
  1020. Canvas.MoveTo(Left + 6, Top + 7);
  1021. Canvas.LineTo(Left + 13, Top + 7);
  1022. Canvas.MoveTo(Left + 7, Top + 6);
  1023. Canvas.LineTo(Left + 7, Top + 2);
  1024. Canvas.LineTo(Left + 10, Top + 2);
  1025. Canvas.LineTo(Left + 10, Top + 6);
  1026. Canvas.LineTo(Left + 11, Top + 6);
  1027. Canvas.LineTo(Left + 11, Top + 1);
  1028. end else if DockSite.Align in [alNone] then
  1029. begin
  1030. Canvas.MoveTo(Left + 5, Top + 6);
  1031. Canvas.LineTo(Left + 8, Top + 6);
  1032. Canvas.MoveTo(Left + 8, Top + 3);
  1033. Canvas.LineTo(Left + 8, Top + 10);
  1034. Canvas.MoveTo(Left + 9, Top + 4);
  1035. Canvas.LineTo(Left + 12, Top + 4);
  1036. Canvas.LineTo(Left + 12, Top + 7);
  1037. Canvas.LineTo(Left + 9, Top + 7);
  1038. Canvas.LineTo(Left + 9, Top + 8);
  1039. Canvas.LineTo(Left + 13, Top + 8);
  1040. end;
  1041. end;
  1042. end;
  1043. procedure TCnVSNETDockTree.DrawCloseButton(Canvas: TCanvas;
  1044. Zone: TCnDockZone; Left, Top: Integer);
  1045. var DrawRect: TRect;
  1046. AZone: TCnVSNETDockZone;
  1047. ColorArr: array[1..2] of TColor;
  1048. ADockClient: TCnDockClient;
  1049. AForm: TForm;
  1050. begin
  1051. if Zone <> nil then
  1052. begin
  1053. { 如果EnableCloseBtn属性为False,就不画关闭按钮 }
  1054. ADockClient := FindDockClient(Zone.ChildControl);
  1055. if (ADockClient <> nil) and (not ADockClient.EnableCloseBtn) then Exit;
  1056. if Zone.ChildControl is TCnTabDockHostForm then
  1057. begin
  1058. AForm := TCnTabDockHostForm(Zone.ChildControl).GetActiveDockForm;
  1059. if AForm <> nil then
  1060. begin
  1061. ADockClient := FindDockClient(AForm);
  1062. if (ADockClient <> nil) and (not ADockClient.EnableCloseBtn) then
  1063. Exit;
  1064. end;
  1065. end;
  1066. AZone := TCnVSNETDockZone(Zone);
  1067. { 得到所要画图的区域的大小 }
  1068. DrawRect.Left := Left + 6;
  1069. DrawRect.Right := DrawRect.Left + 7;
  1070. DrawRect.Top := Top + 3;
  1071. DrawRect.Bottom := DrawRect.Top + 7;
  1072. { 画关闭按钮的边框 }
  1073. if AZone.CloseBtnState <> bsNormal then
  1074. begin
  1075. if AZone.CloseBtnState = bsUp then
  1076. begin
  1077. ColorArr[1] := clBlack;
  1078. if GetActiveControl = AZone.ChildControl then
  1079. ColorArr[2] := clBtnface
  1080. else ColorArr[2] := clWhite;
  1081. end else if AZone.CloseBtnState = bsDown then
  1082. begin
  1083. ColorArr[1] := clBtnface;
  1084. ColorArr[2] := clBlack;
  1085. end;
  1086. Canvas.Pen.Color := ColorArr[1];
  1087. Canvas.MoveTo(Left, Top + ButtonHeight);
  1088. Canvas.LineTo(Left + ButtonWidth, Top + ButtonHeight);
  1089. Canvas.LineTo(Left + ButtonWidth, Top);
  1090. Canvas.Pen.Color := ColorArr[2];
  1091. Canvas.LineTo(Left, Top);
  1092. Canvas.LineTo(Left, Top + ButtonHeight);
  1093. end;
  1094. { 如果关闭按钮是按下的,X的位置就要向右下角移动一个象素的单位 }
  1095. if AZone.CloseBtnState = bsDown then
  1096. OffsetRect(DrawRect, 1, 1);
  1097. { 画关闭按钮的X }
  1098. if AZone.ChildControl = GetActiveControl then
  1099. Canvas.Pen.Color := clWhite
  1100. else
  1101. Canvas.Pen.Color := clBlack;
  1102. Canvas.MoveTo(DrawRect.Left, DrawRect.Top);
  1103. Canvas.LineTo(DrawRect.Right, DrawRect.Bottom);
  1104. Canvas.MoveTo(DrawRect.Right-1, DrawRect.Top);
  1105. Canvas.LineTo(DrawRect.Left-1, DrawRect.Bottom);
  1106. end;
  1107. end;
  1108. procedure TCnVSNETDockTree.GetCaptionRect(var Rect: TRect);
  1109. begin
  1110. if DockSite.Align = alClient then
  1111. inherited
  1112. else
  1113. begin
  1114. Inc(Rect.Left, 2 + CaptionLeftOffset);
  1115. Inc(Rect.Top, 3);
  1116. Dec(Rect.Right, 2*ButtonWidth + ButtonSplitter + CaptionRightOffset - 1);
  1117. Dec(Rect.Bottom, 2);
  1118. end;
  1119. end;
  1120. function TCnVSNETDockTree.GetTopGrabbersHTFlag(const MousePos: TPoint;
  1121. out HTFlag: Integer; Zone: TCnDockZone): TCnDockZone;
  1122. begin
  1123. Result := inherited GetTopGrabbersHTFlag(MousePos, HTFlag, Zone);
  1124. if (Zone <> nil) and (DockSite.Align <> alClient) and (HTFlag <> HTCLOSE) then
  1125. begin
  1126. with Zone.ChildControl do
  1127. if PtInRect(Rect(
  1128. Left + Width - 2*ButtonWidth - RightOffset - ButtonSplitter,
  1129. Top - GrabberSize + TopOffset,
  1130. Left + Width - ButtonWidth - RightOffset - ButtonSplitter,
  1131. Top - GrabberSize + TopOffset + ButtonHeight), MousePos) then
  1132. HTFlag := HTAUTOHIDE;
  1133. end;
  1134. end;
  1135. procedure TCnVSNETDockTree.DrawDockGrabber(
  1136. Control: TControl; const ARect: TRect);
  1137. begin
  1138. inherited;
  1139. if DockSite.Align <> alClient then
  1140. DrawAutoHideButton(FindControlZone(Control), ARect.Right-RightOffset-2*ButtonWidth-ButtonSplitter, ARect.Top+TopOffset);
  1141. end;
  1142. procedure TCnVSNETDockTree.PaintDockGrabberRect(Canvas: TCanvas;
  1143. Control: TControl; const ARect: TRect);
  1144. var DrawRect: TRect;
  1145. begin
  1146. inherited;
  1147. if GetActiveControl <> Control then
  1148. begin
  1149. Canvas.Pen.Color := clGray;
  1150. DrawRect := ARect;
  1151. Inc(DrawRect.Left);
  1152. Canvas.RoundRect(DrawRect.Left, DrawRect.Top, DrawRect.Right, DrawRect.Bottom, 2, 2);
  1153. end;
  1154. end;
  1155. procedure TCnVSNETDockTree.DoLButtonDbClk(var Message: TWMMouse;
  1156. var Zone: TCnDockZone; out HTFlag: Integer);
  1157. begin
  1158. if DockSite is TCnVSPopupPanel then Exit;
  1159. inherited;
  1160. end;
  1161. procedure TCnVSNETDockTree.DoHideZoneChild(AZone: TCnDockZone);
  1162. var AForm: TForm;
  1163. ADockClient: TCnDockClient;
  1164. begin
  1165. { 根据AZone的ChildControl中的值来判断是否关闭当前的客户窗体 }
  1166. if (AZone <> nil) and (AZone.ChildControl <> nil) then
  1167. begin
  1168. if AZone.ChildControl is TCnTabDockHostForm then
  1169. begin
  1170. AForm := TCnTabDockHostForm(AZone.ChildControl).GetActiveDockForm;
  1171. if AForm <> nil then
  1172. begin
  1173. ADockClient := FindDockClient(AForm);
  1174. if (ADockClient <> nil) and (not ADockClient.EnableCloseBtn) then
  1175. Exit else
  1176. AForm.Close;
  1177. end;
  1178. end else inherited;
  1179. end;
  1180. end;
  1181. procedure TCnVSNETDockTree.IgnoreZoneInfor(Stream: TMemoryStream);
  1182. begin
  1183. inherited;
  1184. Stream.Position := Stream.Position + 1;
  1185. end;
  1186. { TCnVSNETConjoinServerOption }
  1187. constructor TCnVSNETConjoinServerOption.Create(
  1188. ADockStyle: TCnBasicDockStyle);
  1189. begin
  1190. inherited;
  1191. SystemInfo := True;
  1192. end;
  1193. destructor TCnVSNETConjoinServerOption.Destroy;
  1194. begin
  1195. inherited;
  1196. end;
  1197. procedure TCnVSNETConjoinServerOption.SetDefaultSystemCaptionInfo;
  1198. begin
  1199. inherited;
  1200. { 默认的获得焦点时的字体颜色是白色 }
  1201. ActiveFont.Color := clWhite;
  1202. ActiveFont.Style := [];
  1203. { 默认的获得焦点时的字体颜色是黑色 }
  1204. InactiveFont.Color := clBlack;
  1205. InactiveFont.Style := [];
  1206. SetActiveTitleEndColor_WithoutChangeSystemInfo(ActiveTitleStartColor);
  1207. SetInactiveTitleStartColor_WithoutChangeSystemInfo(clBtnFace);
  1208. SetInactiveTitleEndColor_WithoutChangeSystemInfo(clBtnFace);
  1209. // SetGrabbersSize_WithoutChangeSystemInfo(19);
  1210. end;
  1211. { TCnVSNETTabServerOption }
  1212. constructor TCnVSNETTabServerOption.Create(ADockStyle: TCnBasicDockStyle);
  1213. begin
  1214. inherited;
  1215. InactiveFont.Color := VSNETPageInactiveFontColor;
  1216. InactiveSheetColor := VSNETPageInactiveSheetColor;
  1217. ShowTabImages := True;
  1218. end;
  1219. { TCnVSNETDockZone }
  1220. constructor TCnVSNETDockZone.Create(Tree: TCnDockTree);
  1221. begin
  1222. inherited;
  1223. FAutoHideBtnState := bsNormal;
  1224. FCloseBtnState := bsNormal;
  1225. FVSPaneVisible := True;
  1226. end;
  1227. procedure TCnVSNETDockZone.DoCustomSetControlName;
  1228. var i: Integer;
  1229. Pane: TCnVSPane;
  1230. DockClient: TCnDockClient;
  1231. begin
  1232. inherited;
  1233. if Tree.DockSite is TCnVSPopupPanel then
  1234. begin
  1235. With TCnVSPopupPanel(Tree.DockSite).VSChannel do
  1236. begin
  1237. AddDockControl(ChildControl);
  1238. if ChildControl is TCnTabDockHostForm then
  1239. begin
  1240. With TCnTabDockHostForm(ChildControl).PageControl do
  1241. begin
  1242. for i := 0 to DockClientCount - 1 do
  1243. begin
  1244. Pane := FindPane(TWinControl(DockClients[i]));
  1245. DockClient := FindDockClient(DockClients[i]);
  1246. if (Pane <> nil) and (DockClient <> nil) then
  1247. begin
  1248. Pane.Width := DockClient.VSPaneWidth;
  1249. end;
  1250. end;
  1251. end;
  1252. end else
  1253. begin
  1254. Pane := FindPane(ChildControl);
  1255. DockClient := FindDockClient(ChildControl);
  1256. if (Pane <> nil) and (DockClient <> nil) then
  1257. begin
  1258. Pane.Width := DockClient.VSPaneWidth;
  1259. end;
  1260. end;
  1261. end;
  1262. end;
  1263. end;
  1264. procedure TCnVSNETDockZone.SetAutoHideBtnDown(const Value: Boolean);
  1265. begin
  1266. FAutoHideBtnDown := Value;
  1267. end;
  1268. procedure TCnVSNETDockZone.SetAutoHideBtnState(const Value: TBtnState);
  1269. begin
  1270. if FAutoHideBtnState <> Value then
  1271. begin
  1272. FAutoHideBtnState := Value;
  1273. Tree.DockSite.Invalidate;
  1274. end;
  1275. end;
  1276. procedure TCnVSNETDockZone.SetChildControlVisible(Client: TControl;
  1277. AViisible: Boolean);
  1278. //var VSChannel: TCnVSChannel;
  1279. // Pane: TCnVSPane;
  1280. begin
  1281. inherited;
  1282. { if Tree.DockSite is TCnVSPopupPanel then
  1283. begin
  1284. VSChannel := TCnVSPopupPanel(Tree.DockSite).VSChannel;
  1285. Pane := VSChannel.FindPane(TWinControl(Client));
  1286. if Pane <> nil then
  1287. Pane.Visible := AViisible;
  1288. end;}
  1289. end;
  1290. procedure TCnVSNETDockZone.SetCloseBtnState(const Value: TBtnState);
  1291. begin
  1292. if FCloseBtnState <> Value then
  1293. begin
  1294. FCloseBtnState := Value;
  1295. Tree.DockSite.Invalidate;
  1296. end;
  1297. end;
  1298. procedure TCnVSNETDockZone.SetVSPaneVisible(const Value: Boolean);
  1299. begin
  1300. FVSPaneVisible := Value;
  1301. end;
  1302. { TCnVSNETTabPanel }
  1303. constructor TCnVSNETTabPanel.Create(AOwner: TComponent);
  1304. begin
  1305. inherited Create(AOwner);
  1306. TabHeight := 25;
  1307. CaptionTopOffset := 1;
  1308. end;
  1309. { TCnVSNETTabPageControl }
  1310. constructor TCnVSNETTabPageControl.Create(AOwner: TComponent);
  1311. begin
  1312. inherited;
  1313. CnDockTabSheetClass := TCnVSNETDockTabSheet;
  1314. CnTabPanelClass := TCnVSNETTabPanel;
  1315. end;
  1316. procedure TCnVSNETTabPageControl.CreatePanel;
  1317. begin
  1318. inherited;
  1319. end;
  1320. procedure TCnVSNETTabPageControl.ShowControl(AControl: TControl);
  1321. begin
  1322. inherited;
  1323. end;
  1324. { TCnVSChannel }
  1325. procedure TCnVSChannel.AddDockControl(Control: TWinControl);
  1326. var Block: TCnVSBlock;
  1327. begin
  1328. if Control is TCnTabDockHostForm then
  1329. begin
  1330. Block := TCnVSBlock.Create(Self);
  1331. Block.AddDockControl(Control);
  1332. FBlockList.Add(Block);
  1333. end else
  1334. begin
  1335. if (BlockCount >= 1) and (Blocks[0].BlockType = btConjoinBlock) then
  1336. begin
  1337. Blocks[0].AddDockControl(Control);
  1338. end else
  1339. begin
  1340. Block := TCnVSBlock.Create(Self);
  1341. Block.AddDockControl(Control);
  1342. FBlockList.Insert(0, Block);
  1343. end;
  1344. end;
  1345. HideAllPopupPanel(Self);
  1346. ResetPosition;
  1347. Invalidate;
  1348. end;
  1349. constructor TCnVSChannel.Create(AOwner: TComponent);
  1350. begin
  1351. inherited;
  1352. if AOwner is TCnVSNETDockPanel then
  1353. begin
  1354. FVSNETDockPanel := TCnVSNETDockPanel(AOwner);
  1355. DockServer := FVSNETDockPanel.DockServer;
  1356. end;
  1357. FBlockList := TList.Create;
  1358. FChannelWidth := 22;
  1359. FBlockStartOffset := 2;
  1360. FBlockUpOffset := 2;
  1361. FBlockInterval := 13;
  1362. Color := VSNETPageInactiveSheetColor;
  1363. ParentFont := True;
  1364. ActivePaneSize := MaxActivePaneWidth;
  1365. end;
  1366. procedure TCnVSChannel.CreateVSPopupPanel;
  1367. begin
  1368. FVSPopupPanel := TCnVSPopupPanel.Create(FVSNETDockPanel);
  1369. FVSPopupPanel.Name := FVSNETDockPanel.Name + '_PopupPanel';
  1370. FVSPopupPanel.Visible := False;
  1371. if Parent is TForm then
  1372. begin
  1373. FVSPopupPanel.Parent := Parent;
  1374. FVSPopupPanel.Align := alNone;
  1375. FVSPopupPanel.BringToFront;
  1376. end;
  1377. FVSPopupPanelSplitter := TCnVSPopupPanelSplitter.Create(Parent);
  1378. if Parent is TForm then
  1379. begin
  1380. FVSPopupPanelSplitter.Parent := Parent;
  1381. FVSPopupPanelSplitter.Align := alNone;
  1382. FVSPopupPanelSplitter.VSPopupPanel := VSPopupPanel;
  1383. FVSPopupPanelSplitter.Color := clBtnface;
  1384. FVSPopupPanelSplitter.Visible := False;
  1385. end;
  1386. end;
  1387. procedure TCnVSChannel.DeleteBlock(Index: Integer);
  1388. begin
  1389. Blocks[Index].Free;
  1390. FBlockList.Delete(Index);
  1391. end;
  1392. destructor TCnVSChannel.Destroy;
  1393. begin
  1394. FreeBlockList;
  1395. inherited;
  1396. end;
  1397. procedure TCnVSChannel.DestroyVSPopupPanel;
  1398. begin
  1399. end;
  1400. function TCnVSChannel.FindDockControl(Control: TWinControl; var BlockIndex: Integer;
  1401. var PaneIndex: Integer): Boolean;
  1402. var i, j: Integer;
  1403. begin
  1404. Result := False;
  1405. BlockIndex := -1;
  1406. PaneIndex := -1;
  1407. if Control = nil then Exit;
  1408. for i := 0 to BlockCount - 1 do
  1409. begin
  1410. for j := 0 to Blocks[i].VSPaneCount - 1 do
  1411. if Blocks[i].VSPanes[j].DockForm = Control then
  1412. begin
  1413. BlockIndex := i;
  1414. PaneIndex := j;
  1415. Result := True;
  1416. Exit;
  1417. end;
  1418. if Blocks[i].FBlockType = btTabBlock then
  1419. begin
  1420. j := 0;
  1421. if Blocks[i].VSPanes[0].DockForm.HostDockSite.Parent = Control then
  1422. begin
  1423. BlockIndex := i;
  1424. PaneIndex := j;
  1425. Result := True;
  1426. Exit;
  1427. end;
  1428. end;
  1429. end;
  1430. end;
  1431. function TCnVSChannel.GetBlockCount: Integer;
  1432. begin
  1433. Result := FBlockList.Count;
  1434. end;
  1435. procedure TCnVSChannel.GetBlockRect(Block: TCnVSBlock; Index: Integer;
  1436. var ARect: TRect);
  1437. var BlockWidth: Integer;
  1438. begin
  1439. if Block.VSPanes[Index].DockForm <> Block.FActiveDockControl then
  1440. BlockWidth := Block.InactiveBlockWidth
  1441. else
  1442. BlockWidth := Block.ActiveBlockWidth;
  1443. { 首先得到画图的区域 }
  1444. case Align of
  1445. alLeft:
  1446. begin
  1447. ARect.Left := -1;
  1448. ARect.Top := FCurrentPos;
  1449. ARect.Right := Width - FBlockUpOffset;
  1450. ARect.Bottom := ARect.Top + BlockWidth;
  1451. end;
  1452. alRight:
  1453. begin
  1454. ARect.Left := FBlockUpOffset;
  1455. ARect.Top := FCurrentPos;
  1456. ARect.Right := Width + 1;
  1457. ARect.Bottom := ARect.Top + BlockWidth;
  1458. end;
  1459. alTop:
  1460. begin
  1461. ARect.Left := FCurrentPos;
  1462. ARect.Top := -1;
  1463. ARect.Right := ARect.Left + BlockWidth;
  1464. ARect.Bottom := Height - FBlockUpOffset;
  1465. end;
  1466. alBottom:
  1467. begin
  1468. ARect.Left := FCurrentPos;
  1469. ARect.Top := FBlockUpOffset;
  1470. ARect.Right := ARect.Left + BlockWidth;
  1471. ARect.Bottom := Height + 1;
  1472. end;
  1473. end;
  1474. { 移动位置 }
  1475. Inc(FCurrentPos, BlockWidth - 1);
  1476. end;
  1477. function TCnVSChannel.GetBlocks(Index: Integer): TCnVSBlock;
  1478. begin
  1479. Result := TCnVSBlock(FBlockList[Index]);
  1480. end;
  1481. function TCnVSChannel.GetDockFormWithMousePos(MousePos: TPoint): TCnVSPane;
  1482. var i, j: Integer;
  1483. ARect: TRect;
  1484. begin
  1485. Result := nil;
  1486. FCurrentPos := FBlockStartOffset;
  1487. for i := 0 to BlockCount - 1 do
  1488. begin
  1489. for j := 0 to Blocks[i].VSPaneCount - 1 do
  1490. begin
  1491. if not Blocks[i].VSPanes[j].Visible then Continue;
  1492. GetBlockRect(Blocks[i], j, ARect);
  1493. if PtInRect(ARect, MousePos) then
  1494. begin
  1495. Result := Blocks[i].VSPanes[j];
  1496. Exit;
  1497. end;
  1498. end;
  1499. Inc(FCurrentPos, FBlockInterval);
  1500. end;
  1501. end;
  1502. procedure TCnVSChannel.HidePopupPanel(Pane: TCnVSPane);
  1503. begin
  1504. if Pane <> nil then
  1505. begin
  1506. if Align in [alLeft, alRight] then
  1507. begin
  1508. VSPopupPanel.Width := 0;
  1509. VSPopupPanelSplitter.Width := 0;
  1510. end
  1511. else if Align in [alTop, alBottom] then
  1512. begin
  1513. VSPopupPanel.Height := 0;
  1514. VSPopupPanelSplitter.Height := 0;
  1515. end;
  1516. FActiveDockForm := nil;
  1517. FActivePane := nil;
  1518. end;
  1519. VSPopupPanel.Visible := False;
  1520. VSPopupPanelSplitter.Visible := False;
  1521. FActivePane := nil;
  1522. end;
  1523. procedure TCnVSChannel.MouseDown(Button: TMouseButton; Shift: TShiftState;
  1524. X, Y: Integer);
  1525. var VSPane: TCnVSPane;
  1526. begin
  1527. inherited;
  1528. VSPane := GetDockFormWithMousePos(Point(X, Y));
  1529. if VSPane <> nil then
  1530. begin
  1531. VSPane.Active := True;
  1532. if VSPane.DockForm.CanFocus then
  1533. VSPane.DockForm.SetFocus;
  1534. end;
  1535. end;
  1536. procedure TCnVSChannel.MouseMove(Shift: TShiftState; X, Y: Integer);
  1537. begin
  1538. inherited;
  1539. PopupDockForm(GetDockFormWithMousePos(Point(X, Y)));
  1540. end;
  1541. procedure TCnVSChannel.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  1542. Y: Integer);
  1543. begin
  1544. inherited;
  1545. end;
  1546. procedure TCnVSChannel.Paint;
  1547. procedure DrawSingleBlock(Block: TCnVSBlock);
  1548. var DrawRect: TRect;
  1549. i: Integer;
  1550. { 调整需要重画的图象的位置 }
  1551. procedure AdjustImagePos;
  1552. begin
  1553. if Align = alLeft then
  1554. begin
  1555. Inc(DrawRect.Left, 3);
  1556. Inc(DrawRect.Top, 4);
  1557. end else if Align = alTop then
  1558. begin
  1559. Inc(DrawRect.Left, 4);
  1560. Inc(DrawRect.Top, 2);
  1561. end else
  1562. if Align = alRight then
  1563. begin
  1564. Inc(DrawRect.Left, 4);
  1565. Inc(DrawRect.Top, 4);
  1566. end else if Align = alBottom then
  1567. begin
  1568. Inc(DrawRect.Left, 4);
  1569. Inc(DrawRect.Top, 3);
  1570. end;
  1571. end;
  1572. var OldGraphicsMode: Integer;
  1573. VisiblePaneCount: Integer;
  1574. begin
  1575. VisiblePaneCount := 0;
  1576. for i := 0 to Block.VSPaneCount - 1 do
  1577. begin
  1578. if not Block.VSPanes[i].Visible then Continue;
  1579. // 得到当前区块的大小
  1580. GetBlockRect(Block, i, DrawRect);
  1581. { 画一个矩形 }
  1582. Canvas.Brush.Color := clBtnFace;
  1583. Canvas.FillRect(DrawRect);
  1584. Canvas.Brush.Color := clGray;
  1585. Canvas.FrameRect(DrawRect);
  1586. { 画图标 }
  1587. AdjustImagePos;
  1588. Block.FImageList.Draw(Canvas, DrawRect.Left, DrawRect.Top, i);
  1589. { 画文字 }
  1590. if Block.ActiveDockControl = Block.VSPanes[i].DockForm then
  1591. begin
  1592. if Align in [alTop, alBottom] then
  1593. Inc(DrawRect.Left, Block.InactiveBlockWidth)
  1594. else if Align in [alLeft, alRight] then
  1595. begin
  1596. Inc(DrawRect.Top, Block.InactiveBlockWidth);
  1597. if Align = alLeft then
  1598. DrawRect.Left := 15
  1599. else DrawRect.Left := 20;
  1600. DrawRect.Right := DrawRect.Left + (DrawRect.Bottom - DrawRect.Top);
  1601. end;
  1602. Canvas.Brush.Color := clBtnFace;
  1603. Canvas.Pen.Color := clBlack;
  1604. Dec(DrawRect.Right, 3);
  1605. OldGraphicsMode := SetGraphicsMode(Canvas.Handle, GM_ADVANCED);
  1606. DrawText(Canvas.Handle, PChar(Block.VSPanes[i].DockForm.Caption), -1, DrawRect, DT_END_ELLIPSIS or DT_NOCLIP);
  1607. SetGraphicsMode(Canvas.Handle, OldGraphicsMode);
  1608. end;
  1609. Inc(VisiblePaneCount);
  1610. end;
  1611. if VisiblePaneCount > 0 then
  1612. Inc(FCurrentPos, FBlockInterval);
  1613. end;
  1614. var i: Integer;
  1615. begin
  1616. inherited;
  1617. { 开始位置 }
  1618. FCurrentPos := FBlockStartOffset;
  1619. for i := 0 to BlockCount - 1 do
  1620. begin
  1621. DrawSingleBlock(Blocks[i]);
  1622. end;
  1623. end;
  1624. procedure TCnVSChannel.PopupDockForm(Pane: TCnVSPane);
  1625. procedure SetSingleDockFormVisible(HostDockSite: TWinControl; AForm: TForm);
  1626. var i: Integer;
  1627. begin
  1628. for i := 0 to HostDockSite.DockClientCount - 1 do
  1629. HostDockSite.DockClients[i].Visible := AForm = HostDockSite.DockClients[i];
  1630. end;
  1631. begin
  1632. if (Pane <> nil) and (ActiveDockForm <> Pane.DockForm) then
  1633. begin
  1634. HidePopupPanel(FActivePane);
  1635. Pane.DockForm.Visible := True;
  1636. PopupPanelAnimate.PopupForm(Self, Pane.Width);
  1637. if (Pane.DockForm <> nil) and (Pane.DockForm.HostDockSite.Parent is TCnTabDockHostForm) then
  1638. begin
  1639. FVSPopupPanel.CnDockManager.ShowSingleControl(Pane.DockForm.HostDockSite.Parent);
  1640. SetSingleDockFormVisible(Pane.DockForm.HostDockSite, Pane.DockForm);
  1641. // 如果是分页方式,就需要改变Caption的值为选中的停靠窗体的Caption
  1642. TCnTabDockHostForm(Pane.DockForm.HostDockSite.Parent).Caption := Pane.DockForm.Caption;
  1643. end
  1644. else
  1645. FVSPopupPanel.CnDockManager.ShowSingleControl(Pane.DockForm);
  1646. FActiveDockForm := Pane.DockForm;
  1647. FActivePane := Pane;
  1648. FVSPopupPanel.CnDockManager.ResetBounds(True);
  1649. // 重新设置FActiveDockControl为当前选中的停靠窗体
  1650. Pane.Block.FActiveDockControl := Pane.DockForm;
  1651. Invalidate;
  1652. end;
  1653. end;
  1654. procedure TCnVSChannel.RemoveDockControl(Control: TWinControl);
  1655. var BlockIndex, PaneIndex: Integer;
  1656. begin
  1657. VSPopupPanel.Visible := False;
  1658. if FindDockControl(Control, BlockIndex, PaneIndex) then
  1659. begin
  1660. Blocks[BlockIndex].DeletePane(PaneIndex);
  1661. if (Blocks[BlockIndex].VSPaneCount <= 0) or (Blocks[BlockIndex].FBlockType = btTabBlock) then
  1662. DeleteBlock(BlockIndex);
  1663. end;
  1664. ResetPosition;
  1665. Invalidate;
  1666. end;
  1667. procedure TCnVSChannel.ResetBlock;
  1668. var i: Integer;
  1669. begin
  1670. if BlockCount > 0 then
  1671. begin
  1672. Blocks[0].FBlockStartPos := FBlockStartOffset;
  1673. for i := 1 to BlockCount - 1 do
  1674. Blocks[i].FBlockStartPos := Blocks[i - 1].FBlockStartPos + Blocks[i - 1].GetTotalWidth + FBlockInterval;
  1675. end;
  1676. end;
  1677. procedure TCnVSChannel.ResetPosition;
  1678. var i, j: Integer;
  1679. PaneCount: Integer;
  1680. begin
  1681. PaneCount := 0;
  1682. for i := 0 to BlockCount - 1 do
  1683. for j := 0 to Blocks[i].VSPaneCount - 1 do
  1684. if Blocks[i].VSPanes[j].Visible then
  1685. Inc(PaneCount);
  1686. { 调整VSChannel的位置,使它总是在服务窗体的客户区的最内层 }
  1687. Visible := PaneCount > 0;
  1688. case Align of
  1689. alLeft:
  1690. begin
  1691. Width := FChannelWidth;
  1692. Left := GetClientAlignControlArea(Parent, Align, Self);
  1693. end;
  1694. alRight:
  1695. begin
  1696. Width := FChannelWidth;
  1697. Left := Parent.ClientWidth - GetClientAlignControlArea(Parent, Align, Self) - FChannelWidth + 1;
  1698. end;
  1699. alTop:
  1700. begin
  1701. Height := FChannelWidth;
  1702. Top := GetClientAlignControlArea(Parent, Align, Self);
  1703. end;
  1704. alBottom:
  1705. begin
  1706. Height := FChannelWidth;
  1707. Top := Parent.ClientHeight - GetClientAlignControlArea(Parent, Align, Self) - FChannelWidth + 1;
  1708. end;
  1709. end;
  1710. end;
  1711. procedure TCnVSChannel.SetVSPopupPanelSplitterPosition;
  1712. begin
  1713. case Align of
  1714. alLeft:
  1715. begin
  1716. VSPopupPanelSplitter.Left := VSPopupPanel.Left + VSPopupPanel.Width;
  1717. VSPopupPanelSplitter.Width := VSPopupPanelSplitter.SplitWidth;
  1718. VSPopupPanelSplitter.Top := VSPopupPanel.Top;
  1719. VSPopupPanelSplitter.Height := VSPopupPanel.Height;
  1720. end;
  1721. alRight:
  1722. begin
  1723. VSPopupPanelSplitter.Left := VSPopupPanel.Left - VSPopupPanelSplitter.SplitWidth;
  1724. VSPopupPanelSplitter.Width := VSPopupPanelSplitter.SplitWidth;
  1725. VSPopupPanelSplitter.Top := VSPopupPanel.Top;
  1726. VSPopupPanelSplitter.Height := VSPopupPanel.Height;
  1727. end;
  1728. alTop:
  1729. begin
  1730. VSPopupPanelSplitter.Left := VSPopupPanel.Left;
  1731. VSPopupPanelSplitter.Width := VSPopupPanel.Width;
  1732. VSPopupPanelSplitter.Top := VSPopupPanel.Top + VSPopupPanel.Height;
  1733. VSPopupPanelSplitter.Height := VSPopupPanelSplitter.SplitWidth;
  1734. end;
  1735. alBottom:
  1736. begin
  1737. VSPopupPanelSplitter.Left := VSPopupPanel.Left;
  1738. VSPopupPanelSplitter.Width := VSPopupPanel.Width;
  1739. VSPopupPanelSplitter.Top := VSPopupPanel.Top - VSPopupPanelSplitter.SplitWidth;
  1740. VSPopupPanelSplitter.Height := VSPopupPanelSplitter.SplitWidth;
  1741. end;
  1742. end;
  1743. VSPopupPanelSplitter.Visible := True;
  1744. VSPopupPanelSplitter.BringToFront;
  1745. end;
  1746. procedure TCnVSChannel.SetVSPopupPanelSplitter(
  1747. const Value: TCnVSPopupPanelSplitter);
  1748. begin
  1749. FVSPopupPanelSplitter := Value;
  1750. end;
  1751. function TCnVSChannel.GetPaneWithControl(AControl: TControl): TCnVSPane;
  1752. var i, j: Integer;
  1753. begin
  1754. Result := nil;
  1755. for i := 0 to BlockCount - 1 do
  1756. for j := 0 to Blocks[i].VSPaneCount - 1 do
  1757. if AControl = Blocks[i].VSPanes[j].DockForm then
  1758. begin
  1759. Result := Blocks[i].VSPanes[j];
  1760. Exit;
  1761. end;
  1762. end;
  1763. procedure TCnVSChannel.SetBlockStartOffset(const Value: Integer);
  1764. begin
  1765. FBlockStartOffset := Value;
  1766. end;
  1767. procedure TCnVSChannel.AnimatePopupPanel(
  1768. AnimateStyle: TPopupPanelAnimateStyle);
  1769. begin
  1770. if AnimateStyle = pasShow then
  1771. begin
  1772. end else if AnimateStyle = pasHide then
  1773. begin
  1774. end;
  1775. end;
  1776. procedure TCnVSChannel.ResetFontAngle;
  1777. var
  1778. LogFont: TLogFont;
  1779. begin
  1780. if Align in [alLeft, alRight] then
  1781. begin
  1782. if GetObject(Canvas.Font.Handle, SizeOf(LogFont), @LogFont) <> 0 then
  1783. begin
  1784. LogFont.lfEscapement := 2700;
  1785. LogFont.lfOrientation := 2700;
  1786. Canvas.Font.Handle := CreateFontIndirect(LogFont);
  1787. end;
  1788. end;
  1789. end;
  1790. procedure TCnVSChannel.RemoveAllBlock;
  1791. var i: Integer;
  1792. begin
  1793. for i := BlockCount - 1 downto 0 do
  1794. DeleteBlock(i);
  1795. FActiveDockForm := nil;
  1796. end;
  1797. procedure TCnVSChannel.HidePopupPanel(Control: TWinControl);
  1798. var BlockIndex, PaneIndex: Integer;
  1799. begin
  1800. FindDockControl(Control, BlockIndex, PaneIndex);
  1801. if (BlockIndex >= 0) and (PaneIndex >= 0) then
  1802. HidePopupPanel(Blocks[BlockIndex].VSPanes[PaneIndex]);
  1803. end;
  1804. procedure TCnVSChannel.PopupDockForm(Control: TWinControl);
  1805. var BlockIndex, PaneIndex: Integer;
  1806. begin
  1807. FindDockControl(Control, BlockIndex, PaneIndex);
  1808. if (BlockIndex >= 0) and (PaneIndex >= 0) then
  1809. PopupDockForm(Blocks[BlockIndex].VSPanes[PaneIndex]);
  1810. end;
  1811. function TCnVSChannel.FindPane(Control: TWinControl): TCnVSPane;
  1812. var i, j: Integer;
  1813. begin
  1814. Result := nil;
  1815. if FindDockControl(Control, i, j) then
  1816. Result := Blocks[i].VSPanes[j];
  1817. end;
  1818. procedure TCnVSChannel.HidePopupPanelWithAnimate(Pane: TCnVSPane);
  1819. begin
  1820. if Pane <> nil then
  1821. PopupPanelAnimate.HideForm(Self, Pane.Width);
  1822. end;
  1823. procedure TCnVSChannel.CMMouseLeave(var Message: TMessage);
  1824. begin
  1825. inherited;
  1826. end;
  1827. procedure TCnVSChannel.ResetActivePaneWidth;
  1828. var DockClient: TCnDockClient;
  1829. begin
  1830. if FActivePane = nil then Exit;
  1831. DockClient := FindDockClient(FActivePane.DockForm);
  1832. if Align in [alLeft, alRight] then
  1833. begin
  1834. FActivePane.Width := VSPopupPanel.Width;
  1835. end
  1836. else if Align in [alTop, alBottom] then
  1837. begin
  1838. FActivePane.Width := VSPopupPanel.Height + VSPopupPanel.CnDockManager.GrabberSize;
  1839. end;
  1840. if DockClient <> nil then
  1841. DockClient.VSPaneWidth := FActivePane.Width;
  1842. end;
  1843. procedure TCnVSChannel.ResetPopupPanelHeight;
  1844. begin
  1845. if Align in [alLeft, alRight] then
  1846. begin
  1847. VSPopupPanel.Top := Top;
  1848. VSPopupPanel.Height := Height;
  1849. VSPopupPanelSplitter.Top := Top;
  1850. VSPopupPanelSplitter.Height := Height;
  1851. end;
  1852. end;
  1853. procedure TCnVSChannel.FreeBlockList;
  1854. var i: Integer;
  1855. begin
  1856. for i := 0 to FBlockList.Count - 1 do
  1857. Blocks[i].Free;
  1858. FBlockList.Free;
  1859. end;
  1860. procedure TCnVSChannel.SetActivePaneSize(const Value: Integer);
  1861. begin
  1862. if FActivePaneSize <> Value then
  1863. begin
  1864. FActivePaneSize := Value;
  1865. Invalidate;
  1866. end;
  1867. end;
  1868. { TCnVSBlock }
  1869. procedure TCnVSBlock.AddDockControl(Control: TWinControl);
  1870. function GetPaneWidth: Integer;
  1871. begin
  1872. Result := 100;
  1873. if Control = nil then Exit;
  1874. case VSChannel.Align of
  1875. alLeft, alRight:
  1876. Result := Control.Width;
  1877. alTop, alBottom:
  1878. Result := Control.Height;
  1879. end;
  1880. end;
  1881. var i, PaneWidth: Integer;
  1882. Icon: TIcon;
  1883. DockClient: TCnDockClient;
  1884. begin
  1885. PaneWidth := GetPaneWidth;
  1886. if Control is TCnTabDockHostForm then
  1887. begin
  1888. FBlockType := btTabBlock;
  1889. with TCnTabDockHostForm(Control) do
  1890. begin
  1891. for i := 0 to DockableControl.DockClientCount - 1 do
  1892. begin
  1893. FVSPaneList.Add(TCnVSPane.Create(Self, TForm(PageControl.DockClients[i]), PaneWidth, FVSPaneList.Count));
  1894. if not IsLoading then
  1895. begin
  1896. DockClient := FindDockClient(PageControl.DockClients[i]);
  1897. if DockClient <> nil then
  1898. DockClient.VSPaneWidth := PaneWidth;
  1899. end;
  1900. if TForm(PageControl.DockClients[i]).Icon = nil then
  1901. begin
  1902. Icon := TIcon.Create;
  1903. Icon.Width := 16;
  1904. Icon.Height := 16;
  1905. FImageList.AddIcon(Icon);
  1906. Icon.Free;
  1907. end
  1908. else
  1909. FImageList.AddIcon(TForm(PageControl.DockClients[i]).Icon);
  1910. TCnVSNETDockTabSheet(PageControl.Pages[i]).OldVisible := PageControl.DockClients[i].Visible;
  1911. if PageControl.Pages[i] <> PageControl.ActivePage then
  1912. PageControl.DockClients[i].Visible := False;
  1913. end;
  1914. for i := 0 to VSPaneCount - 1 do
  1915. begin
  1916. if VSPanes[i].Visible then
  1917. begin
  1918. FActiveDockControl := VSPanes[i].DockForm;
  1919. Break;
  1920. end;
  1921. end;
  1922. end;
  1923. end else
  1924. begin
  1925. FBlockType := btConjoinBlock;
  1926. FVSPaneList.Add(TCnVSPane.Create(Self, TForm(Control), PaneWidth, FVSPaneList.Count));
  1927. if not IsLoading then
  1928. begin
  1929. DockClient := FindDockClient(Control);
  1930. if DockClient <> nil then
  1931. DockClient.VSPaneWidth := PaneWidth;
  1932. end;
  1933. if TForm(Control).Icon = nil then
  1934. begin
  1935. Icon := TIcon.Create;
  1936. Icon.Width := 16;
  1937. Icon.Height := 16;
  1938. FImageList.AddIcon(Icon);
  1939. Icon.Free;
  1940. end else
  1941. FImageList.AddIcon(TForm(Control).Icon);
  1942. FActiveDockControl := Control;
  1943. end;
  1944. ResetActiveBlockWidth;
  1945. end;
  1946. constructor TCnVSBlock.Create(Owner: TCnVSChannel);
  1947. begin
  1948. FVSChannel := Owner;
  1949. FVSPaneList := TList.Create;
  1950. FImageList := TImageList.CreateSize(16, 16);
  1951. FInactiveBlockWidth := 24;
  1952. FActiveBlockWidth := 24;
  1953. end;
  1954. destructor TCnVSBlock.Destroy;
  1955. var i: Integer;
  1956. begin
  1957. FImageList.Free;
  1958. for i := 0 to VSPaneCount - 1 do
  1959. VSPanes[i].Free;
  1960. FVSPaneList.Free;
  1961. inherited;
  1962. end;
  1963. function TCnVSBlock.GetVSPane(Index: Integer): TCnVSPane;
  1964. begin
  1965. Result := TCnVSPane(FVSPaneList[Index]);
  1966. end;
  1967. function TCnVSBlock.GetVSPaneCount: Integer;
  1968. begin
  1969. Result := FVSPaneList.Count;
  1970. end;
  1971. function TCnVSBlock.GetTotalWidth: Integer;
  1972. begin
  1973. Result := (FVSPaneList.Count - 1) * FInactiveBlockWidth + FActiveBlockWidth;
  1974. end;
  1975. procedure TCnVSBlock.RemoveDockControl(Control: TWinControl);
  1976. begin
  1977. ResetActiveBlockWidth;
  1978. end;
  1979. procedure TCnVSBlock.ResetActiveBlockWidth;
  1980. var i: Integer;
  1981. begin
  1982. for i := 0 to VSPaneCount - 1 do
  1983. begin
  1984. FActiveBlockWidth := Max(FActiveBlockWidth, min(VSChannel.ActivePaneSize,
  1985. TForm(VSChannel.Parent).Canvas.TextWidth(VSPanes[i].DockForm.Caption) + InactiveBlockWidth + 10));
  1986. end;
  1987. end;
  1988. procedure TCnVSBlock.DeletePane(Index: Integer);
  1989. var i: Integer;
  1990. begin
  1991. for i := Index to FVSPaneList.Count - 2 do
  1992. VSPanes[i+1].Index := VSPanes[i].Index;
  1993. VSPanes[Index].Free;
  1994. FVSPaneList.Delete(Index);
  1995. end;
  1996. { TCnVSNETDockPanel }
  1997. constructor TCnVSNETDockPanel.Create(AOwner: TComponent);
  1998. begin
  1999. inherited;
  2000. FVSChannelClass := TCnVSChannel;
  2001. end;
  2002. procedure TCnVSNETDockPanel.CreateVSChannel;
  2003. begin
  2004. if (FVSChannelClass <> nil) and
  2005. (FVSChannelClass <> TCnVSChannelClass(ClassType)) then
  2006. begin
  2007. FVSChannel := FVSChannelClass.Create(Self);
  2008. FVSChannel.Parent := Parent;
  2009. FVSChannel.Align := Align;
  2010. // 重新设置字体的角度
  2011. FVSChannel.ResetFontAngle;
  2012. // 重新设置位置
  2013. FVSChannel.ResetPosition;
  2014. // 刚开始创建的时候就要把它隐藏
  2015. FVSChannel.Visible := False;
  2016. // 设置它的名称
  2017. FVSChannel.Name := Name + '_VSChannel';
  2018. // 创建TCnVSPopupPanel
  2019. FVSChannel.CreateVSPopupPanel;
  2020. end;
  2021. end;
  2022. procedure TCnVSNETDockPanel.CustomDockDrop(Source: TCnDragDockObject; X,
  2023. Y: Integer);
  2024. begin
  2025. inherited;
  2026. VSChannel.ActiveDockForm.Perform(CM_EXIT, 0, 0);
  2027. end;
  2028. destructor TCnVSNETDockPanel.Destroy;
  2029. begin
  2030. inherited;
  2031. end;
  2032. procedure TCnVSNETDockPanel.DestroyVSChannel;
  2033. begin
  2034. end;
  2035. procedure TCnVSNETDockPanel.DoAutoHideControl(Control: TWinControl);
  2036. //var
  2037. // ADockClient: TCnDockClient;
  2038. // ADockServer: TCnDockServer;
  2039. // Panel: TCnVSNETDockPanel;
  2040. begin
  2041. { 必须是能够符合停靠条件的才行 }
  2042. (* if self is TCnVSPopupPanel then
  2043. begin
  2044. Panel := TCnVSPopupPanel(self).FVSNETDockPanel;
  2045. ADockClient := FindDockClient(Control);
  2046. if ADockClient <> nil then
  2047. begin
  2048. with ADockClient, Panel do
  2049. begin
  2050. { 对于停靠客户 }
  2051. if (not ADockClient.EnableDock) or
  2052. ((not LeftDock) and (Align = alLeft)) or
  2053. ((not RightDock) and (Align = alRight)) or
  2054. ((not TopDock) and (Align = alTop)) or
  2055. ((not BottomDock) and (Align = alBottom)) then
  2056. Exit;
  2057. { 对于停靠服务器 }
  2058. ADockServer := DockServer;
  2059. if ADockServer <> nil then
  2060. if (not ADockServer.EnableDock) or
  2061. ((not ADockServer.LeftDock) and (Align = alLeft)) or
  2062. ((not ADockServer.RightDock) and (Align = alRight)) or
  2063. ((not ADockServer.TopDock) and (Align = alTop)) or
  2064. ((not ADockServer.BottomDock) and (Align = alBottom)) then
  2065. Exit;
  2066. end;
  2067. end;
  2068. end;*)
  2069. if Align = alNone then
  2070. DoShowControl(Control)
  2071. else
  2072. DoHideControl(Control);
  2073. end;
  2074. procedure TCnVSNETDockPanel.DoHideControl(Control: TWinControl);
  2075. begin
  2076. VSChannel.AddDockControl(Control);
  2077. ShowDockPanel(VisibleDockClientCount > 1, Control, sdfDockPanel);
  2078. Control.Dock(VSChannel.VSPopupPanel, Rect(0, 0, 0, 0));
  2079. VSChannel.VSPopupPanel.CnDockManager.InsertControl(Control, alNone, nil);
  2080. VSChannel.VSPopupPanel.CnDockManager.ShowSingleControl(Control);
  2081. CnDockManager.HideControl(Control);
  2082. ResetChannelBlockStartOffset(VSChannel);
  2083. end;
  2084. procedure TCnVSNETDockPanel.DoShowControl(Control: TWinControl);
  2085. var Panel: TCnVSNETDockPanel;
  2086. // 重新设置停靠窗体的Visible
  2087. procedure ResetDockFormVisible;
  2088. var i: Integer;
  2089. begin
  2090. if Control is TCnTabDockHostForm then
  2091. begin
  2092. with TCnTabDockHostForm(Control) do
  2093. for i := 0 to PageControl.PageCount - 1 do
  2094. begin
  2095. PageControl.Pages[i].Visible := TCnVSNETDockTabSheet(PageControl.Pages[i]).OldVisible;
  2096. PageControl.Pages[i].Controls[0].Visible := PageControl.Pages[i].Visible;
  2097. end;
  2098. end;
  2099. end;
  2100. begin
  2101. if self is TCnVSPopupPanel then
  2102. begin
  2103. Panel := TCnVSPopupPanel(self).FVSNETDockPanel;
  2104. Control.Dock(Panel, Rect(0, 0, 0, 0));
  2105. Panel.CnDockManager.ShowControl(Control);
  2106. CnDockManager.RemoveControl(Control);
  2107. Panel.VSChannel.RemoveDockControl(Control);
  2108. Panel.ShowDockPanel(Panel.VisibleDockClientCount > 0, Control, sdfDockPanel);
  2109. if (Panel.VSChannel.ActiveDockForm <> nil) and Panel.VSChannel.ActiveDockForm.CanFocus then
  2110. Panel.VSChannel.ActiveDockForm.SetFocus;
  2111. Panel.VSChannel.HidePopupPanel(Panel.VSChannel.FActivePane);
  2112. ResetDockFormVisible;
  2113. ResetChannelBlockStartOffset(Panel.VSChannel);
  2114. end;
  2115. end;
  2116. procedure TCnVSNETDockPanel.Resize;
  2117. begin
  2118. inherited;
  2119. if Align in [alTop, alBottom] then
  2120. begin
  2121. TCnVSNETDockPanel(DockServer.DockPanelWithAlign[alleft]).VSChannel.ResetPopupPanelHeight;
  2122. TCnVSNETDockPanel(DockServer.DockPanelWithAlign[alRight]).VSChannel.ResetPopupPanelHeight;
  2123. end;
  2124. end;
  2125. procedure TCnVSNETDockPanel.SetDockServer(const Value: TCnDockServer);
  2126. begin
  2127. inherited;
  2128. if not (Self is TCnVSPopupPanel) then
  2129. CreateVSChannel;
  2130. end;
  2131. { TCnVSPane }
  2132. constructor TCnVSPane.Create(ABlock: TCnVSBlock; AForm: TForm; AWidth: Integer; AIndex: Integer);
  2133. begin
  2134. Block := ABlock;
  2135. DockForm := AForm;
  2136. Width := AWidth;
  2137. Active := False;
  2138. Index := AIndex;
  2139. Visible := AForm.Visible;
  2140. end;
  2141. destructor TCnVSPane.Destroy;
  2142. begin
  2143. inherited;
  2144. end;
  2145. { TCnVSPopupPanel }
  2146. constructor TCnVSPopupPanel.Create(AOwner: TComponent);
  2147. begin
  2148. inherited;
  2149. DockSite := True;
  2150. if AOwner is TCnVSNETDockPanel then
  2151. begin
  2152. FVSNETDockPanel := TCnVSNETDockPanel(AOwner);
  2153. FVSChannel := FVSNETDockPanel.VSChannel;
  2154. DockServer := FVSNETDockPanel.DockServer;
  2155. end;
  2156. Anchors := [akLeft, akRight, akTop, akBottom];
  2157. BoundsRect := Rect(0, 0, 0, 0);
  2158. end;
  2159. function TCnVSPopupPanel.CreateDockManager: IDockManager;
  2160. begin
  2161. if (DockManager = nil) and DockSite and UseDockManager then
  2162. Result := TCnVSNETDockTree.Create(
  2163. Self, TCnVSNETDockZone) as ICnDockManager
  2164. else Result := DockManager;
  2165. end;
  2166. destructor TCnVSPopupPanel.Destroy;
  2167. begin
  2168. inherited;
  2169. end;
  2170. function TCnVSPopupPanel.GetVSChannel: TCnVSChannel;
  2171. begin
  2172. if FVSNETDockPanel <> nil then
  2173. Result := FVSNETDockPanel.VSChannel
  2174. else Result := nil;
  2175. end;
  2176. procedure TCnVSPopupPanel.SetParent(AParent: TWinControl);
  2177. begin
  2178. inherited;
  2179. if AParent = nil then Exit;
  2180. end;
  2181. procedure TCnVSPopupPanel.SetVSNETDockPanel(
  2182. const Value: TCnVSNETDockPanel);
  2183. begin
  2184. FVSNETDockPanel := Value;
  2185. end;
  2186. procedure TCnVSPopupPanel.ShowDockPanel(MakeVisible: Boolean;
  2187. Client: TControl; PanelSizeFrom: TSetDockPanelSizeFrom);
  2188. begin
  2189. if Align <> alNone then
  2190. inherited;
  2191. end;
  2192. { TCnVSNETDockTabSheet }
  2193. constructor TCnVSNETDockTabSheet.Create(AOwner: TComponent);
  2194. begin
  2195. inherited;
  2196. FOldVisible := True;
  2197. end;
  2198. procedure TCnVSNETDockTabSheet.SetOldVisible(const Value: Boolean);
  2199. begin
  2200. FOldVisible := Value;
  2201. end;
  2202. { TCnVSPopupPanelSplitter }
  2203. type
  2204. TWinControlAccess = class(TWinControl);
  2205. constructor TCnVSPopupPanelSplitter.Create(AOwner: TComponent);
  2206. begin
  2207. inherited Create(AOwner);
  2208. FAutoSnap := False;
  2209. Align := alNone;
  2210. Height := 0;
  2211. Width := 0;
  2212. FMinSize := 30;
  2213. FResizeStyle := rsPattern;
  2214. FOldSize := -1;
  2215. FSplitWidth := 4;
  2216. Anchors := [akLeft, akRight, akTop, akBottom];
  2217. end;
  2218. destructor TCnVSPopupPanelSplitter.Destroy;
  2219. begin
  2220. FBrush.Free;
  2221. inherited Destroy;
  2222. end;
  2223. procedure TCnVSPopupPanelSplitter.AllocateLineDC;
  2224. begin
  2225. FLineDC := GetDCEx(Parent.Handle, 0, DCX_CACHE or DCX_CLIPSIBLINGS
  2226. or DCX_LOCKWINDOWUPDATE);
  2227. if ResizeStyle = rsPattern then
  2228. begin
  2229. if FBrush = nil then
  2230. begin
  2231. FBrush := TBrush.Create;
  2232. FBrush.Bitmap := AllocPatternBitmap(clBlack, clWhite);
  2233. end;
  2234. FPrevBrush := SelectObject(FLineDC, FBrush.Handle);
  2235. end;
  2236. end;
  2237. procedure TCnVSPopupPanelSplitter.DrawLine;
  2238. var
  2239. P: TPoint;
  2240. begin
  2241. FLineVisible := not FLineVisible;
  2242. P := Point(Left, Top);
  2243. if VSChannelAlign in [alLeft, alRight] then
  2244. P.X := Left + FSplit else
  2245. P.Y := Top + FSplit;
  2246. with P do PatBlt(FLineDC, X, Y, Width, Height, PATINVERT);
  2247. end;
  2248. procedure TCnVSPopupPanelSplitter.ReleaseLineDC;
  2249. begin
  2250. if FPrevBrush <> 0 then
  2251. SelectObject(FLineDC, FPrevBrush);
  2252. ReleaseDC(Parent.Handle, FLineDC);
  2253. if FBrush <> nil then
  2254. begin
  2255. FBrush.Free;
  2256. FBrush := nil;
  2257. end;
  2258. end;
  2259. function TCnVSPopupPanelSplitter.FindControl: TControl;
  2260. begin
  2261. Result := FVSPopupPanel;
  2262. end;
  2263. procedure TCnVSPopupPanelSplitter.RequestAlign;
  2264. begin
  2265. inherited RequestAlign;
  2266. // if (Cursor <> crVSplit) and (Cursor <> crHSplit) then Exit;
  2267. if VSChannelAlign in [alBottom, alTop] then
  2268. Cursor := crVSplit
  2269. else
  2270. Cursor := crHSplit;
  2271. end;
  2272. procedure TCnVSPopupPanelSplitter.Paint;
  2273. const
  2274. XorColor = $00FFD8CE;
  2275. var
  2276. FrameBrush: HBRUSH;
  2277. R: TRect;
  2278. begin
  2279. R := ClientRect;
  2280. Canvas.Brush.Color := Color;
  2281. InflateRect(R, 2, 2);
  2282. case VSChannelAlign of
  2283. alLeft:
  2284. begin
  2285. Dec(R.Right, 2);
  2286. end;
  2287. alRight:
  2288. begin
  2289. Inc(R.Left, 3);
  2290. end;
  2291. alTop:
  2292. begin
  2293. Dec(R.Bottom, 2);
  2294. end;
  2295. alBottom:
  2296. begin
  2297. Inc(R.Top, 3);
  2298. end;
  2299. end;
  2300. DrawFrameControl(Canvas.Handle, R, DFC_BUTTON, DFCS_BUTTONPUSH or DFCS_ADJUSTRECT);
  2301. R := ClientRect;
  2302. if Beveled then
  2303. begin
  2304. if VSChannelAlign in [alLeft, alRight] then
  2305. InflateRect(R, -1, 2) else
  2306. InflateRect(R, 2, -1);
  2307. OffsetRect(R, 1, 1);
  2308. FrameBrush := CreateSolidBrush(ColorToRGB(clBtnHighlight));
  2309. FrameRect(Canvas.Handle, R, FrameBrush);
  2310. DeleteObject(FrameBrush);
  2311. OffsetRect(R, -2, -2);
  2312. FrameBrush := CreateSolidBrush(ColorToRGB(clBtnShadow));
  2313. FrameRect(Canvas.Handle, R, FrameBrush);
  2314. DeleteObject(FrameBrush);
  2315. end;
  2316. if csDesigning in ComponentState then
  2317. { Draw outline }
  2318. with Canvas do
  2319. begin
  2320. Pen.Style := psDot;
  2321. Pen.Mode := pmXor;
  2322. Pen.Color := XorColor;
  2323. Brush.Style := bsClear;
  2324. Rectangle(0, 0, ClientWidth, ClientHeight);
  2325. end;
  2326. if Assigned(FOnPaint) then FOnPaint(Self);
  2327. end;
  2328. function TCnVSPopupPanelSplitter.DoCanResize(var NewSize: Integer): Boolean;
  2329. begin
  2330. Result := CanResize(NewSize);
  2331. if Result and (NewSize <= MinSize) and FAutoSnap then
  2332. NewSize := 0;
  2333. end;
  2334. function TCnVSPopupPanelSplitter.CanResize(var NewSize: Integer): Boolean;
  2335. begin
  2336. Result := True;
  2337. if Assigned(FOnCanResize) then FOnCanResize(Self, NewSize, Result);
  2338. end;
  2339. procedure TCnVSPopupPanelSplitter.MouseDown(Button: TMouseButton; Shift: TShiftState;
  2340. X, Y: Integer);
  2341. var
  2342. I: Integer;
  2343. begin
  2344. inherited MouseDown(Button, Shift, X, Y);
  2345. if Button = mbLeft then
  2346. begin
  2347. FControl := FindControl;
  2348. FDownPos := Point(X, Y);
  2349. if Assigned(FControl) then
  2350. begin
  2351. if VSChannelAlign in [alLeft, alRight] then
  2352. begin
  2353. FMaxSize := Parent.ClientWidth - FMinSize;
  2354. for I := 0 to Parent.ControlCount - 1 do
  2355. with Parent.Controls[I] do
  2356. if Align in [alLeft, alRight] then Dec(FMaxSize, Width);
  2357. Inc(FMaxSize, FControl.Width);
  2358. end
  2359. else
  2360. begin
  2361. FMaxSize := Parent.ClientHeight - FMinSize;
  2362. for I := 0 to Parent.ControlCount - 1 do
  2363. with Parent.Controls[I] do
  2364. if Align in [alTop, alBottom] then Dec(FMaxSize, Height);
  2365. Inc(FMaxSize, FControl.Height);
  2366. end;
  2367. UpdateSize(X, Y);
  2368. AllocateLineDC;
  2369. with ValidParentForm(Self) do
  2370. if ActiveControl <> nil then
  2371. begin
  2372. FActiveControl := ActiveControl;
  2373. FOldKeyDown := TWinControlAccess(FActiveControl).OnKeyDown;
  2374. TWinControlAccess(FActiveControl).OnKeyDown := FocusKeyDown;
  2375. end;
  2376. if ResizeStyle in [rsLine, rsPattern] then DrawLine;
  2377. end;
  2378. end;
  2379. end;
  2380. procedure TCnVSPopupPanelSplitter.UpdateControlSize;
  2381. begin
  2382. if FNewSize <> FOldSize then
  2383. begin
  2384. case VSChannelAlign of
  2385. alLeft:
  2386. begin
  2387. FControl.Width := FNewSize;
  2388. Left := FControl.Left + FNewSize;
  2389. end;
  2390. alTop:
  2391. begin
  2392. FControl.Height := FNewSize;
  2393. Top := FControl.Top + FNewSize;
  2394. end;
  2395. alRight:
  2396. begin
  2397. Parent.DisableAlign;
  2398. try
  2399. FControl.Left := FControl.Left + (FControl.Width - FNewSize);
  2400. FControl.Width := FNewSize;
  2401. Left := FControl.Left - Width;
  2402. finally
  2403. Parent.EnableAlign;
  2404. end;
  2405. end;
  2406. alBottom:
  2407. begin
  2408. Parent.DisableAlign;
  2409. try
  2410. FControl.Top := FControl.Top + (FControl.Height - FNewSize);
  2411. FControl.Height := FNewSize;
  2412. Top := FControl.Top - Height;
  2413. finally
  2414. Parent.EnableAlign;
  2415. end;
  2416. end;
  2417. end;
  2418. FVSPopupPanel.VSChannel.ResetActivePaneWidth;
  2419. Update;
  2420. if Assigned(FOnMoved) then FOnMoved(Self);
  2421. FOldSize := FNewSize;
  2422. end;
  2423. end;
  2424. procedure TCnVSPopupPanelSplitter.CalcSplitSize(X, Y: Integer; var NewSize, Split: Integer);
  2425. var
  2426. S: Integer;
  2427. begin
  2428. if VSChannelAlign in [alLeft, alRight] then
  2429. Split := X - FDownPos.X
  2430. else
  2431. Split := Y - FDownPos.Y;
  2432. S := 0;
  2433. case VSChannelAlign of
  2434. alLeft: S := FControl.Width + Split;
  2435. alRight: S := FControl.Width - Split;
  2436. alTop: S := FControl.Height + Split;
  2437. alBottom: S := FControl.Height - Split;
  2438. end;
  2439. NewSize := S;
  2440. if S < FMinSize then
  2441. NewSize := FMinSize
  2442. else if S > FMaxSize then
  2443. NewSize := FMaxSize;
  2444. if S <> NewSize then
  2445. begin
  2446. if VSChannelAlign in [alRight, alBottom] then
  2447. S := S - NewSize else
  2448. S := NewSize - S;
  2449. Inc(Split, S);
  2450. end;
  2451. end;
  2452. procedure TCnVSPopupPanelSplitter.UpdateSize(X, Y: Integer);
  2453. begin
  2454. CalcSplitSize(X, Y, FNewSize, FSplit);
  2455. end;
  2456. procedure TCnVSPopupPanelSplitter.MouseMove(Shift: TShiftState; X, Y: Integer);
  2457. var
  2458. NewSize, Split: Integer;
  2459. begin
  2460. inherited;
  2461. if (ssLeft in Shift) and Assigned(FControl) then
  2462. begin
  2463. CalcSplitSize(X, Y, NewSize, Split);
  2464. if DoCanResize(NewSize) then
  2465. begin
  2466. if ResizeStyle in [rsLine, rsPattern] then DrawLine;
  2467. FNewSize := NewSize;
  2468. FSplit := Split;
  2469. if ResizeStyle = rsUpdate then UpdateControlSize;
  2470. if ResizeStyle in [rsLine, rsPattern] then DrawLine;
  2471. end;
  2472. end;
  2473. end;
  2474. procedure TCnVSPopupPanelSplitter.MouseUp(Button: TMouseButton; Shift: TShiftState;
  2475. X, Y: Integer);
  2476. begin
  2477. inherited;
  2478. if Assigned(FControl) then
  2479. begin
  2480. if ResizeStyle in [rsLine, rsPattern] then DrawLine;
  2481. UpdateControlSize;
  2482. StopSizing;
  2483. end;
  2484. end;
  2485. procedure TCnVSPopupPanelSplitter.FocusKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  2486. begin
  2487. if Key = VK_ESCAPE then
  2488. StopSizing
  2489. else if Assigned(FOldKeyDown) then
  2490. FOldKeyDown(Sender, Key, Shift);
  2491. end;
  2492. procedure TCnVSPopupPanelSplitter.SetBeveled(Value: Boolean);
  2493. begin
  2494. FBeveled := Value;
  2495. Repaint;
  2496. end;
  2497. procedure TCnVSPopupPanelSplitter.StopSizing;
  2498. begin
  2499. if Assigned(FControl) then
  2500. begin
  2501. if FLineVisible then DrawLine;
  2502. FControl := nil;
  2503. ReleaseLineDC;
  2504. if Assigned(FActiveControl) then
  2505. begin
  2506. TWinControlAccess(FActiveControl).OnKeyDown := FOldKeyDown;
  2507. FActiveControl := nil;
  2508. end;
  2509. end;
  2510. if Assigned(FOnMoved) then
  2511. FOnMoved(Self);
  2512. end;
  2513. procedure TCnVSPopupPanelSplitter.SetVSPopupPanel(
  2514. const Value: TCnVSPopupPanel);
  2515. begin
  2516. Assert((Value <> nil) and (Value is TCnVSPopupPanel));
  2517. FVSPopupPanel := Value;
  2518. end;
  2519. function TCnVSPopupPanelSplitter.GetVSChannelAlign: TAlign;
  2520. begin
  2521. Result := alNone;
  2522. if (VSPopupPanel <> nil) and (VSPopupPanel.FVSNETDockPanel <> nil) then
  2523. Result := VSPopupPanel.FVSNETDockPanel.Align;
  2524. end;
  2525. procedure TCnVSPopupPanelSplitter.SetSplitWidth(const Value: Integer);
  2526. begin
  2527. FSplitWidth := Value;
  2528. end;
  2529. { TPopupPanelAnimate }
  2530. constructor TPopupPanelAnimate.Create(AOwner: TComponent);
  2531. begin
  2532. inherited;
  2533. Interval := PopupPanelAnimateInterval;
  2534. Enabled := False;
  2535. FMaxWidth := 0;
  2536. FCurrentWidth := 0;
  2537. OnTimer := OnCustomTimer;
  2538. FState := asPopup;
  2539. end;
  2540. destructor TPopupPanelAnimate.Destroy;
  2541. begin
  2542. inherited;
  2543. end;
  2544. procedure TPopupPanelAnimate.HideForm(VSChannel: TCnVSChannel; MaxWidth: Integer);
  2545. begin
  2546. FVSChannel := VSChannel;
  2547. Enabled := (FVSChannel <> nil) and (FVSChannel.ActiveDockForm <> nil);
  2548. if FVSChannel <> nil then
  2549. begin
  2550. FMaxWidth := MaxWidth;
  2551. FCurrentWidth := 0;
  2552. FState := asHide;
  2553. end;
  2554. end;
  2555. procedure TPopupPanelAnimate.OnCustomTimer(Sender: TObject);
  2556. begin
  2557. //
  2558. end;
  2559. procedure TPopupPanelAnimate.PopupForm(VSChannel: TCnVSChannel; MaxWidth: Integer);
  2560. begin
  2561. if (FCurrentWidth > 0) and (FVSChannel <> nil) then
  2562. begin
  2563. FVSChannel.Parent.EnableAlign;
  2564. end;
  2565. FVSChannel := VSChannel;
  2566. Enabled := FVSChannel <> nil;
  2567. if FVSChannel <> nil then
  2568. begin
  2569. FMaxWidth := MaxWidth;
  2570. FCurrentWidth := 0;
  2571. FState := asPopup;
  2572. end;
  2573. end;
  2574. procedure TPopupPanelAnimate.Timer;
  2575. procedure SetControlBringToFront(Control: TWincontrol; Align: TAlign);
  2576. var i: Integer;
  2577. begin
  2578. for i := Control.ControlCount - 1 downto 0 do
  2579. begin
  2580. if Control.Controls[i].Visible and (Control.Controls[i].Align = Align)
  2581. and not (Control.Controls[i] is TCnVSChannel) and not (Control.Controls[i] is TCnDockPanel)
  2582. and not (Control.Controls[i] is TCnDockSplitter) then
  2583. Control.Controls[i].BringToFront;
  2584. end;
  2585. end;
  2586. var SuitablyWidth: Integer;
  2587. begin
  2588. inherited;
  2589. if FVSChannel <> nil then
  2590. begin
  2591. SuitablyWidth := min(FCurrentWidth, FMaxwidth);
  2592. with FVSChannel do
  2593. begin
  2594. if FCurrentWidth = 0 then
  2595. begin
  2596. Parent.DisableAlign;
  2597. VSPopupPanel.BringToFront;
  2598. VSPopupPanelSplitter.BringToFront;
  2599. SetControlBringToFront(Parent, Align);
  2600. BringToFront;
  2601. end;
  2602. case Align of
  2603. alLeft:
  2604. begin
  2605. if FState = asPopup then
  2606. begin
  2607. if FCurrentWidth = 0 then
  2608. begin
  2609. VSPopupPanel.Width := FMaxWidth;
  2610. VSPopupPanel.Top := Top;
  2611. VSPopupPanel.Height := Height;
  2612. VSPopupPanelSplitter.Top := Top;
  2613. VSPopupPanelSplitter.Height := Height;
  2614. VSPopupPanelSplitter.Width := VSPopupPanelSplitter.SplitWidth;
  2615. end;
  2616. VSPopupPanel.Left := Left + Width + SuitablyWidth - VSPopupPanel.Width;
  2617. end else if FState = asHide then
  2618. VSPopupPanel.Left := Left - FCurrentWidth;
  2619. VSPopupPanelSplitter.Left := VSPopupPanel.Left + VSPopupPanel.Width;
  2620. end;
  2621. alRight:
  2622. begin
  2623. if FState = asPopup then
  2624. begin
  2625. if FCurrentWidth = 0 then
  2626. begin
  2627. VSPopupPanel.Width := FMaxWidth;
  2628. VSPopupPanel.Top := Top;
  2629. VSPopupPanel.Height := Height;
  2630. VSPopupPanelSplitter.Top := Top;
  2631. VSPopupPanelSplitter.Height := Height;
  2632. VSPopupPanelSplitter.Width := VSPopupPanelSplitter.SplitWidth;
  2633. end;
  2634. VSPopupPanel.Left := Left - SuitablyWidth;
  2635. end else if FState = asHide then
  2636. VSPopupPanel.Left := Left - VSPopupPanel.Width + FCurrentWidth;
  2637. VSPopupPanelSplitter.Left := VSPopupPanel.Left - VSPopupPanelSplitter.SplitWidth;
  2638. end;
  2639. alTop:
  2640. begin
  2641. if FState = asPopup then
  2642. begin
  2643. if FCurrentWidth = 0 then
  2644. begin
  2645. VSPopupPanel.Left := Left;
  2646. VSPopupPanel.Height := FMaxWidth;
  2647. VSPopupPanel.Width := Width;
  2648. VSPopupPanelSplitter.Left := Left;
  2649. VSPopupPanelSplitter.Width := Width;
  2650. VSPopupPanelSplitter.Height := VSPopupPanelSplitter.SplitWidth;
  2651. end;
  2652. VSPopupPanel.Top := Top + Height + SuitablyWidth - VSPopupPanel.Height;
  2653. end else if FState = asHide then
  2654. VSPopupPanel.Top := Top - FCurrentWidth;
  2655. VSPopupPanelSplitter.Top := VSPopupPanel.Top + VSPopupPanel.Height;
  2656. end;
  2657. alBottom:
  2658. begin
  2659. if FState = asPopup then
  2660. begin
  2661. if FCurrentWidth = 0 then
  2662. begin
  2663. VSPopupPanel.Left := Left;
  2664. VSPopupPanel.Width := Width;
  2665. VSPopupPanel.Height:= FMaxWidth;
  2666. VSPopupPanelSplitter.Left := Left;
  2667. VSPopupPanelSplitter.Width := Width;
  2668. VSPopupPanelSplitter.Height := VSPopupPanelSplitter.SplitWidth;
  2669. end;
  2670. VSPopupPanel.Top := Top - SuitablyWidth;
  2671. end else if FState = asHide then
  2672. VSPopupPanel.Top := Top - VSPopupPanel.Height + FCurrentWidth;
  2673. VSPopupPanelSplitter.Top := VSPopupPanel.Top - VSPopupPanelSplitter.SplitWidth;
  2674. end;
  2675. end;
  2676. VSPopupPanel.Visible := True;
  2677. VSPopupPanelSplitter.Visible := True;
  2678. end;
  2679. if FCurrentWidth >= FMaxwidth then
  2680. begin
  2681. FVSChannel.Parent.EnableAlign;
  2682. Enabled := False;
  2683. if FState = asHide then
  2684. FVSChannel.HidePopupPanel(FVSChannel.FActivePane)
  2685. else
  2686. begin
  2687. if FVSChannel.ActiveDockForm <> nil then
  2688. begin
  2689. if FVSChannel.ActiveDockForm.CanFocus then
  2690. FVSChannel.ActiveDockForm.SetFocus;
  2691. end;
  2692. end;
  2693. FVSChannel := nil;
  2694. FCurrentWidth := 0;
  2695. FMaxwidth := 0;
  2696. end else
  2697. Inc(FCurrentWidth, PopupPanelAnimateMoveWidth);
  2698. end;
  2699. end;
  2700. { TCnVSNETChannelOption }
  2701. constructor TCnVSNETChannelOption.Create(ADockStyle: TCnBasicDockStyle);
  2702. begin
  2703. inherited;
  2704. FActivePaneSize := 100;
  2705. FShowImage := True;
  2706. end;
  2707. procedure TCnVSNETChannelOption.ResetDockClientOption(
  2708. ADockClient: TCnDockClient);
  2709. var VSChannel: TCnVSChannel;
  2710. procedure ResetActiveBlockSize;
  2711. begin
  2712. if VSChannel <> nil then
  2713. VSChannel.ActivePaneSize := ActivePaneSize;
  2714. end;
  2715. begin
  2716. if ADockClient = nil then Exit;
  2717. if ADockClient.ParentForm.HostDockSite is TCnVSPopupPanel then
  2718. VSChannel := TCnVSPopupPanel(ADockClient.ParentForm.HostDockSite).VSChannel
  2719. else if (ADockClient.ParentForm.HostDockSite is TCnVSNETTabPageControl) and
  2720. (ADockClient.ParentForm.HostDockSite.Parent.HostDockSite is TCnVSPopupPanel) then
  2721. VSChannel := TCnVSPopupPanel(ADockClient.ParentForm.HostDockSite.Parent.HostDockSite).VSChannel;
  2722. ResetActiveBlockSize;
  2723. end;
  2724. procedure TCnVSNETChannelOption.ResetDockControlOption;
  2725. var i: Integer;
  2726. ADockServer: TCnDockServer;
  2727. begin
  2728. if DockStyle = nil then Exit;
  2729. { 循环DockStyle的DockBaseControlList列表,然后把每一个TCnDockServer或者
  2730. TCnDockClient取出来,然后调用各自的函数重新设置它们的选项 }
  2731. for i := 0 to DockStyle.DockBaseControlListCount - 1 do
  2732. begin
  2733. if DockStyle.DockBaseControlLists[i] is TCnDockServer then
  2734. begin
  2735. { 重新设置TCnDockServer的选项 }
  2736. ADockServer := TCnDockServer(DockStyle.DockBaseControlLists[i]);
  2737. ResetDockServerOption(ADockServer);
  2738. end;
  2739. end;
  2740. end;
  2741. procedure TCnVSNETChannelOption.ResetDockServerOption(
  2742. ADockServer: TCnDockServer);
  2743. var VSChannel: TCnVSChannel;
  2744. procedure ResetActiveBlockSize;
  2745. begin
  2746. if VSChannel <> nil then
  2747. VSChannel.ActivePaneSize := ActivePaneSize;
  2748. end;
  2749. var i: Integer;
  2750. begin
  2751. if ADockServer = nil then Exit;
  2752. for i := 0 to 3 do
  2753. begin
  2754. if ADockServer.DockPanel[i] = nil then Continue;
  2755. VSChannel := TCnVSNETDockPanel(ADockServer.DockPanel[i]).VSChannel;
  2756. ResetActiveBlockSize;
  2757. end;
  2758. end;
  2759. procedure TCnVSNETChannelOption.SetActivePaneSize(const Value: Integer);
  2760. begin
  2761. if FActivePaneSize <> Value then
  2762. begin
  2763. FActivePaneSize := Max(24, Value);
  2764. ResetDockControlOption;
  2765. end;
  2766. end;
  2767. procedure TCnVSNETChannelOption.SetShowImage(const Value: Boolean);
  2768. begin
  2769. FShowImage := Value;
  2770. end;
  2771. { TCnAppEvents }
  2772. constructor TCnAppEvents.Create(AOwner: TComponent);
  2773. begin
  2774. inherited;
  2775. FOldOnMessage := OnMessage;
  2776. OnMessage := NewOnMessage;
  2777. end;
  2778. procedure TCnAppEvents.NewOnMessage(var Msg: TMsg; var Handled: Boolean);
  2779. var CurrControl: TWinControl;
  2780. DockServer: TCnDockServer;
  2781. VSChannel: TCnVSChannel;
  2782. i, j: Integer;
  2783. { 是否可以隐藏 }
  2784. function CanHide: Boolean;
  2785. begin
  2786. Result := True;
  2787. CurrControl := FindControl(Msg.hwnd);
  2788. if CurrControl = nil then Exit;
  2789. repeat
  2790. { 只有在运行期才能隐藏 }
  2791. if csDesigning in CurrControl.ComponentState then
  2792. begin
  2793. Result := False;
  2794. Exit;
  2795. end;
  2796. { 鼠标点击的控件不能是TCnVSChannel, TCnVSPopupPanel, TCnVSPopupPanelSplitter或者是前面三种控件的子控件}
  2797. Result := not ((CurrControl is TCnVSChannel) or (CurrControl is TCnVSPopupPanel) or (CurrControl is TCnVSPopupPanelSplitter));
  2798. CurrControl := CurrControl.Parent;
  2799. until (CurrControl = nil) or not Result;
  2800. end;
  2801. begin
  2802. if Assigned(FOldOnMessage) then
  2803. FOldOnMessage(Msg, Handled);
  2804. if (Msg.message = WM_LBUTTONDOWN){ or (Msg.message = WM_NCLBUTTONDOWN)} then
  2805. begin
  2806. if CanHide then
  2807. begin
  2808. for i := 0 to Screen.CustomFormCount - 1 do
  2809. begin
  2810. DockServer := FindDockServer(Screen.CustomForms[i]);
  2811. if (DockServer <> nil) and (DockServer.DockStyle is TCnVSNETDockStyle) then
  2812. begin
  2813. if DockServer.DockPanel[0] = nil then Exit;
  2814. for j := 0 to 3 do
  2815. begin
  2816. VSChannel := TCnVSNETDockPanel(DockServer.DockPanel[j]).VSChannel;
  2817. VSChannel.HidePopupPanelWithAnimate(VSChannel.FActivePane);
  2818. end;
  2819. end;
  2820. end;
  2821. // Windows.SetFocus(Msg.hwnd);
  2822. end;
  2823. end;
  2824. end;
  2825. initialization
  2826. PopupPanelAnimate := TPopupPanelAnimate.Create(nil);
  2827. ApplicationEvents := TCnAppEvents.Create(nil);
  2828. finalization
  2829. PopupPanelAnimate.Free;
  2830. ApplicationEvents.Free;
  2831. end.