1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2008 George Giolfan
23 // George Giolfan (georgegiolfan@yahoo.com)
27 using System.Windows.Forms.VisualStyles;
28 namespace System.Windows.Forms.Theming.VisualStyles
30 class ToolStripPainter : Default.ToolStripPainter
32 static bool IsDisabled (ToolStripItem toolStripItem)
34 return !toolStripItem.Enabled;
36 static bool IsPressed (ToolStripItem toolStripItem)
38 return toolStripItem.Pressed;
40 static bool IsChecked (ToolStripItem toolStripItem)
42 ToolStripButton tool_strip_button = toolStripItem as ToolStripButton;
43 if (tool_strip_button == null)
45 return tool_strip_button.Checked;
47 static bool IsHot (ToolStripItem toolStripItem)
49 return toolStripItem.Selected;
51 public override void OnRenderButtonBackground (ToolStripItemRenderEventArgs e)
53 if (!ThemeVisualStyles.RenderClientAreas) {
54 base.OnRenderButtonBackground (e);
57 VisualStyleElement element;
58 if (IsDisabled (e.Item))
59 element = VisualStyleElement.ToolBar.Button.Disabled;
60 else if (IsPressed (e.Item))
61 element = VisualStyleElement.ToolBar.Button.Pressed;
62 else if (IsChecked (e.Item))
64 element = VisualStyleElement.ToolBar.Button.HotChecked;
66 element = VisualStyleElement.ToolBar.Button.Checked;
67 else if (IsHot (e.Item))
68 element = VisualStyleElement.ToolBar.Button.Hot;
70 element = VisualStyleElement.ToolBar.Button.Normal;
71 if (!VisualStyleRenderer.IsElementDefined (element)) {
72 base.OnRenderButtonBackground (e);
75 new VisualStyleRenderer (element).DrawBackground (e.Graphics, e.Item.Bounds);
77 public override void OnRenderDropDownButtonBackground (ToolStripItemRenderEventArgs e)
79 if (!ThemeVisualStyles.RenderClientAreas) {
80 base.OnRenderDropDownButtonBackground (e);
83 VisualStyleElement element;
84 if (IsDisabled (e.Item))
85 element = VisualStyleElement.ToolBar.DropDownButton.Disabled;
86 else if (IsPressed (e.Item))
87 element = VisualStyleElement.ToolBar.DropDownButton.Pressed;
88 else if (IsChecked (e.Item))
90 element = VisualStyleElement.ToolBar.DropDownButton.HotChecked;
92 element = VisualStyleElement.ToolBar.DropDownButton.Checked;
93 else if (IsHot (e.Item))
94 element = VisualStyleElement.ToolBar.DropDownButton.Hot;
96 element = VisualStyleElement.ToolBar.DropDownButton.Normal;
97 if (!VisualStyleRenderer.IsElementDefined (element)) {
98 base.OnRenderDropDownButtonBackground (e);
101 new VisualStyleRenderer (element).DrawBackground (e.Graphics, e.Item.Bounds);
103 public override void OnRenderGrip (ToolStripGripRenderEventArgs e)
105 if (!ThemeVisualStyles.RenderClientAreas) {
106 base.OnRenderGrip (e);
109 if (e.GripStyle == ToolStripGripStyle.Hidden)
111 VisualStyleElement element = e.GripDisplayStyle == ToolStripGripDisplayStyle.Vertical ?
112 VisualStyleElement.Rebar.Gripper.Normal :
113 VisualStyleElement.Rebar.GripperVertical.Normal;
114 if (!VisualStyleRenderer.IsElementDefined (element)) {
115 base.OnRenderGrip (e);
118 new VisualStyleRenderer (element).DrawBackground (e.Graphics, e.GripDisplayStyle == ToolStripGripDisplayStyle.Vertical ?
119 // GetPartSize seems to return useless values.
120 new Rectangle (2, 0, 5, 20) :
121 new Rectangle (0, 2, 20, 5));
123 public override void OnRenderOverflowButtonBackground (ToolStripItemRenderEventArgs e)
125 if (!ThemeVisualStyles.RenderClientAreas) {
126 base.OnRenderOverflowButtonBackground (e);
129 VisualStyleElement element = e.ToolStrip.Orientation == Orientation.Horizontal ?
130 VisualStyleElement.Rebar.Chevron.Normal :
131 VisualStyleElement.Rebar.ChevronVertical.Normal;
132 if (!VisualStyleRenderer.IsElementDefined (element)) {
133 base.OnRenderOverflowButtonBackground (e);
136 OnRenderButtonBackground (e);
137 new VisualStyleRenderer (element).DrawBackground (e.Graphics, e.Item.Bounds);
139 public override void OnRenderSeparator (ToolStripSeparatorRenderEventArgs e)
141 if (!ThemeVisualStyles.RenderClientAreas) {
142 base.OnRenderSeparator (e);
145 VisualStyleElement element = e.ToolStrip.Orientation == Orientation.Horizontal ?
146 VisualStyleElement.ToolBar.SeparatorHorizontal.Normal :
147 VisualStyleElement.ToolBar.SeparatorVertical.Normal;
148 if (!VisualStyleRenderer.IsElementDefined (element)) {
149 base.OnRenderSeparator (e);
152 new VisualStyleRenderer (element).DrawBackground (e.Graphics, e.Item.Bounds);
154 public override void OnRenderSplitButtonBackground (ToolStripItemRenderEventArgs e)
156 if (!ThemeVisualStyles.RenderClientAreas) {
157 base.OnRenderSplitButtonBackground (e);
160 VisualStyleElement element, drop_down_element;
161 if (IsDisabled (e.Item)) {
162 element = VisualStyleElement.ToolBar.SplitButton.Disabled;
163 drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Disabled;;
164 } else if (IsPressed (e.Item)) {
165 element = VisualStyleElement.ToolBar.SplitButton.Pressed;
166 drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Pressed;
167 } else if (IsChecked (e.Item))
168 if (IsHot (e.Item)) {
169 element = VisualStyleElement.ToolBar.SplitButton.HotChecked;
170 drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.HotChecked;
172 element = VisualStyleElement.ToolBar.Button.Checked;
173 drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Checked;
175 else if (IsHot (e.Item)) {
176 element = VisualStyleElement.ToolBar.SplitButton.Hot;
177 drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Hot;
179 element = VisualStyleElement.ToolBar.SplitButton.Normal;
180 drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
182 if (!VisualStyleRenderer.IsElementDefined (element) ||
183 !VisualStyleRenderer.IsElementDefined (drop_down_element)) {
184 base.OnRenderSplitButtonBackground (e);
187 ToolStripSplitButton tool_strip_split_button = (ToolStripSplitButton)e.Item;
188 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
189 renderer.DrawBackground (e.Graphics, tool_strip_split_button.ButtonBounds);
190 renderer.SetParameters (drop_down_element);
191 renderer.DrawBackground (e.Graphics, tool_strip_split_button.DropDownButtonBounds);
193 public override void OnRenderToolStripBackground (ToolStripRenderEventArgs e)
195 if (!ThemeVisualStyles.RenderClientAreas) {
196 base.OnRenderToolStripBackground (e);
199 VisualStyleElement element;
200 if (e.ToolStrip is StatusStrip)
201 element = VisualStyleElement.Status.Bar.Normal;
203 element = VisualStyleElement.Rebar.Band.Normal;
204 if (!VisualStyleRenderer.IsElementDefined (element)) {
205 base.OnRenderToolStripBackground (e);
208 new VisualStyleRenderer (element).DrawBackground (e.Graphics, e.ToolStrip.Bounds, e.AffectedBounds);