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

📄 popupmenu.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.Drawing.Text;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
using Crownwood.Magic.Menus;
using Crownwood.Magic.Win32;
using Crownwood.Magic.Common;
using Crownwood.Magic.Controls;
using Crownwood.Magic.Collections;

namespace Crownwood.Magic.Menus
{
    [ToolboxItem(false)]
    [DefaultProperty("MenuCommands")]
    public class PopupMenu : NativeWindow
    {
        // Enumeration of Indexes into positioning constants array
        protected enum PI
        {
            BorderTop		= 0,
            BorderLeft		= 1,
            BorderBottom	= 2, 
            BorderRight		= 3,
            ImageGapTop		= 4,
            ImageGapLeft	= 5,
            ImageGapBottom	= 6,
            ImageGapRight	= 7,
            TextGapLeft		= 8,
            TextGapRight	= 9,
            SubMenuGapLeft	= 10,
            SubMenuWidth	= 11,
            SubMenuGapRight	= 12,
            SeparatorHeight	= 13,
            SeparatorWidth	= 14,
            ShortcutGap		= 15,
            ShadowWidth		= 16,
            ShadowHeight	= 17,
            ExtraWidthGap	= 18,
            ExtraHeightGap	= 19,
            ExtraRightGap	= 20,
            ExtraReduce		= 21
        }

        // Class constants for sizing/positioning each style
        protected static readonly int[,] _position = { 
                                                        {2, 1, 0, 1, 2, 3, 3, 5, 4, 4, 2, 6, 5, 5, 1, 10, 4, 4, 2, 2, 0, 0},	// IDE
                                                        {1, 0, 1, 2, 2, 1, 3, 4, 3, 3, 2, 8, 5, 5, 5, 10, 0, 0, 2, 2, 2, 5}		// Plain
                                                     };
        // Other class constants
        protected static int _selectionDelay = 400;
        protected static int _expansionDelay = 1100;
        protected static int _imageWidth = 16;
        protected static int _imageHeight = 16;
        protected static int _shadowLength = 4;
        protected static int _shadowHalf = 2;
        protected static int _blendSteps = 6;
        protected static Bitmap _shadowCache = null;
        protected static int _shadowCacheWidth = 0;
        protected static int _shadowCacheHeight = 0;
		
        // Class fields
        protected static ImageList _menuImages = null;
        protected static bool _supportsLayered = false;
		
        // Indexes into the menu images strip
        protected enum ImageIndex
        {
            Check			= 0,
            Radio			= 1,
            SubMenu			= 2,
            CheckSelected	= 3,
            RadioSelected	= 4,
            SubMenuSelected	= 5,
            Expansion		= 6,
            ImageError		= 7
        }

        // Operation of DrawShadowHorizontal
        protected enum Shadow
        {
            Left,
            Right,
            All
        }

        // Class constants that are marked as 'readonly' are allowed computed initialization
        protected readonly int WM_DISMISS = (int)Win32.Msgs.WM_USER + 1;
        protected readonly int WM_OPERATE_SUBMENU = (int)Win32.Msgs.WM_USER + 2;

        // Instance fields
        protected Timer _timer;
        protected Font _textFont;
        protected int _popupItem;
        protected int _trackItem;
        protected int _borderGap;
        protected int _returnDir;
        protected int _extraSize;
        protected int _excludeOffset;
		protected int _animateTime;
		protected bool _animateFirst;
		protected bool _animateIn;
        protected bool _layered;
        protected bool _exitLoop;
        protected bool _mouseOver;
        protected bool _popupDown;
        protected bool _popupRight;
        protected bool _excludeTop;
        protected bool _showInfrequent;
        protected bool _rememberExpansion;
        protected bool _highlightInfrequent;
        protected Color _backColor;
        protected Color _textColor;
        protected Color _highlightTextColor;
        protected Color _highlightColor;
        protected Color _highlightColorDark;
        protected Color _highlightColorLight;
        protected Color _highlightColorLightLight;
        protected Color _controlLL;
        protected Color _controlLLight;
        protected Size _currentSize;
        protected VisualStyle _style;
        protected Point _screenPos;
        protected Point _lastMousePos;
        protected Point _currentPoint;
        protected Point _leftScreenPos;
        protected Point _aboveScreenPos;
        protected Direction _direction;
        protected PopupMenu _parentMenu;
        protected PopupMenu _childMenu;
        protected SolidBrush _controlLBrush;
        protected SolidBrush _controlEBrush;
        protected SolidBrush _controlLLBrush;
        protected Animate _animate;
        protected Animate _animateTrack;
        protected Animation _animateStyle;
        protected ArrayList _drawCommands;
        protected MenuControl _parentControl;
        protected MenuCommand _returnCommand;
        protected MenuCommandCollection _menuCommands;

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

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

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

