DockingManager.cs 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using System.Collections.Specialized;
  14. using System.ComponentModel;
  15. using System.Diagnostics;
  16. using System.Linq;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Input;
  21. using System.Windows.Interop;
  22. using System.Windows.Markup;
  23. using System.Windows.Threading;
  24. using Xceed.Wpf.AvalonDock.Controls;
  25. using Xceed.Wpf.AvalonDock.Layout;
  26. using Xceed.Wpf.AvalonDock.Themes;
  27. namespace Xceed.Wpf.AvalonDock
  28. {
  29. [ContentProperty("Layout")]
  30. [TemplatePart(Name = "PART_AutoHideArea")]
  31. public class DockingManager : Control, IOverlayWindowHost//, ILogicalChildrenContainer
  32. {
  33. private ResourceDictionary currentThemeResourceDictionary; // = null
  34. static DockingManager()
  35. {
  36. DefaultStyleKeyProperty.OverrideMetadata(typeof(DockingManager), new FrameworkPropertyMetadata(typeof(DockingManager)));
  37. FocusableProperty.OverrideMetadata(typeof(DockingManager), new FrameworkPropertyMetadata(false));
  38. HwndSource.DefaultAcquireHwndFocusInMenuMode = false;
  39. }
  40. public DockingManager()
  41. {
  42. Layout = new LayoutRoot() { RootPanel = new LayoutPanel(new LayoutDocumentPaneGroup(new LayoutDocumentPane())) };
  43. this.Loaded += new RoutedEventHandler(DockingManager_Loaded);
  44. this.Unloaded += new RoutedEventHandler(DockingManager_Unloaded);
  45. }
  46. #region Layout
  47. /// <summary>
  48. /// Layout Dependency Property
  49. /// </summary>
  50. public static readonly DependencyProperty LayoutProperty =
  51. DependencyProperty.Register("Layout", typeof(LayoutRoot), typeof(DockingManager),
  52. new FrameworkPropertyMetadata(null,
  53. new PropertyChangedCallback(OnLayoutChanged),
  54. new CoerceValueCallback(CoerceLayoutValue)));
  55. /// <summary>
  56. /// Gets or sets the Layout property. This dependency property
  57. /// indicates layout tree.
  58. /// </summary>
  59. public LayoutRoot Layout
  60. {
  61. get { return (LayoutRoot)GetValue(LayoutProperty); }
  62. set { SetValue(LayoutProperty, value); }
  63. }
  64. /// <summary>
  65. /// Handles changes to the Layout property.
  66. /// </summary>
  67. private static void OnLayoutChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  68. {
  69. ((DockingManager)d).OnLayoutChanged(e.OldValue as LayoutRoot, e.NewValue as LayoutRoot);
  70. }
  71. /// <summary>
  72. /// Provides derived classes an opportunity to handle changes to the <see cref="DockingManager.Layout"/> property.
  73. /// </summary>
  74. protected virtual void OnLayoutChanged(LayoutRoot oldLayout, LayoutRoot newLayout)
  75. {
  76. if (oldLayout != null)
  77. {
  78. oldLayout.PropertyChanged -= new PropertyChangedEventHandler(OnLayoutRootPropertyChanged);
  79. oldLayout.Updated -= new EventHandler(OnLayoutRootUpdated);
  80. }
  81. foreach (var fwc in _fwList.ToArray())
  82. {
  83. fwc.KeepContentVisibleOnClose = true;
  84. fwc.InternalClose();
  85. }
  86. _fwList.Clear();
  87. DetachDocumentsSource(oldLayout, DocumentsSource);
  88. DetachAnchorablesSource(oldLayout, AnchorablesSource);
  89. if (oldLayout != null &&
  90. oldLayout.Manager == this)
  91. oldLayout.Manager = null;
  92. ClearLogicalChildrenList();
  93. DetachLayoutItems();
  94. Layout.Manager = this;
  95. AttachLayoutItems();
  96. AttachDocumentsSource(newLayout, DocumentsSource);
  97. AttachAnchorablesSource(newLayout, AnchorablesSource);
  98. if (IsLoaded)
  99. {
  100. LayoutRootPanel = CreateUIElementForModel(Layout.RootPanel) as LayoutPanelControl;
  101. LeftSidePanel = CreateUIElementForModel(Layout.LeftSide) as LayoutAnchorSideControl;
  102. TopSidePanel = CreateUIElementForModel(Layout.TopSide) as LayoutAnchorSideControl;
  103. RightSidePanel = CreateUIElementForModel(Layout.RightSide) as LayoutAnchorSideControl;
  104. BottomSidePanel = CreateUIElementForModel(Layout.BottomSide) as LayoutAnchorSideControl;
  105. foreach (var fw in Layout.FloatingWindows.ToArray())
  106. {
  107. if (fw.IsValid)
  108. _fwList.Add(CreateUIElementForModel(fw) as LayoutFloatingWindowControl);
  109. }
  110. foreach (var fw in _fwList)
  111. {
  112. //fw.Owner = Window.GetWindow(this);
  113. //fw.SetParentToMainWindowOf(this);
  114. }
  115. }
  116. if (newLayout != null)
  117. {
  118. newLayout.PropertyChanged += new PropertyChangedEventHandler(OnLayoutRootPropertyChanged);
  119. newLayout.Updated += new EventHandler(OnLayoutRootUpdated);
  120. }
  121. if (LayoutChanged != null)
  122. LayoutChanged(this, EventArgs.Empty);
  123. //if (Layout != null)
  124. // Layout.CollectGarbage();
  125. CommandManager.InvalidateRequerySuggested();
  126. }
  127. DispatcherOperation _setFocusAsyncOperation = null;
  128. void OnLayoutRootPropertyChanged(object sender, PropertyChangedEventArgs e)
  129. {
  130. if (e.PropertyName == "RootPanel")
  131. {
  132. if (IsInitialized)
  133. {
  134. var layoutRootPanel = CreateUIElementForModel(Layout.RootPanel) as LayoutPanelControl;
  135. LayoutRootPanel = layoutRootPanel;
  136. }
  137. }
  138. else if (e.PropertyName == "ActiveContent")
  139. {
  140. if (Layout.ActiveContent != null)
  141. {
  142. //Debug.WriteLine(new StackTrace().ToString());
  143. //set focus on active element only after a layout pass is completed
  144. //it's possible that it is not yet visible in the visual tree
  145. if (_setFocusAsyncOperation == null)
  146. {
  147. _setFocusAsyncOperation = Dispatcher.BeginInvoke(new Action(() =>
  148. {
  149. if (Layout.ActiveContent != null)
  150. FocusElementManager.SetFocusOnLastElement(Layout.ActiveContent);
  151. _setFocusAsyncOperation = null;
  152. }), DispatcherPriority.Background);
  153. }
  154. }
  155. if (!_insideInternalSetActiveContent)
  156. ActiveContent = Layout.ActiveContent != null ?
  157. Layout.ActiveContent.Content : null;
  158. }
  159. }
  160. void OnLayoutRootUpdated(object sender, EventArgs e)
  161. {
  162. CommandManager.InvalidateRequerySuggested();
  163. }
  164. /// <summary>
  165. /// Event fired when <see cref="DockingManager.Layout"/> property changes
  166. /// </summary>
  167. public event EventHandler LayoutChanged;
  168. /// <summary>
  169. /// Coerces the <see cref="DockingManager.Layout"/> value.
  170. /// </summary>
  171. private static object CoerceLayoutValue(DependencyObject d, object value)
  172. {
  173. if (value == null)
  174. return new LayoutRoot() { RootPanel = new LayoutPanel(new LayoutDocumentPaneGroup(new LayoutDocumentPane())) };
  175. ((DockingManager)d).OnLayoutChanging(value as LayoutRoot);
  176. return value;
  177. }
  178. /// <summary>
  179. /// Event fired when <see cref="DockingManager.Layout"/> property is about to be changed
  180. /// </summary>
  181. public event EventHandler LayoutChanging;
  182. void OnLayoutChanging(LayoutRoot newLayout)
  183. {
  184. if (LayoutChanging != null)
  185. LayoutChanging(this, EventArgs.Empty);
  186. }
  187. #region LayoutUpdateStrategy
  188. /// <summary>
  189. /// LayoutUpdateStrategy Dependency Property
  190. /// </summary>
  191. public static readonly DependencyProperty LayoutUpdateStrategyProperty =
  192. DependencyProperty.Register("LayoutUpdateStrategy", typeof(ILayoutUpdateStrategy), typeof(DockingManager),
  193. new FrameworkPropertyMetadata((ILayoutUpdateStrategy)null));
  194. /// <summary>
  195. /// Gets or sets the LayoutUpdateStrategy property. This dependency property
  196. /// indicates the strategy class to call when AvalonDock needs to positionate a LayoutAnchorable inside an existing layout.
  197. /// </summary>
  198. /// <remarks>Sometimes it's impossible to automatically insert an anchorable in the layout without specifing the target parent pane.
  199. /// Set this property to an object that will be asked to insert the anchorable to the desidered position.</remarks>
  200. public ILayoutUpdateStrategy LayoutUpdateStrategy
  201. {
  202. get { return (ILayoutUpdateStrategy)GetValue(LayoutUpdateStrategyProperty); }
  203. set { SetValue(LayoutUpdateStrategyProperty, value); }
  204. }
  205. #endregion
  206. #endregion
  207. public override void OnApplyTemplate()
  208. {
  209. base.OnApplyTemplate();
  210. SetupAutoHideWindow();
  211. }
  212. protected override void OnInitialized(EventArgs e)
  213. {
  214. base.OnInitialized(e);
  215. }
  216. void DockingManager_Loaded(object sender, RoutedEventArgs e)
  217. {
  218. if (!DesignerProperties.GetIsInDesignMode(this))
  219. {
  220. if (Layout.Manager == this)
  221. {
  222. LayoutRootPanel = CreateUIElementForModel(Layout.RootPanel) as LayoutPanelControl;
  223. LeftSidePanel = CreateUIElementForModel(Layout.LeftSide) as LayoutAnchorSideControl;
  224. TopSidePanel = CreateUIElementForModel(Layout.TopSide) as LayoutAnchorSideControl;
  225. RightSidePanel = CreateUIElementForModel(Layout.RightSide) as LayoutAnchorSideControl;
  226. BottomSidePanel = CreateUIElementForModel(Layout.BottomSide) as LayoutAnchorSideControl;
  227. }
  228. //load windows not already loaded!
  229. foreach (var fw in Layout.FloatingWindows.Where(fw => !_fwList.Any(fwc => fwc.Model == fw)))
  230. _fwList.Add(CreateUIElementForModel(fw) as LayoutFloatingWindowControl);
  231. //create the overlaywindow if it's possible
  232. if (IsVisible)
  233. CreateOverlayWindow();
  234. FocusElementManager.SetupFocusManagement(this);
  235. }
  236. }
  237. void DockingManager_Unloaded(object sender, RoutedEventArgs e)
  238. {
  239. if (!DesignerProperties.GetIsInDesignMode(this))
  240. {
  241. if (_autoHideWindowManager != null)
  242. {
  243. _autoHideWindowManager.HideAutoWindow();
  244. }
  245. foreach (var fw in _fwList.ToArray())
  246. {
  247. //fw.Owner = null;
  248. fw.SetParentWindowToNull();
  249. fw.KeepContentVisibleOnClose = true;
  250. fw.Close();
  251. }
  252. DestroyOverlayWindow();
  253. FocusElementManager.FinalizeFocusManagement(this);
  254. }
  255. }
  256. internal UIElement CreateUIElementForModel(ILayoutElement model)
  257. {
  258. if (model is LayoutPanel)
  259. return new LayoutPanelControl(model as LayoutPanel);
  260. if (model is LayoutAnchorablePaneGroup)
  261. return new LayoutAnchorablePaneGroupControl(model as LayoutAnchorablePaneGroup);
  262. if (model is LayoutDocumentPaneGroup)
  263. return new LayoutDocumentPaneGroupControl(model as LayoutDocumentPaneGroup);
  264. if (model is LayoutAnchorSide)
  265. {
  266. var templateModelView = new LayoutAnchorSideControl(model as LayoutAnchorSide);
  267. templateModelView.SetBinding(LayoutAnchorSideControl.TemplateProperty, new Binding("AnchorSideTemplate") { Source = this });
  268. return templateModelView;
  269. }
  270. if (model is LayoutAnchorGroup)
  271. {
  272. var templateModelView = new LayoutAnchorGroupControl(model as LayoutAnchorGroup);
  273. templateModelView.SetBinding(LayoutAnchorGroupControl.TemplateProperty, new Binding("AnchorGroupTemplate") { Source = this });
  274. return templateModelView;
  275. }
  276. if (model is LayoutDocumentPane)
  277. {
  278. var templateModelView = new LayoutDocumentPaneControl(model as LayoutDocumentPane);
  279. templateModelView.SetBinding(LayoutDocumentPaneControl.StyleProperty, new Binding("DocumentPaneControlStyle") { Source = this });
  280. return templateModelView;
  281. }
  282. if (model is LayoutAnchorablePane)
  283. {
  284. var templateModelView = new LayoutAnchorablePaneControl(model as LayoutAnchorablePane);
  285. templateModelView.SetBinding(LayoutAnchorablePaneControl.StyleProperty, new Binding("AnchorablePaneControlStyle") { Source = this });
  286. return templateModelView;
  287. }
  288. if (model is LayoutAnchorableFloatingWindow)
  289. {
  290. if (DesignerProperties.GetIsInDesignMode(this))
  291. return null;
  292. var modelFW = model as LayoutAnchorableFloatingWindow;
  293. var newFW = new LayoutAnchorableFloatingWindowControl(modelFW)
  294. {
  295. //Owner = Window.GetWindow(this)
  296. };
  297. newFW.SetParentToMainWindowOf(this);
  298. var paneForExtensions = modelFW.RootPanel.Children.OfType<LayoutAnchorablePane>().FirstOrDefault();
  299. if (paneForExtensions != null)
  300. {
  301. //ensure that floating window position is inside current (or nearest) monitor
  302. paneForExtensions.KeepInsideNearestMonitor();
  303. newFW.Left = paneForExtensions.FloatingLeft;
  304. newFW.Top = paneForExtensions.FloatingTop;
  305. newFW.Width = paneForExtensions.FloatingWidth;
  306. newFW.Height = paneForExtensions.FloatingHeight;
  307. }
  308. newFW.ShowInTaskbar = false;
  309. newFW.Show();
  310. // Do not set the WindowState before showing or it will be lost
  311. if (paneForExtensions != null && paneForExtensions.IsMaximized)
  312. {
  313. newFW.WindowState = WindowState.Maximized;
  314. }
  315. return newFW;
  316. }
  317. if (model is LayoutDocumentFloatingWindow)
  318. {
  319. if (DesignerProperties.GetIsInDesignMode(this))
  320. return null;
  321. var modelFW = model as LayoutDocumentFloatingWindow;
  322. var newFW = new LayoutDocumentFloatingWindowControl(modelFW)
  323. {
  324. //Owner = Window.GetWindow(this)
  325. };
  326. newFW.SetParentToMainWindowOf(this);
  327. var paneForExtensions = modelFW.RootDocument;
  328. if (paneForExtensions != null)
  329. {
  330. //ensure that floating window position is inside current (or nearest) monitor
  331. paneForExtensions.KeepInsideNearestMonitor();
  332. newFW.Left = paneForExtensions.FloatingLeft;
  333. newFW.Top = paneForExtensions.FloatingTop;
  334. newFW.Width = paneForExtensions.FloatingWidth;
  335. newFW.Height = paneForExtensions.FloatingHeight;
  336. }
  337. newFW.ShowInTaskbar = false;
  338. newFW.Show();
  339. // Do not set the WindowState before showing or it will be lost
  340. if (paneForExtensions != null && paneForExtensions.IsMaximized)
  341. {
  342. newFW.WindowState = WindowState.Maximized;
  343. }
  344. return newFW;
  345. }
  346. if (model is LayoutDocument)
  347. {
  348. var templateModelView = new LayoutDocumentControl() { Model = model as LayoutDocument };
  349. return templateModelView;
  350. }
  351. return null;
  352. }
  353. #region DocumentPaneTemplate
  354. /// <summary>
  355. /// DocumentPaneTemplate Dependency Property
  356. /// </summary>
  357. public static readonly DependencyProperty DocumentPaneTemplateProperty =
  358. DependencyProperty.Register("DocumentPaneTemplate", typeof(ControlTemplate), typeof(DockingManager),
  359. new FrameworkPropertyMetadata((ControlTemplate)null,
  360. new PropertyChangedCallback(OnDocumentPaneTemplateChanged)));
  361. /// <summary>
  362. /// Gets or sets the DocumentPaneDataTemplate property. This dependency property
  363. /// indicates .
  364. /// </summary>
  365. public ControlTemplate DocumentPaneTemplate
  366. {
  367. get { return (ControlTemplate)GetValue(DocumentPaneTemplateProperty); }
  368. set { SetValue(DocumentPaneTemplateProperty, value); }
  369. }
  370. /// <summary>
  371. /// Handles changes to the DocumentPaneTemplate property.
  372. /// </summary>
  373. private static void OnDocumentPaneTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  374. {
  375. ((DockingManager)d).OnDocumentPaneTemplateChanged(e);
  376. }
  377. /// <summary>
  378. /// Provides derived classes an opportunity to handle changes to the DocumentPaneTemplate property.
  379. /// </summary>
  380. protected virtual void OnDocumentPaneTemplateChanged(DependencyPropertyChangedEventArgs e)
  381. {
  382. }
  383. #endregion
  384. #region AnchorablePaneTemplate
  385. /// <summary>
  386. /// AnchorablePaneTemplate Dependency Property
  387. /// </summary>
  388. public static readonly DependencyProperty AnchorablePaneTemplateProperty =
  389. DependencyProperty.Register("AnchorablePaneTemplate", typeof(ControlTemplate), typeof(DockingManager),
  390. new FrameworkPropertyMetadata((ControlTemplate)null,
  391. new PropertyChangedCallback(OnAnchorablePaneTemplateChanged)));
  392. /// <summary>
  393. /// Gets or sets the AnchorablePaneTemplate property. This dependency property
  394. /// indicates ....
  395. /// </summary>
  396. public ControlTemplate AnchorablePaneTemplate
  397. {
  398. get { return (ControlTemplate)GetValue(AnchorablePaneTemplateProperty); }
  399. set { SetValue(AnchorablePaneTemplateProperty, value); }
  400. }
  401. /// <summary>
  402. /// Handles changes to the AnchorablePaneDataTemplate property.
  403. /// </summary>
  404. private static void OnAnchorablePaneTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  405. {
  406. ((DockingManager)d).OnAnchorablePaneTemplateChanged(e);
  407. }
  408. /// <summary>
  409. /// Provides derived classes an opportunity to handle changes to the AnchorablePaneDataTemplate property.
  410. /// </summary>
  411. protected virtual void OnAnchorablePaneTemplateChanged(DependencyPropertyChangedEventArgs e)
  412. {
  413. }
  414. #endregion
  415. #region AnchorSideTemplate
  416. /// <summary>
  417. /// AnchorSideTemplate Dependency Property
  418. /// </summary>
  419. public static readonly DependencyProperty AnchorSideTemplateProperty =
  420. DependencyProperty.Register("AnchorSideTemplate", typeof(ControlTemplate), typeof(DockingManager),
  421. new FrameworkPropertyMetadata((ControlTemplate)null));
  422. /// <summary>
  423. /// Gets or sets the AnchorSideTemplate property. This dependency property
  424. /// indicates ....
  425. /// </summary>
  426. public ControlTemplate AnchorSideTemplate
  427. {
  428. get { return (ControlTemplate)GetValue(AnchorSideTemplateProperty); }
  429. set { SetValue(AnchorSideTemplateProperty, value); }
  430. }
  431. #endregion
  432. #region AnchorGroupTemplate
  433. /// <summary>
  434. /// AnchorGroupTemplate Dependency Property
  435. /// </summary>
  436. public static readonly DependencyProperty AnchorGroupTemplateProperty =
  437. DependencyProperty.Register("AnchorGroupTemplate", typeof(ControlTemplate), typeof(DockingManager),
  438. new FrameworkPropertyMetadata((ControlTemplate)null));
  439. /// <summary>
  440. /// Gets or sets the AnchorGroupTemplate property. This dependency property
  441. /// indicates the template used to render the AnchorGroup control.
  442. /// </summary>
  443. public ControlTemplate AnchorGroupTemplate
  444. {
  445. get { return (ControlTemplate)GetValue(AnchorGroupTemplateProperty); }
  446. set { SetValue(AnchorGroupTemplateProperty, value); }
  447. }
  448. #endregion
  449. #region AnchorTemplate
  450. /// <summary>
  451. /// AnchorTemplate Dependency Property
  452. /// </summary>
  453. public static readonly DependencyProperty AnchorTemplateProperty =
  454. DependencyProperty.Register("AnchorTemplate", typeof(ControlTemplate), typeof(DockingManager),
  455. new FrameworkPropertyMetadata((ControlTemplate)null));
  456. /// <summary>
  457. /// Gets or sets the AnchorTemplate property. This dependency property
  458. /// indicates ....
  459. /// </summary>
  460. public ControlTemplate AnchorTemplate
  461. {
  462. get { return (ControlTemplate)GetValue(AnchorTemplateProperty); }
  463. set { SetValue(AnchorTemplateProperty, value); }
  464. }
  465. #endregion
  466. #region DocumentPaneControlStyle
  467. /// <summary>
  468. /// DocumentPaneControlStyle Dependency Property
  469. /// </summary>
  470. public static readonly DependencyProperty DocumentPaneControlStyleProperty =
  471. DependencyProperty.Register("DocumentPaneControlStyle", typeof(Style), typeof(DockingManager),
  472. new FrameworkPropertyMetadata((Style)null,
  473. new PropertyChangedCallback(OnDocumentPaneControlStyleChanged)));
  474. /// <summary>
  475. /// Gets or sets the DocumentPaneControlStyle property. This dependency property
  476. /// indicates ....
  477. /// </summary>
  478. public Style DocumentPaneControlStyle
  479. {
  480. get { return (Style)GetValue(DocumentPaneControlStyleProperty); }
  481. set { SetValue(DocumentPaneControlStyleProperty, value); }
  482. }
  483. /// <summary>
  484. /// Handles changes to the DocumentPaneControlStyle property.
  485. /// </summary>
  486. private static void OnDocumentPaneControlStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  487. {
  488. ((DockingManager)d).OnDocumentPaneControlStyleChanged(e);
  489. }
  490. /// <summary>
  491. /// Provides derived classes an opportunity to handle changes to the DocumentPaneControlStyle property.
  492. /// </summary>
  493. protected virtual void OnDocumentPaneControlStyleChanged(DependencyPropertyChangedEventArgs e)
  494. {
  495. }
  496. #endregion
  497. #region AnchorablePaneControlStyle
  498. /// <summary>
  499. /// AnchorablePaneControlStyle Dependency Property
  500. /// </summary>
  501. public static readonly DependencyProperty AnchorablePaneControlStyleProperty =
  502. DependencyProperty.Register("AnchorablePaneControlStyle", typeof(Style), typeof(DockingManager),
  503. new FrameworkPropertyMetadata((Style)null,
  504. new PropertyChangedCallback(OnAnchorablePaneControlStyleChanged)));
  505. /// <summary>
  506. /// Gets or sets the AnchorablePaneControlStyle property. This dependency property
  507. /// indicates the style to apply to AnchorablePaneControl.
  508. /// </summary>
  509. public Style AnchorablePaneControlStyle
  510. {
  511. get { return (Style)GetValue(AnchorablePaneControlStyleProperty); }
  512. set { SetValue(AnchorablePaneControlStyleProperty, value); }
  513. }
  514. /// <summary>
  515. /// Handles changes to the AnchorablePaneControlStyle property.
  516. /// </summary>
  517. private static void OnAnchorablePaneControlStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  518. {
  519. ((DockingManager)d).OnAnchorablePaneControlStyleChanged(e);
  520. }
  521. /// <summary>
  522. /// Provides derived classes an opportunity to handle changes to the AnchorablePaneControlStyle property.
  523. /// </summary>
  524. protected virtual void OnAnchorablePaneControlStyleChanged(DependencyPropertyChangedEventArgs e)
  525. {
  526. }
  527. #endregion
  528. #region DocumentHeaderTemplate
  529. /// <summary>
  530. /// DocumentHeaderTemplate Dependency Property
  531. /// </summary>
  532. public static readonly DependencyProperty DocumentHeaderTemplateProperty =
  533. DependencyProperty.Register("DocumentHeaderTemplate", typeof(DataTemplate), typeof(DockingManager),
  534. new FrameworkPropertyMetadata((DataTemplate)null,
  535. new PropertyChangedCallback(OnDocumentHeaderTemplateChanged),
  536. new CoerceValueCallback(CoerceDocumentHeaderTemplateValue)));
  537. /// <summary>
  538. /// Gets or sets the DocumentHeaderTemplate property. This dependency property
  539. /// indicates data template to use for document header.
  540. /// </summary>
  541. public DataTemplate DocumentHeaderTemplate
  542. {
  543. get { return (DataTemplate)GetValue(DocumentHeaderTemplateProperty); }
  544. set { SetValue(DocumentHeaderTemplateProperty, value); }
  545. }
  546. /// <summary>
  547. /// Handles changes to the DocumentHeaderTemplate property.
  548. /// </summary>
  549. private static void OnDocumentHeaderTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  550. {
  551. ((DockingManager)d).OnDocumentHeaderTemplateChanged(e);
  552. }
  553. /// <summary>
  554. /// Provides derived classes an opportunity to handle changes to the DocumentHeaderTemplate property.
  555. /// </summary>
  556. protected virtual void OnDocumentHeaderTemplateChanged(DependencyPropertyChangedEventArgs e)
  557. {
  558. }
  559. /// <summary>
  560. /// Coerces the DocumentHeaderTemplate value.
  561. /// </summary>
  562. private static object CoerceDocumentHeaderTemplateValue(DependencyObject d, object value)
  563. {
  564. if (value != null &&
  565. d.GetValue(DocumentHeaderTemplateSelectorProperty) != null)
  566. return null;
  567. return value;
  568. }
  569. #endregion
  570. #region DocumentHeaderTemplateSelector
  571. /// <summary>
  572. /// DocumentHeaderTemplateSelector Dependency Property
  573. /// </summary>
  574. public static readonly DependencyProperty DocumentHeaderTemplateSelectorProperty =
  575. DependencyProperty.Register("DocumentHeaderTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
  576. new FrameworkPropertyMetadata((DataTemplateSelector)null,
  577. new PropertyChangedCallback(OnDocumentHeaderTemplateSelectorChanged),
  578. new CoerceValueCallback(CoerceDocumentHeaderTemplateSelectorValue)));
  579. /// <summary>
  580. /// Gets or sets the DocumentHeaderTemplateSelector property. This dependency property
  581. /// indicates the template selector that is used when selcting the data template for the header.
  582. /// </summary>
  583. public DataTemplateSelector DocumentHeaderTemplateSelector
  584. {
  585. get { return (DataTemplateSelector)GetValue(DocumentHeaderTemplateSelectorProperty); }
  586. set { SetValue(DocumentHeaderTemplateSelectorProperty, value); }
  587. }
  588. /// <summary>
  589. /// Handles changes to the DocumentHeaderTemplateSelector property.
  590. /// </summary>
  591. private static void OnDocumentHeaderTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  592. {
  593. ((DockingManager)d).OnDocumentHeaderTemplateSelectorChanged(e);
  594. }
  595. /// <summary>
  596. /// Provides derived classes an opportunity to handle changes to the DocumentHeaderTemplateSelector property.
  597. /// </summary>
  598. protected virtual void OnDocumentHeaderTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
  599. {
  600. if (e.NewValue != null &&
  601. DocumentHeaderTemplate != null)
  602. DocumentHeaderTemplate = null;
  603. if (DocumentPaneMenuItemHeaderTemplateSelector == null)
  604. DocumentPaneMenuItemHeaderTemplateSelector = DocumentHeaderTemplateSelector;
  605. }
  606. /// <summary>
  607. /// Coerces the DocumentHeaderTemplateSelector value.
  608. /// </summary>
  609. private static object CoerceDocumentHeaderTemplateSelectorValue(DependencyObject d, object value)
  610. {
  611. return value;
  612. }
  613. #endregion
  614. #region DocumentTitleTemplate
  615. /// <summary>
  616. /// DocumentTitleTemplate Dependency Property
  617. /// </summary>
  618. public static readonly DependencyProperty DocumentTitleTemplateProperty =
  619. DependencyProperty.Register("DocumentTitleTemplate", typeof(DataTemplate), typeof(DockingManager),
  620. new FrameworkPropertyMetadata((DataTemplate)null,
  621. new PropertyChangedCallback(OnDocumentTitleTemplateChanged),
  622. new CoerceValueCallback(CoerceDocumentTitleTemplateValue)));
  623. /// <summary>
  624. /// Gets or sets the DocumentTitleTemplate property. This dependency property
  625. /// indicates the datatemplate to use when creating the title for a document.
  626. /// </summary>
  627. public DataTemplate DocumentTitleTemplate
  628. {
  629. get { return (DataTemplate)GetValue(DocumentTitleTemplateProperty); }
  630. set { SetValue(DocumentTitleTemplateProperty, value); }
  631. }
  632. /// <summary>
  633. /// Handles changes to the DocumentTitleTemplate property.
  634. /// </summary>
  635. private static void OnDocumentTitleTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  636. {
  637. ((DockingManager)d).OnDocumentTitleTemplateChanged(e);
  638. }
  639. /// <summary>
  640. /// Provides derived classes an opportunity to handle changes to the DocumentTitleTemplate property.
  641. /// </summary>
  642. protected virtual void OnDocumentTitleTemplateChanged(DependencyPropertyChangedEventArgs e)
  643. {
  644. }
  645. /// <summary>
  646. /// Coerces the DocumentTitleTemplate value.
  647. /// </summary>
  648. private static object CoerceDocumentTitleTemplateValue(DependencyObject d, object value)
  649. {
  650. if (value != null &&
  651. d.GetValue(DocumentTitleTemplateSelectorProperty) != null)
  652. return null;
  653. return value;
  654. }
  655. #endregion
  656. #region DocumentTitleTemplateSelector
  657. /// <summary>
  658. /// DocumentTitleTemplateSelector Dependency Property
  659. /// </summary>
  660. public static readonly DependencyProperty DocumentTitleTemplateSelectorProperty =
  661. DependencyProperty.Register("DocumentTitleTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
  662. new FrameworkPropertyMetadata((DataTemplateSelector)null,
  663. new PropertyChangedCallback(OnDocumentTitleTemplateSelectorChanged),
  664. new CoerceValueCallback(CoerceDocumentTitleTemplateSelectorValue)));
  665. /// <summary>
  666. /// Gets or sets the DocumentTitleTemplateSelector property. This dependency property
  667. /// indicates the data template selector to use when creating the data template for the title.
  668. /// </summary>
  669. public DataTemplateSelector DocumentTitleTemplateSelector
  670. {
  671. get { return (DataTemplateSelector)GetValue(DocumentTitleTemplateSelectorProperty); }
  672. set { SetValue(DocumentTitleTemplateSelectorProperty, value); }
  673. }
  674. /// <summary>
  675. /// Handles changes to the DocumentTitleTemplateSelector property.
  676. /// </summary>
  677. private static void OnDocumentTitleTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  678. {
  679. ((DockingManager)d).OnDocumentTitleTemplateSelectorChanged(e);
  680. }
  681. /// <summary>
  682. /// Provides derived classes an opportunity to handle changes to the DocumentTitleTemplateSelector property.
  683. /// </summary>
  684. protected virtual void OnDocumentTitleTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
  685. {
  686. if (e.NewValue != null)
  687. DocumentTitleTemplate = null;
  688. }
  689. /// <summary>
  690. /// Coerces the DocumentTitleTemplateSelector value.
  691. /// </summary>
  692. private static object CoerceDocumentTitleTemplateSelectorValue(DependencyObject d, object value)
  693. {
  694. return value;
  695. }
  696. #endregion
  697. #region AnchorableTitleTemplate
  698. /// <summary>
  699. /// AnchorableTitleTemplate Dependency Property
  700. /// </summary>
  701. public static readonly DependencyProperty AnchorableTitleTemplateProperty =
  702. DependencyProperty.Register("AnchorableTitleTemplate", typeof(DataTemplate), typeof(DockingManager),
  703. new FrameworkPropertyMetadata((DataTemplate)null,
  704. new PropertyChangedCallback(OnAnchorableTitleTemplateChanged),
  705. new CoerceValueCallback(CoerceAnchorableTitleTemplateValue)));
  706. /// <summary>
  707. /// Gets or sets the AnchorableTitleTemplate property. This dependency property
  708. /// indicates the data template to use for anchorables title.
  709. /// </summary>
  710. public DataTemplate AnchorableTitleTemplate
  711. {
  712. get { return (DataTemplate)GetValue(AnchorableTitleTemplateProperty); }
  713. set { SetValue(AnchorableTitleTemplateProperty, value); }
  714. }
  715. /// <summary>
  716. /// Handles changes to the AnchorableTitleTemplate property.
  717. /// </summary>
  718. private static void OnAnchorableTitleTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  719. {
  720. ((DockingManager)d).OnAnchorableTitleTemplateChanged(e);
  721. }
  722. /// <summary>
  723. /// Provides derived classes an opportunity to handle changes to the AnchorableTitleTemplate property.
  724. /// </summary>
  725. protected virtual void OnAnchorableTitleTemplateChanged(DependencyPropertyChangedEventArgs e)
  726. {
  727. }
  728. /// <summary>
  729. /// Coerces the AnchorableTitleTemplate value.
  730. /// </summary>
  731. private static object CoerceAnchorableTitleTemplateValue(DependencyObject d, object value)
  732. {
  733. if (value != null &&
  734. d.GetValue(AnchorableTitleTemplateSelectorProperty) != null)
  735. return null;
  736. return value;
  737. }
  738. #endregion
  739. #region AnchorableTitleTemplateSelector
  740. /// <summary>
  741. /// AnchorableTitleTemplateSelector Dependency Property
  742. /// </summary>
  743. public static readonly DependencyProperty AnchorableTitleTemplateSelectorProperty =
  744. DependencyProperty.Register("AnchorableTitleTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
  745. new FrameworkPropertyMetadata((DataTemplateSelector)null,
  746. new PropertyChangedCallback(OnAnchorableTitleTemplateSelectorChanged)));
  747. /// <summary>
  748. /// Gets or sets the AnchorableTitleTemplateSelector property. This dependency property
  749. /// indicates selctor to use when selecting data template for the title of anchorables.
  750. /// </summary>
  751. public DataTemplateSelector AnchorableTitleTemplateSelector
  752. {
  753. get { return (DataTemplateSelector)GetValue(AnchorableTitleTemplateSelectorProperty); }
  754. set { SetValue(AnchorableTitleTemplateSelectorProperty, value); }
  755. }
  756. /// <summary>
  757. /// Handles changes to the AnchorableTitleTemplateSelector property.
  758. /// </summary>
  759. private static void OnAnchorableTitleTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  760. {
  761. ((DockingManager)d).OnAnchorableTitleTemplateSelectorChanged(e);
  762. }
  763. /// <summary>
  764. /// Provides derived classes an opportunity to handle changes to the AnchorableTitleTemplateSelector property.
  765. /// </summary>
  766. protected virtual void OnAnchorableTitleTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
  767. {
  768. if (e.NewValue != null &&
  769. AnchorableTitleTemplate != null)
  770. AnchorableTitleTemplate = null;
  771. }
  772. #endregion
  773. #region AnchorableHeaderTemplate
  774. /// <summary>
  775. /// AnchorableHeaderTemplate Dependency Property
  776. /// </summary>
  777. public static readonly DependencyProperty AnchorableHeaderTemplateProperty =
  778. DependencyProperty.Register("AnchorableHeaderTemplate", typeof(DataTemplate), typeof(DockingManager),
  779. new FrameworkPropertyMetadata((DataTemplate)null,
  780. new PropertyChangedCallback(OnAnchorableHeaderTemplateChanged),
  781. new CoerceValueCallback(CoerceAnchorableHeaderTemplateValue)));
  782. /// <summary>
  783. /// Gets or sets the AnchorableHeaderTemplate property. This dependency property
  784. /// indicates the data template to use for anchorable templates.
  785. /// </summary>
  786. public DataTemplate AnchorableHeaderTemplate
  787. {
  788. get { return (DataTemplate)GetValue(AnchorableHeaderTemplateProperty); }
  789. set { SetValue(AnchorableHeaderTemplateProperty, value); }
  790. }
  791. /// <summary>
  792. /// Handles changes to the AnchorableHeaderTemplate property.
  793. /// </summary>
  794. private static void OnAnchorableHeaderTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  795. {
  796. ((DockingManager)d).OnAnchorableHeaderTemplateChanged(e);
  797. }
  798. /// <summary>
  799. /// Provides derived classes an opportunity to handle changes to the AnchorableHeaderTemplate property.
  800. /// </summary>
  801. protected virtual void OnAnchorableHeaderTemplateChanged(DependencyPropertyChangedEventArgs e)
  802. {
  803. }
  804. /// <summary>
  805. /// Coerces the AnchorableHeaderTemplate value.
  806. /// </summary>
  807. private static object CoerceAnchorableHeaderTemplateValue(DependencyObject d, object value)
  808. {
  809. if (value != null &&
  810. d.GetValue(AnchorableHeaderTemplateSelectorProperty) != null)
  811. return null;
  812. return value;
  813. }
  814. #endregion
  815. #region AnchorableHeaderTemplateSelector
  816. /// <summary>
  817. /// AnchorableHeaderTemplateSelector Dependency Property
  818. /// </summary>
  819. public static readonly DependencyProperty AnchorableHeaderTemplateSelectorProperty =
  820. DependencyProperty.Register("AnchorableHeaderTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
  821. new FrameworkPropertyMetadata((DataTemplateSelector)null,
  822. new PropertyChangedCallback(OnAnchorableHeaderTemplateSelectorChanged)));
  823. /// <summary>
  824. /// Gets or sets the AnchorableHeaderTemplateSelector property. This dependency property
  825. /// indicates the selector to use when selecting the data template for anchorable headers.
  826. /// </summary>
  827. public DataTemplateSelector AnchorableHeaderTemplateSelector
  828. {
  829. get { return (DataTemplateSelector)GetValue(AnchorableHeaderTemplateSelectorProperty); }
  830. set { SetValue(AnchorableHeaderTemplateSelectorProperty, value); }
  831. }
  832. /// <summary>
  833. /// Handles changes to the AnchorableHeaderTemplateSelector property.
  834. /// </summary>
  835. private static void OnAnchorableHeaderTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  836. {
  837. ((DockingManager)d).OnAnchorableHeaderTemplateSelectorChanged(e);
  838. }
  839. /// <summary>
  840. /// Provides derived classes an opportunity to handle changes to the AnchorableHeaderTemplateSelector property.
  841. /// </summary>
  842. protected virtual void OnAnchorableHeaderTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
  843. {
  844. if (e.NewValue != null)
  845. AnchorableHeaderTemplate = null;
  846. }
  847. #endregion
  848. protected override void OnGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e)
  849. {
  850. //if (e.NewFocus is Grid)
  851. // Trace.WriteLine(string.Format("DockingManager.OnGotKeyboardFocus({0})", e.NewFocus));
  852. base.OnGotKeyboardFocus(e);
  853. }
  854. protected override void OnPreviewGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e)
  855. {
  856. Trace.WriteLine(string.Format("DockingManager.OnPreviewGotKeyboardFocus({0})", e.NewFocus));
  857. base.OnPreviewGotKeyboardFocus(e);
  858. }
  859. protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
  860. {
  861. Trace.WriteLine(string.Format("DockingManager.OnPreviewLostKeyboardFocus({0})", e.OldFocus));
  862. base.OnPreviewLostKeyboardFocus(e);
  863. }
  864. protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
  865. {
  866. Trace.WriteLine(string.Format("DockingManager.OnMouseLeftButtonDown([{0}])", e.GetPosition(this)));
  867. base.OnMouseLeftButtonDown(e);
  868. }
  869. protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
  870. {
  871. //Trace.WriteLine(string.Format("DockingManager.OnMouseMove([{0}])", e.GetPosition(this)));
  872. base.OnMouseMove(e);
  873. }
  874. #region LayoutRootPanel
  875. /// <summary>
  876. /// LayoutRootPanel Dependency Property
  877. /// </summary>
  878. public static readonly DependencyProperty LayoutRootPanelProperty =
  879. DependencyProperty.Register("LayoutRootPanel", typeof(LayoutPanelControl), typeof(DockingManager),
  880. new FrameworkPropertyMetadata((LayoutPanelControl)null,
  881. new PropertyChangedCallback(OnLayoutRootPanelChanged)));
  882. /// <summary>
  883. /// Gets or sets the LayoutRootPanel property. This dependency property
  884. /// indicates the layout panel control which is attached to the Layout.Root property.
  885. /// </summary>
  886. public LayoutPanelControl LayoutRootPanel
  887. {
  888. get { return (LayoutPanelControl)GetValue(LayoutRootPanelProperty); }
  889. set { SetValue(LayoutRootPanelProperty, value); }
  890. }
  891. /// <summary>
  892. /// Handles changes to the LayoutRootPanel property.
  893. /// </summary>
  894. private static void OnLayoutRootPanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  895. {
  896. ((DockingManager)d).OnLayoutRootPanelChanged(e);
  897. }
  898. /// <summary>
  899. /// Provides derived classes an opportunity to handle changes to the LayoutRootPanel property.
  900. /// </summary>
  901. protected virtual void OnLayoutRootPanelChanged(DependencyPropertyChangedEventArgs e)
  902. {
  903. if (e.OldValue != null)
  904. InternalRemoveLogicalChild(e.OldValue);
  905. if (e.NewValue != null)
  906. InternalAddLogicalChild(e.NewValue);
  907. }
  908. #endregion
  909. #region RightSidePanel
  910. /// <summary>
  911. /// RightSidePanel Dependency Property
  912. /// </summary>
  913. public static readonly DependencyProperty RightSidePanelProperty =
  914. DependencyProperty.Register("RightSidePanel", typeof(LayoutAnchorSideControl), typeof(DockingManager),
  915. new FrameworkPropertyMetadata((LayoutAnchorSideControl)null,
  916. new PropertyChangedCallback(OnRightSidePanelChanged)));
  917. /// <summary>
  918. /// Gets or sets the RightSidePanel property. This dependency property
  919. /// indicates right side anchor panel.
  920. /// </summary>
  921. public LayoutAnchorSideControl RightSidePanel
  922. {
  923. get { return (LayoutAnchorSideControl)GetValue(RightSidePanelProperty); }
  924. set { SetValue(RightSidePanelProperty, value); }
  925. }
  926. /// <summary>
  927. /// Handles changes to the RightSidePanel property.
  928. /// </summary>
  929. private static void OnRightSidePanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  930. {
  931. ((DockingManager)d).OnRightSidePanelChanged(e);
  932. }
  933. /// <summary>
  934. /// Provides derived classes an opportunity to handle changes to the RightSidePanel property.
  935. /// </summary>
  936. protected virtual void OnRightSidePanelChanged(DependencyPropertyChangedEventArgs e)
  937. {
  938. if (e.OldValue != null)
  939. InternalRemoveLogicalChild(e.OldValue);
  940. if (e.NewValue != null)
  941. InternalAddLogicalChild(e.NewValue);
  942. }
  943. #endregion
  944. #region LeftSidePanel
  945. /// <summary>
  946. /// LeftSidePanel Dependency Property
  947. /// </summary>
  948. public static readonly DependencyProperty LeftSidePanelProperty =
  949. DependencyProperty.Register("LeftSidePanel", typeof(LayoutAnchorSideControl), typeof(DockingManager),
  950. new FrameworkPropertyMetadata((LayoutAnchorSideControl)null,
  951. new PropertyChangedCallback(OnLeftSidePanelChanged)));
  952. /// <summary>
  953. /// Gets or sets the LeftSidePanel property. This dependency property
  954. /// indicates the left side panel control.
  955. /// </summary>
  956. public LayoutAnchorSideControl LeftSidePanel
  957. {
  958. get { return (LayoutAnchorSideControl)GetValue(LeftSidePanelProperty); }
  959. set { SetValue(LeftSidePanelProperty, value); }
  960. }
  961. /// <summary>
  962. /// Handles changes to the LeftSidePanel property.
  963. /// </summary>
  964. private static void OnLeftSidePanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  965. {
  966. ((DockingManager)d).OnLeftSidePanelChanged(e);
  967. }
  968. /// <summary>
  969. /// Provides derived classes an opportunity to handle changes to the LeftSidePanel property.
  970. /// </summary>
  971. protected virtual void OnLeftSidePanelChanged(DependencyPropertyChangedEventArgs e)
  972. {
  973. if (e.OldValue != null)
  974. InternalRemoveLogicalChild(e.OldValue);
  975. if (e.NewValue != null)
  976. InternalAddLogicalChild(e.NewValue);
  977. }
  978. #endregion
  979. #region TopSidePanel
  980. /// <summary>
  981. /// TopSidePanel Dependency Property
  982. /// </summary>
  983. public static readonly DependencyProperty TopSidePanelProperty =
  984. DependencyProperty.Register("TopSidePanel", typeof(LayoutAnchorSideControl), typeof(DockingManager),
  985. new FrameworkPropertyMetadata((LayoutAnchorSideControl)null,
  986. new PropertyChangedCallback(OnTopSidePanelChanged)));
  987. /// <summary>
  988. /// Gets or sets the TopSidePanel property. This dependency property
  989. /// indicates top side control panel.
  990. /// </summary>
  991. public LayoutAnchorSideControl TopSidePanel
  992. {
  993. get { return (LayoutAnchorSideControl)GetValue(TopSidePanelProperty); }
  994. set { SetValue(TopSidePanelProperty, value); }
  995. }
  996. /// <summary>
  997. /// Handles changes to the TopSidePanel property.
  998. /// </summary>
  999. private static void OnTopSidePanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  1000. {
  1001. ((DockingManager)d).OnTopSidePanelChanged(e);
  1002. }
  1003. /// <summary>
  1004. /// Provides derived classes an opportunity to handle changes to the TopSidePanel property.
  1005. /// </summary>
  1006. protected virtual void OnTopSidePanelChanged(DependencyPropertyChangedEventArgs e)
  1007. {
  1008. if (e.OldValue != null)
  1009. InternalRemoveLogicalChild(e.OldValue);
  1010. if (e.NewValue != null)
  1011. InternalAddLogicalChild(e.NewValue);
  1012. }
  1013. #endregion
  1014. #region BottomSidePanel
  1015. /// <summary>
  1016. /// BottomSidePanel Dependency Property
  1017. /// </summary>
  1018. public static readonly DependencyProperty BottomSidePanelProperty =
  1019. DependencyProperty.Register("BottomSidePanel", typeof(LayoutAnchorSideControl), typeof(DockingManager),
  1020. new FrameworkPropertyMetadata((LayoutAnchorSideControl)null,
  1021. new PropertyChangedCallback(OnBottomSidePanelChanged)));
  1022. /// <summary>
  1023. /// Gets or sets the BottomSidePanel property. This dependency property
  1024. /// indicates bottom side panel control.
  1025. /// </summary>
  1026. public LayoutAnchorSideControl BottomSidePanel
  1027. {
  1028. get { return (LayoutAnchorSideControl)GetValue(BottomSidePanelProperty); }
  1029. set { SetValue(BottomSidePanelProperty, value); }
  1030. }
  1031. /// <summary>
  1032. /// Handles changes to the BottomSidePanel property.
  1033. /// </summary>
  1034. private static void OnBottomSidePanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  1035. {
  1036. ((DockingManager)d).OnBottomSidePanelChanged(e);
  1037. }
  1038. /// <summary>
  1039. /// Provides derived classes an opportunity to handle changes to the BottomSidePanel property.
  1040. /// </summary>
  1041. protected virtual void OnBottomSidePanelChanged(DependencyPropertyChangedEventArgs e)
  1042. {
  1043. if (e.OldValue != null)
  1044. InternalRemoveLogicalChild(e.OldValue);
  1045. if (e.NewValue != null)
  1046. InternalAddLogicalChild(e.NewValue);
  1047. }
  1048. #endregion
  1049. #region LogicalChildren
  1050. List<WeakReference> _logicalChildren = new List<WeakReference>();
  1051. protected override System.Collections.IEnumerator LogicalChildren
  1052. {
  1053. get
  1054. {
  1055. return _logicalChildren.Select(ch => ch.GetValueOrDefault<object>()).GetEnumerator();
  1056. }
  1057. }
  1058. internal void InternalAddLogicalChild(object element)
  1059. {
  1060. //System.Diagnostics.Trace.WriteLine("[{0}]InternalAddLogicalChild({1})", this, element);
  1061. #if DEBUG
  1062. if (_logicalChildren.Select(ch => ch.GetValueOrDefault<object>()).Contains(element))
  1063. new InvalidOperationException();
  1064. #endif
  1065. if (_logicalChildren.Select(ch => ch.GetValueOrDefault<object>()).Contains(element))
  1066. return;
  1067. _logicalChildren.Add(new WeakReference(element));
  1068. AddLogicalChild(element);
  1069. }
  1070. internal void InternalRemoveLogicalChild(object element)
  1071. {
  1072. //System.Diagnostics.Trace.WriteLine("[{0}]InternalRemoveLogicalChild({1})", this, element);
  1073. var wrToRemove = _logicalChildren.FirstOrDefault(ch => ch.GetValueOrDefault<object>() == element);
  1074. if (wrToRemove != null)
  1075. _logicalChildren.Remove(wrToRemove);
  1076. RemoveLogicalChild(element);
  1077. }
  1078. void ClearLogicalChildrenList()
  1079. {
  1080. foreach (var child in _logicalChildren.Select(ch => ch.GetValueOrDefault<object>()).ToArray())
  1081. RemoveLogicalChild(child);
  1082. _logicalChildren.Clear();
  1083. }
  1084. #endregion
  1085. #region AutoHide window
  1086. internal void ShowAutoHideWindow(LayoutAnchorControl anchor)
  1087. {
  1088. _autoHideWindowManager.ShowAutoHideWindow(anchor);
  1089. //if (_autohideArea == null)
  1090. // return;
  1091. //if (AutoHideWindow != null && AutoHideWindow.Model == anchor.Model)
  1092. // return;
  1093. //Trace.WriteLine("ShowAutoHideWindow()");
  1094. //_currentAutohiddenAnchor = new WeakReference(anchor);
  1095. //HideAutoHideWindow(anchor);
  1096. //SetAutoHideWindow(new LayoutAutoHideWindowControl(anchor));
  1097. //AutoHideWindow.Show();
  1098. }
  1099. internal void HideAutoHideWindow(LayoutAnchorControl anchor)
  1100. {
  1101. _autoHideWindowManager.HideAutoWindow(anchor);
  1102. }
  1103. void SetupAutoHideWindow()
  1104. {
  1105. _autohideArea = GetTemplateChild("PART_AutoHideArea") as FrameworkElement;
  1106. if (_autoHideWindowManager != null)
  1107. _autoHideWindowManager.HideAutoWindow();
  1108. else
  1109. _autoHideWindowManager = new AutoHideWindowManager(this);
  1110. if (AutoHideWindow != null)
  1111. AutoHideWindow.Dispose();
  1112. SetAutoHideWindow(new LayoutAutoHideWindowControl());
  1113. }
  1114. AutoHideWindowManager _autoHideWindowManager;
  1115. FrameworkElement _autohideArea;
  1116. internal FrameworkElement GetAutoHideAreaElement()
  1117. {
  1118. return _autohideArea;
  1119. }
  1120. #region AutoHideWindow
  1121. /// <summary>
  1122. /// AutoHideWindow Read-Only Dependency Property
  1123. /// </summary>
  1124. private static readonly DependencyPropertyKey AutoHideWindowPropertyKey
  1125. = DependencyProperty.RegisterReadOnly("AutoHideWindow", typeof(LayoutAutoHideWindowControl), typeof(DockingManager),
  1126. new FrameworkPropertyMetadata((LayoutAutoHideWindowControl)null,
  1127. new PropertyChangedCallback(OnAutoHideWindowChanged)));
  1128. public static readonly DependencyProperty AutoHideWindowProperty
  1129. = AutoHideWindowPropertyKey.DependencyProperty;
  1130. /// <summary>
  1131. /// Gets the AutoHideWindow property. This dependency property
  1132. /// indicates the currently shown autohide window.
  1133. /// </summary>
  1134. public LayoutAutoHideWindowControl AutoHideWindow
  1135. {
  1136. get { return (LayoutAutoHideWindowControl)GetValue(AutoHideWindowProperty); }
  1137. }
  1138. /// <summary>
  1139. /// Provides a secure method for setting the AutoHideWindow property.
  1140. /// This dependency property indicates the currently shown autohide window.
  1141. /// </summary>
  1142. /// <param name="value">The new value for the property.</param>
  1143. protected void SetAutoHideWindow(LayoutAutoHideWindowControl value)
  1144. {
  1145. SetValue(AutoHideWindowPropertyKey, value);
  1146. }
  1147. /// <summary>
  1148. /// Handles changes to the AutoHideWindow property.
  1149. /// </summary>
  1150. private static void OnAutoHideWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  1151. {
  1152. ((DockingManager)d).OnAutoHideWindowChanged(e);
  1153. }
  1154. /// <summary>
  1155. /// Provides derived classes an opportunity to handle changes to the AutoHideWindow property.
  1156. /// </summary>
  1157. protected virtual void OnAutoHideWindowChanged(DependencyPropertyChangedEventArgs e)
  1158. {
  1159. if (e.OldValue != null)
  1160. InternalRemoveLogicalChild(e.OldValue);
  1161. if (e.NewValue != null)
  1162. InternalAddLogicalChild(e.NewValue);
  1163. }
  1164. #endregion
  1165. #endregion
  1166. // #region AutoHide window
  1167. //WeakReference _currentAutohiddenAnchor = null;
  1168. //internal void ShowAutoHideWindow(LayoutAnchorControl anchor)
  1169. //{
  1170. // if (_autohideArea == null)
  1171. // return;
  1172. // if (AutoHideWindow != null && AutoHideWindow.Model == anchor.Model)
  1173. // return;
  1174. // Trace.WriteLine("ShowAutoHideWindow()");
  1175. // _currentAutohiddenAnchor = new WeakReference(anchor);
  1176. // HideAutoHideWindow(anchor);
  1177. // SetAutoHideWindow(new LayoutAutoHideWindowControl(anchor));
  1178. //}
  1179. //internal void HideAutoHideWindow(LayoutAnchorControl anchor)
  1180. //{
  1181. // if (AutoHideWindow != null)
  1182. // {
  1183. // if (anchor == _currentAutohiddenAnchor.GetValueOrDefault<LayoutAnchorControl>())
  1184. // {
  1185. // Trace.WriteLine("AutoHideWindow()");
  1186. // AutoHideWindow.Dispose();
  1187. // SetAutoHideWindow(null);
  1188. // }
  1189. // }
  1190. //}
  1191. //FrameworkElement _autohideArea;
  1192. //internal FrameworkElement GetAutoHideAreaElement()
  1193. //{
  1194. // return _autohideArea;
  1195. //}
  1196. //void SetupAutoHideArea()
  1197. //{
  1198. // _autohideArea = GetTemplateChild("PART_AutoHideArea") as FrameworkElement;
  1199. //}
  1200. // #region AutoHideWindow
  1201. ///// <summary>
  1202. ///// AutoHideWindow Read-Only Dependency Property
  1203. ///// </summary>
  1204. //private static readonly DependencyPropertyKey AutoHideWindowPropertyKey
  1205. // = DependencyProperty.RegisterReadOnly("AutoHideWindow", typeof(LayoutAutoHideWindowControl), typeof(DockingManager),
  1206. // new FrameworkPropertyMetadata((LayoutAutoHideWindowControl)null,
  1207. // new PropertyChangedCallback(OnAutoHideWindowChanged)));
  1208. //public static readonly DependencyProperty AutoHideWindowProperty
  1209. // = AutoHideWindowPropertyKey.DependencyProperty;
  1210. ///// <summary>
  1211. ///// Gets the AutoHideWindow property. This dependency property
  1212. ///// indicates the currently shown autohide window.
  1213. ///// </summary>
  1214. //public LayoutAutoHideWindowControl AutoHideWindow
  1215. //{
  1216. // get { return (LayoutAutoHideWindowControl)GetValue(AutoHideWindowProperty); }
  1217. //}
  1218. ///// <summary>
  1219. ///// Provides a secure method for setting the AutoHideWindow property.
  1220. ///// This dependency property indicates the currently shown autohide window.
  1221. ///// </summary>
  1222. ///// <param name="value">The new value for the property.</param>
  1223. //protected void SetAutoHideWindow(LayoutAutoHideWindowControl value)
  1224. //{
  1225. // SetValue(AutoHideWindowPropertyKey, value);
  1226. //}
  1227. ///// <summary>
  1228. ///// Handles changes to the AutoHideWindow property.
  1229. ///// </summary>
  1230. //private static void OnAutoHideWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  1231. //{
  1232. // ((DockingManager)d).OnAutoHideWindowChanged(e);
  1233. //}
  1234. ///// <summary>
  1235. ///// Provides derived classes an opportunity to handle changes to the AutoHideWindow property.
  1236. ///// </summary>
  1237. //protected virtual void OnAutoHideWindowChanged(DependencyPropertyChangedEventArgs e)
  1238. //{
  1239. // if (e.OldValue != null)
  1240. // ((ILogicalChildrenContainer)this).InternalRemoveLogicalChild(e.OldValue);
  1241. // if (e.NewValue != null)
  1242. // ((ILogicalChildrenContainer)this).InternalAddLogicalChild(e.NewValue);
  1243. //}
  1244. // #endregion
  1245. // #endregion
  1246. #region Floating Windows
  1247. List<LayoutFloatingWindowControl> _fwList = new List<LayoutFloatingWindowControl>();
  1248. internal void StartDraggingFloatingWindowForContent(LayoutContent contentModel, bool startDrag = true)
  1249. {
  1250. if (!contentModel.CanFloat)
  1251. return;
  1252. var contentModelAsAnchorable = contentModel as LayoutAnchorable;
  1253. if (contentModelAsAnchorable != null &&
  1254. contentModelAsAnchorable.IsAutoHidden)
  1255. contentModelAsAnchorable.ToggleAutoHide();
  1256. var parentPane = contentModel.Parent as ILayoutPane;
  1257. var parentPaneAsPositionableElement = contentModel.Parent as ILayoutPositionableElement;
  1258. var parentPaneAsWithActualSize = contentModel.Parent as ILayoutPositionableElementWithActualSize;
  1259. var contentModelParentChildrenIndex = parentPane.Children.ToList().IndexOf(contentModel);
  1260. if (contentModel.FindParent<LayoutFloatingWindow>() == null)
  1261. {
  1262. ((ILayoutPreviousContainer)contentModel).PreviousContainer = parentPane;
  1263. contentModel.PreviousContainerIndex = contentModelParentChildrenIndex;
  1264. }
  1265. parentPane.RemoveChildAt(contentModelParentChildrenIndex);
  1266. double fwWidth = contentModel.FloatingWidth;
  1267. double fwHeight = contentModel.FloatingHeight;
  1268. if (fwWidth == 0.0)
  1269. fwWidth = parentPaneAsPositionableElement.FloatingWidth;
  1270. if (fwHeight == 0.0)
  1271. fwHeight = parentPaneAsPositionableElement.FloatingHeight;
  1272. if (fwWidth == 0.0)
  1273. fwWidth = parentPaneAsWithActualSize.ActualWidth;
  1274. if (fwHeight == 0.0)
  1275. fwHeight = parentPaneAsWithActualSize.ActualHeight;
  1276. LayoutFloatingWindow fw;
  1277. LayoutFloatingWindowControl fwc;
  1278. if (contentModel is LayoutAnchorable)
  1279. {
  1280. var anchorableContent = contentModel as LayoutAnchorable;
  1281. fw = new LayoutAnchorableFloatingWindow()
  1282. {
  1283. RootPanel = new LayoutAnchorablePaneGroup(
  1284. new LayoutAnchorablePane(anchorableContent)
  1285. {
  1286. DockWidth = parentPaneAsPositionableElement.DockWidth,
  1287. DockHeight = parentPaneAsPositionableElement.DockHeight,
  1288. DockMinHeight = parentPaneAsPositionableElement.DockMinHeight,
  1289. DockMinWidth = parentPaneAsPositionableElement.DockMinWidth,
  1290. FloatingLeft = parentPaneAsPositionableElement.FloatingLeft,
  1291. FloatingTop = parentPaneAsPositionableElement.FloatingTop,
  1292. FloatingWidth = parentPaneAsPositionableElement.FloatingWidth,
  1293. FloatingHeight = parentPaneAsPositionableElement.FloatingHeight,
  1294. })
  1295. };
  1296. Layout.FloatingWindows.Add(fw);
  1297. fwc = new LayoutAnchorableFloatingWindowControl(
  1298. fw as LayoutAnchorableFloatingWindow)
  1299. {
  1300. Width = fwWidth,
  1301. Height = fwHeight,
  1302. Left = contentModel.FloatingLeft,
  1303. Top = contentModel.FloatingTop
  1304. };
  1305. }
  1306. else
  1307. {
  1308. var anchorableDocument = contentModel as LayoutDocument;
  1309. fw = new LayoutDocumentFloatingWindow()
  1310. {
  1311. RootDocument = anchorableDocument
  1312. };
  1313. Layout.FloatingWindows.Add(fw);
  1314. fwc = new LayoutDocumentFloatingWindowControl(
  1315. fw as LayoutDocumentFloatingWindow)
  1316. {
  1317. Width = fwWidth,
  1318. Height = fwHeight,
  1319. Left = contentModel.FloatingLeft,
  1320. Top = contentModel.FloatingTop
  1321. };
  1322. }
  1323. //fwc.Owner = Window.GetWindow(this);
  1324. //fwc.SetParentToMainWindowOf(this);
  1325. _fwList.Add(fwc);
  1326. Layout.CollectGarbage();
  1327. UpdateLayout();
  1328. Dispatcher.BeginInvoke(new Action(() =>
  1329. {
  1330. if (startDrag)
  1331. fwc.AttachDrag();
  1332. fwc.Show();
  1333. }), DispatcherPriority.Send);
  1334. }
  1335. internal void StartDraggingFloatingWindowForPane(LayoutAnchorablePane paneModel)
  1336. {
  1337. if (paneModel.Children.Any(c => !c.CanFloat))
  1338. return;
  1339. var paneAsPositionableElement = paneModel as ILayoutPositionableElement;
  1340. var paneAsWithActualSize = paneModel as ILayoutPositionableElementWithActualSize;
  1341. double fwWidth = paneAsPositionableElement.FloatingWidth;
  1342. double fwHeight = paneAsPositionableElement.FloatingHeight;
  1343. double fwLeft = paneAsPositionableElement.FloatingLeft;
  1344. double fwTop = paneAsPositionableElement.FloatingTop;
  1345. if (fwWidth == 0.0)
  1346. fwWidth = paneAsWithActualSize.ActualWidth;
  1347. if (fwHeight == 0.0)
  1348. fwHeight = paneAsWithActualSize.ActualHeight;
  1349. var destPane = new LayoutAnchorablePane()
  1350. {
  1351. DockWidth = paneAsPositionableElement.DockWidth,
  1352. DockHeight = paneAsPositionableElement.DockHeight,
  1353. DockMinHeight = paneAsPositionableElement.DockMinHeight,
  1354. DockMinWidth = paneAsPositionableElement.DockMinWidth,
  1355. FloatingLeft = paneAsPositionableElement.FloatingLeft,
  1356. FloatingTop = paneAsPositionableElement.FloatingTop,
  1357. FloatingWidth = paneAsPositionableElement.FloatingWidth,
  1358. FloatingHeight = paneAsPositionableElement.FloatingHeight,
  1359. };
  1360. bool savePreviousContainer = paneModel.FindParent<LayoutFloatingWindow>() == null;
  1361. int currentSelectedContentIndex = paneModel.SelectedContentIndex;
  1362. while (paneModel.Children.Count > 0)
  1363. {
  1364. var contentModel = paneModel.Children[paneModel.Children.Count - 1] as LayoutAnchorable;
  1365. if (savePreviousContainer)
  1366. {
  1367. var contentModelAsPreviousContainer = contentModel as ILayoutPreviousContainer;
  1368. contentModelAsPreviousContainer.PreviousContainer = paneModel;
  1369. contentModel.PreviousContainerIndex = paneModel.Children.Count - 1;
  1370. }
  1371. paneModel.RemoveChildAt(paneModel.Children.Count - 1);
  1372. destPane.Children.Insert(0, contentModel);
  1373. }
  1374. if (destPane.Children.Count > 0)
  1375. {
  1376. destPane.SelectedContentIndex = currentSelectedContentIndex;
  1377. }
  1378. LayoutFloatingWindow fw;
  1379. LayoutFloatingWindowControl fwc;
  1380. fw = new LayoutAnchorableFloatingWindow()
  1381. {
  1382. RootPanel = new LayoutAnchorablePaneGroup(
  1383. destPane)
  1384. {
  1385. DockHeight = destPane.DockHeight,
  1386. DockWidth = destPane.DockWidth,
  1387. DockMinHeight = destPane.DockMinHeight,
  1388. DockMinWidth = destPane.DockMinWidth,
  1389. }
  1390. };
  1391. Layout.FloatingWindows.Add(fw);
  1392. fwc = new LayoutAnchorableFloatingWindowControl(
  1393. fw as LayoutAnchorableFloatingWindow)
  1394. {
  1395. Width = fwWidth,
  1396. Height = fwHeight
  1397. };
  1398. //fwc.Owner = Window.GetWindow(this);
  1399. //fwc.SetParentToMainWindowOf(this);
  1400. _fwList.Add(fwc);
  1401. Layout.CollectGarbage();
  1402. InvalidateArrange();
  1403. fwc.AttachDrag();
  1404. fwc.Show();
  1405. }
  1406. internal IEnumerable<LayoutFloatingWindowControl> GetFloatingWindowsByZOrder()
  1407. {
  1408. var parentWindow = Window.GetWindow(this);
  1409. if (parentWindow == null)
  1410. yield break;
  1411. IntPtr windowParentHanlde = new WindowInteropHelper(parentWindow).Handle;
  1412. IntPtr currentHandle = Win32Helper.GetWindow(windowParentHanlde, (uint)Win32Helper.GetWindow_Cmd.GW_HWNDFIRST);
  1413. while (currentHandle != IntPtr.Zero)
  1414. {
  1415. LayoutFloatingWindowControl ctrl = _fwList.FirstOrDefault(fw => new WindowInteropHelper(fw).Handle == currentHandle);
  1416. if (ctrl != null && ctrl.Model.Root.Manager == this)
  1417. yield return ctrl;
  1418. currentHandle = Win32Helper.GetWindow(currentHandle, (uint)Win32Helper.GetWindow_Cmd.GW_HWNDNEXT);
  1419. }
  1420. }
  1421. internal void RemoveFloatingWindow(LayoutFloatingWindowControl floatingWindow)
  1422. {
  1423. _fwList.Remove(floatingWindow);
  1424. }
  1425. public IEnumerable<LayoutFloatingWindowControl> FloatingWindows
  1426. {
  1427. get { return _fwList; }
  1428. }
  1429. #endregion
  1430. #region OverlayWindow
  1431. bool IOverlayWindowHost.HitTest(Point dragPoint)
  1432. {
  1433. Rect detectionRect = new Rect(this.PointToScreenDPIWithoutFlowDirection(new Point()), this.TransformActualSizeToAncestor());
  1434. return detectionRect.Contains(dragPoint);
  1435. }
  1436. DockingManager IOverlayWindowHost.Manager
  1437. {
  1438. get { return this; }
  1439. }
  1440. OverlayWindow _overlayWindow = null;
  1441. void CreateOverlayWindow()
  1442. {
  1443. if (_overlayWindow == null)
  1444. {
  1445. _overlayWindow = new OverlayWindow(this);
  1446. }
  1447. Rect rectWindow = new Rect(this.PointToScreenDPIWithoutFlowDirection(new Point()), this.TransformActualSizeToAncestor());
  1448. _overlayWindow.Left = rectWindow.Left;
  1449. _overlayWindow.Top = rectWindow.Top;
  1450. _overlayWindow.Width = rectWindow.Width;
  1451. _overlayWindow.Height = rectWindow.Height;
  1452. }
  1453. void DestroyOverlayWindow()
  1454. {
  1455. if (_overlayWindow != null)
  1456. {
  1457. _overlayWindow.Close();
  1458. _overlayWindow = null;
  1459. }
  1460. }
  1461. IOverlayWindow IOverlayWindowHost.ShowOverlayWindow(LayoutFloatingWindowControl draggingWindow)
  1462. {
  1463. //Trace.WriteLine("ShowOverlayWindow");
  1464. CreateOverlayWindow();
  1465. _overlayWindow.Owner = draggingWindow;
  1466. _overlayWindow.EnableDropTargets();
  1467. _overlayWindow.Show();
  1468. return _overlayWindow;
  1469. }
  1470. void IOverlayWindowHost.HideOverlayWindow()
  1471. {
  1472. //Trace.WriteLine("HideOverlayWindow");
  1473. _areas = null;
  1474. _overlayWindow.Owner = null;
  1475. _overlayWindow.HideDropTargets();
  1476. }
  1477. List<IDropArea> _areas = null;
  1478. IEnumerable<IDropArea> IOverlayWindowHost.GetDropAreas(LayoutFloatingWindowControl draggingWindow)
  1479. {
  1480. if (_areas != null)
  1481. return _areas;
  1482. bool isDraggingDocuments = draggingWindow.Model is LayoutDocumentFloatingWindow;
  1483. _areas = new List<IDropArea>();
  1484. if (!isDraggingDocuments)
  1485. {
  1486. _areas.Add(new DropArea<DockingManager>(
  1487. this,
  1488. DropAreaType.DockingManager));
  1489. foreach (var areaHost in this.FindVisualChildren<LayoutAnchorablePaneControl>())
  1490. {
  1491. if (areaHost.Model.Descendents().Any())
  1492. {
  1493. _areas.Add(new DropArea<LayoutAnchorablePaneControl>(
  1494. areaHost,
  1495. DropAreaType.AnchorablePane));
  1496. }
  1497. }
  1498. }
  1499. foreach (var areaHost in this.FindVisualChildren<LayoutDocumentPaneControl>())
  1500. {
  1501. _areas.Add(new DropArea<LayoutDocumentPaneControl>(
  1502. areaHost,
  1503. DropAreaType.DocumentPane));
  1504. }
  1505. foreach (var areaHost in this.FindVisualChildren<LayoutDocumentPaneGroupControl>())
  1506. {
  1507. var documentGroupModel = areaHost.Model as LayoutDocumentPaneGroup;
  1508. if (documentGroupModel.Children.Where(c => c.IsVisible).Count() == 0)
  1509. {
  1510. _areas.Add(new DropArea<LayoutDocumentPaneGroupControl>(
  1511. areaHost,
  1512. DropAreaType.DocumentPaneGroup));
  1513. }
  1514. }
  1515. return _areas;
  1516. }
  1517. protected override Size ArrangeOverride(Size arrangeBounds)
  1518. {
  1519. _areas = null;
  1520. return base.ArrangeOverride(arrangeBounds);
  1521. }
  1522. #endregion
  1523. #region LayoutDocument & LayoutAnchorable Templates
  1524. #region LayoutItemTemplate
  1525. /// <summary>
  1526. /// LayoutItemTemplate Dependency Property
  1527. /// </summary>
  1528. public static readonly DependencyProperty LayoutItemTemplateProperty =
  1529. DependencyProperty.Register("LayoutItemTemplate", typeof(DataTemplate), typeof(DockingManager),
  1530. new FrameworkPropertyMetadata((DataTemplate)null,
  1531. new PropertyChangedCallback(OnLayoutItemTemplateChanged)));
  1532. /// <summary>
  1533. /// Gets or sets the AnchorableTemplate property. This dependency property
  1534. /// indicates the template to use to render anchorable and document contents.
  1535. /// </summary>
  1536. public DataTemplate LayoutItemTemplate
  1537. {
  1538. get { return (DataTemplate)GetValue(LayoutItemTemplateProperty); }
  1539. set { SetValue(LayoutItemTemplateProperty, value); }
  1540. }
  1541. /// <summary>
  1542. /// Handles changes to the AnchorableTemplate property.
  1543. /// </summary>
  1544. private static void OnLayoutItemTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  1545. {
  1546. ((DockingManager)d).OnLayoutItemTemplateChanged(e);
  1547. }
  1548. /// <summary>
  1549. /// Provides derived classes an opportunity to handle changes to the AnchorableTemplate property.
  1550. /// </summary>
  1551. protected virtual void OnLayoutItemTemplateChanged(DependencyPropertyChangedEventArgs e)
  1552. {
  1553. }
  1554. #endregion
  1555. #region LayoutItemTemplateSelector
  1556. /// <summary>
  1557. /// LayoutItemTemplateSelector Dependency Property
  1558. /// </summary>
  1559. public static readonly DependencyProperty LayoutItemTemplateSelectorProperty =
  1560. DependencyProperty.Register("LayoutItemTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
  1561. new FrameworkPropertyMetadata((DataTemplateSelector)null,
  1562. new PropertyChangedCallback(OnLayoutItemTemplateSelectorChanged)));
  1563. /// <summary>
  1564. /// Gets or sets the LayoutItemTemplateSelector property. This dependency property
  1565. /// indicates selector object to use for anchorable templates.
  1566. /// </summary>
  1567. public DataTemplateSelector LayoutItemTemplateSelector
  1568. {
  1569. get { return (DataTemplateSelector)GetValue(LayoutItemTemplateSelectorProperty); }
  1570. set { SetValue(LayoutItemTemplateSelectorProperty, value); }
  1571. }
  1572. /// <summary>
  1573. /// Handles changes to the LayoutItemTemplateSelector property.
  1574. /// </summary>
  1575. private static void OnLayoutItemTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  1576. {
  1577. ((DockingManager)d).OnLayoutItemTemplateSelectorChanged(e);
  1578. }
  1579. /// <summary>
  1580. /// Provides derived classes an opportunity to handle changes to the LayoutItemTemplateSelector property.
  1581. /// </summary>
  1582. protected virtual void OnLayoutItemTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
  1583. {
  1584. }
  1585. #endregion
  1586. #endregion
  1587. #region DocumentsSource
  1588. /// <summary>
  1589. /// DocumentsSource Dependency Property
  1590. /// </summary>
  1591. public static readonly DependencyProperty DocumentsSourceProperty =
  1592. DependencyProperty.Register("DocumentsSource", typeof(IEnumerable), typeof(DockingManager),
  1593. new FrameworkPropertyMetadata((IEnumerable)null,
  1594. new PropertyChangedCallback(OnDocumentsSourceChanged)));
  1595. /// <summary>
  1596. /// Gets or sets the DocumentsSource property. This dependency property
  1597. /// indicates the source collection of documents.
  1598. /// </summary>
  1599. public IEnumerable DocumentsSource
  1600. {
  1601. get { return (IEnumerable)GetValue(DocumentsSourceProperty); }
  1602. set { SetValue(DocumentsSourceProperty, value); }
  1603. }
  1604. /// <summary>
  1605. /// Handles changes to the DocumentsSource property.
  1606. /// </summary>
  1607. private static void OnDocumentsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  1608. {
  1609. ((DockingManager)d).OnDocumentsSourceChanged(e);
  1610. }
  1611. /// <summary>
  1612. /// Provides derived classes an opportunity to handle changes to the DocumentsSource property.
  1613. /// </summary>
  1614. protected virtual void OnDocumentsSourceChanged(DependencyPropertyChangedEventArgs e)
  1615. {
  1616. DetachDocumentsSource(Layout, e.OldValue as IEnumerable);
  1617. AttachDocumentsSource(Layout, e.NewValue as IEnumerable);
  1618. }
  1619. void AttachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource)
  1620. {
  1621. if (documentsSource == null)
  1622. return;
  1623. if (layout == null)
  1624. return;
  1625. //if (layout.Descendents().OfType<LayoutDocument>().Any())
  1626. // throw new InvalidOperationException("Unable to set the DocumentsSource property if LayoutDocument objects are already present in the model");
  1627. var documentsImported = layout.Descendents().OfType<LayoutDocument>().Select(d => d.Content).ToArray();
  1628. var documents = documentsSource as IEnumerable;
  1629. var listOfDocumentsToImport = new List<object>(documents.OfType<object>());
  1630. foreach (var document in listOfDocumentsToImport.ToArray())
  1631. {
  1632. if (documentsImported.Contains(document))
  1633. listOfDocumentsToImport.Remove(document);
  1634. }
  1635. LayoutDocumentPane documentPane = null;
  1636. if (layout.LastFocusedDocument != null)
  1637. {
  1638. documentPane = layout.LastFocusedDocument.Parent as LayoutDocumentPane;
  1639. }
  1640. if (documentPane == null)
  1641. {
  1642. documentPane = layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();
  1643. }
  1644. //if (documentPane == null)
  1645. // throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");
  1646. _suspendLayoutItemCreation = true;
  1647. foreach (var documentContentToImport in listOfDocumentsToImport)
  1648. {
  1649. //documentPane.Children.Add(new LayoutDocument() { Content = documentToImport });
  1650. var documentToImport = new LayoutDocument()
  1651. {
  1652. Content = documentContentToImport
  1653. };
  1654. bool added = false;
  1655. if (LayoutUpdateStrategy != null)
  1656. {
  1657. added = LayoutUpdateStrategy.BeforeInsertDocument(layout, documentToImport, documentPane);
  1658. }
  1659. if (!added)
  1660. {
  1661. if (documentPane == null)
  1662. throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");
  1663. documentPane.Children.Add(documentToImport);
  1664. added = true;
  1665. }
  1666. if (LayoutUpdateStrategy != null)
  1667. LayoutUpdateStrategy.AfterInsertDocument(layout, documentToImport);
  1668. CreateDocumentLayoutItem(documentToImport);
  1669. }
  1670. _suspendLayoutItemCreation = true;
  1671. var documentsSourceAsNotifier = documentsSource as INotifyCollectionChanged;
  1672. if (documentsSourceAsNotifier != null)
  1673. documentsSourceAsNotifier.CollectionChanged += new NotifyCollectionChangedEventHandler(documentsSourceElementsChanged);
  1674. }
  1675. internal bool SuspendDocumentsSourceBinding = false;
  1676. void documentsSourceElementsChanged(object sender, NotifyCollectionChangedEventArgs e)
  1677. {
  1678. if (Layout == null)
  1679. return;
  1680. //When deserializing documents are created automatically by the deserializer
  1681. if (SuspendDocumentsSourceBinding)
  1682. return;
  1683. //handle remove
  1684. if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove ||
  1685. e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)
  1686. {
  1687. if (e.OldItems != null)
  1688. {
  1689. var documentsToRemove = Layout.Descendents().OfType<LayoutDocument>().Where(d => e.OldItems.Contains(d.Content)).ToArray();
  1690. foreach (var documentToRemove in documentsToRemove)
  1691. {
  1692. (documentToRemove.Parent as ILayoutContainer).RemoveChild(
  1693. documentToRemove);
  1694. }
  1695. }
  1696. }
  1697. //handle add
  1698. if (e.NewItems != null &&
  1699. (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add ||
  1700. e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace))
  1701. {
  1702. if (e.NewItems != null)
  1703. {
  1704. LayoutDocumentPane documentPane = null;
  1705. if (Layout.LastFocusedDocument != null)
  1706. {
  1707. documentPane = Layout.LastFocusedDocument.Parent as LayoutDocumentPane;
  1708. }
  1709. if (documentPane == null)
  1710. {
  1711. documentPane = Layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();
  1712. }
  1713. //if (documentPane == null)
  1714. // throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");
  1715. _suspendLayoutItemCreation = true;
  1716. foreach (var documentContentToImport in e.NewItems)
  1717. {
  1718. var documentToImport = new LayoutDocument()
  1719. {
  1720. Content = documentContentToImport
  1721. };
  1722. bool added = false;
  1723. if (LayoutUpdateStrategy != null)
  1724. {
  1725. added = LayoutUpdateStrategy.BeforeInsertDocument(Layout, documentToImport, documentPane);
  1726. }
  1727. if (!added)
  1728. {
  1729. if (documentPane == null)
  1730. throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");
  1731. documentPane.Children.Add(documentToImport);
  1732. added = true;
  1733. }
  1734. if (LayoutUpdateStrategy != null)
  1735. {
  1736. LayoutUpdateStrategy.AfterInsertDocument(Layout, documentToImport);
  1737. }
  1738. var root = documentToImport.Root;
  1739. if (root != null && root.Manager == this)
  1740. {
  1741. CreateDocumentLayoutItem(documentToImport);
  1742. }
  1743. }
  1744. _suspendLayoutItemCreation = false;
  1745. }
  1746. }
  1747. if (e.Action == NotifyCollectionChangedAction.Reset)
  1748. {
  1749. //NOTE: I'm going to clear every document present in layout but
  1750. //some documents may have been added directly to the layout, for now I clear them too
  1751. var documentsToRemove = Layout.Descendents().OfType<LayoutDocument>().ToArray();
  1752. foreach (var documentToRemove in documentsToRemove)
  1753. {
  1754. (documentToRemove.Parent as ILayoutContainer).RemoveChild(
  1755. documentToRemove);
  1756. }
  1757. }
  1758. if (Layout != null)
  1759. {
  1760. Layout.CollectGarbage();
  1761. }
  1762. }
  1763. void DetachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource)
  1764. {
  1765. if (documentsSource == null)
  1766. return;
  1767. if (layout == null)
  1768. return;
  1769. var documentsToRemove = layout.Descendents().OfType<LayoutDocument>()
  1770. .Where(d => documentsSource.Contains(d.Content)).ToArray();
  1771. foreach (var documentToRemove in documentsToRemove)
  1772. {
  1773. (documentToRemove.Parent as ILayoutContainer).RemoveChild(
  1774. documentToRemove);
  1775. }
  1776. var documentsSourceAsNotifier = documentsSource as INotifyCollectionChanged;
  1777. if (documentsSourceAsNotifier != null)
  1778. documentsSourceAsNotifier.CollectionChanged -= new NotifyCollectionChangedEventHandler(documentsSourceElementsChanged);
  1779. }
  1780. #endregion
  1781. #region DocumentCloseCommand
  1782. internal void _ExecuteCloseCommand(LayoutDocument document)
  1783. {
  1784. if (DocumentClosing != null)
  1785. {
  1786. var evargs = new DocumentClosingEventArgs(document);
  1787. DocumentClosing(this, evargs);
  1788. if (evargs.Cancel)
  1789. return;
  1790. }
  1791. if (!document.TestCanClose())
  1792. return;
  1793. document.CloseInternal();
  1794. if (DocumentClosed != null)
  1795. {
  1796. var evargs = new DocumentClosedEventArgs(document);
  1797. DocumentClosed(this, evargs);
  1798. }
  1799. }
  1800. /// <summary>
  1801. /// Event fired when a document is about to be closed
  1802. /// </summary>
  1803. /// <remarks>Subscribers have the opportuniy to cancel the operation.</remarks>
  1804. public event EventHandler<DocumentClosingEventArgs> DocumentClosing;
  1805. /// <summary>
  1806. /// Event fired after a document is closed
  1807. /// </summary>
  1808. public event EventHandler<DocumentClosedEventArgs> DocumentClosed;
  1809. #endregion
  1810. internal void _ExecuteCloseAllButThisCommand(LayoutContent contentSelected)
  1811. {
  1812. foreach (var contentToClose in Layout.Descendents().OfType<LayoutContent>().Where(d => d != contentSelected && (d.Parent is LayoutDocumentPane || d.Parent is LayoutDocumentFloatingWindow)).ToArray())
  1813. {
  1814. if (!contentToClose.CanClose)
  1815. continue;
  1816. var layoutItem = GetLayoutItemFromModel(contentToClose);
  1817. if (layoutItem.CloseCommand != null)
  1818. {
  1819. if (layoutItem.CloseCommand.CanExecute(null))
  1820. layoutItem.CloseCommand.Execute(null);
  1821. }
  1822. else
  1823. {
  1824. if (contentToClose is LayoutDocument)
  1825. _ExecuteCloseCommand(contentToClose as LayoutDocument);
  1826. else if (contentToClose is LayoutAnchorable)
  1827. _ExecuteCloseCommand(contentToClose as LayoutAnchorable);
  1828. }
  1829. }
  1830. }
  1831. #region DocumentContextMenu
  1832. /// <summary>
  1833. /// DocumentContextMenu Dependency Property
  1834. /// </summary>
  1835. public static readonly DependencyProperty DocumentContextMenuProperty =
  1836. DependencyProperty.Register("DocumentContextMenu", typeof(ContextMenu), typeof(DockingManager),
  1837. new FrameworkPropertyMetadata((ContextMenu)null));
  1838. /// <summary>
  1839. /// Gets or sets the DocumentContextMenu property. This dependency property
  1840. /// indicates context menu to show for documents.
  1841. /// </summary>
  1842. public ContextMenu DocumentContextMenu
  1843. {
  1844. get { return (ContextMenu)GetValue(DocumentContextMenuProperty); }
  1845. set { SetValue(DocumentContextMenuProperty, value); }
  1846. }
  1847. #endregion
  1848. #region AnchorablesSource
  1849. /// <summary>
  1850. /// AnchorablesSource Dependency Property
  1851. /// </summary>
  1852. public static readonly DependencyProperty AnchorablesSourceProperty =
  1853. DependencyProperty.Register("AnchorablesSource", typeof(IEnumerable), typeof(DockingManager),
  1854. new FrameworkPropertyMetadata((IEnumerable)null,
  1855. new PropertyChangedCallback(OnAnchorablesSourceChanged)));
  1856. /// <summary>
  1857. /// Gets or sets the AnchorablesSource property. This dependency property
  1858. /// indicates source collection of anchorables.
  1859. /// </summary>
  1860. public IEnumerable AnchorablesSource
  1861. {
  1862. get { return (IEnumerable)GetValue(AnchorablesSourceProperty); }
  1863. set { SetValue(AnchorablesSourceProperty, value); }
  1864. }
  1865. /// <summary>
  1866. /// Handles changes to the AnchorablesSource property.
  1867. /// </summary>
  1868. private static void OnAnchorablesSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  1869. {
  1870. ((DockingManager)d).OnAnchorablesSourceChanged(e);
  1871. }
  1872. /// <summary>
  1873. /// Provides derived classes an opportunity to handle changes to the AnchorablesSource property.
  1874. /// </summary>
  1875. protected virtual void OnAnchorablesSourceChanged(DependencyPropertyChangedEventArgs e)
  1876. {
  1877. DetachAnchorablesSource(Layout, e.OldValue as IEnumerable);
  1878. AttachAnchorablesSource(Layout, e.NewValue as IEnumerable);
  1879. }
  1880. void AttachAnchorablesSource(LayoutRoot layout, IEnumerable anchorablesSource)
  1881. {
  1882. if (anchorablesSource == null)
  1883. return;
  1884. if (layout == null)
  1885. return;
  1886. //if (layout.Descendents().OfType<LayoutAnchorable>().Any())
  1887. // throw new InvalidOperationException("Unable to set the AnchorablesSource property if LayoutAnchorable objects are already present in the model");
  1888. var anchorablesImported = layout.Descendents().OfType<LayoutAnchorable>().Select(d => d.Content).ToArray();
  1889. var anchorables = anchorablesSource as IEnumerable;
  1890. var listOfAnchorablesToImport = new List<object>(anchorables.OfType<object>());
  1891. foreach (var document in listOfAnchorablesToImport.ToArray())
  1892. {
  1893. if (anchorablesImported.Contains(document))
  1894. listOfAnchorablesToImport.Remove(document);
  1895. }
  1896. LayoutAnchorablePane anchorablePane = null;
  1897. if (layout.ActiveContent != null)
  1898. {
  1899. //look for active content parent pane
  1900. anchorablePane = layout.ActiveContent.Parent as LayoutAnchorablePane;
  1901. }
  1902. if (anchorablePane == null)
  1903. {
  1904. //look for a pane on the right side
  1905. anchorablePane = layout.Descendents().OfType<LayoutAnchorablePane>().Where(pane => !pane.IsHostedInFloatingWindow && pane.GetSide() == AnchorSide.Right).FirstOrDefault();
  1906. }
  1907. if (anchorablePane == null)
  1908. {
  1909. //look for an available pane
  1910. anchorablePane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault();
  1911. }
  1912. _suspendLayoutItemCreation = true;
  1913. foreach (var anchorableContentToImport in listOfAnchorablesToImport)
  1914. {
  1915. var anchorableToImport = new LayoutAnchorable()
  1916. {
  1917. Content = anchorableContentToImport
  1918. };
  1919. bool added = false;
  1920. if (LayoutUpdateStrategy != null)
  1921. {
  1922. added = LayoutUpdateStrategy.BeforeInsertAnchorable(layout, anchorableToImport, anchorablePane);
  1923. }
  1924. if (!added)
  1925. {
  1926. if (anchorablePane == null)
  1927. {
  1928. var mainLayoutPanel = new LayoutPanel() { Orientation = Orientation.Horizontal };
  1929. if (layout.RootPanel != null)
  1930. {
  1931. mainLayoutPanel.Children.Add(layout.RootPanel);
  1932. }
  1933. layout.RootPanel = mainLayoutPanel;
  1934. anchorablePane = new LayoutAnchorablePane() { DockWidth = new GridLength(200.0, GridUnitType.Pixel) };
  1935. mainLayoutPanel.Children.Add(anchorablePane);
  1936. }
  1937. anchorablePane.Children.Add(anchorableToImport);
  1938. added = true;
  1939. }
  1940. if (LayoutUpdateStrategy != null)
  1941. LayoutUpdateStrategy.AfterInsertAnchorable(layout, anchorableToImport);
  1942. CreateAnchorableLayoutItem(anchorableToImport);
  1943. }
  1944. _suspendLayoutItemCreation = false;
  1945. var anchorablesSourceAsNotifier = anchorablesSource as INotifyCollectionChanged;
  1946. if (anchorablesSourceAsNotifier != null)
  1947. anchorablesSourceAsNotifier.CollectionChanged += new NotifyCollectionChangedEventHandler(anchorablesSourceElementsChanged);
  1948. }
  1949. internal bool SuspendAnchorablesSourceBinding = false;
  1950. void anchorablesSourceElementsChanged(object sender, NotifyCollectionChangedEventArgs e)
  1951. {
  1952. if (Layout == null)
  1953. return;
  1954. //When deserializing documents are created automatically by the deserializer
  1955. if (SuspendAnchorablesSourceBinding)
  1956. return;
  1957. //handle remove
  1958. if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove ||
  1959. e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)
  1960. {
  1961. if (e.OldItems != null)
  1962. {
  1963. var anchorablesToRemove = Layout.Descendents().OfType<LayoutAnchorable>().Where(d => e.OldItems.Contains(d.Content)).ToArray();
  1964. foreach (var anchorableToRemove in anchorablesToRemove)
  1965. {
  1966. (anchorableToRemove.Parent as ILayoutContainer).RemoveChild(
  1967. anchorableToRemove);
  1968. }
  1969. }
  1970. }
  1971. //handle add
  1972. if (e.NewItems != null &&
  1973. (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add ||
  1974. e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace))
  1975. {
  1976. if (e.NewItems != null)
  1977. {
  1978. LayoutAnchorablePane anchorablePane = null;
  1979. if (Layout.ActiveContent != null)
  1980. {
  1981. //look for active content parent pane
  1982. anchorablePane = Layout.ActiveContent.Parent as LayoutAnchorablePane;
  1983. }
  1984. if (anchorablePane == null)
  1985. {
  1986. //look for a pane on the right side
  1987. anchorablePane = Layout.Descendents().OfType<LayoutAnchorablePane>().Where(pane => !pane.IsHostedInFloatingWindow && pane.GetSide() == AnchorSide.Right).FirstOrDefault();
  1988. }
  1989. if (anchorablePane == null)
  1990. {
  1991. //look for an available pane
  1992. anchorablePane = Layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault();
  1993. }
  1994. _suspendLayoutItemCreation = true;
  1995. foreach (var anchorableContentToImport in e.NewItems)
  1996. {
  1997. var anchorableToImport = new LayoutAnchorable()
  1998. {
  1999. Content = anchorableContentToImport
  2000. };
  2001. bool added = false;
  2002. if (LayoutUpdateStrategy != null)
  2003. {
  2004. added = LayoutUpdateStrategy.BeforeInsertAnchorable(Layout, anchorableToImport, anchorablePane);
  2005. }
  2006. if (!added)
  2007. {
  2008. if (anchorablePane == null)
  2009. {
  2010. var mainLayoutPanel = new LayoutPanel() { Orientation = Orientation.Horizontal };
  2011. if (Layout.RootPanel != null)
  2012. {
  2013. mainLayoutPanel.Children.Add(Layout.RootPanel);
  2014. }
  2015. Layout.RootPanel = mainLayoutPanel;
  2016. anchorablePane = new LayoutAnchorablePane() { DockWidth = new GridLength(200.0, GridUnitType.Pixel) };
  2017. mainLayoutPanel.Children.Add(anchorablePane);
  2018. }
  2019. anchorablePane.Children.Add(anchorableToImport);
  2020. added = true;
  2021. }
  2022. if (LayoutUpdateStrategy != null)
  2023. {
  2024. LayoutUpdateStrategy.AfterInsertAnchorable(Layout, anchorableToImport);
  2025. }
  2026. var root = anchorableToImport.Root;
  2027. if (root != null && root.Manager == this)
  2028. {
  2029. CreateAnchorableLayoutItem(anchorableToImport);
  2030. }
  2031. }
  2032. _suspendLayoutItemCreation = false;
  2033. }
  2034. }
  2035. if (e.Action == NotifyCollectionChangedAction.Reset)
  2036. {
  2037. //NOTE: I'm going to clear every anchorable present in layout but
  2038. //some anchorable may have been added directly to the layout, for now I clear them too
  2039. var anchorablesToRemove = Layout.Descendents().OfType<LayoutAnchorable>().ToArray();
  2040. foreach (var anchorableToRemove in anchorablesToRemove)
  2041. {
  2042. (anchorableToRemove.Parent as ILayoutContainer).RemoveChild(
  2043. anchorableToRemove);
  2044. }
  2045. }
  2046. if (Layout != null)
  2047. Layout.CollectGarbage();
  2048. }
  2049. void DetachAnchorablesSource(LayoutRoot layout, IEnumerable anchorablesSource)
  2050. {
  2051. if (anchorablesSource == null)
  2052. return;
  2053. if (layout == null)
  2054. return;
  2055. var anchorablesToRemove = layout.Descendents().OfType<LayoutAnchorable>()
  2056. .Where(d => anchorablesSource.Contains(d.Content)).ToArray();
  2057. foreach (var anchorableToRemove in anchorablesToRemove)
  2058. {
  2059. (anchorableToRemove.Parent as ILayoutContainer).RemoveChild(
  2060. anchorableToRemove);
  2061. }
  2062. var anchorablesSourceAsNotifier = anchorablesSource as INotifyCollectionChanged;
  2063. if (anchorablesSourceAsNotifier != null)
  2064. anchorablesSourceAsNotifier.CollectionChanged -= new NotifyCollectionChangedEventHandler(anchorablesSourceElementsChanged);
  2065. }
  2066. #endregion
  2067. internal void _ExecuteCloseCommand(LayoutAnchorable anchorable)
  2068. {
  2069. var model = anchorable as LayoutAnchorable;
  2070. if (model != null && model.TestCanClose())
  2071. {
  2072. if (model.IsAutoHidden)
  2073. model.ToggleAutoHide();
  2074. //Daniel-调Close()会死循环
  2075. //model.Close();
  2076. model.CloseInternal();
  2077. return;
  2078. }
  2079. }
  2080. internal void _ExecuteHideCommand(LayoutAnchorable anchorable)
  2081. {
  2082. var model = anchorable as LayoutAnchorable;
  2083. if (model != null)
  2084. {
  2085. //by default hide the anchorable
  2086. model.Hide();
  2087. }
  2088. }
  2089. internal void _ExecuteAutoHideCommand(LayoutAnchorable _anchorable)
  2090. {
  2091. _anchorable.ToggleAutoHide();
  2092. }
  2093. internal void _ExecuteFloatCommand(LayoutContent contentToFloat)
  2094. {
  2095. contentToFloat.Float();
  2096. }
  2097. internal void _ExecuteDockCommand(LayoutAnchorable anchorable)
  2098. {
  2099. anchorable.Dock();
  2100. }
  2101. internal void _ExecuteDockAsDocumentCommand(LayoutContent content)
  2102. {
  2103. content.DockAsDocument();
  2104. }
  2105. #region ActiveContent
  2106. /// <summary>
  2107. /// ActiveContent Dependency Property
  2108. /// </summary>
  2109. public static readonly DependencyProperty ActiveContentProperty =
  2110. DependencyProperty.Register("ActiveContent", typeof(object), typeof(DockingManager),
  2111. new FrameworkPropertyMetadata((object)null,
  2112. new PropertyChangedCallback(OnActiveContentChanged)));
  2113. /// <summary>
  2114. /// Gets or sets the ActiveContent property. This dependency property
  2115. /// indicates the content currently active.
  2116. /// </summary>
  2117. public object ActiveContent
  2118. {
  2119. get { return (object)GetValue(ActiveContentProperty); }
  2120. set { SetValue(ActiveContentProperty, value); }
  2121. }
  2122. /// <summary>
  2123. /// Handles changes to the ActiveContent property.
  2124. /// </summary>
  2125. private static void OnActiveContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  2126. {
  2127. ((DockingManager)d).InternalSetActiveContent(e.NewValue);
  2128. ((DockingManager)d).OnActiveContentChanged(e);
  2129. }
  2130. /// <summary>
  2131. /// Provides derived classes an opportunity to handle changes to the ActiveContent property.
  2132. /// </summary>
  2133. protected virtual void OnActiveContentChanged(DependencyPropertyChangedEventArgs e)
  2134. {
  2135. if (ActiveContentChanged != null)
  2136. ActiveContentChanged(this, EventArgs.Empty);
  2137. }
  2138. bool _insideInternalSetActiveContent = false;
  2139. void InternalSetActiveContent(object contentObject)
  2140. {
  2141. var layoutContent = Layout.Descendents().OfType<LayoutContent>().FirstOrDefault(lc => lc == contentObject || lc.Content == contentObject);
  2142. _insideInternalSetActiveContent = true;
  2143. Layout.ActiveContent = layoutContent;
  2144. _insideInternalSetActiveContent = false;
  2145. }
  2146. public event EventHandler ActiveContentChanged;
  2147. #endregion
  2148. #region AnchorableContextMenu
  2149. /// <summary>
  2150. /// AnchorableContextMenu Dependency Property
  2151. /// </summary>
  2152. public static readonly DependencyProperty AnchorableContextMenuProperty =
  2153. DependencyProperty.Register("AnchorableContextMenu", typeof(ContextMenu), typeof(DockingManager),
  2154. new FrameworkPropertyMetadata((ContextMenu)null));
  2155. /// <summary>
  2156. /// Gets or sets the AnchorableContextMenu property. This dependency property
  2157. /// indicates the context menu to show up for anchorables.
  2158. /// </summary>
  2159. public ContextMenu AnchorableContextMenu
  2160. {
  2161. get { return (ContextMenu)GetValue(AnchorableContextMenuProperty); }
  2162. set { SetValue(AnchorableContextMenuProperty, value); }
  2163. }
  2164. #endregion
  2165. #region Theme
  2166. /// <summary>
  2167. /// Theme Dependency Property
  2168. /// </summary>
  2169. public static readonly DependencyProperty ThemeProperty =
  2170. DependencyProperty.Register("Theme", typeof(Theme), typeof(DockingManager),
  2171. new FrameworkPropertyMetadata(null,
  2172. new PropertyChangedCallback(OnThemeChanged)));
  2173. /// <summary>
  2174. /// Gets or sets the Theme property. This dependency property
  2175. /// indicates the theme to use for AvalonDock controls.
  2176. /// </summary>
  2177. public Theme Theme
  2178. {
  2179. get { return (Theme)GetValue(ThemeProperty); }
  2180. set { SetValue(ThemeProperty, value); }
  2181. }
  2182. /// <summary>
  2183. /// Handles changes to the Theme property.
  2184. /// </summary>
  2185. private static void OnThemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  2186. {
  2187. ((DockingManager)d).OnThemeChanged(e);
  2188. }
  2189. /// <summary>
  2190. /// Provides derived classes an opportunity to handle changes to the Theme property.
  2191. /// </summary>
  2192. protected virtual void OnThemeChanged(DependencyPropertyChangedEventArgs e)
  2193. {
  2194. var oldTheme = e.OldValue as Theme;
  2195. var newTheme = e.NewValue as Theme;
  2196. var resources = this.Resources;
  2197. if (oldTheme != null)
  2198. {
  2199. if (oldTheme is DictionaryTheme)
  2200. {
  2201. if (currentThemeResourceDictionary != null)
  2202. {
  2203. resources.MergedDictionaries.Remove(currentThemeResourceDictionary);
  2204. currentThemeResourceDictionary = null;
  2205. }
  2206. }
  2207. else
  2208. {
  2209. var resourceDictionaryToRemove =
  2210. resources.MergedDictionaries.FirstOrDefault(r => r.Source == oldTheme.GetResourceUri());
  2211. if (resourceDictionaryToRemove != null)
  2212. resources.MergedDictionaries.Remove(
  2213. resourceDictionaryToRemove);
  2214. }
  2215. }
  2216. if (newTheme != null)
  2217. {
  2218. if (newTheme is DictionaryTheme)
  2219. {
  2220. currentThemeResourceDictionary = ((DictionaryTheme)newTheme).ThemeResourceDictionary;
  2221. resources.MergedDictionaries.Add(currentThemeResourceDictionary);
  2222. }
  2223. else
  2224. {
  2225. resources.MergedDictionaries.Add(new ResourceDictionary() { Source = newTheme.GetResourceUri() });
  2226. }
  2227. }
  2228. foreach (var fwc in _fwList)
  2229. fwc.UpdateThemeResources(oldTheme);
  2230. if (_navigatorWindow != null)
  2231. _navigatorWindow.UpdateThemeResources();
  2232. if (_overlayWindow != null)
  2233. _overlayWindow.UpdateThemeResources();
  2234. }
  2235. #endregion
  2236. #region GridSplitterWidth
  2237. /// <summary>
  2238. /// GridSplitterWidth Dependency Property
  2239. /// </summary>
  2240. public static readonly DependencyProperty GridSplitterWidthProperty =
  2241. DependencyProperty.Register("GridSplitterWidth", typeof(double), typeof(DockingManager),
  2242. new FrameworkPropertyMetadata((double)6.0));
  2243. /// <summary>
  2244. /// Gets or sets the GridSplitterWidth property. This dependency property
  2245. /// indicates width of grid splitters.
  2246. /// </summary>
  2247. public double GridSplitterWidth
  2248. {
  2249. get { return (double)GetValue(GridSplitterWidthProperty); }
  2250. set { SetValue(GridSplitterWidthProperty, value); }
  2251. }
  2252. #endregion
  2253. #region GridSplitterHeight
  2254. /// <summary>
  2255. /// GridSplitterHeight Dependency Property
  2256. /// </summary>
  2257. public static readonly DependencyProperty GridSplitterHeightProperty =
  2258. DependencyProperty.Register("GridSplitterHeight", typeof(double), typeof(DockingManager),
  2259. new FrameworkPropertyMetadata((double)6.0));
  2260. /// <summary>
  2261. /// Gets or sets the GridSplitterHeight property. This dependency property
  2262. /// indicates height of grid splitters.
  2263. /// </summary>
  2264. public double GridSplitterHeight
  2265. {
  2266. get { return (double)GetValue(GridSplitterHeightProperty); }
  2267. set { SetValue(GridSplitterHeightProperty, value); }
  2268. }
  2269. #endregion
  2270. internal void _ExecuteContentActivateCommand(LayoutContent content)
  2271. {
  2272. content.IsActive = true;
  2273. }
  2274. #region DocumentPaneMenuItemHeaderTemplate
  2275. /// <summary>
  2276. /// DocumentPaneMenuItemHeaderTemplate Dependency Property
  2277. /// </summary>
  2278. public static readonly DependencyProperty DocumentPaneMenuItemHeaderTemplateProperty =
  2279. DependencyProperty.Register("DocumentPaneMenuItemHeaderTemplate", typeof(DataTemplate), typeof(DockingManager),
  2280. new FrameworkPropertyMetadata((DataTemplate)null,
  2281. new PropertyChangedCallback(OnDocumentPaneMenuItemHeaderTemplateChanged),
  2282. new CoerceValueCallback(CoerceDocumentPaneMenuItemHeaderTemplateValue)));
  2283. /// <summary>
  2284. /// Gets or sets the DocumentPaneMenuItemHeaderTemplate property. This dependency property
  2285. /// indicates the header template to use while creating menu items for the document panes.
  2286. /// </summary>
  2287. public DataTemplate DocumentPaneMenuItemHeaderTemplate
  2288. {
  2289. get { return (DataTemplate)GetValue(DocumentPaneMenuItemHeaderTemplateProperty); }
  2290. set { SetValue(DocumentPaneMenuItemHeaderTemplateProperty, value); }
  2291. }
  2292. /// <summary>
  2293. /// Handles changes to the DocumentPaneMenuItemHeaderTemplate property.
  2294. /// </summary>
  2295. private static void OnDocumentPaneMenuItemHeaderTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  2296. {
  2297. ((DockingManager)d).OnDocumentPaneMenuItemHeaderTemplateChanged(e);
  2298. }
  2299. /// <summary>
  2300. /// Provides derived classes an opportunity to handle changes to the DocumentPaneMenuItemHeaderTemplate property.
  2301. /// </summary>
  2302. protected virtual void OnDocumentPaneMenuItemHeaderTemplateChanged(DependencyPropertyChangedEventArgs e)
  2303. {
  2304. }
  2305. /// <summary>
  2306. /// Coerces the DocumentPaneMenuItemHeaderTemplate value.
  2307. /// </summary>
  2308. private static object CoerceDocumentPaneMenuItemHeaderTemplateValue(DependencyObject d, object value)
  2309. {
  2310. if (value != null &&
  2311. d.GetValue(DocumentPaneMenuItemHeaderTemplateSelectorProperty) != null)
  2312. return null;
  2313. if (value == null)
  2314. return d.GetValue(DocumentHeaderTemplateProperty);
  2315. return value;
  2316. }
  2317. #endregion
  2318. #region DocumentPaneMenuItemHeaderTemplateSelector
  2319. /// <summary>
  2320. /// DocumentPaneMenuItemHeaderTemplateSelector Dependency Property
  2321. /// </summary>
  2322. public static readonly DependencyProperty DocumentPaneMenuItemHeaderTemplateSelectorProperty =
  2323. DependencyProperty.Register("DocumentPaneMenuItemHeaderTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
  2324. new FrameworkPropertyMetadata((DataTemplateSelector)null,
  2325. new PropertyChangedCallback(OnDocumentPaneMenuItemHeaderTemplateSelectorChanged),
  2326. new CoerceValueCallback(CoerceDocumentPaneMenuItemHeaderTemplateSelectorValue)));
  2327. /// <summary>
  2328. /// Gets or sets the DocumentPaneMenuItemHeaderTemplateSelector property. This dependency property
  2329. /// indicates the data template selector to use for the menu items show when user select the DocumentPane document switch context menu.
  2330. /// </summary>
  2331. public DataTemplateSelector DocumentPaneMenuItemHeaderTemplateSelector
  2332. {
  2333. get { return (DataTemplateSelector)GetValue(DocumentPaneMenuItemHeaderTemplateSelectorProperty); }
  2334. set { SetValue(DocumentPaneMenuItemHeaderTemplateSelectorProperty, value); }
  2335. }
  2336. /// <summary>
  2337. /// Handles changes to the DocumentPaneMenuItemHeaderTemplateSelector property.
  2338. /// </summary>
  2339. private static void OnDocumentPaneMenuItemHeaderTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  2340. {
  2341. ((DockingManager)d).OnDocumentPaneMenuItemHeaderTemplateSelectorChanged(e);
  2342. }
  2343. /// <summary>
  2344. /// Provides derived classes an opportunity to handle changes to the DocumentPaneMenuItemHeaderTemplateSelector property.
  2345. /// </summary>
  2346. protected virtual void OnDocumentPaneMenuItemHeaderTemplateSelectorChanged(DependencyPropertyChangedEventArgs e)
  2347. {
  2348. if (e.NewValue != null &&
  2349. DocumentPaneMenuItemHeaderTemplate != null)
  2350. DocumentPaneMenuItemHeaderTemplate = null;
  2351. }
  2352. /// <summary>
  2353. /// Coerces the DocumentPaneMenuItemHeaderTemplateSelector value.
  2354. /// </summary>
  2355. private static object CoerceDocumentPaneMenuItemHeaderTemplateSelectorValue(DependencyObject d, object value)
  2356. {
  2357. return value;
  2358. }
  2359. #endregion
  2360. #region IconContentTemplate
  2361. /// <summary>
  2362. /// IconContentTemplate Dependency Property
  2363. /// </summary>
  2364. public static readonly DependencyProperty IconContentTemplateProperty =
  2365. DependencyProperty.Register("IconContentTemplate", typeof(DataTemplate), typeof(DockingManager),
  2366. new FrameworkPropertyMetadata((DataTemplate)null));
  2367. /// <summary>
  2368. /// Gets or sets the IconContentTemplate property. This dependency property
  2369. /// indicates the data template to use while extracting the icon from model.
  2370. /// </summary>
  2371. public DataTemplate IconContentTemplate
  2372. {
  2373. get { return (DataTemplate)GetValue(IconContentTemplateProperty); }
  2374. set { SetValue(IconContentTemplateProperty, value); }
  2375. }
  2376. #endregion
  2377. #region IconContentTemplateSelector
  2378. /// <summary>
  2379. /// IconContentTemplateSelector Dependency Property
  2380. /// </summary>
  2381. public static readonly DependencyProperty IconContentTemplateSelectorProperty =
  2382. DependencyProperty.Register("IconContentTemplateSelector", typeof(DataTemplateSelector), typeof(DockingManager),
  2383. new FrameworkPropertyMetadata((DataTemplateSelector)null));
  2384. /// <summary>
  2385. /// Gets or sets the IconContentTemplateSelector property. This dependency property
  2386. /// indicates data template selector to use while selecting the datatamplate for content icons.
  2387. /// </summary>
  2388. public DataTemplateSelector IconContentTemplateSelector
  2389. {
  2390. get { return (DataTemplateSelector)GetValue(IconContentTemplateSelectorProperty); }
  2391. set { SetValue(IconContentTemplateSelectorProperty, value); }
  2392. }
  2393. #endregion
  2394. #region LayoutItems
  2395. List<LayoutItem> _layoutItems = new List<LayoutItem>();
  2396. bool _suspendLayoutItemCreation = false;
  2397. void DetachLayoutItems()
  2398. {
  2399. if (Layout != null)
  2400. {
  2401. _layoutItems.ForEach<LayoutItem>(i => i.Detach());
  2402. _layoutItems.Clear();
  2403. Layout.ElementAdded -= new EventHandler<LayoutElementEventArgs>(Layout_ElementAdded);
  2404. Layout.ElementRemoved -= new EventHandler<LayoutElementEventArgs>(Layout_ElementRemoved);
  2405. }
  2406. }
  2407. void Layout_ElementRemoved(object sender, LayoutElementEventArgs e)
  2408. {
  2409. if (_suspendLayoutItemCreation)
  2410. return;
  2411. CollectLayoutItemsDeleted();
  2412. }
  2413. void Layout_ElementAdded(object sender, LayoutElementEventArgs e)
  2414. {
  2415. if (_suspendLayoutItemCreation)
  2416. return;
  2417. foreach (var content in Layout.Descendents().OfType<LayoutContent>())
  2418. {
  2419. if (content is LayoutDocument)
  2420. CreateDocumentLayoutItem(content as LayoutDocument);
  2421. else //if (content is LayoutAnchorable)
  2422. CreateAnchorableLayoutItem(content as LayoutAnchorable);
  2423. }
  2424. CollectLayoutItemsDeleted();
  2425. }
  2426. DispatcherOperation _collectLayoutItemsOperations = null;
  2427. void CollectLayoutItemsDeleted()
  2428. {
  2429. if (_collectLayoutItemsOperations != null)
  2430. return;
  2431. _collectLayoutItemsOperations = Dispatcher.BeginInvoke(new Action(() =>
  2432. {
  2433. _collectLayoutItemsOperations = null;
  2434. foreach (var itemToRemove in _layoutItems.Where(item => item.LayoutElement.Root != Layout).ToArray())
  2435. {
  2436. if (itemToRemove != null &&
  2437. itemToRemove.Model != null &&
  2438. itemToRemove.Model is UIElement)
  2439. {
  2440. //((ILogicalChildrenContainer)this).InternalRemoveLogicalChild(itemToRemove.Model as UIElement);
  2441. }
  2442. itemToRemove.Detach();
  2443. _layoutItems.Remove(itemToRemove);
  2444. }
  2445. }));
  2446. }
  2447. void AttachLayoutItems()
  2448. {
  2449. if (Layout != null)
  2450. {
  2451. foreach (var document in Layout.Descendents().OfType<LayoutDocument>().ToArray())
  2452. {
  2453. CreateDocumentLayoutItem(document);
  2454. //var documentItem = new LayoutDocumentItem();
  2455. //documentItem.Attach(document);
  2456. //ApplyStyleToLayoutItem(documentItem);
  2457. //_layoutItems.Add(documentItem);
  2458. }
  2459. foreach (var anchorable in Layout.Descendents().OfType<LayoutAnchorable>().ToArray())
  2460. {
  2461. CreateAnchorableLayoutItem(anchorable);
  2462. //var anchorableItem = new LayoutAnchorableItem();
  2463. //anchorableItem.Attach(anchorable);
  2464. //ApplyStyleToLayoutItem(anchorableItem);
  2465. //_layoutItems.Add(anchorableItem);
  2466. }
  2467. Layout.ElementAdded += new EventHandler<LayoutElementEventArgs>(Layout_ElementAdded);
  2468. Layout.ElementRemoved += new EventHandler<LayoutElementEventArgs>(Layout_ElementRemoved);
  2469. }
  2470. }
  2471. void ApplyStyleToLayoutItem(LayoutItem layoutItem)
  2472. {
  2473. layoutItem._ClearDefaultBindings();
  2474. if (LayoutItemContainerStyle != null)
  2475. layoutItem.Style = LayoutItemContainerStyle;
  2476. else if (LayoutItemContainerStyleSelector != null)
  2477. layoutItem.Style = LayoutItemContainerStyleSelector.SelectStyle(layoutItem.Model, layoutItem);
  2478. layoutItem._SetDefaultBindings();
  2479. }
  2480. void CreateAnchorableLayoutItem(LayoutAnchorable contentToAttach)
  2481. {
  2482. if (_layoutItems.Any(item => item.LayoutElement == contentToAttach))
  2483. return;
  2484. var layoutItem = new LayoutAnchorableItem();
  2485. layoutItem.Attach(contentToAttach);
  2486. ApplyStyleToLayoutItem(layoutItem);
  2487. _layoutItems.Add(layoutItem);
  2488. if (contentToAttach != null &&
  2489. contentToAttach.Content != null &&
  2490. contentToAttach.Content is UIElement)
  2491. {
  2492. InternalAddLogicalChild(contentToAttach.Content);
  2493. }
  2494. }
  2495. void CreateDocumentLayoutItem(LayoutDocument contentToAttach)
  2496. {
  2497. if (_layoutItems.Any(item => item.LayoutElement == contentToAttach))
  2498. return;
  2499. var layoutItem = new LayoutDocumentItem();
  2500. layoutItem.Attach(contentToAttach);
  2501. ApplyStyleToLayoutItem(layoutItem);
  2502. _layoutItems.Add(layoutItem);
  2503. if (contentToAttach != null &&
  2504. contentToAttach.Content != null &&
  2505. contentToAttach.Content is UIElement)
  2506. {
  2507. InternalAddLogicalChild(contentToAttach.Content);
  2508. }
  2509. }
  2510. #region LayoutItemContainerStyle
  2511. /// <summary>
  2512. /// LayoutItemContainerStyle Dependency Property
  2513. /// </summary>
  2514. public static readonly DependencyProperty LayoutItemContainerStyleProperty =
  2515. DependencyProperty.Register("LayoutItemContainerStyle", typeof(Style), typeof(DockingManager),
  2516. new FrameworkPropertyMetadata((Style)null,
  2517. new PropertyChangedCallback(OnLayoutItemContainerStyleChanged)));
  2518. /// <summary>
  2519. /// Gets or sets the LayoutItemContainerStyle property. This dependency property
  2520. /// indicates the style to apply to LayoutDocumentItem objects. A LayoutDocumentItem object is created when a new LayoutDocument is created inside the current Layout.
  2521. /// </summary>
  2522. public Style LayoutItemContainerStyle
  2523. {
  2524. get { return (Style)GetValue(LayoutItemContainerStyleProperty); }
  2525. set { SetValue(LayoutItemContainerStyleProperty, value); }
  2526. }
  2527. /// <summary>
  2528. /// Handles changes to the LayoutItemContainerStyle property.
  2529. /// </summary>
  2530. private static void OnLayoutItemContainerStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  2531. {
  2532. ((DockingManager)d).OnLayoutItemContainerStyleChanged(e);
  2533. }
  2534. /// <summary>
  2535. /// Provides derived classes an opportunity to handle changes to the LayoutItemContainerStyle property.
  2536. /// </summary>
  2537. protected virtual void OnLayoutItemContainerStyleChanged(DependencyPropertyChangedEventArgs e)
  2538. {
  2539. AttachLayoutItems();
  2540. }
  2541. #endregion
  2542. #region LayoutItemContainerStyleSelector
  2543. /// <summary>
  2544. /// LayoutItemContainerStyleSelector Dependency Property
  2545. /// </summary>
  2546. public static readonly DependencyProperty LayoutItemContainerStyleSelectorProperty =
  2547. DependencyProperty.Register("LayoutItemContainerStyleSelector", typeof(StyleSelector), typeof(DockingManager),
  2548. new FrameworkPropertyMetadata((StyleSelector)null,
  2549. new PropertyChangedCallback(OnLayoutItemContainerStyleSelectorChanged)));
  2550. /// <summary>
  2551. /// Gets or sets the LayoutItemContainerStyleSelector property. This dependency property
  2552. /// indicates style selector of the LayoutDocumentItemStyle.
  2553. /// </summary>
  2554. public StyleSelector LayoutItemContainerStyleSelector
  2555. {
  2556. get { return (StyleSelector)GetValue(LayoutItemContainerStyleSelectorProperty); }
  2557. set { SetValue(LayoutItemContainerStyleSelectorProperty, value); }
  2558. }
  2559. /// <summary>
  2560. /// Handles changes to the LayoutItemContainerStyleSelector property.
  2561. /// </summary>
  2562. private static void OnLayoutItemContainerStyleSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  2563. {
  2564. ((DockingManager)d).OnLayoutItemContainerStyleSelectorChanged(e);
  2565. }
  2566. /// <summary>
  2567. /// Provides derived classes an opportunity to handle changes to the LayoutItemContainerStyleSelector property.
  2568. /// </summary>
  2569. protected virtual void OnLayoutItemContainerStyleSelectorChanged(DependencyPropertyChangedEventArgs e)
  2570. {
  2571. AttachLayoutItems();
  2572. }
  2573. #endregion
  2574. /// <summary>
  2575. /// Return the LayoutItem wrapper for the content passed as argument
  2576. /// </summary>
  2577. /// <param name="content">LayoutContent to search</param>
  2578. /// <returns>Either a LayoutAnchorableItem or LayoutDocumentItem which contains the LayoutContent passed as argument</returns>
  2579. public LayoutItem GetLayoutItemFromModel(LayoutContent content)
  2580. {
  2581. return _layoutItems.FirstOrDefault(item => item.LayoutElement == content);
  2582. }
  2583. #endregion
  2584. #region NavigatorWindow
  2585. NavigatorWindow _navigatorWindow = null;
  2586. void ShowNavigatorWindow()
  2587. {
  2588. if (_navigatorWindow == null)
  2589. {
  2590. _navigatorWindow = new NavigatorWindow(this)
  2591. {
  2592. Owner = Window.GetWindow(this),
  2593. WindowStartupLocation = WindowStartupLocation.CenterOwner
  2594. };
  2595. }
  2596. _navigatorWindow.ShowDialog();
  2597. _navigatorWindow = null;
  2598. Trace.WriteLine("ShowNavigatorWindow()");
  2599. }
  2600. bool IsNavigatorWindowActive
  2601. {
  2602. get { return _navigatorWindow != null; }
  2603. }
  2604. protected override void OnPreviewKeyDown(KeyEventArgs e)
  2605. {
  2606. Trace.WriteLine(string.Format("OnPreviewKeyDown({0})", e.Key));
  2607. if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
  2608. {
  2609. if (e.IsDown && e.Key == Key.Tab)
  2610. {
  2611. if (!IsNavigatorWindowActive)
  2612. {
  2613. ShowNavigatorWindow();
  2614. e.Handled = true;
  2615. }
  2616. }
  2617. }
  2618. base.OnPreviewKeyDown(e);
  2619. }
  2620. #endregion
  2621. #region ShowSystemMenu
  2622. /// <summary>
  2623. /// ShowSystemMenu Dependency Property
  2624. /// </summary>
  2625. public static readonly DependencyProperty ShowSystemMenuProperty =
  2626. DependencyProperty.Register("ShowSystemMenu", typeof(bool), typeof(DockingManager),
  2627. new FrameworkPropertyMetadata((bool)true));
  2628. /// <summary>
  2629. /// Gets or sets the ShowSystemMenu property. This dependency property
  2630. /// indicates if floating windows should show the system menu when a custom context menu is not defined.
  2631. /// </summary>
  2632. public bool ShowSystemMenu
  2633. {
  2634. get { return (bool)GetValue(ShowSystemMenuProperty); }
  2635. set { SetValue(ShowSystemMenuProperty, value); }
  2636. }
  2637. #endregion
  2638. #region AllowMixedOrientation
  2639. /// <summary>
  2640. /// AllowMixedOrientation Dependency Property
  2641. /// </summary>
  2642. public static readonly DependencyProperty AllowMixedOrientationProperty =
  2643. DependencyProperty.Register("AllowMixedOrientation", typeof(bool), typeof(DockingManager),
  2644. new FrameworkPropertyMetadata((bool)false));
  2645. /// <summary>
  2646. /// Gets or sets the AllowMixedOrientation property. This dependency property
  2647. /// indicates if the manager should allow mixed orientation for document panes.
  2648. /// </summary>
  2649. public bool AllowMixedOrientation
  2650. {
  2651. get { return (bool)GetValue(AllowMixedOrientationProperty); }
  2652. set { SetValue(AllowMixedOrientationProperty, value); }
  2653. }
  2654. #endregion
  2655. }
  2656. }