LayoutAnchorControl.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using Xceed.Wpf.AvalonDock.Layout;
  17. using System.Windows.Threading;
  18. namespace Xceed.Wpf.AvalonDock.Controls
  19. {
  20. public class LayoutAnchorControl : Control, ILayoutControl
  21. {
  22. static LayoutAnchorControl()
  23. {
  24. DefaultStyleKeyProperty.OverrideMetadata(typeof(LayoutAnchorControl), new FrameworkPropertyMetadata(typeof(LayoutAnchorControl)));
  25. Control.IsHitTestVisibleProperty.AddOwner(typeof(LayoutAnchorControl), new FrameworkPropertyMetadata(true));
  26. }
  27. internal LayoutAnchorControl(LayoutAnchorable model)
  28. {
  29. _model = model;
  30. _model.IsActiveChanged += new EventHandler(_model_IsActiveChanged);
  31. _model.IsSelectedChanged += new EventHandler(_model_IsSelectedChanged);
  32. SetSide(_model.FindParent<LayoutAnchorSide>().Side);
  33. }
  34. void _model_IsSelectedChanged(object sender, EventArgs e)
  35. {
  36. if (!_model.IsAutoHidden)
  37. _model.IsSelectedChanged -= new EventHandler(_model_IsSelectedChanged);
  38. else if (_model.IsSelected)
  39. {
  40. _model.Root.Manager.ShowAutoHideWindow(this);
  41. _model.IsSelected = false;
  42. }
  43. }
  44. void _model_IsActiveChanged(object sender, EventArgs e)
  45. {
  46. if (!_model.IsAutoHidden)
  47. _model.IsActiveChanged -= new EventHandler(_model_IsActiveChanged);
  48. else if (_model.IsActive)
  49. _model.Root.Manager.ShowAutoHideWindow(this);
  50. }
  51. LayoutAnchorable _model;
  52. public ILayoutElement Model
  53. {
  54. get { return _model; }
  55. }
  56. //protected override void OnVisualParentChanged(DependencyObject oldParent)
  57. //{
  58. // base.OnVisualParentChanged(oldParent);
  59. // var contentModel = _model;
  60. // if (oldParent != null && contentModel != null && contentModel.Content is UIElement)
  61. // {
  62. // var oldParentPaneControl = oldParent.FindVisualAncestor<LayoutAnchorablePaneControl>();
  63. // if (oldParentPaneControl != null)
  64. // {
  65. // ((ILogicalChildrenContainer)oldParentPaneControl).InternalRemoveLogicalChild(contentModel.Content);
  66. // }
  67. // }
  68. // if (contentModel.Content != null && contentModel.Content is UIElement)
  69. // {
  70. // var oldLogicalParentPaneControl = LogicalTreeHelper.GetParent(contentModel.Content as UIElement)
  71. // as ILogicalChildrenContainer;
  72. // if (oldLogicalParentPaneControl != null)
  73. // oldLogicalParentPaneControl.InternalRemoveLogicalChild(contentModel.Content);
  74. // }
  75. // if (contentModel != null && contentModel.Content != null && contentModel.Root != null && contentModel.Content is UIElement)
  76. // {
  77. // ((ILogicalChildrenContainer)contentModel.Root.Manager).InternalAddLogicalChild(contentModel.Content);
  78. // }
  79. //}
  80. protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
  81. {
  82. base.OnMouseDown(e);
  83. if (!e.Handled)
  84. {
  85. _model.Root.Manager.ShowAutoHideWindow(this);
  86. _model.IsActive = true;
  87. }
  88. }
  89. DispatcherTimer _openUpTimer = null;
  90. protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e)
  91. {
  92. base.OnMouseEnter(e);
  93. if (!e.Handled)
  94. {
  95. _openUpTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle);
  96. _openUpTimer.Interval = TimeSpan.FromMilliseconds(400);
  97. _openUpTimer.Tick += new EventHandler(_openUpTimer_Tick);
  98. _openUpTimer.Start();
  99. }
  100. }
  101. void _openUpTimer_Tick(object sender, EventArgs e)
  102. {
  103. _openUpTimer.Tick -= new EventHandler(_openUpTimer_Tick);
  104. _openUpTimer.Stop();
  105. _openUpTimer = null;
  106. _model.Root.Manager.ShowAutoHideWindow(this);
  107. }
  108. protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
  109. {
  110. if (_openUpTimer != null)
  111. {
  112. _openUpTimer.Tick -= new EventHandler(_openUpTimer_Tick);
  113. _openUpTimer.Stop();
  114. _openUpTimer = null;
  115. }
  116. base.OnMouseLeave(e);
  117. }
  118. #region Side
  119. /// <summary>
  120. /// Side Read-Only Dependency Property
  121. /// </summary>
  122. private static readonly DependencyPropertyKey SidePropertyKey
  123. = DependencyProperty.RegisterReadOnly("Side", typeof(AnchorSide), typeof(LayoutAnchorControl),
  124. new FrameworkPropertyMetadata((AnchorSide)AnchorSide.Left));
  125. public static readonly DependencyProperty SideProperty
  126. = SidePropertyKey.DependencyProperty;
  127. /// <summary>
  128. /// Gets the Side property. This dependency property
  129. /// indicates the anchor side of the control.
  130. /// </summary>
  131. public AnchorSide Side
  132. {
  133. get { return (AnchorSide)GetValue(SideProperty); }
  134. }
  135. /// <summary>
  136. /// Provides a secure method for setting the Side property.
  137. /// This dependency property indicates the anchor side of the control.
  138. /// </summary>
  139. /// <param name="value">The new value for the property.</param>
  140. protected void SetSide(AnchorSide value)
  141. {
  142. SetValue(SidePropertyKey, value);
  143. }
  144. #endregion
  145. }
  146. }