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

📄 menucontrol.cs

📁 Magic Library 1.7,有说明文档
💻 CS
📖 第 1 页 / 共 5 页
字号:
// *****************************************************************************
// 
//  (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.IO;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.Drawing.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using Microsoft.Win32;
using Crownwood.Magic.Win32;
using Crownwood.Magic.Menus;
using Crownwood.Magic.Common;
using Crownwood.Magic.Controls;
using Crownwood.Magic.Collections;

namespace Crownwood.Magic.Menus
{
    [ToolboxBitmap(typeof(MenuControl))]
    [DefaultProperty("MenuCommands")]
    [DefaultEvent("PopupSelected")]
    [Designer(typeof(Crownwood.Magic.Menus.MenuControlDesigner))]
    public class MenuControl : ContainerControl, IMessageFilter
    {
        internal class MdiClientSubclass : NativeWindow
        {
            protected override void WndProc(ref Message m)
            {
                switch(m.Msg)
                {
                    case (int)Win32.Msgs.WM_MDISETMENU:
                    case (int)Win32.Msgs.WM_MDIREFRESHMENU:
                        return;
                }

                base.WndProc(ref m);
            }			
        }

        // Class constants
        protected const int _lengthGap = 3;
        protected const int _boxExpandUpper = 1;
        protected const int _boxExpandSides = 2;
        protected const int _shadowGap = 4;
        protected const int _shadowYOffset = 4;
        protected const int _separatorWidth = 15;
        protected const int _subMenuBorderAdjust = 2;
        protected const int _minIndex = 0;
        protected const int _restoreIndex = 1;
        protected const int _closeIndex = 2;
        protected const int _chevronIndex = 3;
        protected const int _buttonLength = 16;
        protected const int _chevronLength = 12;
        protected const int _pendantLength = 48;
        protected const int _pendantOffset = 3;

        // Class constant is marked as 'readonly' to allow non constant initialization
        protected readonly int WM_OPERATEMENU = (int)Win32.Msgs.WM_USER + 1;

        // Class fields
        protected static ImageList _menuImages = null;
        protected static bool _supportsLayered = false;

        // Instance fields
        protected int _rowWidth;
        protected int _rowHeight;
        protected int _trackItem;
        protected int _breadthGap;
        protected int _animateTime;
        protected IntPtr _oldFocus;
        protected Pen _controlLPen;
        protected bool _animateFirst;
        protected bool _selected;
        protected bool _multiLine;
        protected bool _mouseOver;
        protected bool _manualFocus;
        protected bool _drawUpwards;
		protected bool _defaultFont;
        protected bool _defaultBackColor;
        protected bool _defaultTextColor;
        protected bool _defaultHighlightBackColor;
        protected bool _defaultHighlightTextColor;
        protected bool _defaultSelectedBackColor;
        protected bool _defaultSelectedTextColor;
        protected bool _defaultPlainSelectedTextColor;
        protected bool _plainAsBlock;
        protected bool _dismissTransfer;
        protected bool _ignoreMouseMove;
        protected bool _expandAllTogether;
        protected bool _rememberExpansion;
        protected bool _deselectReset;
        protected bool _highlightInfrequent;
		protected bool _exitLoop;
        protected Color _textColor;
        protected Color _highlightBackColor;
        protected Color _useHighlightBackColor;
        protected Color _highlightTextColor;
        protected Color _highlightBackDark;
        protected Color _highlightBackLight;
        protected Color _selectedBackColor;
        protected Color _selectedTextColor;
        protected Color _plainSelectedTextColor;
        protected Form _activeChild;
        protected Form _mdiContainer;
        protected VisualStyle _style;
        protected Direction _direction;
        protected PopupMenu _popupMenu;
        protected ArrayList _drawCommands;
        protected SolidBrush _controlLBrush;
        protected SolidBrush _backBrush;
        protected Animate _animate;
        protected Animation _animateStyle;
        internal MdiClientSubclass _clientSubclass;
        protected MenuCommand _chevronStartCommand;
        protected MenuCommandCollection _menuCommands;

        // Instance fields - pendant buttons
        protected InertButton _minButton;
        protected InertButton _restoreButton;
        protected InertButton _closeButton;

        // Instance fields - events
        public event CommandHandler Selected;
        public event CommandHandler Deselected;

        static MenuControl()
        {
            // Create a strip of images by loading an embedded bitmap resource
            _menuImages = ResourceHelper.LoadBitmapStrip(Type.GetType("Crownwood.Magic.Menus.MenuControl"),
                                                         "Crownwood.Magic.Resources.ImagesMenuControl.bmp",
                                                         new Size(_buttonLength, _buttonLength),
                                                         new Point(0,0));

            // We need to know if the OS supports layered windows
            _supportsLayered = (OSFeature.Feature.GetVersionPresent(OSFeature.LayeredWindows) != null);
        }

