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) 2006 Novell, Inc.
26 // Jonathan Pobst (monkey@jpobst.com)
31 using System.Windows.Forms.VisualStyles;
33 namespace System.Windows.Forms
35 public sealed class TrackBarRenderer
37 #region Private Constructor
38 private TrackBarRenderer () { }
41 #region Public Static Methods
42 public static void DrawBottomPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state)
45 throw new InvalidOperationException ();
47 VisualStyleRenderer vsr;
50 case TrackBarThumbState.Disabled:
51 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Disabled);
53 case TrackBarThumbState.Hot:
54 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Hot);
56 case TrackBarThumbState.Normal:
58 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Normal);
60 case TrackBarThumbState.Pressed:
61 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Pressed);
65 vsr.DrawBackground (g, bounds);
68 public static void DrawHorizontalThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
71 throw new InvalidOperationException ();
73 VisualStyleRenderer vsr;
76 case TrackBarThumbState.Disabled:
77 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Disabled);
79 case TrackBarThumbState.Hot:
80 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Hot);
82 case TrackBarThumbState.Normal:
84 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Normal);
86 case TrackBarThumbState.Pressed:
87 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Pressed);
91 vsr.DrawBackground (g, bounds);
94 public static void DrawHorizontalTicks(Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle)
97 throw new InvalidOperationException ();
99 if (bounds.Height <= 0 || bounds.Width <= 0 || numTicks <= 0)
102 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Ticks.Normal);
104 double x = bounds.Left;
105 double delta = (double)(bounds.Width - 2) / (double)(numTicks-1);
107 for(int i = 0; i < numTicks; i++)
109 vsr.DrawEdge(g, new Rectangle((int)Math.Round(x), bounds.Top, 5, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None);
114 public static void DrawHorizontalTrack(Graphics g, Rectangle bounds)
117 throw new InvalidOperationException ();
119 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Track.Normal);
121 vsr.DrawBackground (g, bounds);
124 public static void DrawLeftPointingThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
127 throw new InvalidOperationException ();
129 VisualStyleRenderer vsr;
132 case TrackBarThumbState.Disabled:
133 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Disabled);
135 case TrackBarThumbState.Hot:
136 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Hot);
138 case TrackBarThumbState.Normal:
140 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Normal);
142 case TrackBarThumbState.Pressed:
143 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Pressed);
147 vsr.DrawBackground (g, bounds);
150 public static void DrawRightPointingThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
153 throw new InvalidOperationException ();
155 VisualStyleRenderer vsr;
158 case TrackBarThumbState.Disabled:
159 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Disabled);
161 case TrackBarThumbState.Hot:
162 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Hot);
164 case TrackBarThumbState.Normal:
166 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Normal);
168 case TrackBarThumbState.Pressed:
169 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Pressed);
173 vsr.DrawBackground (g, bounds);
176 public static void DrawTopPointingThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
179 throw new InvalidOperationException ();
181 VisualStyleRenderer vsr;
184 case TrackBarThumbState.Disabled:
185 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Disabled);
187 case TrackBarThumbState.Hot:
188 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Hot);
190 case TrackBarThumbState.Normal:
192 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Normal);
194 case TrackBarThumbState.Pressed:
195 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Pressed);
199 vsr.DrawBackground (g, bounds);
202 public static void DrawVerticalThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
205 throw new InvalidOperationException ();
207 VisualStyleRenderer vsr;
210 case TrackBarThumbState.Disabled:
211 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Disabled);
213 case TrackBarThumbState.Hot:
214 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Hot);
216 case TrackBarThumbState.Normal:
218 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Normal);
220 case TrackBarThumbState.Pressed:
221 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Pressed);
225 vsr.DrawBackground (g, bounds);
228 public static void DrawVerticalTicks (Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle)
231 throw new InvalidOperationException ();
233 if (bounds.Height <= 0 || bounds.Width <= 0 || numTicks <= 0)
236 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.TicksVertical.Normal);
238 double y = bounds.Top;
239 double delta = (double)(bounds.Height - 2) / (double)(numTicks - 1);
241 for (int i = 0; i < numTicks; i++) {
242 vsr.DrawEdge (g, new Rectangle (bounds.Left, (int)Math.Round (y), bounds.Width, 5), Edges.Top, edgeStyle, EdgeEffects.None);
247 public static void DrawVerticalTrack (Graphics g, Rectangle bounds)
250 throw new InvalidOperationException ();
252 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Track.Normal);
254 vsr.DrawBackground (g, bounds);
257 public static Size GetBottomPointingThumbSize(Graphics g, TrackBarThumbState state)
260 throw new InvalidOperationException ();
262 VisualStyleRenderer vsr;
265 case TrackBarThumbState.Disabled:
266 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Disabled);
268 case TrackBarThumbState.Hot:
269 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Hot);
271 case TrackBarThumbState.Normal:
273 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Normal);
275 case TrackBarThumbState.Pressed:
276 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Pressed);
280 return vsr.GetPartSize (g, ThemeSizeType.Draw);
283 public static Size GetLeftPointingThumbSize (Graphics g, TrackBarThumbState state)
286 throw new InvalidOperationException ();
288 VisualStyleRenderer vsr;
291 case TrackBarThumbState.Disabled:
292 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Disabled);
294 case TrackBarThumbState.Hot:
295 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Hot);
297 case TrackBarThumbState.Normal:
299 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Normal);
301 case TrackBarThumbState.Pressed:
302 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Pressed);
306 return vsr.GetPartSize (g, ThemeSizeType.Draw);
309 public static Size GetRightPointingThumbSize (Graphics g, TrackBarThumbState state)
312 throw new InvalidOperationException ();
314 VisualStyleRenderer vsr;
317 case TrackBarThumbState.Disabled:
318 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Disabled);
320 case TrackBarThumbState.Hot:
321 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Hot);
323 case TrackBarThumbState.Normal:
325 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Normal);
327 case TrackBarThumbState.Pressed:
328 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Pressed);
332 return vsr.GetPartSize (g, ThemeSizeType.Draw);
335 public static Size GetTopPointingThumbSize (Graphics g, TrackBarThumbState state)
338 throw new InvalidOperationException ();
340 VisualStyleRenderer vsr;
343 case TrackBarThumbState.Disabled:
344 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Disabled);
346 case TrackBarThumbState.Hot:
347 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Hot);
349 case TrackBarThumbState.Normal:
351 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Normal);
353 case TrackBarThumbState.Pressed:
354 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Pressed);
358 return vsr.GetPartSize (g, ThemeSizeType.Draw);
362 #region Public Static Properties
363 public static bool IsSupported {
364 get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }