📄 windowcontenttabbed.cs
字号:
// *****************************************************************************
//
// (c) Crownwood Consulting Limited 2002
// All rights reserved. The software and associated documentation
// supplied hereunder are the proprietary information of Crownwood Consulting
// Limited, Haxey, North Lincolnshire, England and are supplied subject to
// licence terms.
//
// Magic Version 1.7 www.dotnetmagic.com
// *****************************************************************************
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using Crownwood.Magic.Common;
using Crownwood.Magic.Controls;
using Crownwood.Magic.Collections;
namespace Crownwood.Magic.Docking
{
[ToolboxItem(false)]
public class WindowContentTabbed : WindowContent, IHotZoneSource, IMessageFilter
{
// Class constants
protected static int _plainBorder = 3;
protected static int _hotAreaInflate = -3;
// Instance fields
protected int _dragPageIndex;
protected Content _activeContent;
protected RedockerContent _redocker;
protected Magic.Controls.TabControl _tabControl;
public WindowContentTabbed(DockingManager manager, VisualStyle vs)
: base(manager, vs)
{
_redocker = null;
_activeContent = null;
// Create the TabControl used for viewing the Content windows
_tabControl = new Magic.Controls.TabControl();
// It should always occupy the remaining space after all details
_tabControl.Dock = DockStyle.Fill;
// Show tabs only if two or more tab pages exist
_tabControl.HideTabsMode = Magic.Controls.TabControl.HideTabsModes.HideUsingLogic;
// Hook into the TabControl notifications
_tabControl.GotFocus += new EventHandler(OnTabControlGotFocus);
_tabControl.LostFocus += new EventHandler(OnTabControlLostFocus);
_tabControl.PageGotFocus += new EventHandler(OnTabControlGotFocus);
_tabControl.PageLostFocus += new EventHandler(OnTabControlLostFocus);
_tabControl.SelectionChanged += new EventHandler(OnSelectionChanged);
_tabControl.PageDragStart += new MouseEventHandler(OnPageDragStart);
_tabControl.PageDragMove += new MouseEventHandler(OnPageDragMove);
_tabControl.PageDragEnd += new MouseEventHandler(OnPageDragEnd);
_tabControl.PageDragQuit += new MouseEventHandler(OnPageDragQuit);
_tabControl.DoubleClickTab += new Magic.Controls.TabControl.DoubleClickTabHandler(OnDoubleClickTab);
_tabControl.Font = manager.TabControlFont;
_tabControl.BackColor = manager.BackColor;
_tabControl.ForeColor = manager.InactiveTextColor;
// Define the visual style required
_tabControl.Style = vs;
// Allow developers a chance to override default settings
manager.OnTabControlCreated(_tabControl);
switch(vs)
{
case VisualStyle.IDE:
Controls.Add(_tabControl);
break;
case VisualStyle.Plain:
// Only the border at the pages edge and not around the whole control
_tabControl.InsetBorderPagesOnly = !_manager.PlainTabBorder;
// We want a border around the TabControl so it is indented and looks consistent
// with the Plain look and feel, so use the helper Control 'BorderForControl'
BorderForControl bfc = new BorderForControl(_tabControl, _plainBorder);
// It should always occupy the remaining space after all details
bfc.Dock = DockStyle.Fill;
// Define the default border border
bfc.BackColor = _manager.BackColor;
// When in 'VisualStyle.Plain' we need to
Controls.Add(bfc);
break;
}
// Need to hook into message pump so that the ESCAPE key can be
// intercepted when in redocking mode
Application.AddMessageFilter(this);
}
public Content CurrentContent
{
get
{
Magic.Controls.TabPage tp = _tabControl.SelectedTab;
if (tp != null)
return (Content)tp.Tag;
else
return null;
}
}
public Magic.Controls.TabControl TabControl
{
get { return _tabControl; }
}
public void HideCurrentContent()
{
Magic.Controls.TabPage tp = _tabControl.SelectedTab;
int count = _tabControl.TabPages.Count;
// Find currently selected tab
int index = _tabControl.SelectedIndex;
// Decide which other tab to make selected instead
if (count > 1)
{
// Move to the next control along
int newSelect = index + 1;
// Wrap around to first tab if at end
if (newSelect == count)
newSelect = 0;
// Change selection
_tabControl.SelectedIndex = newSelect;
}
else
{
// Hide myself as am about to die
this.Hide();
// Ensure the focus goes somewhere else
_manager.Container.Focus();
}
if (tp != null)
{
// Have the manager perform the Hide operation for us
_manager.HideContent(tp.Tag as Content);
}
}
public override void BringContentToFront(Content c)
{
// Find the matching Page and select it
foreach(Magic.Controls.TabPage page in _tabControl.TabPages)
if (page.Tag == c)
{
_tabControl.SelectedTab = page;
break;
}
}
public override void PropogateNameValue(PropogateName name, object value)
{
base.PropogateNameValue(name, value);
switch(name)
{
case PropogateName.BackColor:
Color newColor = (Color)value;
// In Plain style we need to color the intermidiate window as well
if (_style == VisualStyle.Plain)
{
BorderForControl bfc = this.Controls[0] as BorderForControl;
bfc.BackColor = newColor;
}
_tabControl.BackColor = newColor;
this.BackColor = newColor;
Invalidate();
break;
case PropogateName.InactiveTextColor:
_tabControl.ForeColor = (Color)value;
break;
case PropogateName.PlainTabBorder:
_tabControl.InsetBorderPagesOnly = !(bool)value;
break;
case PropogateName.TabControlFont:
_tabControl.Font = (Font)value;
break;
}
}
protected override void OnContentsClearing()
{
_tabControl.TabPages.Clear();
base.OnContentsClearing();
if (!this.AutoDispose)
{
// Inform each detail of the change in title text
NotifyFullTitleText("");
}
}
protected override void OnContentInserted(int index, object value)
{
base.OnContentInserted(index, value);
Content content = value as Content;
// Create TabPage to represent the Content
Magic.Controls.TabPage newPage = new Magic.Controls.TabPage();
// Reflect the Content properties int the TabPage
newPage.Title = content.Title;
newPage.ImageList = content.ImageList;
newPage.ImageIndex = content.ImageIndex;
newPage.Control = content.Control;
newPage.Tag = content;
// Reflect same order in TabPages collection as Content collection
_tabControl.TabPages.Insert(index, newPage);
}
protected override void OnContentRemoving(int index, object value)
{
base.OnContentRemoving(index, value);
Content c = value as Content;
// Find the matching Page and remove it
foreach(Magic.Controls.TabPage page in _tabControl.TabPages)
if (page.Tag == c)
{
_tabControl.TabPages.Remove(page);
break;
}
}
public override void WindowDetailGotFocus(WindowDetail wd)
{
// Transfer focus from WindowDetail to the TabControl
_tabControl.Focus();
}
protected void OnSelectionChanged(object sender, EventArgs e)
{
if (_tabControl.TabPages.Count == 0)
{
// Inform each detail of the change in title text
NotifyFullTitleText("");
}
else
{
// Inform each detail of the new title text
if (_tabControl.SelectedIndex != -1)
{
Content selectedContent = _tabControl.SelectedTab.Tag as Content;
NotifyAutoHideImage(selectedContent.AutoHidden);
NotifyCloseButton(selectedContent.CloseButton);
NotifyHideButton(selectedContent.HideButton);
NotifyFullTitleText(selectedContent.FullTitle);
NotifyShowCaptionBar(selectedContent.CaptionBar);
}
}
}
protected void OnTabControlGotFocus(object sender, EventArgs e)
{
NotifyContentGotFocus();
}
protected void OnTabControlLostFocus(object sender, EventArgs e)
{
NotifyContentLostFocus();
}
public void AddHotZones(Redocker redock, HotZoneCollection collection)
{
RedockerContent redocker = redock as RedockerContent;
bool itself = false;
bool nullZone = false;
// We process differently for WindowContent to redock into itself!
if ((redocker.WindowContent != null) && (redocker.WindowContent == this))
itself = true;
// We do not allow a Content to redock into its existing container
if (itself && !_contents.Contains(redocker.Content))
nullZone = true;
Rectangle newSize = this.RectangleToScreen(this.ClientRectangle);
Rectangle hotArea = _tabControl.RectangleToScreen(_tabControl.ClientRectangle);;
// Find any caption detail and use that area as the hot area
foreach(WindowDetail wd in _windowDetails)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -