⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dockindicator.cs

📁 Fireball.CodeEditor is an source code editor control derived from the best compona SyntaxBox Control
💻 CS
📖 第 1 页 / 共 2 页
字号:
#region Fireball License
//    Copyright (C) 2005  Sebastian Faltoni sebastian{at}dotnetfireball{dot}net
//
//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License as published by the Free Software Foundation; either
//    version 2.1 of the License, or (at your option) any later version.
//
//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public
//    License along with this library; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#endregion
#region Original License
// *****************************************************************************
// 
//  Copyright 2004, Weifen Luo
//  All rights reserved. The software and associated documentation 
//  supplied hereunder are the proprietary information of Weifen Luo
//  and are supplied subject to licence terms.
// 
//  WinFormsUI Library Version 1.0
// *****************************************************************************
#endregion

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;

namespace Fireball.Docking
{
	internal class DockIndicator : DragForm
	{
		#region IHitTest
		private interface IHitTest
		{
			DockStyle HitTest(Point pt);
			DockStyle Status	{	get;	set;	}
		}
		#endregion

		#region PanelIndicator
		private class PanelIndicator : PictureBox, IHitTest
		{
			private const string _ResourceImagePanelLeft = "DockIndicator.PanelLeft.bmp";
			private const string _ResourceImagePanelLeftActive = "DockIndicator.PanelLeft.Active.bmp";
			private const string _ResourceImagePanelRight = "DockIndicator.PanelRight.bmp";
			private const string _ResourceImagePanelRightActive = "DockIndicator.PanelRight.Active.bmp";
			private const string _ResourceImagePanelTop = "DockIndicator.PanelTop.bmp";
			private const string _ResourceImagePanelTopActive = "DockIndicator.PanelTop.Active.bmp";
			private const string _ResourceImagePanelBottom = "DockIndicator.PanelBottom.bmp";
			private const string _ResourceImagePanelBottomActive = "DockIndicator.PanelBottom.Active.bmp";
			private const string _ResourceImagePanelFill = "DockIndicator.PanelFill.bmp";
			private const string _ResourceImagePanelFillActive = "DockIndicator.PanelFill.Active.bmp";

			private static Image _imagePanelLeft;
			private static Image _imagePanelRight;
			private static Image _imagePanelTop;
			private static Image _imagePanelBottom;
			private static Image _imagePanelFill;
			private static Image _imagePanelLeftActive = null;
			private static Image _imagePanelRightActive = null;
			private static Image _imagePanelTopActive = null;
			private static Image _imagePanelBottomActive = null;
			private static Image _imagePanelFillActive = null;

			static PanelIndicator()
			{
				_imagePanelLeft = ResourceHelper.LoadBitmap(_ResourceImagePanelLeft);
				_imagePanelRight = ResourceHelper.LoadBitmap(_ResourceImagePanelRight);
				_imagePanelTop = ResourceHelper.LoadBitmap(_ResourceImagePanelTop);
				_imagePanelBottom = ResourceHelper.LoadBitmap(_ResourceImagePanelBottom);
				_imagePanelFill= ResourceHelper.LoadBitmap(_ResourceImagePanelFill);
				_imagePanelLeftActive = ResourceHelper.LoadBitmap(_ResourceImagePanelLeftActive);
				_imagePanelRightActive = ResourceHelper.LoadBitmap(_ResourceImagePanelRightActive);
				_imagePanelTopActive = ResourceHelper.LoadBitmap(_ResourceImagePanelTopActive);
				_imagePanelBottomActive = ResourceHelper.LoadBitmap(_ResourceImagePanelBottomActive);
				_imagePanelFillActive = ResourceHelper.LoadBitmap(_ResourceImagePanelFillActive);
			}

			public PanelIndicator(DockStyle dockStyle)
			{
				m_dockStyle = dockStyle;
				SizeMode = PictureBoxSizeMode.AutoSize;
				Image = ImageInactive;
			}