        public MenuControl()
        {
            // Set default values
            _trackItem = -1;
            _oldFocus = IntPtr.Zero;
            _minButton = null;
            _popupMenu = null;
            _activeChild = null;
            _closeButton = null;
            _controlLPen = null;
            _mdiContainer = null;
            _restoreButton = null;
            _controlLBrush = null;
            _chevronStartCommand = null;
            _animateFirst = true;
			_exitLoop = false;
            _selected = false;
            _multiLine = false;
            _mouseOver = false;
			_defaultFont = true;
            _manualFocus = false;
            _drawUpwards = false;
            _plainAsBlock = false;
            _clientSubclass = null;
            _ignoreMouseMove = false;
            _deselectReset = true;
            _expandAllTogether = true;
            _rememberExpansion = true;
            _highlightInfrequent = true;
            _dismissTransfer = false;
            _style = VisualStyle.IDE;
            _direction = Direction.Horizontal;
            _menuCommands = new MenuCommandCollection();
            this.Dock = DockStyle.Top;
			this.Cursor = System.Windows.Forms.Cursors.Arrow;
			
            // Animation details
            _animateTime = 100;
            _animate = Animate.System;
            _animateStyle = Animation.System;

            // Prevent flicker with double buffering and all painting inside WM_PAINT
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            // Should not be allowed to select this control
            SetStyle(ControlStyles.Selectable, false);

            // Hookup to collection events
            _menuCommands.Cleared += new CollectionClear(OnCollectionCleared);
            _menuCommands.Inserted += new CollectionChange(OnCollectionInserted);
            _menuCommands.Removed += new CollectionChange(OnCollectionRemoved);

			// Need notification when the MenuFont is changed
			Microsoft.Win32.SystemEvents.UserPreferenceChanged += 
			    new UserPreferenceChangedEventHandler(OnPreferenceChanged);

            DefineColors();
            
            // Set the starting Font
            DefineFont(SystemInformation.MenuFont);

            // Do not allow tab key to select this control
            this.TabStop = false;

            // Default to one line of items
            this.Height = _rowHeight;

            // Add ourself to the application filtering list
            Application.AddMessageFilter(this);
        }

        protected override void Dispose(bool disposing)
        {
            if( disposing )
            {
                // Remove notifications
                Microsoft.Win32.SystemEvents.UserPreferenceChanged -= 
                    new UserPreferenceChangedEventHandler(OnPreferenceChanged);
            }
            base.Dispose( disposing );
        }

        [Category("Behaviour")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public MenuCommandCollection MenuCommands
        {
            get { return _menuCommands; }
        } 

        [Category("Appearance")]
        public VisualStyle Style
        {
            get { return _style; }
			
            set
            {
                if (_style != value)
                {
                    _style = value;

                    Recalculate();
                    Invalidate();
                }
            }
        }

        public override Font Font
        {
            get { return base.Font; }
			
            set
            {
				if (value != base.Font)
				{
					_defaultFont = (value == SystemInformation.MenuFont);

					DefineFont(value);

					Recalculate();
					Invalidate();
				}
            }
        }

		public override Color BackColor
		{
			get { return base.BackColor; }

			set
			{
				if (value != base.BackColor)
				{
					_defaultBackColor = (value == SystemColors.Control);
                    base.BackColor = value;
                    _backBrush = new SolidBrush(base.BackColor);
                    
					Recalculate();
					Invalidate();
				}
			}
		}

        private bool ShouldSerializeBackColor()
        {
            return this.BackColor != SystemColors.Control;
        }

        [Category("Appearance")]
        public Color TextColor
        {
            get { return _textColor; }

            set
            {
                if (value != _textColor)
                {
                    _textColor = value;
                    _defaultTextColor = (value == SystemColors.MenuText);

                    Recalculate();
                    Invalidate();
                }
            }
        }

        private bool ShouldSerializeTextColor()
        {
            return _textColor != SystemColors.MenuText;
        }

        [Category("Appearance")]
        public Color HighlightBackColor
        {
            get { return _highlightBackColor; }

            set
            {
                if (value != _highlightBackColor)
                {
                    _defaultHighlightBackColor = (value == SystemColors.Highlight);
                    DefineHighlightBackColors(value);                    

                    Recalculate();
                    Invalidate();
                }
            }
        }

        private bool ShouldSerializeHighlightBackColor()
        {
            return _highlightBackColor != SystemColors.Highlight;
        }

        [Category("Appearance")]
        public Color HighlightTextColor
        {
            get { return _highlightTextColor; }

            set
            {

⌨️ 快捷键说明

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