fe07cf8cc20cf96316150755d995b24ca76ea7ad
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripRenderer.cs
1 //
2 // ToolStripRenderer.cs
3 //
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:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
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.
22 //
23 // Copyright (c) Jonathan Pobst
24 //
25 // Authors:
26 //      Jonathan Pobst (monkey@jpobst.com)
27 //
28 #if NET_2_0
29
30 using System;
31 using System.Drawing;
32 using System.Drawing.Imaging;
33
34 namespace System.Windows.Forms
35 {
36         public abstract class ToolStripRenderer
37         {
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}
45                                   });
46
47                 protected ToolStripRenderer () 
48                 {
49                 }
50
51                 #region Public Methods
52                 public static Image CreateDisabledImage(Image normalImage)
53                 {
54                         // Code adapted from ThemeWin32Classic.cs
55                         ImageAttributes ia = new ImageAttributes();
56                         ia.SetColorMatrix (grayscale_matrix);
57                         
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);
60                         
61                         return b;
62                 }
63
64                 public void DrawArrow (ToolStripArrowRenderEventArgs e)
65                 { this.OnRenderArrow (e); }
66                 
67                 public void DrawButtonBackground (ToolStripItemRenderEventArgs e)
68                 { this.OnRenderButtonBackground (e); }
69
70                 public void DrawDropDownButtonBackground (ToolStripItemRenderEventArgs e)
71                 { this.OnRenderDropDownButtonBackground (e); }
72
73                 public void DrawGrip (ToolStripGripRenderEventArgs e)
74                 { this.OnRenderGrip (e); }
75
76                 public void DrawImageMargin (ToolStripRenderEventArgs e)
77                 { this.OnRenderImageMargin (e); }
78
79                 public void DrawItemBackground (ToolStripItemRenderEventArgs e)
80                 { this.OnRenderItemBackground (e); }
81
82                 public void DrawItemCheck (ToolStripItemImageRenderEventArgs e)
83                 { this.OnRenderItemCheck (e); }
84
85                 public void DrawItemImage (ToolStripItemImageRenderEventArgs e)
86                 { this.OnRenderItemImage (e); }
87
88                 public void DrawItemText (ToolStripItemTextRenderEventArgs e)
89                 { this.OnRenderItemText (e); }
90
91                 public void DrawLabelBackground (ToolStripItemRenderEventArgs e)
92                 { this.OnRenderLabelBackground (e); }
93
94                 public void DrawMenuItemBackground (ToolStripItemRenderEventArgs e)
95                 { this.OnRenderMenuItemBackground (e); }
96
97                 public void DrawOverflowButtonBackground (ToolStripItemRenderEventArgs e)
98                 { this.OnRenderOverflowButtonBackground (e); }
99
100                 public void DrawSeparator (ToolStripSeparatorRenderEventArgs e)
101                 { this.OnRenderSeparator (e); }
102
103                 public void DrawSplitButton (ToolStripItemRenderEventArgs e)
104                 { this.OnRenderSplitButtonBackground (e); }
105
106                 public void DrawStatusStripSizingGrip (ToolStripRenderEventArgs e)
107                 { this.OnRenderStatusStripSizingGrip (e); }
108
109                 public void DrawToolStripBackground (ToolStripRenderEventArgs e)
110                 { this.OnRenderToolStripBackground (e); }
111
112                 public void DrawToolStripBorder (ToolStripRenderEventArgs e)
113                 { this.OnRenderToolStripBorder (e); }
114
115                 public void DrawToolStripContentPanelBackground (ToolStripContentPanelRenderEventArgs e)
116                 { this.OnRenderToolStripContentPanelBackground (e); }
117
118                 public void DrawToolStripPanelBackground (ToolStripPanelRenderEventArgs e)
119                 { this.OnRenderToolStripPanelBackground (e); }
120
121                 public void DrawToolStripStatusLabelBackground (ToolStripItemRenderEventArgs e)
122                 { this.OnRenderToolStripStatusLabelBackground (e); }
123                 #endregion
124
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) {}
130
131                 protected virtual void OnRenderArrow (ToolStripArrowRenderEventArgs e)
132                 { if (RenderArrow != null) RenderArrow (this, e); }
133
134                 protected virtual void OnRenderButtonBackground (ToolStripItemRenderEventArgs e)
135                 { if (RenderButtonBackground != null) RenderButtonBackground (this, e); }
136
137                 protected virtual void OnRenderDropDownButtonBackground (ToolStripItemRenderEventArgs e)
138                 { if (RenderDropDownButtonBackground != null) RenderDropDownButtonBackground (this, e); }
139                 
140                 protected virtual void OnRenderGrip (ToolStripGripRenderEventArgs e)
141                 { if (RenderGrip != null) RenderGrip (this, e); }
142
143                 protected virtual void OnRenderImageMargin (ToolStripRenderEventArgs e)
144                 { if (RenderImageMargin != null) RenderImageMargin (this, e); }
145
146                 protected virtual void OnRenderItemBackground (ToolStripItemRenderEventArgs e)
147                 { if (RenderItemBackground != null) RenderItemBackground (this, e); }
148
149                 protected virtual void OnRenderItemCheck (ToolStripItemImageRenderEventArgs e)
150                 { if (RenderItemCheck != null) RenderItemCheck (this, e); }
151
152                 protected virtual void OnRenderItemImage (ToolStripItemImageRenderEventArgs e)
153                 { if (RenderItemImage != null) RenderItemImage (this, e); }
154
155                 protected virtual void OnRenderItemText (ToolStripItemTextRenderEventArgs e)
156                 { if (RenderItemText != null) RenderItemText (this, e); }
157
158                 protected virtual void OnRenderLabelBackground (ToolStripItemRenderEventArgs e)
159                 { if (RenderLabelBackground != null) RenderLabelBackground (this, e); }
160
161                 protected virtual void OnRenderMenuItemBackground (ToolStripItemRenderEventArgs e)
162                 { if (RenderMenuItemBackground != null) RenderMenuItemBackground (this, e); }
163
164                 protected virtual void OnRenderOverflowButtonBackground (ToolStripItemRenderEventArgs e)
165                 { if (RenderOverflowButtonBackground != null) RenderOverflowButtonBackground (this, e); }
166
167                 protected virtual void OnRenderSeparator (ToolStripSeparatorRenderEventArgs e)
168                 { if (RenderSeparator != null) RenderSeparator (this, e); }
169
170                 protected virtual void OnRenderSplitButtonBackground (ToolStripItemRenderEventArgs e)
171                 { if (RenderSplitButtonBackground != null) RenderSplitButtonBackground (this, e); }
172
173                 protected virtual void OnRenderStatusStripSizingGrip (ToolStripRenderEventArgs e)
174                 { if (RenderStatusStripSizingGrip != null) RenderStatusStripSizingGrip (this, e); }
175
176                 protected virtual void OnRenderToolStripBackground (ToolStripRenderEventArgs e)
177                 { if (RenderToolStripBackground != null) RenderToolStripBackground (this, e); }
178
179                 protected virtual void OnRenderToolStripBorder (ToolStripRenderEventArgs e)
180                 { if (RenderToolStripBorder != null) RenderToolStripBorder (this, e); }
181
182                 protected virtual void OnRenderToolStripContentPanelBackground (ToolStripContentPanelRenderEventArgs e)
183                 { if (RenderToolStripContentPanelBackground != null) RenderToolStripContentPanelBackground (this, e); }
184
185                 protected virtual void OnRenderToolStripPanelBackground (ToolStripPanelRenderEventArgs e)
186                 { if (RenderToolStripPanelBackground != null) RenderToolStripPanelBackground (this, e); }
187
188                 protected virtual void OnRenderToolStripStatusLabelBackground (ToolStripItemRenderEventArgs e)
189                 { if (RenderToolStripStatusLabelBackground != null) RenderToolStripStatusLabelBackground (this, e); }
190                 #endregion
191
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;
213                 #endregion
214         }
215 }
216 #endif