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

📄 windowdetailcaption.cs

📁 Magic Library 1.7,有说明文档
💻 CS
📖 第 1 页 / 共 4 页
字号:
// *****************************************************************************
// 
//  (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 System.Drawing.Imaging;
using Microsoft.Win32;
using Crownwood.Magic.Common;
using Crownwood.Magic.Controls;

namespace Crownwood.Magic.Docking
{
    [ToolboxItem(false)]
    public class WindowDetailCaption : WindowDetail, IMessageFilter
    {
        // Class fields
        protected static ImageList _images;

        // Instance events
        public event EventHandler Close;
		public event EventHandler Restore;
		public event EventHandler InvertAutoHide;
        public event ContextHandler Context;

        // Instance fields
        protected InertButton _maxButton;
        protected InertButton _closeButton;
        protected InertButton _hideButton;
        protected RedockerContent _redocker;
        protected IZoneMaximizeWindow _maxInterface;
        protected bool _showCloseButton;
        protected bool _showHideButton;
        protected bool _ignoreHideButton;
        protected bool _pinnedImage;

        // Class fields
        protected static ImageAttributes _activeAttr = new ImageAttributes();
        protected static ImageAttributes _inactiveAttr = new ImageAttributes();

        public WindowDetailCaption(DockingManager manager, 
                                   Size fixedSize, 
                                   EventHandler closeHandler, 
                                   EventHandler restoreHandler, 
                                   EventHandler invertAutoHideHandler, 
                                   ContextHandler contextHandler)
            : base(manager)
        {
            // Setup correct color remapping depending on initial colors
            DefineButtonRemapping();

            // Default state
            _maxButton = null;
            _hideButton = null;
            _maxInterface = null;
            _redocker = null;
            _showCloseButton = true;
            _showHideButton = true;
            _ignoreHideButton = false;
            _pinnedImage = false;
            
            // Prevent flicker with double buffering and all painting inside WM_PAINT
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            // Our size is always fixed at the required length in both directions
            // as one of the sizes will be provided for us because of our docking
            this.Size = fixedSize;

            if (closeHandler != null)
                this.Close += closeHandler;	

            if (restoreHandler != null)
                this.Restore += restoreHandler;	

            if (invertAutoHideHandler != null)
                this.InvertAutoHide += invertAutoHideHandler;
    
            if (contextHandler != null)
                this.Context += contextHandler;	

            // Let derived classes override the button creation
            CreateButtons();

            // Need to hook into message pump so that the ESCAPE key can be 
            // intercepted when in redocking mode
            Application.AddMessageFilter(this);
        }

        public override Zone ParentZone
        {
            set
            {
                base.ParentZone = value;

                RecalculateMaximizeButton();
                RecalculateButtons();
            }
        }

        public virtual void OnClose()
        {
            // Any attached event handlers?
            if (Close != null)
                Close(this, EventArgs.Empty);
        }

        public virtual void OnInvertAutoHide()
        {
            // Any attached event handlers?
            if (InvertAutoHide != null)
                InvertAutoHide(this, EventArgs.Empty);
        }
        
        public virtual void OnRestore()
        {
            // Any attached event handlers?
            if (Restore != null)
                Restore(this, EventArgs.Empty);
        }

        public virtual void OnContext(Point screenPos)
        {
            // Any attached event handlers?
            if (Context != null)
                Context(screenPos);
        }

        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
				if (_closeButton != null)
				{
					_closeButton.Click -= new EventHandler(OnButtonClose);
					_closeButton.GotFocus -= new EventHandler(OnButtonGotFocus);
				}

                if (_hideButton != null)
                {
                    _hideButton.Click -= new EventHandler(OnButtonHide);
                    _hideButton.GotFocus -= new EventHandler(OnButtonGotFocus);
                }
                
