2 // TrackBarRenderer.cs
\r
4 // Permission is hereby granted, free of charge, to any person obtaining
\r
5 // a copy of this software and associated documentation files (the
\r
6 // "Software"), to deal in the Software without restriction, including
\r
7 // without limitation the rights to use, copy, modify, merge, publish,
\r
8 // distribute, sublicense, and/or sell copies of the Software, and to
\r
9 // permit persons to whom the Software is furnished to do so, subject to
\r
10 // the following conditions:
\r
12 // The above copyright notice and this permission notice shall be
\r
13 // included in all copies or substantial portions of the Software.
\r
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 // Copyright (c) 2006 Novell, Inc.
\r
26 // Jonathan Pobst (monkey@jpobst.com)
\r
30 using System.Drawing;
\r
31 using System.Windows.Forms.VisualStyles;
\r
33 namespace System.Windows.Forms
\r
35 public sealed class TrackBarRenderer
\r
37 #region Private Constructor
\r
38 private TrackBarRenderer () { }
\r
41 #region Public Static Methods
\r
42 public static void DrawBottomPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state)
\r
45 throw new InvalidOperationException ();
\r
47 VisualStyleRenderer vsr;
\r
50 case TrackBarThumbState.Disabled:
\r
51 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Disabled);
\r
53 case TrackBarThumbState.Hot:
\r
54 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Hot);
\r
56 case TrackBarThumbState.Normal:
\r
58 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Normal);
\r
60 case TrackBarThumbState.Pressed:
\r
61 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Pressed);
\r
65 vsr.DrawBackground (g, bounds);
\r
68 public static void DrawHorizontalThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
\r
71 throw new InvalidOperationException ();
\r
73 VisualStyleRenderer vsr;
\r
76 case TrackBarThumbState.Disabled:
\r
77 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Disabled);
\r
79 case TrackBarThumbState.Hot:
\r
80 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Hot);
\r
82 case TrackBarThumbState.Normal:
\r
84 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Normal);
\r
86 case TrackBarThumbState.Pressed:
\r
87 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Thumb.Pressed);
\r
91 vsr.DrawBackground (g, bounds);
\r
94 public static void DrawHorizontalTicks(Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle)
\r
97 throw new InvalidOperationException ();
\r
99 if (bounds.Height <= 0 || bounds.Width <= 0 || numTicks <= 0)
\r
102 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Ticks.Normal);
\r
104 double x = bounds.Left;
\r
105 double delta = (double)(bounds.Width - 2) / (double)(numTicks-1);
\r
107 for(int i = 0; i < numTicks; i++)
\r
109 vsr.DrawEdge(g, new Rectangle((int)Math.Round(x), bounds.Top, 5, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None);
\r
114 public static void DrawHorizontalTrack(Graphics g, Rectangle bounds)
\r
117 throw new InvalidOperationException ();
\r
119 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Track.Normal);
\r
121 vsr.DrawBackground (g, bounds);
\r
124 public static void DrawLeftPointingThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
\r
127 throw new InvalidOperationException ();
\r
129 VisualStyleRenderer vsr;
\r
132 case TrackBarThumbState.Disabled:
\r
133 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Disabled);
\r
135 case TrackBarThumbState.Hot:
\r
136 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Hot);
\r
138 case TrackBarThumbState.Normal:
\r
140 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Normal);
\r
142 case TrackBarThumbState.Pressed:
\r
143 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Pressed);
\r
147 vsr.DrawBackground (g, bounds);
\r
150 public static void DrawRightPointingThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
\r
153 throw new InvalidOperationException ();
\r
155 VisualStyleRenderer vsr;
\r
158 case TrackBarThumbState.Disabled:
\r
159 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Disabled);
\r
161 case TrackBarThumbState.Hot:
\r
162 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Hot);
\r
164 case TrackBarThumbState.Normal:
\r
166 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Normal);
\r
168 case TrackBarThumbState.Pressed:
\r
169 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Pressed);
\r
173 vsr.DrawBackground (g, bounds);
\r
176 public static void DrawTopPointingThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
\r
179 throw new InvalidOperationException ();
\r
181 VisualStyleRenderer vsr;
\r
184 case TrackBarThumbState.Disabled:
\r
185 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Disabled);
\r
187 case TrackBarThumbState.Hot:
\r
188 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Hot);
\r
190 case TrackBarThumbState.Normal:
\r
192 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Normal);
\r
194 case TrackBarThumbState.Pressed:
\r
195 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Pressed);
\r
199 vsr.DrawBackground (g, bounds);
\r
202 public static void DrawVerticalThumb (Graphics g, Rectangle bounds, TrackBarThumbState state)
\r
205 throw new InvalidOperationException ();
\r
207 VisualStyleRenderer vsr;
\r
210 case TrackBarThumbState.Disabled:
\r
211 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Disabled);
\r
213 case TrackBarThumbState.Hot:
\r
214 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Hot);
\r
216 case TrackBarThumbState.Normal:
\r
218 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Normal);
\r
220 case TrackBarThumbState.Pressed:
\r
221 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbVertical.Pressed);
\r
225 vsr.DrawBackground (g, bounds);
\r
228 public static void DrawVerticalTicks (Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle)
\r
231 throw new InvalidOperationException ();
\r
233 if (bounds.Height <= 0 || bounds.Width <= 0 || numTicks <= 0)
\r
236 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.TicksVertical.Normal);
\r
238 double y = bounds.Top;
\r
239 double delta = (double)(bounds.Height - 2) / (double)(numTicks - 1);
\r
241 for (int i = 0; i < numTicks; i++) {
\r
242 vsr.DrawEdge (g, new Rectangle (bounds.Left, (int)Math.Round (y), bounds.Width, 5), Edges.Top, edgeStyle, EdgeEffects.None);
\r
247 public static void DrawVerticalTrack (Graphics g, Rectangle bounds)
\r
250 throw new InvalidOperationException ();
\r
252 VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.Track.Normal);
\r
254 vsr.DrawBackground (g, bounds);
\r
257 public static Size GetBottomPointingThumbSize(Graphics g, TrackBarThumbState state)
\r
260 throw new InvalidOperationException ();
\r
262 VisualStyleRenderer vsr;
\r
265 case TrackBarThumbState.Disabled:
\r
266 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Disabled);
\r
268 case TrackBarThumbState.Hot:
\r
269 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Hot);
\r
271 case TrackBarThumbState.Normal:
\r
273 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Normal);
\r
275 case TrackBarThumbState.Pressed:
\r
276 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Pressed);
\r
280 return vsr.GetPartSize (g, ThemeSizeType.Draw);
\r
283 public static Size GetLeftPointingThumbSize (Graphics g, TrackBarThumbState state)
\r
286 throw new InvalidOperationException ();
\r
288 VisualStyleRenderer vsr;
\r
291 case TrackBarThumbState.Disabled:
\r
292 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Disabled);
\r
294 case TrackBarThumbState.Hot:
\r
295 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Hot);
\r
297 case TrackBarThumbState.Normal:
\r
299 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Normal);
\r
301 case TrackBarThumbState.Pressed:
\r
302 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbLeft.Pressed);
\r
306 return vsr.GetPartSize (g, ThemeSizeType.Draw);
\r
309 public static Size GetRightPointingThumbSize (Graphics g, TrackBarThumbState state)
\r
312 throw new InvalidOperationException ();
\r
314 VisualStyleRenderer vsr;
\r
317 case TrackBarThumbState.Disabled:
\r
318 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Disabled);
\r
320 case TrackBarThumbState.Hot:
\r
321 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Hot);
\r
323 case TrackBarThumbState.Normal:
\r
325 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Normal);
\r
327 case TrackBarThumbState.Pressed:
\r
328 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbRight.Pressed);
\r
332 return vsr.GetPartSize (g, ThemeSizeType.Draw);
\r
335 public static Size GetTopPointingThumbSize (Graphics g, TrackBarThumbState state)
\r
338 throw new InvalidOperationException ();
\r
340 VisualStyleRenderer vsr;
\r
343 case TrackBarThumbState.Disabled:
\r
344 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Disabled);
\r
346 case TrackBarThumbState.Hot:
\r
347 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Hot);
\r
349 case TrackBarThumbState.Normal:
\r
351 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Normal);
\r
353 case TrackBarThumbState.Pressed:
\r
354 vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Pressed);
\r
358 return vsr.GetPartSize (g, ThemeSizeType.Draw);
\r
362 #region Public Static Properties
\r
363 public static bool IsSupported {
\r
364 get { return VisualStyleInformation.IsEnabledByUser && (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled || Application.VisualStyleState == VisualStyleState.ClientAreaEnabled); }
\r