        public PopupMenu()
        {
            // Create collection objects
            _drawCommands = new ArrayList();
            _menuCommands = new MenuCommandCollection(); 

            // Default the properties
            _returnDir = 0;
            _extraSize = 0;
            _popupItem = -1;
            _trackItem = -1;
            _childMenu = null;
            _exitLoop = false;
            _popupDown = true;
            _mouseOver = false;
            _excludeTop = true;
            _popupRight = true;
            _parentMenu = null;
            _excludeOffset = 0;
            _parentControl = null;
            _returnCommand = null;
            _controlLBrush = null;
            _controlEBrush = null;
            _controlLLBrush = null;
            _highlightInfrequent = false;
            _showInfrequent = false;
            _style = VisualStyle.IDE;
            _rememberExpansion = true;
            _lastMousePos = new Point(-1,-1);
            _direction = Direction.Horizontal;
            _textFont = SystemInformation.MenuFont;

			// Animation details
            _animateTime = 100;
            _animate = Animate.System;
			_animateStyle = Animation.System;
			_animateFirst = true;
			_animateIn = true;

            // Create and initialise the timer object (but do not start it running!)
            _timer = new Timer();
            _timer.Interval = _selectionDelay;
            _timer.Tick += new EventHandler(OnTimerExpire);

            // Define default colors
            _textColor = SystemColors.MenuText;
            _highlightTextColor = SystemColors.HighlightText;
            DefineHighlightColors(SystemColors.Highlight);
            DefineColors(SystemColors.Control);
        }

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

        [Category("Appearance")]
        [DefaultValue(typeof(VisualStyle), "IDE")]
        public VisualStyle Style
        {
            get { return _style; }
            set { _style = value; }
        }

        [Category("Appearance")]
        public Font Font
        {
            get { return _textFont; }
            set { _textFont = value; }
        }

        [Category("Behaviour")]
        [DefaultValue(false)]
        public bool ShowInfrequent
        {
            get { return _showInfrequent; }
            set { _showInfrequent = value; }
        }

        [Category("Behaviour")]
        [DefaultValue(true)]
        public bool RememberExpansion
        {
            get { return _rememberExpansion; }
            set { _rememberExpansion = value; }
        }
        
        [Category("Behaviour")]
        [DefaultValue(true)]
        public bool HighlightInfrequent
        {
            get { return _highlightInfrequent; }
            set { _highlightInfrequent = value; }
        }

        [Category("Behaviour")]
        public Color BackColor
        {
            get { return _backColor; }
            set { DefineColors(value); }
        }
       
        [Category("Behaviour")]
        public Color TextColor
        {
            get { return _textColor; }
            set { _textColor = value; }
        }

        [Category("Behaviour")]
        public Color HighlightTextColor
        {
            get { return _highlightTextColor; }
            set { _highlightTextColor = value; }
        }

        [Category("Behaviour")]
        public Color HighlightColor
        {
            get { return _highlightColor; }
            set { DefineHighlightColors(value); }
        }

        [Category("Animate")]
        [DefaultValue(typeof(Animate), "System")]
        public Animate Animate
        {
            get { return _animate; }
            set { _animate = value; }
        }

        [Category("AnimateTime")]
        public int AnimateTime
        {
            get { return _animateTime; }
            set { _animateTime = value; }
        }

⌨️ 快捷键说明

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