			private DockStyle m_dockStyle;
			private DockStyle DockStyle
			{
				get	{	return m_dockStyle;	}
			}

			private DockStyle m_status;
			public DockStyle Status
			{
				get	{	return m_status;	}
				set
				{
					if (value != DockStyle && value != DockStyle.None)
						throw new InvalidEnumArgumentException();

					if (m_status == value)
						return;

					m_status = value;
					IsActivated = (m_status != DockStyle.None);
				}
			}

			private Image ImageInactive
			{
				get
				{	
					if (DockStyle == DockStyle.Left)
						return _imagePanelLeft;
					else if (DockStyle == DockStyle.Right)
						return _imagePanelRight;
					else if (DockStyle == DockStyle.Top)
						return _imagePanelTop;
					else if (DockStyle == DockStyle.Bottom)
						return _imagePanelBottom;
					else if (DockStyle == DockStyle.Fill)
						return _imagePanelFill;
					else
						return null;
				}
			}

			private Image ImageActive
			{
				get
				{
					if (DockStyle == DockStyle.Left)
						return _imagePanelLeftActive;
					else if (DockStyle == DockStyle.Right)
						return _imagePanelRightActive;
					else if (DockStyle == DockStyle.Top)
						return _imagePanelTopActive;
					else if (DockStyle == DockStyle.Bottom)
						return _imagePanelBottomActive;
					else if (DockStyle == DockStyle.Fill)
						return _imagePanelFillActive;
					else
						return null;
				}
			}

			private bool m_isActivated = false;
			private bool IsActivated
			{
				get	{	return m_isActivated;	}
				set
				{	
					m_isActivated = value;
					Image = IsActivated ? ImageActive : ImageInactive;
				}
			}

			public DockStyle HitTest(Point pt)
			{
				return ClientRectangle.Contains(PointToClient(pt)) ? DockStyle : DockStyle.None;
			}
		}
		#endregion PanelIndicator

		#region PaneIndicator
		private class PaneIndicator : PictureBox, IHitTest
		{
			private struct HotSpotIndex
			{
				public HotSpotIndex(int x, int y, DockStyle dockStyle)
				{
					m_x = x;
					m_y = y;
					m_dockStyle = dockStyle;
				}

				private int m_x;
				public int X
				{
					get	{	return m_x;	}
				}

				private int m_y;
				public int Y
				{
					get	{	return m_y;	}
				}

				private DockStyle m_dockStyle;
				public DockStyle DockStyle
				{
					get	{	return m_dockStyle;	}
				}
			}

			private const string _ResourceBitmapPaneDiamond = "DockIndicator.PaneDiamond.bmp";
			private const string _ResourceBitmapPaneDiamondLeft = "DockIndicator.PaneDiamond.Left.bmp";
			private const string _ResourceBitmapPaneDiamondRight = "DockIndicator.PaneDiamond.Right.bmp";
			private const string _ResourceBitmapPaneDiamondTop = "DockIndicator.PaneDiamond.Top.bmp";
			private const string _ResourceBitmapPaneDiamondBottom = "DockIndicator.PaneDiamond.Bottom.bmp";
			private const string _ResourceBitmapPaneDiamondFill = "DockIndicator.PaneDiamond.Fill.bmp";
			private const string _ResourceBitmapPaneDiamondHotSpot = "DockIndicator.PaneDiamond.HotSpot.bmp";
			private const string _ResourceBitmapPaneDiamondHotSpotIndex = "DockIndicator.PaneDiamond.HotSpotIndex.bmp";

			private static Bitmap _bitmapPaneDiamond;
			private static Bitmap _bitmapPaneDiamondLeft;
			private static Bitmap _bitmapPaneDiamondRight;
			private static Bitmap _bitmapPaneDiamondTop;
			private static Bitmap _bitmapPaneDiamondBottom;
			private static Bitmap _bitmapPaneDiamondFill;
			private static Bitmap _bitmapPaneDiamondHotSpot;
			private static Bitmap _bitmapPaneDiamondHotSpotIndex;
			private static HotSpotIndex[] _hotSpots;
			private static GraphicsPath _displayingGraphicsPath;

			static PaneIndicator()
			{
				_bitmapPaneDiamond = ResourceHelper.LoadBitmap(_ResourceBitmapPaneDiamond);
				_bitmapPaneDiamondLeft = ResourceHelper.LoadBitmap(_ResourceBitmapPaneDiamondLeft);
				_bitmapPaneDiamondRight = ResourceHelper.LoadBitmap(_ResourceBitmapPaneDiamondRight);
				_bitmapPaneDiamondTop = ResourceHelper.LoadBitmap(_ResourceBitmapPaneDiamondTop);
				_bitmapPaneDiamondBottom = ResourceHelper.LoadBitmap(_ResourceBitmapPaneDiamondBottom);
				_bitmapPaneDiamondFill = ResourceHelper.LoadBitmap(_ResourceBitmapPaneDiamondFill);
				_bitmapPaneDiamondHotSpot = ResourceHelper.LoadBitmap(_ResourceBitmapPaneDiamondHotSpot);
				_bitmapPaneDiamondHotSpotIndex = ResourceHelper.LoadBitmap(_ResourceBitmapPaneDiamondHotSpotIndex);
				_hotSpots = new HotSpotIndex[]
					{
						new HotSpotIndex(1, 0, DockStyle.Top),
						new HotSpotIndex(0, 1, DockStyle.Left),
						new HotSpotIndex(1, 1, DockStyle.Fill),
						new HotSpotIndex(2, 1, DockStyle.Right),
						new HotSpotIndex(1, 2, DockStyle.Bottom)
					};
				_displayingGraphicsPath = DrawHelper.CalculateGraphicsPathFromBitmap(_bitmapPaneDiamond);
			}

			public PaneIndicator()
			{
				SizeMode = PictureBoxSizeMode.AutoSize;
				Image = _bitmapPaneDiamond;
				Region = new Region(DisplayingGraphicsPath);
			}

			public GraphicsPath DisplayingGraphicsPath
			{
				get	{	return _displayingGraphicsPath;	}
			}

			public DockStyle HitTest(Point pt)
			{
				pt = PointToClient(pt);
				if (!ClientRectangle.Contains(pt))
					return DockStyle.None;

				for (int i=_hotSpots.GetLowerBound(0); i<=_hotSpots.GetUpperBound(0); i++)
				{
					if (_bitmapPaneDiamondHotSpot.GetPixel(pt.X, pt.Y) == _bitmapPaneDiamondHotSpotIndex.GetPixel(_hotSpots[i].X, _hotSpots[i].Y))
						return _hotSpots[i].DockStyle;
				}

				return DockStyle.None;
			}

			private DockStyle m_status = DockStyle.None;
			public DockStyle Status
			{
				get	{	return m_status;	}
				set
				{
					m_status = value;
					if (m_status == DockStyle.None)
						Image = _bitmapPaneDiamond;
					else if (m_status == DockStyle.Left)
						Image = _bitmapPaneDiamondLeft;
					else if (m_status == DockStyle.Right)
						Image = _bitmapPaneDiamondRight;
					else if (m_status == DockStyle.Top)
						Image = _bitmapPaneDiamondTop;
					else if (m_status == DockStyle.Bottom)
						Image = _bitmapPaneDiamondBottom;
					else if (m_status == DockStyle.Fill)
						Image = _bitmapPaneDiamondFill;
				}
			}
		}
		#endregion PaneIndicator

		#region consts
		private int _PanelIndicatorMargin = 10;
		#endregion

		public DockIndicator(DragHandler dragHandler)
		{
			m_dragHandler = dragHandler;
			Controls.AddRange(new Control[]
				{
					PaneDiamond,
					PanelLeft,
					PanelRight,
					PanelTop,
					PanelBottom,
					PanelFill
				});
			Bounds = GetAllScreenBounds();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -