1 //------------------------------------------------------------------------------
2 // <copyright file="ToolWindowPane.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
8 using System
.Collections
;
9 using System
.ComponentModel
;
10 using System
.ComponentModel
.Design
;
11 using System
.Diagnostics
;
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"]/*' />
25 /// Summary description for ToolWindowPane.
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"]/*' />
43 protected ToolWindowPane(IServiceProvider provider
)
47 toolClsid
= Guid
.Empty
;
49 bitmapResourceID
= -1;
50 toolBarLocation
= VSTWT_LOCATION
.VSTWT_TOP
;
53 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.Caption"]/*' />
55 /// Get or Set the text on the title bar of the ToolWindow
60 get { return caption; }
64 if (frame
!= null && caption
!= null)
66 // Since the window is already created, set the coresponding property
67 int hr
= NativeMethods
.S_OK
;
69 hr
= frame
.SetProperty((int)__VSFPROPID
.VSFPROPID_Caption
, caption
);
70 } catch (COMException e
) {
73 Debug
.Assert(hr
>= 0, "Failed to set caption on toolwindow");
78 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.Frame"]/*' />
80 /// Get or Set the Frame (IvsWindowFrame) hosting the ToolWindow
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"]/*' />
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.
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"]/*' />
111 /// If the toolwindow has a ToolBar, it is described by this parameter.
112 /// Otherwise this is null
114 public CommandID ToolBar
116 get { return toolBarCommandID; }
120 throw new Exception(Resources
.ToolWindow_TooLateToAddToolbar
);
121 toolBarCommandID
= value;
125 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.ToolBarLocation"]/*' />
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
130 public int ToolBarLocation
132 get { return (int)toolBarLocation; }
136 throw new Exception(Resources
.ToolWindow_TooLateToAddToolbar
);
137 toolBarLocation
= (VSTWT_LOCATION
)value;
141 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.ToolClsid"]/*' />
143 /// This is used to specify the CLSID of a tool that should be used for this toolwindow
145 public Guid ToolClsid
147 get { return toolClsid; }
151 throw new Exception(Resources
.ToolWindow_TooLateToAddTool
);
156 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.BitmapResourceID"]/*' />
158 /// Get or Set the resource ID for the bitmap strip from which to take the window frame icon
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
171 hr
= frame
.SetProperty((int)__VSFPROPID
.VSFPROPID_BitmapResource
, bitmapResourceID
);
172 } catch (COMException e
) {
175 Debug
.Assert(hr
>= 0, "Failed to set bitmap resource on toolwindow");
180 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.BitmapIndex"]/*' />
182 /// Get or Set the index of the image to use in the bitmap strip for the window frame icon
184 public int BitmapIndex
186 get { return bitmapIndex; }
190 if (frame
!= null && bitmapIndex
!= -1)
192 int hr
= NativeMethods
.S_OK
;
193 // Since the window is already created, set the coresponding property
195 hr
= frame
.SetProperty((int)__VSFPROPID
.VSFPROPID_BitmapIndex
, bitmapIndex
);
196 } catch (COMException e
) {
199 Debug
.Assert(hr
>= 0, "Failed to set bitmap index on toolwindow");
204 /// <include file='doc\ToolWindowPane.uex' path='docs/doc[@for="ToolWindowPane.GetIVsWindowPane"]/*' />
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
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"]/*' />
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
223 /// This is called when someone set the Frame property.
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)
231 BitmapResourceID
= bitmapResourceID
;
232 BitmapIndex
= bitmapIndex
;
236 /// This should be overriden if you want to run code before the window is shown
237 /// but after its toolbar is added.
239 public virtual void OnToolBarAdded()