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; }
74 public override void DrawButtonBase (Graphics dc, Rectangle clip_area, ButtonBase button)
76 if (button.FlatStyle == FlatStyle.System) {
77 ButtonRenderer.DrawButton (
79 new Rectangle (Point.Empty, button.Size),
82 button.TextFormatFlags,
85 ShouldPaintFocusRectagle (button),
86 GetPushButtonState (button)
90 base.DrawButtonBase (dc, clip_area, button);
92 static PushButtonState GetPushButtonState (ButtonBase button)
95 return PushButtonState.Disabled;
97 return PushButtonState.Pressed;
99 return PushButtonState.Hot;
100 if (button.IsDefault || button.Focused || button.paint_as_acceptbutton)
101 return PushButtonState.Default;
102 return PushButtonState.Normal;
107 public override void DrawButtonBackground (Graphics g, Button button, Rectangle clipArea)
109 if (!RenderClientAreas ||
110 !button.UseVisualStyleBackColor) {
111 base.DrawButtonBackground (g, button, clipArea);
114 ButtonRenderer.GetPushButtonRenderer (GetPushButtonState (button)).DrawBackground (g, new Rectangle (Point.Empty, button.Size));
119 protected override void CheckBox_DrawCheckBox (Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle)
121 if (checkbox.Appearance == Appearance.Normal && checkbox.FlatStyle == FlatStyle.System) {
122 CheckBoxRenderer.DrawCheckBox (
124 new Point (checkbox_rectangle.Left, checkbox_rectangle.Top),
125 GetCheckBoxState (checkbox)
129 base.CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
131 static CheckBoxState GetCheckBoxState (CheckBox checkBox)
133 switch (checkBox.CheckState) {
134 case CheckState.Checked:
135 if (!checkBox.Enabled)
136 return CheckBoxState.CheckedDisabled;
137 else if (checkBox.Pressed)
138 return CheckBoxState.CheckedPressed;
139 else if (checkBox.Entered)
140 return CheckBoxState.CheckedHot;
141 return CheckBoxState.CheckedNormal;
142 case CheckState.Indeterminate:
143 if (!checkBox.Enabled)
144 return CheckBoxState.MixedDisabled;
145 else if (checkBox.Pressed)
146 return CheckBoxState.MixedPressed;
147 else if (checkBox.Entered)
148 return CheckBoxState.MixedHot;
149 return CheckBoxState.MixedNormal;
151 if (!checkBox.Enabled)
152 return CheckBoxState.UncheckedDisabled;
153 else if (checkBox.Pressed)
154 return CheckBoxState.UncheckedPressed;
155 else if (checkBox.Entered)
156 return CheckBoxState.UncheckedHot;
157 return CheckBoxState.UncheckedNormal;
162 static VisualStyleElement ComboBoxGetVisualStyleElement (ComboBox comboBox, ButtonState state)
164 if (state == ButtonState.Inactive)
165 return VisualStyleElement.ComboBox.DropDownButton.Disabled;
166 if (state == ButtonState.Pushed)
167 return VisualStyleElement.ComboBox.DropDownButton.Pressed;
168 if (comboBox.DropDownButtonEntered)
169 return VisualStyleElement.ComboBox.DropDownButton.Hot;
170 return VisualStyleElement.ComboBox.DropDownButton.Normal;
172 public override void ComboBoxDrawNormalDropDownButton (ComboBox comboBox, Graphics g, Rectangle clippingArea, Rectangle area, ButtonState state)
174 if (!RenderClientAreas) {
175 base.ComboBoxDrawNormalDropDownButton (comboBox, g, clippingArea, area, state);
178 VisualStyleElement element = ComboBoxGetVisualStyleElement (comboBox, state);
179 if (!VisualStyleRenderer.IsElementDefined (element)) {
180 base.ComboBoxDrawNormalDropDownButton (comboBox, g, clippingArea, area, state);
183 new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
185 public override bool ComboBoxNormalDropDownButtonHasTransparentBackground (ComboBox comboBox, ButtonState state)
187 if (!RenderClientAreas)
188 return base.ComboBoxNormalDropDownButtonHasTransparentBackground (comboBox, state);
189 VisualStyleElement element = ComboBoxGetVisualStyleElement (comboBox, state);
190 if (!VisualStyleRenderer.IsElementDefined (element))
191 return base.ComboBoxNormalDropDownButtonHasTransparentBackground (comboBox, state);
192 return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
194 public override bool ComboBoxDropDownButtonHasHotElementStyle (ComboBox comboBox)
196 if (!RenderClientAreas)
197 return base.ComboBoxDropDownButtonHasHotElementStyle (comboBox);
199 switch (comboBox.FlatStyle) {
201 case FlatStyle.Popup:
202 return base.ComboBoxDropDownButtonHasHotElementStyle (comboBox);
207 static bool ComboBoxShouldPaintBackground (ComboBox comboBox)
209 if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
212 switch (comboBox.FlatStyle) {
214 case FlatStyle.Popup:
220 public override void ComboBoxDrawBackground (ComboBox comboBox, Graphics g, Rectangle clippingArea, FlatStyle style)
222 if (!RenderClientAreas || !ComboBoxShouldPaintBackground (comboBox)) {
223 base.ComboBoxDrawBackground (comboBox, g, clippingArea, style);
226 VisualStyleElement element;
227 if (!comboBox.Enabled)
228 element = VisualStyleElement.ComboBox.Border.Disabled;
229 else if (comboBox.Entered)
230 element = VisualStyleElement.ComboBox.Border.Hot;
231 else if (comboBox.Focused)
232 element = VisualStyleElement.ComboBox.Border.Focused;
234 element = VisualStyleElement.ComboBox.Border.Normal;
235 if (!VisualStyleRenderer.IsElementDefined (element)) {
236 base.ComboBoxDrawBackground (comboBox, g, clippingArea, style);
239 new VisualStyleRenderer (element).DrawBackground (g, new Rectangle (Point.Empty, comboBox.Size), clippingArea);
241 public override bool CombBoxBackgroundHasHotElementStyle (ComboBox comboBox)
243 if (RenderClientAreas &&
244 ComboBoxShouldPaintBackground (comboBox) &&
246 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ComboBox.Border.Hot))
248 return base.CombBoxBackgroundHasHotElementStyle (comboBox);
253 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
255 if (!RenderClientAreas ||
256 (state & ButtonState.Flat) == ButtonState.Flat ||
257 (state & ButtonState.Checked) == ButtonState.Checked) {
258 base.CPDrawButton (dc, rectangle, state);
261 VisualStyleElement element;
262 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
263 element = VisualStyleElement.Button.PushButton.Disabled;
264 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
265 element = VisualStyleElement.Button.PushButton.Pressed;
267 element = VisualStyleElement.Button.PushButton.Normal;
268 if (!VisualStyleRenderer.IsElementDefined (element)) {
269 base.CPDrawButton (dc, rectangle, state);
272 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
275 #region DrawCaptionButton
276 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state)
278 if (!RenderClientAreas ||
279 (state & ButtonState.Flat) == ButtonState.Flat ||
280 (state & ButtonState.Checked) == ButtonState.Checked) {
281 base.CPDrawCaptionButton (graphics, rectangle, button, state);
284 VisualStyleElement element = GetCaptionButtonVisualStyleElement (button, state);
285 if (!VisualStyleRenderer.IsElementDefined (element)) {
286 base.CPDrawCaptionButton (graphics, rectangle, button, state);
289 new VisualStyleRenderer (element).DrawBackground (graphics, rectangle);
291 static VisualStyleElement GetCaptionButtonVisualStyleElement (CaptionButton button, ButtonState state)
294 case CaptionButton.Minimize:
295 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
296 return VisualStyleElement.Window.MinButton.Disabled;
297 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
298 return VisualStyleElement.Window.MinButton.Pressed;
300 return VisualStyleElement.Window.MinButton.Normal;
301 case CaptionButton.Maximize:
302 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
303 return VisualStyleElement.Window.MaxButton.Disabled;
304 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
305 return VisualStyleElement.Window.MaxButton.Pressed;
307 return VisualStyleElement.Window.MaxButton.Normal;
308 case CaptionButton.Close:
309 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
310 return VisualStyleElement.Window.CloseButton.Disabled;
311 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
312 return VisualStyleElement.Window.CloseButton.Pressed;
314 return VisualStyleElement.Window.CloseButton.Normal;
315 case CaptionButton.Restore:
316 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
317 return VisualStyleElement.Window.RestoreButton.Disabled;
318 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
319 return VisualStyleElement.Window.RestoreButton.Pressed;
321 return VisualStyleElement.Window.RestoreButton.Normal;
323 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
324 return VisualStyleElement.Window.HelpButton.Disabled;
325 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
326 return VisualStyleElement.Window.HelpButton.Pressed;
328 return VisualStyleElement.Window.HelpButton.Normal;
333 public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
335 if (!RenderClientAreas ||
336 (state & ButtonState.Flat) == ButtonState.Flat) {
337 base.CPDrawCheckBox (dc, rectangle, state);
340 VisualStyleElement element;
341 if ((state & ButtonState.Checked) == ButtonState.Checked)
342 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
343 element = VisualStyleElement.Button.CheckBox.CheckedDisabled;
344 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
345 element = VisualStyleElement.Button.CheckBox.CheckedPressed;
347 element = VisualStyleElement.Button.CheckBox.CheckedNormal;
349 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
350 element = VisualStyleElement.Button.CheckBox.UncheckedDisabled;
351 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
352 element = VisualStyleElement.Button.CheckBox.UncheckedPressed;
354 element = VisualStyleElement.Button.CheckBox.UncheckedNormal;
355 if (!VisualStyleRenderer.IsElementDefined (element)) {
356 base.CPDrawCheckBox (dc, rectangle, state);
359 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
362 #region DrawComboButton
363 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
365 if (!RenderClientAreas ||
366 (state & ButtonState.Flat) == ButtonState.Flat ||
367 (state & ButtonState.Checked) == ButtonState.Checked) {
368 base.CPDrawComboButton (graphics, rectangle, state);
371 VisualStyleElement element;
372 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
373 element = VisualStyleElement.ComboBox.DropDownButton.Disabled;
374 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
375 element = VisualStyleElement.ComboBox.DropDownButton.Pressed;
377 element = VisualStyleElement.ComboBox.DropDownButton.Normal;
378 if (!VisualStyleRenderer.IsElementDefined (element)) {
379 base.CPDrawComboButton (graphics, rectangle, state);
382 new VisualStyleRenderer (element).DrawBackground (graphics, rectangle);
385 #region DrawMixedCheckBox
386 public override void CPDrawMixedCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
388 if (!RenderClientAreas ||
389 (state & ButtonState.Flat) == ButtonState.Flat) {
390 base.CPDrawMixedCheckBox (dc, rectangle, state);
393 VisualStyleElement element;
394 if ((state & ButtonState.Checked) == ButtonState.Checked)
395 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
396 element = VisualStyleElement.Button.CheckBox.MixedDisabled;
397 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
398 element = VisualStyleElement.Button.CheckBox.MixedPressed;
400 element = VisualStyleElement.Button.CheckBox.MixedNormal;
402 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
403 element = VisualStyleElement.Button.CheckBox.UncheckedDisabled;
404 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
405 element = VisualStyleElement.Button.CheckBox.UncheckedPressed;
407 element = VisualStyleElement.Button.CheckBox.UncheckedNormal;
408 if (!VisualStyleRenderer.IsElementDefined (element)) {
409 base.CPDrawMixedCheckBox (dc, rectangle, state);
412 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
415 #region DrawRadioButton
416 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
418 if (!RenderClientAreas ||
419 (state & ButtonState.Flat) == ButtonState.Flat) {
420 base.CPDrawRadioButton (dc, rectangle, state);
423 VisualStyleElement element;
424 if ((state & ButtonState.Checked) == ButtonState.Checked)
425 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
426 element = VisualStyleElement.Button.RadioButton.CheckedDisabled;
427 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
428 element = VisualStyleElement.Button.RadioButton.CheckedPressed;
430 element = VisualStyleElement.Button.RadioButton.CheckedNormal;
432 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
433 element = VisualStyleElement.Button.RadioButton.UncheckedDisabled;
434 else if ((state & ButtonState.Pushed) == ButtonState.Pushed)
435 element = VisualStyleElement.Button.RadioButton.UncheckedPressed;
437 element = VisualStyleElement.Button.RadioButton.UncheckedNormal;
438 if (!VisualStyleRenderer.IsElementDefined (element)) {
439 base.CPDrawRadioButton (dc, rectangle, state);
442 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
445 #region DrawScrollButton
446 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
448 if (!RenderClientAreas ||
449 (state & ButtonState.Flat) == ButtonState.Flat ||
450 (state & ButtonState.Checked) == ButtonState.Checked) {
451 base.CPDrawScrollButton (dc, area, type, state);
454 VisualStyleElement element = GetScrollButtonVisualStyleElement (type, state);
455 if (!VisualStyleRenderer.IsElementDefined (element)) {
456 base.CPDrawScrollButton (dc, area, type, state);
459 new VisualStyleRenderer (element).DrawBackground (dc, area);
461 static VisualStyleElement GetScrollButtonVisualStyleElement (ScrollButton type, ButtonState state)
464 case ScrollButton.Left:
465 if (IsDisabled (state))
466 return VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled;
467 else if (IsPressed (state))
468 return VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
470 return VisualStyleElement.ScrollBar.ArrowButton.LeftNormal;
471 case ScrollButton.Right:
472 if (IsDisabled (state))
473 return VisualStyleElement.ScrollBar.ArrowButton.RightDisabled;
474 else if (IsPressed (state))
475 return VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
477 return VisualStyleElement.ScrollBar.ArrowButton.RightNormal;
478 case ScrollButton.Up:
479 if (IsDisabled (state))
480 return VisualStyleElement.ScrollBar.ArrowButton.UpDisabled;
481 else if (IsPressed (state))
482 return VisualStyleElement.ScrollBar.ArrowButton.UpPressed;
484 return VisualStyleElement.ScrollBar.ArrowButton.UpNormal;
486 if (IsDisabled (state))
487 return VisualStyleElement.ScrollBar.ArrowButton.DownDisabled;
488 else if (IsPressed (state))
489 return VisualStyleElement.ScrollBar.ArrowButton.DownPressed;
491 return VisualStyleElement.ScrollBar.ArrowButton.DownNormal;
494 static bool IsDisabled (ButtonState state)
496 return (state & ButtonState.Inactive) == ButtonState.Inactive;
498 static bool IsPressed (ButtonState state)
500 return (state & ButtonState.Pushed) == ButtonState.Pushed;
506 #region DataGridViewHeaderCell
507 #region DataGridViewRowHeaderCell
508 public override bool DataGridViewRowHeaderCellDrawBackground (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
510 if (!RenderClientAreas ||
511 !cell.DataGridView.EnableHeadersVisualStyles)
512 return base.DataGridViewRowHeaderCellDrawBackground (cell, g, bounds);
513 VisualStyleElement element = DataGridViewRowHeaderCellGetVisualStyleElement (cell);
514 if (!VisualStyleRenderer.IsElementDefined (element))
515 return base.DataGridViewRowHeaderCellDrawBackground (cell, g, bounds);
517 Bitmap bitmap = new Bitmap (bounds.Height, bounds.Width);
518 Graphics bitmap_g = Graphics.FromImage (bitmap);
519 Rectangle bitmap_rectangle = new Rectangle (Point.Empty, bitmap.Size);
520 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
521 if (!AreEqual (element, VisualStyleElement.Header.Item.Normal) && renderer.IsBackgroundPartiallyTransparent ())
522 new VisualStyleRenderer (VisualStyleElement.Header.Item.Normal).DrawBackground (bitmap_g, bitmap_rectangle);
523 renderer.DrawBackground (bitmap_g, bitmap_rectangle);
525 g.Transform = new Matrix(0, 1, 1, 0, 0, 0);
526 g.DrawImage (bitmap, bounds.Y, bounds.X);
531 public override bool DataGridViewRowHeaderCellDrawSelectionBackground (DataGridViewRowHeaderCell cell)
533 if (!RenderClientAreas ||
534 !cell.DataGridView.EnableHeadersVisualStyles || !VisualStyleRenderer.IsElementDefined (DataGridViewRowHeaderCellGetVisualStyleElement (cell)))
535 return base.DataGridViewRowHeaderCellDrawSelectionBackground (cell);
538 public override bool DataGridViewRowHeaderCellDrawBorder (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
540 if (!RenderClientAreas ||
541 !cell.DataGridView.EnableHeadersVisualStyles || !VisualStyleRenderer.IsElementDefined (DataGridViewRowHeaderCellGetVisualStyleElement (cell)))
542 return base.DataGridViewRowHeaderCellDrawBorder (cell, g, bounds);
543 g.DrawLine (cell.GetBorderPen (), bounds.Right - 1, bounds.Top, bounds.Right - 1, bounds.Bottom - 1);
546 static VisualStyleElement DataGridViewRowHeaderCellGetVisualStyleElement (DataGridViewRowHeaderCell cell)
548 if (cell.DataGridView.PressedHeaderCell == cell)
549 return VisualStyleElement.Header.Item.Pressed;
550 if (cell.DataGridView.EnteredHeaderCell == cell)
551 return VisualStyleElement.Header.Item.Hot;
552 if (cell.OwningRow.SelectedInternal)
553 return VisualStyleElement.Header.Item.Pressed;
554 return VisualStyleElement.Header.Item.Normal;
557 #region DataGridViewColumnHeaderCell
558 public override bool DataGridViewColumnHeaderCellDrawBackground (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
560 if (!RenderClientAreas ||
561 !cell.DataGridView.EnableHeadersVisualStyles || cell is DataGridViewTopLeftHeaderCell)
562 return base.DataGridViewColumnHeaderCellDrawBackground (cell, g, bounds);
563 VisualStyleElement element = DataGridViewColumnHeaderCellGetVisualStyleElement (cell);
564 if (!VisualStyleRenderer.IsElementDefined (element))
565 return base.DataGridViewColumnHeaderCellDrawBackground (cell, g, bounds);
567 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
568 if (!AreEqual (element, VisualStyleElement.Header.Item.Normal) && renderer.IsBackgroundPartiallyTransparent ())
569 new VisualStyleRenderer (VisualStyleElement.Header.Item.Normal).DrawBackground (g, bounds);
570 renderer.DrawBackground (g, bounds);
573 public override bool DataGridViewColumnHeaderCellDrawBorder (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
575 if (!RenderClientAreas ||
576 !cell.DataGridView.EnableHeadersVisualStyles ||
577 cell is DataGridViewTopLeftHeaderCell ||
578 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Normal))
579 return base.DataGridViewColumnHeaderCellDrawBorder (cell, g, bounds);
580 g.DrawLine (cell.GetBorderPen (), bounds.Left, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
583 static VisualStyleElement DataGridViewColumnHeaderCellGetVisualStyleElement (DataGridViewColumnHeaderCell cell)
585 if (cell.DataGridView.PressedHeaderCell == cell)
586 return VisualStyleElement.Header.Item.Pressed;
587 if (cell.DataGridView.EnteredHeaderCell == cell)
588 return VisualStyleElement.Header.Item.Hot;
589 return VisualStyleElement.Header.Item.Normal;
592 public override bool DataGridViewHeaderCellHasPressedStyle (DataGridView dataGridView)
594 if (!RenderClientAreas ||
595 !dataGridView.EnableHeadersVisualStyles ||
596 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Pressed))
597 return base.DataGridViewHeaderCellHasPressedStyle (dataGridView);
600 public override bool DataGridViewHeaderCellHasHotStyle (DataGridView dataGridView)
602 if (!RenderClientAreas ||
603 !dataGridView.EnableHeadersVisualStyles ||
604 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Hot))
605 return base.DataGridViewHeaderCellHasHotStyle (dataGridView);
611 #region DateTimePicker
613 protected override void DateTimePickerDrawBorder (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
615 if (!RenderClientAreas) {
616 base.DateTimePickerDrawBorder (dateTimePicker, g, clippingArea);
619 VisualStyleElement element;
620 if (!dateTimePicker.Enabled)
621 element = VisualStyleElement.DatePicker.DateBorder.Disabled;
622 else if (dateTimePicker.Entered)
623 element = VisualStyleElement.DatePicker.DateBorder.Hot;
624 else if (dateTimePicker.Focused)
625 element = VisualStyleElement.DatePicker.DateBorder.Focused;
627 element = VisualStyleElement.DatePicker.DateBorder.Normal;
628 if (!VisualStyleRenderer.IsElementDefined (element)) {
629 base.DateTimePickerDrawBorder (dateTimePicker, g, clippingArea);
632 new VisualStyleRenderer (element).DrawBackground (g, new Rectangle (Point.Empty, dateTimePicker.Size), clippingArea);
634 public override bool DateTimePickerBorderHasHotElementStyle {
636 if (RenderClientAreas &&
637 VisualStyleRenderer.IsElementDefined (VisualStyleElement.DatePicker.DateBorder.Hot))
639 return base.DateTimePickerBorderHasHotElementStyle;
643 #region Drop down button
644 protected override void DateTimePickerDrawDropDownButton (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
646 if (!RenderClientAreas) {
647 base.DateTimePickerDrawDropDownButton (dateTimePicker, g, clippingArea);
650 VisualStyleElement element;
651 if (!dateTimePicker.Enabled)
652 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Disabled;
653 else if (dateTimePicker.is_drop_down_visible)
654 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Pressed;
655 else if (dateTimePicker.DropDownButtonEntered)
656 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Hot;
658 element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Normal;
659 if (!VisualStyleRenderer.IsElementDefined (element)) {
660 base.DateTimePickerDrawDropDownButton (dateTimePicker, g, clippingArea);
663 new VisualStyleRenderer (element).DrawBackground (g, dateTimePicker.drop_down_arrow_rect, clippingArea);
665 //TODO: Until somebody figures out how to obtain the proper width this will need to be updated when new Windows versions/themes are released.
666 const int DateTimePickerDropDownWidthOnWindowsVista = 34;
667 const int DateTimePickerDropDownHeightOnWindowsVista = 20;
668 public override Rectangle DateTimePickerGetDropDownButtonArea (DateTimePicker dateTimePicker)
670 if (!RenderClientAreas)
671 return base.DateTimePickerGetDropDownButtonArea (dateTimePicker);
672 VisualStyleElement element = VisualStyleElement.DatePicker.ShowCalendarButtonRight.Pressed;
673 if (!VisualStyleRenderer.IsElementDefined (element))
674 return base.DateTimePickerGetDropDownButtonArea (dateTimePicker);
675 Size size = new Size (DateTimePickerDropDownWidthOnWindowsVista, DateTimePickerDropDownHeightOnWindowsVista);
676 return new Rectangle (dateTimePicker.Width - size.Width, 0, size.Width, size.Height);
678 public override Rectangle DateTimePickerGetDateArea (DateTimePicker dateTimePicker)
680 if (!RenderClientAreas ||
681 dateTimePicker.ShowUpDown)
682 return base.DateTimePickerGetDateArea (dateTimePicker);
683 VisualStyleElement element = VisualStyleElement.DatePicker.DateBorder.Normal;
684 if (!VisualStyleRenderer.IsElementDefined (element))
685 return base.DateTimePickerGetDateArea (dateTimePicker);
686 Graphics g = dateTimePicker.CreateGraphics ();
687 Rectangle result = new VisualStyleRenderer (element).GetBackgroundContentRectangle (g, dateTimePicker.ClientRectangle);
689 result.Width -= DateTimePickerDropDownWidthOnWindowsVista;
692 public override bool DateTimePickerDropDownButtonHasHotElementStyle {
694 if (RenderClientAreas &&
695 VisualStyleRenderer.IsElementDefined (VisualStyleElement.DatePicker.ShowCalendarButtonRight.Hot))
697 return base.DateTimePickerDropDownButtonHasHotElementStyle;
703 protected override void ListViewDrawColumnHeaderBackground (ListView listView, ColumnHeader columnHeader, Graphics g, Rectangle area, Rectangle clippingArea)
705 if (!RenderClientAreas) {
706 base.ListViewDrawColumnHeaderBackground (listView, columnHeader, g, area, clippingArea);
709 VisualStyleElement element;
710 if (listView.HeaderStyle == ColumnHeaderStyle.Clickable)
711 if (columnHeader.Pressed)
712 element = VisualStyleElement.Header.Item.Pressed;
713 else if (columnHeader == listView.EnteredColumnHeader)
714 element = VisualStyleElement.Header.Item.Hot;
716 element = VisualStyleElement.Header.Item.Normal;
718 element = VisualStyleElement.Header.Item.Normal;
719 if (!VisualStyleRenderer.IsElementDefined (element)) {
720 base.ListViewDrawColumnHeaderBackground (listView, columnHeader, g, area, clippingArea);
723 new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
725 protected override void ListViewDrawUnusedHeaderBackground (ListView listView, Graphics g, Rectangle area, Rectangle clippingArea)
727 if (!RenderClientAreas) {
728 base.ListViewDrawUnusedHeaderBackground (listView, g, area, clippingArea);
731 VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
732 if (!VisualStyleRenderer.IsElementDefined (element)) {
733 base.ListViewDrawUnusedHeaderBackground (listView, g, area, clippingArea);
736 new VisualStyleRenderer (element).DrawBackground (g, area, clippingArea);
738 public override bool ListViewHasHotHeaderStyle {
740 if (!RenderClientAreas ||
741 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.Header.Item.Hot))
742 return base.ListViewHasHotHeaderStyle;
746 public override int ListViewGetHeaderHeight (ListView listView, Font font)
748 if (!RenderClientAreas)
749 return base.ListViewGetHeaderHeight (listView, font);
750 VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
751 if (!VisualStyleRenderer.IsElementDefined (element))
752 return base.ListViewGetHeaderHeight (listView, font);
753 Control control = null;
755 if (listView == null) {
756 control = new Control ();
757 g = control.CreateGraphics ();
759 g = listView.CreateGraphics ();
760 int result = new VisualStyleRenderer (element).GetPartSize (g, ThemeSizeType.True).Height;
762 if (listView == null)
768 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box)
770 GroupBoxRenderer.DrawGroupBox (
772 new Rectangle (Point.Empty, box.Size),
775 box.ForeColor == GroupBox.DefaultForeColor ? Color.Empty : box.ForeColor,
776 box.Enabled ? GroupBoxState.Normal : GroupBoxState.Disabled);
779 #region Managed window
780 Rectangle ManagedWindowGetTitleBarRectangle (InternalWindowManager wm)
782 return new Rectangle (0, 0, wm.Form.Width, ManagedWindowTitleBarHeight (wm) + ManagedWindowBorderWidth (wm) + (wm.IsMinimized ? 1 : 0));
784 Region ManagedWindowGetWindowRegion (Form form)
786 if (form.WindowManager is MdiWindowManager && form.WindowManager.IsMaximized)
788 VisualStyleElement title_bar_element = ManagedWindowGetTitleBarVisualStyleElement (form.WindowManager);
789 if (!VisualStyleRenderer.IsElementDefined (title_bar_element))
791 VisualStyleRenderer renderer = new VisualStyleRenderer (title_bar_element);
792 if (!renderer.IsBackgroundPartiallyTransparent ())
794 IDeviceContext dc = GetMeasurementDeviceContext ();
795 Rectangle title_bar_rectangle = ManagedWindowGetTitleBarRectangle (form.WindowManager);
796 Region region = renderer.GetBackgroundRegion (dc, title_bar_rectangle);
797 ReleaseMeasurementDeviceContext (dc);
798 region.Union (new Rectangle (0, title_bar_rectangle.Bottom, form.Width, form.Height));
801 public override void ManagedWindowOnSizeInitializedOrChanged (Form form)
803 base.ManagedWindowOnSizeInitializedOrChanged (form);
804 if (!render_non_client_areas)
806 form.Region = ManagedWindowGetWindowRegion (form);
808 protected override Rectangle ManagedWindowDrawTitleBarAndBorders (Graphics dc, Rectangle clip, InternalWindowManager wm)
810 if (!render_non_client_areas)
811 return base.ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
812 VisualStyleElement title_bar_element = ManagedWindowGetTitleBarVisualStyleElement (wm);
813 VisualStyleElement left_border_element;
814 VisualStyleElement right_border_element;
815 VisualStyleElement bottom_border_element;
816 ManagedWindowGetBorderVisualStyleElements (wm, out left_border_element, out right_border_element, out bottom_border_element);
817 if (!VisualStyleRenderer.IsElementDefined (title_bar_element) ||
818 (!wm.IsMinimized && (
819 !VisualStyleRenderer.IsElementDefined (left_border_element) ||
820 !VisualStyleRenderer.IsElementDefined (right_border_element) ||
821 !VisualStyleRenderer.IsElementDefined (bottom_border_element))))
822 return base.ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
823 VisualStyleRenderer renderer = new VisualStyleRenderer (title_bar_element);
824 Rectangle title_bar_rectangle = ManagedWindowGetTitleBarRectangle (wm);
825 renderer.DrawBackground (dc, title_bar_rectangle, clip);
826 if (!wm.IsMinimized) {
827 int border_width = ManagedWindowBorderWidth (wm);
828 renderer.SetParameters (left_border_element);
829 renderer.DrawBackground (dc, new Rectangle (
831 title_bar_rectangle.Bottom,
833 wm.Form.Height - title_bar_rectangle.Bottom
835 renderer.SetParameters (right_border_element);
836 renderer.DrawBackground (dc, new Rectangle (
837 wm.Form.Width - border_width,
838 title_bar_rectangle.Bottom,
840 wm.Form.Height - title_bar_rectangle.Bottom
842 renderer.SetParameters (bottom_border_element);
843 renderer.DrawBackground (dc, new Rectangle (
845 wm.Form.Height - border_width,
850 return title_bar_rectangle;
852 static FormWindowState ManagedWindowGetWindowState (InternalWindowManager wm)
854 return wm.GetWindowState ();
856 static bool ManagedWindowIsDisabled (InternalWindowManager wm)
858 return !wm.Form.Enabled;
860 static bool ManagedWindowIsActive (InternalWindowManager wm)
864 static VisualStyleElement ManagedWindowGetTitleBarVisualStyleElement (InternalWindowManager wm)
868 switch (ManagedWindowGetWindowState (wm)) {
869 case FormWindowState.Minimized:
870 if (ManagedWindowIsDisabled (wm))
871 return VisualStyleElement.Window.SmallMinCaption.Disabled;
872 else if (ManagedWindowIsActive (wm))
873 return VisualStyleElement.Window.SmallMinCaption.Active;
874 return VisualStyleElement.Window.SmallMinCaption.Inactive;
875 case FormWindowState.Maximized:
876 if (ManagedWindowIsDisabled (wm))
877 return VisualStyleElement.Window.SmallMaxCaption.Disabled;
878 else if (ManagedWindowIsActive (wm))
879 return VisualStyleElement.Window.SmallMaxCaption.Active;
880 return VisualStyleElement.Window.SmallMaxCaption.Inactive;
882 if (ManagedWindowIsDisabled (wm))
883 return VisualStyleElement.Window.SmallCaption.Disabled;
884 else if (ManagedWindowIsActive (wm))
885 return VisualStyleElement.Window.SmallCaption.Active;
886 return VisualStyleElement.Window.SmallCaption.Inactive;
890 #region Normal window
891 switch (ManagedWindowGetWindowState (wm)) {
892 case FormWindowState.Minimized:
893 if (ManagedWindowIsDisabled (wm))
894 return VisualStyleElement.Window.MinCaption.Disabled;
895 else if (ManagedWindowIsActive (wm))
896 return VisualStyleElement.Window.MinCaption.Active;
897 return VisualStyleElement.Window.MinCaption.Inactive;
898 case FormWindowState.Maximized:
899 if (ManagedWindowIsDisabled (wm))
900 return VisualStyleElement.Window.MaxCaption.Disabled;
901 else if (ManagedWindowIsActive (wm))
902 return VisualStyleElement.Window.MaxCaption.Active;
903 return VisualStyleElement.Window.MaxCaption.Inactive;
905 if (ManagedWindowIsDisabled (wm))
906 return VisualStyleElement.Window.Caption.Disabled;
907 else if (ManagedWindowIsActive (wm))
908 return VisualStyleElement.Window.Caption.Active;
909 return VisualStyleElement.Window.Caption.Inactive;
913 static void ManagedWindowGetBorderVisualStyleElements (InternalWindowManager wm, out VisualStyleElement left, out VisualStyleElement right, out VisualStyleElement bottom)
915 bool active = !ManagedWindowIsDisabled (wm) && ManagedWindowIsActive (wm);
916 if (wm.IsToolWindow) {
918 left = VisualStyleElement.Window.SmallFrameLeft.Active;
919 right = VisualStyleElement.Window.SmallFrameRight.Active;
920 bottom = VisualStyleElement.Window.SmallFrameBottom.Active;
922 left = VisualStyleElement.Window.SmallFrameLeft.Inactive;
923 right = VisualStyleElement.Window.SmallFrameRight.Inactive;
924 bottom = VisualStyleElement.Window.SmallFrameBottom.Inactive;
928 left = VisualStyleElement.Window.FrameLeft.Active;
929 right = VisualStyleElement.Window.FrameRight.Active;
930 bottom = VisualStyleElement.Window.FrameBottom.Active;
932 left = VisualStyleElement.Window.FrameLeft.Inactive;
933 right = VisualStyleElement.Window.FrameRight.Inactive;
934 bottom = VisualStyleElement.Window.FrameBottom.Inactive;
938 public override bool ManagedWindowTitleButtonHasHotElementStyle (TitleButton button, Form form)
940 if (render_non_client_areas && (button.State & ButtonState.Inactive) != ButtonState.Inactive) {
941 VisualStyleElement element;
942 if (ManagedWindowIsMaximizedMdiChild (form))
943 switch (button.Caption) {
944 case CaptionButton.Close:
945 element = VisualStyleElement.Window.MdiCloseButton.Hot;
947 case CaptionButton.Help:
948 element = VisualStyleElement.Window.MdiHelpButton.Hot;
950 case CaptionButton.Minimize:
951 element = VisualStyleElement.Window.MdiMinButton.Hot;
954 element = VisualStyleElement.Window.MdiRestoreButton.Hot;
957 else if (form.WindowManager.IsToolWindow)
958 element = VisualStyleElement.Window.SmallCloseButton.Hot;
960 switch (button.Caption) {
961 case CaptionButton.Close:
962 element = VisualStyleElement.Window.CloseButton.Hot;
964 case CaptionButton.Help:
965 element = VisualStyleElement.Window.HelpButton.Hot;
967 case CaptionButton.Maximize:
968 element = VisualStyleElement.Window.MaxButton.Hot;
970 case CaptionButton.Minimize:
971 element = VisualStyleElement.Window.MinButton.Hot;
974 element = VisualStyleElement.Window.RestoreButton.Hot;
977 if (VisualStyleRenderer.IsElementDefined (element))
980 return base.ManagedWindowTitleButtonHasHotElementStyle (button, form);
982 static bool ManagedWindowIsMaximizedMdiChild (Form form)
984 return form.WindowManager is MdiWindowManager &&
985 ManagedWindowGetWindowState (form.WindowManager) == FormWindowState.Maximized;
987 static bool ManagedWindowTitleButtonIsDisabled (TitleButton button, InternalWindowManager wm)
989 return (button.State & ButtonState.Inactive) == ButtonState.Inactive;
991 static bool ManagedWindowTitleButtonIsPressed (TitleButton button)
993 return (button.State & ButtonState.Pushed) == ButtonState.Pushed;
995 static VisualStyleElement ManagedWindowGetTitleButtonVisualStyleElement (TitleButton button, Form form)
997 if (form.WindowManager.IsToolWindow) {
998 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
999 return VisualStyleElement.Window.SmallCloseButton.Disabled;
1000 if (ManagedWindowTitleButtonIsPressed (button))
1001 return VisualStyleElement.Window.SmallCloseButton.Pressed;
1003 return VisualStyleElement.Window.SmallCloseButton.Hot;
1004 return VisualStyleElement.Window.SmallCloseButton.Normal;
1006 switch (button.Caption) {
1007 case CaptionButton.Close:
1008 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1009 return VisualStyleElement.Window.CloseButton.Disabled;
1010 if (ManagedWindowTitleButtonIsPressed (button))
1011 return VisualStyleElement.Window.CloseButton.Pressed;
1013 return VisualStyleElement.Window.CloseButton.Hot;
1014 return VisualStyleElement.Window.CloseButton.Normal;
1015 case CaptionButton.Help:
1016 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1017 return VisualStyleElement.Window.HelpButton.Disabled;
1018 if (ManagedWindowTitleButtonIsPressed (button))
1019 return VisualStyleElement.Window.HelpButton.Pressed;
1021 return VisualStyleElement.Window.HelpButton.Hot;
1022 return VisualStyleElement.Window.HelpButton.Normal;
1023 case CaptionButton.Maximize:
1024 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1025 return VisualStyleElement.Window.MaxButton.Disabled;
1026 if (ManagedWindowTitleButtonIsPressed (button))
1027 return VisualStyleElement.Window.MaxButton.Pressed;
1029 return VisualStyleElement.Window.MaxButton.Hot;
1030 return VisualStyleElement.Window.MaxButton.Normal;
1031 case CaptionButton.Minimize:
1032 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1033 return VisualStyleElement.Window.MinButton.Disabled;
1034 if (ManagedWindowTitleButtonIsPressed (button))
1035 return VisualStyleElement.Window.MinButton.Pressed;
1037 return VisualStyleElement.Window.MinButton.Hot;
1038 return VisualStyleElement.Window.MinButton.Normal;
1040 if (ManagedWindowTitleButtonIsDisabled (button, form.WindowManager))
1041 return VisualStyleElement.Window.RestoreButton.Disabled;
1042 if (ManagedWindowTitleButtonIsPressed (button))
1043 return VisualStyleElement.Window.RestoreButton.Pressed;
1045 return VisualStyleElement.Window.RestoreButton.Hot;
1046 return VisualStyleElement.Window.RestoreButton.Normal;
1049 protected override void ManagedWindowDrawTitleButton (Graphics dc, TitleButton button, Rectangle clip, Form form)
1051 if (!render_non_client_areas) {
1052 base.ManagedWindowDrawTitleButton (dc, button, clip, form);
1055 VisualStyleElement element = ManagedWindowGetTitleButtonVisualStyleElement (button, form);
1056 if (!VisualStyleRenderer.IsElementDefined (element)) {
1057 base.ManagedWindowDrawTitleButton (dc, button, clip, form);
1060 new VisualStyleRenderer (element).DrawBackground (dc, button.Rectangle, clip);
1062 public override Size ManagedWindowButtonSize (InternalWindowManager wm)
1064 if (!render_non_client_areas)
1065 return base.ManagedWindowButtonSize (wm);
1066 VisualStyleElement element = wm.IsToolWindow && !wm.IsMinimized ?
1067 VisualStyleElement.Window.SmallCloseButton.Normal :
1068 VisualStyleElement.Window.CloseButton.Normal;
1069 if (!VisualStyleRenderer.IsElementDefined (element))
1070 return base.ManagedWindowButtonSize (wm);
1071 IDeviceContext dc = GetMeasurementDeviceContext ();
1072 Size result = new VisualStyleRenderer (element).GetPartSize (dc, ThemeSizeType.True);
1073 ReleaseMeasurementDeviceContext (dc);
1076 public override void ManagedWindowDrawMenuButton (Graphics dc, TitleButton button, Rectangle clip, InternalWindowManager wm)
1078 if (!render_non_client_areas) {
1079 base.ManagedWindowDrawMenuButton (dc, button, clip, wm);
1082 VisualStyleElement element = ManagedWindowGetMenuButtonVisualStyleElement (button, wm);
1083 if (!VisualStyleRenderer.IsElementDefined (element)) {
1084 base.ManagedWindowDrawMenuButton (dc, button, clip, wm);
1087 new VisualStyleRenderer (element).DrawBackground (dc, button.Rectangle, clip);
1089 static VisualStyleElement ManagedWindowGetMenuButtonVisualStyleElement (TitleButton button, InternalWindowManager wm)
1091 switch (button.Caption) {
1092 case CaptionButton.Close:
1093 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1094 return VisualStyleElement.Window.MdiCloseButton.Disabled;
1095 if (ManagedWindowTitleButtonIsPressed (button))
1096 return VisualStyleElement.Window.MdiCloseButton.Pressed;
1098 return VisualStyleElement.Window.MdiCloseButton.Hot;
1099 return VisualStyleElement.Window.MdiCloseButton.Normal;
1100 case CaptionButton.Help:
1101 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1102 return VisualStyleElement.Window.MdiHelpButton.Disabled;
1103 if (ManagedWindowTitleButtonIsPressed (button))
1104 return VisualStyleElement.Window.MdiHelpButton.Pressed;
1106 return VisualStyleElement.Window.MdiHelpButton.Hot;
1107 return VisualStyleElement.Window.MdiHelpButton.Normal;
1108 case CaptionButton.Minimize:
1109 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1110 return VisualStyleElement.Window.MdiMinButton.Disabled;
1111 if (ManagedWindowTitleButtonIsPressed (button))
1112 return VisualStyleElement.Window.MdiMinButton.Pressed;
1114 return VisualStyleElement.Window.MdiMinButton.Hot;
1115 return VisualStyleElement.Window.MdiMinButton.Normal;
1117 if (ManagedWindowTitleButtonIsDisabled (button, wm))
1118 return VisualStyleElement.Window.MdiRestoreButton.Disabled;
1119 if (ManagedWindowTitleButtonIsPressed (button))
1120 return VisualStyleElement.Window.MdiRestoreButton.Pressed;
1122 return VisualStyleElement.Window.MdiRestoreButton.Hot;
1123 return VisualStyleElement.Window.MdiRestoreButton.Normal;
1126 public override Size ManagedWindowGetMenuButtonSize (InternalWindowManager wm)
1128 if (!render_non_client_areas)
1129 return base.ManagedWindowGetMenuButtonSize (wm);
1130 VisualStyleElement element = VisualStyleElement.Window.MdiCloseButton.Normal;
1131 if (!VisualStyleRenderer.IsElementDefined (element))
1132 return base.ManagedWindowGetMenuButtonSize (wm);
1133 IDeviceContext dc = GetMeasurementDeviceContext ();
1134 Size result = new VisualStyleRenderer (element).GetPartSize (dc, ThemeSizeType.True);
1135 ReleaseMeasurementDeviceContext (dc);
1140 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
1142 if (!RenderClientAreas ||
1143 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.ProgressBar.Bar.Normal) ||
1144 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.ProgressBar.Chunk.Normal)) {
1145 base.DrawProgressBar (dc, clip_rect, ctrl);
1148 VisualStyleRenderer renderer = new VisualStyleRenderer (VisualStyleElement.ProgressBar.Bar.Normal);
1149 renderer.DrawBackground (dc, ctrl.ClientRectangle, clip_rect);
1150 Rectangle client_area = renderer.GetBackgroundContentRectangle (dc, new Rectangle (Point.Empty, ctrl.Size));
1151 renderer = new VisualStyleRenderer (VisualStyleElement.ProgressBar.Chunk.Normal);
1154 int max_blocks = int.MaxValue;
1155 int start_pixel = client_area.X;
1157 draw_mode = (int)ctrl.Style;
1159 switch (draw_mode) {
1161 case 1: // Continuous
1162 client_area.Width = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(Math.Max (ctrl.Maximum - ctrl.Minimum, 1))));
1163 renderer.DrawBackground (dc, client_area, clip_rect);
1166 int ms_diff = (int)(DateTime.Now - ctrl.start).TotalMilliseconds;
1167 double percent_done = (double)ms_diff % (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
1169 start_pixel = client_area.X + (int)(client_area.Width * percent_done);
1173 int block_width = renderer.GetInteger (IntegerProperty.ProgressChunkSize);
1174 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;
1175 int block_count = 0;
1176 int increment = block_width + renderer.GetInteger (IntegerProperty.ProgressSpaceSize);
1177 Rectangle block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height);
1179 if (max_blocks != int.MaxValue) {
1180 if (block_count == max_blocks)
1182 if (block_rect.Right >= client_area.Width)
1183 block_rect.X -= client_area.Width;
1185 if (block_rect.X >= first_pixel_outside_filled_area)
1187 if (block_rect.Right >= first_pixel_outside_filled_area)
1188 if (first_pixel_outside_filled_area == client_area.Right)
1189 block_rect.Width = first_pixel_outside_filled_area - block_rect.X;
1193 if (clip_rect.IntersectsWith (block_rect))
1194 renderer.DrawBackground (dc, block_rect, clip_rect);
1195 block_rect.X += increment;
1203 protected override void RadioButton_DrawButton (RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle) {
1204 if (radio_button.Appearance == Appearance.Normal && radio_button.FlatStyle == FlatStyle.System) {
1205 RadioButtonRenderer.DrawRadioButton (
1207 new Point (radiobutton_rectangle.Left, radiobutton_rectangle.Top),
1208 GetRadioButtonState (radio_button)
1212 base.RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
1214 static RadioButtonState GetRadioButtonState (RadioButton checkBox)
1216 if (checkBox.Checked) {
1217 if (!checkBox.Enabled)
1218 return RadioButtonState.CheckedDisabled;
1219 else if (checkBox.Pressed)
1220 return RadioButtonState.CheckedPressed;
1221 else if (checkBox.Entered)
1222 return RadioButtonState.CheckedHot;
1223 return RadioButtonState.CheckedNormal;
1225 if (!checkBox.Enabled)
1226 return RadioButtonState.UncheckedDisabled;
1227 else if (checkBox.Pressed)
1228 return RadioButtonState.UncheckedPressed;
1229 else if (checkBox.Entered)
1230 return RadioButtonState.UncheckedHot;
1231 return RadioButtonState.UncheckedNormal;
1236 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
1238 if (!RenderClientAreas ||
1239 !ScrollBarAreElementsDefined) {
1240 base.DrawScrollBar (dc, clip, bar);
1243 VisualStyleElement element;
1244 VisualStyleRenderer renderer;
1245 int scroll_button_width = bar.scrollbutton_width;
1246 int scroll_button_height = bar.scrollbutton_height;
1248 bar.FirstArrowArea = new Rectangle (0, 0, bar.Width, scroll_button_height);
1249 bar.SecondArrowArea = new Rectangle (
1251 bar.ClientRectangle.Height - scroll_button_height,
1253 scroll_button_height);
1254 Rectangle thumb_pos = bar.ThumbPos;
1255 thumb_pos.Width = bar.Width;
1256 bar.ThumbPos = thumb_pos;
1257 #region Background, upper track
1258 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
1259 element = VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed;
1261 element = bar.Enabled ?
1262 VisualStyleElement.ScrollBar.LowerTrackVertical.Normal :
1263 VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1264 renderer = new VisualStyleRenderer (element);
1265 Rectangle upper_track_rect = new Rectangle (
1268 bar.ClientRectangle.Width,
1270 if (clip.IntersectsWith (upper_track_rect))
1271 renderer.DrawBackground (dc, upper_track_rect, clip);
1273 #region Background, lower track
1274 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
1275 element = VisualStyles.VisualStyleElement.ScrollBar.LowerTrackVertical.Pressed;
1277 element = bar.Enabled ?
1278 VisualStyleElement.ScrollBar.LowerTrackVertical.Normal :
1279 VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1280 renderer = new VisualStyleRenderer (element);
1281 Rectangle lower_track_rect = new Rectangle (
1283 bar.ThumbPos.Bottom,
1284 bar.ClientRectangle.Width,
1285 bar.ClientRectangle.Height - bar.ThumbPos.Bottom);
1286 if (clip.IntersectsWith (lower_track_rect))
1287 renderer.DrawBackground (dc, lower_track_rect, clip);
1290 if (clip.IntersectsWith (bar.FirstArrowArea)) {
1292 element = VisualStyleElement.ScrollBar.ArrowButton.UpDisabled;
1293 else if (bar.firstbutton_state == ButtonState.Pushed)
1294 element = VisualStyleElement.ScrollBar.ArrowButton.UpPressed;
1295 else if (bar.FirstButtonEntered)
1296 element = VisualStyleElement.ScrollBar.ArrowButton.UpHot;
1297 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1298 element = VisualStyleElement.ScrollBar.ArrowButton.UpHover;
1300 element = VisualStyleElement.ScrollBar.ArrowButton.UpNormal;
1301 renderer = new VisualStyleRenderer (element);
1302 renderer.DrawBackground (dc, bar.FirstArrowArea);
1304 if (clip.IntersectsWith (bar.SecondArrowArea)) {
1306 element = VisualStyleElement.ScrollBar.ArrowButton.DownDisabled;
1307 else if (bar.secondbutton_state == ButtonState.Pushed)
1308 element = VisualStyleElement.ScrollBar.ArrowButton.DownPressed;
1309 else if (bar.SecondButtonEntered)
1310 element = VisualStyleElement.ScrollBar.ArrowButton.DownHot;
1311 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1312 element = VisualStyleElement.ScrollBar.ArrowButton.DownHover;
1314 element = VisualStyleElement.ScrollBar.ArrowButton.DownNormal;
1315 renderer = new VisualStyleRenderer (element);
1316 renderer.DrawBackground (dc, bar.SecondArrowArea);
1319 #region Thumb and grip
1321 element = VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled;
1322 else if (bar.ThumbPressed)
1323 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed;
1324 else if (bar.ThumbEntered)
1325 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot;
1327 element = VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal;
1328 renderer = new VisualStyleRenderer (element);
1329 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1331 if (bar.Enabled && bar.ThumbPos.Height >= 20) {
1332 element = VisualStyleElement.ScrollBar.GripperVertical.Normal;
1333 renderer = new VisualStyleRenderer (element);
1334 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1338 bar.FirstArrowArea = new Rectangle (0, 0, scroll_button_width, bar.Height);
1339 bar.SecondArrowArea = new Rectangle (
1340 bar.ClientRectangle.Width - scroll_button_width,
1342 scroll_button_width,
1344 Rectangle thumb_pos = bar.ThumbPos;
1345 thumb_pos.Height = bar.Height;
1346 bar.ThumbPos = thumb_pos;
1347 #region Background, left track
1348 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
1349 element = VisualStyleElement.ScrollBar.LeftTrackHorizontal.Pressed;
1351 element = bar.Enabled ?
1352 VisualStyleElement.ScrollBar.LeftTrackHorizontal.Normal :
1353 VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled;
1354 renderer = new VisualStyleRenderer (element);
1355 Rectangle left_track_rect = new Rectangle (
1359 bar.ClientRectangle.Height);
1360 if (clip.IntersectsWith (left_track_rect))
1361 renderer.DrawBackground (dc, left_track_rect, clip);
1363 #region Background, right track
1364 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
1365 element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Pressed;
1367 element = bar.Enabled ?
1368 VisualStyleElement.ScrollBar.RightTrackHorizontal.Normal :
1369 VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
1370 renderer = new VisualStyleRenderer (element);
1371 Rectangle right_track_rect = new Rectangle (
1374 bar.ClientRectangle.Width - bar.ThumbPos.Right,
1375 bar.ClientRectangle.Height);
1376 if (clip.IntersectsWith (right_track_rect))
1377 renderer.DrawBackground (dc, right_track_rect, clip);
1380 if (clip.IntersectsWith (bar.FirstArrowArea)) {
1382 element = VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled;
1383 else if (bar.firstbutton_state == ButtonState.Pushed)
1384 element = VisualStyleElement.ScrollBar.ArrowButton.LeftPressed;
1385 else if (bar.FirstButtonEntered)
1386 element = VisualStyleElement.ScrollBar.ArrowButton.LeftHot;
1387 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1388 element = VisualStyleElement.ScrollBar.ArrowButton.LeftHover;
1390 element = VisualStyleElement.ScrollBar.ArrowButton.LeftNormal;
1391 renderer = new VisualStyleRenderer (element);
1392 renderer.DrawBackground (dc, bar.FirstArrowArea);
1394 if (clip.IntersectsWith (bar.SecondArrowArea)) {
1396 element = VisualStyleElement.ScrollBar.ArrowButton.RightDisabled;
1397 else if (bar.secondbutton_state == ButtonState.Pushed)
1398 element = VisualStyleElement.ScrollBar.ArrowButton.RightPressed;
1399 else if (bar.SecondButtonEntered)
1400 element = VisualStyleElement.ScrollBar.ArrowButton.RightHot;
1401 else if (ScrollBarHasHoverArrowButtonStyleVisualStyles && bar.Entered)
1402 element = VisualStyleElement.ScrollBar.ArrowButton.RightHover;
1404 element = VisualStyleElement.ScrollBar.ArrowButton.RightNormal;
1405 renderer = new VisualStyleRenderer (element);
1406 renderer.DrawBackground (dc, bar.SecondArrowArea);
1409 #region Thumb and grip
1411 element = VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled;
1412 else if (bar.ThumbPressed)
1413 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Pressed;
1414 else if (bar.ThumbEntered)
1415 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Hot;
1417 element = VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Normal;
1418 renderer = new VisualStyleRenderer (element);
1419 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1421 if (bar.Enabled && bar.ThumbPos.Height >= 20) {
1422 element = VisualStyleElement.ScrollBar.GripperHorizontal.Normal;
1423 renderer = new VisualStyleRenderer (element);
1424 renderer.DrawBackground (dc, bar.ThumbPos, clip);
1429 public override bool ScrollBarHasHotElementStyles {
1431 if (!RenderClientAreas)
1432 return base.ScrollBarHasHotElementStyles;
1433 return ScrollBarAreElementsDefined;
1436 public override bool ScrollBarHasPressedThumbStyle {
1438 if (!RenderClientAreas)
1439 return base.ScrollBarHasPressedThumbStyle;
1440 return ScrollBarAreElementsDefined;
1443 const int WindowsVistaMajorVersion = 6;
1444 static bool ScrollBarHasHoverArrowButtonStyleVisualStyles =
1445 Environment.OSVersion.Version.Major >= WindowsVistaMajorVersion;
1446 public override bool ScrollBarHasHoverArrowButtonStyle {
1448 if (RenderClientAreas &&
1449 ScrollBarHasHoverArrowButtonStyleVisualStyles)
1450 return ScrollBarAreElementsDefined;
1451 return base.ScrollBarHasHoverArrowButtonStyle;
1454 static bool ScrollBarAreElementsDefined {
1457 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ArrowButton.DownDisabled) &&
1458 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.GripperHorizontal.Normal) &&
1459 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.GripperVertical.Normal) &&
1460 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.LeftTrackHorizontal.Disabled) &&
1461 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.LowerTrackVertical.Disabled) &&
1462 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.RightTrackHorizontal.Disabled) &&
1463 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.SizeBox.LeftAlign) &&
1464 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Disabled) &&
1465 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.ThumbButtonVertical.Disabled) &&
1466 VisualStyleRenderer.IsElementDefined (VisualStyleElement.ScrollBar.UpperTrackVertical.Disabled);
1471 protected override void DrawStatusBarBackground(Graphics dc, Rectangle clip, StatusBar sb) {
1472 if (!RenderClientAreas) {
1473 base.DrawStatusBarBackground (dc, clip, sb);
1476 VisualStyleElement element = VisualStyleElement.Status.Bar.Normal;
1477 if (!VisualStyleRenderer.IsElementDefined (element)) {
1478 base.DrawStatusBarBackground (dc, clip, sb);
1481 new VisualStyleRenderer (element).DrawBackground (dc, sb.ClientRectangle, clip);
1483 protected override void DrawStatusBarSizingGrip (Graphics dc, Rectangle clip, StatusBar sb, Rectangle area)
1485 if (!RenderClientAreas) {
1486 base.DrawStatusBarSizingGrip (dc, clip, sb, area);
1489 VisualStyleElement element = VisualStyleElement.Status.Gripper.Normal;
1490 if (!VisualStyleRenderer.IsElementDefined (element)) {
1491 base.DrawStatusBarSizingGrip (dc, clip, sb, area);
1494 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1495 Rectangle sizing_grip_rectangle = new Rectangle (Point.Empty, renderer.GetPartSize (dc, ThemeSizeType.True));
1496 sizing_grip_rectangle.X = sb.Width - sizing_grip_rectangle.Width;
1497 sizing_grip_rectangle.Y = sb.Height - sizing_grip_rectangle.Height;
1498 renderer.DrawBackground (dc, sizing_grip_rectangle, clip);
1500 protected override void DrawStatusBarPanelBackground (Graphics dc, Rectangle area, StatusBarPanel panel)
1502 if (!RenderClientAreas) {
1503 base.DrawStatusBarPanelBackground (dc, area, panel);
1506 VisualStyleElement element = VisualStyleElement.Status.Pane.Normal;
1507 if (!VisualStyleRenderer.IsElementDefined (element)) {
1508 base.DrawStatusBarPanelBackground (dc, area, panel);
1511 new VisualStyleRenderer (element).DrawBackground (dc, area);
1515 static bool TextBoxBaseShouldPaint (TextBoxBase textBoxBase)
1517 return textBoxBase.BorderStyle == BorderStyle.Fixed3D;
1519 static VisualStyleElement TextBoxBaseGetVisualStyleElement (TextBoxBase textBoxBase)
1521 if (!textBoxBase.Enabled)
1522 return VisualStyleElement.TextBox.TextEdit.Disabled;
1523 if (textBoxBase.ReadOnly)
1524 return VisualStyleElement.TextBox.TextEdit.ReadOnly;
1525 if (textBoxBase.Entered)
1526 return VisualStyleElement.TextBox.TextEdit.Hot;
1527 if (textBoxBase.Focused)
1528 return VisualStyleElement.TextBox.TextEdit.Focused;
1529 return VisualStyleElement.TextBox.TextEdit.Normal;
1531 public override void TextBoxBaseFillBackground (TextBoxBase textBoxBase, Graphics g, Rectangle clippingArea)
1533 if (!RenderClientAreas ||
1534 !TextBoxBaseShouldPaint (textBoxBase)) {
1535 base.TextBoxBaseFillBackground (textBoxBase, g, clippingArea);
1538 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1539 if (!VisualStyleRenderer.IsElementDefined (element)) {
1540 base.TextBoxBaseFillBackground (textBoxBase, g, clippingArea);
1543 Rectangle bounds = new Rectangle(Point.Empty, textBoxBase.Size);
1544 bounds.X -= (bounds.Width - textBoxBase.ClientSize.Width) / 2;
1545 bounds.Y -= (bounds.Height - textBoxBase.ClientSize.Height) / 2;
1546 new VisualStyleRenderer (element).DrawBackground (g, bounds, clippingArea);
1548 public override bool TextBoxBaseHandleWmNcPaint (TextBoxBase textBoxBase, ref Message m)
1550 if (!RenderClientAreas ||
1551 !TextBoxBaseShouldPaint (textBoxBase))
1552 return base.TextBoxBaseHandleWmNcPaint (textBoxBase, ref m);
1553 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1554 if (!VisualStyleRenderer.IsElementDefined (element))
1555 return base.TextBoxBaseHandleWmNcPaint (textBoxBase, ref m);
1556 PaintEventArgs e = XplatUI.PaintEventStart (ref m, textBoxBase.Handle, false);
1557 new VisualStyleRenderer (element).DrawBackgroundExcludingArea (
1559 new Rectangle (Point.Empty, textBoxBase.Size),
1560 new Rectangle (new Point ((textBoxBase.Width - textBoxBase.ClientSize.Width) / 2,
1561 (textBoxBase.Height - textBoxBase.ClientSize.Height) / 2),
1562 textBoxBase.ClientSize));
1563 XplatUI.PaintEventEnd (ref m, textBoxBase.Handle, false);
1566 public override bool TextBoxBaseShouldPaintBackground (TextBoxBase textBoxBase)
1568 if (!RenderClientAreas ||
1569 !TextBoxBaseShouldPaint (textBoxBase))
1570 return base.TextBoxBaseShouldPaintBackground (textBoxBase);
1571 VisualStyleElement element = TextBoxBaseGetVisualStyleElement (textBoxBase);
1572 if (!VisualStyleRenderer.IsElementDefined (element))
1573 return base.TextBoxBaseShouldPaintBackground (textBoxBase);
1574 return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
1578 protected override Size TrackBarGetThumbSize (TrackBar trackBar)
1580 if (!RenderClientAreas)
1581 return base.TrackBarGetThumbSize (trackBar);
1582 VisualStyleElement element = TrackBarGetThumbVisualStyleElement (trackBar);
1583 if (!VisualStyleRenderer.IsElementDefined (element))
1584 return base.TrackBarGetThumbSize (trackBar);
1585 Graphics g = trackBar.CreateGraphics ();
1586 Size result = new VisualStyleRenderer (element).GetPartSize (g, ThemeSizeType.True);
1588 return trackBar.Orientation == Orientation.Horizontal ? result : TrackBarRotateVerticalThumbSize (result);
1590 static VisualStyleElement TrackBarGetThumbVisualStyleElement (TrackBar trackBar)
1592 if (trackBar.Orientation == Orientation.Horizontal)
1593 switch (trackBar.TickStyle) {
1594 case TickStyle.BottomRight:
1595 case TickStyle.None:
1596 return TrackBarGetHorizontalThumbBottomVisualStyleElement (trackBar);
1597 case TickStyle.TopLeft:
1598 return TrackBarGetHorizontalThumbTopVisualStyleElement (trackBar);
1600 return TrackBarGetHorizontalThumbVisualStyleElement (trackBar);
1603 switch (trackBar.TickStyle) {
1604 case TickStyle.BottomRight:
1605 case TickStyle.None:
1606 return TrackBarGetVerticalThumbRightVisualStyleElement (trackBar);
1607 case TickStyle.TopLeft:
1608 return TrackBarGetVerticalThumbLeftVisualStyleElement (trackBar);
1610 return TrackBarGetVerticalThumbVisualStyleElement (trackBar);
1613 static Size TrackBarRotateVerticalThumbSize (Size value)
1615 int temporary = value.Width;
1616 value.Width = value.Height;
1617 value.Height = temporary;
1621 protected override void TrackBarDrawHorizontalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
1623 if (!RenderClientAreas) {
1624 base.TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1627 VisualStyleElement element = VisualStyleElement.TrackBar.Track.Normal;
1628 if (!VisualStyleRenderer.IsElementDefined (element)) {
1629 base.TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1632 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1633 renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (thumb_area.Width, renderer.GetPartSize (dc, ThemeSizeType.True).Height)), clippingArea);
1635 protected override void TrackBarDrawVerticalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
1637 if (!RenderClientAreas) {
1638 base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1641 VisualStyleElement element = VisualStyleElement.TrackBar.TrackVertical.Normal;
1642 if (!VisualStyleRenderer.IsElementDefined (element)) {
1643 base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
1646 VisualStyleRenderer renderer = new VisualStyleRenderer (element);
1647 renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (renderer.GetPartSize (dc, ThemeSizeType.True).Width, thumb_area.Height)), clippingArea);
1651 static bool TrackBarIsDisabled (TrackBar trackBar)
1653 return !trackBar.Enabled;
1655 static bool TrackBarIsHot (TrackBar trackBar)
1657 return trackBar.ThumbEntered;
1659 static bool TrackBarIsPressed (TrackBar trackBar)
1661 return trackBar.thumb_pressed;
1663 static bool TrackBarIsFocused (TrackBar trackBar)
1665 return trackBar.Focused;
1668 protected override void TrackBarDrawHorizontalThumbBottom (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1670 if (!RenderClientAreas) {
1671 base.TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1674 VisualStyleElement element = TrackBarGetHorizontalThumbBottomVisualStyleElement (trackBar);
1675 if (!VisualStyleRenderer.IsElementDefined (element)) {
1676 base.TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1679 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1681 static VisualStyleElement TrackBarGetHorizontalThumbBottomVisualStyleElement (TrackBar trackBar)
1683 if (TrackBarIsDisabled (trackBar))
1684 return VisualStyleElement.TrackBar.ThumbBottom.Disabled;
1685 else if (TrackBarIsPressed (trackBar))
1686 return VisualStyleElement.TrackBar.ThumbBottom.Pressed;
1687 else if (TrackBarIsHot (trackBar))
1688 return VisualStyleElement.TrackBar.ThumbBottom.Hot;
1689 else if (TrackBarIsFocused (trackBar))
1690 return VisualStyleElement.TrackBar.ThumbBottom.Focused;
1691 return VisualStyleElement.TrackBar.ThumbBottom.Normal;
1693 protected override void TrackBarDrawHorizontalThumbTop (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1695 if (!RenderClientAreas) {
1696 base.TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1699 VisualStyleElement element = TrackBarGetHorizontalThumbTopVisualStyleElement (trackBar);
1700 if (!VisualStyleRenderer.IsElementDefined (element)) {
1701 base.TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1704 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1706 static VisualStyleElement TrackBarGetHorizontalThumbTopVisualStyleElement (TrackBar trackBar)
1708 if (TrackBarIsDisabled (trackBar))
1709 return VisualStyleElement.TrackBar.ThumbTop.Disabled;
1710 else if (TrackBarIsPressed (trackBar))
1711 return VisualStyleElement.TrackBar.ThumbTop.Pressed;
1712 else if (TrackBarIsHot (trackBar))
1713 return VisualStyleElement.TrackBar.ThumbTop.Hot;
1714 else if (TrackBarIsFocused (trackBar))
1715 return VisualStyleElement.TrackBar.ThumbTop.Focused;
1716 return VisualStyleElement.TrackBar.ThumbTop.Normal;
1718 protected override void TrackBarDrawHorizontalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1720 if (!RenderClientAreas) {
1721 base.TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1724 VisualStyleElement element = TrackBarGetHorizontalThumbVisualStyleElement (trackBar);
1725 if (!VisualStyleRenderer.IsElementDefined (element)) {
1726 base.TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1729 new VisualStyleRenderer (element).DrawBackground (dc, thumb_pos, clippingArea);
1731 static VisualStyleElement TrackBarGetHorizontalThumbVisualStyleElement (TrackBar trackBar)
1733 if (TrackBarIsDisabled (trackBar))
1734 return VisualStyleElement.TrackBar.Thumb.Disabled;
1735 else if (TrackBarIsPressed (trackBar))
1736 return VisualStyleElement.TrackBar.Thumb.Pressed;
1737 else if (TrackBarIsHot (trackBar))
1738 return VisualStyleElement.TrackBar.Thumb.Hot;
1739 else if (TrackBarIsFocused (trackBar))
1740 return VisualStyleElement.TrackBar.Thumb.Focused;
1741 return VisualStyleElement.TrackBar.Thumb.Normal;
1745 static Rectangle TrackBarRotateVerticalThumbSize (Rectangle value)
1747 int temporary = value.Width;
1748 value.Width = value.Height;
1749 value.Height = temporary;
1752 protected override void TrackBarDrawVerticalThumbRight (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1754 if (!RenderClientAreas) {
1755 base.TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1758 VisualStyleElement element = TrackBarGetVerticalThumbRightVisualStyleElement (trackBar);
1759 if (!VisualStyleRenderer.IsElementDefined (element)) {
1760 base.TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1763 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1765 static VisualStyleElement TrackBarGetVerticalThumbRightVisualStyleElement (TrackBar trackBar)
1767 if (TrackBarIsDisabled (trackBar))
1768 return VisualStyleElement.TrackBar.ThumbRight.Disabled;
1769 else if (TrackBarIsPressed (trackBar))
1770 return VisualStyleElement.TrackBar.ThumbRight.Pressed;
1771 else if (TrackBarIsHot (trackBar))
1772 return VisualStyleElement.TrackBar.ThumbRight.Hot;
1773 else if (TrackBarIsFocused (trackBar))
1774 return VisualStyleElement.TrackBar.ThumbRight.Focused;
1775 return VisualStyleElement.TrackBar.ThumbRight.Normal;
1777 protected override void TrackBarDrawVerticalThumbLeft (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1779 if (!RenderClientAreas) {
1780 base.TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1783 VisualStyleElement element = TrackBarGetVerticalThumbLeftVisualStyleElement (trackBar);
1784 if (!VisualStyleRenderer.IsElementDefined (element)) {
1785 base.TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1788 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1790 static VisualStyleElement TrackBarGetVerticalThumbLeftVisualStyleElement (TrackBar trackBar)
1792 if (TrackBarIsDisabled (trackBar))
1793 return VisualStyleElement.TrackBar.ThumbLeft.Disabled;
1794 else if (TrackBarIsPressed (trackBar))
1795 return VisualStyleElement.TrackBar.ThumbLeft.Pressed;
1796 else if (TrackBarIsHot (trackBar))
1797 return VisualStyleElement.TrackBar.ThumbLeft.Hot;
1798 else if (TrackBarIsFocused (trackBar))
1799 return VisualStyleElement.TrackBar.ThumbLeft.Focused;
1800 return VisualStyleElement.TrackBar.ThumbLeft.Normal;
1802 protected override void TrackBarDrawVerticalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
1804 if (!RenderClientAreas) {
1805 base.TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1808 VisualStyleElement element = TrackBarGetVerticalThumbVisualStyleElement (trackBar);
1809 if (!VisualStyleRenderer.IsElementDefined (element)) {
1810 base.TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clippingArea, trackBar);
1813 new VisualStyleRenderer (element).DrawBackground (dc, TrackBarRotateVerticalThumbSize (thumb_pos), clippingArea);
1815 static VisualStyleElement TrackBarGetVerticalThumbVisualStyleElement (TrackBar trackBar)
1817 if (TrackBarIsDisabled (trackBar))
1818 return VisualStyleElement.TrackBar.ThumbVertical.Disabled;
1819 else if (TrackBarIsPressed (trackBar))
1820 return VisualStyleElement.TrackBar.ThumbVertical.Pressed;
1821 else if (TrackBarIsHot (trackBar))
1822 return VisualStyleElement.TrackBar.ThumbVertical.Hot;
1823 else if (TrackBarIsFocused (trackBar))
1824 return VisualStyleElement.TrackBar.ThumbVertical.Focused;
1825 return VisualStyleElement.TrackBar.ThumbVertical.Normal;
1830 const EdgeStyle TrackBarTickEdgeStyle = EdgeStyle.Bump;
1831 const EdgeEffects TrackBarTickEdgeEffects = EdgeEffects.None;
1833 protected override ITrackBarTickPainter TrackBarGetHorizontalTickPainter (Graphics g)
1835 if (!RenderClientAreas ||
1836 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.TrackBar.Ticks.Normal))
1837 return base.TrackBarGetHorizontalTickPainter (g);
1838 return new TrackBarHorizontalTickPainter (g);
1840 class TrackBarHorizontalTickPainter : ITrackBarTickPainter
1842 readonly Graphics g;
1843 readonly VisualStyleRenderer renderer;
1844 public TrackBarHorizontalTickPainter (Graphics g)
1847 renderer = new VisualStyleRenderer (VisualStyleElement.TrackBar.Ticks.Normal);
1849 public void Paint (float x1, float y1, float x2, float y2)
1851 renderer.DrawEdge (g, new Rectangle (
1852 (int)Math.Round (x1),
1853 (int)Math.Round (y1),
1855 (int)Math.Round (y2 - y1) + 1), Edges.Left, TrackBarTickEdgeStyle, TrackBarTickEdgeEffects);
1860 protected override ITrackBarTickPainter TrackBarGetVerticalTickPainter (Graphics g)
1862 if (!RenderClientAreas ||
1863 !VisualStyleRenderer.IsElementDefined (VisualStyleElement.TrackBar.TicksVertical.Normal))
1864 return base.TrackBarGetVerticalTickPainter (g);
1865 return new TrackBarVerticalTickPainter (g);
1867 class TrackBarVerticalTickPainter : ITrackBarTickPainter
1869 readonly Graphics g;
1870 readonly VisualStyleRenderer renderer;
1871 public TrackBarVerticalTickPainter (Graphics g)
1874 renderer = new VisualStyleRenderer (VisualStyleElement.TrackBar.TicksVertical.Normal);
1876 public void Paint (float x1, float y1, float x2, float y2)
1878 renderer.DrawEdge (g, new Rectangle (
1879 (int)Math.Round (x1),
1880 (int)Math.Round (y1),
1881 (int)Math.Round (x2 - x1) + 1,
1882 1), Edges.Top, TrackBarTickEdgeStyle, TrackBarTickEdgeEffects);
1887 public override bool TrackBarHasHotThumbStyle {
1889 if (!RenderClientAreas)
1890 return base.TrackBarHasHotThumbStyle;
1896 static bool ToolBarIsDisabled (ToolBarItem item)
1898 return !item.Button.Enabled;
1900 static bool ToolBarIsPressed (ToolBarItem item)
1902 return item.Pressed;
1904 static bool ToolBarIsChecked (ToolBarItem item)
1906 return item.Button.Pushed;
1908 static bool ToolBarIsHot (ToolBarItem item)
1910 return item.Hilight;
1913 protected override void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat)
1915 if (!RenderClientAreas) {
1916 base.DrawToolBarButtonBorder (dc, item, is_flat);
1919 if (item.Button.Style == ToolBarButtonStyle.Separator)
1921 VisualStyleElement element;
1922 if (item.Button.Style == ToolBarButtonStyle.DropDownButton)
1923 element = ToolBarGetDropDownButtonVisualStyleElement (item);
1925 element = ToolBarGetButtonVisualStyleElement (item);
1926 if (!VisualStyleRenderer.IsElementDefined (element)) {
1927 base.DrawToolBarButtonBorder (dc, item, is_flat);
1930 Rectangle rectangle = item.Rectangle;
1931 if (item.Button.Style == ToolBarButtonStyle.DropDownButton && item.Button.Parent.DropDownArrows)
1932 rectangle.Width -= ToolBarDropDownWidth;
1933 new VisualStyleRenderer (element).DrawBackground (dc, rectangle);
1935 private static VisualStyleElement ToolBarGetDropDownButtonVisualStyleElement (ToolBarItem item)
1937 if (item.Button.Parent.DropDownArrows) {
1938 if (ToolBarIsDisabled (item))
1939 return VisualStyleElement.ToolBar.SplitButton.Disabled;
1940 if (ToolBarIsPressed (item))
1941 return VisualStyleElement.ToolBar.SplitButton.Pressed;
1942 if (ToolBarIsChecked (item))
1943 if (ToolBarIsHot (item))
1944 return VisualStyleElement.ToolBar.SplitButton.HotChecked;
1946 return VisualStyleElement.ToolBar.SplitButton.Checked;
1947 if (ToolBarIsHot (item))
1948 return VisualStyleElement.ToolBar.SplitButton.Hot;
1949 return VisualStyleElement.ToolBar.SplitButton.Normal;
1951 if (ToolBarIsDisabled (item))
1952 return VisualStyleElement.ToolBar.DropDownButton.Disabled;
1953 if (ToolBarIsPressed (item))
1954 return VisualStyleElement.ToolBar.DropDownButton.Pressed;
1955 if (ToolBarIsChecked (item))
1956 if (ToolBarIsHot (item))
1957 return VisualStyleElement.ToolBar.DropDownButton.HotChecked;
1959 return VisualStyleElement.ToolBar.DropDownButton.Checked;
1960 if (ToolBarIsHot (item))
1961 return VisualStyleElement.ToolBar.DropDownButton.Hot;
1962 return VisualStyleElement.ToolBar.DropDownButton.Normal;
1965 private static VisualStyleElement ToolBarGetButtonVisualStyleElement (ToolBarItem item)
1967 if (ToolBarIsDisabled (item))
1968 return VisualStyleElement.ToolBar.Button.Disabled;
1969 if (ToolBarIsPressed (item))
1970 return VisualStyleElement.ToolBar.Button.Pressed;
1971 if (ToolBarIsChecked (item))
1972 if (ToolBarIsHot (item))
1973 return VisualStyleElement.ToolBar.Button.HotChecked;
1975 return VisualStyleElement.ToolBar.Button.Checked;
1976 if (ToolBarIsHot (item))
1977 return VisualStyleElement.ToolBar.Button.Hot;
1978 return VisualStyleElement.ToolBar.Button.Normal;
1982 protected override void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
1984 if (!RenderClientAreas) {
1985 base.DrawToolBarSeparator (dc, item);
1988 VisualStyleElement element = ToolBarGetSeparatorVisualStyleElement (item);
1989 if (!VisualStyleRenderer.IsElementDefined (element)) {
1990 base.DrawToolBarSeparator (dc, item);
1993 Rectangle area = item.Rectangle;
1994 new VisualStyleRenderer (element).DrawBackground (dc, item.Rectangle);
1996 static VisualStyleElement ToolBarGetSeparatorVisualStyleElement (ToolBarItem toolBarItem)
1998 return toolBarItem.Button.Parent.Vertical ?
1999 VisualStyleElement.ToolBar.SeparatorVertical.Normal :
2000 VisualStyleElement.ToolBar.SeparatorHorizontal.Normal;
2003 #region Toggle button background
2004 protected override void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item)
2006 if (!RenderClientAreas ||
2007 !VisualStyleRenderer.IsElementDefined (ToolBarGetButtonVisualStyleElement (item)))
2008 base.DrawToolBarToggleButtonBackground (dc, item);
2011 #region Drop down arrow
2012 protected override void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
2014 if (!RenderClientAreas) {
2015 base.DrawToolBarDropDownArrow (dc, item, is_flat);
2018 VisualStyleElement element = ToolBarGetDropDownArrowVisualStyleElement (item);
2019 if (!VisualStyleRenderer.IsElementDefined (element)) {
2020 base.DrawToolBarDropDownArrow (dc, item, is_flat);
2023 Rectangle rect = item.Rectangle;
2024 rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
2025 rect.Width = ToolBarDropDownWidth;
2026 new VisualStyleRenderer (element).DrawBackground (dc, rect);
2028 private static VisualStyleElement ToolBarGetDropDownArrowVisualStyleElement (ToolBarItem item)
2030 if (ToolBarIsDisabled (item))
2031 return VisualStyleElement.ToolBar.SplitButtonDropDown.Disabled;
2032 if (ToolBarIsPressed (item))
2033 return VisualStyleElement.ToolBar.SplitButtonDropDown.Pressed;
2034 if (ToolBarIsChecked (item))
2035 if (ToolBarIsHot (item))
2036 return VisualStyleElement.ToolBar.SplitButtonDropDown.HotChecked;
2038 return VisualStyleElement.ToolBar.SplitButtonDropDown.Checked;
2039 if (ToolBarIsHot (item))
2040 return VisualStyleElement.ToolBar.SplitButtonDropDown.Hot;
2041 return VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
2044 public override bool ToolBarHasHotElementStyles (ToolBar toolBar)
2046 if (!RenderClientAreas)
2047 return base.ToolBarHasHotElementStyles (toolBar);
2050 public override bool ToolBarHasHotCheckedElementStyles {
2052 if (!RenderClientAreas)
2053 return base.ToolBarHasHotCheckedElementStyles;
2059 protected override void ToolTipDrawBackground (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
2061 if (!RenderClientAreas) {
2062 base.ToolTipDrawBackground (dc, clip_rectangle, control);
2065 VisualStyleElement element = VisualStyleElement.ToolTip.Standard.Normal;
2066 if (!VisualStyleRenderer.IsElementDefined (element)) {
2067 base.ToolTipDrawBackground (dc, clip_rectangle, control);
2070 new VisualStyleRenderer (element).DrawBackground (dc, control.Bounds);
2072 public override bool ToolTipTransparentBackground {
2074 if (!RenderClientAreas)
2075 return base.ToolTipTransparentBackground;
2076 VisualStyleElement element = VisualStyleElement.ToolTip.Standard.Normal;
2077 if (!VisualStyleRenderer.IsElementDefined (element))
2078 return base.ToolTipTransparentBackground;
2079 return new VisualStyleRenderer (element).IsBackgroundPartiallyTransparent ();
2084 [MonoTODO("Use the sizing information provided by the VisualStyles API.")]
2085 public override void TreeViewDrawNodePlusMinus (TreeView treeView, TreeNode node, Graphics dc, int x, int middle)
2087 if (!RenderClientAreas) {
2088 base.TreeViewDrawNodePlusMinus (treeView, node, dc, x, middle);
2091 VisualStyleElement element = node.IsExpanded ?
2092 VisualStyleElement.TreeView.Glyph.Opened :
2093 VisualStyleElement.TreeView.Glyph.Closed;
2094 if (!VisualStyleRenderer.IsElementDefined (element)) {
2095 base.TreeViewDrawNodePlusMinus (treeView, node, dc, x, middle);
2098 new VisualStyleRenderer (element).DrawBackground (dc, new Rectangle (x, middle - 4, 9, 9));
2102 public override void UpDownBaseDrawButton (Graphics g, Rectangle bounds, bool top, PushButtonState state)
2104 if (!RenderClientAreas) {
2105 base.UpDownBaseDrawButton (g, bounds, top, state);
2108 VisualStyleElement element;
2111 case PushButtonState.Disabled:
2112 element = VisualStyleElement.Spin.Up.Disabled;
2114 case PushButtonState.Pressed:
2115 element = VisualStyleElement.Spin.Up.Pressed;
2117 case PushButtonState.Hot:
2118 element = VisualStyleElement.Spin.Up.Hot;
2121 element = VisualStyleElement.Spin.Up.Normal;
2126 case PushButtonState.Disabled:
2127 element = VisualStyleElement.Spin.Down.Disabled;
2129 case PushButtonState.Pressed:
2130 element = VisualStyleElement.Spin.Down.Pressed;
2132 case PushButtonState.Hot:
2133 element = VisualStyleElement.Spin.Down.Hot;
2136 element = VisualStyleElement.Spin.Down.Normal;
2139 if (!VisualStyleRenderer.IsElementDefined (element)) {
2140 base.UpDownBaseDrawButton (g, bounds, top, state);
2143 new VisualStyleRenderer (element).DrawBackground (g, bounds);
2145 public override bool UpDownBaseHasHotButtonStyle {
2147 if (!RenderClientAreas)
2148 return base.UpDownBaseHasHotButtonStyle;
2154 static bool AreEqual (VisualStyleElement value1, VisualStyleElement value2)
2157 value1.ClassName == value1.ClassName &&
2158 value1.Part == value2.Part &&
2159 value1.State == value2.State;
2161 #region Measurement device context
2162 static Control control;
2163 static IDeviceContext GetMeasurementDeviceContext ()
2165 if (control == null)
2166 control = new Control ();
2167 return control.CreateGraphics ();
2169 static void ReleaseMeasurementDeviceContext (IDeviceContext dc)