2 // ToolStripRenderer.cs
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) Jonathan Pobst
26 // Jonathan Pobst (monkey@jpobst.com)
32 using System.Drawing.Imaging;
34 namespace System.Windows.Forms
36 public abstract class ToolStripRenderer
38 private static ColorMatrix grayscale_matrix = new ColorMatrix (new float[][] {
39 new float[]{0.3f,0.3f,0.3f,0,0},
40 new float[]{0.59f,0.59f,0.59f,0,0},
41 new float[]{0.11f,0.11f,0.11f,0,0},
42 new float[]{0,0,0,1,0,0},
43 new float[]{0,0,0,0,1,0},
44 new float[]{0,0,0,0,0,1}
47 protected ToolStripRenderer ()
51 #region Public Methods
52 public static Image CreateDisabledImage(Image normalImage)
54 // Code adapted from ThemeWin32Classic.cs
55 ImageAttributes ia = new ImageAttributes();
56 ia.SetColorMatrix (grayscale_matrix);
58 Bitmap b = new Bitmap(normalImage);
59 Graphics.FromImage(b).DrawImage(normalImage, new Rectangle (0, 0, normalImage.Width, normalImage.Height), 0, 0, normalImage.Width, normalImage.Height, GraphicsUnit.Pixel, ia);
64 public void DrawArrow (ToolStripArrowRenderEventArgs e)
65 { this.OnRenderArrow (e); }
67 public void DrawButtonBackground (ToolStripItemRenderEventArgs e)
68 { this.OnRenderButtonBackground (e); }
70 public void DrawDropDownButtonBackground (ToolStripItemRenderEventArgs e)
71 { this.OnRenderDropDownButtonBackground (e); }
73 public void DrawGrip (ToolStripGripRenderEventArgs e)
74 { this.OnRenderGrip (e); }
76 public void DrawImageMargin (ToolStripRenderEventArgs e)
77 { this.OnRenderImageMargin (e); }
79 public void DrawItemBackground (ToolStripItemRenderEventArgs e)
80 { this.OnRenderItemBackground (e); }
82 public void DrawItemCheck (ToolStripItemImageRenderEventArgs e)
83 { this.OnRenderItemCheck (e); }
85 public void DrawItemImage (ToolStripItemImageRenderEventArgs e)
86 { this.OnRenderItemImage (e); }
88 public void DrawItemText (ToolStripItemTextRenderEventArgs e)
89 { this.OnRenderItemText (e); }
91 public void DrawLabelBackground (ToolStripItemRenderEventArgs e)
92 { this.OnRenderLabelBackground (e); }
94 public void DrawMenuItemBackground (ToolStripItemRenderEventArgs e)
95 { this.OnRenderMenuItemBackground (e); }
97 public void DrawOverflowButtonBackground (ToolStripItemRenderEventArgs e)
98 { this.OnRenderOverflowButtonBackground (e); }
100 public void DrawSeparator (ToolStripSeparatorRenderEventArgs e)
101 { this.OnRenderSeparator (e); }
103 public void DrawSplitButton (ToolStripItemRenderEventArgs e)
104 { this.OnRenderSplitButtonBackground (e); }
106 public void DrawStatusStripSizingGrip (ToolStripRenderEventArgs e)
107 { this.OnRenderStatusStripSizingGrip (e); }
109 public void DrawToolStripBackground (ToolStripRenderEventArgs e)
110 { this.OnRenderToolStripBackground (e); }
112 public void DrawToolStripBorder (ToolStripRenderEventArgs e)
113 { this.OnRenderToolStripBorder (e); }
115 public void DrawToolStripContentPanelBackground (ToolStripContentPanelRenderEventArgs e)
116 { this.OnRenderToolStripContentPanelBackground (e); }
118 public void DrawToolStripPanelBackground (ToolStripPanelRenderEventArgs e)
119 { this.OnRenderToolStripPanelBackground (e); }
121 public void DrawToolStripStatusLabelBackground (ToolStripItemRenderEventArgs e)
122 { this.OnRenderToolStripStatusLabelBackground (e); }
125 #region Protected Methods
126 protected internal virtual void Initialize (ToolStrip toolStrip) {}
127 protected internal virtual void InitializeContentPanel (ToolStripContentPanel contentPanel) {}
128 protected internal virtual void InitializeItem (ToolStripItem item) {}
129 protected internal virtual void InitializePanel (ToolStripPanel toolStripPanel) {}
131 protected virtual void OnRenderArrow (ToolStripArrowRenderEventArgs e)
132 { if (RenderArrow != null) RenderArrow (this, e); }
134 protected virtual void OnRenderButtonBackground (ToolStripItemRenderEventArgs e)
135 { if (RenderButtonBackground != null) RenderButtonBackground (this, e); }
137 protected virtual void OnRenderDropDownButtonBackground (ToolStripItemRenderEventArgs e)
138 { if (RenderDropDownButtonBackground != null) RenderDropDownButtonBackground (this, e); }
140 protected virtual void OnRenderGrip (ToolStripGripRenderEventArgs e)
141 { if (RenderGrip != null) RenderGrip (this, e); }
143 protected virtual void OnRenderImageMargin (ToolStripRenderEventArgs e)
144 { if (RenderImageMargin != null) RenderImageMargin (this, e); }
146 protected virtual void OnRenderItemBackground (ToolStripItemRenderEventArgs e)
147 { if (RenderItemBackground != null) RenderItemBackground (this, e); }
149 protected virtual void OnRenderItemCheck (ToolStripItemImageRenderEventArgs e)
150 { if (RenderItemCheck != null) RenderItemCheck (this, e); }
152 protected virtual void OnRenderItemImage (ToolStripItemImageRenderEventArgs e)
153 { if (RenderItemImage != null) RenderItemImage (this, e); }
155 protected virtual void OnRenderItemText (ToolStripItemTextRenderEventArgs e)
156 { if (RenderItemText != null) RenderItemText (this, e); }
158 protected virtual void OnRenderLabelBackground (ToolStripItemRenderEventArgs e)
159 { if (RenderLabelBackground != null) RenderLabelBackground (this, e); }
161 protected virtual void OnRenderMenuItemBackground (ToolStripItemRenderEventArgs e)
162 { if (RenderMenuItemBackground != null) RenderMenuItemBackground (this, e); }
164 protected virtual void OnRenderOverflowButtonBackground (ToolStripItemRenderEventArgs e)
165 { if (RenderOverflowButtonBackground != null) RenderOverflowButtonBackground (this, e); }
167 protected virtual void OnRenderSeparator (ToolStripSeparatorRenderEventArgs e)
168 { if (RenderSeparator != null) RenderSeparator (this, e); }
170 protected virtual void OnRenderSplitButtonBackground (ToolStripItemRenderEventArgs e)
171 { if (RenderSplitButtonBackground != null) RenderSplitButtonBackground (this, e); }
173 protected virtual void OnRenderStatusStripSizingGrip (ToolStripRenderEventArgs e)
174 { if (RenderStatusStripSizingGrip != null) RenderStatusStripSizingGrip (this, e); }
176 protected virtual void OnRenderToolStripBackground (ToolStripRenderEventArgs e)
177 { if (RenderToolStripBackground != null) RenderToolStripBackground (this, e); }
179 protected virtual void OnRenderToolStripBorder (ToolStripRenderEventArgs e)
180 { if (RenderToolStripBorder != null) RenderToolStripBorder (this, e); }
182 protected virtual void OnRenderToolStripContentPanelBackground (ToolStripContentPanelRenderEventArgs e)
183 { if (RenderToolStripContentPanelBackground != null) RenderToolStripContentPanelBackground (this, e); }
185 protected virtual void OnRenderToolStripPanelBackground (ToolStripPanelRenderEventArgs e)
186 { if (RenderToolStripPanelBackground != null) RenderToolStripPanelBackground (this, e); }
188 protected virtual void OnRenderToolStripStatusLabelBackground (ToolStripItemRenderEventArgs e)
189 { if (RenderToolStripStatusLabelBackground != null) RenderToolStripStatusLabelBackground (this, e); }
192 #region Public Events
193 public event ToolStripArrowRenderEventHandler RenderArrow;
194 public event ToolStripItemRenderEventHandler RenderButtonBackground;
195 public event ToolStripItemRenderEventHandler RenderDropDownButtonBackground;
196 public event ToolStripGripRenderEventHandler RenderGrip;
197 public event ToolStripRenderEventHandler RenderImageMargin;
198 public event ToolStripItemRenderEventHandler RenderItemBackground;
199 public event ToolStripItemImageRenderEventHandler RenderItemCheck;
200 public event ToolStripItemImageRenderEventHandler RenderItemImage;
201 public event ToolStripItemTextRenderEventHandler RenderItemText;
202 public event ToolStripItemRenderEventHandler RenderLabelBackground;
203 public event ToolStripItemRenderEventHandler RenderMenuItemBackground;
204 public event ToolStripItemRenderEventHandler RenderOverflowButtonBackground;
205 public event ToolStripSeparatorRenderEventHandler RenderSeparator;
206 public event ToolStripItemRenderEventHandler RenderSplitButtonBackground;
207 public event ToolStripRenderEventHandler RenderStatusStripSizingGrip;
208 public event ToolStripRenderEventHandler RenderToolStripBackground;
209 public event ToolStripRenderEventHandler RenderToolStripBorder;
210 public event ToolStripContentPanelRenderEventHandler RenderToolStripContentPanelBackground;
211 public event ToolStripPanelRenderEventHandler RenderToolStripPanelBackground;
212 public event ToolStripItemRenderEventHandler RenderToolStripStatusLabelBackground;