- Timestamp:
- 01/21/13 09:05:57 (11 years ago)
- Location:
- branches/UnloadJobs
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/UnloadJobs/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.7.0/WinFormsUI-2.7.0/Docking/DockPane.cs
r8616 r9174 1 1 using System; 2 2 using System.ComponentModel; 3 using System.Diagnostics.CodeAnalysis; 3 4 using System.Drawing; 4 using System. Drawing.Drawing2D;5 using System.Security.Permissions; 5 6 using System.Windows.Forms; 6 using System.Runtime.InteropServices; 7 using System.Security.Permissions; 8 using System.Diagnostics.CodeAnalysis; 9 10 namespace WeifenLuo.WinFormsUI.Docking 11 { 12 [ToolboxItem(false)] 13 public partial class DockPane : UserControl, IDockDragSource 14 { 15 public enum AppearanceStyle 16 { 17 ToolWindow, 18 Document 19 } 20 21 private enum HitTestArea 22 { 23 Caption, 24 TabStrip, 25 Content, 26 None 27 } 28 29 private struct HitTestResult 30 { 31 public HitTestArea HitArea; 32 public int Index; 33 34 public HitTestResult(HitTestArea hitTestArea, int index) 35 { 36 HitArea = hitTestArea; 37 Index = index; 38 } 39 } 40 41 private DockPaneCaptionBase m_captionControl; 42 private DockPaneCaptionBase CaptionControl 43 { 44 get { return m_captionControl; } 45 } 46 47 private DockPaneStripBase m_tabStripControl; 48 internal DockPaneStripBase TabStripControl 49 { 50 get { return m_tabStripControl; } 51 } 52 53 internal protected DockPane(IDockContent content, DockState visibleState, bool show) 54 { 55 InternalConstruct(content, visibleState, false, Rectangle.Empty, null, DockAlignment.Right, 0.5, show); 56 } 57 58 [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId = "1#")] 59 internal protected DockPane(IDockContent content, FloatWindow floatWindow, bool show) 60 { 61 if (floatWindow == null) 62 throw new ArgumentNullException("floatWindow"); 63 64 InternalConstruct(content, DockState.Float, false, Rectangle.Empty, floatWindow.NestedPanes.GetDefaultPreviousPane(this), DockAlignment.Right, 0.5, show); 65 } 66 67 internal protected DockPane(IDockContent content, DockPane previousPane, DockAlignment alignment, double proportion, bool show) 68 { 69 if (previousPane == null) 70 throw (new ArgumentNullException("previousPane")); 71 InternalConstruct(content, previousPane.DockState, false, Rectangle.Empty, previousPane, alignment, proportion, show); 72 } 73 74 [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId = "1#")] 75 internal protected DockPane(IDockContent content, Rectangle floatWindowBounds, bool show) 76 { 77 InternalConstruct(content, DockState.Float, true, floatWindowBounds, null, DockAlignment.Right, 0.5, show); 78 } 79 80 private void InternalConstruct(IDockContent content, DockState dockState, bool flagBounds, Rectangle floatWindowBounds, DockPane prevPane, DockAlignment alignment, double proportion, bool show) 81 { 82 if (dockState == DockState.Hidden || dockState == DockState.Unknown) 83 throw new ArgumentException(Strings.DockPane_SetDockState_InvalidState); 84 85 if (content == null) 86 throw new ArgumentNullException(Strings.DockPane_Constructor_NullContent); 87 88 if (content.DockHandler.DockPanel == null) 89 throw new ArgumentException(Strings.DockPane_Constructor_NullDockPanel); 90 91 92 SuspendLayout(); 93 SetStyle(ControlStyles.Selectable, false); 94 95 m_isFloat = (dockState == DockState.Float); 96 97 m_contents = new DockContentCollection(); 98 m_displayingContents = new DockContentCollection(this); 99 m_dockPanel = content.DockHandler.DockPanel; 100 m_dockPanel.AddPane(this); 101 102 m_splitter = new SplitterControl(this); 103 104 m_nestedDockingStatus = new NestedDockingStatus(this); 105 106 m_captionControl = DockPanel.DockPaneCaptionFactory.CreateDockPaneCaption(this); 107 m_tabStripControl = DockPanel.DockPaneStripFactory.CreateDockPaneStrip(this); 108 Controls.AddRange(new Control[] { m_captionControl, m_tabStripControl }); 109 110 DockPanel.SuspendLayout(true); 111 if (flagBounds) 112 FloatWindow = DockPanel.FloatWindowFactory.CreateFloatWindow(DockPanel, this, floatWindowBounds); 113 else if (prevPane != null) 114 DockTo(prevPane.NestedPanesContainer, prevPane, alignment, proportion); 115 116 SetDockState(dockState); 117 if (show) 118 content.DockHandler.Pane = this; 119 else if (this.IsFloat) 120 content.DockHandler.FloatPane = this; 121 else 122 content.DockHandler.PanelPane = this; 123 124 ResumeLayout(); 125 DockPanel.ResumeLayout(true, true); 126 } 127 128 private bool m_isDisposing; 129 130 protected override void Dispose(bool disposing) 131 { 132 if (disposing) 133 { 134 // IMPORTANT: avoid nested call into this method on Mono. 135 // https://github.com/dockpanelsuite/dockpanelsuite/issues/16 136 if (Win32Helper.IsRunningOnMono) 137 { 138 if (m_isDisposing) 139 return; 140 141 m_isDisposing = true; 142 } 143 144 m_dockState = DockState.Unknown; 145 146 if (NestedPanesContainer != null) 147 NestedPanesContainer.NestedPanes.Remove(this); 148 149 if (DockPanel != null) 150 { 151 DockPanel.RemovePane(this); 152 m_dockPanel = null; 153 } 154 155 Splitter.Dispose(); 156 if (m_autoHidePane != null) 157 m_autoHidePane.Dispose(); 158 } 159 base.Dispose(disposing); 160 } 161 162 private IDockContent m_activeContent = null; 163 public virtual IDockContent ActiveContent 164 { 165 get { return m_activeContent; } 166 set 167 { 168 if (ActiveContent == value) 169 return; 170 171 if (value != null) 172 { 173 if (!DisplayingContents.Contains(value)) 174 throw (new InvalidOperationException(Strings.DockPane_ActiveContent_InvalidValue)); 175 } 176 else 177 { 178 if (DisplayingContents.Count != 0) 179 throw (new InvalidOperationException(Strings.DockPane_ActiveContent_InvalidValue)); 180 } 181 182 IDockContent oldValue = m_activeContent; 183 184 if (DockPanel.ActiveAutoHideContent == oldValue) 185 DockPanel.ActiveAutoHideContent = null; 186 187 m_activeContent = value; 188 189 if (DockPanel.DocumentStyle == DocumentStyle.DockingMdi && DockState == DockState.Document) 190 { 191 if (m_activeContent != null) 192 m_activeContent.DockHandler.Form.BringToFront(); 193 } 194 else 195 { 196 if (m_activeContent != null) 197 m_activeContent.DockHandler.SetVisible(); 198 if (oldValue != null && DisplayingContents.Contains(oldValue)) 199 oldValue.DockHandler.SetVisible(); 200 if (IsActivated && m_activeContent != null) 201 m_activeContent.DockHandler.Activate(); 202 } 203 204 if (FloatWindow != null) 205 FloatWindow.SetText(); 206 207 if (DockPanel.DocumentStyle == DocumentStyle.DockingMdi && 208 DockState == DockState.Document) 209 RefreshChanges(false); // delayed layout to reduce screen flicker 210 else 211 RefreshChanges(); 212 213 if (m_activeContent != null) 214 TabStripControl.EnsureTabVisible(m_activeContent); 215 } 216 } 217 218 private bool m_allowDockDragAndDrop = true; 219 public virtual bool AllowDockDragAndDrop 220 { 221 get { return m_allowDockDragAndDrop; } 222 set { m_allowDockDragAndDrop = value; } 223 } 224 225 private IDisposable m_autoHidePane = null; 226 internal IDisposable AutoHidePane 227 { 228 get { return m_autoHidePane; } 229 set { m_autoHidePane = value; } 230 } 231 232 private object m_autoHideTabs = null; 233 internal object AutoHideTabs 234 { 235 get { return m_autoHideTabs; } 236 set { m_autoHideTabs = value; } 237 } 238 239 private object TabPageContextMenu 240 { 241 get 242 { 243 IDockContent content = ActiveContent; 244 245 if (content == null) 246 return null; 247 248 if (content.DockHandler.TabPageContextMenuStrip != null) 249 return content.DockHandler.TabPageContextMenuStrip; 250 else if (content.DockHandler.TabPageContextMenu != null) 251 return content.DockHandler.TabPageContextMenu; 252 else 253 return null; 254 } 255 } 256 257 internal bool HasTabPageContextMenu 258 { 259 get { return TabPageContextMenu != null; } 260 } 261 262 internal void ShowTabPageContextMenu(Control control, Point position) 263 { 264 object menu = TabPageContextMenu; 265 266 if (menu == null) 267 return; 268 269 ContextMenuStrip contextMenuStrip = menu as ContextMenuStrip; 270 if (contextMenuStrip != null) 271 { 272 contextMenuStrip.Show(control, position); 273 return; 274 } 275 276 ContextMenu contextMenu = menu as ContextMenu; 277 if (contextMenu != null) 278 contextMenu.Show(this, position); 279 } 280 281 private Rectangle CaptionRectangle 282 { 283 get 284 { 285 if (!HasCaption) 286 return Rectangle.Empty; 287 288 Rectangle rectWindow = DisplayingRectangle; 289 int x, y, width; 290 x = rectWindow.X; 291 y = rectWindow.Y; 292 width = rectWindow.Width; 293 int height = CaptionControl.MeasureHeight(); 294 295 return new Rectangle(x, y, width, height); 296 } 297 } 298 299 internal Rectangle ContentRectangle 300 { 301 get 302 { 303 Rectangle rectWindow = DisplayingRectangle; 304 Rectangle rectCaption = CaptionRectangle; 305 Rectangle rectTabStrip = TabStripRectangle; 306 307 int x = rectWindow.X; 308 309 int y = rectWindow.Y + (rectCaption.IsEmpty ? 0 : rectCaption.Height); 310 if (DockState == DockState.Document && DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Top) 311 y += rectTabStrip.Height; 312 313 int width = rectWindow.Width; 314 int height = rectWindow.Height - rectCaption.Height - rectTabStrip.Height; 315 316 return new Rectangle(x, y, width, height); 317 } 318 } 319 320 internal Rectangle TabStripRectangle 321 { 322 get 323 { 324 if (Appearance == AppearanceStyle.ToolWindow) 325 return TabStripRectangle_ToolWindow; 326 else 327 return TabStripRectangle_Document; 328 } 329 } 330 331 private Rectangle TabStripRectangle_ToolWindow 332 { 333 get 334 { 335 if (DisplayingContents.Count <= 1 || IsAutoHide) 336 return Rectangle.Empty; 337 338 Rectangle rectWindow = DisplayingRectangle; 339 340 int width = rectWindow.Width; 341 int height = TabStripControl.MeasureHeight(); 342 int x = rectWindow.X; 343 int y = rectWindow.Bottom - height; 344 Rectangle rectCaption = CaptionRectangle; 345 if (rectCaption.Contains(x, y)) 346 y = rectCaption.Y + rectCaption.Height; 347 348 return new Rectangle(x, y, width, height); 349 } 350 } 351 352 private Rectangle TabStripRectangle_Document 353 { 354 get 355 { 356 if (DisplayingContents.Count == 0) 357 return Rectangle.Empty; 358 359 if (DisplayingContents.Count == 1 && DockPanel.DocumentStyle == DocumentStyle.DockingSdi) 360 return Rectangle.Empty; 361 362 Rectangle rectWindow = DisplayingRectangle; 363 int x = rectWindow.X; 364 int width = rectWindow.Width; 365 int height = TabStripControl.MeasureHeight(); 366 367 int y = 0; 368 if (DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom) 369 y = rectWindow.Height - height; 370 else 371 y = rectWindow.Y; 372 373 return new Rectangle(x, y, width, height); 374 } 375 } 376 377 public virtual string CaptionText 378 { 379 get { return ActiveContent == null ? string.Empty : ActiveContent.DockHandler.TabText; } 380 } 381 382 private DockContentCollection m_contents; 383 public DockContentCollection Contents 384 { 385 get { return m_contents; } 386 } 387 388 private DockContentCollection m_displayingContents; 389 public DockContentCollection DisplayingContents 390 { 391 get { return m_displayingContents; } 392 } 393 394 private DockPanel m_dockPanel; 395 public DockPanel DockPanel 396 { 397 get { return m_dockPanel; } 398 } 399 400 private bool HasCaption 401 { 402 get 403 { 404 if (DockState == DockState.Document || 405 DockState == DockState.Hidden || 406 DockState == DockState.Unknown || 407 (DockState == DockState.Float && FloatWindow.VisibleNestedPanes.Count <= 1)) 408 return false; 409 else 410 return true; 411 } 412 } 413 414 private bool m_isActivated = false; 415 public bool IsActivated 416 { 417 get { return m_isActivated; } 418 } 419 internal void SetIsActivated(bool value) 420 { 421 if (m_isActivated == value) 422 return; 423 424 m_isActivated = value; 425 if (DockState != DockState.Document) 426 RefreshChanges(false); 427 OnIsActivatedChanged(EventArgs.Empty); 428 } 429 430 private bool m_isActiveDocumentPane = false; 431 public bool IsActiveDocumentPane 432 { 433 get { return m_isActiveDocumentPane; } 434 } 435 internal void SetIsActiveDocumentPane(bool value) 436 { 437 if (m_isActiveDocumentPane == value) 438 return; 439 440 m_isActiveDocumentPane = value; 441 if (DockState == DockState.Document) 442 RefreshChanges(); 443 OnIsActiveDocumentPaneChanged(EventArgs.Empty); 444 } 445 446 public bool IsDockStateValid(DockState dockState) 447 { 448 foreach (IDockContent content in Contents) 449 if (!content.DockHandler.IsDockStateValid(dockState)) 450 return false; 451 452 return true; 453 } 454 455 public bool IsAutoHide 456 { 457 get { return DockHelper.IsDockStateAutoHide(DockState); } 458 } 459 460 public AppearanceStyle Appearance 461 { 462 get { return (DockState == DockState.Document) ? AppearanceStyle.Document : AppearanceStyle.ToolWindow; } 463 } 464 465 internal Rectangle DisplayingRectangle 466 { 467 get { return ClientRectangle; } 468 } 469 470 public void Activate() 471 { 472 if (DockHelper.IsDockStateAutoHide(DockState) && DockPanel.ActiveAutoHideContent != ActiveContent) 473 DockPanel.ActiveAutoHideContent = ActiveContent; 474 else if (!IsActivated && ActiveContent != null) 475 ActiveContent.DockHandler.Activate(); 476 } 477 478 internal void AddContent(IDockContent content) 479 { 480 if (Contents.Contains(content)) 481 return; 482 483 Contents.Add(content); 484 } 485 486 internal void Close() 487 { 488 Dispose(); 489 } 490 491 public void CloseActiveContent() 492 { 493 CloseContent(ActiveContent); 494 } 495 496 internal void CloseContent(IDockContent content) 497 { 498 if (content == null) 499 return; 500 501 if (!content.DockHandler.CloseButton) 502 return; 503 504 DockPanel dockPanel = DockPanel; 505 506 dockPanel.SuspendLayout(true); 507 508 try 509 { 510 if (content.DockHandler.HideOnClose) 511 { 512 content.DockHandler.Hide(); 513 NestedDockingStatus.NestedPanes.SwitchPaneWithFirstChild(this); 514 } 515 else 516 content.DockHandler.Close(); 517 } 518 finally 519 { 520 dockPanel.ResumeLayout(true, true); 521 } 522 } 523 524 private HitTestResult GetHitTest(Point ptMouse) 525 { 526 Point ptMouseClient = PointToClient(ptMouse); 527 528 Rectangle rectCaption = CaptionRectangle; 529 if (rectCaption.Contains(ptMouseClient)) 530 return new HitTestResult(HitTestArea.Caption, -1); 531 532 Rectangle rectContent = ContentRectangle; 533 if (rectContent.Contains(ptMouseClient)) 534 return new HitTestResult(HitTestArea.Content, -1); 535 536 Rectangle rectTabStrip = TabStripRectangle; 537 if (rectTabStrip.Contains(ptMouseClient)) 538 return new HitTestResult(HitTestArea.TabStrip, TabStripControl.HitTest(TabStripControl.PointToClient(ptMouse))); 539 540 return new HitTestResult(HitTestArea.None, -1); 541 } 542 543 private bool m_isHidden = true; 544 public bool IsHidden 545 { 546 get { return m_isHidden; } 547 } 548 private void SetIsHidden(bool value) 549 { 550 if (m_isHidden == value) 551 return; 552 553 m_isHidden = value; 554 if (DockHelper.IsDockStateAutoHide(DockState)) 555 { 556 DockPanel.RefreshAutoHideStrip(); 557 DockPanel.PerformLayout(); 558 } 559 else if (NestedPanesContainer != null) 560 ((Control)NestedPanesContainer).PerformLayout(); 561 } 562 563 protected override void OnLayout(LayoutEventArgs levent) 564 { 565 SetIsHidden(DisplayingContents.Count == 0); 566 if (!IsHidden) 567 { 568 CaptionControl.Bounds = CaptionRectangle; 569 TabStripControl.Bounds = TabStripRectangle; 570 571 SetContentBounds(); 572 573 foreach (IDockContent content in Contents) 574 { 575 if (DisplayingContents.Contains(content)) 576 if (content.DockHandler.FlagClipWindow && content.DockHandler.Form.Visible) 577 content.DockHandler.FlagClipWindow = false; 578 } 579 } 580 581 base.OnLayout(levent); 582 } 583 584 internal void SetContentBounds() 585 { 586 Rectangle rectContent = ContentRectangle; 587 if (DockState == DockState.Document && DockPanel.DocumentStyle == DocumentStyle.DockingMdi) 588 rectContent = DockPanel.RectangleToMdiClient(RectangleToScreen(rectContent)); 589 590 Rectangle rectInactive = new Rectangle(-rectContent.Width, rectContent.Y, rectContent.Width, rectContent.Height); 591 foreach (IDockContent content in Contents) 592 if (content.DockHandler.Pane == this) 593 { 594 if (content == ActiveContent) 595 content.DockHandler.Form.Bounds = rectContent; 596 else 597 content.DockHandler.Form.Bounds = rectInactive; 598 } 599 } 600 601 internal void RefreshChanges() 602 { 603 RefreshChanges(true); 604 } 605 606 private void RefreshChanges(bool performLayout) 607 { 608 if (IsDisposed) 609 return; 610 611 CaptionControl.RefreshChanges(); 612 TabStripControl.RefreshChanges(); 613 if (DockState == DockState.Float && FloatWindow != null) 614 FloatWindow.RefreshChanges(); 615 if (DockHelper.IsDockStateAutoHide(DockState) && DockPanel != null) 616 { 617 DockPanel.RefreshAutoHideStrip(); 618 DockPanel.PerformLayout(); 619 } 620 621 if (performLayout) 622 PerformLayout(); 623 } 624 625 internal void RemoveContent(IDockContent content) 626 { 627 if (!Contents.Contains(content)) 628 return; 629 630 Contents.Remove(content); 631 } 632 633 public void SetContentIndex(IDockContent content, int index) 634 { 635 int oldIndex = Contents.IndexOf(content); 636 if (oldIndex == -1) 637 throw (new ArgumentException(Strings.DockPane_SetContentIndex_InvalidContent)); 638 639 if (index < 0 || index > Contents.Count - 1) 640 if (index != -1) 641 throw (new ArgumentOutOfRangeException(Strings.DockPane_SetContentIndex_InvalidIndex)); 642 643 if (oldIndex == index) 644 return; 645 if (oldIndex == Contents.Count - 1 && index == -1) 646 return; 647 648 Contents.Remove(content); 649 if (index == -1) 650 Contents.Add(content); 651 else if (oldIndex < index) 652 Contents.AddAt(content, index - 1); 653 else 654 Contents.AddAt(content, index); 655 656 RefreshChanges(); 657 } 658 659 private void SetParent() 660 { 661 if (DockState == DockState.Unknown || DockState == DockState.Hidden) 662 { 663 SetParent(null); 664 Splitter.Parent = null; 665 } 666 else if (DockState == DockState.Float) 667 { 668 SetParent(FloatWindow); 669 Splitter.Parent = FloatWindow; 670 } 671 else if (DockHelper.IsDockStateAutoHide(DockState)) 672 { 673 SetParent(DockPanel.AutoHideControl); 674 Splitter.Parent = null; 675 } 676 else 677 { 678 SetParent(DockPanel.DockWindows[DockState]); 679 Splitter.Parent = Parent; 680 } 681 } 682 683 private void SetParent(Control value) 684 { 685 if (Parent == value) 686 return; 687 688 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 689 // Workaround of .Net Framework bug: 690 // Change the parent of a control with focus may result in the first 691 // MDI child form get activated. 692 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 693 IDockContent contentFocused = GetFocusedContent(); 694 if (contentFocused != null) 695 DockPanel.SaveFocus(); 696 697 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 698 699 Parent = value; 700 701 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 702 // Workaround of .Net Framework bug: 703 // Change the parent of a control with focus may result in the first 704 // MDI child form get activated. 705 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 706 if (contentFocused != null) 707 contentFocused.DockHandler.Activate(); 708 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 709 } 710 711 public new void Show() 712 { 713 Activate(); 714 } 715 716 internal void TestDrop(IDockDragSource dragSource, DockOutlineBase dockOutline) 717 { 718 if (!dragSource.CanDockTo(this)) 719 return; 720 721 Point ptMouse = Control.MousePosition; 722 723 HitTestResult hitTestResult = GetHitTest(ptMouse); 724 if (hitTestResult.HitArea == HitTestArea.Caption) 725 dockOutline.Show(this, -1); 726 else if (hitTestResult.HitArea == HitTestArea.TabStrip && hitTestResult.Index != -1) 727 dockOutline.Show(this, hitTestResult.Index); 728 } 729 730 internal void ValidateActiveContent() 731 { 732 if (ActiveContent == null) 733 { 734 if (DisplayingContents.Count != 0) 735 ActiveContent = DisplayingContents[0]; 736 return; 737 } 738 739 if (DisplayingContents.IndexOf(ActiveContent) >= 0) 740 return; 741 742 IDockContent prevVisible = null; 743 for (int i = Contents.IndexOf(ActiveContent) - 1; i >= 0; i--) 744 if (Contents[i].DockHandler.DockState == DockState) 745 { 746 prevVisible = Contents[i]; 747 break; 748 } 749 750 IDockContent nextVisible = null; 751 for (int i = Contents.IndexOf(ActiveContent) + 1; i < Contents.Count; i++) 752 if (Contents[i].DockHandler.DockState == DockState) 753 { 754 nextVisible = Contents[i]; 755 break; 756 } 757 758 if (prevVisible != null) 759 ActiveContent = prevVisible; 760 else if (nextVisible != null) 761 ActiveContent = nextVisible; 762 else 763 ActiveContent = null; 764 } 765 766 private static readonly object DockStateChangedEvent = new object(); 767 public event EventHandler DockStateChanged 768 { 769 add { Events.AddHandler(DockStateChangedEvent, value); } 770 remove { Events.RemoveHandler(DockStateChangedEvent, value); } 771 } 772 protected virtual void OnDockStateChanged(EventArgs e) 773 { 774 EventHandler handler = (EventHandler)Events[DockStateChangedEvent]; 775 if (handler != null) 776 handler(this, e); 777 } 778 779 private static readonly object IsActivatedChangedEvent = new object(); 780 public event EventHandler IsActivatedChanged 781 { 782 add { Events.AddHandler(IsActivatedChangedEvent, value); } 783 remove { Events.RemoveHandler(IsActivatedChangedEvent, value); } 784 } 785 protected virtual void OnIsActivatedChanged(EventArgs e) 786 { 787 EventHandler handler = (EventHandler)Events[IsActivatedChangedEvent]; 788 if (handler != null) 789 handler(this, e); 790 } 791 792 private static readonly object IsActiveDocumentPaneChangedEvent = new object(); 793 public event EventHandler IsActiveDocumentPaneChanged 794 { 795 add { Events.AddHandler(IsActiveDocumentPaneChangedEvent, value); } 796 remove { Events.RemoveHandler(IsActiveDocumentPaneChangedEvent, value); } 797 } 798 protected virtual void OnIsActiveDocumentPaneChanged(EventArgs e) 799 { 800 EventHandler handler = (EventHandler)Events[IsActiveDocumentPaneChangedEvent]; 801 if (handler != null) 802 handler(this, e); 803 } 804 805 public DockWindow DockWindow 806 { 807 get { return (m_nestedDockingStatus.NestedPanes == null) ? null : m_nestedDockingStatus.NestedPanes.Container as DockWindow; } 808 set 809 { 810 DockWindow oldValue = DockWindow; 811 if (oldValue == value) 812 return; 813 814 DockTo(value); 815 } 816 } 817 818 public FloatWindow FloatWindow 819 { 820 get { return (m_nestedDockingStatus.NestedPanes == null) ? null : m_nestedDockingStatus.NestedPanes.Container as FloatWindow; } 821 set 822 { 823 FloatWindow oldValue = FloatWindow; 824 if (oldValue == value) 825 return; 826 827 DockTo(value); 828 } 829 } 830 831 private NestedDockingStatus m_nestedDockingStatus; 832 public NestedDockingStatus NestedDockingStatus 833 { 834 get { return m_nestedDockingStatus; } 835 } 836 837 private bool m_isFloat; 838 public bool IsFloat 839 { 840 get { return m_isFloat; } 841 } 842 843 public INestedPanesContainer NestedPanesContainer 844 { 845 get 846 { 847 if (NestedDockingStatus.NestedPanes == null) 848 return null; 849 else 850 return NestedDockingStatus.NestedPanes.Container; 851 } 852 } 853 854 private DockState m_dockState = DockState.Unknown; 855 public DockState DockState 856 { 857 get { return m_dockState; } 858 set 859 { 860 SetDockState(value); 861 } 862 } 863 864 public DockPane SetDockState(DockState value) 865 { 866 if (value == DockState.Unknown || value == DockState.Hidden) 867 throw new InvalidOperationException(Strings.DockPane_SetDockState_InvalidState); 868 869 if ((value == DockState.Float) == this.IsFloat) 870 { 871 InternalSetDockState(value); 872 return this; 873 } 874 875 if (DisplayingContents.Count == 0) 876 return null; 877 878 IDockContent firstContent = null; 879 for (int i = 0; i < DisplayingContents.Count; i++) 880 { 881 IDockContent content = DisplayingContents[i]; 882 if (content.DockHandler.IsDockStateValid(value)) 883 { 884 firstContent = content; 885 break; 886 } 887 } 888 if (firstContent == null) 889 return null; 890 891 firstContent.DockHandler.DockState = value; 892 DockPane pane = firstContent.DockHandler.Pane; 893 DockPanel.SuspendLayout(true); 894 for (int i = 0; i < DisplayingContents.Count; i++) 895 { 896 IDockContent content = DisplayingContents[i]; 897 if (content.DockHandler.IsDockStateValid(value)) 898 content.DockHandler.Pane = pane; 899 } 900 DockPanel.ResumeLayout(true, true); 901 return pane; 902 } 903 904 private void InternalSetDockState(DockState value) 905 { 906 if (m_dockState == value) 907 return; 908 909 DockState oldDockState = m_dockState; 910 INestedPanesContainer oldContainer = NestedPanesContainer; 911 912 m_dockState = value; 913 914 SuspendRefreshStateChange(); 915 916 IDockContent contentFocused = GetFocusedContent(); 917 if (contentFocused != null) 918 DockPanel.SaveFocus(); 919 920 if (!IsFloat) 921 DockWindow = DockPanel.DockWindows[DockState]; 922 else if (FloatWindow == null) 923 FloatWindow = DockPanel.FloatWindowFactory.CreateFloatWindow(DockPanel, this); 924 925 if (contentFocused != null) 926 if (!Win32Helper.IsRunningOnMono) 927 DockPanel.ContentFocusManager.Activate(contentFocused); 928 929 ResumeRefreshStateChange(oldContainer, oldDockState); 930 } 931 932 private int m_countRefreshStateChange = 0; 933 private void SuspendRefreshStateChange() 934 { 935 m_countRefreshStateChange++; 936 DockPanel.SuspendLayout(true); 937 } 938 939 private void ResumeRefreshStateChange() 940 { 941 m_countRefreshStateChange--; 942 System.Diagnostics.Debug.Assert(m_countRefreshStateChange >= 0); 943 DockPanel.ResumeLayout(true, true); 944 } 945 946 private bool IsRefreshStateChangeSuspended 947 { 948 get { return m_countRefreshStateChange != 0; } 949 } 950 951 private void ResumeRefreshStateChange(INestedPanesContainer oldContainer, DockState oldDockState) 952 { 953 ResumeRefreshStateChange(); 954 RefreshStateChange(oldContainer, oldDockState); 955 } 956 957 private void RefreshStateChange(INestedPanesContainer oldContainer, DockState oldDockState) 958 { 959 lock (this) 960 { 961 if (IsRefreshStateChangeSuspended) 962 return; 963 964 SuspendRefreshStateChange(); 965 } 966 967 DockPanel.SuspendLayout(true); 968 969 IDockContent contentFocused = GetFocusedContent(); 970 if (contentFocused != null) 971 DockPanel.SaveFocus(); 972 SetParent(); 973 974 if (ActiveContent != null) 975 ActiveContent.DockHandler.SetDockState(ActiveContent.DockHandler.IsHidden, DockState, ActiveContent.DockHandler.Pane); 976 foreach (IDockContent content in Contents) 977 { 978 if (content.DockHandler.Pane == this) 979 content.DockHandler.SetDockState(content.DockHandler.IsHidden, DockState, content.DockHandler.Pane); 980 } 981 982 if (oldContainer != null) 983 { 984 Control oldContainerControl = (Control)oldContainer; 985 if (oldContainer.DockState == oldDockState && !oldContainerControl.IsDisposed) 986 oldContainerControl.PerformLayout(); 987 } 988 if (DockHelper.IsDockStateAutoHide(oldDockState)) 989 DockPanel.RefreshActiveAutoHideContent(); 990 991 if (NestedPanesContainer.DockState == DockState) 992 ((Control)NestedPanesContainer).PerformLayout(); 993 if (DockHelper.IsDockStateAutoHide(DockState)) 994 DockPanel.RefreshActiveAutoHideContent(); 995 996 if (DockHelper.IsDockStateAutoHide(oldDockState) || 997 DockHelper.IsDockStateAutoHide(DockState)) 998 { 999 DockPanel.RefreshAutoHideStrip(); 1000 DockPanel.PerformLayout(); 1001 } 1002 1003 ResumeRefreshStateChange(); 1004 1005 if (contentFocused != null) 1006 contentFocused.DockHandler.Activate(); 1007 1008 DockPanel.ResumeLayout(true, true); 1009 1010 if (oldDockState != DockState) 1011 OnDockStateChanged(EventArgs.Empty); 1012 } 1013 1014 private IDockContent GetFocusedContent() 1015 { 1016 IDockContent contentFocused = null; 1017 foreach (IDockContent content in Contents) 1018 { 1019 if (content.DockHandler.Form.ContainsFocus) 1020 { 1021 contentFocused = content; 1022 break; 1023 } 1024 } 1025 1026 return contentFocused; 1027 } 1028 1029 public DockPane DockTo(INestedPanesContainer container) 1030 { 1031 if (container == null) 1032 throw new InvalidOperationException(Strings.DockPane_DockTo_NullContainer); 1033 1034 DockAlignment alignment; 1035 if (container.DockState == DockState.DockLeft || container.DockState == DockState.DockRight) 1036 alignment = DockAlignment.Bottom; 1037 else 1038 alignment = DockAlignment.Right; 1039 1040 return DockTo(container, container.NestedPanes.GetDefaultPreviousPane(this), alignment, 0.5); 1041 } 1042 1043 public DockPane DockTo(INestedPanesContainer container, DockPane previousPane, DockAlignment alignment, double proportion) 1044 { 1045 if (container == null) 1046 throw new InvalidOperationException(Strings.DockPane_DockTo_NullContainer); 1047 1048 if (container.IsFloat == this.IsFloat) 1049 { 1050 InternalAddToDockList(container, previousPane, alignment, proportion); 1051 return this; 1052 } 1053 1054 IDockContent firstContent = GetFirstContent(container.DockState); 1055 if (firstContent == null) 1056 return null; 1057 1058 DockPane pane; 1059 DockPanel.DummyContent.DockPanel = DockPanel; 1060 if (container.IsFloat) 1061 pane = DockPanel.DockPaneFactory.CreateDockPane(DockPanel.DummyContent, (FloatWindow)container, true); 1062 else 1063 pane = DockPanel.DockPaneFactory.CreateDockPane(DockPanel.DummyContent, container.DockState, true); 1064 1065 pane.DockTo(container, previousPane, alignment, proportion); 1066 SetVisibleContentsToPane(pane); 1067 DockPanel.DummyContent.DockPanel = null; 1068 1069 return pane; 1070 } 1071 1072 private void SetVisibleContentsToPane(DockPane pane) 1073 { 1074 SetVisibleContentsToPane(pane, ActiveContent); 1075 } 1076 1077 private void SetVisibleContentsToPane(DockPane pane, IDockContent activeContent) 1078 { 1079 for (int i = 0; i < DisplayingContents.Count; i++) 1080 { 1081 IDockContent content = DisplayingContents[i]; 1082 if (content.DockHandler.IsDockStateValid(pane.DockState)) 1083 { 1084 content.DockHandler.Pane = pane; 1085 i--; 1086 } 1087 } 1088 1089 if (activeContent.DockHandler.Pane == pane) 1090 pane.ActiveContent = activeContent; 1091 } 1092 1093 private void InternalAddToDockList(INestedPanesContainer container, DockPane prevPane, DockAlignment alignment, double proportion) 1094 { 1095 if ((container.DockState == DockState.Float) != IsFloat) 1096 throw new InvalidOperationException(Strings.DockPane_DockTo_InvalidContainer); 1097 1098 int count = container.NestedPanes.Count; 1099 if (container.NestedPanes.Contains(this)) 1100 count--; 1101 if (prevPane == null && count > 0) 1102 throw new InvalidOperationException(Strings.DockPane_DockTo_NullPrevPane); 1103 1104 if (prevPane != null && !container.NestedPanes.Contains(prevPane)) 1105 throw new InvalidOperationException(Strings.DockPane_DockTo_NoPrevPane); 1106 1107 if (prevPane == this) 1108 throw new InvalidOperationException(Strings.DockPane_DockTo_SelfPrevPane); 1109 1110 INestedPanesContainer oldContainer = NestedPanesContainer; 1111 DockState oldDockState = DockState; 1112 container.NestedPanes.Add(this); 1113 NestedDockingStatus.SetStatus(container.NestedPanes, prevPane, alignment, proportion); 1114 1115 if (DockHelper.IsDockWindowState(DockState)) 1116 m_dockState = container.DockState; 1117 1118 RefreshStateChange(oldContainer, oldDockState); 1119 } 1120 1121 public void SetNestedDockingProportion(double proportion) 1122 { 1123 NestedDockingStatus.SetStatus(NestedDockingStatus.NestedPanes, NestedDockingStatus.PreviousPane, NestedDockingStatus.Alignment, proportion); 1124 if (NestedPanesContainer != null) 1125 ((Control)NestedPanesContainer).PerformLayout(); 1126 } 1127 1128 public DockPane Float() 1129 { 1130 DockPanel.SuspendLayout(true); 1131 1132 IDockContent activeContent = ActiveContent; 1133 1134 DockPane floatPane = GetFloatPaneFromContents(); 1135 if (floatPane == null) 1136 { 1137 IDockContent firstContent = GetFirstContent(DockState.Float); 1138 if (firstContent == null) 1139 { 1140 DockPanel.ResumeLayout(true, true); 1141 return null; 1142 } 1143 floatPane = DockPanel.DockPaneFactory.CreateDockPane(firstContent, DockState.Float, true); 1144 } 1145 SetVisibleContentsToPane(floatPane, activeContent); 1146 1147 DockPanel.ResumeLayout(true, true); 1148 return floatPane; 1149 } 1150 1151 private DockPane GetFloatPaneFromContents() 1152 { 1153 DockPane floatPane = null; 1154 for (int i = 0; i < DisplayingContents.Count; i++) 1155 { 1156 IDockContent content = DisplayingContents[i]; 1157 if (!content.DockHandler.IsDockStateValid(DockState.Float)) 1158 continue; 1159 1160 if (floatPane != null && content.DockHandler.FloatPane != floatPane) 1161 return null; 1162 else 1163 floatPane = content.DockHandler.FloatPane; 1164 } 1165 1166 return floatPane; 1167 } 1168 1169 private IDockContent GetFirstContent(DockState dockState) 1170 { 1171 for (int i = 0; i < DisplayingContents.Count; i++) 1172 { 1173 IDockContent content = DisplayingContents[i]; 1174 if (content.DockHandler.IsDockStateValid(dockState)) 1175 return content; 1176 } 1177 return null; 1178 } 1179 1180 public void RestoreToPanel() 1181 { 1182 DockPanel.SuspendLayout(true); 1183 1184 IDockContent activeContent = DockPanel.ActiveContent; 1185 1186 for (int i = DisplayingContents.Count - 1; i >= 0; i--) 1187 { 1188 IDockContent content = DisplayingContents[i]; 1189 if (content.DockHandler.CheckDockState(false) != DockState.Unknown) 1190 content.DockHandler.IsFloat = false; 1191 } 1192 1193 DockPanel.ResumeLayout(true, true); 1194 } 1195 1196 [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 1197 protected override void WndProc(ref Message m) 1198 { 1199 if (m.Msg == (int)Win32.Msgs.WM_MOUSEACTIVATE) 1200 Activate(); 1201 1202 base.WndProc(ref m); 1203 } 1204 1205 #region IDockDragSource Members 1206 1207 #region IDragSource Members 1208 1209 Control IDragSource.DragControl 1210 { 1211 get { return this; } 1212 } 1213 1214 #endregion 1215 1216 bool IDockDragSource.IsDockStateValid(DockState dockState) 1217 { 1218 return IsDockStateValid(dockState); 1219 } 1220 1221 bool IDockDragSource.CanDockTo(DockPane pane) 1222 { 1223 if (!IsDockStateValid(pane.DockState)) 1224 return false; 1225 1226 if (pane == this) 1227 return false; 1228 1229 return true; 1230 } 1231 1232 Rectangle IDockDragSource.BeginDrag(Point ptMouse) 1233 { 1234 Point location = PointToScreen(new Point(0, 0)); 1235 Size size; 1236 1237 DockPane floatPane = ActiveContent.DockHandler.FloatPane; 1238 if (DockState == DockState.Float || floatPane == null || floatPane.FloatWindow.NestedPanes.Count != 1) 1239 size = DockPanel.DefaultFloatWindowSize; 1240 else 1241 size = floatPane.FloatWindow.Size; 1242 1243 if (ptMouse.X > location.X + size.Width) 1244 location.X += ptMouse.X - (location.X + size.Width) + Measures.SplitterSize; 1245 1246 return new Rectangle(location, size); 1247 } 1248 1249 void IDockDragSource.EndDrag() 1250 { 1251 } 1252 1253 public void FloatAt(Rectangle floatWindowBounds) 1254 { 1255 if (FloatWindow == null || FloatWindow.NestedPanes.Count != 1) 1256 FloatWindow = DockPanel.FloatWindowFactory.CreateFloatWindow(DockPanel, this, floatWindowBounds); 1257 else 1258 FloatWindow.Bounds = floatWindowBounds; 1259 1260 DockState = DockState.Float; 1261 1262 NestedDockingStatus.NestedPanes.SwitchPaneWithFirstChild(this); 1263 } 1264 1265 public void DockTo(DockPane pane, DockStyle dockStyle, int contentIndex) 1266 { 1267 if (dockStyle == DockStyle.Fill) 1268 { 1269 IDockContent activeContent = ActiveContent; 1270 for (int i = Contents.Count - 1; i >= 0; i--) 1271 { 1272 IDockContent c = Contents[i]; 1273 if (c.DockHandler.DockState == DockState) 1274 { 1275 c.DockHandler.Pane = pane; 1276 if (contentIndex != -1) 1277 pane.SetContentIndex(c, contentIndex); 1278 } 1279 } 1280 pane.ActiveContent = activeContent; 1281 } 1282 else 1283 { 1284 if (dockStyle == DockStyle.Left) 1285 DockTo(pane.NestedPanesContainer, pane, DockAlignment.Left, 0.5); 1286 else if (dockStyle == DockStyle.Right) 1287 DockTo(pane.NestedPanesContainer, pane, DockAlignment.Right, 0.5); 1288 else if (dockStyle == DockStyle.Top) 1289 DockTo(pane.NestedPanesContainer, pane, DockAlignment.Top, 0.5); 1290 else if (dockStyle == DockStyle.Bottom) 1291 DockTo(pane.NestedPanesContainer, pane, DockAlignment.Bottom, 0.5); 1292 1293 DockState = pane.DockState; 1294 } 1295 } 1296 1297 public void DockTo(DockPanel panel, DockStyle dockStyle) 1298 { 1299 if (panel != DockPanel) 1300 throw new ArgumentException(Strings.IDockDragSource_DockTo_InvalidPanel, "panel"); 1301 1302 if (dockStyle == DockStyle.Top) 1303 DockState = DockState.DockTop; 1304 else if (dockStyle == DockStyle.Bottom) 1305 DockState = DockState.DockBottom; 1306 else if (dockStyle == DockStyle.Left) 1307 DockState = DockState.DockLeft; 1308 else if (dockStyle == DockStyle.Right) 1309 DockState = DockState.DockRight; 1310 else if (dockStyle == DockStyle.Fill) 1311 DockState = DockState.Document; 1312 } 1313 1314 #endregion 1315 } 7 8 namespace WeifenLuo.WinFormsUI.Docking { 9 [ToolboxItem(false)] 10 public partial class DockPane : UserControl, IDockDragSource { 11 public enum AppearanceStyle { 12 ToolWindow, 13 Document 14 } 15 16 private enum HitTestArea { 17 Caption, 18 TabStrip, 19 Content, 20 None 21 } 22 23 private struct HitTestResult { 24 public HitTestArea HitArea; 25 public int Index; 26 27 public HitTestResult(HitTestArea hitTestArea, int index) { 28 HitArea = hitTestArea; 29 Index = index; 30 } 31 } 32 33 private DockPaneCaptionBase m_captionControl; 34 private DockPaneCaptionBase CaptionControl { 35 get { return m_captionControl; } 36 } 37 38 private DockPaneStripBase m_tabStripControl; 39 internal DockPaneStripBase TabStripControl { 40 get { return m_tabStripControl; } 41 } 42 43 internal protected DockPane(IDockContent content, DockState visibleState, bool show) { 44 InternalConstruct(content, visibleState, false, Rectangle.Empty, null, DockAlignment.Right, 0.5, show); 45 } 46 47 [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId = "1#")] 48 internal protected DockPane(IDockContent content, FloatWindow floatWindow, bool show) { 49 if (floatWindow == null) 50 throw new ArgumentNullException("floatWindow"); 51 52 InternalConstruct(content, DockState.Float, false, Rectangle.Empty, floatWindow.NestedPanes.GetDefaultPreviousPane(this), DockAlignment.Right, 0.5, show); 53 } 54 55 internal protected DockPane(IDockContent content, DockPane previousPane, DockAlignment alignment, double proportion, bool show) { 56 if (previousPane == null) 57 throw (new ArgumentNullException("previousPane")); 58 InternalConstruct(content, previousPane.DockState, false, Rectangle.Empty, previousPane, alignment, proportion, show); 59 } 60 61 [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId = "1#")] 62 internal protected DockPane(IDockContent content, Rectangle floatWindowBounds, bool show) { 63 InternalConstruct(content, DockState.Float, true, floatWindowBounds, null, DockAlignment.Right, 0.5, show); 64 } 65 66 private void InternalConstruct(IDockContent content, DockState dockState, bool flagBounds, Rectangle floatWindowBounds, DockPane prevPane, DockAlignment alignment, double proportion, bool show) { 67 if (dockState == DockState.Hidden || dockState == DockState.Unknown) 68 throw new ArgumentException(Strings.DockPane_SetDockState_InvalidState); 69 70 if (content == null) 71 throw new ArgumentNullException(Strings.DockPane_Constructor_NullContent); 72 73 if (content.DockHandler.DockPanel == null) 74 throw new ArgumentException(Strings.DockPane_Constructor_NullDockPanel); 75 76 77 SuspendLayout(); 78 SetStyle(ControlStyles.Selectable, false); 79 80 m_isFloat = (dockState == DockState.Float); 81 82 m_contents = new DockContentCollection(); 83 m_displayingContents = new DockContentCollection(this); 84 m_dockPanel = content.DockHandler.DockPanel; 85 m_dockPanel.AddPane(this); 86 87 m_splitter = new SplitterControl(this); 88 89 m_nestedDockingStatus = new NestedDockingStatus(this); 90 91 m_captionControl = DockPanel.DockPaneCaptionFactory.CreateDockPaneCaption(this); 92 m_tabStripControl = DockPanel.DockPaneStripFactory.CreateDockPaneStrip(this); 93 Controls.AddRange(new Control[] { m_captionControl, m_tabStripControl }); 94 95 DockPanel.SuspendLayout(true); 96 if (flagBounds) 97 FloatWindow = DockPanel.FloatWindowFactory.CreateFloatWindow(DockPanel, this, floatWindowBounds); 98 else if (prevPane != null) 99 DockTo(prevPane.NestedPanesContainer, prevPane, alignment, proportion); 100 101 SetDockState(dockState); 102 if (show) 103 content.DockHandler.Pane = this; 104 else if (this.IsFloat) 105 content.DockHandler.FloatPane = this; 106 else 107 content.DockHandler.PanelPane = this; 108 109 ResumeLayout(); 110 DockPanel.ResumeLayout(true, true); 111 } 112 113 private bool m_isDisposing; 114 115 protected override void Dispose(bool disposing) { 116 if (disposing) { 117 // IMPORTANT: avoid nested call into this method on Mono. 118 // https://github.com/dockpanelsuite/dockpanelsuite/issues/16 119 if (Win32Helper.IsRunningOnMono) { 120 if (m_isDisposing) 121 return; 122 123 m_isDisposing = true; 124 } 125 126 if (m_captionControl != null) { 127 m_captionControl.Dispose(); 128 m_captionControl = null; 129 } 130 131 m_dockState = DockState.Unknown; 132 133 if (NestedPanesContainer != null) 134 NestedPanesContainer.NestedPanes.Remove(this); 135 136 if (DockPanel != null) { 137 DockPanel.RemovePane(this); 138 m_dockPanel = null; 139 } 140 141 Splitter.Dispose(); 142 if (m_autoHidePane != null) 143 m_autoHidePane.Dispose(); 144 } 145 base.Dispose(disposing); 146 } 147 148 private IDockContent m_activeContent = null; 149 public virtual IDockContent ActiveContent { 150 get { return m_activeContent; } 151 set { 152 if (ActiveContent == value) 153 return; 154 155 if (value != null) { 156 if (!DisplayingContents.Contains(value)) 157 throw (new InvalidOperationException(Strings.DockPane_ActiveContent_InvalidValue)); 158 } else { 159 if (DisplayingContents.Count != 0) 160 throw (new InvalidOperationException(Strings.DockPane_ActiveContent_InvalidValue)); 161 } 162 163 IDockContent oldValue = m_activeContent; 164 165 if (DockPanel.ActiveAutoHideContent == oldValue) 166 DockPanel.ActiveAutoHideContent = null; 167 168 m_activeContent = value; 169 170 if (DockPanel.DocumentStyle == DocumentStyle.DockingMdi && DockState == DockState.Document) { 171 if (m_activeContent != null) 172 m_activeContent.DockHandler.Form.BringToFront(); 173 } else { 174 if (m_activeContent != null) 175 m_activeContent.DockHandler.SetVisible(); 176 if (oldValue != null && DisplayingContents.Contains(oldValue)) 177 oldValue.DockHandler.SetVisible(); 178 if (IsActivated && m_activeContent != null) 179 m_activeContent.DockHandler.Activate(); 180 } 181 182 if (FloatWindow != null) 183 FloatWindow.SetText(); 184 185 if (DockPanel.DocumentStyle == DocumentStyle.DockingMdi && 186 DockState == DockState.Document) 187 RefreshChanges(false); // delayed layout to reduce screen flicker 188 else 189 RefreshChanges(); 190 191 if (m_activeContent != null) 192 TabStripControl.EnsureTabVisible(m_activeContent); 193 } 194 } 195 196 private bool m_allowDockDragAndDrop = true; 197 public virtual bool AllowDockDragAndDrop { 198 get { return m_allowDockDragAndDrop; } 199 set { m_allowDockDragAndDrop = value; } 200 } 201 202 private IDisposable m_autoHidePane = null; 203 internal IDisposable AutoHidePane { 204 get { return m_autoHidePane; } 205 set { m_autoHidePane = value; } 206 } 207 208 private object m_autoHideTabs = null; 209 internal object AutoHideTabs { 210 get { return m_autoHideTabs; } 211 set { m_autoHideTabs = value; } 212 } 213 214 private object TabPageContextMenu { 215 get { 216 IDockContent content = ActiveContent; 217 218 if (content == null) 219 return null; 220 221 if (content.DockHandler.TabPageContextMenuStrip != null) 222 return content.DockHandler.TabPageContextMenuStrip; 223 else if (content.DockHandler.TabPageContextMenu != null) 224 return content.DockHandler.TabPageContextMenu; 225 else 226 return null; 227 } 228 } 229 230 internal bool HasTabPageContextMenu { 231 get { return TabPageContextMenu != null; } 232 } 233 234 internal void ShowTabPageContextMenu(Control control, Point position) { 235 object menu = TabPageContextMenu; 236 237 if (menu == null) 238 return; 239 240 ContextMenuStrip contextMenuStrip = menu as ContextMenuStrip; 241 if (contextMenuStrip != null) { 242 contextMenuStrip.Show(control, position); 243 return; 244 } 245 246 ContextMenu contextMenu = menu as ContextMenu; 247 if (contextMenu != null) 248 contextMenu.Show(this, position); 249 } 250 251 private Rectangle CaptionRectangle { 252 get { 253 if (!HasCaption) 254 return Rectangle.Empty; 255 256 Rectangle rectWindow = DisplayingRectangle; 257 int x, y, width; 258 x = rectWindow.X; 259 y = rectWindow.Y; 260 width = rectWindow.Width; 261 int height = CaptionControl.MeasureHeight(); 262 263 return new Rectangle(x, y, width, height); 264 } 265 } 266 267 internal Rectangle ContentRectangle { 268 get { 269 Rectangle rectWindow = DisplayingRectangle; 270 Rectangle rectCaption = CaptionRectangle; 271 Rectangle rectTabStrip = TabStripRectangle; 272 273 int x = rectWindow.X; 274 275 int y = rectWindow.Y + (rectCaption.IsEmpty ? 0 : rectCaption.Height); 276 if (DockState == DockState.Document && DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Top) 277 y += rectTabStrip.Height; 278 279 int width = rectWindow.Width; 280 int height = rectWindow.Height - rectCaption.Height - rectTabStrip.Height; 281 282 return new Rectangle(x, y, width, height); 283 } 284 } 285 286 internal Rectangle TabStripRectangle { 287 get { 288 if (Appearance == AppearanceStyle.ToolWindow) 289 return TabStripRectangle_ToolWindow; 290 else 291 return TabStripRectangle_Document; 292 } 293 } 294 295 private Rectangle TabStripRectangle_ToolWindow { 296 get { 297 if (DisplayingContents.Count <= 1 || IsAutoHide) 298 return Rectangle.Empty; 299 300 Rectangle rectWindow = DisplayingRectangle; 301 302 int width = rectWindow.Width; 303 int height = TabStripControl.MeasureHeight(); 304 int x = rectWindow.X; 305 int y = rectWindow.Bottom - height; 306 Rectangle rectCaption = CaptionRectangle; 307 if (rectCaption.Contains(x, y)) 308 y = rectCaption.Y + rectCaption.Height; 309 310 return new Rectangle(x, y, width, height); 311 } 312 } 313 314 private Rectangle TabStripRectangle_Document { 315 get { 316 if (DisplayingContents.Count == 0) 317 return Rectangle.Empty; 318 319 if (DisplayingContents.Count == 1 && DockPanel.DocumentStyle == DocumentStyle.DockingSdi) 320 return Rectangle.Empty; 321 322 Rectangle rectWindow = DisplayingRectangle; 323 int x = rectWindow.X; 324 int width = rectWindow.Width; 325 int height = TabStripControl.MeasureHeight(); 326 327 int y = 0; 328 if (DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom) 329 y = rectWindow.Height - height; 330 else 331 y = rectWindow.Y; 332 333 return new Rectangle(x, y, width, height); 334 } 335 } 336 337 public virtual string CaptionText { 338 get { return ActiveContent == null ? string.Empty : ActiveContent.DockHandler.TabText; } 339 } 340 341 private DockContentCollection m_contents; 342 public DockContentCollection Contents { 343 get { return m_contents; } 344 } 345 346 private DockContentCollection m_displayingContents; 347 public DockContentCollection DisplayingContents { 348 get { return m_displayingContents; } 349 } 350 351 private DockPanel m_dockPanel; 352 public DockPanel DockPanel { 353 get { return m_dockPanel; } 354 } 355 356 private bool HasCaption { 357 get { 358 if (DockState == DockState.Document || 359 DockState == DockState.Hidden || 360 DockState == DockState.Unknown || 361 (DockState == DockState.Float && FloatWindow.VisibleNestedPanes.Count <= 1)) 362 return false; 363 else 364 return true; 365 } 366 } 367 368 private bool m_isActivated = false; 369 public bool IsActivated { 370 get { return m_isActivated; } 371 } 372 internal void SetIsActivated(bool value) { 373 if (m_isActivated == value) 374 return; 375 376 m_isActivated = value; 377 if (DockState != DockState.Document) 378 RefreshChanges(false); 379 OnIsActivatedChanged(EventArgs.Empty); 380 } 381 382 private bool m_isActiveDocumentPane = false; 383 public bool IsActiveDocumentPane { 384 get { return m_isActiveDocumentPane; } 385 } 386 internal void SetIsActiveDocumentPane(bool value) { 387 if (m_isActiveDocumentPane == value) 388 return; 389 390 m_isActiveDocumentPane = value; 391 if (DockState == DockState.Document) 392 RefreshChanges(); 393 OnIsActiveDocumentPaneChanged(EventArgs.Empty); 394 } 395 396 public bool IsDockStateValid(DockState dockState) { 397 foreach (IDockContent content in Contents) 398 if (!content.DockHandler.IsDockStateValid(dockState)) 399 return false; 400 401 return true; 402 } 403 404 public bool IsAutoHide { 405 get { return DockHelper.IsDockStateAutoHide(DockState); } 406 } 407 408 public AppearanceStyle Appearance { 409 get { return (DockState == DockState.Document) ? AppearanceStyle.Document : AppearanceStyle.ToolWindow; } 410 } 411 412 internal Rectangle DisplayingRectangle { 413 get { return ClientRectangle; } 414 } 415 416 public void Activate() { 417 if (DockHelper.IsDockStateAutoHide(DockState) && DockPanel.ActiveAutoHideContent != ActiveContent) 418 DockPanel.ActiveAutoHideContent = ActiveContent; 419 else if (!IsActivated && ActiveContent != null) 420 ActiveContent.DockHandler.Activate(); 421 } 422 423 internal void AddContent(IDockContent content) { 424 if (Contents.Contains(content)) 425 return; 426 427 Contents.Add(content); 428 } 429 430 internal void Close() { 431 Dispose(); 432 } 433 434 public void CloseActiveContent() { 435 CloseContent(ActiveContent); 436 } 437 438 internal void CloseContent(IDockContent content) { 439 if (content == null) 440 return; 441 442 if (!content.DockHandler.CloseButton) 443 return; 444 445 DockPanel dockPanel = DockPanel; 446 447 dockPanel.SuspendLayout(true); 448 449 try { 450 if (content.DockHandler.HideOnClose) { 451 content.DockHandler.Hide(); 452 NestedDockingStatus.NestedPanes.SwitchPaneWithFirstChild(this); 453 } else 454 content.DockHandler.Close(); 455 } 456 finally { 457 dockPanel.ResumeLayout(true, true); 458 } 459 } 460 461 private HitTestResult GetHitTest(Point ptMouse) { 462 Point ptMouseClient = PointToClient(ptMouse); 463 464 Rectangle rectCaption = CaptionRectangle; 465 if (rectCaption.Contains(ptMouseClient)) 466 return new HitTestResult(HitTestArea.Caption, -1); 467 468 Rectangle rectContent = ContentRectangle; 469 if (rectContent.Contains(ptMouseClient)) 470 return new HitTestResult(HitTestArea.Content, -1); 471 472 Rectangle rectTabStrip = TabStripRectangle; 473 if (rectTabStrip.Contains(ptMouseClient)) 474 return new HitTestResult(HitTestArea.TabStrip, TabStripControl.HitTest(TabStripControl.PointToClient(ptMouse))); 475 476 return new HitTestResult(HitTestArea.None, -1); 477 } 478 479 private bool m_isHidden = true; 480 public bool IsHidden { 481 get { return m_isHidden; } 482 } 483 private void SetIsHidden(bool value) { 484 if (m_isHidden == value) 485 return; 486 487 m_isHidden = value; 488 if (DockHelper.IsDockStateAutoHide(DockState)) { 489 DockPanel.RefreshAutoHideStrip(); 490 DockPanel.PerformLayout(); 491 } else if (NestedPanesContainer != null) 492 ((Control)NestedPanesContainer).PerformLayout(); 493 } 494 495 protected override void OnLayout(LayoutEventArgs levent) { 496 SetIsHidden(DisplayingContents.Count == 0); 497 if (!IsHidden) { 498 CaptionControl.Bounds = CaptionRectangle; 499 TabStripControl.Bounds = TabStripRectangle; 500 501 SetContentBounds(); 502 503 foreach (IDockContent content in Contents) { 504 if (DisplayingContents.Contains(content)) 505 if (content.DockHandler.FlagClipWindow && content.DockHandler.Form.Visible) 506 content.DockHandler.FlagClipWindow = false; 507 } 508 } 509 510 base.OnLayout(levent); 511 } 512 513 internal void SetContentBounds() { 514 Rectangle rectContent = ContentRectangle; 515 if (DockState == DockState.Document && DockPanel.DocumentStyle == DocumentStyle.DockingMdi) 516 rectContent = DockPanel.RectangleToMdiClient(RectangleToScreen(rectContent)); 517 518 Rectangle rectInactive = new Rectangle(-rectContent.Width, rectContent.Y, rectContent.Width, rectContent.Height); 519 foreach (IDockContent content in Contents) 520 if (content.DockHandler.Pane == this) { 521 if (content == ActiveContent) 522 content.DockHandler.Form.Bounds = rectContent; 523 else 524 content.DockHandler.Form.Bounds = rectInactive; 525 } 526 } 527 528 internal void RefreshChanges() { 529 RefreshChanges(true); 530 } 531 532 private void RefreshChanges(bool performLayout) { 533 if (IsDisposed) 534 return; 535 536 CaptionControl.RefreshChanges(); 537 TabStripControl.RefreshChanges(); 538 if (DockState == DockState.Float && FloatWindow != null) 539 FloatWindow.RefreshChanges(); 540 if (DockHelper.IsDockStateAutoHide(DockState) && DockPanel != null) { 541 DockPanel.RefreshAutoHideStrip(); 542 DockPanel.PerformLayout(); 543 } 544 545 if (performLayout) 546 PerformLayout(); 547 } 548 549 internal void RemoveContent(IDockContent content) { 550 if (!Contents.Contains(content)) 551 return; 552 553 Contents.Remove(content); 554 } 555 556 public void SetContentIndex(IDockContent content, int index) { 557 int oldIndex = Contents.IndexOf(content); 558 if (oldIndex == -1) 559 throw (new ArgumentException(Strings.DockPane_SetContentIndex_InvalidContent)); 560 561 if (index < 0 || index > Contents.Count - 1) 562 if (index != -1) 563 throw (new ArgumentOutOfRangeException(Strings.DockPane_SetContentIndex_InvalidIndex)); 564 565 if (oldIndex == index) 566 return; 567 if (oldIndex == Contents.Count - 1 && index == -1) 568 return; 569 570 Contents.Remove(content); 571 if (index == -1) 572 Contents.Add(content); 573 else if (oldIndex < index) 574 Contents.AddAt(content, index - 1); 575 else 576 Contents.AddAt(content, index); 577 578 RefreshChanges(); 579 } 580 581 private void SetParent() { 582 if (DockState == DockState.Unknown || DockState == DockState.Hidden) { 583 SetParent(null); 584 Splitter.Parent = null; 585 } else if (DockState == DockState.Float) { 586 SetParent(FloatWindow); 587 Splitter.Parent = FloatWindow; 588 } else if (DockHelper.IsDockStateAutoHide(DockState)) { 589 SetParent(DockPanel.AutoHideControl); 590 Splitter.Parent = null; 591 } else { 592 SetParent(DockPanel.DockWindows[DockState]); 593 Splitter.Parent = Parent; 594 } 595 } 596 597 private void SetParent(Control value) { 598 if (Parent == value) 599 return; 600 601 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 602 // Workaround of .Net Framework bug: 603 // Change the parent of a control with focus may result in the first 604 // MDI child form get activated. 605 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 606 IDockContent contentFocused = GetFocusedContent(); 607 if (contentFocused != null) 608 DockPanel.SaveFocus(); 609 610 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 611 612 Parent = value; 613 614 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 615 // Workaround of .Net Framework bug: 616 // Change the parent of a control with focus may result in the first 617 // MDI child form get activated. 618 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 619 if (contentFocused != null) 620 contentFocused.DockHandler.Activate(); 621 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 622 } 623 624 public new void Show() { 625 Activate(); 626 } 627 628 internal void TestDrop(IDockDragSource dragSource, DockOutlineBase dockOutline) { 629 if (!dragSource.CanDockTo(this)) 630 return; 631 632 Point ptMouse = Control.MousePosition; 633 634 HitTestResult hitTestResult = GetHitTest(ptMouse); 635 if (hitTestResult.HitArea == HitTestArea.Caption) 636 dockOutline.Show(this, -1); 637 else if (hitTestResult.HitArea == HitTestArea.TabStrip && hitTestResult.Index != -1) 638 dockOutline.Show(this, hitTestResult.Index); 639 } 640 641 internal void ValidateActiveContent() { 642 if (ActiveContent == null) { 643 if (DisplayingContents.Count != 0) 644 ActiveContent = DisplayingContents[0]; 645 return; 646 } 647 648 if (DisplayingContents.IndexOf(ActiveContent) >= 0) 649 return; 650 651 IDockContent prevVisible = null; 652 for (int i = Contents.IndexOf(ActiveContent) - 1; i >= 0; i--) 653 if (Contents[i].DockHandler.DockState == DockState) { 654 prevVisible = Contents[i]; 655 break; 656 } 657 658 IDockContent nextVisible = null; 659 for (int i = Contents.IndexOf(ActiveContent) + 1; i < Contents.Count; i++) 660 if (Contents[i].DockHandler.DockState == DockState) { 661 nextVisible = Contents[i]; 662 break; 663 } 664 665 if (prevVisible != null) 666 ActiveContent = prevVisible; 667 else if (nextVisible != null) 668 ActiveContent = nextVisible; 669 else 670 ActiveContent = null; 671 } 672 673 private static readonly object DockStateChangedEvent = new object(); 674 public event EventHandler DockStateChanged { 675 add { Events.AddHandler(DockStateChangedEvent, value); } 676 remove { Events.RemoveHandler(DockStateChangedEvent, value); } 677 } 678 protected virtual void OnDockStateChanged(EventArgs e) { 679 EventHandler handler = (EventHandler)Events[DockStateChangedEvent]; 680 if (handler != null) 681 handler(this, e); 682 } 683 684 private static readonly object IsActivatedChangedEvent = new object(); 685 public event EventHandler IsActivatedChanged { 686 add { Events.AddHandler(IsActivatedChangedEvent, value); } 687 remove { Events.RemoveHandler(IsActivatedChangedEvent, value); } 688 } 689 protected virtual void OnIsActivatedChanged(EventArgs e) { 690 EventHandler handler = (EventHandler)Events[IsActivatedChangedEvent]; 691 if (handler != null) 692 handler(this, e); 693 } 694 695 private static readonly object IsActiveDocumentPaneChangedEvent = new object(); 696 public event EventHandler IsActiveDocumentPaneChanged { 697 add { Events.AddHandler(IsActiveDocumentPaneChangedEvent, value); } 698 remove { Events.RemoveHandler(IsActiveDocumentPaneChangedEvent, value); } 699 } 700 protected virtual void OnIsActiveDocumentPaneChanged(EventArgs e) { 701 EventHandler handler = (EventHandler)Events[IsActiveDocumentPaneChangedEvent]; 702 if (handler != null) 703 handler(this, e); 704 } 705 706 public DockWindow DockWindow { 707 get { return (m_nestedDockingStatus.NestedPanes == null) ? null : m_nestedDockingStatus.NestedPanes.Container as DockWindow; } 708 set { 709 DockWindow oldValue = DockWindow; 710 if (oldValue == value) 711 return; 712 713 DockTo(value); 714 } 715 } 716 717 public FloatWindow FloatWindow { 718 get { return (m_nestedDockingStatus.NestedPanes == null) ? null : m_nestedDockingStatus.NestedPanes.Container as FloatWindow; } 719 set { 720 FloatWindow oldValue = FloatWindow; 721 if (oldValue == value) 722 return; 723 724 DockTo(value); 725 } 726 } 727 728 private NestedDockingStatus m_nestedDockingStatus; 729 public NestedDockingStatus NestedDockingStatus { 730 get { return m_nestedDockingStatus; } 731 } 732 733 private bool m_isFloat; 734 public bool IsFloat { 735 get { return m_isFloat; } 736 } 737 738 public INestedPanesContainer NestedPanesContainer { 739 get { 740 if (NestedDockingStatus.NestedPanes == null) 741 return null; 742 else 743 return NestedDockingStatus.NestedPanes.Container; 744 } 745 } 746 747 private DockState m_dockState = DockState.Unknown; 748 public DockState DockState { 749 get { return m_dockState; } 750 set { 751 SetDockState(value); 752 } 753 } 754 755 public DockPane SetDockState(DockState value) { 756 if (value == DockState.Unknown || value == DockState.Hidden) 757 throw new InvalidOperationException(Strings.DockPane_SetDockState_InvalidState); 758 759 if ((value == DockState.Float) == this.IsFloat) { 760 InternalSetDockState(value); 761 return this; 762 } 763 764 if (DisplayingContents.Count == 0) 765 return null; 766 767 IDockContent firstContent = null; 768 for (int i = 0; i < DisplayingContents.Count; i++) { 769 IDockContent content = DisplayingContents[i]; 770 if (content.DockHandler.IsDockStateValid(value)) { 771 firstContent = content; 772 break; 773 } 774 } 775 if (firstContent == null) 776 return null; 777 778 firstContent.DockHandler.DockState = value; 779 DockPane pane = firstContent.DockHandler.Pane; 780 DockPanel.SuspendLayout(true); 781 for (int i = 0; i < DisplayingContents.Count; i++) { 782 IDockContent content = DisplayingContents[i]; 783 if (content.DockHandler.IsDockStateValid(value)) 784 content.DockHandler.Pane = pane; 785 } 786 DockPanel.ResumeLayout(true, true); 787 return pane; 788 } 789 790 private void InternalSetDockState(DockState value) { 791 if (m_dockState == value) 792 return; 793 794 DockState oldDockState = m_dockState; 795 INestedPanesContainer oldContainer = NestedPanesContainer; 796 797 m_dockState = value; 798 799 SuspendRefreshStateChange(); 800 801 IDockContent contentFocused = GetFocusedContent(); 802 if (contentFocused != null) 803 DockPanel.SaveFocus(); 804 805 if (!IsFloat) 806 DockWindow = DockPanel.DockWindows[DockState]; 807 else if (FloatWindow == null) 808 FloatWindow = DockPanel.FloatWindowFactory.CreateFloatWindow(DockPanel, this); 809 810 if (contentFocused != null) 811 if (!Win32Helper.IsRunningOnMono) 812 DockPanel.ContentFocusManager.Activate(contentFocused); 813 814 ResumeRefreshStateChange(oldContainer, oldDockState); 815 } 816 817 private int m_countRefreshStateChange = 0; 818 private void SuspendRefreshStateChange() { 819 m_countRefreshStateChange++; 820 DockPanel.SuspendLayout(true); 821 } 822 823 private void ResumeRefreshStateChange() { 824 m_countRefreshStateChange--; 825 System.Diagnostics.Debug.Assert(m_countRefreshStateChange >= 0); 826 DockPanel.ResumeLayout(true, true); 827 } 828 829 private bool IsRefreshStateChangeSuspended { 830 get { return m_countRefreshStateChange != 0; } 831 } 832 833 private void ResumeRefreshStateChange(INestedPanesContainer oldContainer, DockState oldDockState) { 834 ResumeRefreshStateChange(); 835 RefreshStateChange(oldContainer, oldDockState); 836 } 837 838 private void RefreshStateChange(INestedPanesContainer oldContainer, DockState oldDockState) { 839 lock (this) { 840 if (IsRefreshStateChangeSuspended) 841 return; 842 843 SuspendRefreshStateChange(); 844 } 845 846 DockPanel.SuspendLayout(true); 847 848 IDockContent contentFocused = GetFocusedContent(); 849 if (contentFocused != null) 850 DockPanel.SaveFocus(); 851 SetParent(); 852 853 if (ActiveContent != null) 854 ActiveContent.DockHandler.SetDockState(ActiveContent.DockHandler.IsHidden, DockState, ActiveContent.DockHandler.Pane); 855 foreach (IDockContent content in Contents) { 856 if (content.DockHandler.Pane == this) 857 content.DockHandler.SetDockState(content.DockHandler.IsHidden, DockState, content.DockHandler.Pane); 858 } 859 860 if (oldContainer != null) { 861 Control oldContainerControl = (Control)oldContainer; 862 if (oldContainer.DockState == oldDockState && !oldContainerControl.IsDisposed) 863 oldContainerControl.PerformLayout(); 864 } 865 if (DockHelper.IsDockStateAutoHide(oldDockState)) 866 DockPanel.RefreshActiveAutoHideContent(); 867 868 if (NestedPanesContainer.DockState == DockState) 869 ((Control)NestedPanesContainer).PerformLayout(); 870 if (DockHelper.IsDockStateAutoHide(DockState)) 871 DockPanel.RefreshActiveAutoHideContent(); 872 873 if (DockHelper.IsDockStateAutoHide(oldDockState) || 874 DockHelper.IsDockStateAutoHide(DockState)) { 875 DockPanel.RefreshAutoHideStrip(); 876 DockPanel.PerformLayout(); 877 } 878 879 ResumeRefreshStateChange(); 880 881 if (contentFocused != null) 882 contentFocused.DockHandler.Activate(); 883 884 DockPanel.ResumeLayout(true, true); 885 886 if (oldDockState != DockState) 887 OnDockStateChanged(EventArgs.Empty); 888 } 889 890 private IDockContent GetFocusedContent() { 891 IDockContent contentFocused = null; 892 foreach (IDockContent content in Contents) { 893 if (content.DockHandler.Form.ContainsFocus) { 894 contentFocused = content; 895 break; 896 } 897 } 898 899 return contentFocused; 900 } 901 902 public DockPane DockTo(INestedPanesContainer container) { 903 if (container == null) 904 throw new InvalidOperationException(Strings.DockPane_DockTo_NullContainer); 905 906 DockAlignment alignment; 907 if (container.DockState == DockState.DockLeft || container.DockState == DockState.DockRight) 908 alignment = DockAlignment.Bottom; 909 else 910 alignment = DockAlignment.Right; 911 912 return DockTo(container, container.NestedPanes.GetDefaultPreviousPane(this), alignment, 0.5); 913 } 914 915 public DockPane DockTo(INestedPanesContainer container, DockPane previousPane, DockAlignment alignment, double proportion) { 916 if (container == null) 917 throw new InvalidOperationException(Strings.DockPane_DockTo_NullContainer); 918 919 if (container.IsFloat == this.IsFloat) { 920 InternalAddToDockList(container, previousPane, alignment, proportion); 921 return this; 922 } 923 924 IDockContent firstContent = GetFirstContent(container.DockState); 925 if (firstContent == null) 926 return null; 927 928 DockPane pane; 929 DockPanel.DummyContent.DockPanel = DockPanel; 930 if (container.IsFloat) 931 pane = DockPanel.DockPaneFactory.CreateDockPane(DockPanel.DummyContent, (FloatWindow)container, true); 932 else 933 pane = DockPanel.DockPaneFactory.CreateDockPane(DockPanel.DummyContent, container.DockState, true); 934 935 pane.DockTo(container, previousPane, alignment, proportion); 936 SetVisibleContentsToPane(pane); 937 DockPanel.DummyContent.DockPanel = null; 938 939 return pane; 940 } 941 942 private void SetVisibleContentsToPane(DockPane pane) { 943 SetVisibleContentsToPane(pane, ActiveContent); 944 } 945 946 private void SetVisibleContentsToPane(DockPane pane, IDockContent activeContent) { 947 for (int i = 0; i < DisplayingContents.Count; i++) { 948 IDockContent content = DisplayingContents[i]; 949 if (content.DockHandler.IsDockStateValid(pane.DockState)) { 950 content.DockHandler.Pane = pane; 951 i--; 952 } 953 } 954 955 if (activeContent.DockHandler.Pane == pane) 956 pane.ActiveContent = activeContent; 957 } 958 959 private void InternalAddToDockList(INestedPanesContainer container, DockPane prevPane, DockAlignment alignment, double proportion) { 960 if ((container.DockState == DockState.Float) != IsFloat) 961 throw new InvalidOperationException(Strings.DockPane_DockTo_InvalidContainer); 962 963 int count = container.NestedPanes.Count; 964 if (container.NestedPanes.Contains(this)) 965 count--; 966 if (prevPane == null && count > 0) 967 throw new InvalidOperationException(Strings.DockPane_DockTo_NullPrevPane); 968 969 if (prevPane != null && !container.NestedPanes.Contains(prevPane)) 970 throw new InvalidOperationException(Strings.DockPane_DockTo_NoPrevPane); 971 972 if (prevPane == this) 973 throw new InvalidOperationException(Strings.DockPane_DockTo_SelfPrevPane); 974 975 INestedPanesContainer oldContainer = NestedPanesContainer; 976 DockState oldDockState = DockState; 977 container.NestedPanes.Add(this); 978 NestedDockingStatus.SetStatus(container.NestedPanes, prevPane, alignment, proportion); 979 980 if (DockHelper.IsDockWindowState(DockState)) 981 m_dockState = container.DockState; 982 983 RefreshStateChange(oldContainer, oldDockState); 984 } 985 986 public void SetNestedDockingProportion(double proportion) { 987 NestedDockingStatus.SetStatus(NestedDockingStatus.NestedPanes, NestedDockingStatus.PreviousPane, NestedDockingStatus.Alignment, proportion); 988 if (NestedPanesContainer != null) 989 ((Control)NestedPanesContainer).PerformLayout(); 990 } 991 992 public DockPane Float() { 993 DockPanel.SuspendLayout(true); 994 995 IDockContent activeContent = ActiveContent; 996 997 DockPane floatPane = GetFloatPaneFromContents(); 998 if (floatPane == null) { 999 IDockContent firstContent = GetFirstContent(DockState.Float); 1000 if (firstContent == null) { 1001 DockPanel.ResumeLayout(true, true); 1002 return null; 1003 } 1004 floatPane = DockPanel.DockPaneFactory.CreateDockPane(firstContent, DockState.Float, true); 1005 } 1006 SetVisibleContentsToPane(floatPane, activeContent); 1007 1008 DockPanel.ResumeLayout(true, true); 1009 return floatPane; 1010 } 1011 1012 private DockPane GetFloatPaneFromContents() { 1013 DockPane floatPane = null; 1014 for (int i = 0; i < DisplayingContents.Count; i++) { 1015 IDockContent content = DisplayingContents[i]; 1016 if (!content.DockHandler.IsDockStateValid(DockState.Float)) 1017 continue; 1018 1019 if (floatPane != null && content.DockHandler.FloatPane != floatPane) 1020 return null; 1021 else 1022 floatPane = content.DockHandler.FloatPane; 1023 } 1024 1025 return floatPane; 1026 } 1027 1028 private IDockContent GetFirstContent(DockState dockState) { 1029 for (int i = 0; i < DisplayingContents.Count; i++) { 1030 IDockContent content = DisplayingContents[i]; 1031 if (content.DockHandler.IsDockStateValid(dockState)) 1032 return content; 1033 } 1034 return null; 1035 } 1036 1037 public void RestoreToPanel() { 1038 DockPanel.SuspendLayout(true); 1039 1040 IDockContent activeContent = DockPanel.ActiveContent; 1041 1042 for (int i = DisplayingContents.Count - 1; i >= 0; i--) { 1043 IDockContent content = DisplayingContents[i]; 1044 if (content.DockHandler.CheckDockState(false) != DockState.Unknown) 1045 content.DockHandler.IsFloat = false; 1046 } 1047 1048 DockPanel.ResumeLayout(true, true); 1049 } 1050 1051 [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 1052 protected override void WndProc(ref Message m) { 1053 if (m.Msg == (int)Win32.Msgs.WM_MOUSEACTIVATE) 1054 Activate(); 1055 1056 base.WndProc(ref m); 1057 } 1058 1059 #region IDockDragSource Members 1060 1061 #region IDragSource Members 1062 1063 Control IDragSource.DragControl { 1064 get { return this; } 1065 } 1066 1067 #endregion 1068 1069 bool IDockDragSource.IsDockStateValid(DockState dockState) { 1070 return IsDockStateValid(dockState); 1071 } 1072 1073 bool IDockDragSource.CanDockTo(DockPane pane) { 1074 if (!IsDockStateValid(pane.DockState)) 1075 return false; 1076 1077 if (pane == this) 1078 return false; 1079 1080 return true; 1081 } 1082 1083 Rectangle IDockDragSource.BeginDrag(Point ptMouse) { 1084 Point location = PointToScreen(new Point(0, 0)); 1085 Size size; 1086 1087 DockPane floatPane = ActiveContent.DockHandler.FloatPane; 1088 if (DockState == DockState.Float || floatPane == null || floatPane.FloatWindow.NestedPanes.Count != 1) 1089 size = DockPanel.DefaultFloatWindowSize; 1090 else 1091 size = floatPane.FloatWindow.Size; 1092 1093 if (ptMouse.X > location.X + size.Width) 1094 location.X += ptMouse.X - (location.X + size.Width) + Measures.SplitterSize; 1095 1096 return new Rectangle(location, size); 1097 } 1098 1099 void IDockDragSource.EndDrag() { 1100 } 1101 1102 public void FloatAt(Rectangle floatWindowBounds) { 1103 if (FloatWindow == null || FloatWindow.NestedPanes.Count != 1) 1104 FloatWindow = DockPanel.FloatWindowFactory.CreateFloatWindow(DockPanel, this, floatWindowBounds); 1105 else 1106 FloatWindow.Bounds = floatWindowBounds; 1107 1108 DockState = DockState.Float; 1109 1110 NestedDockingStatus.NestedPanes.SwitchPaneWithFirstChild(this); 1111 } 1112 1113 public void DockTo(DockPane pane, DockStyle dockStyle, int contentIndex) { 1114 if (dockStyle == DockStyle.Fill) { 1115 IDockContent activeContent = ActiveContent; 1116 for (int i = Contents.Count - 1; i >= 0; i--) { 1117 IDockContent c = Contents[i]; 1118 if (c.DockHandler.DockState == DockState) { 1119 c.DockHandler.Pane = pane; 1120 if (contentIndex != -1) 1121 pane.SetContentIndex(c, contentIndex); 1122 } 1123 } 1124 pane.ActiveContent = activeContent; 1125 } else { 1126 if (dockStyle == DockStyle.Left) 1127 DockTo(pane.NestedPanesContainer, pane, DockAlignment.Left, 0.5); 1128 else if (dockStyle == DockStyle.Right) 1129 DockTo(pane.NestedPanesContainer, pane, DockAlignment.Right, 0.5); 1130 else if (dockStyle == DockStyle.Top) 1131 DockTo(pane.NestedPanesContainer, pane, DockAlignment.Top, 0.5); 1132 else if (dockStyle == DockStyle.Bottom) 1133 DockTo(pane.NestedPanesContainer, pane, DockAlignment.Bottom, 0.5); 1134 1135 DockState = pane.DockState; 1136 } 1137 } 1138 1139 public void DockTo(DockPanel panel, DockStyle dockStyle) { 1140 if (panel != DockPanel) 1141 throw new ArgumentException(Strings.IDockDragSource_DockTo_InvalidPanel, "panel"); 1142 1143 if (dockStyle == DockStyle.Top) 1144 DockState = DockState.DockTop; 1145 else if (dockStyle == DockStyle.Bottom) 1146 DockState = DockState.DockBottom; 1147 else if (dockStyle == DockStyle.Left) 1148 DockState = DockState.DockLeft; 1149 else if (dockStyle == DockStyle.Right) 1150 DockState = DockState.DockRight; 1151 else if (dockStyle == DockStyle.Fill) 1152 DockState = DockState.Document; 1153 } 1154 1155 #endregion 1156 } 1316 1157 } -
branches/UnloadJobs/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.7.0/WinFormsUI-2.7.0/Docking/DockPanel.cs
r8616 r9174 1 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Diagnostics.CodeAnalysis; 2 5 using System.Drawing; 3 using System.Drawing.Drawing2D;4 6 using System.Windows.Forms; 5 using System.ComponentModel;6 using System.Runtime.InteropServices;7 using System.IO;8 using System.Text;9 using System.Diagnostics.CodeAnalysis;10 using System.Collections.Generic;11 7 12 8 // To simplify the process of finding the toolbox bitmap resource: … … 15 11 // #3 use the "<default namespace>.<resourcename>" string to locate the resource. 16 12 // See: http://www.bobpowell.net/toolboxbitmap.htm 17 internal class resfinder 18 { 13 internal class resfinder { 19 14 } 20 15 21 namespace WeifenLuo.WinFormsUI.Docking 22 { 23 [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId = "0#")] 24 public delegate IDockContent DeserializeDockContent(string persistString); 25 26 [LocalizedDescription("DockPanel_Description")] 27 [Designer("System.Windows.Forms.Design.ControlDesigner, System.Design")] 28 [ToolboxBitmap(typeof(resfinder), "WeifenLuo.WinFormsUI.Docking.DockPanel.bmp")] 29 [DefaultProperty("DocumentStyle")] 30 [DefaultEvent("ActiveContentChanged")] 31 public partial class DockPanel : Panel 32 { 33 private FocusManagerImpl m_focusManager; 34 private DockPanelExtender m_extender; 35 private DockPaneCollection m_panes; 36 private FloatWindowCollection m_floatWindows; 37 private AutoHideWindowControl m_autoHideWindow; 38 private DockWindowCollection m_dockWindows; 39 private DockContent m_dummyContent; 40 private Control m_dummyControl; 41 42 public DockPanel() 43 { 44 m_focusManager = new FocusManagerImpl(this); 45 m_extender = new DockPanelExtender(this); 46 m_panes = new DockPaneCollection(); 47 m_floatWindows = new FloatWindowCollection(); 48 49 SuspendLayout(); 50 51 m_autoHideWindow = new AutoHideWindowControl(this); 52 m_autoHideWindow.Visible = false; 53 SetAutoHideWindowParent(); 54 55 m_dummyControl = new DummyControl(); 56 m_dummyControl.Bounds = new Rectangle(0, 0, 1, 1); 57 Controls.Add(m_dummyControl); 58 59 m_dockWindows = new DockWindowCollection(this); 60 Controls.AddRange(new Control[] { 16 namespace WeifenLuo.WinFormsUI.Docking { 17 [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId = "0#")] 18 public delegate IDockContent DeserializeDockContent(string persistString); 19 20 [LocalizedDescription("DockPanel_Description")] 21 [Designer("System.Windows.Forms.Design.ControlDesigner, System.Design")] 22 [ToolboxBitmap(typeof(resfinder), "WeifenLuo.WinFormsUI.Docking.DockPanel.bmp")] 23 [DefaultProperty("DocumentStyle")] 24 [DefaultEvent("ActiveContentChanged")] 25 public partial class DockPanel : Panel { 26 private FocusManagerImpl m_focusManager; 27 private DockPanelExtender m_extender; 28 private DockPaneCollection m_panes; 29 private FloatWindowCollection m_floatWindows; 30 private AutoHideWindowControl m_autoHideWindow; 31 private DockWindowCollection m_dockWindows; 32 private DockContent m_dummyContent; 33 private Control m_dummyControl; 34 35 public DockPanel() { 36 m_focusManager = new FocusManagerImpl(this); 37 m_extender = new DockPanelExtender(this); 38 m_panes = new DockPaneCollection(); 39 m_floatWindows = new FloatWindowCollection(); 40 41 SuspendLayout(); 42 43 m_autoHideWindow = new AutoHideWindowControl(this); 44 m_autoHideWindow.Visible = false; 45 SetAutoHideWindowParent(); 46 47 m_dummyControl = new DummyControl(); 48 m_dummyControl.Bounds = new Rectangle(0, 0, 1, 1); 49 Controls.Add(m_dummyControl); 50 51 m_dockWindows = new DockWindowCollection(this); 52 Controls.AddRange(new Control[] { 61 53 DockWindows[DockState.Document], 62 54 DockWindows[DockState.DockLeft], … … 66 58 }); 67 59 68 m_dummyContent = new DockContent(); 69 ResumeLayout(); 70 } 71 72 private Color m_BackColor; 73 /// <summary> 74 /// Determines the color with which the client rectangle will be drawn. 75 /// If this property is used instead of the BackColor it will not have any influence on the borders to the surrounding controls (DockPane). 76 /// The BackColor property changes the borders of surrounding controls (DockPane). 77 /// Alternatively both properties may be used (BackColor to draw and define the color of the borders and DockBackColor to define the color of the client rectangle). 78 /// For Backgroundimages: Set your prefered Image, then set the DockBackColor and the BackColor to the same Color (Control) 79 /// </summary> 80 [Description("Determines the color with which the client rectangle will be drawn.\r\n" + 81 "If this property is used instead of the BackColor it will not have any influence on the borders to the surrounding controls (DockPane).\r\n" + 82 "The BackColor property changes the borders of surrounding controls (DockPane).\r\n" + 83 "Alternatively both properties may be used (BackColor to draw and define the color of the borders and DockBackColor to define the color of the client rectangle).\r\n" + 84 "For Backgroundimages: Set your prefered Image, then set the DockBackColor and the BackColor to the same Color (Control).")] 85 public Color DockBackColor 86 { 87 get 88 { 89 return !m_BackColor.IsEmpty ? m_BackColor : base.BackColor; 90 } 91 set 92 { 93 if (m_BackColor != value) 94 { 95 m_BackColor = value; 96 this.Refresh(); 97 } 98 } 99 } 100 101 private bool ShouldSerializeDockBackColor() 102 { 103 return !m_BackColor.IsEmpty; 104 } 105 106 private void ResetDockBackColor() 107 { 108 DockBackColor = Color.Empty; 109 } 110 111 private AutoHideStripBase m_autoHideStripControl = null; 112 internal AutoHideStripBase AutoHideStripControl 113 { 114 get 115 { 116 if (m_autoHideStripControl == null) 117 { 118 m_autoHideStripControl = AutoHideStripFactory.CreateAutoHideStrip(this); 119 Controls.Add(m_autoHideStripControl); 120 } 121 return m_autoHideStripControl; 122 } 123 } 124 internal void ResetAutoHideStripControl() 125 { 126 if (m_autoHideStripControl != null) 127 m_autoHideStripControl.Dispose(); 128 129 m_autoHideStripControl = null; 130 } 131 132 private void MdiClientHandleAssigned(object sender, EventArgs e) 133 { 134 SetMdiClient(); 135 PerformLayout(); 136 } 137 138 private void MdiClient_Layout(object sender, LayoutEventArgs e) 139 { 140 if (DocumentStyle != DocumentStyle.DockingMdi) 141 return; 142 143 foreach (DockPane pane in Panes) 144 if (pane.DockState == DockState.Document) 145 pane.SetContentBounds(); 146 147 InvalidateWindowRegion(); 148 } 149 150 private bool m_disposed = false; 151 protected override void Dispose(bool disposing) 152 { 153 lock (this) 154 { 155 if (!m_disposed && disposing) 156 { 157 m_focusManager.Dispose(); 158 if (m_mdiClientController != null) 159 { 160 m_mdiClientController.HandleAssigned -= new EventHandler(MdiClientHandleAssigned); 161 m_mdiClientController.MdiChildActivate -= new EventHandler(ParentFormMdiChildActivate); 162 m_mdiClientController.Layout -= new LayoutEventHandler(MdiClient_Layout); 163 m_mdiClientController.Dispose(); 164 } 165 FloatWindows.Dispose(); 166 Panes.Dispose(); 167 DummyContent.Dispose(); 168 169 m_disposed = true; 170 } 171 172 base.Dispose(disposing); 173 } 174 } 175 176 [Browsable(false)] 177 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] 178 public IDockContent ActiveAutoHideContent 179 { 180 get { return AutoHideWindow.ActiveContent; } 181 set { AutoHideWindow.ActiveContent = value; } 182 } 183 184 private bool m_allowEndUserDocking = !Win32Helper.IsRunningOnMono; 185 [LocalizedCategory("Category_Docking")] 186 [LocalizedDescription("DockPanel_AllowEndUserDocking_Description")] 187 [DefaultValue(true)] 188 public bool AllowEndUserDocking 189 { 190 get 191 { 192 if (Win32Helper.IsRunningOnMono && m_allowEndUserDocking) 193 m_allowEndUserDocking = false; 194 195 return m_allowEndUserDocking; 196 } 197 set 198 { 199 if (Win32Helper.IsRunningOnMono && value) 200 throw new InvalidOperationException("AllowEndUserDocking can only be false if running on Mono"); 201 202 m_allowEndUserDocking = value; 203 } 204 } 205 206 private bool m_allowEndUserNestedDocking = !Win32Helper.IsRunningOnMono; 207 [LocalizedCategory("Category_Docking")] 208 [LocalizedDescription("DockPanel_AllowEndUserNestedDocking_Description")] 209 [DefaultValue(true)] 210 public bool AllowEndUserNestedDocking 211 { 212 get 213 { 214 if (Win32Helper.IsRunningOnMono && m_allowEndUserDocking) 215 m_allowEndUserDocking = false; 216 return m_allowEndUserNestedDocking; 217 } 218 set 219 { 220 if (Win32Helper.IsRunningOnMono && value) 221 throw new InvalidOperationException("AllowEndUserNestedDocking can only be false if running on Mono"); 222 223 m_allowEndUserNestedDocking = value; 224 } 225 } 226 227 private DockContentCollection m_contents = new DockContentCollection(); 228 [Browsable(false)] 229 public DockContentCollection Contents 230 { 231 get { return m_contents; } 232 } 233 234 internal DockContent DummyContent 235 { 236 get { return m_dummyContent; } 237 } 238 239 private bool m_rightToLeftLayout = false; 240 [DefaultValue(false)] 241 [LocalizedCategory("Appearance")] 242 [LocalizedDescription("DockPanel_RightToLeftLayout_Description")] 243 public bool RightToLeftLayout 244 { 245 get { return m_rightToLeftLayout; } 246 set 247 { 248 if (m_rightToLeftLayout == value) 249 return; 250 251 m_rightToLeftLayout = value; 252 foreach (FloatWindow floatWindow in FloatWindows) 253 floatWindow.RightToLeftLayout = value; 254 } 255 } 256 257 protected override void OnRightToLeftChanged(EventArgs e) 258 { 259 base.OnRightToLeftChanged(e); 260 foreach (FloatWindow floatWindow in FloatWindows) 261 { 262 if (floatWindow.RightToLeft != RightToLeft) 263 floatWindow.RightToLeft = RightToLeft; 264 } 265 } 266 267 private bool m_showDocumentIcon = false; 268 [DefaultValue(false)] 269 [LocalizedCategory("Category_Docking")] 270 [LocalizedDescription("DockPanel_ShowDocumentIcon_Description")] 271 public bool ShowDocumentIcon 272 { 273 get { return m_showDocumentIcon; } 274 set 275 { 276 if (m_showDocumentIcon == value) 277 return; 278 279 m_showDocumentIcon = value; 280 Refresh(); 281 } 282 } 283 284 private DocumentTabStripLocation m_documentTabStripLocation = DocumentTabStripLocation.Top; 285 [DefaultValue(DocumentTabStripLocation.Top)] 286 [LocalizedCategory("Category_Docking")] 287 [LocalizedDescription("DockPanel_DocumentTabStripLocation")] 288 public DocumentTabStripLocation DocumentTabStripLocation 289 { 290 get { return m_documentTabStripLocation; } 291 set { m_documentTabStripLocation = value; } 292 } 293 294 [Browsable(false)] 295 public DockPanelExtender Extender 296 { 297 get { return m_extender; } 298 } 299 300 [Browsable(false)] 301 public DockPanelExtender.IDockPaneFactory DockPaneFactory 302 { 303 get { return Extender.DockPaneFactory; } 304 } 305 306 [Browsable(false)] 307 public DockPanelExtender.IFloatWindowFactory FloatWindowFactory 308 { 309 get { return Extender.FloatWindowFactory; } 310 } 311 312 internal DockPanelExtender.IDockPaneCaptionFactory DockPaneCaptionFactory 313 { 314 get { return Extender.DockPaneCaptionFactory; } 315 } 316 317 internal DockPanelExtender.IDockPaneStripFactory DockPaneStripFactory 318 { 319 get { return Extender.DockPaneStripFactory; } 320 } 321 322 internal DockPanelExtender.IAutoHideStripFactory AutoHideStripFactory 323 { 324 get { return Extender.AutoHideStripFactory; } 325 } 326 327 [Browsable(false)] 328 public DockPaneCollection Panes 329 { 330 get { return m_panes; } 331 } 332 333 internal Rectangle DockArea 334 { 335 get 336 { 337 return new Rectangle(DockPadding.Left, DockPadding.Top, 338 ClientRectangle.Width - DockPadding.Left - DockPadding.Right, 339 ClientRectangle.Height - DockPadding.Top - DockPadding.Bottom); 340 } 341 } 342 343 private double m_dockBottomPortion = 0.25; 344 [LocalizedCategory("Category_Docking")] 345 [LocalizedDescription("DockPanel_DockBottomPortion_Description")] 346 [DefaultValue(0.25)] 347 public double DockBottomPortion 348 { 349 get { return m_dockBottomPortion; } 350 set 351 { 352 if (value <= 0) 353 throw new ArgumentOutOfRangeException("value"); 354 355 if (value == m_dockBottomPortion) 356 return; 357 358 m_dockBottomPortion = value; 359 360 if (m_dockBottomPortion < 1 && m_dockTopPortion < 1) 361 { 362 if (m_dockTopPortion + m_dockBottomPortion > 1) 363 m_dockTopPortion = 1 - m_dockBottomPortion; 364 } 365 366 PerformLayout(); 367 } 368 } 369 370 private double m_dockLeftPortion = 0.25; 371 [LocalizedCategory("Category_Docking")] 372 [LocalizedDescription("DockPanel_DockLeftPortion_Description")] 373 [DefaultValue(0.25)] 374 public double DockLeftPortion 375 { 376 get { return m_dockLeftPortion; } 377 set 378 { 379 if (value <= 0) 380 throw new ArgumentOutOfRangeException("value"); 381 382 if (value == m_dockLeftPortion) 383 return; 384 385 m_dockLeftPortion = value; 386 387 if (m_dockLeftPortion < 1 && m_dockRightPortion < 1) 388 { 389 if (m_dockLeftPortion + m_dockRightPortion > 1) 390 m_dockRightPortion = 1 - m_dockLeftPortion; 391 } 392 PerformLayout(); 393 } 394 } 395 396 private double m_dockRightPortion = 0.25; 397 [LocalizedCategory("Category_Docking")] 398 [LocalizedDescription("DockPanel_DockRightPortion_Description")] 399 [DefaultValue(0.25)] 400 public double DockRightPortion 401 { 402 get { return m_dockRightPortion; } 403 set 404 { 405 if (value <= 0) 406 throw new ArgumentOutOfRangeException("value"); 407 408 if (value == m_dockRightPortion) 409 return; 410 411 m_dockRightPortion = value; 412 413 if (m_dockLeftPortion < 1 && m_dockRightPortion < 1) 414 { 415 if (m_dockLeftPortion + m_dockRightPortion > 1) 416 m_dockLeftPortion = 1 - m_dockRightPortion; 417 } 418 PerformLayout(); 419 } 420 } 421 422 private double m_dockTopPortion = 0.25; 423 [LocalizedCategory("Category_Docking")] 424 [LocalizedDescription("DockPanel_DockTopPortion_Description")] 425 [DefaultValue(0.25)] 426 public double DockTopPortion 427 { 428 get { return m_dockTopPortion; } 429 set 430 { 431 if (value <= 0) 432 throw new ArgumentOutOfRangeException("value"); 433 434 if (value == m_dockTopPortion) 435 return; 436 437 m_dockTopPortion = value; 438 439 if (m_dockTopPortion < 1 && m_dockBottomPortion < 1) 440 { 441 if (m_dockTopPortion + m_dockBottomPortion > 1) 442 m_dockBottomPortion = 1 - m_dockTopPortion; 443 } 444 PerformLayout(); 445 } 446 } 447 448 [Browsable(false)] 449 public DockWindowCollection DockWindows 450 { 451 get { return m_dockWindows; } 452 } 453 454 public void UpdateDockWindowZOrder(DockStyle dockStyle, bool fullPanelEdge) 455 { 456 if (dockStyle == DockStyle.Left) 457 { 458 if (fullPanelEdge) 459 DockWindows[DockState.DockLeft].SendToBack(); 460 else 461 DockWindows[DockState.DockLeft].BringToFront(); 462 } 463 else if (dockStyle == DockStyle.Right) 464 { 465 if (fullPanelEdge) 466 DockWindows[DockState.DockRight].SendToBack(); 467 else 468 DockWindows[DockState.DockRight].BringToFront(); 469 } 470 else if (dockStyle == DockStyle.Top) 471 { 472 if (fullPanelEdge) 473 DockWindows[DockState.DockTop].SendToBack(); 474 else 475 DockWindows[DockState.DockTop].BringToFront(); 476 } 477 else if (dockStyle == DockStyle.Bottom) 478 { 479 if (fullPanelEdge) 480 DockWindows[DockState.DockBottom].SendToBack(); 481 else 482 DockWindows[DockState.DockBottom].BringToFront(); 483 } 484 } 485 486 [Browsable(false)] 487 public int DocumentsCount 488 { 489 get 490 { 491 int count = 0; 492 foreach (IDockContent content in Documents) 493 count++; 494 495 return count; 496 } 497 } 498 499 public IDockContent[] DocumentsToArray() 500 { 501 int count = DocumentsCount; 502 IDockContent[] documents = new IDockContent[count]; 503 int i = 0; 504 foreach (IDockContent content in Documents) 505 { 506 documents[i] = content; 507 i++; 508 } 509 510 return documents; 511 } 512 513 [Browsable(false)] 514 public IEnumerable<IDockContent> Documents 515 { 516 get 517 { 518 foreach (IDockContent content in Contents) 519 { 520 if (content.DockHandler.DockState == DockState.Document) 521 yield return content; 522 } 523 } 524 } 525 526 private Rectangle DocumentRectangle 527 { 528 get 529 { 530 Rectangle rect = DockArea; 531 if (DockWindows[DockState.DockLeft].VisibleNestedPanes.Count != 0) 532 { 533 rect.X += (int)(DockArea.Width * DockLeftPortion); 534 rect.Width -= (int)(DockArea.Width * DockLeftPortion); 535 } 536 if (DockWindows[DockState.DockRight].VisibleNestedPanes.Count != 0) 537 rect.Width -= (int)(DockArea.Width * DockRightPortion); 538 if (DockWindows[DockState.DockTop].VisibleNestedPanes.Count != 0) 539 { 540 rect.Y += (int)(DockArea.Height * DockTopPortion); 541 rect.Height -= (int)(DockArea.Height * DockTopPortion); 542 } 543 if (DockWindows[DockState.DockBottom].VisibleNestedPanes.Count != 0) 544 rect.Height -= (int)(DockArea.Height * DockBottomPortion); 545 546 return rect; 547 } 548 } 549 550 private Control DummyControl 551 { 552 get { return m_dummyControl; } 553 } 554 555 [Browsable(false)] 556 public FloatWindowCollection FloatWindows 557 { 558 get { return m_floatWindows; } 559 } 560 561 private Size m_defaultFloatWindowSize = new Size(300, 300); 562 [Category("Layout")] 563 [LocalizedDescription("DockPanel_DefaultFloatWindowSize_Description")] 564 public Size DefaultFloatWindowSize 565 { 566 get { return m_defaultFloatWindowSize; } 567 set { m_defaultFloatWindowSize = value; } 568 } 569 private bool ShouldSerializeDefaultFloatWindowSize() 570 { 571 return DefaultFloatWindowSize != new Size(300, 300); 572 } 573 private void ResetDefaultFloatWindowSize() 574 { 575 DefaultFloatWindowSize = new Size(300, 300); 576 } 577 578 private DocumentStyle m_documentStyle = DocumentStyle.DockingMdi; 579 [LocalizedCategory("Category_Docking")] 580 [LocalizedDescription("DockPanel_DocumentStyle_Description")] 581 [DefaultValue(DocumentStyle.DockingMdi)] 582 public DocumentStyle DocumentStyle 583 { 584 get { return m_documentStyle; } 585 set 586 { 587 if (value == m_documentStyle) 588 return; 589 590 if (!Enum.IsDefined(typeof(DocumentStyle), value)) 591 throw new InvalidEnumArgumentException(); 592 593 if (value == DocumentStyle.SystemMdi && DockWindows[DockState.Document].VisibleNestedPanes.Count > 0) 594 throw new InvalidEnumArgumentException(); 595 596 m_documentStyle = value; 597 598 SuspendLayout(true); 599 600 SetAutoHideWindowParent(); 601 SetMdiClient(); 602 InvalidateWindowRegion(); 603 604 foreach (IDockContent content in Contents) 605 { 606 if (content.DockHandler.DockState == DockState.Document) 607 content.DockHandler.SetPaneAndVisible(content.DockHandler.Pane); 608 } 609 610 PerformMdiClientLayout(); 611 612 ResumeLayout(true, true); 613 } 614 } 615 616 private bool _supprtDeeplyNestedContent = false; 617 [LocalizedCategory("Category_Performance")] 618 [LocalizedDescription("DockPanel_SupportDeeplyNestedContent_Description")] 619 [DefaultValue(false)] 620 public bool SupportDeeplyNestedContent 621 { 622 get { return _supprtDeeplyNestedContent; } 623 set { _supprtDeeplyNestedContent = value; } 624 } 625 626 private int GetDockWindowSize(DockState dockState) 627 { 628 if (dockState == DockState.DockLeft || dockState == DockState.DockRight) 629 { 630 int width = ClientRectangle.Width - DockPadding.Left - DockPadding.Right; 631 int dockLeftSize = m_dockLeftPortion >= 1 ? (int)m_dockLeftPortion : (int)(width * m_dockLeftPortion); 632 int dockRightSize = m_dockRightPortion >= 1 ? (int)m_dockRightPortion : (int)(width * m_dockRightPortion); 633 634 if (dockLeftSize < MeasurePane.MinSize) 635 dockLeftSize = MeasurePane.MinSize; 636 if (dockRightSize < MeasurePane.MinSize) 637 dockRightSize = MeasurePane.MinSize; 638 639 if (dockLeftSize + dockRightSize > width - MeasurePane.MinSize) 640 { 641 int adjust = (dockLeftSize + dockRightSize) - (width - MeasurePane.MinSize); 642 dockLeftSize -= adjust / 2; 643 dockRightSize -= adjust / 2; 644 } 645 646 return dockState == DockState.DockLeft ? dockLeftSize : dockRightSize; 647 } 648 else if (dockState == DockState.DockTop || dockState == DockState.DockBottom) 649 { 650 int height = ClientRectangle.Height - DockPadding.Top - DockPadding.Bottom; 651 int dockTopSize = m_dockTopPortion >= 1 ? (int)m_dockTopPortion : (int)(height * m_dockTopPortion); 652 int dockBottomSize = m_dockBottomPortion >= 1 ? (int)m_dockBottomPortion : (int)(height * m_dockBottomPortion); 653 654 if (dockTopSize < MeasurePane.MinSize) 655 dockTopSize = MeasurePane.MinSize; 656 if (dockBottomSize < MeasurePane.MinSize) 657 dockBottomSize = MeasurePane.MinSize; 658 659 if (dockTopSize + dockBottomSize > height - MeasurePane.MinSize) 660 { 661 int adjust = (dockTopSize + dockBottomSize) - (height - MeasurePane.MinSize); 662 dockTopSize -= adjust / 2; 663 dockBottomSize -= adjust / 2; 664 } 665 666 return dockState == DockState.DockTop ? dockTopSize : dockBottomSize; 667 } 668 else 669 return 0; 670 } 671 672 protected override void OnLayout(LayoutEventArgs levent) 673 { 674 SuspendLayout(true); 675 676 AutoHideStripControl.Bounds = ClientRectangle; 677 678 CalculateDockPadding(); 679 680 DockWindows[DockState.DockLeft].Width = GetDockWindowSize(DockState.DockLeft); 681 DockWindows[DockState.DockRight].Width = GetDockWindowSize(DockState.DockRight); 682 DockWindows[DockState.DockTop].Height = GetDockWindowSize(DockState.DockTop); 683 DockWindows[DockState.DockBottom].Height = GetDockWindowSize(DockState.DockBottom); 684 685 AutoHideWindow.Bounds = GetAutoHideWindowBounds(AutoHideWindowRectangle); 686 687 DockWindows[DockState.Document].BringToFront(); 688 AutoHideWindow.BringToFront(); 689 690 base.OnLayout(levent); 691 692 if (DocumentStyle == DocumentStyle.SystemMdi && MdiClientExists) 693 { 694 SetMdiClientBounds(SystemMdiClientBounds); 695 InvalidateWindowRegion(); 696 } 697 else if (DocumentStyle == DocumentStyle.DockingMdi) 698 InvalidateWindowRegion(); 699 700 ResumeLayout(true, true); 701 } 702 703 internal Rectangle GetTabStripRectangle(DockState dockState) 704 { 705 return AutoHideStripControl.GetTabStripRectangle(dockState); 706 } 707 708 protected override void OnPaint(PaintEventArgs e) 709 { 710 base.OnPaint(e); 711 712 if (DockBackColor == BackColor) return; 713 714 Graphics g = e.Graphics; 715 SolidBrush bgBrush = new SolidBrush(DockBackColor); 716 g.FillRectangle(bgBrush, ClientRectangle); 717 } 718 719 internal void AddContent(IDockContent content) 720 { 721 if (content == null) 722 throw(new ArgumentNullException()); 723 724 if (!Contents.Contains(content)) 725 { 726 Contents.Add(content); 727 OnContentAdded(new DockContentEventArgs(content)); 728 } 729 } 730 731 internal void AddPane(DockPane pane) 732 { 733 if (Panes.Contains(pane)) 734 return; 735 736 Panes.Add(pane); 737 } 738 739 internal void AddFloatWindow(FloatWindow floatWindow) 740 { 741 if (FloatWindows.Contains(floatWindow)) 742 return; 743 744 FloatWindows.Add(floatWindow); 745 } 746 747 private void CalculateDockPadding() 748 { 749 DockPadding.All = 0; 750 751 int height = AutoHideStripControl.MeasureHeight(); 752 753 if (AutoHideStripControl.GetNumberOfPanes(DockState.DockLeftAutoHide) > 0) 754 DockPadding.Left = height; 755 if (AutoHideStripControl.GetNumberOfPanes(DockState.DockRightAutoHide) > 0) 756 DockPadding.Right = height; 757 if (AutoHideStripControl.GetNumberOfPanes(DockState.DockTopAutoHide) > 0) 758 DockPadding.Top = height; 759 if (AutoHideStripControl.GetNumberOfPanes(DockState.DockBottomAutoHide) > 0) 760 DockPadding.Bottom = height; 761 } 762 763 internal void RemoveContent(IDockContent content) 764 { 765 if (content == null) 766 throw(new ArgumentNullException()); 767 768 if (Contents.Contains(content)) 769 { 770 Contents.Remove(content); 771 OnContentRemoved(new DockContentEventArgs(content)); 772 } 773 } 774 775 internal void RemovePane(DockPane pane) 776 { 777 if (!Panes.Contains(pane)) 778 return; 779 780 Panes.Remove(pane); 781 } 782 783 internal void RemoveFloatWindow(FloatWindow floatWindow) 784 { 785 if (!FloatWindows.Contains(floatWindow)) 786 return; 787 788 FloatWindows.Remove(floatWindow); 789 } 790 791 public void SetPaneIndex(DockPane pane, int index) 792 { 793 int oldIndex = Panes.IndexOf(pane); 794 if (oldIndex == -1) 795 throw(new ArgumentException(Strings.DockPanel_SetPaneIndex_InvalidPane)); 796 797 if (index < 0 || index > Panes.Count - 1) 798 if (index != -1) 799 throw(new ArgumentOutOfRangeException(Strings.DockPanel_SetPaneIndex_InvalidIndex)); 800 801 if (oldIndex == index) 802 return; 803 if (oldIndex == Panes.Count - 1 && index == -1) 804 return; 805 806 Panes.Remove(pane); 807 if (index == -1) 808 Panes.Add(pane); 809 else if (oldIndex < index) 810 Panes.AddAt(pane, index - 1); 811 else 812 Panes.AddAt(pane, index); 813 } 814 815 public void SuspendLayout(bool allWindows) 816 { 817 FocusManager.SuspendFocusTracking(); 818 SuspendLayout(); 819 if (allWindows) 820 SuspendMdiClientLayout(); 821 } 822 823 public void ResumeLayout(bool performLayout, bool allWindows) 824 { 825 FocusManager.ResumeFocusTracking(); 826 ResumeLayout(performLayout); 827 if (allWindows) 828 ResumeMdiClientLayout(performLayout); 829 } 830 831 internal Form ParentForm 832 { 833 get 834 { 835 if (!IsParentFormValid()) 836 throw new InvalidOperationException(Strings.DockPanel_ParentForm_Invalid); 837 838 return GetMdiClientController().ParentForm; 839 } 840 } 841 842 private bool IsParentFormValid() 843 { 844 if (DocumentStyle == DocumentStyle.DockingSdi || DocumentStyle == DocumentStyle.DockingWindow) 845 return true; 846 847 if (!MdiClientExists) 848 GetMdiClientController().RenewMdiClient(); 849 850 return (MdiClientExists); 851 } 852 853 protected override void OnParentChanged(EventArgs e) 854 { 855 SetAutoHideWindowParent(); 856 GetMdiClientController().ParentForm = (this.Parent as Form); 857 base.OnParentChanged (e); 858 } 859 860 private void SetAutoHideWindowParent() 861 { 862 Control parent; 863 if (DocumentStyle == DocumentStyle.DockingMdi || 864 DocumentStyle == DocumentStyle.SystemMdi) 865 parent = this.Parent; 866 else 867 parent = this; 868 if (AutoHideWindow.Parent != parent) 869 { 870 AutoHideWindow.Parent = parent; 871 AutoHideWindow.BringToFront(); 872 } 873 } 874 875 protected override void OnVisibleChanged(EventArgs e) 876 { 877 base.OnVisibleChanged (e); 878 879 if (Visible) 880 SetMdiClient(); 881 } 882 883 private Rectangle SystemMdiClientBounds 884 { 885 get 886 { 887 if (!IsParentFormValid() || !Visible) 888 return Rectangle.Empty; 889 890 Rectangle rect = ParentForm.RectangleToClient(RectangleToScreen(DocumentWindowBounds)); 891 return rect; 892 } 893 } 894 895 internal Rectangle DocumentWindowBounds 896 { 897 get 898 { 899 Rectangle rectDocumentBounds = DisplayRectangle; 900 if (DockWindows[DockState.DockLeft].Visible) 901 { 902 rectDocumentBounds.X += DockWindows[DockState.DockLeft].Width; 903 rectDocumentBounds.Width -= DockWindows[DockState.DockLeft].Width; 904 } 905 if (DockWindows[DockState.DockRight].Visible) 906 rectDocumentBounds.Width -= DockWindows[DockState.DockRight].Width; 907 if (DockWindows[DockState.DockTop].Visible) 908 { 909 rectDocumentBounds.Y += DockWindows[DockState.DockTop].Height; 910 rectDocumentBounds.Height -= DockWindows[DockState.DockTop].Height; 911 } 912 if (DockWindows[DockState.DockBottom].Visible) 913 rectDocumentBounds.Height -= DockWindows[DockState.DockBottom].Height; 914 915 return rectDocumentBounds; 916 917 } 918 } 919 920 private PaintEventHandler m_dummyControlPaintEventHandler = null; 921 private void InvalidateWindowRegion() 922 { 923 if (DesignMode) 924 return; 925 926 if (m_dummyControlPaintEventHandler == null) 927 m_dummyControlPaintEventHandler = new PaintEventHandler(DummyControl_Paint); 928 929 DummyControl.Paint += m_dummyControlPaintEventHandler; 930 DummyControl.Invalidate(); 931 } 932 933 void DummyControl_Paint(object sender, PaintEventArgs e) 934 { 935 DummyControl.Paint -= m_dummyControlPaintEventHandler; 936 UpdateWindowRegion(); 937 } 938 939 private void UpdateWindowRegion() 940 { 941 if (this.DocumentStyle == DocumentStyle.DockingMdi) 942 UpdateWindowRegion_ClipContent(); 943 else if (this.DocumentStyle == DocumentStyle.DockingSdi || 944 this.DocumentStyle == DocumentStyle.DockingWindow) 945 UpdateWindowRegion_FullDocumentArea(); 946 else if (this.DocumentStyle == DocumentStyle.SystemMdi) 947 UpdateWindowRegion_EmptyDocumentArea(); 948 } 949 950 private void UpdateWindowRegion_FullDocumentArea() 951 { 952 SetRegion(null); 953 } 954 955 private void UpdateWindowRegion_EmptyDocumentArea() 956 { 957 Rectangle rect = DocumentWindowBounds; 958 SetRegion(new Rectangle[] { rect }); 959 } 960 961 private void UpdateWindowRegion_ClipContent() 962 { 963 int count = 0; 964 foreach (DockPane pane in this.Panes) 965 { 966 if (!pane.Visible || pane.DockState != DockState.Document) 967 continue; 968 969 count ++; 970 } 971 972 if (count == 0) 973 { 974 SetRegion(null); 975 return; 976 } 977 978 Rectangle[] rects = new Rectangle[count]; 979 int i = 0; 980 foreach (DockPane pane in this.Panes) 981 { 982 if (!pane.Visible || pane.DockState != DockState.Document) 983 continue; 984 985 rects[i] = RectangleToClient(pane.RectangleToScreen(pane.ContentRectangle)); 986 i++; 987 } 988 989 SetRegion(rects); 990 } 991 992 private Rectangle[] m_clipRects = null; 993 private void SetRegion(Rectangle[] clipRects) 994 { 995 if (!IsClipRectsChanged(clipRects)) 996 return; 997 998 m_clipRects = clipRects; 999 1000 if (m_clipRects == null || m_clipRects.GetLength(0) == 0) 1001 Region = null; 1002 else 1003 { 1004 Region region = new Region(new Rectangle(0, 0, this.Width, this.Height)); 1005 foreach (Rectangle rect in m_clipRects) 1006 region.Exclude(rect); 1007 Region = region; 1008 } 1009 } 1010 1011 private bool IsClipRectsChanged(Rectangle[] clipRects) 1012 { 1013 if (clipRects == null && m_clipRects == null) 1014 return false; 1015 else if ((clipRects == null) != (m_clipRects == null)) 1016 return true; 1017 1018 foreach (Rectangle rect in clipRects) 1019 { 1020 bool matched = false; 1021 foreach (Rectangle rect2 in m_clipRects) 1022 { 1023 if (rect == rect2) 1024 { 1025 matched = true; 1026 break; 1027 } 1028 } 1029 if (!matched) 1030 return true; 1031 } 1032 1033 foreach (Rectangle rect2 in m_clipRects) 1034 { 1035 bool matched = false; 1036 foreach (Rectangle rect in clipRects) 1037 { 1038 if (rect == rect2) 1039 { 1040 matched = true; 1041 break; 1042 } 1043 } 1044 if (!matched) 1045 return true; 1046 } 1047 return false; 1048 } 1049 1050 private static readonly object ContentAddedEvent = new object(); 1051 [LocalizedCategory("Category_DockingNotification")] 1052 [LocalizedDescription("DockPanel_ContentAdded_Description")] 1053 public event EventHandler<DockContentEventArgs> ContentAdded 1054 { 1055 add { Events.AddHandler(ContentAddedEvent, value); } 1056 remove { Events.RemoveHandler(ContentAddedEvent, value); } 1057 } 1058 protected virtual void OnContentAdded(DockContentEventArgs e) 1059 { 1060 EventHandler<DockContentEventArgs> handler = (EventHandler<DockContentEventArgs>)Events[ContentAddedEvent]; 1061 if (handler != null) 1062 handler(this, e); 1063 } 1064 1065 private static readonly object ContentRemovedEvent = new object(); 1066 [LocalizedCategory("Category_DockingNotification")] 1067 [LocalizedDescription("DockPanel_ContentRemoved_Description")] 1068 public event EventHandler<DockContentEventArgs> ContentRemoved 1069 { 1070 add { Events.AddHandler(ContentRemovedEvent, value); } 1071 remove { Events.RemoveHandler(ContentRemovedEvent, value); } 1072 } 1073 protected virtual void OnContentRemoved(DockContentEventArgs e) 1074 { 1075 EventHandler<DockContentEventArgs> handler = (EventHandler<DockContentEventArgs>)Events[ContentRemovedEvent]; 1076 if (handler != null) 1077 handler(this, e); 1078 } 1079 } 60 m_dummyContent = new DockContent(); 61 ResumeLayout(); 62 } 63 64 private Color m_BackColor; 65 /// <summary> 66 /// Determines the color with which the client rectangle will be drawn. 67 /// If this property is used instead of the BackColor it will not have any influence on the borders to the surrounding controls (DockPane). 68 /// The BackColor property changes the borders of surrounding controls (DockPane). 69 /// Alternatively both properties may be used (BackColor to draw and define the color of the borders and DockBackColor to define the color of the client rectangle). 70 /// For Backgroundimages: Set your prefered Image, then set the DockBackColor and the BackColor to the same Color (Control) 71 /// </summary> 72 [Description("Determines the color with which the client rectangle will be drawn.\r\n" + 73 "If this property is used instead of the BackColor it will not have any influence on the borders to the surrounding controls (DockPane).\r\n" + 74 "The BackColor property changes the borders of surrounding controls (DockPane).\r\n" + 75 "Alternatively both properties may be used (BackColor to draw and define the color of the borders and DockBackColor to define the color of the client rectangle).\r\n" + 76 "For Backgroundimages: Set your prefered Image, then set the DockBackColor and the BackColor to the same Color (Control).")] 77 public Color DockBackColor { 78 get { 79 return !m_BackColor.IsEmpty ? m_BackColor : base.BackColor; 80 } 81 set { 82 if (m_BackColor != value) { 83 m_BackColor = value; 84 this.Refresh(); 85 } 86 } 87 } 88 89 private bool ShouldSerializeDockBackColor() { 90 return !m_BackColor.IsEmpty; 91 } 92 93 private void ResetDockBackColor() { 94 DockBackColor = Color.Empty; 95 } 96 97 private AutoHideStripBase m_autoHideStripControl = null; 98 internal AutoHideStripBase AutoHideStripControl { 99 get { 100 if (m_autoHideStripControl == null) { 101 m_autoHideStripControl = AutoHideStripFactory.CreateAutoHideStrip(this); 102 Controls.Add(m_autoHideStripControl); 103 } 104 return m_autoHideStripControl; 105 } 106 } 107 internal void ResetAutoHideStripControl() { 108 if (m_autoHideStripControl != null) 109 m_autoHideStripControl.Dispose(); 110 111 m_autoHideStripControl = null; 112 } 113 114 private void MdiClientHandleAssigned(object sender, EventArgs e) { 115 SetMdiClient(); 116 PerformLayout(); 117 } 118 119 private void MdiClient_Layout(object sender, LayoutEventArgs e) { 120 if (DocumentStyle != DocumentStyle.DockingMdi) 121 return; 122 123 foreach (DockPane pane in Panes) 124 if (pane.DockState == DockState.Document) 125 pane.SetContentBounds(); 126 127 InvalidateWindowRegion(); 128 } 129 130 private bool m_disposed = false; 131 protected override void Dispose(bool disposing) { 132 lock (this) { 133 if (!m_disposed && disposing) { 134 m_focusManager.Dispose(); 135 if (m_mdiClientController != null) { 136 m_mdiClientController.HandleAssigned -= new EventHandler(MdiClientHandleAssigned); 137 m_mdiClientController.MdiChildActivate -= new EventHandler(ParentFormMdiChildActivate); 138 m_mdiClientController.Layout -= new LayoutEventHandler(MdiClient_Layout); 139 m_mdiClientController.Dispose(); 140 } 141 FloatWindows.Dispose(); 142 Panes.Dispose(); 143 DummyContent.Dispose(); 144 145 foreach (var dw in m_dockWindows) { 146 dw.Dispose(); 147 } 148 m_dockWindows = null; 149 150 m_disposed = true; 151 } 152 153 base.Dispose(disposing); 154 } 155 } 156 157 [Browsable(false)] 158 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] 159 public IDockContent ActiveAutoHideContent { 160 get { return AutoHideWindow.ActiveContent; } 161 set { AutoHideWindow.ActiveContent = value; } 162 } 163 164 private bool m_allowEndUserDocking = !Win32Helper.IsRunningOnMono; 165 [LocalizedCategory("Category_Docking")] 166 [LocalizedDescription("DockPanel_AllowEndUserDocking_Description")] 167 [DefaultValue(true)] 168 public bool AllowEndUserDocking { 169 get { 170 if (Win32Helper.IsRunningOnMono && m_allowEndUserDocking) 171 m_allowEndUserDocking = false; 172 173 return m_allowEndUserDocking; 174 } 175 set { 176 if (Win32Helper.IsRunningOnMono && value) 177 throw new InvalidOperationException("AllowEndUserDocking can only be false if running on Mono"); 178 179 m_allowEndUserDocking = value; 180 } 181 } 182 183 private bool m_allowEndUserNestedDocking = !Win32Helper.IsRunningOnMono; 184 [LocalizedCategory("Category_Docking")] 185 [LocalizedDescription("DockPanel_AllowEndUserNestedDocking_Description")] 186 [DefaultValue(true)] 187 public bool AllowEndUserNestedDocking { 188 get { 189 if (Win32Helper.IsRunningOnMono && m_allowEndUserDocking) 190 m_allowEndUserDocking = false; 191 return m_allowEndUserNestedDocking; 192 } 193 set { 194 if (Win32Helper.IsRunningOnMono && value) 195 throw new InvalidOperationException("AllowEndUserNestedDocking can only be false if running on Mono"); 196 197 m_allowEndUserNestedDocking = value; 198 } 199 } 200 201 private DockContentCollection m_contents = new DockContentCollection(); 202 [Browsable(false)] 203 public DockContentCollection Contents { 204 get { return m_contents; } 205 } 206 207 internal DockContent DummyContent { 208 get { return m_dummyContent; } 209 } 210 211 private bool m_rightToLeftLayout = false; 212 [DefaultValue(false)] 213 [LocalizedCategory("Appearance")] 214 [LocalizedDescription("DockPanel_RightToLeftLayout_Description")] 215 public bool RightToLeftLayout { 216 get { return m_rightToLeftLayout; } 217 set { 218 if (m_rightToLeftLayout == value) 219 return; 220 221 m_rightToLeftLayout = value; 222 foreach (FloatWindow floatWindow in FloatWindows) 223 floatWindow.RightToLeftLayout = value; 224 } 225 } 226 227 protected override void OnRightToLeftChanged(EventArgs e) { 228 base.OnRightToLeftChanged(e); 229 foreach (FloatWindow floatWindow in FloatWindows) { 230 if (floatWindow.RightToLeft != RightToLeft) 231 floatWindow.RightToLeft = RightToLeft; 232 } 233 } 234 235 private bool m_showDocumentIcon = false; 236 [DefaultValue(false)] 237 [LocalizedCategory("Category_Docking")] 238 [LocalizedDescription("DockPanel_ShowDocumentIcon_Description")] 239 public bool ShowDocumentIcon { 240 get { return m_showDocumentIcon; } 241 set { 242 if (m_showDocumentIcon == value) 243 return; 244 245 m_showDocumentIcon = value; 246 Refresh(); 247 } 248 } 249 250 private DocumentTabStripLocation m_documentTabStripLocation = DocumentTabStripLocation.Top; 251 [DefaultValue(DocumentTabStripLocation.Top)] 252 [LocalizedCategory("Category_Docking")] 253 [LocalizedDescription("DockPanel_DocumentTabStripLocation")] 254 public DocumentTabStripLocation DocumentTabStripLocation { 255 get { return m_documentTabStripLocation; } 256 set { m_documentTabStripLocation = value; } 257 } 258 259 [Browsable(false)] 260 public DockPanelExtender Extender { 261 get { return m_extender; } 262 } 263 264 [Browsable(false)] 265 public DockPanelExtender.IDockPaneFactory DockPaneFactory { 266 get { return Extender.DockPaneFactory; } 267 } 268 269 [Browsable(false)] 270 public DockPanelExtender.IFloatWindowFactory FloatWindowFactory { 271 get { return Extender.FloatWindowFactory; } 272 } 273 274 internal DockPanelExtender.IDockPaneCaptionFactory DockPaneCaptionFactory { 275 get { return Extender.DockPaneCaptionFactory; } 276 } 277 278 internal DockPanelExtender.IDockPaneStripFactory DockPaneStripFactory { 279 get { return Extender.DockPaneStripFactory; } 280 } 281 282 internal DockPanelExtender.IAutoHideStripFactory AutoHideStripFactory { 283 get { return Extender.AutoHideStripFactory; } 284 } 285 286 [Browsable(false)] 287 public DockPaneCollection Panes { 288 get { return m_panes; } 289 } 290 291 internal Rectangle DockArea { 292 get { 293 return new Rectangle(DockPadding.Left, DockPadding.Top, 294 ClientRectangle.Width - DockPadding.Left - DockPadding.Right, 295 ClientRectangle.Height - DockPadding.Top - DockPadding.Bottom); 296 } 297 } 298 299 private double m_dockBottomPortion = 0.25; 300 [LocalizedCategory("Category_Docking")] 301 [LocalizedDescription("DockPanel_DockBottomPortion_Description")] 302 [DefaultValue(0.25)] 303 public double DockBottomPortion { 304 get { return m_dockBottomPortion; } 305 set { 306 if (value <= 0) 307 throw new ArgumentOutOfRangeException("value"); 308 309 if (value == m_dockBottomPortion) 310 return; 311 312 m_dockBottomPortion = value; 313 314 if (m_dockBottomPortion < 1 && m_dockTopPortion < 1) { 315 if (m_dockTopPortion + m_dockBottomPortion > 1) 316 m_dockTopPortion = 1 - m_dockBottomPortion; 317 } 318 319 PerformLayout(); 320 } 321 } 322 323 private double m_dockLeftPortion = 0.25; 324 [LocalizedCategory("Category_Docking")] 325 [LocalizedDescription("DockPanel_DockLeftPortion_Description")] 326 [DefaultValue(0.25)] 327 public double DockLeftPortion { 328 get { return m_dockLeftPortion; } 329 set { 330 if (value <= 0) 331 throw new ArgumentOutOfRangeException("value"); 332 333 if (value == m_dockLeftPortion) 334 return; 335 336 m_dockLeftPortion = value; 337 338 if (m_dockLeftPortion < 1 && m_dockRightPortion < 1) { 339 if (m_dockLeftPortion + m_dockRightPortion > 1) 340 m_dockRightPortion = 1 - m_dockLeftPortion; 341 } 342 PerformLayout(); 343 } 344 } 345 346 private double m_dockRightPortion = 0.25; 347 [LocalizedCategory("Category_Docking")] 348 [LocalizedDescription("DockPanel_DockRightPortion_Description")] 349 [DefaultValue(0.25)] 350 public double DockRightPortion { 351 get { return m_dockRightPortion; } 352 set { 353 if (value <= 0) 354 throw new ArgumentOutOfRangeException("value"); 355 356 if (value == m_dockRightPortion) 357 return; 358 359 m_dockRightPortion = value; 360 361 if (m_dockLeftPortion < 1 && m_dockRightPortion < 1) { 362 if (m_dockLeftPortion + m_dockRightPortion > 1) 363 m_dockLeftPortion = 1 - m_dockRightPortion; 364 } 365 PerformLayout(); 366 } 367 } 368 369 private double m_dockTopPortion = 0.25; 370 [LocalizedCategory("Category_Docking")] 371 [LocalizedDescription("DockPanel_DockTopPortion_Description")] 372 [DefaultValue(0.25)] 373 public double DockTopPortion { 374 get { return m_dockTopPortion; } 375 set { 376 if (value <= 0) 377 throw new ArgumentOutOfRangeException("value"); 378 379 if (value == m_dockTopPortion) 380 return; 381 382 m_dockTopPortion = value; 383 384 if (m_dockTopPortion < 1 && m_dockBottomPortion < 1) { 385 if (m_dockTopPortion + m_dockBottomPortion > 1) 386 m_dockBottomPortion = 1 - m_dockTopPortion; 387 } 388 PerformLayout(); 389 } 390 } 391 392 [Browsable(false)] 393 public DockWindowCollection DockWindows { 394 get { return m_dockWindows; } 395 } 396 397 public void UpdateDockWindowZOrder(DockStyle dockStyle, bool fullPanelEdge) { 398 if (dockStyle == DockStyle.Left) { 399 if (fullPanelEdge) 400 DockWindows[DockState.DockLeft].SendToBack(); 401 else 402 DockWindows[DockState.DockLeft].BringToFront(); 403 } else if (dockStyle == DockStyle.Right) { 404 if (fullPanelEdge) 405 DockWindows[DockState.DockRight].SendToBack(); 406 else 407 DockWindows[DockState.DockRight].BringToFront(); 408 } else if (dockStyle == DockStyle.Top) { 409 if (fullPanelEdge) 410 DockWindows[DockState.DockTop].SendToBack(); 411 else 412 DockWindows[DockState.DockTop].BringToFront(); 413 } else if (dockStyle == DockStyle.Bottom) { 414 if (fullPanelEdge) 415 DockWindows[DockState.DockBottom].SendToBack(); 416 else 417 DockWindows[DockState.DockBottom].BringToFront(); 418 } 419 } 420 421 [Browsable(false)] 422 public int DocumentsCount { 423 get { 424 int count = 0; 425 foreach (IDockContent content in Documents) 426 count++; 427 428 return count; 429 } 430 } 431 432 public IDockContent[] DocumentsToArray() { 433 int count = DocumentsCount; 434 IDockContent[] documents = new IDockContent[count]; 435 int i = 0; 436 foreach (IDockContent content in Documents) { 437 documents[i] = content; 438 i++; 439 } 440 441 return documents; 442 } 443 444 [Browsable(false)] 445 public IEnumerable<IDockContent> Documents { 446 get { 447 foreach (IDockContent content in Contents) { 448 if (content.DockHandler.DockState == DockState.Document) 449 yield return content; 450 } 451 } 452 } 453 454 private Rectangle DocumentRectangle { 455 get { 456 Rectangle rect = DockArea; 457 if (DockWindows[DockState.DockLeft].VisibleNestedPanes.Count != 0) { 458 rect.X += (int)(DockArea.Width * DockLeftPortion); 459 rect.Width -= (int)(DockArea.Width * DockLeftPortion); 460 } 461 if (DockWindows[DockState.DockRight].VisibleNestedPanes.Count != 0) 462 rect.Width -= (int)(DockArea.Width * DockRightPortion); 463 if (DockWindows[DockState.DockTop].VisibleNestedPanes.Count != 0) { 464 rect.Y += (int)(DockArea.Height * DockTopPortion); 465 rect.Height -= (int)(DockArea.Height * DockTopPortion); 466 } 467 if (DockWindows[DockState.DockBottom].VisibleNestedPanes.Count != 0) 468 rect.Height -= (int)(DockArea.Height * DockBottomPortion); 469 470 return rect; 471 } 472 } 473 474 private Control DummyControl { 475 get { return m_dummyControl; } 476 } 477 478 [Browsable(false)] 479 public FloatWindowCollection FloatWindows { 480 get { return m_floatWindows; } 481 } 482 483 private Size m_defaultFloatWindowSize = new Size(300, 300); 484 [Category("Layout")] 485 [LocalizedDescription("DockPanel_DefaultFloatWindowSize_Description")] 486 public Size DefaultFloatWindowSize { 487 get { return m_defaultFloatWindowSize; } 488 set { m_defaultFloatWindowSize = value; } 489 } 490 private bool ShouldSerializeDefaultFloatWindowSize() { 491 return DefaultFloatWindowSize != new Size(300, 300); 492 } 493 private void ResetDefaultFloatWindowSize() { 494 DefaultFloatWindowSize = new Size(300, 300); 495 } 496 497 private DocumentStyle m_documentStyle = DocumentStyle.DockingMdi; 498 [LocalizedCategory("Category_Docking")] 499 [LocalizedDescription("DockPanel_DocumentStyle_Description")] 500 [DefaultValue(DocumentStyle.DockingMdi)] 501 public DocumentStyle DocumentStyle { 502 get { return m_documentStyle; } 503 set { 504 if (value == m_documentStyle) 505 return; 506 507 if (!Enum.IsDefined(typeof(DocumentStyle), value)) 508 throw new InvalidEnumArgumentException(); 509 510 if (value == DocumentStyle.SystemMdi && DockWindows[DockState.Document].VisibleNestedPanes.Count > 0) 511 throw new InvalidEnumArgumentException(); 512 513 m_documentStyle = value; 514 515 SuspendLayout(true); 516 517 SetAutoHideWindowParent(); 518 SetMdiClient(); 519 InvalidateWindowRegion(); 520 521 foreach (IDockContent content in Contents) { 522 if (content.DockHandler.DockState == DockState.Document) 523 content.DockHandler.SetPaneAndVisible(content.DockHandler.Pane); 524 } 525 526 PerformMdiClientLayout(); 527 528 ResumeLayout(true, true); 529 } 530 } 531 532 private bool _supprtDeeplyNestedContent = false; 533 [LocalizedCategory("Category_Performance")] 534 [LocalizedDescription("DockPanel_SupportDeeplyNestedContent_Description")] 535 [DefaultValue(false)] 536 public bool SupportDeeplyNestedContent { 537 get { return _supprtDeeplyNestedContent; } 538 set { _supprtDeeplyNestedContent = value; } 539 } 540 541 private int GetDockWindowSize(DockState dockState) { 542 if (dockState == DockState.DockLeft || dockState == DockState.DockRight) { 543 int width = ClientRectangle.Width - DockPadding.Left - DockPadding.Right; 544 int dockLeftSize = m_dockLeftPortion >= 1 ? (int)m_dockLeftPortion : (int)(width * m_dockLeftPortion); 545 int dockRightSize = m_dockRightPortion >= 1 ? (int)m_dockRightPortion : (int)(width * m_dockRightPortion); 546 547 if (dockLeftSize < MeasurePane.MinSize) 548 dockLeftSize = MeasurePane.MinSize; 549 if (dockRightSize < MeasurePane.MinSize) 550 dockRightSize = MeasurePane.MinSize; 551 552 if (dockLeftSize + dockRightSize > width - MeasurePane.MinSize) { 553 int adjust = (dockLeftSize + dockRightSize) - (width - MeasurePane.MinSize); 554 dockLeftSize -= adjust / 2; 555 dockRightSize -= adjust / 2; 556 } 557 558 return dockState == DockState.DockLeft ? dockLeftSize : dockRightSize; 559 } else if (dockState == DockState.DockTop || dockState == DockState.DockBottom) { 560 int height = ClientRectangle.Height - DockPadding.Top - DockPadding.Bottom; 561 int dockTopSize = m_dockTopPortion >= 1 ? (int)m_dockTopPortion : (int)(height * m_dockTopPortion); 562 int dockBottomSize = m_dockBottomPortion >= 1 ? (int)m_dockBottomPortion : (int)(height * m_dockBottomPortion); 563 564 if (dockTopSize < MeasurePane.MinSize) 565 dockTopSize = MeasurePane.MinSize; 566 if (dockBottomSize < MeasurePane.MinSize) 567 dockBottomSize = MeasurePane.MinSize; 568 569 if (dockTopSize + dockBottomSize > height - MeasurePane.MinSize) { 570 int adjust = (dockTopSize + dockBottomSize) - (height - MeasurePane.MinSize); 571 dockTopSize -= adjust / 2; 572 dockBottomSize -= adjust / 2; 573 } 574 575 return dockState == DockState.DockTop ? dockTopSize : dockBottomSize; 576 } else 577 return 0; 578 } 579 580 protected override void OnLayout(LayoutEventArgs levent) { 581 SuspendLayout(true); 582 583 AutoHideStripControl.Bounds = ClientRectangle; 584 585 CalculateDockPadding(); 586 587 DockWindows[DockState.DockLeft].Width = GetDockWindowSize(DockState.DockLeft); 588 DockWindows[DockState.DockRight].Width = GetDockWindowSize(DockState.DockRight); 589 DockWindows[DockState.DockTop].Height = GetDockWindowSize(DockState.DockTop); 590 DockWindows[DockState.DockBottom].Height = GetDockWindowSize(DockState.DockBottom); 591 592 AutoHideWindow.Bounds = GetAutoHideWindowBounds(AutoHideWindowRectangle); 593 594 DockWindows[DockState.Document].BringToFront(); 595 AutoHideWindow.BringToFront(); 596 597 base.OnLayout(levent); 598 599 if (DocumentStyle == DocumentStyle.SystemMdi && MdiClientExists) { 600 SetMdiClientBounds(SystemMdiClientBounds); 601 InvalidateWindowRegion(); 602 } else if (DocumentStyle == DocumentStyle.DockingMdi) 603 InvalidateWindowRegion(); 604 605 ResumeLayout(true, true); 606 } 607 608 internal Rectangle GetTabStripRectangle(DockState dockState) { 609 return AutoHideStripControl.GetTabStripRectangle(dockState); 610 } 611 612 protected override void OnPaint(PaintEventArgs e) { 613 base.OnPaint(e); 614 615 if (DockBackColor == BackColor) return; 616 617 Graphics g = e.Graphics; 618 SolidBrush bgBrush = new SolidBrush(DockBackColor); 619 g.FillRectangle(bgBrush, ClientRectangle); 620 } 621 622 internal void AddContent(IDockContent content) { 623 if (content == null) 624 throw (new ArgumentNullException()); 625 626 if (!Contents.Contains(content)) { 627 Contents.Add(content); 628 OnContentAdded(new DockContentEventArgs(content)); 629 } 630 } 631 632 internal void AddPane(DockPane pane) { 633 if (Panes.Contains(pane)) 634 return; 635 636 Panes.Add(pane); 637 } 638 639 internal void AddFloatWindow(FloatWindow floatWindow) { 640 if (FloatWindows.Contains(floatWindow)) 641 return; 642 643 FloatWindows.Add(floatWindow); 644 } 645 646 private void CalculateDockPadding() { 647 DockPadding.All = 0; 648 649 int height = AutoHideStripControl.MeasureHeight(); 650 651 if (AutoHideStripControl.GetNumberOfPanes(DockState.DockLeftAutoHide) > 0) 652 DockPadding.Left = height; 653 if (AutoHideStripControl.GetNumberOfPanes(DockState.DockRightAutoHide) > 0) 654 DockPadding.Right = height; 655 if (AutoHideStripControl.GetNumberOfPanes(DockState.DockTopAutoHide) > 0) 656 DockPadding.Top = height; 657 if (AutoHideStripControl.GetNumberOfPanes(DockState.DockBottomAutoHide) > 0) 658 DockPadding.Bottom = height; 659 } 660 661 internal void RemoveContent(IDockContent content) { 662 if (content == null) 663 throw (new ArgumentNullException()); 664 665 if (Contents.Contains(content)) { 666 Contents.Remove(content); 667 OnContentRemoved(new DockContentEventArgs(content)); 668 } 669 } 670 671 internal void RemovePane(DockPane pane) { 672 if (!Panes.Contains(pane)) 673 return; 674 675 Panes.Remove(pane); 676 } 677 678 internal void RemoveFloatWindow(FloatWindow floatWindow) { 679 if (!FloatWindows.Contains(floatWindow)) 680 return; 681 682 FloatWindows.Remove(floatWindow); 683 } 684 685 public void SetPaneIndex(DockPane pane, int index) { 686 int oldIndex = Panes.IndexOf(pane); 687 if (oldIndex == -1) 688 throw (new ArgumentException(Strings.DockPanel_SetPaneIndex_InvalidPane)); 689 690 if (index < 0 || index > Panes.Count - 1) 691 if (index != -1) 692 throw (new ArgumentOutOfRangeException(Strings.DockPanel_SetPaneIndex_InvalidIndex)); 693 694 if (oldIndex == index) 695 return; 696 if (oldIndex == Panes.Count - 1 && index == -1) 697 return; 698 699 Panes.Remove(pane); 700 if (index == -1) 701 Panes.Add(pane); 702 else if (oldIndex < index) 703 Panes.AddAt(pane, index - 1); 704 else 705 Panes.AddAt(pane, index); 706 } 707 708 public void SuspendLayout(bool allWindows) { 709 FocusManager.SuspendFocusTracking(); 710 SuspendLayout(); 711 if (allWindows) 712 SuspendMdiClientLayout(); 713 } 714 715 public void ResumeLayout(bool performLayout, bool allWindows) { 716 FocusManager.ResumeFocusTracking(); 717 ResumeLayout(performLayout); 718 if (allWindows) 719 ResumeMdiClientLayout(performLayout); 720 } 721 722 internal Form ParentForm { 723 get { 724 if (!IsParentFormValid()) 725 throw new InvalidOperationException(Strings.DockPanel_ParentForm_Invalid); 726 727 return GetMdiClientController().ParentForm; 728 } 729 } 730 731 private bool IsParentFormValid() { 732 if (DocumentStyle == DocumentStyle.DockingSdi || DocumentStyle == DocumentStyle.DockingWindow) 733 return true; 734 735 if (!MdiClientExists) 736 GetMdiClientController().RenewMdiClient(); 737 738 return (MdiClientExists); 739 } 740 741 protected override void OnParentChanged(EventArgs e) { 742 SetAutoHideWindowParent(); 743 GetMdiClientController().ParentForm = (this.Parent as Form); 744 base.OnParentChanged(e); 745 } 746 747 private void SetAutoHideWindowParent() { 748 Control parent; 749 if (DocumentStyle == DocumentStyle.DockingMdi || 750 DocumentStyle == DocumentStyle.SystemMdi) 751 parent = this.Parent; 752 else 753 parent = this; 754 if (AutoHideWindow.Parent != parent) { 755 AutoHideWindow.Parent = parent; 756 AutoHideWindow.BringToFront(); 757 } 758 } 759 760 protected override void OnVisibleChanged(EventArgs e) { 761 base.OnVisibleChanged(e); 762 763 if (Visible) 764 SetMdiClient(); 765 } 766 767 private Rectangle SystemMdiClientBounds { 768 get { 769 if (!IsParentFormValid() || !Visible) 770 return Rectangle.Empty; 771 772 Rectangle rect = ParentForm.RectangleToClient(RectangleToScreen(DocumentWindowBounds)); 773 return rect; 774 } 775 } 776 777 internal Rectangle DocumentWindowBounds { 778 get { 779 Rectangle rectDocumentBounds = DisplayRectangle; 780 if (DockWindows[DockState.DockLeft].Visible) { 781 rectDocumentBounds.X += DockWindows[DockState.DockLeft].Width; 782 rectDocumentBounds.Width -= DockWindows[DockState.DockLeft].Width; 783 } 784 if (DockWindows[DockState.DockRight].Visible) 785 rectDocumentBounds.Width -= DockWindows[DockState.DockRight].Width; 786 if (DockWindows[DockState.DockTop].Visible) { 787 rectDocumentBounds.Y += DockWindows[DockState.DockTop].Height; 788 rectDocumentBounds.Height -= DockWindows[DockState.DockTop].Height; 789 } 790 if (DockWindows[DockState.DockBottom].Visible) 791 rectDocumentBounds.Height -= DockWindows[DockState.DockBottom].Height; 792 793 return rectDocumentBounds; 794 795 } 796 } 797 798 private PaintEventHandler m_dummyControlPaintEventHandler = null; 799 private void InvalidateWindowRegion() { 800 if (DesignMode) 801 return; 802 803 if (m_dummyControlPaintEventHandler == null) 804 m_dummyControlPaintEventHandler = new PaintEventHandler(DummyControl_Paint); 805 806 DummyControl.Paint += m_dummyControlPaintEventHandler; 807 DummyControl.Invalidate(); 808 } 809 810 void DummyControl_Paint(object sender, PaintEventArgs e) { 811 DummyControl.Paint -= m_dummyControlPaintEventHandler; 812 UpdateWindowRegion(); 813 } 814 815 private void UpdateWindowRegion() { 816 if (this.DocumentStyle == DocumentStyle.DockingMdi) 817 UpdateWindowRegion_ClipContent(); 818 else if (this.DocumentStyle == DocumentStyle.DockingSdi || 819 this.DocumentStyle == DocumentStyle.DockingWindow) 820 UpdateWindowRegion_FullDocumentArea(); 821 else if (this.DocumentStyle == DocumentStyle.SystemMdi) 822 UpdateWindowRegion_EmptyDocumentArea(); 823 } 824 825 private void UpdateWindowRegion_FullDocumentArea() { 826 SetRegion(null); 827 } 828 829 private void UpdateWindowRegion_EmptyDocumentArea() { 830 Rectangle rect = DocumentWindowBounds; 831 SetRegion(new Rectangle[] { rect }); 832 } 833 834 private void UpdateWindowRegion_ClipContent() { 835 int count = 0; 836 foreach (DockPane pane in this.Panes) { 837 if (!pane.Visible || pane.DockState != DockState.Document) 838 continue; 839 840 count++; 841 } 842 843 if (count == 0) { 844 SetRegion(null); 845 return; 846 } 847 848 Rectangle[] rects = new Rectangle[count]; 849 int i = 0; 850 foreach (DockPane pane in this.Panes) { 851 if (!pane.Visible || pane.DockState != DockState.Document) 852 continue; 853 854 rects[i] = RectangleToClient(pane.RectangleToScreen(pane.ContentRectangle)); 855 i++; 856 } 857 858 SetRegion(rects); 859 } 860 861 private Rectangle[] m_clipRects = null; 862 private void SetRegion(Rectangle[] clipRects) { 863 if (!IsClipRectsChanged(clipRects)) 864 return; 865 866 m_clipRects = clipRects; 867 868 if (m_clipRects == null || m_clipRects.GetLength(0) == 0) 869 Region = null; 870 else { 871 Region region = new Region(new Rectangle(0, 0, this.Width, this.Height)); 872 foreach (Rectangle rect in m_clipRects) 873 region.Exclude(rect); 874 Region = region; 875 } 876 } 877 878 private bool IsClipRectsChanged(Rectangle[] clipRects) { 879 if (clipRects == null && m_clipRects == null) 880 return false; 881 else if ((clipRects == null) != (m_clipRects == null)) 882 return true; 883 884 foreach (Rectangle rect in clipRects) { 885 bool matched = false; 886 foreach (Rectangle rect2 in m_clipRects) { 887 if (rect == rect2) { 888 matched = true; 889 break; 890 } 891 } 892 if (!matched) 893 return true; 894 } 895 896 foreach (Rectangle rect2 in m_clipRects) { 897 bool matched = false; 898 foreach (Rectangle rect in clipRects) { 899 if (rect == rect2) { 900 matched = true; 901 break; 902 } 903 } 904 if (!matched) 905 return true; 906 } 907 return false; 908 } 909 910 private static readonly object ContentAddedEvent = new object(); 911 [LocalizedCategory("Category_DockingNotification")] 912 [LocalizedDescription("DockPanel_ContentAdded_Description")] 913 public event EventHandler<DockContentEventArgs> ContentAdded { 914 add { Events.AddHandler(ContentAddedEvent, value); } 915 remove { Events.RemoveHandler(ContentAddedEvent, value); } 916 } 917 protected virtual void OnContentAdded(DockContentEventArgs e) { 918 EventHandler<DockContentEventArgs> handler = (EventHandler<DockContentEventArgs>)Events[ContentAddedEvent]; 919 if (handler != null) 920 handler(this, e); 921 } 922 923 private static readonly object ContentRemovedEvent = new object(); 924 [LocalizedCategory("Category_DockingNotification")] 925 [LocalizedDescription("DockPanel_ContentRemoved_Description")] 926 public event EventHandler<DockContentEventArgs> ContentRemoved { 927 add { Events.AddHandler(ContentRemovedEvent, value); } 928 remove { Events.RemoveHandler(ContentRemovedEvent, value); } 929 } 930 protected virtual void OnContentRemoved(DockContentEventArgs e) { 931 EventHandler<DockContentEventArgs> handler = (EventHandler<DockContentEventArgs>)Events[ContentRemovedEvent]; 932 if (handler != null) 933 handler(this, e); 934 } 935 } 1080 936 } -
branches/UnloadJobs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.Designer.cs
r7967 r9174 27 27 private System.ComponentModel.IContainer components = null; 28 28 29 /// <summary>30 /// Clean up any resources being used.31 /// </summary>32 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>33 protected override void Dispose(bool disposing) {34 if (disposing) {35 if (components != null) components.Dispose();36 }37 base.Dispose(disposing);38 }39 29 40 30 #region Component Designer generated code -
branches/UnloadJobs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.cs
r8587 r9174 298 298 } 299 299 #endregion 300 301 /// <summary> 302 /// Clean up any resources being used. (copied from Designer.cs file) 303 /// </summary> 304 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 305 protected override void Dispose(bool disposing) { 306 if (disposing) { 307 if (components != null) components.Dispose(); 308 ActiveView = null; 309 cachedView = null; 310 viewContextMenuStrip.ItemClicked -= new System.Windows.Forms.ToolStripItemClickedEventHandler(this.viewContextMenuStrip_ItemClicked); 311 viewContextMenuStrip.Dispose(); 312 } 313 base.Dispose(disposing); 314 } 300 315 } 301 316 } -
branches/UnloadJobs/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/DockForm.cs
r7259 r9174 75 75 76 76 protected override void Dispose(bool disposing) { 77 if (View != null) 77 if (View != null) { 78 78 View.CaptionChanged -= new System.EventHandler(View_CaptionChanged); 79 view = null; 80 } 79 81 if (disposing && (components != null)) { 80 82 components.Dispose(); -
branches/UnloadJobs/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs
r8821 r9174 316 316 if (ActiveView == view) 317 317 ActiveView = null; 318 319 if (showContentInViewHost) { 320 ViewHost vh = view as ViewHost; 321 vh.Content = null; 322 vh.Dispose(); 323 } 318 324 } 319 325 -
branches/UnloadJobs/HeuristicLab.Operators.Views.GraphVisualization.Views/3.3/GraphVisualizationInfoView.Designer.cs
r7967 r9174 26 26 /// </summary> 27 27 private System.ComponentModel.IContainer components = null; 28 29 /// <summary>30 /// Clean up any resources being used.31 /// </summary>32 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>33 protected override void Dispose(bool disposing) {34 if (disposing && (components != null)) {35 components.Dispose();36 }37 base.Dispose(disposing);38 }39 28 40 29 #region Component Designer generated code -
branches/UnloadJobs/HeuristicLab.Operators.Views.GraphVisualization.Views/3.3/GraphVisualizationInfoView.cs
r9011 r9174 349 349 } 350 350 } 351 352 /// <summary> 353 /// Clean up any resources being used. 354 /// </summary> 355 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 356 protected override void Dispose(bool disposing) { 357 if (disposing && (components != null)) { 358 if (Content != null) { 359 DeregisterContentEvents(); 360 } 361 foreach (IConnectionInfo connectionInfo in this.connectionInfoConnectionMapping.FirstValues.ToList()) { 362 DeregisterConnectionInfoEvents(connectionInfo); 363 } 364 foreach (IShapeInfo shapeInfo in this.shapeInfoShapeMapping.FirstValues.ToList()) { 365 DeregisterShapeInfoEvents(shapeInfo); 366 } 367 foreach (var shape in this.shapeInfoShapeMapping.SecondValues.ToList()) { 368 DeregisterShapeEvents(shape); 369 } 370 if (Content != null) { 371 foreach (IShapeInfo shapeInfo in this.Content.ShapeInfos) 372 DeregisterShapeInfoEvents(shapeInfo); 373 foreach (IConnectionInfo connectionInfo in this.Content.ConnectionInfos) 374 DeregisterConnectionInfoEvents(connectionInfo); 375 } 376 this.graphVisualization.OnEntityRemoved -= new System.EventHandler<global::Netron.Diagramming.Core.EntityEventArgs>(this.graphVisualization_OnEntityRemoved); 377 this.graphVisualization.OnEntityAdded -= new System.EventHandler<global::Netron.Diagramming.Core.EntityEventArgs>(this.graphVisualization_OnEntityAdded); 378 379 components.Dispose(); 380 } 381 base.Dispose(disposing); 382 } 351 383 } 352 384 } -
branches/UnloadJobs/HeuristicLab.Operators.Views.GraphVisualization.Views/3.3/OperatorGraphView.Designer.cs
r8000 r9174 26 26 /// </summary> 27 27 private System.ComponentModel.IContainer components = null; 28 29 /// <summary>30 /// Clean up any resources being used.31 /// </summary>32 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>33 protected override void Dispose(bool disposing) {34 if (disposing && (components != null)) {35 components.Dispose();36 }37 base.Dispose(disposing);38 }39 28 40 29 #region Component Designer generated code -
branches/UnloadJobs/HeuristicLab.Operators.Views.GraphVisualization.Views/3.3/OperatorGraphView.cs
r8860 r9174 319 319 } 320 320 } 321 322 /// <summary> 323 /// Clean up any resources being used. 324 /// </summary> 325 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 326 protected override void Dispose(bool disposing) { 327 if (disposing && (components != null)) { 328 this.graphVisualizationInfoView.Controller.OnShowContextMenu -= new EventHandler<EntityMenuEventArgs>(Controller_OnShowContextMenu); 329 this.graphVisualizationInfoView.Controller.Model.Selection.OnNewSelection -= new EventHandler(Controller_SelectionChanged); 330 this.graphVisualizationInfoView.Controller.OnMouseDown -= new EventHandler<MouseEventArgs>(Controller_OnMouseDown); 331 this.graphVisualizationInfoView.Controller.ParentControl.MouseDown -= new MouseEventHandler(ParentControl_MouseDown); 332 this.graphVisualizationInfoView.Controller.ParentControl.MouseUp -= new MouseEventHandler(ParentControl_MouseUp); 333 foreach (ITool tool in this.graphVisualizationInfoView.Controller.Tools) { 334 tool.OnToolActivate -= new EventHandler<ToolEventArgs>(tool_OnToolActivate); 335 tool.OnToolDeactivate -= new EventHandler<ToolEventArgs>(tool_OnToolDeactivate); 336 } 337 detailsViewHost.Content = null; 338 components.Dispose(); 339 } 340 base.Dispose(disposing); 341 } 321 342 } 322 343 }
Note: See TracChangeset
for help on using the changeset viewer.