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);
200 switch (comboBox.FlatStyle) {
202 case FlatStyle.Popup:
203 return base.ComboBoxDropDownButtonHasHotElementStyle (comboBox);
208 static bool ComboBoxShouldPaintBackground (ComboBox comboBox)
210 if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
213 switch (comboBox.FlatStyle) {
215 case FlatStyle.Popup:
221 public override void ComboBoxDrawBackground (ComboBox comboBox, Graphics g, Rectangle clippingArea, FlatStyle style)
223 if (!RenderClientAreas || !ComboBoxShouldPaintBackground (comboBox)) {
224 base.ComboBoxDrawBackground (comboBox, g, clippingArea, style);
227 VisualStyleElement element;
228 if (!comboBox.Enabled)
229 element = VisualStyleElement.ComboBox.Border.Disabled;
230 else if (comboBox.Entered)
231 element = VisualStyleElement.ComboBox.Border.Hot;
232 else if (comboBox.Focused)
233 element = VisualStyleElement.ComboBox.Border.Focused;
235 element = VisualStyleElement.ComboBox.Border.Normal;
236 if (!VisualStyleRenderer.IsElementDefined (element)) {
237 base.ComboBoxDrawBackground (comboBox, g, clippingArea, style);
240 new VisualStyleRenderer (element).DrawBackground (g, new Rectangle (Point.Empty, comboBox.Size), clippingArea);
242 public override bool CombBoxBackgroundHasHotElementStyle (ComboBox comboBox)
244 if (RenderClientAreas &&
245 ComboBoxShouldPaintBackground (comboBox) &&
247 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ComboBox.Border.Hot))
249 return base.CombBoxBackgroundHasHotElementStyle (comboBox);
254 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
256 if (!RenderClientAreas ||
257 (state & ButtonState.Flat) == ButtonState.Flat ||
258 (state & ButtonState.Checked) == ButtonState.Checked) {
259 base.CPDrawButton (dc, rectangle, state);
262 VisualStyleElement element;
263 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
264 element = VisualStyleElement.Button.PushButton.Disabled;
265 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
266 element = VisualStyleElement.Button.PushButton.Pressed;
268 element = VisualStyleElement.Button.PushButton.Normal;
269 if (!VisualStyleRenderer.IsElementDefined (element)) {
270 base.CPDrawButton (dc, rectangle, state);
273 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
276 #region DrawCaptionButton
277 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state)
279 if (!RenderClientAreas ||
280 (state & ButtonState.Flat) == ButtonState.Flat ||
281 (state & ButtonState.Checked) == ButtonState.Checked) {
282 base.CPDrawCaptionButton (graphics, rectangle, button, state);
285 VisualStyleElement element = GetCaptionButtonVisualStyleElement (button, state);
286 if (!VisualStyleRenderer.IsElementDefined (element)) {
287 base.CPDrawCaptionButton (graphics, rectangle, button, state);
290 new VisualStyleRenderer (element).DrawBackground (graphics, rectangle);
292 static VisualStyleElement GetCaptionButtonVisualStyleElement (CaptionButton button, ButtonState state)
295 case CaptionButton.Minimize:
296 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
297 return VisualStyleElement.Window.MinButton.Disabled;
298 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
299 return VisualStyleElement.Window.MinButton.Pressed;
301 return VisualStyleElement.Window.MinButton.Normal;
302 case CaptionButton.Maximize:
303 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
304 return VisualStyleElement.Window.MaxButton.Disabled;
305 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
306 return VisualStyleElement.Window.MaxButton.Pressed;
308 return VisualStyleElement.Window.MaxButton.Normal;
309 case CaptionButton.Close:
310 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
311 return VisualStyleElement.Window.CloseButton.Disabled;
312 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
313 return VisualStyleElement.Window.CloseButton.Pressed;
315 return VisualStyleElement.Window.CloseButton.Normal;
316 case CaptionButton.Restore:
317 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
318 return VisualStyleElement.Window.RestoreButton.Disabled;
319 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
320 return VisualStyleElement.Window.RestoreButton.Pressed;
322 return VisualStyleElement.Window.RestoreButton.Normal;
324 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
325 return VisualStyleElement.Window.HelpButton.Disabled;
326 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
327 return VisualStyleElement.Window.HelpButton.Pressed;
329 return VisualStyleElement.Window.HelpButton.Normal;
334 public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
336 if (!RenderClientAreas ||
337 (state & ButtonState.Flat) == ButtonState.Flat) {
338 base.CPDrawCheckBox (dc, rectangle, state);
341 VisualStyleElement element;
342 if ((state & ButtonState.Checked) == ButtonState.Checked)
343 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
344 element = VisualStyleElement.Button.CheckBox.CheckedDisabled;
345 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
346 element = VisualStyleElement.Button.CheckBox.CheckedPressed;
348 element = VisualStyleElement.Button.CheckBox.CheckedNormal;
350 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
351 element = VisualStyleElement.Button.CheckBox.UncheckedDisabled;
352 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
353 element = VisualStyleElement.Button.CheckBox.UncheckedPressed;
355 element = VisualStyleElement.Button.CheckBox.UncheckedNormal;
356 if (!VisualStyleRenderer.IsElementDefined (element)) {
357 base.CPDrawCheckBox (dc, rectangle, state);
360 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
363 #region DrawComboButton
364 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
366 if (!RenderClientAreas ||
367 (state & ButtonState.Flat) == ButtonState.Flat ||
368 (state & ButtonState.Checked) == ButtonState.Checked) {
369 base.CPDrawComboButton (graphics, rectangle, state);
372 VisualStyleElement element;
373 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
374 element = VisualStyleElement.ComboBox.DropDownButton.Disabled;
375 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
376 element = VisualStyleElement.ComboBox.DropDownButton.Pressed;
378 element = VisualStyleElement.ComboBox.DropDownButton.Normal;
379 if (!VisualStyleRenderer.IsElementDefined (element)) {
380 base.CPDrawComboButton (graphics, rectangle, state);
383 new VisualStyleRenderer (element).DrawBackground (graphics, rectangle);
386 #region DrawMixedCheckBox
387 public override void CPDrawMixedCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
389 if (!RenderClientAreas ||
390 (state & ButtonState.Flat) == ButtonState.Flat) {
391 base.CPDrawMixedCheckBox (dc, rectangle, state);
394 VisualStyleElement element;
395 if ((state & ButtonState.Checked) == ButtonState.Checked)
396 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
397 element = VisualStyleElement.Button.CheckBox.MixedDisabled;
398 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
399 element = VisualStyleElement.Button.CheckBox.MixedPressed;
401 element = VisualStyleElement.Button.CheckBox.MixedNormal;
403 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
404 element = VisualStyleElement.Button.CheckBox.UncheckedDisabled;
405 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
406 element = VisualStyleElement.Button.CheckBox.UncheckedPressed;
408 element = VisualStyleElement.Button.CheckBox.UncheckedNormal;
409 if (!VisualStyleRenderer.IsElementDefined (element)) {
410 base.CPDrawMixedCheckBox (dc, rectangle, state);
413 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
416 #region DrawRadioButton
417 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
419 if (!RenderClientAreas ||
420 (state & ButtonState.Flat) == ButtonState.Flat) {
421 base.CPDrawRadioButton (dc, rectangle, state);
424 VisualStyleElement element;
425 if ((state & ButtonState.Checked) == ButtonState.Checked)
426 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
427 element = VisualStyleElement.Button.RadioButton.CheckedDisabled;
428 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
429 element = VisualStyleElement.Button.RadioButton.CheckedPressed;
431 element = VisualStyleElement.Button.RadioButton.CheckedNormal;
433 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
434 element = VisualStyleElement.Button.RadioButton.UncheckedDisabled;
435 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
436 element = VisualStyleElement.Button.RadioButton.UncheckedPressed;
438 element = VisualStyleElement.Button.RadioButton.UncheckedNormal;
439 if (!VisualStyleRenderer.IsElementDefined (element)) {
440 base.CPDrawRadioButton (dc, rectangle, state);
443 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
446 #region DrawScrollButton
447 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
449 if (!RenderClientAreas ||
450 (state & ButtonState.Flat) == ButtonState.Flat ||
451 (state & ButtonState.Checked) == ButtonState.Checked) {
452 base.CPDrawScrollButton (dc, area, type, state);
455 VisualStyleElement element = GetScrollButtonVisualStyleElement (type, state);
456 if (!VisualStyleRenderer.IsElementDefined (element)) {
457 base.CPDrawScrollButton (dc, area, type, state);
460 new VisualStyleRenderer (element).DrawBackground (dc, area);
462 static VisualStyleElement GetScrollButtonVisualStyleElement (ScrollButton type, ButtonState state)
465 case ScrollButton.Left:
466 if (IsDisabled (state))
467 return VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled;
468 else if (IsPressed (state))
469 return VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
471 return VisualStyleElement.ScrollBar.ArrowButton.LeftNormal;
472 case ScrollButton.Right:
473 if (IsDisabled (state))
474 return VisualStyleElement.ScrollBar.ArrowButton.RightDisabled;
475 else if (IsPressed (state))
476 return VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
478 return VisualStyleElement.ScrollBar.ArrowButton.RightNormal;
479 case ScrollButton.Up:
480 if (IsDisabled (state))
481 return VisualStyleElement.ScrollBar.ArrowButton.UpDisabled;
482 else if (IsPressed (state))
483 return VisualStyleElement.ScrollBar.ArrowButton.UpPressed;
485 return VisualStyleElement.ScrollBar.ArrowButton.UpNormal;
487 if (IsDisabled (state))
488 return VisualStyleElement.ScrollBar.ArrowButton.DownDisabled;
489 else if (IsPressed (state))
490 return VisualStyleElement.ScrollBar.ArrowButton.DownPressed;
492 return VisualStyleElement.ScrollBar.ArrowButton.DownNormal;
495 static bool IsDisabled (ButtonState state)
497 return (state & ButtonState.Inactive) == ButtonState.Inactive;
499 static bool IsPressed (ButtonState state)
501 return (state & ButtonState.Pushed) == ButtonState.Pushed;
507 #region DataGridViewHeaderCell
508 #region DataGridViewRowHeaderCell
509 public override bool DataGridViewRowHeaderCellDrawBackground (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
511 if (!RenderClientAreas ||
512 !cell.DataGridView.EnableHeadersVisualStyles)
513 return base.DataGridViewRowHeaderCellDrawBackground (cell, g, bounds);
514 VisualStyleElement element = DataGridViewRowHeaderCellGetVisualStyleElement (cell);
515 if (!VisualStyleRenderer.IsElementDefined (element))
516 return base.DataGridViewRowHeaderCellDrawBackground (cell, g, bounds);
518 Bitmap bitmap = new Bitmap (bounds.Height, bounds.Width);
519 Graphics bitmap_g = Graphics.FromImage (bitmap);
520 Rectangle bitmap_rectangle = new Rectangle (Point.Empty, bitmap.Size);
521 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
522 if (!AreEqual (element, VisualStyleElement.Header.Item.Normal) && renderer.IsBackgroundPartiallyTransparent ())
523 new VisualStyleRenderer (VisualStyleElement.Header.Item.Normal).DrawBackground (bitmap_g, bitmap_rectangle);
524 renderer.DrawBackground (bitmap_g, bitmap_rectangle);
526 g.Transform = new Matrix(0, 1, 1, 0, 0, 0);
527 g.DrawImage (bitmap, bounds.Y, bounds.X);
532 public override bool DataGridViewRowHeaderCellDrawSelectionBackground (DataGridViewRowHeaderCell cell)
534 if (!RenderClientAreas ||
535 !cell.DataGridView.EnableHeadersVisualStyles || !VisualStyleRenderer.IsElementDefined (DataGridViewRowHeaderCellGetVisualStyleElement (cell)))
536 return base.DataGridViewRowHeaderCellDrawSelectionBackground (cell);
539 public override bool DataGridViewRowHeaderCellDrawBorder (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
541 if (!RenderClientAreas ||
542 !cell.DataGridView.EnableHeadersVisualStyles || !VisualStyleRenderer.IsElementDefined (DataGridViewRowHeaderCellGetVisualStyleElement (cell)))
543 return base.DataGridViewRowHeaderCellDrawBorder (cell, g, bounds);
544 g.DrawLine (cell.GetBorderPen (), bounds.Right - 1, bounds.Top, bounds.Right - 1, bounds.Bottom - 1);
547 static VisualStyleElement DataGridViewRowHeaderCellGetVisualStyleElement (DataGridViewRowHeaderCell cell)
549 if (cell.DataGridView.PressedHeaderCell == cell)
550 return VisualStyleElement.Header.Item.Pressed;
551 if (cell.DataGridView.EnteredHeaderCell == cell)
552 return VisualStyleElement.Header.Item.Hot;
553 if (cell.OwningRow.SelectedInternal)
554 return VisualStyleElement.Header.Item.Pressed;
555 return VisualStyleElement.Header.Item.Normal;
558 #region DataGridViewColumnHeaderCell
559 public override bool DataGridViewColumnHeaderCellDrawBackground (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
561 if (!RenderClientAreas ||
562 !cell.DataGridView.EnableHeadersVisualStyles || cell is DataGridViewTopLeftHeaderCell)
563 return base.DataGridViewColumnHeaderCellDrawBackground (cell, g, bounds);
564 VisualStyleElement element = DataGridViewColumnHeaderCellGetVisualStyleElement (cell);
565 if (!VisualStyleRenderer.IsElementDefined (element))
566 return base.DataGridViewColumnHeaderCellDrawBackground (cell, g, bounds);
568 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
569 if (!AreEqual (element, VisualStyleElement.Header.Item.Normal) && renderer.IsBackgroundPartiallyTransparent ())
570 new VisualStyleRenderer (VisualStyleElement.Header.Item.Normal).DrawBackground (g, bounds);
571 renderer.DrawBackground (g, bounds);
574 public override bool DataGridViewColumnHeaderCellDrawBorder (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
576 if (!RenderClientAreas ||
577 !cell.DataGridView.EnableHeadersVisualStyles ||
578 cell is DataGridViewTopLeftHeaderCell ||
579 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Normal))
580 return base.DataGridViewColumnHeaderCellDrawBorder (cell, g, bounds);
581 g.DrawLine (cell.GetBorderPen (), bounds.Left, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
584 static VisualStyleElement DataGridViewColumnHeaderCellGetVisualStyleElement (DataGridViewColumnHeaderCell cell)
586 if (cell.DataGridView.PressedHeaderCell == cell)
587 return VisualStyleElement.Header.Item.Pressed;
588 if (cell.DataGridView.EnteredHeaderCell == cell)
589 return VisualStyleElement.Header.Item.Hot;
590 return VisualStyleElement.Header.Item.Normal;
593 public override bool DataGridViewHeaderCellHasPressedStyle (DataGridView dataGridView)
595 if (!RenderClientAreas ||
596 !dataGridView.EnableHeadersVisualStyles ||
597 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Pressed))
598 return base.DataGridViewHeaderCellHasPressedStyle (dataGridView);
601 public override bool DataGridViewHeaderCellHasHotStyle (DataGridView dataGridView)
603 if (!RenderClientAreas ||
604 !dataGridView.EnableHeadersVisualStyles ||
605 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Hot))
606 return base.DataGridViewHeaderCellHasHotStyle (dataGridView);
612 #region DateTimePicker
614 protected override void DateTimePickerDrawBorder (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
616 if (!RenderClientAreas) {
617 base.DateTimePickerDrawBorder (dateTimePicker, g, clippingArea);
620 VisualStyleElement element;
621 if (!dateTimePicker.Enabled)
622 element = VisualStyleElement.DatePicker.DateBorder.Disabled;
623 else if (dateTimePicker.Entered)
624 element = VisualStyleElement.DatePicker.DateBorder.Hot;
625 else if (dateTimePicker.Focused)
626 element = VisualStyleElement.DatePicker.DateBorder.Focused;
628 element = VisualStyleElement.DatePicker.DateBorder.Normal;
629 if (!VisualStyleRenderer.IsElementDefined (element)) {
630 base.DateTimePickerDrawBorder (dateTimePicker, g, clippingArea);
633 new VisualStyleRenderer (element).DrawBackground (g, new Rectangle (Point.Empty, dateTimePicker.Size), clippingArea);
635 public override bool DateTimePickerBorderHasHotElementStyle {
637 if (RenderClientAreas &&
638 VisualStyleRenderer.IsElementDefined (VisualStyleElement.DatePicker.DateBorder.Hot))
640 return base.DateTimePickerBorderHasHotElementStyle;
644 #region Drop down button
645 protected override void DateTimePickerDrawDropDownButton (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
647 if (!RenderClientAreas) {
648 base.DateTimePickerDrawDropDownButton (dateTimePicker, g, clippingArea);
651 VisualStyleElement element;
652 if (!dateTimePicker.Enabled)
653 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Disabled;
654 else if (dateTimePicker.is_drop_down_visible)
655 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Pressed;
656 else if (dateTimePicker.DropDownButtonEntered)
657 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Hot;
659 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Normal;
660 if (!VisualStyleRenderer.IsElementDefined (element)) {
661 base.DateTimePickerDrawDropDownButton (dateTimePicker, g, clippingArea);
664 new VisualStyleRenderer (element).DrawBackground (g, dateTimePicker.drop_down_arrow_rect, clippingArea);
666 //TODO: Until somebody figures out how to obtain the proper width this will need to be updated when new Windows versions/themes are released.
667 const int DateTimePickerDropDownWidthOnWindowsVista = 34;
668 const int DateTimePickerDropDownHeightOnWindowsVista = 20;
669 public override Rectangle DateTimePickerGetDropDownButtonArea (DateTimePicker dateTimePicker)
671 if (!RenderClientAreas)
672 return base.DateTimePickerGetDropDownButtonArea (dateTimePicker);
673 VisualStyleElement element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Pressed;
674 if (!VisualStyleRenderer.IsElementDefined (element))
675 return base.DateTimePickerGetDropDownButtonArea (dateTimePicker);
676 Size size = new Size (DateTimePickerDropDownWidthOnWindowsVista, DateTimePickerDropDownHeightOnWindowsVista);
677 return new Rectangle (dateTimePicker.Width - size.Width, 0, size.Width, size.Height);
679 public override Rectangle DateTimePickerGetDateArea (DateTimePicker dateTimePicker)
681 if (!RenderClientAreas ||
682 dateTimePicker.ShowUpDown)
683 return base.DateTimePickerGetDateArea (dateTimePicker);
684 VisualStyleElement element = VisualStyleElement.DatePicker.DateBorder.Normal;
685 if (!VisualStyleRenderer.IsElementDefined (element))
686 return base.DateTimePickerGetDateArea (dateTimePicker);
687 Graphics g = dateTimePicker.CreateGraphics ();
688 Rectangle result = new VisualStyleRenderer (element).GetBackgroundContentRectangle (g, dateTimePicker.ClientRectangle);
690 result.Width -= DateTimePickerDropDownWidthOnWindowsVista;
693 public override bool DateTimePickerDropDownButtonHasHotElementStyle {
695 if (RenderClientAreas &&
696 VisualStyleRenderer.IsElementDefined (VisualStyleElement.DatePicker.ShowCalendarButtonRight.Hot))
698 return base.DateTimePickerDropDownButtonHasHotElementStyle;
704 protected override void ListViewDrawColumnHeaderBackground (ListView listView, ColumnHeader columnHeader, Graphics g, Rectangle area, Rectangle clippingArea)
706 if (!RenderClientAreas) {
707 base.ListViewDrawColumnHeaderBackground (listView, columnHeader, g, area, clippingArea);
710 VisualStyleElement element;
711 if (listView.HeaderStyle == ColumnHeaderStyle.Clickable)
712 if (columnHeader.Pressed)
713 element = VisualStyleElement.Header.Item.Pressed;
714 else if (columnHeader == listView.EnteredColumnHeader)
715 element = VisualStyleElement.Header.Item.Hot;
717 element = VisualStyleElement.Header.Item.Normal;
719 element = VisualStyleElement.Header.Item.Normal;
720 if (!VisualStyleRenderer.IsElementDefined (element)) {
721 base.ListViewDrawColumnHeaderBackground (listView, columnHeader, g, area, clippingArea);
724 new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
726 protected override void ListViewDrawUnusedHeaderBackground (ListView listView, Graphics g, Rectangle area, Rectangle clippingArea)
728 if (!RenderClientAreas) {
729 base.ListViewDrawUnusedHeaderBackground (listView, g, area, clippingArea);
732 VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
733 if (!VisualStyleRenderer.IsElementDefined (element)) {
734 base.ListViewDrawUnusedHeaderBackground (listView, g, area, clippingArea);
737 new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
739 public override bool ListViewHasHotHeaderStyle {
741 if (!RenderClientAreas ||
742 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Hot))
743 return base.ListViewHasHotHeaderStyle;
747 public override int ListViewGetHeaderHeight (ListView listView, Font font)
749 if (!RenderClientAreas)
750 return base.ListViewGetHeaderHeight (listView, font);
751 VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
752 if (!VisualStyleRenderer.IsElementDefined (element))
753 return base.ListViewGetHeaderHeight (listView, font);
754 Control control = null;
756 if (listView == null) {
757 control = new Control ();
758 g = control.CreateGraphics ();
760 g = listView.CreateGraphics ();
761 int result = new VisualStyleRenderer (element).GetPartSize (g, ThemeSizeType.True).Height;
763 if (listView == null)
769 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box)
771 GroupBoxRenderer.DrawGroupBox (
773 new Rectangle (Point.Empty, box.Size),
776 box.ForeColor == GroupBox.DefaultForeColor ? Color.Empty : box.ForeColor,
777 box.Enabled ? GroupBoxState.Normal : GroupBoxState.Disabled);
780 #region Managed window
781 Rectangle ManagedWindowGetTitleBarRectangle (InternalWindowManager wm)
783 return new Rectangle (0, 0, wm.Form.Width, ManagedWindowTitleBarHeight (wm) + ManagedWindowBorderWidth (wm) * (wm.IsMinimized ? 2 : 1));
785 Region ManagedWindowGetWindowRegion (Form form)
787 if (form.WindowManager is MdiWindowManager && form.WindowManager.IsMaximized)
789 VisualStyleElement title_bar_element = ManagedWindowGetTitleBarVisualStyleElement (form.WindowManager);
790 if (!VisualStyleRenderer.IsElementDefined (title_bar_element))
792 VisualStyleRenderer renderer = new VisualStyleRenderer (title_bar_element);
793 if (!renderer.IsBackgroundPartiallyTransparent ())
795 IDeviceContext dc = GetMeasurementDeviceContext ();
796 Rectangle title_bar_rectangle = ManagedWindowGetTitleBarRectangle (form.WindowManager);
797 Region region = renderer.GetBackgroundRegion (dc, title_bar_rectangle);
798 ReleaseMeasurementDeviceContext (dc);
799 region.Union (new Rectangle (0, title_bar_rectangle.Bottom, form.Width, form.Height));
802 public override void ManagedWindowOnSizeInitializedOrChanged (Form form)
804 base.ManagedWindowOnSizeInitializedOrChanged (form);
805 if (!render_non_client_areas)
807 form.Region = ManagedWindowGetWindowRegion (form);
809 protected override Rectangle ManagedWindowDrawTitleBarAndBorders (Graphics dc, Rectangle clip, InternalWindowManager wm)
811 if (!render_non_client_areas)
812 return base.ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
813 VisualStyleElement title_bar_element = ManagedWindowGetTitleBarVisualStyleElement (wm);
814 VisualStyleElement left_border_element;
815 VisualStyleElement right_border_element;
816 VisualStyleElement bottom_border_element;
817 ManagedWindowGetBorderVisualStyleElements (wm, out left_border_element, out right_border_element, out bottom_border_element);
818 if (!VisualStyleRenderer.IsElementDefined (title_bar_element) ||
819 (!wm.IsMinimized && (
820 !VisualStyleRenderer.IsElementDefined (left_border_element) ||
821 !VisualStyleRenderer.IsElementDefined (right_border_element) ||
822 !VisualStyleRenderer.IsElementDefined (bottom_border_element))))
823 return base.ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
824 VisualStyleRenderer renderer = new VisualStyleRenderer (title_bar_element);
825 Rectangle title_bar_rectangle = ManagedWindowGetTitleBarRectangle (wm);
826 renderer.DrawBackground (dc, title_bar_rectangle, clip);
827 if (!wm.IsMinimized) {
828 int border_width = ManagedWindowBorderWidth (wm);
829 renderer.SetParameters (left_border_element);
830 renderer.DrawBackground (dc, new Rectangle (
832 title_bar_rectangle.Bottom,
834 wm.Form.Height - title_bar_rectangle.Bottom
836 renderer.SetParameters (right_border_element);
837 renderer.DrawBackground (dc, new Rectangle (
838 wm.Form.Width - border_width,
839 title_bar_rectangle.Bottom,
841 wm.Form.Height - title_bar_rectangle.Bottom
843 renderer.SetParameters (bottom_border_element);
844 renderer.DrawBackground (dc, new Rectangle (
846 wm.Form.Height - border_width,
851 return title_bar_rectangle;
853 static FormWindowState ManagedWindowGetWindowState (InternalWindowManager wm)
855 return wm.GetWindowState ();
857 static bool ManagedWindowIsDisabled (InternalWindowManager wm)
859 return !wm.Form.Enabled;
861 static bool ManagedWindowIsActive (InternalWindowManager wm)
865 static VisualStyleElement ManagedWindowGetTitleBarVisualStyleElement (InternalWindowManager wm)
869 switch (ManagedWindowGetWindowState (wm)) {
870 case FormWindowState.Minimized:
871 if (ManagedWindowIsDisabled (wm))
872 return VisualStyleElement.Window.SmallMinCaption.Disabled;
873 else if (ManagedWindowIsActive (wm))
874 return VisualStyleElement.Window.SmallMinCaption.Active;
875 return VisualStyleElement.Window.SmallMinCaption.Inactive;
876 case FormWindowState.Maximized:
877 if (ManagedWindowIsDisabled (wm))
878 return VisualStyleElement.Window.SmallMaxCaption.Disabled;
879 else if (ManagedWindowIsActive (wm))
880 return VisualStyleElement.Window.SmallMaxCaption.Active;
881 return VisualStyleElement.Window.SmallMaxCaption.Inactive;
883 if (ManagedWindowIsDisabled (wm))
884 return VisualStyleElement.Window.SmallCaption.Disabled;
885 else if (ManagedWindowIsActive (wm))
886 return VisualStyleElement.Window.SmallCaption.Active;
887 return VisualStyleElement.Window.SmallCaption.Inactive;
891 #region Normal window
892 switch (ManagedWindowGetWindowState (wm)) {
893 case FormWindowState.Minimized:
894 if (ManagedWindowIsDisabled (wm))
895 return VisualStyleElement.Window.MinCaption.Disabled;
896 else if (ManagedWindowIsActive (wm))
897 return VisualStyleElement.Window.MinCaption.Active;
898 return VisualStyleElement.Window.MinCaption.Inactive;
899 case FormWindowState.Maximized:
900 if (ManagedWindowIsDisabled (wm))
901 return VisualStyleElement.Window.MaxCaption.Disabled;
902 else if (ManagedWindowIsActive (wm))
903 return VisualStyleElement.Window.MaxCaption.Active;
904 return VisualStyleElement.Window.MaxCaption.Inactive;
906 if (ManagedWindowIsDisabled (wm))
907 return VisualStyleElement.Window.Caption.Disabled;
908 else if (ManagedWindowIsActive (wm))
909 return VisualStyleElement.Window.Caption.Active;
910 return VisualStyleElement.Window.Caption.Inactive;
914 static void ManagedWindowGetBorderVisualStyleElements (InternalWindowManager wm, out VisualStyleElement left, out VisualStyleElement right, out VisualStyleElement bottom)
916 bool active = !ManagedWindowIsDisabled (wm) && ManagedWindowIsActive (wm);
917 if (wm.IsToolWindow) {
919 left = VisualStyleElement.Window.SmallFrameLeft.Active;
920 right = VisualStyleElement.Window.SmallFrameRight.Active;
921 bottom = VisualStyleElement.Window.SmallFrameBottom.Active;
923 left = VisualStyleElement.Window.SmallFrameLeft.Inactive;
924 right = VisualStyleElement.Window.SmallFrameRight.Inactive;
925 bottom = VisualStyleElement.Window.SmallFrameBottom.Inactive;
929 left = VisualStyleElement.Window.FrameLeft.Active;
930 right = VisualStyleElement.Window.FrameRight.Active;
931 bottom = VisualStyleElement.Window.FrameBottom.Active;
933 left = VisualStyleElement.Window.FrameLeft.Inactive;
934 right = VisualStyleElement.Window.FrameRight.Inactive;
935 bottom = VisualStyleElement.Window.FrameBottom.Inactive;
939 public override bool ManagedWindowTitleButtonHasHotElementStyle (TitleButton button, Form form)
941 if (render_non_client_areas && (button.State & ButtonState.Inactive) != ButtonState.Inactive) {
942 VisualStyleElement element;
943 if (ManagedWindowIsMaximizedMdiChild (form))
944 switch (button.Caption) {
945 case CaptionButton.Close:
946 element = VisualStyleElement.Window.MdiCloseButton.Hot;
948 case CaptionButton.Help:
949 element = VisualStyleElement.Window.MdiHelpButton.Hot;
951 case CaptionButton.Minimize:
952 element = VisualStyleElement.Window.MdiMinButton.Hot;
955 element = VisualStyleElement.Window.MdiRestoreButton.Hot;
958 else if (form.WindowManager.IsToolWindow)
959 element = VisualStyleElement.Window.SmallCloseButton.Hot;
961 switch (button.Caption) {
962 case CaptionButton.Close:
963 element = VisualStyleElement.Window.CloseButton.Hot;
965 case CaptionButton.Help:
966 element = VisualStyleElement.Window.HelpButton.Hot;
968 case CaptionButton.Maximize:
969 element = VisualStyleElement.Window.MaxButton.Hot;
971 case CaptionButton.Minimize:
972 element = VisualStyleElement.Window.MinButton.Hot;
975 element = VisualStyleElement.Window.RestoreButton.Hot;
978 if (VisualStyleRenderer.IsElementDefined (element))
981 return base.ManagedWindowTitleButtonHasHotElementStyle (button, form);
983 static bool ManagedWindowIsMaximizedMdiChild (Form form)
985 return form.WindowManager is MdiWindowManager &&
986 ManagedWindowGetWindowState (form.WindowManager) == FormWindowState.Maximized;
988 static bool ManagedWindowTitleButtonIsDisabled (TitleButton button, InternalWindowManager wm)
990 return (button.State & ButtonState.Inactive) == ButtonState.Inactive;
992 static bool ManagedWindowTitleButtonIsPressed (TitleButton button)
994 return (button.State & ButtonState.Pushed) == ButtonState.Pushed;
996 static VisualStyleElement ManagedWindowGetTitleButtonVisualStyleElement (TitleButton button, Form form)
998 if (form.WindowManager.IsToolWindow) {
999 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1000 return VisualStyleElement.Window.SmallCloseButton.Disabled;
1001 if (ManagedWindowTitleButtonIsPressed (button))
1002 return VisualStyleElement.Window.SmallCloseButton.Pressed;
1004 return VisualStyleElement.Window.SmallCloseButton.Hot;
1005 return VisualStyleElement.Window.SmallCloseButton.Normal;
1007 switch (button.Caption) {
1008 case CaptionButton.Close:
1009 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1010 return VisualStyleElement.Window.CloseButton.Disabled;
1011 if (ManagedWindowTitleButtonIsPressed (button))
1012 return VisualStyleElement.Window.CloseButton.Pressed;
1014 return VisualStyleElement.Window.CloseButton.Hot;
1015 return VisualStyleElement.Window.CloseButton.Normal;
1016 case CaptionButton.Help:
1017 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1018 return VisualStyleElement.Window.HelpButton.Disabled;
1019 if (ManagedWindowTitleButtonIsPressed (button))
1020 return VisualStyleElement.Window.HelpButton.Pressed;
1022 return VisualStyleElement.Window.HelpButton.Hot;
1023 return VisualStyleElement.Window.HelpButton.Normal;
1024 case CaptionButton.Maximize:
1025 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1026 return VisualStyleElement.Window.MaxButton.Disabled;
1027 if (ManagedWindowTitleButtonIsPressed (button))
1028 return VisualStyleElement.Window.MaxButton.Pressed;
1030 return VisualStyleElement.Window.MaxButton.Hot;
1031 return VisualStyleElement.Window.MaxButton.Normal;
1032 case CaptionButton.Minimize:
1033 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1034 return VisualStyleElement.Window.MinButton.Disabled;
1035 if (ManagedWindowTitleButtonIsPressed (button))
1036 return VisualStyleElement.Window.MinButton.Pressed;
1038 return VisualStyleElement.Window.MinButton.Hot;
1039 return VisualStyleElement.Window.MinButton.Normal;
1041 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1042 return VisualStyleElement.Window.RestoreButton.Disabled;
1043 if (ManagedWindowTitleButtonIsPressed (button))
1044 return VisualStyleElement.Window.RestoreButton.Pressed;
1046 return VisualStyleElement.Window.RestoreButton.Hot;
1047 return VisualStyleElement.Window.RestoreButton.Normal;
1050 protected override void ManagedWindowDrawTitleButton (Graphics dc, TitleButton button, Rectangle clip, Form form)
1052 if (!render_non_client_areas) {
1053 base.ManagedWindowDrawTitleButton (dc, button, clip, form);
1056 VisualStyleElement element = ManagedWindowGetTitleButtonVisualStyleElement (button, form);
1057 if (!VisualStyleRenderer.IsElementDefined (element)) {
1058 base.ManagedWindowDrawTitleButton (dc, button, clip, form);
1061 new VisualStyleRenderer (element).DrawBackground (dc, button.Rectangle, clip);
1063 public override Size ManagedWindowButtonSize (InternalWindowManager wm)
1065 if (!render_non_client_areas)
1066 return base.ManagedWindowButtonSize (wm);
1067 VisualStyleElement element = wm.IsToolWindow && !wm.IsMinimized ?
1068 VisualStyleElement.Window.SmallCloseButton.Normal :
1069 VisualStyleElement.Window.CloseButton.Normal;
1070 if (!VisualStyleRenderer.IsElementDefined (element))
1071 return base.ManagedWindowButtonSize (wm);
1072 IDeviceContext dc = GetMeasurementDeviceContext ();
1073 Size result = new VisualStyleRenderer (element).GetPartSize (dc, ThemeSizeType.True);
1074 ReleaseMeasurementDeviceContext (dc);
1077 public override void ManagedWindowDrawMenuButton (Graphics dc, TitleButton button, Rectangle clip, InternalWindowManager wm)
1079 if (!render_non_client_areas) {
1080 base.ManagedWindowDrawMenuButton (dc, button, clip, wm);
1083 VisualStyleElement element = ManagedWindowGetMenuButtonVisualStyleElement (button, wm);
1084 if (!VisualStyleRenderer.IsElementDefined (element)) {
1085 base.ManagedWindowDrawMenuButton (dc, button, clip, wm);
1088 new VisualStyleRenderer (element).DrawBackground (dc, button.Rectangle, clip);
1090 static VisualStyleElement ManagedWindowGetMenuButtonVisualStyleElement (TitleButton button, InternalWindowManager wm)
1092 switch (button.Caption) {
1093 case CaptionButton.Close:
1094 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1095 return VisualStyleElement.Window.MdiCloseButton.Disabled;
1096 if (ManagedWindowTitleButtonIsPressed (button))
1097 return VisualStyleElement.Window.MdiCloseButton.Pressed;
1099 return VisualStyleElement.Window.MdiCloseButton.Hot;
1100 return VisualStyleElement.Window.MdiCloseButton.Normal;
1101 case CaptionButton.Help:
1102 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1103 return VisualStyleElement.Window.MdiHelpButton.Disabled;
1104 if (ManagedWindowTitleButtonIsPressed (button))
1105 return VisualStyleElement.Window.MdiHelpButton.Pressed;
1107 return VisualStyleElement.Window.MdiHelpButton.Hot;
1108 return VisualStyleElement.Window.MdiHelpButton.Normal;
1109 case CaptionButton.Minimize:
1110 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1111 return VisualStyleElement.Window.MdiMinButton.Disabled;
1112 if (ManagedWindowTitleButtonIsPressed (button))
1113 return VisualStyleElement.Window.MdiMinButton.Pressed;
1115 return VisualStyleElement.Window.MdiMinButton.Hot;
1116 return VisualStyleElement.Window.MdiMinButton.Normal;
1118 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1119 return VisualStyleElement.Window.MdiRestoreButton.Disabled;
1120 if (ManagedWindowTitleButtonIsPressed (button))
1121 return VisualStyleElement.Window.MdiRestoreButton.Pressed;
1123 return VisualStyleElement.Window.MdiRestoreButton.Hot;
1124 return VisualStyleElement.Window.MdiRestoreButton.Normal;
1129 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
1131 if (!RenderClientAreas ||
1132 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.ProgressBar.Bar.Normal) ||
1133 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.ProgressBar.Chunk.Normal)) {
1134 base.DrawProgressBar (dc, clip_rect, ctrl);
1137 VisualStyleRenderer renderer = new VisualStyleRenderer (VisualStyleElement.ProgressBar.Bar.Normal);
1138 renderer.DrawBackground (dc, ctrl.ClientRectangle, clip_rect);
1139 Rectangle client_area = renderer.GetBackgroundContentRectangle (dc, new Rectangle (Point.Empty, ctrl.Size));
1140 renderer = new VisualStyleRenderer (VisualStyleElement.ProgressBar.Chunk.Normal);
1143 int max_blocks = int.MaxValue;
1144 int start_pixel = client_area.X;
1146 draw_mode = (int)ctrl.Style;
1148 switch (draw_mode) {
1150 case 1: // Continuous
1151 client_area.Width = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(Math.Max (ctrl.Maximum - ctrl.Minimum, 1))));
1152 renderer.DrawBackground (dc, client_area, clip_rect);
1155 int ms_diff = (int)(DateTime.Now - ctrl.start).TotalMilliseconds;
1156 double percent_done = (double)ms_diff % (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
1158 start_pixel = client_area.X + (int)(client_area.Width * percent_done);
1162 int block_width = renderer.GetInteger (IntegerProperty.ProgressChunkSize);
1163 block_width = Math.Max (block_width, 0); // block_width is used to break out the loop below, it must be >= 0!
1164 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;
1165 int block_count = 0;
1166 int increment = block_width + renderer.GetInteger (IntegerProperty.ProgressSpaceSize);
1167 Rectangle block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height);
1169 if (max_blocks != int.MaxValue) {
1170 if (block_count == max_blocks)
1172 if (block_rect.Right >= client_area.Width)
1173 block_rect.X -= client_area.Width;
1175 if (block_rect.X >= first_pixel_outside_filled_area)
1177 if (block_rect.Right >= first_pixel_outside_filled_area)
1178 if (first_pixel_outside_filled_area == client_area.Right)
1179 block_rect.Width = first_pixel_outside_filled_area - block_rect.X;
1183 if (clip_rect.IntersectsWith (block_rect))
1184 renderer.DrawBackground (dc, block_rect, clip_rect);
1185 block_rect.X += increment;
1193 protected override void RadioButton_DrawButton (RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle) {
1194 if (radio_button.Appearance == Appearance.Normal && radio_button.FlatStyle == FlatStyle.System) {
1195 RadioButtonRenderer.DrawRadioButton (
1197 new Point (radiobutton_rectangle.Left, radiobutton_rectangle.Top),
1198 GetRadioButtonState (radio_button)
1202 base.RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
1204 static RadioButtonState GetRadioButtonState (RadioButton checkBox)
1206 if (checkBox.Checked) {
1207 if (!checkBox.Enabled)
1208 return RadioButtonState.CheckedDisabled;
1209 else if (checkBox.Pressed)
1210 return RadioButtonState.CheckedPressed;
1211 else if (checkBox.Entered)
1212 return RadioButtonState.CheckedHot;
1213 return RadioButtonState.CheckedNormal;
1215 if (!checkBox.Enabled)
1216 return RadioButtonState.UncheckedDisabled;
1217 else if (checkBox.Pressed)
1218 return RadioButtonState.UncheckedPressed;
1219 else if (checkBox.Entered)
1220 return RadioButtonState.UncheckedHot;
1221 return RadioButtonState.UncheckedNormal;
1226 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
1228 if (!RenderClientAreas ||
1229 !ScrollBarAreElementsDefined) {
1230 base.DrawScrollBar (dc, clip, bar);
1233 VisualStyleElement element;
1234 VisualStyleRenderer renderer;
1235 int scroll_button_width = bar.scrollbutton_width;
1236 int scroll_button_height = bar.scrollbutton_height;
1238 bar.FirstArrowArea = new Rectangle (0, 0, bar.Width, scroll_button_height);
1239 bar.SecondArrowArea = new Rectangle (
1241 bar.ClientRectangle.Height - scroll_button_height,
1243 scroll_button_height);
1244 Rectangle thumb_pos = bar.ThumbPos;
1245 thumb_pos.Width = bar.Width;
1246 bar.ThumbPos = thumb_pos;
1247 #region Background, upper track
1248 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
1249 element = VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed;
1251 element = bar.Enabled ?
1252 VisualStyleElement.ScrollBar.LowerTrackVertical.Normal :
1253 VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1254 renderer = new VisualStyleRenderer (element);
1255 Rectangle upper_track_rect = new Rectangle (
1258 bar.ClientRectangle.Width,
1260 if (clip.IntersectsWith (upper_track_rect))
1261 renderer.DrawBackground (dc, upper_track_rect, clip);
1263 #region Background, lower track
1264 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
1265 element = VisualStyles.VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed;
1267 element = bar.Enabled ?
1268 VisualStyleElement.ScrollBar.LowerTrackVertical.Normal :
1269 VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1270 renderer = new VisualStyleRenderer (element);
1271 Rectangle lower_track_rect = new Rectangle (
1273 bar.ThumbPos.Bottom,
1274 bar.ClientRectangle.Width,
1275 bar.ClientRectangle.Height - bar.ThumbPos.Bottom);
1276 if (clip.IntersectsWith (lower_track_rect))
1277 renderer.DrawBackground (dc, lower_track_rect, clip);
1280 if (clip.IntersectsWith (bar.FirstArrowArea)) {
1282 element = VisualStyleElement.ScrollBar.ArrowButton.UpDisabled;
1283 else if (bar.firstbutton_state == ButtonState.Pushed)
1284 element = VisualStyleElement.ScrollBar.ArrowButton.UpPressed;
1285 else if (bar.FirstButtonEntered)
1286 element = VisualStyleElement.ScrollBar.ArrowButton.UpHot;
1287 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1288 element = VisualStyleElement.ScrollBar.ArrowButton.UpHover;
1290 element = VisualStyleElement.ScrollBar.ArrowButton.UpNormal;
1291 renderer = new VisualStyleRenderer (element);
1292 renderer.DrawBackground (dc, bar.FirstArrowArea);
1294 if (clip.IntersectsWith (bar.SecondArrowArea)) {
1296 element = VisualStyleElement.ScrollBar.ArrowButton.DownDisabled;
1297 else if (bar.secondbutton_state == ButtonState.Pushed)
1298 element = VisualStyleElement.ScrollBar.ArrowButton.DownPressed;
1299 else if (bar.SecondButtonEntered)
1300 element = VisualStyleElement.ScrollBar.ArrowButton.DownHot;
1301 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1302 element = VisualStyleElement.ScrollBar.ArrowButton.DownHover;
1304 element = VisualStyleElement.ScrollBar.ArrowButton.DownNormal;
1305 renderer = new VisualStyleRenderer (element);
1306 renderer.DrawBackground (dc, bar.SecondArrowArea);
1309 #region Thumb and grip
1311 element = VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1312 else if (bar.ThumbPressed)
1313 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed;
1314 else if (bar.ThumbEntered)
1315 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot;
1317 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal;
1318 renderer = new VisualStyleRenderer (element);
1319 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1321 if (bar.Enabled && bar.ThumbPos.Height >= 20) {
1322 element = VisualStyleElement.ScrollBar.GripperVertical.Normal;
1323 if (VisualStyleRenderer.IsElementDefined (element)) {
1324 renderer = new VisualStyleRenderer (element);
1325 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1330 bar.FirstArrowArea = new Rectangle (0, 0, scroll_button_width, bar.Height);
1331 bar.SecondArrowArea = new Rectangle (
1332 bar.ClientRectangle.Width - scroll_button_width,
1334 scroll_button_width,
1336 Rectangle thumb_pos = bar.ThumbPos;
1337 thumb_pos.Height = bar.Height;
1338 bar.ThumbPos = thumb_pos;
1339 #region Background, left track
1340 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
1341 element = VisualStyleElement.ScrollBar.LeftTrackHorizontal.Pressed;
1343 element = bar.Enabled ?
1344 VisualStyleElement.ScrollBar.LeftTrackHorizontal.Normal :
1345 VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled;
1346 renderer = new VisualStyleRenderer (element);
1347 Rectangle left_track_rect = new Rectangle (
1351 bar.ClientRectangle.Height);
1352 if (clip.IntersectsWith (left_track_rect))
1353 renderer.DrawBackground (dc, left_track_rect, clip);
1355 #region Background, right track
1356 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
1357 element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Pressed;
1359 element = bar.Enabled ?
1360 VisualStyleElement.ScrollBar.RightTrackHorizontal.Normal :
1361 VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
1362 renderer = new VisualStyleRenderer (element);
1363 Rectangle right_track_rect = new Rectangle (
1366 bar.ClientRectangle.Width - bar.ThumbPos.Right,
1367 bar.ClientRectangle.Height);
1368 if (clip.IntersectsWith (right_track_rect))
1369 renderer.DrawBackground (dc, right_track_rect, clip);
1372 if (clip.IntersectsWith (bar.FirstArrowArea)) {
1374 element = VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled;
1375 else if (bar.firstbutton_state == ButtonState.Pushed)
1376 element = VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
1377 else if (bar.FirstButtonEntered)
1378 element = VisualStyleElement.ScrollBar.ArrowButton.LeftHot;
1379 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1380 element = VisualStyleElement.ScrollBar.ArrowButton.LeftHover;
1382 element = VisualStyleElement.ScrollBar.ArrowButton.LeftNormal;
1383 renderer = new VisualStyleRenderer (element);
1384 renderer.DrawBackground (dc, bar.FirstArrowArea);
1386 if (clip.IntersectsWith (bar.SecondArrowArea)) {
1388 element = VisualStyleElement.ScrollBar.ArrowButton.RightDisabled;
1389 else if (bar.secondbutton_state == ButtonState.Pushed)
1390 element = VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
1391 else if (bar.SecondButtonEntered)
1392 element = VisualStyleElement.ScrollBar.ArrowButton.RightHot;
1393 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1394 element = VisualStyleElement.ScrollBar.ArrowButton.RightHover;
1396 element = VisualStyleElement.ScrollBar.ArrowButton.RightNormal;
1397 renderer = new VisualStyleRenderer (element);
1398 renderer.DrawBackground (dc, bar.SecondArrowArea);
1401 #region Thumb and grip
1403 element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
1404 else if (bar.ThumbPressed)
1405 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Pressed;
1406 else if (bar.ThumbEntered)
1407 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Hot;
1409 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Normal;
1410 renderer = new VisualStyleRenderer (element);
1411 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1413 if (bar.Enabled && bar.ThumbPos.Height >= 20) {
1414 element = VisualStyleElement.ScrollBar.GripperHorizontal.Normal;
1415 if (VisualStyleRenderer.IsElementDefined (element)) {
1416 renderer = new VisualStyleRenderer (element);
1417 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1423 public override bool ScrollBarHasHotElementStyles {
1425 if (!RenderClientAreas)
1426 return base.ScrollBarHasHotElementStyles;
1427 return ScrollBarAreElementsDefined;
1430 public override bool ScrollBarHasPressedThumbStyle {
1432 if (!RenderClientAreas)
1433 return base.ScrollBarHasPressedThumbStyle;
1434 return ScrollBarAreElementsDefined;
1437 const int WindowsVistaMajorVersion = 6;
1438 static bool ScrollBarHasHoverArrowButtonStyleVisualStyles =
1439 Environment.OSVersion.Version.Major >= WindowsVistaMajorVersion;
1440 public override bool ScrollBarHasHoverArrowButtonStyle {
1442 if (RenderClientAreas &&
1443 ScrollBarHasHoverArrowButtonStyleVisualStyles)
1444 return ScrollBarAreElementsDefined;
1445 return base.ScrollBarHasHoverArrowButtonStyle;
1448 static bool ScrollBarAreElementsDefined {
1451 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ArrowButton.DownDisabled) &&
1452 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled) &&
1453 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled) &&
1454 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled) &&
1455 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Disabled) &&
1456 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ThumbButtonVertical.Disabled) &&
1457 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.UpperTrackVertical.Disabled);
1462 protected override void DrawStatusBarBackground(Graphics dc, Rectangle clip, StatusBar sb) {
1463 if (!RenderClientAreas) {
1464 base.DrawStatusBarBackground (dc, clip, sb);
1467 VisualStyleElement element = VisualStyleElement.Status.Bar.Normal;
1468 if (!VisualStyleRenderer.IsElementDefined (element)) {
1469 base.DrawStatusBarBackground (dc, clip, sb);
1472 new VisualStyleRenderer (element).DrawBackground (dc, sb.ClientRectangle, clip);
1474 protected override void DrawStatusBarSizingGrip (Graphics dc, Rectangle clip, StatusBar sb, Rectangle area)
1476 if (!RenderClientAreas) {
1477 base.DrawStatusBarSizingGrip (dc, clip, sb, area);
1480 VisualStyleElement element = VisualStyleElement.Status.Gripper.Normal;
1481 if (!VisualStyleRenderer.IsElementDefined (element)) {
1482 base.DrawStatusBarSizingGrip (dc, clip, sb, area);
1485 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1486 Rectangle sizing_grip_rectangle = new Rectangle (Point.Empty, renderer.GetPartSize (dc, ThemeSizeType.True));
1487 sizing_grip_rectangle.X = sb.Width - sizing_grip_rectangle.Width;
1488 sizing_grip_rectangle.Y = sb.Height - sizing_grip_rectangle.Height;
1489 renderer.DrawBackground (dc, sizing_grip_rectangle, clip);
1491 protected override void DrawStatusBarPanelBackground (Graphics dc, Rectangle area, StatusBarPanel panel)
1493 if (!RenderClientAreas) {
1494 base.DrawStatusBarPanelBackground (dc, area, panel);
1497 VisualStyleElement element = VisualStyleElement.Status.Pane.Normal;
1498 if (!VisualStyleRenderer.IsElementDefined (element)) {
1499 base.DrawStatusBarPanelBackground (dc, area, panel);
1502 new VisualStyleRenderer (element).DrawBackground (dc, area);
1506 static bool TextBoxBaseShouldPaint (TextBoxBase textBoxBase)
1508 return textBoxBase.BorderStyle == BorderStyle.Fixed3D;
1510 static VisualStyleElement TextBoxBaseGetVisualStyleElement (TextBoxBase textBoxBase)
1512 if (!textBoxBase.Enabled)
1513 return VisualStyleElement.TextBox.TextEdit.Disabled;
1514 if (textBoxBase.ReadOnly)
1515 return VisualStyleElement.TextBox.TextEdit.ReadOnly;
1516 if (textBoxBase.Entered)
1517 return VisualStyleElement.TextBox.TextEdit.Hot;
1518 if (textBoxBase.Focused)
1519 return VisualStyleElement.TextBox.TextEdit.Focused;
1520 return VisualStyleElement.TextBox.TextEdit.Normal;
1522 public override void TextBoxBaseFillBackground (TextBoxBase textBoxBase, Graphics g, Rectangle clippingArea)
1524 if (!RenderClientAreas ||
1525 !TextBoxBaseShouldPaint (textBoxBase)) {
1526 base.TextBoxBaseFillBackground (textBoxBase, g, clippingArea);
1529 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1530 if (!VisualStyleRenderer.IsElementDefined (element)) {
1531 base.TextBoxBaseFillBackground (textBoxBase, g, clippingArea);
1534 Rectangle bounds = new Rectangle(Point.Empty, textBoxBase.Size);
1535 bounds.X -= (bounds.Width - textBoxBase.ClientSize.Width) / 2;
1536 bounds.Y -= (bounds.Height - textBoxBase.ClientSize.Height) / 2;
1537 new VisualStyleRenderer (element).DrawBackground (g, bounds, clippingArea);
1539 public override bool TextBoxBaseHandleWmNcPaint (TextBoxBase textBoxBase, ref Message m)
1541 if (!RenderClientAreas ||
1542 !TextBoxBaseShouldPaint (textBoxBase))
1543 return base.TextBoxBaseHandleWmNcPaint (textBoxBase, ref m);
1544 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1545 if (!VisualStyleRenderer.IsElementDefined (element))
1546 return base.TextBoxBaseHandleWmNcPaint (textBoxBase, ref m);
1547 PaintEventArgs e = XplatUI.PaintEventStart (ref m, textBoxBase.Handle, false);
1548 new VisualStyleRenderer (element).DrawBackgroundExcludingArea (
1550 new Rectangle (Point.Empty, textBoxBase.Size),
1551 new Rectangle (new Point ((textBoxBase.Width - textBoxBase.ClientSize.Width) / 2,
1552 (textBoxBase.Height - textBoxBase.ClientSize.Height) / 2),
1553 textBoxBase.ClientSize));
1554 XplatUI.PaintEventEnd (ref m, textBoxBase.Handle, false);
1557 public override bool TextBoxBaseShouldPaintBackground (TextBoxBase textBoxBase)
1559 if (!RenderClientAreas ||
1560 !TextBoxBaseShouldPaint (textBoxBase))
1561 return base.TextBoxBaseShouldPaintBackground (textBoxBase);
1562 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1563 if (!VisualStyleRenderer.IsElementDefined (element))
1564 return base.TextBoxBaseShouldPaintBackground (textBoxBase);
1565 return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
1569 static bool ToolBarIsDisabled (ToolBarItem item)
1571 return !item.Button.Enabled;
1573 static bool ToolBarIsPressed (ToolBarItem item)
1575 return item.Pressed;
1577 static bool ToolBarIsChecked (ToolBarItem item)
1579 return item.Button.Pushed;
1581 static bool ToolBarIsHot (ToolBarItem item)
1583 return item.Hilight;
1586 protected override void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat)
1588 if (!RenderClientAreas) {
1589 base.DrawToolBarButtonBorder (dc, item, is_flat);
1592 if (item.Button.Style == ToolBarButtonStyle.Separator)
1594 VisualStyleElement element;
1595 if (item.Button.Style == ToolBarButtonStyle.DropDownButton)
1596 element = ToolBarGetDropDownButtonVisualStyleElement (item);
1598 element = ToolBarGetButtonVisualStyleElement (item);
1599 if (!VisualStyleRenderer.IsElementDefined (element)) {
1600 base.DrawToolBarButtonBorder (dc, item, is_flat);
1603 Rectangle rectangle = item.Rectangle;
1604 if (item.Button.Style == ToolBarButtonStyle.DropDownButton && item.Button.Parent.DropDownArrows)
1605 rectangle.Width -= ToolBarDropDownWidth;
1606 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
1608 private static VisualStyleElement ToolBarGetDropDownButtonVisualStyleElement (ToolBarItem item)
1610 if (item.Button.Parent.DropDownArrows) {
1611 if (ToolBarIsDisabled (item))
1612 return VisualStyleElement.ToolBar.SplitButton.Disabled;
1613 if (ToolBarIsPressed (item))
1614 return VisualStyleElement.ToolBar.SplitButton.Pressed;
1615 if (ToolBarIsChecked (item))
1616 if (ToolBarIsHot (item))
1617 return VisualStyleElement.ToolBar.SplitButton.HotChecked;
1619 return VisualStyleElement.ToolBar.SplitButton.Checked;
1620 if (ToolBarIsHot (item))
1621 return VisualStyleElement.ToolBar.SplitButton.Hot;
1622 return VisualStyleElement.ToolBar.SplitButton.Normal;
1624 if (ToolBarIsDisabled (item))
1625 return VisualStyleElement.ToolBar.DropDownButton.Disabled;
1626 if (ToolBarIsPressed (item))
1627 return VisualStyleElement.ToolBar.DropDownButton.Pressed;
1628 if (ToolBarIsChecked (item))
1629 if (ToolBarIsHot (item))
1630 return VisualStyleElement.ToolBar.DropDownButton.HotChecked;
1632 return VisualStyleElement.ToolBar.DropDownButton.Checked;
1633 if (ToolBarIsHot (item))
1634 return VisualStyleElement.ToolBar.DropDownButton.Hot;
1635 return VisualStyleElement.ToolBar.DropDownButton.Normal;
1638 private static VisualStyleElement ToolBarGetButtonVisualStyleElement (ToolBarItem item)
1640 if (ToolBarIsDisabled (item))
1641 return VisualStyleElement.ToolBar.Button.Disabled;
1642 if (ToolBarIsPressed (item))
1643 return VisualStyleElement.ToolBar.Button.Pressed;
1644 if (ToolBarIsChecked (item))
1645 if (ToolBarIsHot (item))
1646 return VisualStyleElement.ToolBar.Button.HotChecked;
1648 return VisualStyleElement.ToolBar.Button.Checked;
1649 if (ToolBarIsHot (item))
1650 return VisualStyleElement.ToolBar.Button.Hot;
1651 return VisualStyleElement.ToolBar.Button.Normal;
1655 protected override void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
1657 if (!RenderClientAreas) {
1658 base.DrawToolBarSeparator (dc, item);
1661 VisualStyleElement element = ToolBarGetSeparatorVisualStyleElement (item);
1662 if (!VisualStyleRenderer.IsElementDefined (element)) {
1663 base.DrawToolBarSeparator (dc, item);
1666 new VisualStyleRenderer (element).DrawBackground (dc, item.Rectangle);
1668 static VisualStyleElement ToolBarGetSeparatorVisualStyleElement (ToolBarItem toolBarItem)
1670 return toolBarItem.Button.Parent.Vertical ?
1671 VisualStyleElement.ToolBar.SeparatorVertical.Normal :
1672 VisualStyleElement.ToolBar.SeparatorHorizontal.Normal;
1675 #region Toggle button background
1676 protected override void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item)
1678 if (!RenderClientAreas ||
1679 !VisualStyleRenderer.IsElementDefined (ToolBarGetButtonVisualStyleElement (item)))
1680 base.DrawToolBarToggleButtonBackground (dc, item);
1683 #region Drop down arrow
1684 protected override void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
1686 if (!RenderClientAreas) {
1687 base.DrawToolBarDropDownArrow (dc, item, is_flat);
1690 VisualStyleElement element = ToolBarGetDropDownArrowVisualStyleElement (item);
1691 if (!VisualStyleRenderer.IsElementDefined (element)) {
1692 base.DrawToolBarDropDownArrow (dc, item, is_flat);
1695 Rectangle rect = item.Rectangle;
1696 rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
1697 rect.Width = ToolBarDropDownWidth;
1698 new VisualStyleRenderer (element).DrawBackground (dc, rect);
1700 private static VisualStyleElement ToolBarGetDropDownArrowVisualStyleElement (ToolBarItem item)
1702 if (ToolBarIsDisabled (item))
1703 return VisualStyleElement.ToolBar.SplitButtonDropDown.Disabled;
1704 if (ToolBarIsPressed (item))
1705 return VisualStyleElement.ToolBar.SplitButtonDropDown.Pressed;
1706 if (ToolBarIsChecked (item))
1707 if (ToolBarIsHot (item))
1708 return VisualStyleElement.ToolBar.SplitButtonDropDown.HotChecked;
1710 return VisualStyleElement.ToolBar.SplitButtonDropDown.Checked;
1711 if (ToolBarIsHot (item))
1712 return VisualStyleElement.ToolBar.SplitButtonDropDown.Hot;
1713 return VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
1716 public override bool ToolBarHasHotElementStyles (ToolBar toolBar)
1718 if (!RenderClientAreas)
1719 return base.ToolBarHasHotElementStyles (toolBar);
1722 public override bool ToolBarHasHotCheckedElementStyles {
1724 if (!RenderClientAreas)
1725 return base.ToolBarHasHotCheckedElementStyles;
1731 protected override void ToolTipDrawBackground (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
1733 if (!RenderClientAreas) {
1734 base.ToolTipDrawBackground (dc, clip_rectangle, control);
1737 VisualStyleElement element = VisualStyleElement.ToolTip.Standard.Normal;
1738 if (!VisualStyleRenderer.IsElementDefined (element)) {
1739 base.ToolTipDrawBackground (dc, clip_rectangle, control);
1742 new VisualStyleRenderer (element).DrawBackground (dc, control.ClientRectangle);
1744 public override bool ToolTipTransparentBackground {
1746 if (!RenderClientAreas)
1747 return base.ToolTipTransparentBackground;
1748 VisualStyleElement element = VisualStyleElement.ToolTip.Standard.Normal;
1749 if (!VisualStyleRenderer.IsElementDefined (element))
1750 return base.ToolTipTransparentBackground;
1751 return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
1756 protected override Size TrackBarGetThumbSize (TrackBar trackBar)
1758 if (!RenderClientAreas)
1759 return base.TrackBarGetThumbSize (trackBar);
1760 VisualStyleElement element = TrackBarGetThumbVisualStyleElement (trackBar);
1761 if (!VisualStyleRenderer.IsElementDefined (element))
1762 return base.TrackBarGetThumbSize (trackBar);
1763 Graphics g = trackBar.CreateGraphics ();
1764 Size result = new VisualStyleRenderer (element).GetPartSize (g, ThemeSizeType.True);
1766 return trackBar.Orientation == Orientation.Horizontal ? result : TrackBarRotateVerticalThumbSize (result);
1768 static VisualStyleElement TrackBarGetThumbVisualStyleElement (TrackBar trackBar)
1770 if (trackBar.Orientation == Orientation.Horizontal)
1771 switch (trackBar.TickStyle) {
1772 case TickStyle.BottomRight:
1773 case TickStyle.None:
1774 return TrackBarGetHorizontalThumbBottomVisualStyleElement (trackBar);
1775 case TickStyle.TopLeft:
1776 return TrackBarGetHorizontalThumbTopVisualStyleElement (trackBar);
1778 return TrackBarGetHorizontalThumbVisualStyleElement (trackBar);
1781 switch (trackBar.TickStyle) {
1782 case TickStyle.BottomRight:
1783 case TickStyle.None:
1784 return TrackBarGetVerticalThumbRightVisualStyleElement (trackBar);
1785 case TickStyle.TopLeft:
1786 return TrackBarGetVerticalThumbLeftVisualStyleElement (trackBar);
1788 return TrackBarGetVerticalThumbVisualStyleElement (trackBar);
1791 static Size TrackBarRotateVerticalThumbSize (Size value)
1793 int temporary = value.Width;
1794 value.Width = value.Height;
1795 value.Height = temporary;
1799 protected override void TrackBarDrawHorizontalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
1801 if (!RenderClientAreas) {
1802 base.TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1805 VisualStyleElement element = VisualStyleElement.TrackBar.Track.Normal;
1806 if (!VisualStyleRenderer.IsElementDefined (element)) {
1807 base.TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1810 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1811 renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (thumb_area.Width, renderer.GetPartSize (dc, ThemeSizeType.True).Height)), clippingArea);
1813 protected override void TrackBarDrawVerticalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
1815 if (!RenderClientAreas) {
1816 base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1819 VisualStyleElement element = VisualStyleElement.TrackBar.TrackVertical.Normal;
1820 if (!VisualStyleRenderer.IsElementDefined (element)) {
1821 base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1824 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1825 renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (renderer.GetPartSize (dc, ThemeSizeType.True).Width, thumb_area.Height)), clippingArea);
1829 static bool TrackBarIsDisabled (TrackBar trackBar)
1831 return !trackBar.Enabled;
1833 static bool TrackBarIsHot (TrackBar trackBar)
1835 return trackBar.ThumbEntered;
1837 static bool TrackBarIsPressed (TrackBar trackBar)
1839 return trackBar.thumb_pressed;
1841 static bool TrackBarIsFocused (TrackBar trackBar)
1843 return trackBar.Focused;
1846 protected override void TrackBarDrawHorizontalThumbBottom (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1848 if (!RenderClientAreas) {
1849 base.TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1852 VisualStyleElement element = TrackBarGetHorizontalThumbBottomVisualStyleElement (trackBar);
1853 if (!VisualStyleRenderer.IsElementDefined (element)) {
1854 base.TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1857 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1859 static VisualStyleElement TrackBarGetHorizontalThumbBottomVisualStyleElement (TrackBar trackBar)
1861 if (TrackBarIsDisabled (trackBar))
1862 return VisualStyleElement.TrackBar.ThumbBottom.Disabled;
1863 else if (TrackBarIsPressed (trackBar))
1864 return VisualStyleElement.TrackBar.ThumbBottom.Pressed;
1865 else if (TrackBarIsHot (trackBar))
1866 return VisualStyleElement.TrackBar.ThumbBottom.Hot;
1867 else if (TrackBarIsFocused (trackBar))
1868 return VisualStyleElement.TrackBar.ThumbBottom.Focused;
1869 return VisualStyleElement.TrackBar.ThumbBottom.Normal;
1871 protected override void TrackBarDrawHorizontalThumbTop (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1873 if (!RenderClientAreas) {
1874 base.TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1877 VisualStyleElement element = TrackBarGetHorizontalThumbTopVisualStyleElement (trackBar);
1878 if (!VisualStyleRenderer.IsElementDefined (element)) {
1879 base.TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1882 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1884 static VisualStyleElement TrackBarGetHorizontalThumbTopVisualStyleElement (TrackBar trackBar)
1886 if (TrackBarIsDisabled (trackBar))
1887 return VisualStyleElement.TrackBar.ThumbTop.Disabled;
1888 else if (TrackBarIsPressed (trackBar))
1889 return VisualStyleElement.TrackBar.ThumbTop.Pressed;
1890 else if (TrackBarIsHot (trackBar))
1891 return VisualStyleElement.TrackBar.ThumbTop.Hot;
1892 else if (TrackBarIsFocused (trackBar))
1893 return VisualStyleElement.TrackBar.ThumbTop.Focused;
1894 return VisualStyleElement.TrackBar.ThumbTop.Normal;
1896 protected override void TrackBarDrawHorizontalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1898 if (!RenderClientAreas) {
1899 base.TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1902 VisualStyleElement element = TrackBarGetHorizontalThumbVisualStyleElement (trackBar);
1903 if (!VisualStyleRenderer.IsElementDefined (element)) {
1904 base.TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1907 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1909 static VisualStyleElement TrackBarGetHorizontalThumbVisualStyleElement (TrackBar trackBar)
1911 if (TrackBarIsDisabled (trackBar))
1912 return VisualStyleElement.TrackBar.Thumb.Disabled;
1913 else if (TrackBarIsPressed (trackBar))
1914 return VisualStyleElement.TrackBar.Thumb.Pressed;
1915 else if (TrackBarIsHot (trackBar))
1916 return VisualStyleElement.TrackBar.Thumb.Hot;
1917 else if (TrackBarIsFocused (trackBar))
1918 return VisualStyleElement.TrackBar.Thumb.Focused;
1919 return VisualStyleElement.TrackBar.Thumb.Normal;
1923 static Rectangle TrackBarRotateVerticalThumbSize (Rectangle value)
1925 int temporary = value.Width;
1926 value.Width = value.Height;
1927 value.Height = temporary;
1930 protected override void TrackBarDrawVerticalThumbRight (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1932 if (!RenderClientAreas) {
1933 base.TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1936 VisualStyleElement element = TrackBarGetVerticalThumbRightVisualStyleElement (trackBar);
1937 if (!VisualStyleRenderer.IsElementDefined (element)) {
1938 base.TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1941 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1943 static VisualStyleElement TrackBarGetVerticalThumbRightVisualStyleElement (TrackBar trackBar)
1945 if (TrackBarIsDisabled (trackBar))
1946 return VisualStyleElement.TrackBar.ThumbRight.Disabled;
1947 else if (TrackBarIsPressed (trackBar))
1948 return VisualStyleElement.TrackBar.ThumbRight.Pressed;
1949 else if (TrackBarIsHot (trackBar))
1950 return VisualStyleElement.TrackBar.ThumbRight.Hot;
1951 else if (TrackBarIsFocused (trackBar))
1952 return VisualStyleElement.TrackBar.ThumbRight.Focused;
1953 return VisualStyleElement.TrackBar.ThumbRight.Normal;
1955 protected override void TrackBarDrawVerticalThumbLeft (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1957 if (!RenderClientAreas) {
1958 base.TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1961 VisualStyleElement element = TrackBarGetVerticalThumbLeftVisualStyleElement (trackBar);
1962 if (!VisualStyleRenderer.IsElementDefined (element)) {
1963 base.TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1966 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1968 static VisualStyleElement TrackBarGetVerticalThumbLeftVisualStyleElement (TrackBar trackBar)
1970 if (TrackBarIsDisabled (trackBar))
1971 return VisualStyleElement.TrackBar.ThumbLeft.Disabled;
1972 else if (TrackBarIsPressed (trackBar))
1973 return VisualStyleElement.TrackBar.ThumbLeft.Pressed;
1974 else if (TrackBarIsHot (trackBar))
1975 return VisualStyleElement.TrackBar.ThumbLeft.Hot;
1976 else if (TrackBarIsFocused (trackBar))
1977 return VisualStyleElement.TrackBar.ThumbLeft.Focused;
1978 return VisualStyleElement.TrackBar.ThumbLeft.Normal;
1980 protected override void TrackBarDrawVerticalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1982 if (!RenderClientAreas) {
1983 base.TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1986 VisualStyleElement element = TrackBarGetVerticalThumbVisualStyleElement (trackBar);
1987 if (!VisualStyleRenderer.IsElementDefined (element)) {
1988 base.TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1991 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1993 static VisualStyleElement TrackBarGetVerticalThumbVisualStyleElement (TrackBar trackBar)
1995 if (TrackBarIsDisabled (trackBar))
1996 return VisualStyleElement.TrackBar.ThumbVertical.Disabled;
1997 else if (TrackBarIsPressed (trackBar))
1998 return VisualStyleElement.TrackBar.ThumbVertical.Pressed;
1999 else if (TrackBarIsHot (trackBar))
2000 return VisualStyleElement.TrackBar.ThumbVertical.Hot;
2001 else if (TrackBarIsFocused (trackBar))
2002 return VisualStyleElement.TrackBar.ThumbVertical.Focused;
2003 return VisualStyleElement.TrackBar.ThumbVertical.Normal;
2008 const EdgeStyle TrackBarTickEdgeStyle = EdgeStyle.Bump;
2009 const EdgeEffects TrackBarTickEdgeEffects = EdgeEffects.None;
2011 protected override ITrackBarTickPainter TrackBarGetHorizontalTickPainter (Graphics g)
2013 if (!RenderClientAreas ||
2014 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.TrackBar.Ticks.Normal))
2015 return base.TrackBarGetHorizontalTickPainter (g);
2016 return new TrackBarHorizontalTickPainter (g);
2018 class TrackBarHorizontalTickPainter : ITrackBarTickPainter
2020 readonly Graphics g;
2021 readonly VisualStyleRenderer renderer;
2022 public TrackBarHorizontalTickPainter (Graphics g)
2025 renderer = new VisualStyleRenderer (VisualStyleElement.TrackBar.Ticks.Normal);
2027 public void Paint (float x1, float y1, float x2, float y2)
2029 renderer.DrawEdge (g, new Rectangle (
2030 (int)Math.Round (x1),
2031 (int)Math.Round (y1),
2033 (int)Math.Round (y2 - y1) + 1), Edges.Left, TrackBarTickEdgeStyle, TrackBarTickEdgeEffects);
2038 protected override ITrackBarTickPainter TrackBarGetVerticalTickPainter (Graphics g)
2040 if (!RenderClientAreas ||
2041 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.TrackBar.TicksVertical.Normal))
2042 return base.TrackBarGetVerticalTickPainter (g);
2043 return new TrackBarVerticalTickPainter (g);
2045 class TrackBarVerticalTickPainter : ITrackBarTickPainter
2047 readonly Graphics g;
2048 readonly VisualStyleRenderer renderer;
2049 public TrackBarVerticalTickPainter (Graphics g)
2052 renderer = new VisualStyleRenderer (VisualStyleElement.TrackBar.TicksVertical.Normal);
2054 public void Paint (float x1, float y1, float x2, float y2)
2056 renderer.DrawEdge (g, new Rectangle (
2057 (int)Math.Round (x1),
2058 (int)Math.Round (y1),
2059 (int)Math.Round (x2 - x1) + 1,
2060 1), Edges.Top, TrackBarTickEdgeStyle, TrackBarTickEdgeEffects);
2065 public override bool TrackBarHasHotThumbStyle {
2067 if (!RenderClientAreas)
2068 return base.TrackBarHasHotThumbStyle;
2074 [MonoTODO("Use the sizing information provided by the VisualStyles API.")]
2075 public override void TreeViewDrawNodePlusMinus (TreeView treeView, TreeNode node, Graphics dc, int x, int middle)
2077 if (!RenderClientAreas) {
2078 base.TreeViewDrawNodePlusMinus (treeView, node, dc, x, middle);
2081 VisualStyleElement element = node.IsExpanded ?
2082 VisualStyleElement.TreeView.Glyph.Opened :
2083 VisualStyleElement.TreeView.Glyph.Closed;
2084 if (!VisualStyleRenderer.IsElementDefined (element)) {
2085 base.TreeViewDrawNodePlusMinus (treeView, node, dc, x, middle);
2088 new VisualStyleRenderer (element).DrawBackground (dc, new Rectangle (x, middle - 4, 9, 9));
2092 public override void UpDownBaseDrawButton (Graphics g, Rectangle bounds, bool top, PushButtonState state)
2094 if (!RenderClientAreas) {
2095 base.UpDownBaseDrawButton (g, bounds, top, state);
2098 VisualStyleElement element;
2101 case PushButtonState.Disabled:
2102 element = VisualStyleElement.Spin.Up.Disabled;
2104 case PushButtonState.Pressed:
2105 element = VisualStyleElement.Spin.Up.Pressed;
2107 case PushButtonState.Hot:
2108 element = VisualStyleElement.Spin.Up.Hot;
2111 element = VisualStyleElement.Spin.Up.Normal;
2116 case PushButtonState.Disabled:
2117 element = VisualStyleElement.Spin.Down.Disabled;
2119 case PushButtonState.Pressed:
2120 element = VisualStyleElement.Spin.Down.Pressed;
2122 case PushButtonState.Hot:
2123 element = VisualStyleElement.Spin.Down.Hot;
2126 element = VisualStyleElement.Spin.Down.Normal;
2129 if (!VisualStyleRenderer.IsElementDefined (element)) {
2130 base.UpDownBaseDrawButton (g, bounds, top, state);
2133 new VisualStyleRenderer (element).DrawBackground (g, bounds);
2135 public override bool UpDownBaseHasHotButtonStyle {
2137 if (!RenderClientAreas)
2138 return base.UpDownBaseHasHotButtonStyle;
2146 static bool AreEqual (VisualStyleElement value1, VisualStyleElement value2)
2149 value1.ClassName == value1.ClassName &&
2150 value1.Part == value2.Part &&
2151 value1.State == value2.State;
2154 #region Measurement device context
2155 static Control control;
2156 static IDeviceContext GetMeasurementDeviceContext ()
2158 if (control == null)
2159 control = new Control ();
2160 return control.CreateGraphics ();
2162 static void ReleaseMeasurementDeviceContext (IDeviceContext dc)