added some development tools
[windows-sources.git] / developer / VSSDK / VisualStudioIntegration / Common / Source / CSharp / Shell90 / ToolWindowPane.cs
blob8ef6b31d2a9c2fc69101859d983f8681547bc016
1 //------------------------------------------------------------------------------
2 // <copyright file="ToolWindowPane.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
7 using System;
8 using System.Collections;
9 using System.ComponentModel;
10 using System.ComponentModel.Design;
11 using System.Diagnostics;
12 using System.Drawing;
13 using System.Runtime.InteropServices;
14 using System.Windows.Forms;
15 using Microsoft.VisualStudio.OLE.Interop;
16 using Microsoft.VisualStudio.Shell.Interop;
18 using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
19 using IServiceProvider = System.IServiceProvider;
21 namespace Microsoft.VisualStudio.Shell
23 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane"]/*' />
24 /// <summary>
25 /// Summary description for ToolWindowPane.
26 /// </summary>
27 [System.Runtime.InteropServices.ComVisible(true)]
28 public abstract class ToolWindowPane : WindowPane
30 private string caption;
31 private IVsWindowFrame frame = null;
32 private Microsoft.VisualStudio.Shell.Package package = null;
33 private CommandID toolBarCommandID = null;
34 private VSTWT_LOCATION toolBarLocation;
35 private int bitmapResourceID;
36 private int bitmapIndex;
37 private Guid toolClsid;
39 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.ToolWindowPane"]/*' />
40 /// <summary>
41 /// Constructor
42 /// </summary>
43 protected ToolWindowPane(IServiceProvider provider)
45 base(provider)
47 toolClsid = Guid.Empty;
48 bitmapIndex = -1;
49 bitmapResourceID = -1;
50 toolBarLocation = VSTWT_LOCATION.VSTWT_TOP;
53 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.Caption"]/*' />
54 /// <summary>
55 /// Get or Set the text on the title bar of the ToolWindow
56 /// </summary>
57 /// <value></value>
58 public string Caption
60 get { return caption; }
61 set
63 caption = value;
64 if (frame != null && caption != null)
66 // Since the window is already created, set the coresponding property
67 int hr = NativeMethods.S_OK;
68 try {
69 hr = frame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, caption);
70 } catch (COMException e) {
71 hr = e.ErrorCode;
73 Debug.Assert(hr >= 0, "Failed to set caption on toolwindow");
78 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.Frame"]/*' />
79 /// <summary>
80 /// Get or Set the Frame (IvsWindowFrame) hosting the ToolWindow
81 /// </summary>
82 public object Frame
84 get { return frame; }
85 set
87 frame = (IVsWindowFrame)value;
88 // Fire the event to let any custom creation code run
89 OnToolWindowCreated();
93 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.Package"]/*' />
94 /// <summary>
95 /// Get or Set the Package (Microsoft.VisualStudio.Shell.Package) owning the ToolWindow.
96 /// This should only be set by the base Package class when it creates the toolwindow.
97 /// </summary>
98 public object Package
100 get { return package; }
103 if (frame != null || package != null)
104 throw new NotSupportedException(Resources.ToolWindow_PackageOnlySetByCreator);
105 package = (Microsoft.VisualStudio.Shell.Package)value;
109 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.ToolBar"]/*' />
110 /// <summary>
111 /// If the toolwindow has a ToolBar, it is described by this parameter.
112 /// Otherwise this is null
113 /// </summary>
114 public CommandID ToolBar
116 get { return toolBarCommandID; }
119 if (frame != null)
120 throw new Exception(Resources.ToolWindow_TooLateToAddToolbar);
121 toolBarCommandID = value;
125 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.ToolBarLocation"]/*' />
126 /// <summary>
127 /// Get or Set where the toolbar should be in the tool window (Up, down, left, right).
128 /// This parameter is based on VSTWT_LOCATION
129 /// </summary>
130 public int ToolBarLocation
132 get { return (int)toolBarLocation; }
135 if (frame != null)
136 throw new Exception(Resources.ToolWindow_TooLateToAddToolbar);
137 toolBarLocation = (VSTWT_LOCATION)value;
141 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.ToolClsid"]/*' />
142 /// <summary>
143 /// This is used to specify the CLSID of a tool that should be used for this toolwindow
144 /// </summary>
145 public Guid ToolClsid
147 get { return toolClsid; }
150 if (frame != null)
151 throw new Exception(Resources.ToolWindow_TooLateToAddTool);
152 toolClsid = value;
156 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.BitmapResourceID"]/*' />
157 /// <summary>
158 /// Get or Set the resource ID for the bitmap strip from which to take the window frame icon
159 /// </summary>
160 public int BitmapResourceID
162 get { return bitmapResourceID; }
165 bitmapResourceID = value;
166 if (frame != null && bitmapResourceID != -1)
168 int hr = NativeMethods.S_OK;
169 // Since the window is already created, set the coresponding property
170 try {
171 hr = frame.SetProperty((int)__VSFPROPID.VSFPROPID_BitmapResource, bitmapResourceID);
172 } catch (COMException e) {
173 hr = e.ErrorCode;
175 Debug.Assert(hr >= 0, "Failed to set bitmap resource on toolwindow");
180 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.BitmapIndex"]/*' />
181 /// <summary>
182 /// Get or Set the index of the image to use in the bitmap strip for the window frame icon
183 /// </summary>
184 public int BitmapIndex
186 get { return bitmapIndex; }
189 bitmapIndex = value;
190 if (frame != null && bitmapIndex != -1)
192 int hr = NativeMethods.S_OK;
193 // Since the window is already created, set the coresponding property
194 try {
195 hr = frame.SetProperty((int)__VSFPROPID.VSFPROPID_BitmapIndex, bitmapIndex);
196 } catch (COMException e) {
197 hr = e.ErrorCode;
199 Debug.Assert(hr >= 0, "Failed to set bitmap index on toolwindow");
204 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.GetIVsWindowPane"]/*' />
205 /// <summary>
206 /// This method make it possible to provide an IVsWindowPane not derived from ToolWindowPane
207 /// To support that scenario one would override this method and create their IVsWindowPane and
208 /// return it.
209 /// </summary>
210 /// <returns>IVsWindowPane to be hosted in the toolwindow frame</returns>
211 public virtual object GetIVsWindowPane()
213 return (IVsWindowPane)this;
216 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.OnToolWindowCreated"]/*' />
217 /// <summary>
218 /// This method can be overriden by the derived class to execute
219 /// any code that needs to run after the IVsWindowFrame is created.
220 /// If the toolwindow has a toolbar with a combobox, it should make
221 /// sure its command handler are set by the time they return from
222 /// this method.
223 /// This is called when someone set the Frame property.
224 /// </summary>
225 public virtual void OnToolWindowCreated()
227 Debug.Assert(frame != null, "Frame should be set before this method is called");
229 // If any property were set, set them on the frame (setting our properties will take care of it)
230 Caption = caption;
231 BitmapResourceID = bitmapResourceID;
232 BitmapIndex = bitmapIndex;
235 /// <summary>
236 /// This should be overriden if you want to run code before the window is shown
237 /// but after its toolbar is added.
238 /// </summary>
239 public virtual void OnToolBarAdded()