ViewMenu.cs :  » GUI » Paint.net » PaintDotNet » Menus » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » Paint.net 
Paint.net » PaintDotNet » Menus » ViewMenu.cs
/////////////////////////////////////////////////////////////////////////////////
// Paint.NET                                                                   //
// Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors.     //
// Portions Copyright (C) Microsoft Corporation. All Rights Reserved.          //
// See src/Resources/Files/License.txt for full licensing and attribution      //
// details.                                                                    //
// .                                                                           //
/////////////////////////////////////////////////////////////////////////////////

using PaintDotNet.Actions;
using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace PaintDotNet.Menus{
    internal sealed class ViewMenu
        : PdnMenuItem
    {
        private PdnMenuItem menuViewZoomIn;
        private PdnMenuItem menuViewZoomOut;
        private PdnMenuItem menuViewZoomToWindow;
        private PdnMenuItem menuViewZoomToSelection;
        private PdnMenuItem menuViewActualSize;
        private ToolStripSeparator menuViewSeparator1;
        private PdnMenuItem menuViewGrid;
        private PdnMenuItem menuViewRulers;
        private ToolStripSeparator menuViewSeparator2;
        private PdnMenuItem menuViewPixels;
        private PdnMenuItem menuViewInches;
        private PdnMenuItem menuViewCentimeters;

        private bool OnOemPlusShortcut(Keys keys)
        {
            this.menuViewZoomIn.PerformClick();
            return true;
        }

        private bool OnOemMinusShortcut(Keys keys)
        {
            this.menuViewZoomOut.PerformClick();
            return true;
        }

        private bool OnCtrlAltZero(Keys keys)
        {
            this.menuViewActualSize.PerformClick();
            return true;
        }

        public ViewMenu()
        {
            InitializeComponent();
            PdnBaseForm.RegisterFormHotKey(Keys.Control | Keys.OemMinus, OnOemMinusShortcut);
            PdnBaseForm.RegisterFormHotKey(Keys.Control | Keys.Oemplus, OnOemPlusShortcut);
            PdnBaseForm.RegisterFormHotKey(Keys.Control | Keys.Alt | Keys.D0, OnCtrlAltZero);
        }

        private void InitializeComponent()
        {
            this.menuViewZoomIn = new PdnMenuItem();
            this.menuViewZoomOut = new PdnMenuItem();
            this.menuViewZoomToWindow = new PdnMenuItem();
            this.menuViewZoomToSelection = new PdnMenuItem();
            this.menuViewActualSize = new PdnMenuItem();
            this.menuViewSeparator1 = new ToolStripSeparator();
            this.menuViewGrid = new PdnMenuItem();
            this.menuViewRulers = new PdnMenuItem();
            this.menuViewSeparator2 = new ToolStripSeparator();
            this.menuViewPixels = new PdnMenuItem();
            this.menuViewInches = new PdnMenuItem();
            this.menuViewCentimeters = new PdnMenuItem();
            // 
            // menuView
            // 
            this.DropDownItems.AddRange(
                new System.Windows.Forms.ToolStripItem[] 
                {
                    this.menuViewZoomIn,
                    this.menuViewZoomOut,
                    this.menuViewZoomToWindow,
                    this.menuViewZoomToSelection,
                    this.menuViewActualSize,
                    this.menuViewSeparator1,
                    this.menuViewGrid,
                    this.menuViewRulers,
                    this.menuViewSeparator2,
                    this.menuViewPixels,
                    this.menuViewInches,
                    this.menuViewCentimeters,
                });
            this.Name = "Menu.View";
            this.Text = PdnResources.GetString("Menu.View.Text"); 
            // 
            // menuViewZoomIn
            // 
            this.menuViewZoomIn.Name = "ZoomIn";
            this.menuViewZoomIn.ShortcutKeys = Keys.Control | Keys.Add;
            this.menuViewZoomIn.ShortcutKeyDisplayString = PdnResources.GetString("Menu.View.ZoomIn.ShortcutKeyDisplayString");
            this.menuViewZoomIn.Click += new System.EventHandler(this.MenuViewZoomIn_Click);
            // 
            // menuViewZoomOut
            // 
            this.menuViewZoomOut.Name = "ZoomOut";
            this.menuViewZoomOut.ShortcutKeys = Keys.Control | Keys.Subtract;
            this.menuViewZoomOut.ShortcutKeyDisplayString = PdnResources.GetString("Menu.View.ZoomOut.ShortcutKeyDisplayString");
            this.menuViewZoomOut.Click += new System.EventHandler(this.MenuViewZoomOut_Click);
            // 
            // menuViewZoomToWindow
            // 
            this.menuViewZoomToWindow.Name = "ZoomToWindow";
            this.menuViewZoomToWindow.ShortcutKeys = Keys.Control | Keys.B;
            this.menuViewZoomToWindow.Click += new System.EventHandler(this.MenuViewZoomToWindow_Click);
            // 
            // menuViewZoomToSelection
            // 
            this.menuViewZoomToSelection.Name = "ZoomToSelection";
            this.menuViewZoomToSelection.ShortcutKeys = Keys.Control | Keys.Shift | Keys.B;
            this.menuViewZoomToSelection.Click += new System.EventHandler(this.MenuViewZoomToSelection_Click);
            // 
            // menuViewActualSize
            // 
            this.menuViewActualSize.Name = "ActualSize";
            this.menuViewActualSize.ShortcutKeys = Keys.Control | Keys.Shift | Keys.A;
            this.menuViewActualSize.Click += new System.EventHandler(this.MenuViewActualSize_Click);
            // 
            // menuViewGrid
            // 
            this.menuViewGrid.Name = "Grid";
            this.menuViewGrid.Click += new System.EventHandler(this.MenuViewGrid_Click);
            // 
            // menuViewRulers
            // 
            this.menuViewRulers.Name = "Rulers";
            this.menuViewRulers.Click += new System.EventHandler(this.MenuViewRulers_Click);
            //
            // menuViewPixels
            //
            this.menuViewPixels.Name = "Pixels";
            this.menuViewPixels.Click += new EventHandler(MenuViewPixels_Click);
            this.menuViewPixels.Text = PdnResources.GetString("MeasurementUnit.Pixel.Plural");
            //
            // menuViewInches
            //
            this.menuViewInches.Name = "Inches";
            this.menuViewInches.Text = PdnResources.GetString("MeasurementUnit.Inch.Plural");
            this.menuViewInches.Click += new EventHandler(MenuViewInches_Click);
            //
            // menuViewCentimeters
            //
            this.menuViewCentimeters.Name = "Centimeters";
            this.menuViewCentimeters.Click += new EventHandler(MenuViewCentimeters_Click);
            this.menuViewCentimeters.Text = PdnResources.GetString("MeasurementUnit.Centimeter.Plural");
        }

        protected override void OnDropDownOpening(EventArgs e)
        {
            this.menuViewPixels.Checked = false;
            this.menuViewInches.Checked = false;
            this.menuViewCentimeters.Checked = false;

            switch (AppWorkspace.Units)
            {
                case MeasurementUnit.Pixel:
                    this.menuViewPixels.Checked = true;
                    break;

                case MeasurementUnit.Inch:
                    this.menuViewInches.Checked = true;
                    break;

                case MeasurementUnit.Centimeter:
                    this.menuViewCentimeters.Checked = true;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
            }

            if (AppWorkspace.ActiveDocumentWorkspace != null)
            {
                this.menuViewZoomIn.Enabled = true;
                this.menuViewZoomOut.Enabled = true;
                this.menuViewZoomToWindow.Enabled = true;
                this.menuViewZoomToSelection.Enabled = !AppWorkspace.ActiveDocumentWorkspace.Selection.IsEmpty;
                this.menuViewActualSize.Enabled = true;
                this.menuViewGrid.Enabled = true;
                this.menuViewRulers.Enabled = true;
                this.menuViewPixels.Enabled = true;
                this.menuViewInches.Enabled = true;
                this.menuViewCentimeters.Enabled = true;

                this.menuViewZoomToWindow.Checked = (AppWorkspace.ActiveDocumentWorkspace.ZoomBasis == ZoomBasis.FitToWindow);
                this.menuViewGrid.Checked = AppWorkspace.ActiveDocumentWorkspace.DrawGrid;
                this.menuViewRulers.Checked = AppWorkspace.ActiveDocumentWorkspace.RulersEnabled;
            }
            else
            {
                this.menuViewZoomIn.Enabled = false;
                this.menuViewZoomOut.Enabled = false;
                this.menuViewZoomToWindow.Enabled = false;
                this.menuViewZoomToSelection.Enabled = false;
                this.menuViewActualSize.Enabled = false;
                this.menuViewGrid.Enabled = false;
                this.menuViewRulers.Enabled = false;
                this.menuViewPixels.Enabled = true;
                this.menuViewInches.Enabled = true;
                this.menuViewCentimeters.Enabled = true;
            }

            base.OnDropDownOpening(e);
        }

        private void MenuViewZoomIn_Click(object sender, System.EventArgs e)
        {
            if (AppWorkspace.ActiveDocumentWorkspace != null)
            {
                AppWorkspace.ActiveDocumentWorkspace.PerformAction(new ZoomInAction());
            }
        }

        private void MenuViewZoomOut_Click(object sender, System.EventArgs e)
        {
            if (AppWorkspace.ActiveDocumentWorkspace != null)
            {
                AppWorkspace.ActiveDocumentWorkspace.PerformAction(new ZoomOutAction());
            }
        }

        private void MenuViewZoomToWindow_Click(object sender, EventArgs e)
        {
            if (AppWorkspace.ActiveDocumentWorkspace != null)
            {
                AppWorkspace.ActiveDocumentWorkspace.PerformAction(new ZoomToWindowAction());
            }
        }

        private void MenuViewZoomToSelection_Click(object sender, EventArgs e)
        {
            if (AppWorkspace.ActiveDocumentWorkspace != null)
            {
                AppWorkspace.ActiveDocumentWorkspace.PerformAction(new ZoomToSelectionAction());
            }
        }

        private void MenuViewPixels_Click(object sender, EventArgs e)
        {
            AppWorkspace.Units = MeasurementUnit.Pixel;
        }

        private void MenuViewInches_Click(object sender, EventArgs e)
        {
            AppWorkspace.Units = MeasurementUnit.Inch;
        }

        private void MenuViewCentimeters_Click(object sender, EventArgs e)
        {
            AppWorkspace.Units = MeasurementUnit.Centimeter;
        }

        private void MenuViewActualSize_Click(object sender, System.EventArgs e)
        {
            if (AppWorkspace.ActiveDocumentWorkspace != null)
            {
                AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
                AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
            }
        }

        private void MenuViewRulers_Click(object sender, System.EventArgs e)
        {
            if (AppWorkspace.ActiveDocumentWorkspace != null)
            {
                AppWorkspace.ActiveDocumentWorkspace.RulersEnabled = !AppWorkspace.ActiveDocumentWorkspace.RulersEnabled;
            }
        }

        private void MenuViewGrid_Click(object sender, System.EventArgs e)
        {
            if (AppWorkspace.ActiveDocumentWorkspace != null)
            {
                AppWorkspace.ActiveDocumentWorkspace.DrawGrid = !AppWorkspace.ActiveDocumentWorkspace.DrawGrid;
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.