                if (_maxButton != null)
				{
					_maxButton.Click -= new EventHandler(OnButtonMax);
					_maxButton.GotFocus -= new EventHandler(OnButtonGotFocus);
				}
            }
            base.Dispose( disposing );
        }

        public override void NotifyAutoHideImage(bool autoHidden)
        {
            _pinnedImage = autoHidden;
            UpdateAutoHideImage();
        }

        public override void NotifyCloseButton(bool show)
        {
            _showCloseButton = show;
            RecalculateButtons();
        }

        public override void NotifyHideButton(bool show)
        {
            // Ignore the AutoHide feature when in floating form
            _ignoreHideButton = (_parentWindow.State == State.Floating);
            
            _showHideButton = show;
            RecalculateButtons();
        }

        public override void NotifyShowCaptionBar(bool show)
        {
            this.Visible = show;
        }
        
        protected void RecalculateMaximizeButton()
        {
            // Are we inside a Zone?
            if (this.ParentZone != null)
            {
                // Does the Zone support the maximizing of a Window?
                IZoneMaximizeWindow zmw = this.ParentZone as IZoneMaximizeWindow;

                if (zmw != null)
                {
                    AddMaximizeInterface(zmw);
                    return;
                }
            }

            RemoveMaximizeInterface();
        }

        protected void AddMaximizeInterface(IZoneMaximizeWindow zmw)
        {
            // Has the maximize button already been created?
            if (_maxInterface == null)
            {
                // Create the InertButton
                _maxButton = new InertButton(_images, 0);

                // Hook into button events
                _maxButton.Click += new EventHandler(OnButtonMax);
                _maxButton.GotFocus += new EventHandler(OnButtonGotFocus);

                // Define the default remapping
                _maxButton.ImageAttributes = _inactiveAttr;

                OnAddMaximizeInterface();

                Controls.Add(_maxButton);

                // Remember the interface reference
                _maxInterface = zmw;

                // Hook into the interface change events
                _maxInterface.RefreshMaximize += new EventHandler(OnRefreshMaximize);

                RecalculateButtons();
            }
        }

        protected void RemoveMaximizeInterface()
        {
            if (_maxInterface != null)
            {
                // Unhook from the interface change events
                _maxInterface.RefreshMaximize -= new EventHandler(OnRefreshMaximize);

                // Remove the interface reference
                _maxInterface = null;

				// Use helper method to circumvent form Close bug
				ControlHelper.Remove(this.Controls, _maxButton);

                OnRemoveMaximizeInterface();

                // Unhook into button events
                _maxButton.Click -= new EventHandler(OnButtonMax);
                _maxButton.GotFocus -= new EventHandler(OnButtonGotFocus);

                // Kill the button which is no longer needed
                _maxButton.Dispose();
                _maxButton = null;

                RecalculateButtons();
            }
        }

        protected void OnRefreshMaximize(object sender, EventArgs e)
        {
            UpdateMaximizeImage();
        }
	
        protected void OnButtonMax(object sender, EventArgs e)
        {
            if (this.ParentWindow != null)
            {
                if (_maxInterface.IsMaximizeAvailable())
                {
                    // Are we already maximized?
                    if (_maxInterface.IsWindowMaximized(this.ParentWindow))
                        _maxInterface.RestoreWindow();
                    else
                        _maxInterface.MaximizeWindow(this.ParentWindow);
                }
            }			
        }

        protected void OnButtonClose(Object sender, EventArgs e)
        {
            if (_showCloseButton)
                OnClose();
        }

        protected void OnButtonHide(Object sender, EventArgs e)
        {
            // Plain button can still be pressed when disabled, so double check 
            // that an event should actually be generated
            if (_showHideButton && !_ignoreHideButton)
                OnInvertAutoHide();
        }

        protected void OnButtonGotFocus(Object sender, EventArgs e)
        {
            // Inform parent window we have now got the focus
            if (this.ParentWindow != null)
                this.ParentWindow.WindowDetailGotFocus(this);
        }

		protected override void OnDoubleClick(EventArgs e)
		{
            // The double click event will cause the control to be destroyed as 
            // the Contents are restored to their alternative positions, so need to
            // double check the control is not already dead
            if (!IsDisposed)
            {
                // Are we currently in a redocking state?
                if (_redocker != null)
                {
                    // No longer need the object
                    _redocker = null;
                }
            }

			// Fire attached event handlers
			OnRestore();
		}

        protected override void OnMouseDown(MouseEventArgs e)
        {
            // The double click event will cause the control to be destroyed as 
            // the Contents are restored to their alternative positions, so need to
            // double check the control is not already dead

⌨️ 快捷键说明

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