Changeset 9174 for branches/UnloadJobs/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.7.0/WinFormsUI-2.7.0/Docking/DockPanel.cs
- Timestamp:
- 01/21/13 09:05:57 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.