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
21 // Copyright (c) 2004-2006 Novell, Inc.
24 // George Giolfan, georgegiolfan@yahoo.com
25 // Ernesto Carrea, equistango@gmail.com
28 using System.Drawing.Drawing2D;
29 using System.Windows.Forms.VisualStyles;
31 namespace System.Windows.Forms
34 /// VisualStyles theme.
37 /// This theme uses only the managed VisualStyles API.
38 /// To select it, set MONO_THEME to VisualStyles and call <see cref="Application.EnableVisualStyles"/>.
40 class ThemeVisualStyles : ThemeWin32Classic
42 static bool render_client_areas;
43 static bool render_non_client_areas;
45 public ThemeVisualStyles ()
50 public override void ResetDefaults ()
52 base.ResetDefaults ();
58 bool visual_styles_is_enabled_by_user = VisualStyleInformation.IsEnabledByUser;
60 visual_styles_is_enabled_by_user &&
61 (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled ||
62 Application.VisualStyleState == VisualStyleState.ClientAreaEnabled);
63 render_non_client_areas =
64 visual_styles_is_enabled_by_user &&
65 (Application.VisualStyleState == VisualStyleState.ClientAndNonClientAreasEnabled/* ||
66 Application.VisualStyleState == VisualStyleState.NonClientAreaEnabled*/);
69 public static bool RenderClientAreas {
70 get { return render_client_areas; }
75 public override void DrawButtonBase (Graphics dc, Rectangle clip_area, ButtonBase button)
77 if (button.FlatStyle == FlatStyle.System) {
78 ButtonRenderer.DrawButton (
80 new Rectangle (Point.Empty, button.Size),
83 button.TextFormatFlags,
86 ShouldPaintFocusRectagle (button),
87 GetPushButtonState (button)
91 base.DrawButtonBase (dc, clip_area, button);
93 static PushButtonState GetPushButtonState (ButtonBase button)
96 return PushButtonState.Disabled;
98 return PushButtonState.Pressed;
100 return PushButtonState.Hot;
101 if (button.IsDefault || button.Focused || button.paint_as_acceptbutton)
102 return PushButtonState.Default;
103 return PushButtonState.Normal;
108 public override void DrawButtonBackground (Graphics g, Button button, Rectangle clipArea)
110 if (!RenderClientAreas ||
111 !button.UseVisualStyleBackColor) {
112 base.DrawButtonBackground (g, button, clipArea);
115 ButtonRenderer.GetPushButtonRenderer (GetPushButtonState (button)).DrawBackground (g, new Rectangle (Point.Empty, button.Size));
120 protected override void CheckBox_DrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
122 if (checkbox.Appearance == Appearance.Normal && checkbox.FlatStyle == FlatStyle.System) {
123 CheckBoxRenderer.DrawCheckBox (
125 new Point (checkbox_rectangle.Left, checkbox_rectangle.Top),
126 GetCheckBoxState (checkbox)
130 base.CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
132 static CheckBoxState GetCheckBoxState (CheckBox checkBox)
134 switch (checkBox.CheckState) {
135 case CheckState.Checked:
136 if (!checkBox.Enabled)
137 return CheckBoxState.CheckedDisabled;
138 else if (checkBox.Pressed)
139 return CheckBoxState.CheckedPressed;
140 else if (checkBox.Entered)
141 return CheckBoxState.CheckedHot;
142 return CheckBoxState.CheckedNormal;
143 case CheckState.Indeterminate:
144 if (!checkBox.Enabled)
145 return CheckBoxState.MixedDisabled;
146 else if (checkBox.Pressed)
147 return CheckBoxState.MixedPressed;
148 else if (checkBox.Entered)
149 return CheckBoxState.MixedHot;
150 return CheckBoxState.MixedNormal;
152 if (!checkBox.Enabled)
153 return CheckBoxState.UncheckedDisabled;
154 else if (checkBox.Pressed)
155 return CheckBoxState.UncheckedPressed;
156 else if (checkBox.Entered)
157 return CheckBoxState.UncheckedHot;
158 return CheckBoxState.UncheckedNormal;
163 static VisualStyleElement ComboBoxGetVisualStyleElement (ComboBox comboBox, ButtonState state)
165 if (state == ButtonState.Inactive)
166 return VisualStyleElement.ComboBox.DropDownButton.Disabled;
167 if (state == ButtonState.Pushed)
168 return VisualStyleElement.ComboBox.DropDownButton.Pressed;
169 if (comboBox.DropDownButtonEntered)
170 return VisualStyleElement.ComboBox.DropDownButton.Hot;
171 return VisualStyleElement.ComboBox.DropDownButton.Normal;
173 public override void ComboBoxDrawNormalDropDownButton (ComboBox comboBox, Graphics g, Rectangle clippingArea, Rectangle area, ButtonState state)
175 if (!RenderClientAreas) {
176 base.ComboBoxDrawNormalDropDownButton (comboBox, g, clippingArea, area, state);
179 VisualStyleElement element = ComboBoxGetVisualStyleElement (comboBox, state);
180 if (!VisualStyleRenderer.IsElementDefined (element)) {
181 base.ComboBoxDrawNormalDropDownButton (comboBox, g, clippingArea, area, state);
184 new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
186 public override bool ComboBoxNormalDropDownButtonHasTransparentBackground (ComboBox comboBox, ButtonState state)
188 if (!RenderClientAreas)
189 return base.ComboBoxNormalDropDownButtonHasTransparentBackground (comboBox, state);
190 VisualStyleElement element = ComboBoxGetVisualStyleElement (comboBox, state);
191 if (!VisualStyleRenderer.IsElementDefined (element))
192 return base.ComboBoxNormalDropDownButtonHasTransparentBackground (comboBox, state);
193 return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
195 public override bool ComboBoxDropDownButtonHasHotElementStyle (ComboBox comboBox)
197 if (!RenderClientAreas)
198 return base.ComboBoxDropDownButtonHasHotElementStyle (comboBox);
199 switch (comboBox.FlatStyle) {
201 case FlatStyle.Popup:
202 return base.ComboBoxDropDownButtonHasHotElementStyle (comboBox);
206 static bool ComboBoxShouldPaintBackground (ComboBox comboBox)
208 if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
210 switch (comboBox.FlatStyle) {
212 case FlatStyle.Popup:
217 public override void ComboBoxDrawBackground (ComboBox comboBox, Graphics g, Rectangle clippingArea, FlatStyle style)
219 if (!RenderClientAreas || !ComboBoxShouldPaintBackground (comboBox)) {
220 base.ComboBoxDrawBackground (comboBox, g, clippingArea, style);
223 VisualStyleElement element;
224 if (!comboBox.Enabled)
225 element = VisualStyleElement.ComboBox.Border.Disabled;
226 else if (comboBox.Entered)
227 element = VisualStyleElement.ComboBox.Border.Hot;
228 else if (comboBox.Focused)
229 element = VisualStyleElement.ComboBox.Border.Focused;
231 element = VisualStyleElement.ComboBox.Border.Normal;
232 if (!VisualStyleRenderer.IsElementDefined (element)) {
233 base.ComboBoxDrawBackground (comboBox, g, clippingArea, style);
236 new VisualStyleRenderer (element).DrawBackground (g, new Rectangle (Point.Empty, comboBox.Size), clippingArea);
238 public override bool CombBoxBackgroundHasHotElementStyle (ComboBox comboBox)
240 if (RenderClientAreas &&
241 ComboBoxShouldPaintBackground (comboBox) &&
243 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ComboBox.Border.Hot))
245 return base.CombBoxBackgroundHasHotElementStyle (comboBox);
250 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
252 if (!RenderClientAreas ||
253 (state & ButtonState.Flat) == ButtonState.Flat ||
254 (state & ButtonState.Checked) == ButtonState.Checked) {
255 base.CPDrawButton (dc, rectangle, state);
258 VisualStyleElement element;
259 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
260 element = VisualStyleElement.Button.PushButton.Disabled;
261 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
262 element = VisualStyleElement.Button.PushButton.Pressed;
264 element = VisualStyleElement.Button.PushButton.Normal;
265 if (!VisualStyleRenderer.IsElementDefined (element)) {
266 base.CPDrawButton (dc, rectangle, state);
269 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
272 #region DrawCaptionButton
273 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state)
275 if (!RenderClientAreas ||
276 (state & ButtonState.Flat) == ButtonState.Flat ||
277 (state & ButtonState.Checked) == ButtonState.Checked) {
278 base.CPDrawCaptionButton (graphics, rectangle, button, state);
281 VisualStyleElement element = GetCaptionButtonVisualStyleElement (button, state);
282 if (!VisualStyleRenderer.IsElementDefined (element)) {
283 base.CPDrawCaptionButton (graphics, rectangle, button, state);
286 new VisualStyleRenderer (element).DrawBackground (graphics, rectangle);
288 static VisualStyleElement GetCaptionButtonVisualStyleElement (CaptionButton button, ButtonState state)
291 case CaptionButton.Minimize:
292 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
293 return VisualStyleElement.Window.MinButton.Disabled;
294 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
295 return VisualStyleElement.Window.MinButton.Pressed;
297 return VisualStyleElement.Window.MinButton.Normal;
298 case CaptionButton.Maximize:
299 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
300 return VisualStyleElement.Window.MaxButton.Disabled;
301 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
302 return VisualStyleElement.Window.MaxButton.Pressed;
304 return VisualStyleElement.Window.MaxButton.Normal;
305 case CaptionButton.Close:
306 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
307 return VisualStyleElement.Window.CloseButton.Disabled;
308 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
309 return VisualStyleElement.Window.CloseButton.Pressed;
311 return VisualStyleElement.Window.CloseButton.Normal;
312 case CaptionButton.Restore:
313 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
314 return VisualStyleElement.Window.RestoreButton.Disabled;
315 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
316 return VisualStyleElement.Window.RestoreButton.Pressed;
318 return VisualStyleElement.Window.RestoreButton.Normal;
320 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
321 return VisualStyleElement.Window.HelpButton.Disabled;
322 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
323 return VisualStyleElement.Window.HelpButton.Pressed;
325 return VisualStyleElement.Window.HelpButton.Normal;
330 public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
332 if (!RenderClientAreas ||
333 (state & ButtonState.Flat) == ButtonState.Flat) {
334 base.CPDrawCheckBox (dc, rectangle, state);
337 VisualStyleElement element;
338 if ((state & ButtonState.Checked) == ButtonState.Checked)
339 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
340 element = VisualStyleElement.Button.CheckBox.CheckedDisabled;
341 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
342 element = VisualStyleElement.Button.CheckBox.CheckedPressed;
344 element = VisualStyleElement.Button.CheckBox.CheckedNormal;
346 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
347 element = VisualStyleElement.Button.CheckBox.UncheckedDisabled;
348 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
349 element = VisualStyleElement.Button.CheckBox.UncheckedPressed;
351 element = VisualStyleElement.Button.CheckBox.UncheckedNormal;
352 if (!VisualStyleRenderer.IsElementDefined (element)) {
353 base.CPDrawCheckBox (dc, rectangle, state);
356 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
359 #region DrawComboButton
360 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
362 if (!RenderClientAreas ||
363 (state & ButtonState.Flat) == ButtonState.Flat ||
364 (state & ButtonState.Checked) == ButtonState.Checked) {
365 base.CPDrawComboButton (graphics, rectangle, state);
368 VisualStyleElement element;
369 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
370 element = VisualStyleElement.ComboBox.DropDownButton.Disabled;
371 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
372 element = VisualStyleElement.ComboBox.DropDownButton.Pressed;
374 element = VisualStyleElement.ComboBox.DropDownButton.Normal;
375 if (!VisualStyleRenderer.IsElementDefined (element)) {
376 base.CPDrawComboButton (graphics, rectangle, state);
379 new VisualStyleRenderer (element).DrawBackground (graphics, rectangle);
382 #region DrawMixedCheckBox
383 public override void CPDrawMixedCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
385 if (!RenderClientAreas ||
386 (state & ButtonState.Flat) == ButtonState.Flat) {
387 base.CPDrawMixedCheckBox (dc, rectangle, state);
390 VisualStyleElement element;
391 if ((state & ButtonState.Checked) == ButtonState.Checked)
392 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
393 element = VisualStyleElement.Button.CheckBox.MixedDisabled;
394 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
395 element = VisualStyleElement.Button.CheckBox.MixedPressed;
397 element = VisualStyleElement.Button.CheckBox.MixedNormal;
399 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
400 element = VisualStyleElement.Button.CheckBox.UncheckedDisabled;
401 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
402 element = VisualStyleElement.Button.CheckBox.UncheckedPressed;
404 element = VisualStyleElement.Button.CheckBox.UncheckedNormal;
405 if (!VisualStyleRenderer.IsElementDefined (element)) {
406 base.CPDrawMixedCheckBox (dc, rectangle, state);
409 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
412 #region DrawRadioButton
413 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
415 if (!RenderClientAreas ||
416 (state & ButtonState.Flat) == ButtonState.Flat) {
417 base.CPDrawRadioButton (dc, rectangle, state);
420 VisualStyleElement element;
421 if ((state & ButtonState.Checked) == ButtonState.Checked)
422 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
423 element = VisualStyleElement.Button.RadioButton.CheckedDisabled;
424 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
425 element = VisualStyleElement.Button.RadioButton.CheckedPressed;
427 element = VisualStyleElement.Button.RadioButton.CheckedNormal;
429 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
430 element = VisualStyleElement.Button.RadioButton.UncheckedDisabled;
431 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
432 element = VisualStyleElement.Button.RadioButton.UncheckedPressed;
434 element = VisualStyleElement.Button.RadioButton.UncheckedNormal;
435 if (!VisualStyleRenderer.IsElementDefined (element)) {
436 base.CPDrawRadioButton (dc, rectangle, state);
439 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
442 #region DrawScrollButton
443 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
445 if (!RenderClientAreas ||
446 (state & ButtonState.Flat) == ButtonState.Flat ||
447 (state & ButtonState.Checked) == ButtonState.Checked) {
448 base.CPDrawScrollButton (dc, area, type, state);
451 VisualStyleElement element = GetScrollButtonVisualStyleElement (type, state);
452 if (!VisualStyleRenderer.IsElementDefined (element)) {
453 base.CPDrawScrollButton (dc, area, type, state);
456 new VisualStyleRenderer (element).DrawBackground (dc, area);
458 static VisualStyleElement GetScrollButtonVisualStyleElement (ScrollButton type, ButtonState state)
461 case ScrollButton.Left:
462 if (IsDisabled (state))
463 return VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled;
464 else if (IsPressed (state))
465 return VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
467 return VisualStyleElement.ScrollBar.ArrowButton.LeftNormal;
468 case ScrollButton.Right:
469 if (IsDisabled (state))
470 return VisualStyleElement.ScrollBar.ArrowButton.RightDisabled;
471 else if (IsPressed (state))
472 return VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
474 return VisualStyleElement.ScrollBar.ArrowButton.RightNormal;
475 case ScrollButton.Up:
476 if (IsDisabled (state))
477 return VisualStyleElement.ScrollBar.ArrowButton.UpDisabled;
478 else if (IsPressed (state))
479 return VisualStyleElement.ScrollBar.ArrowButton.UpPressed;
481 return VisualStyleElement.ScrollBar.ArrowButton.UpNormal;
483 if (IsDisabled (state))
484 return VisualStyleElement.ScrollBar.ArrowButton.DownDisabled;
485 else if (IsPressed (state))
486 return VisualStyleElement.ScrollBar.ArrowButton.DownPressed;
488 return VisualStyleElement.ScrollBar.ArrowButton.DownNormal;
491 static bool IsDisabled (ButtonState state)
493 return (state & ButtonState.Inactive) == ButtonState.Inactive;
495 static bool IsPressed (ButtonState state)
497 return (state & ButtonState.Pushed) == ButtonState.Pushed;
503 #region DataGridViewHeaderCell
504 #region DataGridViewRowHeaderCell
505 public override bool DataGridViewRowHeaderCellDrawBackground (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
507 if (!RenderClientAreas ||
508 !cell.DataGridView.EnableHeadersVisualStyles)
509 return base.DataGridViewRowHeaderCellDrawBackground (cell, g, bounds);
510 VisualStyleElement element = DataGridViewRowHeaderCellGetVisualStyleElement (cell);
511 if (!VisualStyleRenderer.IsElementDefined (element))
512 return base.DataGridViewRowHeaderCellDrawBackground (cell, g, bounds);
514 Bitmap bitmap = new Bitmap (bounds.Height, bounds.Width);
515 Graphics bitmap_g = Graphics.FromImage (bitmap);
516 Rectangle bitmap_rectangle = new Rectangle (Point.Empty, bitmap.Size);
517 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
518 if (!AreEqual (element, VisualStyleElement.Header.Item.Normal) && renderer.IsBackgroundPartiallyTransparent ())
519 new VisualStyleRenderer (VisualStyleElement.Header.Item.Normal).DrawBackground (bitmap_g, bitmap_rectangle);
520 renderer.DrawBackground (bitmap_g, bitmap_rectangle);
522 g.Transform = new Matrix(0, 1, 1, 0, 0, 0);
523 g.DrawImage (bitmap, bounds.Y, bounds.X);
528 public override bool DataGridViewRowHeaderCellDrawSelectionBackground (DataGridViewRowHeaderCell cell)
530 if (!RenderClientAreas ||
531 !cell.DataGridView.EnableHeadersVisualStyles || !VisualStyleRenderer.IsElementDefined (DataGridViewRowHeaderCellGetVisualStyleElement (cell)))
532 return base.DataGridViewRowHeaderCellDrawSelectionBackground (cell);
535 public override bool DataGridViewRowHeaderCellDrawBorder (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
537 if (!RenderClientAreas ||
538 !cell.DataGridView.EnableHeadersVisualStyles || !VisualStyleRenderer.IsElementDefined (DataGridViewRowHeaderCellGetVisualStyleElement (cell)))
539 return base.DataGridViewRowHeaderCellDrawBorder (cell, g, bounds);
540 g.DrawLine (cell.GetBorderPen (), bounds.Right - 1, bounds.Top, bounds.Right - 1, bounds.Bottom - 1);
543 static VisualStyleElement DataGridViewRowHeaderCellGetVisualStyleElement (DataGridViewRowHeaderCell cell)
545 if (cell.DataGridView.PressedHeaderCell == cell)
546 return VisualStyleElement.Header.Item.Pressed;
547 if (cell.DataGridView.EnteredHeaderCell == cell)
548 return VisualStyleElement.Header.Item.Hot;
549 if (cell.OwningRow.SelectedInternal)
550 return VisualStyleElement.Header.Item.Pressed;
551 return VisualStyleElement.Header.Item.Normal;
554 #region DataGridViewColumnHeaderCell
555 public override bool DataGridViewColumnHeaderCellDrawBackground (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
557 if (!RenderClientAreas ||
558 !cell.DataGridView.EnableHeadersVisualStyles || cell is DataGridViewTopLeftHeaderCell)
559 return base.DataGridViewColumnHeaderCellDrawBackground (cell, g, bounds);
560 VisualStyleElement element = DataGridViewColumnHeaderCellGetVisualStyleElement (cell);
561 if (!VisualStyleRenderer.IsElementDefined (element))
562 return base.DataGridViewColumnHeaderCellDrawBackground (cell, g, bounds);
564 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
565 if (!AreEqual (element, VisualStyleElement.Header.Item.Normal) && renderer.IsBackgroundPartiallyTransparent ())
566 new VisualStyleRenderer (VisualStyleElement.Header.Item.Normal).DrawBackground (g, bounds);
567 renderer.DrawBackground (g, bounds);
570 public override bool DataGridViewColumnHeaderCellDrawBorder (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
572 if (!RenderClientAreas ||
573 !cell.DataGridView.EnableHeadersVisualStyles ||
574 cell is DataGridViewTopLeftHeaderCell ||
575 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Normal))
576 return base.DataGridViewColumnHeaderCellDrawBorder (cell, g, bounds);
577 g.DrawLine (cell.GetBorderPen (), bounds.Left, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
580 static VisualStyleElement DataGridViewColumnHeaderCellGetVisualStyleElement (DataGridViewColumnHeaderCell cell)
582 if (cell.DataGridView.PressedHeaderCell == cell)
583 return VisualStyleElement.Header.Item.Pressed;
584 if (cell.DataGridView.EnteredHeaderCell == cell)
585 return VisualStyleElement.Header.Item.Hot;
586 return VisualStyleElement.Header.Item.Normal;
589 public override bool DataGridViewHeaderCellHasPressedStyle (DataGridView dataGridView)
591 if (!RenderClientAreas ||
592 !dataGridView.EnableHeadersVisualStyles ||
593 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Pressed))
594 return base.DataGridViewHeaderCellHasPressedStyle (dataGridView);
597 public override bool DataGridViewHeaderCellHasHotStyle (DataGridView dataGridView)
599 if (!RenderClientAreas ||
600 !dataGridView.EnableHeadersVisualStyles ||
601 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Hot))
602 return base.DataGridViewHeaderCellHasHotStyle (dataGridView);
608 #region DateTimePicker
610 protected override void DateTimePickerDrawBorder (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
612 if (!RenderClientAreas) {
613 base.DateTimePickerDrawBorder (dateTimePicker, g, clippingArea);
616 VisualStyleElement element;
617 if (!dateTimePicker.Enabled)
618 element = VisualStyleElement.DatePicker.DateBorder.Disabled;
619 else if (dateTimePicker.Entered)
620 element = VisualStyleElement.DatePicker.DateBorder.Hot;
621 else if (dateTimePicker.Focused)
622 element = VisualStyleElement.DatePicker.DateBorder.Focused;
624 element = VisualStyleElement.DatePicker.DateBorder.Normal;
625 if (!VisualStyleRenderer.IsElementDefined (element)) {
626 base.DateTimePickerDrawBorder (dateTimePicker, g, clippingArea);
629 new VisualStyleRenderer (element).DrawBackground (g, new Rectangle (Point.Empty, dateTimePicker.Size), clippingArea);
631 public override bool DateTimePickerBorderHasHotElementStyle {
633 if (RenderClientAreas &&
634 VisualStyleRenderer.IsElementDefined (VisualStyleElement.DatePicker.DateBorder.Hot))
636 return base.DateTimePickerBorderHasHotElementStyle;
640 #region Drop down button
641 protected override void DateTimePickerDrawDropDownButton (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
643 if (!RenderClientAreas) {
644 base.DateTimePickerDrawDropDownButton (dateTimePicker, g, clippingArea);
647 VisualStyleElement element;
648 if (!dateTimePicker.Enabled)
649 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Disabled;
650 else if (dateTimePicker.is_drop_down_visible)
651 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Pressed;
652 else if (dateTimePicker.DropDownButtonEntered)
653 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Hot;
655 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Normal;
656 if (!VisualStyleRenderer.IsElementDefined (element)) {
657 base.DateTimePickerDrawDropDownButton (dateTimePicker, g, clippingArea);
660 new VisualStyleRenderer (element).DrawBackground (g, dateTimePicker.drop_down_arrow_rect, clippingArea);
662 //TODO: Until somebody figures out how to obtain the proper width this will need to be updated when new Windows versions/themes are released.
663 const int DateTimePickerDropDownWidthOnWindowsVista = 34;
664 const int DateTimePickerDropDownHeightOnWindowsVista = 20;
665 public override Rectangle DateTimePickerGetDropDownButtonArea (DateTimePicker dateTimePicker)
667 if (!RenderClientAreas)
668 return base.DateTimePickerGetDropDownButtonArea (dateTimePicker);
669 VisualStyleElement element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Pressed;
670 if (!VisualStyleRenderer.IsElementDefined (element))
671 return base.DateTimePickerGetDropDownButtonArea (dateTimePicker);
672 Size size = new Size (DateTimePickerDropDownWidthOnWindowsVista, DateTimePickerDropDownHeightOnWindowsVista);
673 return new Rectangle (dateTimePicker.Width - size.Width, 0, size.Width, size.Height);
675 public override Rectangle DateTimePickerGetDateArea (DateTimePicker dateTimePicker)
677 if (!RenderClientAreas ||
678 dateTimePicker.ShowUpDown)
679 return base.DateTimePickerGetDateArea (dateTimePicker);
680 VisualStyleElement element = VisualStyleElement.DatePicker.DateBorder.Normal;
681 if (!VisualStyleRenderer.IsElementDefined (element))
682 return base.DateTimePickerGetDateArea (dateTimePicker);
683 Graphics g = dateTimePicker.CreateGraphics ();
684 Rectangle result = new VisualStyleRenderer (element).GetBackgroundContentRectangle (g, dateTimePicker.ClientRectangle);
686 result.Width -= DateTimePickerDropDownWidthOnWindowsVista;
689 public override bool DateTimePickerDropDownButtonHasHotElementStyle {
691 if (RenderClientAreas &&
692 VisualStyleRenderer.IsElementDefined (VisualStyleElement.DatePicker.ShowCalendarButtonRight.Hot))
694 return base.DateTimePickerDropDownButtonHasHotElementStyle;
700 protected override void ListViewDrawColumnHeaderBackground (ListView listView, ColumnHeader columnHeader, Graphics g, Rectangle area, Rectangle clippingArea)
702 if (!RenderClientAreas) {
703 base.ListViewDrawColumnHeaderBackground (listView, columnHeader, g, area, clippingArea);
706 VisualStyleElement element;
707 if (listView.HeaderStyle == ColumnHeaderStyle.Clickable)
708 if (columnHeader.Pressed)
709 element = VisualStyleElement.Header.Item.Pressed;
710 else if (columnHeader == listView.EnteredColumnHeader)
711 element = VisualStyleElement.Header.Item.Hot;
713 element = VisualStyleElement.Header.Item.Normal;
715 element = VisualStyleElement.Header.Item.Normal;
716 if (!VisualStyleRenderer.IsElementDefined (element)) {
717 base.ListViewDrawColumnHeaderBackground (listView, columnHeader, g, area, clippingArea);
720 new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
722 protected override void ListViewDrawUnusedHeaderBackground (ListView listView, Graphics g, Rectangle area, Rectangle clippingArea)
724 if (!RenderClientAreas) {
725 base.ListViewDrawUnusedHeaderBackground (listView, g, area, clippingArea);
728 VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
729 if (!VisualStyleRenderer.IsElementDefined (element)) {
730 base.ListViewDrawUnusedHeaderBackground (listView, g, area, clippingArea);
733 new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
735 public override bool ListViewHasHotHeaderStyle {
737 if (!RenderClientAreas ||
738 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Hot))
739 return base.ListViewHasHotHeaderStyle;
743 public override int ListViewGetHeaderHeight (ListView listView, Font font)
745 if (!RenderClientAreas)
746 return base.ListViewGetHeaderHeight (listView, font);
747 VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
748 if (!VisualStyleRenderer.IsElementDefined (element))
749 return base.ListViewGetHeaderHeight (listView, font);
750 Control control = null;
752 if (listView == null) {
753 control = new Control ();
754 g = control.CreateGraphics ();
756 g = listView.CreateGraphics ();
757 int result = new VisualStyleRenderer (element).GetPartSize (g, ThemeSizeType.True).Height;
759 if (listView == null)
765 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box)
767 GroupBoxRenderer.DrawGroupBox (
769 new Rectangle (Point.Empty, box.Size),
772 box.ForeColor == GroupBox.DefaultForeColor ? Color.Empty : box.ForeColor,
773 box.Enabled ? GroupBoxState.Normal : GroupBoxState.Disabled);
776 #region Managed window
777 Rectangle ManagedWindowGetTitleBarRectangle (InternalWindowManager wm)
779 return new Rectangle (0, 0, wm.Form.Width, ManagedWindowTitleBarHeight (wm) + ManagedWindowBorderWidth (wm) * (wm.IsMinimized ? 2 : 1));
781 Region ManagedWindowGetWindowRegion (Form form)
783 if (form.WindowManager is MdiWindowManager && form.WindowManager.IsMaximized)
785 VisualStyleElement title_bar_element = ManagedWindowGetTitleBarVisualStyleElement (form.WindowManager);
786 if (!VisualStyleRenderer.IsElementDefined (title_bar_element))
788 VisualStyleRenderer renderer = new VisualStyleRenderer (title_bar_element);
789 if (!renderer.IsBackgroundPartiallyTransparent ())
791 IDeviceContext dc = GetMeasurementDeviceContext ();
792 Rectangle title_bar_rectangle = ManagedWindowGetTitleBarRectangle (form.WindowManager);
793 Region region = renderer.GetBackgroundRegion (dc, title_bar_rectangle);
794 ReleaseMeasurementDeviceContext (dc);
795 region.Union (new Rectangle (0, title_bar_rectangle.Bottom, form.Width, form.Height));
798 public override void ManagedWindowOnSizeInitializedOrChanged (Form form)
800 base.ManagedWindowOnSizeInitializedOrChanged (form);
801 if (!render_non_client_areas)
803 form.Region = ManagedWindowGetWindowRegion (form);
805 protected override Rectangle ManagedWindowDrawTitleBarAndBorders (Graphics dc, Rectangle clip, InternalWindowManager wm)
807 if (!render_non_client_areas)
808 return base.ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
809 VisualStyleElement title_bar_element = ManagedWindowGetTitleBarVisualStyleElement (wm);
810 VisualStyleElement left_border_element;
811 VisualStyleElement right_border_element;
812 VisualStyleElement bottom_border_element;
813 ManagedWindowGetBorderVisualStyleElements (wm, out left_border_element, out right_border_element, out bottom_border_element);
814 if (!VisualStyleRenderer.IsElementDefined (title_bar_element) ||
815 (!wm.IsMinimized && (
816 !VisualStyleRenderer.IsElementDefined (left_border_element) ||
817 !VisualStyleRenderer.IsElementDefined (right_border_element) ||
818 !VisualStyleRenderer.IsElementDefined (bottom_border_element))))
819 return base.ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
820 VisualStyleRenderer renderer = new VisualStyleRenderer (title_bar_element);
821 Rectangle title_bar_rectangle = ManagedWindowGetTitleBarRectangle (wm);
822 renderer.DrawBackground (dc, title_bar_rectangle, clip);
823 if (!wm.IsMinimized) {
824 int border_width = ManagedWindowBorderWidth (wm);
825 renderer.SetParameters (left_border_element);
826 renderer.DrawBackground (dc, new Rectangle (
828 title_bar_rectangle.Bottom,
830 wm.Form.Height - title_bar_rectangle.Bottom
832 renderer.SetParameters (right_border_element);
833 renderer.DrawBackground (dc, new Rectangle (
834 wm.Form.Width - border_width,
835 title_bar_rectangle.Bottom,
837 wm.Form.Height - title_bar_rectangle.Bottom
839 renderer.SetParameters (bottom_border_element);
840 renderer.DrawBackground (dc, new Rectangle (
842 wm.Form.Height - border_width,
847 return title_bar_rectangle;
849 static FormWindowState ManagedWindowGetWindowState (InternalWindowManager wm)
851 return wm.GetWindowState ();
853 static bool ManagedWindowIsDisabled (InternalWindowManager wm)
855 return !wm.Form.Enabled;
857 static bool ManagedWindowIsActive (InternalWindowManager wm)
861 static VisualStyleElement ManagedWindowGetTitleBarVisualStyleElement (InternalWindowManager wm)
865 switch (ManagedWindowGetWindowState (wm)) {
866 case FormWindowState.Minimized:
867 if (ManagedWindowIsDisabled (wm))
868 return VisualStyleElement.Window.SmallMinCaption.Disabled;
869 else if (ManagedWindowIsActive (wm))
870 return VisualStyleElement.Window.SmallMinCaption.Active;
871 return VisualStyleElement.Window.SmallMinCaption.Inactive;
872 case FormWindowState.Maximized:
873 if (ManagedWindowIsDisabled (wm))
874 return VisualStyleElement.Window.SmallMaxCaption.Disabled;
875 else if (ManagedWindowIsActive (wm))
876 return VisualStyleElement.Window.SmallMaxCaption.Active;
877 return VisualStyleElement.Window.SmallMaxCaption.Inactive;
879 if (ManagedWindowIsDisabled (wm))
880 return VisualStyleElement.Window.SmallCaption.Disabled;
881 else if (ManagedWindowIsActive (wm))
882 return VisualStyleElement.Window.SmallCaption.Active;
883 return VisualStyleElement.Window.SmallCaption.Inactive;
887 #region Normal window
888 switch (ManagedWindowGetWindowState (wm)) {
889 case FormWindowState.Minimized:
890 if (ManagedWindowIsDisabled (wm))
891 return VisualStyleElement.Window.MinCaption.Disabled;
892 else if (ManagedWindowIsActive (wm))
893 return VisualStyleElement.Window.MinCaption.Active;
894 return VisualStyleElement.Window.MinCaption.Inactive;
895 case FormWindowState.Maximized:
896 if (ManagedWindowIsDisabled (wm))
897 return VisualStyleElement.Window.MaxCaption.Disabled;
898 else if (ManagedWindowIsActive (wm))
899 return VisualStyleElement.Window.MaxCaption.Active;
900 return VisualStyleElement.Window.MaxCaption.Inactive;
902 if (ManagedWindowIsDisabled (wm))
903 return VisualStyleElement.Window.Caption.Disabled;
904 else if (ManagedWindowIsActive (wm))
905 return VisualStyleElement.Window.Caption.Active;
906 return VisualStyleElement.Window.Caption.Inactive;
910 static void ManagedWindowGetBorderVisualStyleElements (InternalWindowManager wm, out VisualStyleElement left, out VisualStyleElement right, out VisualStyleElement bottom)
912 bool active = !ManagedWindowIsDisabled (wm) && ManagedWindowIsActive (wm);
913 if (wm.IsToolWindow) {
915 left = VisualStyleElement.Window.SmallFrameLeft.Active;
916 right = VisualStyleElement.Window.SmallFrameRight.Active;
917 bottom = VisualStyleElement.Window.SmallFrameBottom.Active;
919 left = VisualStyleElement.Window.SmallFrameLeft.Inactive;
920 right = VisualStyleElement.Window.SmallFrameRight.Inactive;
921 bottom = VisualStyleElement.Window.SmallFrameBottom.Inactive;
925 left = VisualStyleElement.Window.FrameLeft.Active;
926 right = VisualStyleElement.Window.FrameRight.Active;
927 bottom = VisualStyleElement.Window.FrameBottom.Active;
929 left = VisualStyleElement.Window.FrameLeft.Inactive;
930 right = VisualStyleElement.Window.FrameRight.Inactive;
931 bottom = VisualStyleElement.Window.FrameBottom.Inactive;
935 public override bool ManagedWindowTitleButtonHasHotElementStyle (TitleButton button, Form form)
937 if (render_non_client_areas && (button.State & ButtonState.Inactive) != ButtonState.Inactive) {
938 VisualStyleElement element;
939 if (ManagedWindowIsMaximizedMdiChild (form))
940 switch (button.Caption) {
941 case CaptionButton.Close:
942 element = VisualStyleElement.Window.MdiCloseButton.Hot;
944 case CaptionButton.Help:
945 element = VisualStyleElement.Window.MdiHelpButton.Hot;
947 case CaptionButton.Minimize:
948 element = VisualStyleElement.Window.MdiMinButton.Hot;
951 element = VisualStyleElement.Window.MdiRestoreButton.Hot;
954 else if (form.WindowManager.IsToolWindow)
955 element = VisualStyleElement.Window.SmallCloseButton.Hot;
957 switch (button.Caption) {
958 case CaptionButton.Close:
959 element = VisualStyleElement.Window.CloseButton.Hot;
961 case CaptionButton.Help:
962 element = VisualStyleElement.Window.HelpButton.Hot;
964 case CaptionButton.Maximize:
965 element = VisualStyleElement.Window.MaxButton.Hot;
967 case CaptionButton.Minimize:
968 element = VisualStyleElement.Window.MinButton.Hot;
971 element = VisualStyleElement.Window.RestoreButton.Hot;
974 if (VisualStyleRenderer.IsElementDefined (element))
977 return base.ManagedWindowTitleButtonHasHotElementStyle (button, form);
979 static bool ManagedWindowIsMaximizedMdiChild (Form form)
981 return form.WindowManager is MdiWindowManager &&
982 ManagedWindowGetWindowState (form.WindowManager) == FormWindowState.Maximized;
984 static bool ManagedWindowTitleButtonIsDisabled (TitleButton button, InternalWindowManager wm)
986 return (button.State & ButtonState.Inactive) == ButtonState.Inactive;
988 static bool ManagedWindowTitleButtonIsPressed (TitleButton button)
990 return (button.State & ButtonState.Pushed) == ButtonState.Pushed;
992 static VisualStyleElement ManagedWindowGetTitleButtonVisualStyleElement (TitleButton button, Form form)
994 if (form.WindowManager.IsToolWindow) {
995 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
996 return VisualStyleElement.Window.SmallCloseButton.Disabled;
997 if (ManagedWindowTitleButtonIsPressed (button))
998 return VisualStyleElement.Window.SmallCloseButton.Pressed;
1000 return VisualStyleElement.Window.SmallCloseButton.Hot;
1001 return VisualStyleElement.Window.SmallCloseButton.Normal;
1003 switch (button.Caption) {
1004 case CaptionButton.Close:
1005 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1006 return VisualStyleElement.Window.CloseButton.Disabled;
1007 if (ManagedWindowTitleButtonIsPressed (button))
1008 return VisualStyleElement.Window.CloseButton.Pressed;
1010 return VisualStyleElement.Window.CloseButton.Hot;
1011 return VisualStyleElement.Window.CloseButton.Normal;
1012 case CaptionButton.Help:
1013 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1014 return VisualStyleElement.Window.HelpButton.Disabled;
1015 if (ManagedWindowTitleButtonIsPressed (button))
1016 return VisualStyleElement.Window.HelpButton.Pressed;
1018 return VisualStyleElement.Window.HelpButton.Hot;
1019 return VisualStyleElement.Window.HelpButton.Normal;
1020 case CaptionButton.Maximize:
1021 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1022 return VisualStyleElement.Window.MaxButton.Disabled;
1023 if (ManagedWindowTitleButtonIsPressed (button))
1024 return VisualStyleElement.Window.MaxButton.Pressed;
1026 return VisualStyleElement.Window.MaxButton.Hot;
1027 return VisualStyleElement.Window.MaxButton.Normal;
1028 case CaptionButton.Minimize:
1029 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1030 return VisualStyleElement.Window.MinButton.Disabled;
1031 if (ManagedWindowTitleButtonIsPressed (button))
1032 return VisualStyleElement.Window.MinButton.Pressed;
1034 return VisualStyleElement.Window.MinButton.Hot;
1035 return VisualStyleElement.Window.MinButton.Normal;
1037 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1038 return VisualStyleElement.Window.RestoreButton.Disabled;
1039 if (ManagedWindowTitleButtonIsPressed (button))
1040 return VisualStyleElement.Window.RestoreButton.Pressed;
1042 return VisualStyleElement.Window.RestoreButton.Hot;
1043 return VisualStyleElement.Window.RestoreButton.Normal;
1046 protected override void ManagedWindowDrawTitleButton (Graphics dc, TitleButton button, Rectangle clip, Form form)
1048 if (!render_non_client_areas) {
1049 base.ManagedWindowDrawTitleButton (dc, button, clip, form);
1052 VisualStyleElement element = ManagedWindowGetTitleButtonVisualStyleElement (button, form);
1053 if (!VisualStyleRenderer.IsElementDefined (element)) {
1054 base.ManagedWindowDrawTitleButton (dc, button, clip, form);
1057 new VisualStyleRenderer (element).DrawBackground (dc, button.Rectangle, clip);
1059 public override Size ManagedWindowButtonSize (InternalWindowManager wm)
1061 if (!render_non_client_areas)
1062 return base.ManagedWindowButtonSize (wm);
1063 VisualStyleElement element = wm.IsToolWindow && !wm.IsMinimized ?
1064 VisualStyleElement.Window.SmallCloseButton.Normal :
1065 VisualStyleElement.Window.CloseButton.Normal;
1066 if (!VisualStyleRenderer.IsElementDefined (element))
1067 return base.ManagedWindowButtonSize (wm);
1068 IDeviceContext dc = GetMeasurementDeviceContext ();
1069 Size result = new VisualStyleRenderer (element).GetPartSize (dc, ThemeSizeType.True);
1070 ReleaseMeasurementDeviceContext (dc);
1073 public override void ManagedWindowDrawMenuButton (Graphics dc, TitleButton button, Rectangle clip, InternalWindowManager wm)
1075 if (!render_non_client_areas) {
1076 base.ManagedWindowDrawMenuButton (dc, button, clip, wm);
1079 VisualStyleElement element = ManagedWindowGetMenuButtonVisualStyleElement (button, wm);
1080 if (!VisualStyleRenderer.IsElementDefined (element)) {
1081 base.ManagedWindowDrawMenuButton (dc, button, clip, wm);
1084 new VisualStyleRenderer (element).DrawBackground (dc, button.Rectangle, clip);
1086 static VisualStyleElement ManagedWindowGetMenuButtonVisualStyleElement (TitleButton button, InternalWindowManager wm)
1088 switch (button.Caption) {
1089 case CaptionButton.Close:
1090 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1091 return VisualStyleElement.Window.MdiCloseButton.Disabled;
1092 if (ManagedWindowTitleButtonIsPressed (button))
1093 return VisualStyleElement.Window.MdiCloseButton.Pressed;
1095 return VisualStyleElement.Window.MdiCloseButton.Hot;
1096 return VisualStyleElement.Window.MdiCloseButton.Normal;
1097 case CaptionButton.Help:
1098 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1099 return VisualStyleElement.Window.MdiHelpButton.Disabled;
1100 if (ManagedWindowTitleButtonIsPressed (button))
1101 return VisualStyleElement.Window.MdiHelpButton.Pressed;
1103 return VisualStyleElement.Window.MdiHelpButton.Hot;
1104 return VisualStyleElement.Window.MdiHelpButton.Normal;
1105 case CaptionButton.Minimize:
1106 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1107 return VisualStyleElement.Window.MdiMinButton.Disabled;
1108 if (ManagedWindowTitleButtonIsPressed (button))
1109 return VisualStyleElement.Window.MdiMinButton.Pressed;
1111 return VisualStyleElement.Window.MdiMinButton.Hot;
1112 return VisualStyleElement.Window.MdiMinButton.Normal;
1114 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1115 return VisualStyleElement.Window.MdiRestoreButton.Disabled;
1116 if (ManagedWindowTitleButtonIsPressed (button))
1117 return VisualStyleElement.Window.MdiRestoreButton.Pressed;
1119 return VisualStyleElement.Window.MdiRestoreButton.Hot;
1120 return VisualStyleElement.Window.MdiRestoreButton.Normal;
1125 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
1127 if (!RenderClientAreas ||
1128 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.ProgressBar.Bar.Normal) ||
1129 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.ProgressBar.Chunk.Normal)) {
1130 base.DrawProgressBar (dc, clip_rect, ctrl);
1133 VisualStyleRenderer renderer = new VisualStyleRenderer (VisualStyleElement.ProgressBar.Bar.Normal);
1134 renderer.DrawBackground (dc, ctrl.ClientRectangle, clip_rect);
1135 Rectangle client_area = renderer.GetBackgroundContentRectangle (dc, new Rectangle (Point.Empty, ctrl.Size));
1136 renderer = new VisualStyleRenderer (VisualStyleElement.ProgressBar.Chunk.Normal);
1139 int max_blocks = int.MaxValue;
1140 int start_pixel = client_area.X;
1141 draw_mode = (int)ctrl.Style;
1142 switch (draw_mode) {
1143 case 1: // Continuous
1144 client_area.Width = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(Math.Max (ctrl.Maximum - ctrl.Minimum, 1))));
1145 renderer.DrawBackground (dc, client_area, clip_rect);
1148 int ms_diff = (int)(DateTime.Now - ctrl.start).TotalMilliseconds;
1149 double percent_done = (double) ms_diff / ProgressBarMarqueeSpeedScaling
1150 % (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
1152 start_pixel = client_area.X + (int)(client_area.Width * percent_done);
1155 int block_width = renderer.GetInteger (IntegerProperty.ProgressChunkSize);
1156 block_width = Math.Max (block_width, 0); // block_width is used to break out the loop below, it must be >= 0!
1157 int first_pixel_outside_filled_area = (int)(((double)(ctrl.Value - ctrl.Minimum) * client_area.Width) / (Math.Max (ctrl.Maximum - ctrl.Minimum, 1))) + client_area.X;
1158 int block_count = 0;
1159 int increment = block_width + renderer.GetInteger (IntegerProperty.ProgressSpaceSize);
1160 Rectangle block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height);
1162 if (max_blocks != int.MaxValue) {
1163 if (block_count == max_blocks)
1165 if (block_rect.Right >= client_area.Width)
1166 block_rect.X -= client_area.Width;
1168 if (block_rect.X >= first_pixel_outside_filled_area)
1170 if (block_rect.Right >= first_pixel_outside_filled_area)
1171 if (first_pixel_outside_filled_area == client_area.Right)
1172 block_rect.Width = first_pixel_outside_filled_area - block_rect.X;
1176 if (clip_rect.IntersectsWith (block_rect))
1177 renderer.DrawBackground (dc, block_rect, clip_rect);
1178 block_rect.X += increment;
1186 protected override void RadioButton_DrawButton (RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle) {
1187 if (radio_button.Appearance == Appearance.Normal && radio_button.FlatStyle == FlatStyle.System) {
1188 RadioButtonRenderer.DrawRadioButton (
1190 new Point (radiobutton_rectangle.Left, radiobutton_rectangle.Top),
1191 GetRadioButtonState (radio_button)
1195 base.RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
1197 static RadioButtonState GetRadioButtonState (RadioButton checkBox)
1199 if (checkBox.Checked) {
1200 if (!checkBox.Enabled)
1201 return RadioButtonState.CheckedDisabled;
1202 else if (checkBox.Pressed)
1203 return RadioButtonState.CheckedPressed;
1204 else if (checkBox.Entered)
1205 return RadioButtonState.CheckedHot;
1206 return RadioButtonState.CheckedNormal;
1208 if (!checkBox.Enabled)
1209 return RadioButtonState.UncheckedDisabled;
1210 else if (checkBox.Pressed)
1211 return RadioButtonState.UncheckedPressed;
1212 else if (checkBox.Entered)
1213 return RadioButtonState.UncheckedHot;
1214 return RadioButtonState.UncheckedNormal;
1219 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
1221 if (!RenderClientAreas ||
1222 !ScrollBarAreElementsDefined) {
1223 base.DrawScrollBar (dc, clip, bar);
1226 VisualStyleElement element;
1227 VisualStyleRenderer renderer;
1228 int scroll_button_width = bar.scrollbutton_width;
1229 int scroll_button_height = bar.scrollbutton_height;
1231 bar.FirstArrowArea = new Rectangle (0, 0, bar.Width, scroll_button_height);
1232 bar.SecondArrowArea = new Rectangle (
1234 bar.ClientRectangle.Height - scroll_button_height,
1236 scroll_button_height);
1237 Rectangle thumb_pos = bar.ThumbPos;
1238 thumb_pos.Width = bar.Width;
1239 bar.ThumbPos = thumb_pos;
1240 #region Background, upper track
1241 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
1242 element = VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed;
1244 element = bar.Enabled ?
1245 VisualStyleElement.ScrollBar.LowerTrackVertical.Normal :
1246 VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1247 renderer = new VisualStyleRenderer (element);
1248 Rectangle upper_track_rect = new Rectangle (
1251 bar.ClientRectangle.Width,
1253 if (clip.IntersectsWith (upper_track_rect))
1254 renderer.DrawBackground (dc, upper_track_rect, clip);
1256 #region Background, lower track
1257 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
1258 element = VisualStyles.VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed;
1260 element = bar.Enabled ?
1261 VisualStyleElement.ScrollBar.LowerTrackVertical.Normal :
1262 VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1263 renderer = new VisualStyleRenderer (element);
1264 Rectangle lower_track_rect = new Rectangle (
1266 bar.ThumbPos.Bottom,
1267 bar.ClientRectangle.Width,
1268 bar.ClientRectangle.Height - bar.ThumbPos.Bottom);
1269 if (clip.IntersectsWith (lower_track_rect))
1270 renderer.DrawBackground (dc, lower_track_rect, clip);
1273 if (clip.IntersectsWith (bar.FirstArrowArea)) {
1275 element = VisualStyleElement.ScrollBar.ArrowButton.UpDisabled;
1276 else if (bar.firstbutton_state == ButtonState.Pushed)
1277 element = VisualStyleElement.ScrollBar.ArrowButton.UpPressed;
1278 else if (bar.FirstButtonEntered)
1279 element = VisualStyleElement.ScrollBar.ArrowButton.UpHot;
1280 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1281 element = VisualStyleElement.ScrollBar.ArrowButton.UpHover;
1283 element = VisualStyleElement.ScrollBar.ArrowButton.UpNormal;
1284 renderer = new VisualStyleRenderer (element);
1285 renderer.DrawBackground (dc, bar.FirstArrowArea);
1287 if (clip.IntersectsWith (bar.SecondArrowArea)) {
1289 element = VisualStyleElement.ScrollBar.ArrowButton.DownDisabled;
1290 else if (bar.secondbutton_state == ButtonState.Pushed)
1291 element = VisualStyleElement.ScrollBar.ArrowButton.DownPressed;
1292 else if (bar.SecondButtonEntered)
1293 element = VisualStyleElement.ScrollBar.ArrowButton.DownHot;
1294 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1295 element = VisualStyleElement.ScrollBar.ArrowButton.DownHover;
1297 element = VisualStyleElement.ScrollBar.ArrowButton.DownNormal;
1298 renderer = new VisualStyleRenderer (element);
1299 renderer.DrawBackground (dc, bar.SecondArrowArea);
1302 #region Thumb and grip
1304 element = VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1305 else if (bar.ThumbPressed)
1306 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed;
1307 else if (bar.ThumbEntered)
1308 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot;
1310 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal;
1311 renderer = new VisualStyleRenderer (element);
1312 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1314 if (bar.Enabled && bar.ThumbPos.Height >= 20) {
1315 element = VisualStyleElement.ScrollBar.GripperVertical.Normal;
1316 if (VisualStyleRenderer.IsElementDefined (element)) {
1317 renderer = new VisualStyleRenderer (element);
1318 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1323 bar.FirstArrowArea = new Rectangle (0, 0, scroll_button_width, bar.Height);
1324 bar.SecondArrowArea = new Rectangle (
1325 bar.ClientRectangle.Width - scroll_button_width,
1327 scroll_button_width,
1329 Rectangle thumb_pos = bar.ThumbPos;
1330 thumb_pos.Height = bar.Height;
1331 bar.ThumbPos = thumb_pos;
1332 #region Background, left track
1333 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
1334 element = VisualStyleElement.ScrollBar.LeftTrackHorizontal.Pressed;
1336 element = bar.Enabled ?
1337 VisualStyleElement.ScrollBar.LeftTrackHorizontal.Normal :
1338 VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled;
1339 renderer = new VisualStyleRenderer (element);
1340 Rectangle left_track_rect = new Rectangle (
1344 bar.ClientRectangle.Height);
1345 if (clip.IntersectsWith (left_track_rect))
1346 renderer.DrawBackground (dc, left_track_rect, clip);
1348 #region Background, right track
1349 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
1350 element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Pressed;
1352 element = bar.Enabled ?
1353 VisualStyleElement.ScrollBar.RightTrackHorizontal.Normal :
1354 VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
1355 renderer = new VisualStyleRenderer (element);
1356 Rectangle right_track_rect = new Rectangle (
1359 bar.ClientRectangle.Width - bar.ThumbPos.Right,
1360 bar.ClientRectangle.Height);
1361 if (clip.IntersectsWith (right_track_rect))
1362 renderer.DrawBackground (dc, right_track_rect, clip);
1365 if (clip.IntersectsWith (bar.FirstArrowArea)) {
1367 element = VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled;
1368 else if (bar.firstbutton_state == ButtonState.Pushed)
1369 element = VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
1370 else if (bar.FirstButtonEntered)
1371 element = VisualStyleElement.ScrollBar.ArrowButton.LeftHot;
1372 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1373 element = VisualStyleElement.ScrollBar.ArrowButton.LeftHover;
1375 element = VisualStyleElement.ScrollBar.ArrowButton.LeftNormal;
1376 renderer = new VisualStyleRenderer (element);
1377 renderer.DrawBackground (dc, bar.FirstArrowArea);
1379 if (clip.IntersectsWith (bar.SecondArrowArea)) {
1381 element = VisualStyleElement.ScrollBar.ArrowButton.RightDisabled;
1382 else if (bar.secondbutton_state == ButtonState.Pushed)
1383 element = VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
1384 else if (bar.SecondButtonEntered)
1385 element = VisualStyleElement.ScrollBar.ArrowButton.RightHot;
1386 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1387 element = VisualStyleElement.ScrollBar.ArrowButton.RightHover;
1389 element = VisualStyleElement.ScrollBar.ArrowButton.RightNormal;
1390 renderer = new VisualStyleRenderer (element);
1391 renderer.DrawBackground (dc, bar.SecondArrowArea);
1394 #region Thumb and grip
1396 element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
1397 else if (bar.ThumbPressed)
1398 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Pressed;
1399 else if (bar.ThumbEntered)
1400 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Hot;
1402 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Normal;
1403 renderer = new VisualStyleRenderer (element);
1404 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1406 if (bar.Enabled && bar.ThumbPos.Height >= 20) {
1407 element = VisualStyleElement.ScrollBar.GripperHorizontal.Normal;
1408 if (VisualStyleRenderer.IsElementDefined (element)) {
1409 renderer = new VisualStyleRenderer (element);
1410 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1416 public override bool ScrollBarHasHotElementStyles {
1418 if (!RenderClientAreas)
1419 return base.ScrollBarHasHotElementStyles;
1420 return ScrollBarAreElementsDefined;
1423 public override bool ScrollBarHasPressedThumbStyle {
1425 if (!RenderClientAreas)
1426 return base.ScrollBarHasPressedThumbStyle;
1427 return ScrollBarAreElementsDefined;
1430 const int WindowsVistaMajorVersion = 6;
1431 static bool ScrollBarHasHoverArrowButtonStyleVisualStyles =
1432 Environment.OSVersion.Version.Major >= WindowsVistaMajorVersion;
1433 public override bool ScrollBarHasHoverArrowButtonStyle {
1435 if (RenderClientAreas &&
1436 ScrollBarHasHoverArrowButtonStyleVisualStyles)
1437 return ScrollBarAreElementsDefined;
1438 return base.ScrollBarHasHoverArrowButtonStyle;
1441 static bool ScrollBarAreElementsDefined {
1444 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ArrowButton.DownDisabled) &&
1445 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled) &&
1446 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled) &&
1447 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled) &&
1448 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Disabled) &&
1449 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ThumbButtonVertical.Disabled) &&
1450 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.UpperTrackVertical.Disabled);
1455 protected override void DrawStatusBarBackground(Graphics dc, Rectangle clip, StatusBar sb) {
1456 if (!RenderClientAreas) {
1457 base.DrawStatusBarBackground (dc, clip, sb);
1460 VisualStyleElement element = VisualStyleElement.Status.Bar.Normal;
1461 if (!VisualStyleRenderer.IsElementDefined (element)) {
1462 base.DrawStatusBarBackground (dc, clip, sb);
1465 new VisualStyleRenderer (element).DrawBackground (dc, sb.ClientRectangle, clip);
1467 protected override void DrawStatusBarSizingGrip (Graphics dc, Rectangle clip, StatusBar sb, Rectangle area)
1469 if (!RenderClientAreas) {
1470 base.DrawStatusBarSizingGrip (dc, clip, sb, area);
1473 VisualStyleElement element = VisualStyleElement.Status.Gripper.Normal;
1474 if (!VisualStyleRenderer.IsElementDefined (element)) {
1475 base.DrawStatusBarSizingGrip (dc, clip, sb, area);
1478 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1479 Rectangle sizing_grip_rectangle = new Rectangle (Point.Empty, renderer.GetPartSize (dc, ThemeSizeType.True));
1480 sizing_grip_rectangle.X = sb.Width - sizing_grip_rectangle.Width;
1481 sizing_grip_rectangle.Y = sb.Height - sizing_grip_rectangle.Height;
1482 renderer.DrawBackground (dc, sizing_grip_rectangle, clip);
1484 protected override void DrawStatusBarPanelBackground (Graphics dc, Rectangle area, StatusBarPanel panel)
1486 if (!RenderClientAreas) {
1487 base.DrawStatusBarPanelBackground (dc, area, panel);
1490 VisualStyleElement element = VisualStyleElement.Status.Pane.Normal;
1491 if (!VisualStyleRenderer.IsElementDefined (element)) {
1492 base.DrawStatusBarPanelBackground (dc, area, panel);
1495 new VisualStyleRenderer (element).DrawBackground (dc, area);
1499 static bool TextBoxBaseShouldPaint (TextBoxBase textBoxBase)
1501 return textBoxBase.BorderStyle == BorderStyle.Fixed3D;
1503 static VisualStyleElement TextBoxBaseGetVisualStyleElement (TextBoxBase textBoxBase)
1505 if (!textBoxBase.Enabled)
1506 return VisualStyleElement.TextBox.TextEdit.Disabled;
1507 if (textBoxBase.ReadOnly)
1508 return VisualStyleElement.TextBox.TextEdit.ReadOnly;
1509 if (textBoxBase.Entered)
1510 return VisualStyleElement.TextBox.TextEdit.Hot;
1511 if (textBoxBase.Focused)
1512 return VisualStyleElement.TextBox.TextEdit.Focused;
1513 return VisualStyleElement.TextBox.TextEdit.Normal;
1515 public override void TextBoxBaseFillBackground (TextBoxBase textBoxBase, Graphics g, Rectangle clippingArea)
1517 if (!RenderClientAreas ||
1518 !TextBoxBaseShouldPaint (textBoxBase)) {
1519 base.TextBoxBaseFillBackground (textBoxBase, g, clippingArea);
1522 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1523 if (!VisualStyleRenderer.IsElementDefined (element)) {
1524 base.TextBoxBaseFillBackground (textBoxBase, g, clippingArea);
1527 Rectangle bounds = new Rectangle(Point.Empty, textBoxBase.Size);
1528 bounds.X -= (bounds.Width - textBoxBase.ClientSize.Width) / 2;
1529 bounds.Y -= (bounds.Height - textBoxBase.ClientSize.Height) / 2;
1530 new VisualStyleRenderer (element).DrawBackground (g, bounds, clippingArea);
1532 public override bool TextBoxBaseHandleWmNcPaint (TextBoxBase textBoxBase, ref Message m)
1534 if (!RenderClientAreas ||
1535 !TextBoxBaseShouldPaint (textBoxBase))
1536 return base.TextBoxBaseHandleWmNcPaint (textBoxBase, ref m);
1537 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1538 if (!VisualStyleRenderer.IsElementDefined (element))
1539 return base.TextBoxBaseHandleWmNcPaint (textBoxBase, ref m);
1540 PaintEventArgs e = XplatUI.PaintEventStart (ref m, textBoxBase.Handle, false);
1541 new VisualStyleRenderer (element).DrawBackgroundExcludingArea (
1543 new Rectangle (Point.Empty, textBoxBase.Size),
1544 new Rectangle (new Point ((textBoxBase.Width - textBoxBase.ClientSize.Width) / 2,
1545 (textBoxBase.Height - textBoxBase.ClientSize.Height) / 2),
1546 textBoxBase.ClientSize));
1547 XplatUI.PaintEventEnd (ref m, textBoxBase.Handle, false);
1550 public override bool TextBoxBaseShouldPaintBackground (TextBoxBase textBoxBase)
1552 if (!RenderClientAreas ||
1553 !TextBoxBaseShouldPaint (textBoxBase))
1554 return base.TextBoxBaseShouldPaintBackground (textBoxBase);
1555 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1556 if (!VisualStyleRenderer.IsElementDefined (element))
1557 return base.TextBoxBaseShouldPaintBackground (textBoxBase);
1558 return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
1562 static bool ToolBarIsDisabled (ToolBarItem item)
1564 return !item.Button.Enabled;
1566 static bool ToolBarIsPressed (ToolBarItem item)
1568 return item.Pressed;
1570 static bool ToolBarIsChecked (ToolBarItem item)
1572 return item.Button.Pushed;
1574 static bool ToolBarIsHot (ToolBarItem item)
1576 return item.Hilight;
1579 protected override void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat)
1581 if (!RenderClientAreas) {
1582 base.DrawToolBarButtonBorder (dc, item, is_flat);
1585 if (item.Button.Style == ToolBarButtonStyle.Separator)
1587 VisualStyleElement element;
1588 if (item.Button.Style == ToolBarButtonStyle.DropDownButton)
1589 element = ToolBarGetDropDownButtonVisualStyleElement (item);
1591 element = ToolBarGetButtonVisualStyleElement (item);
1592 if (!VisualStyleRenderer.IsElementDefined (element)) {
1593 base.DrawToolBarButtonBorder (dc, item, is_flat);
1596 Rectangle rectangle = item.Rectangle;
1597 if (item.Button.Style == ToolBarButtonStyle.DropDownButton && item.Button.Parent.DropDownArrows)
1598 rectangle.Width -= ToolBarDropDownWidth;
1599 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
1601 private static VisualStyleElement ToolBarGetDropDownButtonVisualStyleElement (ToolBarItem item)
1603 if (item.Button.Parent.DropDownArrows) {
1604 if (ToolBarIsDisabled (item))
1605 return VisualStyleElement.ToolBar.SplitButton.Disabled;
1606 if (ToolBarIsPressed (item))
1607 return VisualStyleElement.ToolBar.SplitButton.Pressed;
1608 if (ToolBarIsChecked (item))
1609 if (ToolBarIsHot (item))
1610 return VisualStyleElement.ToolBar.SplitButton.HotChecked;
1612 return VisualStyleElement.ToolBar.SplitButton.Checked;
1613 if (ToolBarIsHot (item))
1614 return VisualStyleElement.ToolBar.SplitButton.Hot;
1615 return VisualStyleElement.ToolBar.SplitButton.Normal;
1617 if (ToolBarIsDisabled (item))
1618 return VisualStyleElement.ToolBar.DropDownButton.Disabled;
1619 if (ToolBarIsPressed (item))
1620 return VisualStyleElement.ToolBar.DropDownButton.Pressed;
1621 if (ToolBarIsChecked (item))
1622 if (ToolBarIsHot (item))
1623 return VisualStyleElement.ToolBar.DropDownButton.HotChecked;
1625 return VisualStyleElement.ToolBar.DropDownButton.Checked;
1626 if (ToolBarIsHot (item))
1627 return VisualStyleElement.ToolBar.DropDownButton.Hot;
1628 return VisualStyleElement.ToolBar.DropDownButton.Normal;
1631 private static VisualStyleElement ToolBarGetButtonVisualStyleElement (ToolBarItem item)
1633 if (ToolBarIsDisabled (item))
1634 return VisualStyleElement.ToolBar.Button.Disabled;
1635 if (ToolBarIsPressed (item))
1636 return VisualStyleElement.ToolBar.Button.Pressed;
1637 if (ToolBarIsChecked (item))
1638 if (ToolBarIsHot (item))
1639 return VisualStyleElement.ToolBar.Button.HotChecked;
1641 return VisualStyleElement.ToolBar.Button.Checked;
1642 if (ToolBarIsHot (item))
1643 return VisualStyleElement.ToolBar.Button.Hot;
1644 return VisualStyleElement.ToolBar.Button.Normal;
1648 protected override void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
1650 if (!RenderClientAreas) {
1651 base.DrawToolBarSeparator (dc, item);
1654 VisualStyleElement element = ToolBarGetSeparatorVisualStyleElement (item);
1655 if (!VisualStyleRenderer.IsElementDefined (element)) {
1656 base.DrawToolBarSeparator (dc, item);
1659 new VisualStyleRenderer (element).DrawBackground (dc, item.Rectangle);
1661 static VisualStyleElement ToolBarGetSeparatorVisualStyleElement (ToolBarItem toolBarItem)
1663 return toolBarItem.Button.Parent.Vertical ?
1664 VisualStyleElement.ToolBar.SeparatorVertical.Normal :
1665 VisualStyleElement.ToolBar.SeparatorHorizontal.Normal;
1668 #region Toggle button background
1669 protected override void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item)
1671 if (!RenderClientAreas ||
1672 !VisualStyleRenderer.IsElementDefined (ToolBarGetButtonVisualStyleElement (item)))
1673 base.DrawToolBarToggleButtonBackground (dc, item);
1676 #region Drop down arrow
1677 protected override void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
1679 if (!RenderClientAreas) {
1680 base.DrawToolBarDropDownArrow (dc, item, is_flat);
1683 VisualStyleElement element = ToolBarGetDropDownArrowVisualStyleElement (item);
1684 if (!VisualStyleRenderer.IsElementDefined (element)) {
1685 base.DrawToolBarDropDownArrow (dc, item, is_flat);
1688 Rectangle rect = item.Rectangle;
1689 rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
1690 rect.Width = ToolBarDropDownWidth;
1691 new VisualStyleRenderer (element).DrawBackground (dc, rect);
1693 private static VisualStyleElement ToolBarGetDropDownArrowVisualStyleElement (ToolBarItem item)
1695 if (ToolBarIsDisabled (item))
1696 return VisualStyleElement.ToolBar.SplitButtonDropDown.Disabled;
1697 if (ToolBarIsPressed (item))
1698 return VisualStyleElement.ToolBar.SplitButtonDropDown.Pressed;
1699 if (ToolBarIsChecked (item))
1700 if (ToolBarIsHot (item))
1701 return VisualStyleElement.ToolBar.SplitButtonDropDown.HotChecked;
1703 return VisualStyleElement.ToolBar.SplitButtonDropDown.Checked;
1704 if (ToolBarIsHot (item))
1705 return VisualStyleElement.ToolBar.SplitButtonDropDown.Hot;
1706 return VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
1709 public override bool ToolBarHasHotElementStyles (ToolBar toolBar)
1711 if (!RenderClientAreas)
1712 return base.ToolBarHasHotElementStyles (toolBar);
1715 public override bool ToolBarHasHotCheckedElementStyles {
1717 if (!RenderClientAreas)
1718 return base.ToolBarHasHotCheckedElementStyles;
1724 protected override void ToolTipDrawBackground (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
1726 if (!RenderClientAreas) {
1727 base.ToolTipDrawBackground (dc, clip_rectangle, control);
1730 VisualStyleElement element = VisualStyleElement.ToolTip.Standard.Normal;
1731 if (!VisualStyleRenderer.IsElementDefined (element)) {
1732 base.ToolTipDrawBackground (dc, clip_rectangle, control);
1735 new VisualStyleRenderer (element).DrawBackground (dc, control.ClientRectangle);
1737 public override bool ToolTipTransparentBackground {
1739 if (!RenderClientAreas)
1740 return base.ToolTipTransparentBackground;
1741 VisualStyleElement element = VisualStyleElement.ToolTip.Standard.Normal;
1742 if (!VisualStyleRenderer.IsElementDefined (element))
1743 return base.ToolTipTransparentBackground;
1744 return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
1749 protected override Size TrackBarGetThumbSize (TrackBar trackBar)
1751 if (!RenderClientAreas)
1752 return base.TrackBarGetThumbSize (trackBar);
1753 VisualStyleElement element = TrackBarGetThumbVisualStyleElement (trackBar);
1754 if (!VisualStyleRenderer.IsElementDefined (element))
1755 return base.TrackBarGetThumbSize (trackBar);
1756 Graphics g = trackBar.CreateGraphics ();
1757 Size result = new VisualStyleRenderer (element).GetPartSize (g, ThemeSizeType.True);
1759 return trackBar.Orientation == Orientation.Horizontal ? result : TrackBarRotateVerticalThumbSize (result);
1761 static VisualStyleElement TrackBarGetThumbVisualStyleElement (TrackBar trackBar)
1763 if (trackBar.Orientation == Orientation.Horizontal)
1764 switch (trackBar.TickStyle) {
1765 case TickStyle.BottomRight:
1766 case TickStyle.None:
1767 return TrackBarGetHorizontalThumbBottomVisualStyleElement (trackBar);
1768 case TickStyle.TopLeft:
1769 return TrackBarGetHorizontalThumbTopVisualStyleElement (trackBar);
1771 return TrackBarGetHorizontalThumbVisualStyleElement (trackBar);
1774 switch (trackBar.TickStyle) {
1775 case TickStyle.BottomRight:
1776 case TickStyle.None:
1777 return TrackBarGetVerticalThumbRightVisualStyleElement (trackBar);
1778 case TickStyle.TopLeft:
1779 return TrackBarGetVerticalThumbLeftVisualStyleElement (trackBar);
1781 return TrackBarGetVerticalThumbVisualStyleElement (trackBar);
1784 static Size TrackBarRotateVerticalThumbSize (Size value)
1786 int temporary = value.Width;
1787 value.Width = value.Height;
1788 value.Height = temporary;
1792 protected override void TrackBarDrawHorizontalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
1794 if (!RenderClientAreas) {
1795 base.TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1798 VisualStyleElement element = VisualStyleElement.TrackBar.Track.Normal;
1799 if (!VisualStyleRenderer.IsElementDefined (element)) {
1800 base.TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1803 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1804 renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (thumb_area.Width, renderer.GetPartSize (dc, ThemeSizeType.True).Height)), clippingArea);
1806 protected override void TrackBarDrawVerticalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
1808 if (!RenderClientAreas) {
1809 base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1812 VisualStyleElement element = VisualStyleElement.TrackBar.TrackVertical.Normal;
1813 if (!VisualStyleRenderer.IsElementDefined (element)) {
1814 base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1817 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1818 renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (renderer.GetPartSize (dc, ThemeSizeType.True).Width, thumb_area.Height)), clippingArea);
1822 static bool TrackBarIsDisabled (TrackBar trackBar)
1824 return !trackBar.Enabled;
1826 static bool TrackBarIsHot (TrackBar trackBar)
1828 return trackBar.ThumbEntered;
1830 static bool TrackBarIsPressed (TrackBar trackBar)
1832 return trackBar.thumb_pressed;
1834 static bool TrackBarIsFocused (TrackBar trackBar)
1836 return trackBar.Focused;
1839 protected override void TrackBarDrawHorizontalThumbBottom (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1841 if (!RenderClientAreas) {
1842 base.TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1845 VisualStyleElement element = TrackBarGetHorizontalThumbBottomVisualStyleElement (trackBar);
1846 if (!VisualStyleRenderer.IsElementDefined (element)) {
1847 base.TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1850 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1852 static VisualStyleElement TrackBarGetHorizontalThumbBottomVisualStyleElement (TrackBar trackBar)
1854 if (TrackBarIsDisabled (trackBar))
1855 return VisualStyleElement.TrackBar.ThumbBottom.Disabled;
1856 else if (TrackBarIsPressed (trackBar))
1857 return VisualStyleElement.TrackBar.ThumbBottom.Pressed;
1858 else if (TrackBarIsHot (trackBar))
1859 return VisualStyleElement.TrackBar.ThumbBottom.Hot;
1860 else if (TrackBarIsFocused (trackBar))
1861 return VisualStyleElement.TrackBar.ThumbBottom.Focused;
1862 return VisualStyleElement.TrackBar.ThumbBottom.Normal;
1864 protected override void TrackBarDrawHorizontalThumbTop (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1866 if (!RenderClientAreas) {
1867 base.TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1870 VisualStyleElement element = TrackBarGetHorizontalThumbTopVisualStyleElement (trackBar);
1871 if (!VisualStyleRenderer.IsElementDefined (element)) {
1872 base.TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1875 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1877 static VisualStyleElement TrackBarGetHorizontalThumbTopVisualStyleElement (TrackBar trackBar)
1879 if (TrackBarIsDisabled (trackBar))
1880 return VisualStyleElement.TrackBar.ThumbTop.Disabled;
1881 else if (TrackBarIsPressed (trackBar))
1882 return VisualStyleElement.TrackBar.ThumbTop.Pressed;
1883 else if (TrackBarIsHot (trackBar))
1884 return VisualStyleElement.TrackBar.ThumbTop.Hot;
1885 else if (TrackBarIsFocused (trackBar))
1886 return VisualStyleElement.TrackBar.ThumbTop.Focused;
1887 return VisualStyleElement.TrackBar.ThumbTop.Normal;
1889 protected override void TrackBarDrawHorizontalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1891 if (!RenderClientAreas) {
1892 base.TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1895 VisualStyleElement element = TrackBarGetHorizontalThumbVisualStyleElement (trackBar);
1896 if (!VisualStyleRenderer.IsElementDefined (element)) {
1897 base.TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1900 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1902 static VisualStyleElement TrackBarGetHorizontalThumbVisualStyleElement (TrackBar trackBar)
1904 if (TrackBarIsDisabled (trackBar))
1905 return VisualStyleElement.TrackBar.Thumb.Disabled;
1906 else if (TrackBarIsPressed (trackBar))
1907 return VisualStyleElement.TrackBar.Thumb.Pressed;
1908 else if (TrackBarIsHot (trackBar))
1909 return VisualStyleElement.TrackBar.Thumb.Hot;
1910 else if (TrackBarIsFocused (trackBar))
1911 return VisualStyleElement.TrackBar.Thumb.Focused;
1912 return VisualStyleElement.TrackBar.Thumb.Normal;
1916 static Rectangle TrackBarRotateVerticalThumbSize (Rectangle value)
1918 int temporary = value.Width;
1919 value.Width = value.Height;
1920 value.Height = temporary;
1923 protected override void TrackBarDrawVerticalThumbRight (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1925 if (!RenderClientAreas) {
1926 base.TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1929 VisualStyleElement element = TrackBarGetVerticalThumbRightVisualStyleElement (trackBar);
1930 if (!VisualStyleRenderer.IsElementDefined (element)) {
1931 base.TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1934 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1936 static VisualStyleElement TrackBarGetVerticalThumbRightVisualStyleElement (TrackBar trackBar)
1938 if (TrackBarIsDisabled (trackBar))
1939 return VisualStyleElement.TrackBar.ThumbRight.Disabled;
1940 else if (TrackBarIsPressed (trackBar))
1941 return VisualStyleElement.TrackBar.ThumbRight.Pressed;
1942 else if (TrackBarIsHot (trackBar))
1943 return VisualStyleElement.TrackBar.ThumbRight.Hot;
1944 else if (TrackBarIsFocused (trackBar))
1945 return VisualStyleElement.TrackBar.ThumbRight.Focused;
1946 return VisualStyleElement.TrackBar.ThumbRight.Normal;
1948 protected override void TrackBarDrawVerticalThumbLeft (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1950 if (!RenderClientAreas) {
1951 base.TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1954 VisualStyleElement element = TrackBarGetVerticalThumbLeftVisualStyleElement (trackBar);
1955 if (!VisualStyleRenderer.IsElementDefined (element)) {
1956 base.TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1959 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1961 static VisualStyleElement TrackBarGetVerticalThumbLeftVisualStyleElement (TrackBar trackBar)
1963 if (TrackBarIsDisabled (trackBar))
1964 return VisualStyleElement.TrackBar.ThumbLeft.Disabled;
1965 else if (TrackBarIsPressed (trackBar))
1966 return VisualStyleElement.TrackBar.ThumbLeft.Pressed;
1967 else if (TrackBarIsHot (trackBar))
1968 return VisualStyleElement.TrackBar.ThumbLeft.Hot;
1969 else if (TrackBarIsFocused (trackBar))
1970 return VisualStyleElement.TrackBar.ThumbLeft.Focused;
1971 return VisualStyleElement.TrackBar.ThumbLeft.Normal;
1973 protected override void TrackBarDrawVerticalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1975 if (!RenderClientAreas) {
1976 base.TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1979 VisualStyleElement element = TrackBarGetVerticalThumbVisualStyleElement (trackBar);
1980 if (!VisualStyleRenderer.IsElementDefined (element)) {
1981 base.TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1984 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1986 static VisualStyleElement TrackBarGetVerticalThumbVisualStyleElement (TrackBar trackBar)
1988 if (TrackBarIsDisabled (trackBar))
1989 return VisualStyleElement.TrackBar.ThumbVertical.Disabled;
1990 else if (TrackBarIsPressed (trackBar))
1991 return VisualStyleElement.TrackBar.ThumbVertical.Pressed;
1992 else if (TrackBarIsHot (trackBar))
1993 return VisualStyleElement.TrackBar.ThumbVertical.Hot;
1994 else if (TrackBarIsFocused (trackBar))
1995 return VisualStyleElement.TrackBar.ThumbVertical.Focused;
1996 return VisualStyleElement.TrackBar.ThumbVertical.Normal;
2001 const EdgeStyle TrackBarTickEdgeStyle = EdgeStyle.Bump;
2002 const EdgeEffects TrackBarTickEdgeEffects = EdgeEffects.None;
2004 protected override ITrackBarTickPainter TrackBarGetHorizontalTickPainter (Graphics g)
2006 if (!RenderClientAreas ||
2007 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.TrackBar.Ticks.Normal))
2008 return base.TrackBarGetHorizontalTickPainter (g);
2009 return new TrackBarHorizontalTickPainter (g);
2011 class TrackBarHorizontalTickPainter : ITrackBarTickPainter
2013 readonly Graphics g;
2014 readonly VisualStyleRenderer renderer;
2015 public TrackBarHorizontalTickPainter (Graphics g)
2018 renderer = new VisualStyleRenderer (VisualStyleElement.TrackBar.Ticks.Normal);
2020 public void Paint (float x1, float y1, float x2, float y2)
2022 renderer.DrawEdge (g, new Rectangle (
2023 (int)Math.Round (x1),
2024 (int)Math.Round (y1),
2026 (int)Math.Round (y2 - y1) + 1), Edges.Left, TrackBarTickEdgeStyle, TrackBarTickEdgeEffects);
2031 protected override ITrackBarTickPainter TrackBarGetVerticalTickPainter (Graphics g)
2033 if (!RenderClientAreas ||
2034 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.TrackBar.TicksVertical.Normal))
2035 return base.TrackBarGetVerticalTickPainter (g);
2036 return new TrackBarVerticalTickPainter (g);
2038 class TrackBarVerticalTickPainter : ITrackBarTickPainter
2040 readonly Graphics g;
2041 readonly VisualStyleRenderer renderer;
2042 public TrackBarVerticalTickPainter (Graphics g)
2045 renderer = new VisualStyleRenderer (VisualStyleElement.TrackBar.TicksVertical.Normal);
2047 public void Paint (float x1, float y1, float x2, float y2)
2049 renderer.DrawEdge (g, new Rectangle (
2050 (int)Math.Round (x1),
2051 (int)Math.Round (y1),
2052 (int)Math.Round (x2 - x1) + 1,
2053 1), Edges.Top, TrackBarTickEdgeStyle, TrackBarTickEdgeEffects);
2058 public override bool TrackBarHasHotThumbStyle {
2060 if (!RenderClientAreas)
2061 return base.TrackBarHasHotThumbStyle;
2067 [MonoInternalNote ("Use the sizing information provided by the VisualStyles API.")]
2068 public override void TreeViewDrawNodePlusMinus (TreeView treeView, TreeNode node, Graphics dc, int x, int middle)
2070 if (!RenderClientAreas) {
2071 base.TreeViewDrawNodePlusMinus (treeView, node, dc, x, middle);
2074 VisualStyleElement element = node.IsExpanded ?
2075 VisualStyleElement.TreeView.Glyph.Opened :
2076 VisualStyleElement.TreeView.Glyph.Closed;
2077 if (!VisualStyleRenderer.IsElementDefined (element)) {
2078 base.TreeViewDrawNodePlusMinus (treeView, node, dc, x, middle);
2081 new VisualStyleRenderer (element).DrawBackground (dc, new Rectangle (x, middle - 4, 9, 9));
2085 public override void UpDownBaseDrawButton (Graphics g, Rectangle bounds, bool top, PushButtonState state)
2087 if (!RenderClientAreas) {
2088 base.UpDownBaseDrawButton (g, bounds, top, state);
2091 VisualStyleElement element;
2094 case PushButtonState.Disabled:
2095 element = VisualStyleElement.Spin.Up.Disabled;
2097 case PushButtonState.Pressed:
2098 element = VisualStyleElement.Spin.Up.Pressed;
2100 case PushButtonState.Hot:
2101 element = VisualStyleElement.Spin.Up.Hot;
2104 element = VisualStyleElement.Spin.Up.Normal;
2109 case PushButtonState.Disabled:
2110 element = VisualStyleElement.Spin.Down.Disabled;
2112 case PushButtonState.Pressed:
2113 element = VisualStyleElement.Spin.Down.Pressed;
2115 case PushButtonState.Hot:
2116 element = VisualStyleElement.Spin.Down.Hot;
2119 element = VisualStyleElement.Spin.Down.Normal;
2122 if (!VisualStyleRenderer.IsElementDefined (element)) {
2123 base.UpDownBaseDrawButton (g, bounds, top, state);
2126 new VisualStyleRenderer (element).DrawBackground (g, bounds);
2128 public override bool UpDownBaseHasHotButtonStyle {
2130 if (!RenderClientAreas)
2131 return base.UpDownBaseHasHotButtonStyle;
2138 static bool AreEqual (VisualStyleElement value1, VisualStyleElement value2)
2141 value1.ClassName == value1.ClassName &&
2142 value1.Part == value2.Part &&
2143 value1.State == value2.State;
2146 #region Measurement device context
2147 static Control control;
2148 static IDeviceContext GetMeasurementDeviceContext ()
2150 if (control == null)
2151 control = new Control ();
2152 return control.CreateGraphics ();
2154 static void ReleaseMeasurementDeviceContext (IDeviceContext dc)