mdiclientcontroller.cs
来自「Fireball.CodeEditor is an source code ed」· CS 代码 · 共 578 行 · 第 1/2 页
CS
578 行
#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.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Runtime.InteropServices;
namespace Fireball.Docking
{
// This class comes from Jacob Slusser's MdiClientController class.
// It has been modified to the coding standards.
[ToolboxBitmap(typeof(MdiClientController), "Resources.MdiClientController.bmp")]
internal class MdiClientController : NativeWindow, IComponent, IDisposable
{
private bool m_autoScroll = true;
private Color m_backColor = SystemColors.AppWorkspace;
private BorderStyle m_borderStyle = BorderStyle.Fixed3D;
private MdiClient m_mdiClient = null;
private Image m_image = null;
private ContentAlignment m_imageAlign = ContentAlignment.MiddleCenter;
private Form m_parentForm = null;
private ISite m_site = null;
private bool m_stretchImage = false;
public MdiClientController() : this(null)
{
}
public MdiClientController(Form parentForm)
{
ParentForm = parentForm;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if(disposing)
{
lock(this)
{
if(Site != null && Site.Container != null)
Site.Container.Remove(this);
if(Disposed != null)
Disposed(this, EventArgs.Empty);
}
}
}
[DefaultValue(true), Category("Layout")]
[LocalizedDescription("MdiClientController.AutoScroll.Description")]
public bool AutoScroll
{
get { return m_autoScroll; }
set
{
// By default the MdiClient control scrolls. It can appear though that
// there are no scrollbars by turning them off when the non-client
// area is calculated. I decided to expose this method following
// the .NET vernacular of an AutoScroll property.
m_autoScroll = value;
if(MdiClient != null)
UpdateStyles();
}
}
[DefaultValue(typeof(Color), "AppWorkspace")]
[Category("Appearance")]
[LocalizedDescription("MdiClientController.BackColor.Description")]
public Color BackColor
{
// Use the BackColor property of the MdiClient control. This is one of
// the few properties in the MdiClient class that actually works.
get
{
if(MdiClient != null)
return MdiClient.BackColor;
return m_backColor;
}
set
{
m_backColor = value;
if(MdiClient != null)
MdiClient.BackColor = value;
}
}
[DefaultValue(BorderStyle.Fixed3D)]
[Category("Appearance")]
[LocalizedDescription("MdiClientController.BorderStyle.Description")]
public BorderStyle BorderStyle
{
get { return m_borderStyle; }
set
{
// Error-check the enum.
if(!Enum.IsDefined(typeof(BorderStyle), value))
throw new InvalidEnumArgumentException();
m_borderStyle = value;
if(MdiClient == null)
return;
// This property can actually be visible in design-mode,
// but to keep it consistent with the others,
// prevent this from being show at design-time.
if(Site != null && Site.DesignMode)
return;
// There is no BorderStyle property exposed by the MdiClient class,
// but this can be controlled by Win32 functions. A Win32 ExStyle
// of WS_EX_CLIENTEDGE is equivalent to a Fixed3D border and a
// Style of WS_BORDER is equivalent to a FixedSingle border.
// This code is inspired Jason Dori's article:
// "Adding designable borders to user controls".
// http://www.codeproject.com/cs/miscctrl/CsAddingBorders.asp
// Get styles using Win32 calls
int style = User32.GetWindowLong(MdiClient.Handle, (int)Win32.GetWindowLongIndex.GWL_STYLE);
int exStyle = User32.GetWindowLong(MdiClient.Handle, (int)Win32.GetWindowLongIndex.GWL_EXSTYLE);
// Add or remove style flags as necessary.
switch(m_borderStyle)
{
case BorderStyle.Fixed3D:
exStyle |= (int)Win32.WindowExStyles.WS_EX_CLIENTEDGE;
style &= ~((int)Win32.WindowStyles.WS_BORDER);
break;
case BorderStyle.FixedSingle:
exStyle &= ~((int)Win32.WindowExStyles.WS_EX_CLIENTEDGE);
style |= (int)Win32.WindowStyles.WS_BORDER;
break;
case BorderStyle.None:
style &= ~((int)Win32.WindowStyles.WS_BORDER);
exStyle &= ~((int)Win32.WindowExStyles.WS_EX_CLIENTEDGE);
break;
}
// Set the styles using Win32 calls
User32.SetWindowLong(MdiClient.Handle, (int)Win32.GetWindowLongIndex.GWL_STYLE, style);
User32.SetWindowLong(MdiClient.Handle, (int)Win32.GetWindowLongIndex.GWL_EXSTYLE, exStyle);
// Cause an update of the non-client area.
UpdateStyles();
}
}
[Browsable(false)]
public MdiClient MdiClient
{
get { return m_mdiClient; }
}
[Browsable(false)]
public new IntPtr Handle
{
// Hide this property during design-time.
get { return base.Handle; }
}
[DefaultValue(null)]
[Category("Appearance")]
[LocalizedDescription("MdiClientController.Image.Description")]
public Image Image
{
get { return m_image; }
set
{
m_image = value;
if(MdiClient != null)
MdiClient.Invalidate();
}
}
[DefaultValue(ContentAlignment.MiddleCenter)]
[Category("Appearance")]
[LocalizedDescription("MdiClientController.ImageAlign.Description")]
public ContentAlignment ImageAlign
{
get { return m_imageAlign; }
set
{
// Error-check the enum.
if(!Enum.IsDefined(typeof(ContentAlignment), value))
throw new InvalidEnumArgumentException();
m_imageAlign = value;
if(MdiClient != null)
MdiClient.Invalidate();
}
}
[Browsable(false)]
public Form ParentForm
{
get { return m_parentForm; }
set
{
// If the ParentForm has previously been set,
// unwire events connected to the old parent.
if(m_parentForm != null)
{
m_parentForm.HandleCreated -= new EventHandler(ParentFormHandleCreated);
m_parentForm.MdiChildActivate -= new EventHandler(ParentFormMdiChildActivate);
}
m_parentForm = value;
if(m_parentForm == null)
return;
// If the parent form has not been created yet,
// wait to initialize the MDI client until it is.
if(m_parentForm.IsHandleCreated)
{
InitializeMdiClient();
RefreshProperties();
}
else
m_parentForm.HandleCreated += new EventHandler(ParentFormHandleCreated);
m_parentForm.MdiChildActivate += new EventHandler(ParentFormMdiChildActivate);
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public ISite Site
{
get { return m_site; }
set
{
m_site = value;
if(m_site == null)
return;
// If the component is dropped onto a form during design-time,
// set the ParentForm property.
IDesignerHost host = (value.GetService(typeof(IDesignerHost)) as IDesignerHost);
if(host != null)
{
Form parent = host.RootComponent as Form;
if(parent != null)
ParentForm = parent;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?