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 ? 1 : 0));
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 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;
1164 int block_count = 0;
1165 int increment = block_width + renderer.GetInteger (IntegerProperty.ProgressSpaceSize);
1166 Rectangle block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height);
1168 if (max_blocks != int.MaxValue) {
1169 if (block_count == max_blocks)
1171 if (block_rect.Right >= client_area.Width)
1172 block_rect.X -= client_area.Width;
1174 if (block_rect.X >= first_pixel_outside_filled_area)
1176 if (block_rect.Right >= first_pixel_outside_filled_area)
1177 if (first_pixel_outside_filled_area == client_area.Right)
1178 block_rect.Width = first_pixel_outside_filled_area - block_rect.X;
1182 if (clip_rect.IntersectsWith (block_rect))
1183 renderer.DrawBackground (dc, block_rect, clip_rect);
1184 block_rect.X += increment;
1192 protected override void RadioButton_DrawButton (RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle) {
1193 if (radio_button.Appearance == Appearance.Normal && radio_button.FlatStyle == FlatStyle.System) {
1194 RadioButtonRenderer.DrawRadioButton (
1196 new Point (radiobutton_rectangle.Left, radiobutton_rectangle.Top),
1197 GetRadioButtonState (radio_button)
1201 base.RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
1203 static RadioButtonState GetRadioButtonState (RadioButton checkBox)
1205 if (checkBox.Checked) {
1206 if (!checkBox.Enabled)
1207 return RadioButtonState.CheckedDisabled;
1208 else if (checkBox.Pressed)
1209 return RadioButtonState.CheckedPressed;
1210 else if (checkBox.Entered)
1211 return RadioButtonState.CheckedHot;
1212 return RadioButtonState.CheckedNormal;
1214 if (!checkBox.Enabled)
1215 return RadioButtonState.UncheckedDisabled;
1216 else if (checkBox.Pressed)
1217 return RadioButtonState.UncheckedPressed;
1218 else if (checkBox.Entered)
1219 return RadioButtonState.UncheckedHot;
1220 return RadioButtonState.UncheckedNormal;
1225 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
1227 if (!RenderClientAreas ||
1228 !ScrollBarAreElementsDefined) {
1229 base.DrawScrollBar (dc, clip, bar);
1232 VisualStyleElement element;
1233 VisualStyleRenderer renderer;
1234 int scroll_button_width = bar.scrollbutton_width;
1235 int scroll_button_height = bar.scrollbutton_height;
1237 bar.FirstArrowArea = new Rectangle (0, 0, bar.Width, scroll_button_height);
1238 bar.SecondArrowArea = new Rectangle (
1240 bar.ClientRectangle.Height - scroll_button_height,
1242 scroll_button_height);
1243 Rectangle thumb_pos = bar.ThumbPos;
1244 thumb_pos.Width = bar.Width;
1245 bar.ThumbPos = thumb_pos;
1246 #region Background, upper track
1247 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
1248 element = VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed;
1250 element = bar.Enabled ?
1251 VisualStyleElement.ScrollBar.LowerTrackVertical.Normal :
1252 VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1253 renderer = new VisualStyleRenderer (element);
1254 Rectangle upper_track_rect = new Rectangle (
1257 bar.ClientRectangle.Width,
1259 if (clip.IntersectsWith (upper_track_rect))
1260 renderer.DrawBackground (dc, upper_track_rect, clip);
1262 #region Background, lower track
1263 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
1264 element = VisualStyles.VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed;
1266 element = bar.Enabled ?
1267 VisualStyleElement.ScrollBar.LowerTrackVertical.Normal :
1268 VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1269 renderer = new VisualStyleRenderer (element);
1270 Rectangle lower_track_rect = new Rectangle (
1272 bar.ThumbPos.Bottom,
1273 bar.ClientRectangle.Width,
1274 bar.ClientRectangle.Height - bar.ThumbPos.Bottom);
1275 if (clip.IntersectsWith (lower_track_rect))
1276 renderer.DrawBackground (dc, lower_track_rect, clip);
1279 if (clip.IntersectsWith (bar.FirstArrowArea)) {
1281 element = VisualStyleElement.ScrollBar.ArrowButton.UpDisabled;
1282 else if (bar.firstbutton_state == ButtonState.Pushed)
1283 element = VisualStyleElement.ScrollBar.ArrowButton.UpPressed;
1284 else if (bar.FirstButtonEntered)
1285 element = VisualStyleElement.ScrollBar.ArrowButton.UpHot;
1286 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1287 element = VisualStyleElement.ScrollBar.ArrowButton.UpHover;
1289 element = VisualStyleElement.ScrollBar.ArrowButton.UpNormal;
1290 renderer = new VisualStyleRenderer (element);
1291 renderer.DrawBackground (dc, bar.FirstArrowArea);
1293 if (clip.IntersectsWith (bar.SecondArrowArea)) {
1295 element = VisualStyleElement.ScrollBar.ArrowButton.DownDisabled;
1296 else if (bar.secondbutton_state == ButtonState.Pushed)
1297 element = VisualStyleElement.ScrollBar.ArrowButton.DownPressed;
1298 else if (bar.SecondButtonEntered)
1299 element = VisualStyleElement.ScrollBar.ArrowButton.DownHot;
1300 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1301 element = VisualStyleElement.ScrollBar.ArrowButton.DownHover;
1303 element = VisualStyleElement.ScrollBar.ArrowButton.DownNormal;
1304 renderer = new VisualStyleRenderer (element);
1305 renderer.DrawBackground (dc, bar.SecondArrowArea);
1308 #region Thumb and grip
1310 element = VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1311 else if (bar.ThumbPressed)
1312 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed;
1313 else if (bar.ThumbEntered)
1314 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot;
1316 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal;
1317 renderer = new VisualStyleRenderer (element);
1318 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1320 if (bar.Enabled && bar.ThumbPos.Height >= 20) {
1321 element = VisualStyleElement.ScrollBar.GripperVertical.Normal;
1322 renderer = new VisualStyleRenderer (element);
1323 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1327 bar.FirstArrowArea = new Rectangle (0, 0, scroll_button_width, bar.Height);
1328 bar.SecondArrowArea = new Rectangle (
1329 bar.ClientRectangle.Width - scroll_button_width,
1331 scroll_button_width,
1333 Rectangle thumb_pos = bar.ThumbPos;
1334 thumb_pos.Height = bar.Height;
1335 bar.ThumbPos = thumb_pos;
1336 #region Background, left track
1337 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
1338 element = VisualStyleElement.ScrollBar.LeftTrackHorizontal.Pressed;
1340 element = bar.Enabled ?
1341 VisualStyleElement.ScrollBar.LeftTrackHorizontal.Normal :
1342 VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled;
1343 renderer = new VisualStyleRenderer (element);
1344 Rectangle left_track_rect = new Rectangle (
1348 bar.ClientRectangle.Height);
1349 if (clip.IntersectsWith (left_track_rect))
1350 renderer.DrawBackground (dc, left_track_rect, clip);
1352 #region Background, right track
1353 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
1354 element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Pressed;
1356 element = bar.Enabled ?
1357 VisualStyleElement.ScrollBar.RightTrackHorizontal.Normal :
1358 VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
1359 renderer = new VisualStyleRenderer (element);
1360 Rectangle right_track_rect = new Rectangle (
1363 bar.ClientRectangle.Width - bar.ThumbPos.Right,
1364 bar.ClientRectangle.Height);
1365 if (clip.IntersectsWith (right_track_rect))
1366 renderer.DrawBackground (dc, right_track_rect, clip);
1369 if (clip.IntersectsWith (bar.FirstArrowArea)) {
1371 element = VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled;
1372 else if (bar.firstbutton_state == ButtonState.Pushed)
1373 element = VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
1374 else if (bar.FirstButtonEntered)
1375 element = VisualStyleElement.ScrollBar.ArrowButton.LeftHot;
1376 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1377 element = VisualStyleElement.ScrollBar.ArrowButton.LeftHover;
1379 element = VisualStyleElement.ScrollBar.ArrowButton.LeftNormal;
1380 renderer = new VisualStyleRenderer (element);
1381 renderer.DrawBackground (dc, bar.FirstArrowArea);
1383 if (clip.IntersectsWith (bar.SecondArrowArea)) {
1385 element = VisualStyleElement.ScrollBar.ArrowButton.RightDisabled;
1386 else if (bar.secondbutton_state == ButtonState.Pushed)
1387 element = VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
1388 else if (bar.SecondButtonEntered)
1389 element = VisualStyleElement.ScrollBar.ArrowButton.RightHot;
1390 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1391 element = VisualStyleElement.ScrollBar.ArrowButton.RightHover;
1393 element = VisualStyleElement.ScrollBar.ArrowButton.RightNormal;
1394 renderer = new VisualStyleRenderer (element);
1395 renderer.DrawBackground (dc, bar.SecondArrowArea);
1398 #region Thumb and grip
1400 element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
1401 else if (bar.ThumbPressed)
1402 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Pressed;
1403 else if (bar.ThumbEntered)
1404 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Hot;
1406 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Normal;
1407 renderer = new VisualStyleRenderer (element);
1408 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1410 if (bar.Enabled && bar.ThumbPos.Height >= 20) {
1411 element = VisualStyleElement.ScrollBar.GripperHorizontal.Normal;
1412 renderer = new VisualStyleRenderer (element);
1413 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1418 public override bool ScrollBarHasHotElementStyles {
1420 if (!RenderClientAreas)
1421 return base.ScrollBarHasHotElementStyles;
1422 return ScrollBarAreElementsDefined;
1425 public override bool ScrollBarHasPressedThumbStyle {
1427 if (!RenderClientAreas)
1428 return base.ScrollBarHasPressedThumbStyle;
1429 return ScrollBarAreElementsDefined;
1432 const int WindowsVistaMajorVersion = 6;
1433 static bool ScrollBarHasHoverArrowButtonStyleVisualStyles =
1434 Environment.OSVersion.Version.Major >= WindowsVistaMajorVersion;
1435 public override bool ScrollBarHasHoverArrowButtonStyle {
1437 if (RenderClientAreas &&
1438 ScrollBarHasHoverArrowButtonStyleVisualStyles)
1439 return ScrollBarAreElementsDefined;
1440 return base.ScrollBarHasHoverArrowButtonStyle;
1443 static bool ScrollBarAreElementsDefined {
1446 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ArrowButton.DownDisabled) &&
1447 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.GripperHorizontal.Normal) &&
1448 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.GripperVertical.Normal) &&
1449 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled) &&
1450 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled) &&
1451 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled) &&
1452 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.SizeBox.LeftAlign) &&
1453 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Disabled) &&
1454 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ThumbButtonVertical.Disabled) &&
1455 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.UpperTrackVertical.Disabled);
1460 protected override void DrawStatusBarBackground(Graphics dc, Rectangle clip, StatusBar sb) {
1461 if (!RenderClientAreas) {
1462 base.DrawStatusBarBackground (dc, clip, sb);
1465 VisualStyleElement element = VisualStyleElement.Status.Bar.Normal;
1466 if (!VisualStyleRenderer.IsElementDefined (element)) {
1467 base.DrawStatusBarBackground (dc, clip, sb);
1470 new VisualStyleRenderer (element).DrawBackground (dc, sb.ClientRectangle, clip);
1472 protected override void DrawStatusBarSizingGrip (Graphics dc, Rectangle clip, StatusBar sb, Rectangle area)
1474 if (!RenderClientAreas) {
1475 base.DrawStatusBarSizingGrip (dc, clip, sb, area);
1478 VisualStyleElement element = VisualStyleElement.Status.Gripper.Normal;
1479 if (!VisualStyleRenderer.IsElementDefined (element)) {
1480 base.DrawStatusBarSizingGrip (dc, clip, sb, area);
1483 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1484 Rectangle sizing_grip_rectangle = new Rectangle (Point.Empty, renderer.GetPartSize (dc, ThemeSizeType.True));
1485 sizing_grip_rectangle.X = sb.Width - sizing_grip_rectangle.Width;
1486 sizing_grip_rectangle.Y = sb.Height - sizing_grip_rectangle.Height;
1487 renderer.DrawBackground (dc, sizing_grip_rectangle, clip);
1489 protected override void DrawStatusBarPanelBackground (Graphics dc, Rectangle area, StatusBarPanel panel)
1491 if (!RenderClientAreas) {
1492 base.DrawStatusBarPanelBackground (dc, area, panel);
1495 VisualStyleElement element = VisualStyleElement.Status.Pane.Normal;
1496 if (!VisualStyleRenderer.IsElementDefined (element)) {
1497 base.DrawStatusBarPanelBackground (dc, area, panel);
1500 new VisualStyleRenderer (element).DrawBackground (dc, area);
1504 static bool TextBoxBaseShouldPaint (TextBoxBase textBoxBase)
1506 return textBoxBase.BorderStyle == BorderStyle.Fixed3D;
1508 static VisualStyleElement TextBoxBaseGetVisualStyleElement (TextBoxBase textBoxBase)
1510 if (!textBoxBase.Enabled)
1511 return VisualStyleElement.TextBox.TextEdit.Disabled;
1512 if (textBoxBase.ReadOnly)
1513 return VisualStyleElement.TextBox.TextEdit.ReadOnly;
1514 if (textBoxBase.Entered)
1515 return VisualStyleElement.TextBox.TextEdit.Hot;
1516 if (textBoxBase.Focused)
1517 return VisualStyleElement.TextBox.TextEdit.Focused;
1518 return VisualStyleElement.TextBox.TextEdit.Normal;
1520 public override void TextBoxBaseFillBackground (TextBoxBase textBoxBase, Graphics g, Rectangle clippingArea)
1522 if (!RenderClientAreas ||
1523 !TextBoxBaseShouldPaint (textBoxBase)) {
1524 base.TextBoxBaseFillBackground (textBoxBase, g, clippingArea);
1527 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1528 if (!VisualStyleRenderer.IsElementDefined (element)) {
1529 base.TextBoxBaseFillBackground (textBoxBase, g, clippingArea);
1532 Rectangle bounds = new Rectangle(Point.Empty, textBoxBase.Size);
1533 bounds.X -= (bounds.Width - textBoxBase.ClientSize.Width) / 2;
1534 bounds.Y -= (bounds.Height - textBoxBase.ClientSize.Height) / 2;
1535 new VisualStyleRenderer (element).DrawBackground (g, bounds, clippingArea);
1537 public override bool TextBoxBaseHandleWmNcPaint (TextBoxBase textBoxBase, ref Message m)
1539 if (!RenderClientAreas ||
1540 !TextBoxBaseShouldPaint (textBoxBase))
1541 return base.TextBoxBaseHandleWmNcPaint (textBoxBase, ref m);
1542 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1543 if (!VisualStyleRenderer.IsElementDefined (element))
1544 return base.TextBoxBaseHandleWmNcPaint (textBoxBase, ref m);
1545 PaintEventArgs e = XplatUI.PaintEventStart (ref m, textBoxBase.Handle, false);
1546 new VisualStyleRenderer (element).DrawBackgroundExcludingArea (
1548 new Rectangle (Point.Empty, textBoxBase.Size),
1549 new Rectangle (new Point ((textBoxBase.Width - textBoxBase.ClientSize.Width) / 2,
1550 (textBoxBase.Height - textBoxBase.ClientSize.Height) / 2),
1551 textBoxBase.ClientSize));
1552 XplatUI.PaintEventEnd (ref m, textBoxBase.Handle, false);
1555 public override bool TextBoxBaseShouldPaintBackground (TextBoxBase textBoxBase)
1557 if (!RenderClientAreas ||
1558 !TextBoxBaseShouldPaint (textBoxBase))
1559 return base.TextBoxBaseShouldPaintBackground (textBoxBase);
1560 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1561 if (!VisualStyleRenderer.IsElementDefined (element))
1562 return base.TextBoxBaseShouldPaintBackground (textBoxBase);
1563 return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
1567 static bool ToolBarIsDisabled (ToolBarItem item)
1569 return !item.Button.Enabled;
1571 static bool ToolBarIsPressed (ToolBarItem item)
1573 return item.Pressed;
1575 static bool ToolBarIsChecked (ToolBarItem item)
1577 return item.Button.Pushed;
1579 static bool ToolBarIsHot (ToolBarItem item)
1581 return item.Hilight;
1584 protected override void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat)
1586 if (!RenderClientAreas) {
1587 base.DrawToolBarButtonBorder (dc, item, is_flat);
1590 if (item.Button.Style == ToolBarButtonStyle.Separator)
1592 VisualStyleElement element;
1593 if (item.Button.Style == ToolBarButtonStyle.DropDownButton)
1594 element = ToolBarGetDropDownButtonVisualStyleElement (item);
1596 element = ToolBarGetButtonVisualStyleElement (item);
1597 if (!VisualStyleRenderer.IsElementDefined (element)) {
1598 base.DrawToolBarButtonBorder (dc, item, is_flat);
1601 Rectangle rectangle = item.Rectangle;
1602 if (item.Button.Style == ToolBarButtonStyle.DropDownButton && item.Button.Parent.DropDownArrows)
1603 rectangle.Width -= ToolBarDropDownWidth;
1604 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
1606 private static VisualStyleElement ToolBarGetDropDownButtonVisualStyleElement (ToolBarItem item)
1608 if (item.Button.Parent.DropDownArrows) {
1609 if (ToolBarIsDisabled (item))
1610 return VisualStyleElement.ToolBar.SplitButton.Disabled;
1611 if (ToolBarIsPressed (item))
1612 return VisualStyleElement.ToolBar.SplitButton.Pressed;
1613 if (ToolBarIsChecked (item))
1614 if (ToolBarIsHot (item))
1615 return VisualStyleElement.ToolBar.SplitButton.HotChecked;
1617 return VisualStyleElement.ToolBar.SplitButton.Checked;
1618 if (ToolBarIsHot (item))
1619 return VisualStyleElement.ToolBar.SplitButton.Hot;
1620 return VisualStyleElement.ToolBar.SplitButton.Normal;
1622 if (ToolBarIsDisabled (item))
1623 return VisualStyleElement.ToolBar.DropDownButton.Disabled;
1624 if (ToolBarIsPressed (item))
1625 return VisualStyleElement.ToolBar.DropDownButton.Pressed;
1626 if (ToolBarIsChecked (item))
1627 if (ToolBarIsHot (item))
1628 return VisualStyleElement.ToolBar.DropDownButton.HotChecked;
1630 return VisualStyleElement.ToolBar.DropDownButton.Checked;
1631 if (ToolBarIsHot (item))
1632 return VisualStyleElement.ToolBar.DropDownButton.Hot;
1633 return VisualStyleElement.ToolBar.DropDownButton.Normal;
1636 private static VisualStyleElement ToolBarGetButtonVisualStyleElement (ToolBarItem item)
1638 if (ToolBarIsDisabled (item))
1639 return VisualStyleElement.ToolBar.Button.Disabled;
1640 if (ToolBarIsPressed (item))
1641 return VisualStyleElement.ToolBar.Button.Pressed;
1642 if (ToolBarIsChecked (item))
1643 if (ToolBarIsHot (item))
1644 return VisualStyleElement.ToolBar.Button.HotChecked;
1646 return VisualStyleElement.ToolBar.Button.Checked;
1647 if (ToolBarIsHot (item))
1648 return VisualStyleElement.ToolBar.Button.Hot;
1649 return VisualStyleElement.ToolBar.Button.Normal;
1653 protected override void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
1655 if (!RenderClientAreas) {
1656 base.DrawToolBarSeparator (dc, item);
1659 VisualStyleElement element = ToolBarGetSeparatorVisualStyleElement (item);
1660 if (!VisualStyleRenderer.IsElementDefined (element)) {
1661 base.DrawToolBarSeparator (dc, item);
1664 new VisualStyleRenderer (element).DrawBackground (dc, item.Rectangle);
1666 static VisualStyleElement ToolBarGetSeparatorVisualStyleElement (ToolBarItem toolBarItem)
1668 return toolBarItem.Button.Parent.Vertical ?
1669 VisualStyleElement.ToolBar.SeparatorVertical.Normal :
1670 VisualStyleElement.ToolBar.SeparatorHorizontal.Normal;
1673 #region Toggle button background
1674 protected override void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item)
1676 if (!RenderClientAreas ||
1677 !VisualStyleRenderer.IsElementDefined (ToolBarGetButtonVisualStyleElement (item)))
1678 base.DrawToolBarToggleButtonBackground (dc, item);
1681 #region Drop down arrow
1682 protected override void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
1684 if (!RenderClientAreas) {
1685 base.DrawToolBarDropDownArrow (dc, item, is_flat);
1688 VisualStyleElement element = ToolBarGetDropDownArrowVisualStyleElement (item);
1689 if (!VisualStyleRenderer.IsElementDefined (element)) {
1690 base.DrawToolBarDropDownArrow (dc, item, is_flat);
1693 Rectangle rect = item.Rectangle;
1694 rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
1695 rect.Width = ToolBarDropDownWidth;
1696 new VisualStyleRenderer (element).DrawBackground (dc, rect);
1698 private static VisualStyleElement ToolBarGetDropDownArrowVisualStyleElement (ToolBarItem item)
1700 if (ToolBarIsDisabled (item))
1701 return VisualStyleElement.ToolBar.SplitButtonDropDown.Disabled;
1702 if (ToolBarIsPressed (item))
1703 return VisualStyleElement.ToolBar.SplitButtonDropDown.Pressed;
1704 if (ToolBarIsChecked (item))
1705 if (ToolBarIsHot (item))
1706 return VisualStyleElement.ToolBar.SplitButtonDropDown.HotChecked;
1708 return VisualStyleElement.ToolBar.SplitButtonDropDown.Checked;
1709 if (ToolBarIsHot (item))
1710 return VisualStyleElement.ToolBar.SplitButtonDropDown.Hot;
1711 return VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
1714 public override bool ToolBarHasHotElementStyles (ToolBar toolBar)
1716 if (!RenderClientAreas)
1717 return base.ToolBarHasHotElementStyles (toolBar);
1720 public override bool ToolBarHasHotCheckedElementStyles {
1722 if (!RenderClientAreas)
1723 return base.ToolBarHasHotCheckedElementStyles;
1729 protected override void ToolTipDrawBackground (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
1731 if (!RenderClientAreas) {
1732 base.ToolTipDrawBackground (dc, clip_rectangle, control);
1735 VisualStyleElement element = VisualStyleElement.ToolTip.Standard.Normal;
1736 if (!VisualStyleRenderer.IsElementDefined (element)) {
1737 base.ToolTipDrawBackground (dc, clip_rectangle, control);
1740 new VisualStyleRenderer (element).DrawBackground (dc, control.Bounds);
1742 public override bool ToolTipTransparentBackground {
1744 if (!RenderClientAreas)
1745 return base.ToolTipTransparentBackground;
1746 VisualStyleElement element = VisualStyleElement.ToolTip.Standard.Normal;
1747 if (!VisualStyleRenderer.IsElementDefined (element))
1748 return base.ToolTipTransparentBackground;
1749 return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
1754 protected override Size TrackBarGetThumbSize (TrackBar trackBar)
1756 if (!RenderClientAreas)
1757 return base.TrackBarGetThumbSize (trackBar);
1758 VisualStyleElement element = TrackBarGetThumbVisualStyleElement (trackBar);
1759 if (!VisualStyleRenderer.IsElementDefined (element))
1760 return base.TrackBarGetThumbSize (trackBar);
1761 Graphics g = trackBar.CreateGraphics ();
1762 Size result = new VisualStyleRenderer (element).GetPartSize (g, ThemeSizeType.True);
1764 return trackBar.Orientation == Orientation.Horizontal ? result : TrackBarRotateVerticalThumbSize (result);
1766 static VisualStyleElement TrackBarGetThumbVisualStyleElement (TrackBar trackBar)
1768 if (trackBar.Orientation == Orientation.Horizontal)
1769 switch (trackBar.TickStyle) {
1770 case TickStyle.BottomRight:
1771 case TickStyle.None:
1772 return TrackBarGetHorizontalThumbBottomVisualStyleElement (trackBar);
1773 case TickStyle.TopLeft:
1774 return TrackBarGetHorizontalThumbTopVisualStyleElement (trackBar);
1776 return TrackBarGetHorizontalThumbVisualStyleElement (trackBar);
1779 switch (trackBar.TickStyle) {
1780 case TickStyle.BottomRight:
1781 case TickStyle.None:
1782 return TrackBarGetVerticalThumbRightVisualStyleElement (trackBar);
1783 case TickStyle.TopLeft:
1784 return TrackBarGetVerticalThumbLeftVisualStyleElement (trackBar);
1786 return TrackBarGetVerticalThumbVisualStyleElement (trackBar);
1789 static Size TrackBarRotateVerticalThumbSize (Size value)
1791 int temporary = value.Width;
1792 value.Width = value.Height;
1793 value.Height = temporary;
1797 protected override void TrackBarDrawHorizontalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
1799 if (!RenderClientAreas) {
1800 base.TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1803 VisualStyleElement element = VisualStyleElement.TrackBar.Track.Normal;
1804 if (!VisualStyleRenderer.IsElementDefined (element)) {
1805 base.TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1808 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1809 renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (thumb_area.Width, renderer.GetPartSize (dc, ThemeSizeType.True).Height)), clippingArea);
1811 protected override void TrackBarDrawVerticalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
1813 if (!RenderClientAreas) {
1814 base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1817 VisualStyleElement element = VisualStyleElement.TrackBar.TrackVertical.Normal;
1818 if (!VisualStyleRenderer.IsElementDefined (element)) {
1819 base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1822 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1823 renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (renderer.GetPartSize (dc, ThemeSizeType.True).Width, thumb_area.Height)), clippingArea);
1827 static bool TrackBarIsDisabled (TrackBar trackBar)
1829 return !trackBar.Enabled;
1831 static bool TrackBarIsHot (TrackBar trackBar)
1833 return trackBar.ThumbEntered;
1835 static bool TrackBarIsPressed (TrackBar trackBar)
1837 return trackBar.thumb_pressed;
1839 static bool TrackBarIsFocused (TrackBar trackBar)
1841 return trackBar.Focused;
1844 protected override void TrackBarDrawHorizontalThumbBottom (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1846 if (!RenderClientAreas) {
1847 base.TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1850 VisualStyleElement element = TrackBarGetHorizontalThumbBottomVisualStyleElement (trackBar);
1851 if (!VisualStyleRenderer.IsElementDefined (element)) {
1852 base.TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1855 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1857 static VisualStyleElement TrackBarGetHorizontalThumbBottomVisualStyleElement (TrackBar trackBar)
1859 if (TrackBarIsDisabled (trackBar))
1860 return VisualStyleElement.TrackBar.ThumbBottom.Disabled;
1861 else if (TrackBarIsPressed (trackBar))
1862 return VisualStyleElement.TrackBar.ThumbBottom.Pressed;
1863 else if (TrackBarIsHot (trackBar))
1864 return VisualStyleElement.TrackBar.ThumbBottom.Hot;
1865 else if (TrackBarIsFocused (trackBar))
1866 return VisualStyleElement.TrackBar.ThumbBottom.Focused;
1867 return VisualStyleElement.TrackBar.ThumbBottom.Normal;
1869 protected override void TrackBarDrawHorizontalThumbTop (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1871 if (!RenderClientAreas) {
1872 base.TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1875 VisualStyleElement element = TrackBarGetHorizontalThumbTopVisualStyleElement (trackBar);
1876 if (!VisualStyleRenderer.IsElementDefined (element)) {
1877 base.TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1880 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1882 static VisualStyleElement TrackBarGetHorizontalThumbTopVisualStyleElement (TrackBar trackBar)
1884 if (TrackBarIsDisabled (trackBar))
1885 return VisualStyleElement.TrackBar.ThumbTop.Disabled;
1886 else if (TrackBarIsPressed (trackBar))
1887 return VisualStyleElement.TrackBar.ThumbTop.Pressed;
1888 else if (TrackBarIsHot (trackBar))
1889 return VisualStyleElement.TrackBar.ThumbTop.Hot;
1890 else if (TrackBarIsFocused (trackBar))
1891 return VisualStyleElement.TrackBar.ThumbTop.Focused;
1892 return VisualStyleElement.TrackBar.ThumbTop.Normal;
1894 protected override void TrackBarDrawHorizontalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1896 if (!RenderClientAreas) {
1897 base.TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1900 VisualStyleElement element = TrackBarGetHorizontalThumbVisualStyleElement (trackBar);
1901 if (!VisualStyleRenderer.IsElementDefined (element)) {
1902 base.TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1905 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1907 static VisualStyleElement TrackBarGetHorizontalThumbVisualStyleElement (TrackBar trackBar)
1909 if (TrackBarIsDisabled (trackBar))
1910 return VisualStyleElement.TrackBar.Thumb.Disabled;
1911 else if (TrackBarIsPressed (trackBar))
1912 return VisualStyleElement.TrackBar.Thumb.Pressed;
1913 else if (TrackBarIsHot (trackBar))
1914 return VisualStyleElement.TrackBar.Thumb.Hot;
1915 else if (TrackBarIsFocused (trackBar))
1916 return VisualStyleElement.TrackBar.Thumb.Focused;
1917 return VisualStyleElement.TrackBar.Thumb.Normal;
1921 static Rectangle TrackBarRotateVerticalThumbSize (Rectangle value)
1923 int temporary = value.Width;
1924 value.Width = value.Height;
1925 value.Height = temporary;
1928 protected override void TrackBarDrawVerticalThumbRight (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1930 if (!RenderClientAreas) {
1931 base.TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1934 VisualStyleElement element = TrackBarGetVerticalThumbRightVisualStyleElement (trackBar);
1935 if (!VisualStyleRenderer.IsElementDefined (element)) {
1936 base.TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1939 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1941 static VisualStyleElement TrackBarGetVerticalThumbRightVisualStyleElement (TrackBar trackBar)
1943 if (TrackBarIsDisabled (trackBar))
1944 return VisualStyleElement.TrackBar.ThumbRight.Disabled;
1945 else if (TrackBarIsPressed (trackBar))
1946 return VisualStyleElement.TrackBar.ThumbRight.Pressed;
1947 else if (TrackBarIsHot (trackBar))
1948 return VisualStyleElement.TrackBar.ThumbRight.Hot;
1949 else if (TrackBarIsFocused (trackBar))
1950 return VisualStyleElement.TrackBar.ThumbRight.Focused;
1951 return VisualStyleElement.TrackBar.ThumbRight.Normal;
1953 protected override void TrackBarDrawVerticalThumbLeft (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1955 if (!RenderClientAreas) {
1956 base.TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1959 VisualStyleElement element = TrackBarGetVerticalThumbLeftVisualStyleElement (trackBar);
1960 if (!VisualStyleRenderer.IsElementDefined (element)) {
1961 base.TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1964 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1966 static VisualStyleElement TrackBarGetVerticalThumbLeftVisualStyleElement (TrackBar trackBar)
1968 if (TrackBarIsDisabled (trackBar))
1969 return VisualStyleElement.TrackBar.ThumbLeft.Disabled;
1970 else if (TrackBarIsPressed (trackBar))
1971 return VisualStyleElement.TrackBar.ThumbLeft.Pressed;
1972 else if (TrackBarIsHot (trackBar))
1973 return VisualStyleElement.TrackBar.ThumbLeft.Hot;
1974 else if (TrackBarIsFocused (trackBar))
1975 return VisualStyleElement.TrackBar.ThumbLeft.Focused;
1976 return VisualStyleElement.TrackBar.ThumbLeft.Normal;
1978 protected override void TrackBarDrawVerticalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1980 if (!RenderClientAreas) {
1981 base.TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1984 VisualStyleElement element = TrackBarGetVerticalThumbVisualStyleElement (trackBar);
1985 if (!VisualStyleRenderer.IsElementDefined (element)) {
1986 base.TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1989 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1991 static VisualStyleElement TrackBarGetVerticalThumbVisualStyleElement (TrackBar trackBar)
1993 if (TrackBarIsDisabled (trackBar))
1994 return VisualStyleElement.TrackBar.ThumbVertical.Disabled;
1995 else if (TrackBarIsPressed (trackBar))
1996 return VisualStyleElement.TrackBar.ThumbVertical.Pressed;
1997 else if (TrackBarIsHot (trackBar))
1998 return VisualStyleElement.TrackBar.ThumbVertical.Hot;
1999 else if (TrackBarIsFocused (trackBar))
2000 return VisualStyleElement.TrackBar.ThumbVertical.Focused;
2001 return VisualStyleElement.TrackBar.ThumbVertical.Normal;
2006 const EdgeStyle TrackBarTickEdgeStyle = EdgeStyle.Bump;
2007 const EdgeEffects TrackBarTickEdgeEffects = EdgeEffects.None;
2009 protected override ITrackBarTickPainter TrackBarGetHorizontalTickPainter (Graphics g)
2011 if (!RenderClientAreas ||
2012 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.TrackBar.Ticks.Normal))
2013 return base.TrackBarGetHorizontalTickPainter (g);
2014 return new TrackBarHorizontalTickPainter (g);
2016 class TrackBarHorizontalTickPainter : ITrackBarTickPainter
2018 readonly Graphics g;
2019 readonly VisualStyleRenderer renderer;
2020 public TrackBarHorizontalTickPainter (Graphics g)
2023 renderer = new VisualStyleRenderer (VisualStyleElement.TrackBar.Ticks.Normal);
2025 public void Paint (float x1, float y1, float x2, float y2)
2027 renderer.DrawEdge (g, new Rectangle (
2028 (int)Math.Round (x1),
2029 (int)Math.Round (y1),
2031 (int)Math.Round (y2 - y1) + 1), Edges.Left, TrackBarTickEdgeStyle, TrackBarTickEdgeEffects);
2036 protected override ITrackBarTickPainter TrackBarGetVerticalTickPainter (Graphics g)
2038 if (!RenderClientAreas ||
2039 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.TrackBar.TicksVertical.Normal))
2040 return base.TrackBarGetVerticalTickPainter (g);
2041 return new TrackBarVerticalTickPainter (g);
2043 class TrackBarVerticalTickPainter : ITrackBarTickPainter
2045 readonly Graphics g;
2046 readonly VisualStyleRenderer renderer;
2047 public TrackBarVerticalTickPainter (Graphics g)
2050 renderer = new VisualStyleRenderer (VisualStyleElement.TrackBar.TicksVertical.Normal);
2052 public void Paint (float x1, float y1, float x2, float y2)
2054 renderer.DrawEdge (g, new Rectangle (
2055 (int)Math.Round (x1),
2056 (int)Math.Round (y1),
2057 (int)Math.Round (x2 - x1) + 1,
2058 1), Edges.Top, TrackBarTickEdgeStyle, TrackBarTickEdgeEffects);
2063 public override bool TrackBarHasHotThumbStyle {
2065 if (!RenderClientAreas)
2066 return base.TrackBarHasHotThumbStyle;
2072 [MonoTODO("Use the sizing information provided by the VisualStyles API.")]
2073 public override void TreeViewDrawNodePlusMinus (TreeView treeView, TreeNode node, Graphics dc, int x, int middle)
2075 if (!RenderClientAreas) {
2076 base.TreeViewDrawNodePlusMinus (treeView, node, dc, x, middle);
2079 VisualStyleElement element = node.IsExpanded ?
2080 VisualStyleElement.TreeView.Glyph.Opened :
2081 VisualStyleElement.TreeView.Glyph.Closed;
2082 if (!VisualStyleRenderer.IsElementDefined (element)) {
2083 base.TreeViewDrawNodePlusMinus (treeView, node, dc, x, middle);
2086 new VisualStyleRenderer (element).DrawBackground (dc, new Rectangle (x, middle - 4, 9, 9));
2090 public override void UpDownBaseDrawButton (Graphics g, Rectangle bounds, bool top, PushButtonState state)
2092 if (!RenderClientAreas) {
2093 base.UpDownBaseDrawButton (g, bounds, top, state);
2096 VisualStyleElement element;
2099 case PushButtonState.Disabled:
2100 element = VisualStyleElement.Spin.Up.Disabled;
2102 case PushButtonState.Pressed:
2103 element = VisualStyleElement.Spin.Up.Pressed;
2105 case PushButtonState.Hot:
2106 element = VisualStyleElement.Spin.Up.Hot;
2109 element = VisualStyleElement.Spin.Up.Normal;
2114 case PushButtonState.Disabled:
2115 element = VisualStyleElement.Spin.Down.Disabled;
2117 case PushButtonState.Pressed:
2118 element = VisualStyleElement.Spin.Down.Pressed;
2120 case PushButtonState.Hot:
2121 element = VisualStyleElement.Spin.Down.Hot;
2124 element = VisualStyleElement.Spin.Down.Normal;
2127 if (!VisualStyleRenderer.IsElementDefined (element)) {
2128 base.UpDownBaseDrawButton (g, bounds, top, state);
2131 new VisualStyleRenderer (element).DrawBackground (g, bounds);
2133 public override bool UpDownBaseHasHotButtonStyle {
2135 if (!RenderClientAreas)
2136 return base.UpDownBaseHasHotButtonStyle;
2144 static bool AreEqual (VisualStyleElement value1, VisualStyleElement value2)
2147 value1.ClassName == value1.ClassName &&
2148 value1.Part == value2.Part &&
2149 value1.State == value2.State;
2152 #region Measurement device context
2153 static Control control;
2154 static IDeviceContext GetMeasurementDeviceContext ()
2156 if (control == null)
2157 control = new Control ();
2158 return control.CreateGraphics ();
2160 static void ReleaseMeasurementDeviceContext (IDeviceContext dc)