ToolWindowPane.cs :  » Development » StyleCop » Microsoft » VisualStudio » Shell » 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 » Development » StyleCop 
StyleCop » Microsoft » VisualStudio » Shell » ToolWindowPane.cs
//------------------------------------------------------------------------------
// <copyright file="ToolWindowPane.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell.Interop;

using IOleServiceProviderMicrosoft.VisualStudio.OLE.Interop.IServiceProvider;
using IServiceProviderSystem.IServiceProvider;

namespace Microsoft.VisualStudio.Shell{
    /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane"]/*' />
    /// <summary>
    /// Summary description for ToolWindowPane.
    /// </summary>
    [System.Runtime.InteropServices.ComVisible(true)]
    public abstract class ToolWindowPane : WindowPane
    {
        private string caption;
        private IVsWindowFrame frame = null;
        private Microsoft.VisualStudio.Shell.Package package = null;
        private CommandID toolBarCommandID = null;
        private VSTWT_LOCATION toolBarLocation;
        private int bitmapResourceID;
        private int bitmapIndex;
        private Guid toolClsid;

        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.ToolWindowPane"]/*' />
        /// <summary>
        /// Constructor
        /// </summary>
        protected ToolWindowPane(IServiceProvider provider)
        :
        base(provider)
        {
            toolClsid = Guid.Empty;
            bitmapIndex = -1;
            bitmapResourceID = -1;
            toolBarLocation = VSTWT_LOCATION.VSTWT_TOP;
        }
    
        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.Caption"]/*' />
        /// <summary>
        /// Get or Set the text on the title bar of the ToolWindow
        /// </summary>
        /// <value></value>
        public string Caption
        {
            get { return caption; }
            set
            {
                caption = value;
                if (frame != null && caption != null)
                {
                    // Since the window is already created, set the coresponding property
                    int hr = NativeMethods.S_OK;
                    try {
                        hr = frame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, caption);
                    } catch (COMException e) {
                        hr = e.ErrorCode;
                    }
                    Debug.Assert(hr >= 0, "Failed to set caption on toolwindow");
                }
            }
        }

        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.Frame"]/*' />
        /// <summary>
        /// Get or Set the Frame (IvsWindowFrame) hosting the ToolWindow
        /// </summary>
        public object Frame
        {
            get { return frame; }
            set
            {
                frame = (IVsWindowFrame)value;
                // Fire the event to let any custom creation code run
                OnToolWindowCreated();
            }
        }

        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.Package"]/*' />
        /// <summary>
        /// Get or Set the Package (Microsoft.VisualStudio.Shell.Package) owning the ToolWindow.
        /// This should only be set by the base Package class when it creates the toolwindow.
        /// </summary>
        public object Package
        {
            get { return package; }
            set
            {
                if (frame != null || package != null)
                    throw new NotSupportedException(Resources.ToolWindow_PackageOnlySetByCreator);
                package = (Microsoft.VisualStudio.Shell.Package)value;
            }
        }

        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.ToolBar"]/*' />
        /// <summary>
        /// If the toolwindow has a ToolBar, it is described by this parameter.
        /// Otherwise this is null
        /// </summary>
        public CommandID ToolBar
        {
            get { return toolBarCommandID; }
            set
            {
                if (frame != null)
                    throw new Exception(Resources.ToolWindow_TooLateToAddToolbar);
                toolBarCommandID = value;
            }
        }

        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.ToolBarLocation"]/*' />
        /// <summary>
        /// Get or Set where the toolbar should be in the tool window (Up, down, left, right).
        /// This parameter is based on VSTWT_LOCATION
        /// </summary>
        public int ToolBarLocation
        {
            get { return (int)toolBarLocation; }
            set
            {
                if (frame != null)
                    throw new Exception(Resources.ToolWindow_TooLateToAddToolbar);
                toolBarLocation = (VSTWT_LOCATION)value;
            }
        }

        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.ToolClsid"]/*' />
        /// <summary>
        /// This is used to specify the CLSID of a tool that should be used for this toolwindow
        /// </summary>
        public Guid ToolClsid
        {
            get { return toolClsid; }
            set
            {
                if (frame != null)
                    throw new Exception(Resources.ToolWindow_TooLateToAddTool);
                toolClsid = value;
            }
        }

        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.BitmapResourceID"]/*' />
        /// <summary>
        /// Get or Set the resource ID for the bitmap strip from which to take the window frame icon
        /// </summary>
        public int BitmapResourceID
        {
            get { return bitmapResourceID; }
            set
            {
                bitmapResourceID = value;
                if (frame != null && bitmapResourceID != -1)
                {
                    int hr = NativeMethods.S_OK;
                    // Since the window is already created, set the coresponding property
                    try {
                        hr = frame.SetProperty((int)__VSFPROPID.VSFPROPID_BitmapResource, bitmapResourceID);
                    } catch (COMException e) {
                        hr = e.ErrorCode;
                    }
                    Debug.Assert(hr >= 0, "Failed to set bitmap resource on toolwindow");
                }
            }
        }

        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.BitmapIndex"]/*' />
        /// <summary>
        /// Get or Set the index of the image to use in the bitmap strip for the window frame icon
        /// </summary>
        public int BitmapIndex
        {
            get { return bitmapIndex; }
            set
            {
                bitmapIndex = value;
                if (frame != null && bitmapIndex != -1)
                {
                    int hr = NativeMethods.S_OK;
                    // Since the window is already created, set the coresponding property
                    try {
                        hr = frame.SetProperty((int)__VSFPROPID.VSFPROPID_BitmapIndex, bitmapIndex);
                    } catch (COMException e) {
                        hr = e.ErrorCode;
                    }
                    Debug.Assert(hr >= 0, "Failed to set bitmap index on toolwindow");
                }
            }
        }

        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.GetIVsWindowPane"]/*' />
        /// <summary>
        /// This method make it possible to provide an IVsWindowPane not derived from ToolWindowPane
        /// To support that scenario one would override this method and create their IVsWindowPane and
        /// return it.
        /// </summary>
        /// <returns>IVsWindowPane to be hosted in the toolwindow frame</returns>
        public virtual object GetIVsWindowPane()
        {
            return (IVsWindowPane)this;
        }

        /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.OnToolWindowCreated"]/*' />
        /// <summary>
        /// This method can be overriden by the derived class to execute
        /// any code that needs to run after the IVsWindowFrame is created.
        /// If the toolwindow has a toolbar with a combobox, it should make
        /// sure its command handler are set by the time they return from
        /// this method.
        /// This is called when someone set the Frame property.
        /// </summary>
        public virtual void OnToolWindowCreated()
        {
            Debug.Assert(frame != null, "Frame should be set before this method is called");

            // If any property were set, set them on the frame (setting our properties will take care of it)
            Caption = caption;
            BitmapResourceID = bitmapResourceID;
            BitmapIndex = bitmapIndex;
        }

        /// <summary>
        /// This should be overriden if you want to run code before the window is shown
        /// but after its toolbar is added.
        /// </summary>
        public virtual void OnToolBarAdded()
        {
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.