DocumentPaneTabPanel.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.Controls;
  15. using System.Windows;
  16. using Xceed.Wpf.AvalonDock.Layout;
  17. namespace Xceed.Wpf.AvalonDock.Controls
  18. {
  19. public class DocumentPaneTabPanel : Panel
  20. {
  21. public DocumentPaneTabPanel()
  22. {
  23. FlowDirection = System.Windows.FlowDirection.LeftToRight;
  24. }
  25. protected override Size MeasureOverride(Size availableSize)
  26. {
  27. var visibleChildren = Children.Cast<UIElement>().Where(ch => ch.Visibility != System.Windows.Visibility.Collapsed);
  28. Size desideredSize = new Size();
  29. foreach (FrameworkElement child in Children)
  30. {
  31. child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  32. desideredSize.Width += child.DesiredSize.Width;
  33. desideredSize.Height = Math.Max(desideredSize.Height, child.DesiredSize.Height);
  34. }
  35. return new Size(Math.Min(desideredSize.Width, availableSize.Width), desideredSize.Height);
  36. }
  37. protected override Size ArrangeOverride(Size finalSize)
  38. {
  39. restart:
  40. var visibleChildren = Children.Cast<UIElement>().Where(ch => ch.Visibility != System.Windows.Visibility.Collapsed);
  41. double offset = 0.0;
  42. bool skipAllOthers = false;
  43. foreach (TabItem doc in visibleChildren)
  44. {
  45. var layoutContent = doc.Content as LayoutContent;
  46. if (skipAllOthers || offset + doc.DesiredSize.Width > finalSize.Width)
  47. {
  48. if (layoutContent.IsSelected)
  49. {
  50. var parentContainer = layoutContent.Parent as ILayoutContainer;
  51. var parentSelector = layoutContent.Parent as ILayoutContentSelector;
  52. var parentPane = layoutContent.Parent as ILayoutPane;
  53. int contentIndex = parentSelector.IndexOf(layoutContent);
  54. if (contentIndex > 0 &&
  55. parentContainer.ChildrenCount > 1)
  56. {
  57. parentPane.MoveChild(contentIndex, 0);
  58. parentSelector.SelectedContentIndex = 0;
  59. goto restart;
  60. }
  61. }
  62. doc.Visibility = System.Windows.Visibility.Hidden;
  63. skipAllOthers = true;
  64. }
  65. else
  66. {
  67. doc.Visibility = System.Windows.Visibility.Visible;
  68. doc.Arrange(new Rect(offset, 0.0, doc.DesiredSize.Width, finalSize.Height));
  69. offset += doc.ActualWidth + doc.Margin.Left + doc.Margin.Right;
  70. }
  71. }
  72. return finalSize;
  73. }
  74. protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
  75. {
  76. //if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed &&
  77. // LayoutDocumentTabItem.IsDraggingItem())
  78. //{
  79. // var contentModel = LayoutDocumentTabItem.GetDraggingItem().Model;
  80. // var manager = contentModel.Root.Manager;
  81. // LayoutDocumentTabItem.ResetDraggingItem();
  82. // System.Diagnostics.Trace.WriteLine("OnMouseLeave()");
  83. // manager.StartDraggingFloatingWindowForContent(contentModel);
  84. //}
  85. base.OnMouseLeave(e);
  86. }
  87. }
  88. }