File size: 24,286 Bytes
b1b3bae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
using System;
using System.Windows.Forms;
using System.Drawing;
namespace WeifenLuo.WinFormsUI.Docking
{
partial class DockPanel
{
internal class DefaultAutoHideWindowControl : AutoHideWindowControl
{
public DefaultAutoHideWindowControl(DockPanel dockPanel) : base(dockPanel)
{
m_splitter = new SplitterControl(this);
Controls.Add(m_splitter);
}
protected override void OnLayout(LayoutEventArgs levent)
{
DockPadding.All = 0;
if (DockState == DockState.DockLeftAutoHide)
{
DockPadding.Right = 2;
m_splitter.Dock = DockStyle.Right;
}
else if (DockState == DockState.DockRightAutoHide)
{
DockPadding.Left = 2;
m_splitter.Dock = DockStyle.Left;
}
else if (DockState == DockState.DockTopAutoHide)
{
DockPadding.Bottom = 2;
m_splitter.Dock = DockStyle.Bottom;
}
else if (DockState == DockState.DockBottomAutoHide)
{
DockPadding.Top = 2;
m_splitter.Dock = DockStyle.Top;
}
Rectangle rectDisplaying = DisplayingRectangle;
Rectangle rectHidden = new Rectangle(-rectDisplaying.Width, rectDisplaying.Y, rectDisplaying.Width, rectDisplaying.Height);
foreach (Control c in Controls)
{
DockPane pane = c as DockPane;
if (pane == null)
continue;
if (pane == ActivePane)
pane.Bounds = rectDisplaying;
else
pane.Bounds = rectHidden;
}
base.OnLayout(levent);
}
protected override void OnPaint(PaintEventArgs e)
{
// Draw the border
Graphics g = e.Graphics;
if (DockState == DockState.DockBottomAutoHide)
g.DrawLine(SystemPens.ControlLightLight, 0, 1, ClientRectangle.Right, 1);
else if (DockState == DockState.DockRightAutoHide)
g.DrawLine(SystemPens.ControlLightLight, 1, 0, 1, ClientRectangle.Bottom);
else if (DockState == DockState.DockTopAutoHide)
{
g.DrawLine(SystemPens.ControlDark, 0, ClientRectangle.Height - 2, ClientRectangle.Right, ClientRectangle.Height - 2);
g.DrawLine(SystemPens.ControlDarkDark, 0, ClientRectangle.Height - 1, ClientRectangle.Right, ClientRectangle.Height - 1);
}
else if (DockState == DockState.DockLeftAutoHide)
{
g.DrawLine(SystemPens.ControlDark, ClientRectangle.Width - 2, 0, ClientRectangle.Width - 2, ClientRectangle.Bottom);
g.DrawLine(SystemPens.ControlDarkDark, ClientRectangle.Width - 1, 0, ClientRectangle.Width - 1, ClientRectangle.Bottom);
}
base.OnPaint(e);
}
}
public class AutoHideWindowControl : Panel, ISplitterDragSource
{
protected class SplitterControl : SplitterBase
{
public SplitterControl(AutoHideWindowControl autoHideWindow)
{
m_autoHideWindow = autoHideWindow;
}
private AutoHideWindowControl m_autoHideWindow;
private AutoHideWindowControl AutoHideWindow
{
get { return m_autoHideWindow; }
}
protected override int SplitterSize
{
get { return Measures.SplitterSize; }
}
protected override void StartDrag()
{
AutoHideWindow.DockPanel.BeginDrag(AutoHideWindow, AutoHideWindow.RectangleToScreen(Bounds));
}
}
#region consts
private const int ANIMATE_TIME = 100; // in mini-seconds
#endregion
private Timer m_timerMouseTrack;
protected SplitterBase m_splitter;
public AutoHideWindowControl(DockPanel dockPanel)
{
m_dockPanel = dockPanel;
m_timerMouseTrack = new Timer();
m_timerMouseTrack.Tick += new EventHandler(TimerMouseTrack_Tick);
Visible = false;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
m_timerMouseTrack.Dispose();
}
base.Dispose(disposing);
}
private DockPanel m_dockPanel = null;
public DockPanel DockPanel
{
get { return m_dockPanel; }
}
private DockPane m_activePane = null;
public DockPane ActivePane
{
get { return m_activePane; }
}
private void SetActivePane()
{
DockPane value = (ActiveContent == null ? null : ActiveContent.DockHandler.Pane);
if (value == m_activePane)
return;
m_activePane = value;
}
private static readonly object ActiveContentChangedEvent = new object();
public event EventHandler ActiveContentChanged
{
add { Events.AddHandler(ActiveContentChangedEvent, value); }
remove { Events.RemoveHandler(ActiveContentChangedEvent, value); }
}
protected virtual void OnActiveContentChanged(EventArgs e)
{
EventHandler handler = (EventHandler)Events[ActiveContentChangedEvent];
if (handler != null)
handler(this, e);
}
private IDockContent m_activeContent = null;
public IDockContent ActiveContent
{
get { return m_activeContent; }
set
{
if (value == m_activeContent)
return;
if (value != null)
{
if (!DockHelper.IsDockStateAutoHide(value.DockHandler.DockState) || value.DockHandler.DockPanel != DockPanel)
throw (new InvalidOperationException(Strings.DockPanel_ActiveAutoHideContent_InvalidValue));
}
DockPanel.SuspendLayout();
if (m_activeContent != null)
{
if (m_activeContent.DockHandler.Form.ContainsFocus)
{
if (!Win32Helper.IsRunningOnMono)
{
DockPanel.ContentFocusManager.GiveUpFocus(m_activeContent);
}
}
AnimateWindow(false);
}
m_activeContent = value;
SetActivePane();
if (ActivePane != null)
ActivePane.ActiveContent = m_activeContent;
if (m_activeContent != null)
AnimateWindow(true);
DockPanel.ResumeLayout();
DockPanel.RefreshAutoHideStrip();
SetTimerMouseTrack();
OnActiveContentChanged(EventArgs.Empty);
}
}
public DockState DockState
{
get { return ActiveContent == null ? DockState.Unknown : ActiveContent.DockHandler.DockState; }
}
private bool m_flagAnimate = true;
private bool FlagAnimate
{
get { return m_flagAnimate; }
set { m_flagAnimate = value; }
}
private bool m_flagDragging = false;
internal bool FlagDragging
{
get { return m_flagDragging; }
set
{
if (m_flagDragging == value)
return;
m_flagDragging = value;
SetTimerMouseTrack();
}
}
private void AnimateWindow(bool show)
{
if (!FlagAnimate && Visible != show)
{
Visible = show;
return;
}
Parent.SuspendLayout();
Rectangle rectSource = GetRectangle(!show);
Rectangle rectTarget = GetRectangle(show);
int dxLoc, dyLoc;
int dWidth, dHeight;
dxLoc = dyLoc = dWidth = dHeight = 0;
if (DockState == DockState.DockTopAutoHide)
dHeight = show ? 1 : -1;
else if (DockState == DockState.DockLeftAutoHide)
dWidth = show ? 1 : -1;
else if (DockState == DockState.DockRightAutoHide)
{
dxLoc = show ? -1 : 1;
dWidth = show ? 1 : -1;
}
else if (DockState == DockState.DockBottomAutoHide)
{
dyLoc = (show ? -1 : 1);
dHeight = (show ? 1 : -1);
}
if (show)
{
Bounds = DockPanel.GetAutoHideWindowBounds(new Rectangle(-rectTarget.Width, -rectTarget.Height, rectTarget.Width, rectTarget.Height));
if (Visible == false)
Visible = true;
PerformLayout();
}
SuspendLayout();
LayoutAnimateWindow(rectSource);
if (Visible == false)
Visible = true;
int speedFactor = 1;
int totalPixels = (rectSource.Width != rectTarget.Width) ?
Math.Abs(rectSource.Width - rectTarget.Width) :
Math.Abs(rectSource.Height - rectTarget.Height);
int remainPixels = totalPixels;
DateTime startingTime = DateTime.Now;
while (rectSource != rectTarget)
{
DateTime startPerMove = DateTime.Now;
rectSource.X += dxLoc * speedFactor;
rectSource.Y += dyLoc * speedFactor;
rectSource.Width += dWidth * speedFactor;
rectSource.Height += dHeight * speedFactor;
if (Math.Sign(rectTarget.X - rectSource.X) != Math.Sign(dxLoc))
rectSource.X = rectTarget.X;
if (Math.Sign(rectTarget.Y - rectSource.Y) != Math.Sign(dyLoc))
rectSource.Y = rectTarget.Y;
if (Math.Sign(rectTarget.Width - rectSource.Width) != Math.Sign(dWidth))
rectSource.Width = rectTarget.Width;
if (Math.Sign(rectTarget.Height - rectSource.Height) != Math.Sign(dHeight))
rectSource.Height = rectTarget.Height;
LayoutAnimateWindow(rectSource);
if (Parent != null)
Parent.Update();
remainPixels -= speedFactor;
while (true)
{
TimeSpan time = new TimeSpan(0, 0, 0, 0, ANIMATE_TIME);
TimeSpan elapsedPerMove = DateTime.Now - startPerMove;
TimeSpan elapsedTime = DateTime.Now - startingTime;
if (((int)((time - elapsedTime).TotalMilliseconds)) <= 0)
{
speedFactor = remainPixels;
break;
}
else
speedFactor = remainPixels * (int)elapsedPerMove.TotalMilliseconds / (int)((time - elapsedTime).TotalMilliseconds);
if (speedFactor >= 1)
break;
}
}
ResumeLayout();
Parent.ResumeLayout();
}
private void LayoutAnimateWindow(Rectangle rect)
{
Bounds = DockPanel.GetAutoHideWindowBounds(rect);
Rectangle rectClient = ClientRectangle;
if (DockState == DockState.DockLeftAutoHide)
ActivePane.Location = new Point(rectClient.Right - 2 - Measures.SplitterSize - ActivePane.Width, ActivePane.Location.Y);
else if (DockState == DockState.DockTopAutoHide)
ActivePane.Location = new Point(ActivePane.Location.X, rectClient.Bottom - 2 - Measures.SplitterSize - ActivePane.Height);
}
private Rectangle GetRectangle(bool show)
{
if (DockState == DockState.Unknown)
return Rectangle.Empty;
Rectangle rect = DockPanel.AutoHideWindowRectangle;
if (show)
return rect;
if (DockState == DockState.DockLeftAutoHide)
rect.Width = 0;
else if (DockState == DockState.DockRightAutoHide)
{
rect.X += rect.Width;
rect.Width = 0;
}
else if (DockState == DockState.DockTopAutoHide)
rect.Height = 0;
else
{
rect.Y += rect.Height;
rect.Height = 0;
}
return rect;
}
private void SetTimerMouseTrack()
{
if (ActivePane == null || ActivePane.IsActivated || FlagDragging)
{
m_timerMouseTrack.Enabled = false;
return;
}
// start the timer
int hovertime = SystemInformation.MouseHoverTime ;
// assign a default value 400 in case of setting Timer.Interval invalid value exception
if (hovertime <= 0)
hovertime = 400;
m_timerMouseTrack.Interval = 2 * (int)hovertime;
m_timerMouseTrack.Enabled = true;
}
protected virtual Rectangle DisplayingRectangle
{
get
{
Rectangle rect = ClientRectangle;
// exclude the border and the splitter
if (DockState == DockState.DockBottomAutoHide)
{
rect.Y += 2 + Measures.SplitterSize;
rect.Height -= 2 + Measures.SplitterSize;
}
else if (DockState == DockState.DockRightAutoHide)
{
rect.X += 2 + Measures.SplitterSize;
rect.Width -= 2 + Measures.SplitterSize;
}
else if (DockState == DockState.DockTopAutoHide)
rect.Height -= 2 + Measures.SplitterSize;
else if (DockState == DockState.DockLeftAutoHide)
rect.Width -= 2 + Measures.SplitterSize;
return rect;
}
}
public void RefreshActiveContent()
{
if (ActiveContent == null)
return;
if (!DockHelper.IsDockStateAutoHide(ActiveContent.DockHandler.DockState))
{
FlagAnimate = false;
ActiveContent = null;
FlagAnimate = true;
}
}
public void RefreshActivePane()
{
SetTimerMouseTrack();
}
private void TimerMouseTrack_Tick(object sender, EventArgs e)
{
if (IsDisposed)
return;
if (ActivePane == null || ActivePane.IsActivated)
{
m_timerMouseTrack.Enabled = false;
return;
}
DockPane pane = ActivePane;
Point ptMouseInAutoHideWindow = PointToClient(Control.MousePosition);
Point ptMouseInDockPanel = DockPanel.PointToClient(Control.MousePosition);
Rectangle rectTabStrip = DockPanel.GetTabStripRectangle(pane.DockState);
if (!ClientRectangle.Contains(ptMouseInAutoHideWindow) && !rectTabStrip.Contains(ptMouseInDockPanel))
{
ActiveContent = null;
m_timerMouseTrack.Enabled = false;
}
}
#region ISplitterDragSource Members
void ISplitterDragSource.BeginDrag(Rectangle rectSplitter)
{
FlagDragging = true;
}
void ISplitterDragSource.EndDrag()
{
FlagDragging = false;
}
bool ISplitterDragSource.IsVertical
{
get { return (DockState == DockState.DockLeftAutoHide || DockState == DockState.DockRightAutoHide); }
}
Rectangle ISplitterDragSource.DragLimitBounds
{
get
{
Rectangle rectLimit = DockPanel.DockArea;
if ((this as ISplitterDragSource).IsVertical)
{
rectLimit.X += MeasurePane.MinSize;
rectLimit.Width -= 2 * MeasurePane.MinSize;
}
else
{
rectLimit.Y += MeasurePane.MinSize;
rectLimit.Height -= 2 * MeasurePane.MinSize;
}
return DockPanel.RectangleToScreen(rectLimit);
}
}
void ISplitterDragSource.MoveSplitter(int offset)
{
Rectangle rectDockArea = DockPanel.DockArea;
IDockContent content = ActiveContent;
if (DockState == DockState.DockLeftAutoHide && rectDockArea.Width > 0)
{
if (content.DockHandler.AutoHidePortion < 1)
content.DockHandler.AutoHidePortion += ((double)offset) / (double)rectDockArea.Width;
else
content.DockHandler.AutoHidePortion = Width + offset;
}
else if (DockState == DockState.DockRightAutoHide && rectDockArea.Width > 0)
{
if (content.DockHandler.AutoHidePortion < 1)
content.DockHandler.AutoHidePortion -= ((double)offset) / (double)rectDockArea.Width;
else
content.DockHandler.AutoHidePortion = Width - offset;
}
else if (DockState == DockState.DockBottomAutoHide && rectDockArea.Height > 0)
{
if (content.DockHandler.AutoHidePortion < 1)
content.DockHandler.AutoHidePortion -= ((double)offset) / (double)rectDockArea.Height;
else
content.DockHandler.AutoHidePortion = Height - offset;
}
else if (DockState == DockState.DockTopAutoHide && rectDockArea.Height > 0)
{
if (content.DockHandler.AutoHidePortion < 1)
content.DockHandler.AutoHidePortion += ((double)offset) / (double)rectDockArea.Height;
else
content.DockHandler.AutoHidePortion = Height + offset;
}
}
#region IDragSource Members
Control IDragSource.DragControl
{
get { return this; }
}
#endregion
#endregion
}
private AutoHideWindowControl AutoHideWindow
{
get { return m_autoHideWindow; }
}
internal Control AutoHideControl
{
get { return m_autoHideWindow; }
}
internal void RefreshActiveAutoHideContent()
{
AutoHideWindow.RefreshActiveContent();
}
internal Rectangle AutoHideWindowRectangle
{
get
{
DockState state = AutoHideWindow.DockState;
Rectangle rectDockArea = DockArea;
if (ActiveAutoHideContent == null)
return Rectangle.Empty;
if (Parent == null)
return Rectangle.Empty;
Rectangle rect = Rectangle.Empty;
double autoHideSize = ActiveAutoHideContent.DockHandler.AutoHidePortion;
if (state == DockState.DockLeftAutoHide)
{
if (autoHideSize < 1)
autoHideSize = rectDockArea.Width * autoHideSize;
if (autoHideSize > rectDockArea.Width - MeasurePane.MinSize)
autoHideSize = rectDockArea.Width - MeasurePane.MinSize;
rect.X = rectDockArea.X;
rect.Y = rectDockArea.Y;
rect.Width = (int)autoHideSize;
rect.Height = rectDockArea.Height;
}
else if (state == DockState.DockRightAutoHide)
{
if (autoHideSize < 1)
autoHideSize = rectDockArea.Width * autoHideSize;
if (autoHideSize > rectDockArea.Width - MeasurePane.MinSize)
autoHideSize = rectDockArea.Width - MeasurePane.MinSize;
rect.X = rectDockArea.X + rectDockArea.Width - (int)autoHideSize;
rect.Y = rectDockArea.Y;
rect.Width = (int)autoHideSize;
rect.Height = rectDockArea.Height;
}
else if (state == DockState.DockTopAutoHide)
{
if (autoHideSize < 1)
autoHideSize = rectDockArea.Height * autoHideSize;
if (autoHideSize > rectDockArea.Height - MeasurePane.MinSize)
autoHideSize = rectDockArea.Height - MeasurePane.MinSize;
rect.X = rectDockArea.X;
rect.Y = rectDockArea.Y;
rect.Width = rectDockArea.Width;
rect.Height = (int)autoHideSize;
}
else if (state == DockState.DockBottomAutoHide)
{
if (autoHideSize < 1)
autoHideSize = rectDockArea.Height * autoHideSize;
if (autoHideSize > rectDockArea.Height - MeasurePane.MinSize)
autoHideSize = rectDockArea.Height - MeasurePane.MinSize;
rect.X = rectDockArea.X;
rect.Y = rectDockArea.Y + rectDockArea.Height - (int)autoHideSize;
rect.Width = rectDockArea.Width;
rect.Height = (int)autoHideSize;
}
return rect;
}
}
internal Rectangle GetAutoHideWindowBounds(Rectangle rectAutoHideWindow)
{
if (DocumentStyle == DocumentStyle.SystemMdi ||
DocumentStyle == DocumentStyle.DockingMdi)
return (Parent == null) ? Rectangle.Empty : Parent.RectangleToClient(RectangleToScreen(rectAutoHideWindow));
else
return rectAutoHideWindow;
}
internal void RefreshAutoHideStrip()
{
AutoHideStripControl.RefreshChanges();
}
}
}
|