/
ThemeWin32Classic.cs
5572 lines (4633 loc) · 199 KB
/
ThemeWin32Classic.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2004-2005 Novell, Inc.
//
// Authors:
// Jordi Mas i Hernandez, jordi@ximian.com
// Peter Bartok, pbartok@novell.com
// John BouAntoun, jba-mono@optusnet.com.au
// Marek Safar, marek.safar@seznam.cz
//
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
namespace System.Windows.Forms
{
internal class ThemeWin32Classic : Theme
{
public override Version Version {
get {
return new Version(0, 1, 0, 0);
}
}
/* Hardcoded colour values not exposed in the API constants in all configurations */
protected static readonly Color arrow_color = Color.Black;
protected static readonly Color pen_ticks_color = Color.Black;
protected static readonly Color progressbarblock_color = Color.FromArgb (255, 0, 0, 128);
protected static StringFormat string_format_menu_text;
protected static StringFormat string_format_menu_shortcut;
protected static StringFormat string_format_menu_menubar_text;
static readonly Rectangle checkbox_rect = new Rectangle (2, 2, 11,11); // Position of the checkbox relative to the item
static ImageAttributes imagedisabled_attributes = null;
const int SEPARATOR_HEIGHT = 5;
const int SM_CXBORDER = 1;
const int SM_CYBORDER = 1;
const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab
const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
#region Principal Theme Methods
public ThemeWin32Classic ()
{
defaultWindowBackColor = this.ColorWindow;
defaultWindowForeColor = this.ColorControlText;
default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
/* Menu string formats */
string_format_menu_text = new StringFormat ();
string_format_menu_text.LineAlignment = StringAlignment.Center;
string_format_menu_text.Alignment = StringAlignment.Near;
string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
string_format_menu_shortcut = new StringFormat ();
string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
string_format_menu_shortcut.Alignment = StringAlignment.Far;
string_format_menu_menubar_text = new StringFormat ();
string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
string_format_menu_menubar_text.Alignment = StringAlignment.Center;
string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
always_draw_hotkeys = false;
}
public override void ResetDefaults() {
throw new NotImplementedException("Need to implement ResetDefaults() for Win32 theme");
}
public override bool DoubleBufferingSupported {
get {return true; }
}
#endregion // Principal Theme Methods
#region Internal Methods
protected SolidBrush GetControlBackBrush (Color c) {
if (c == DefaultControlBackColor)
return ResPool.GetSolidBrush (ColorControl);
return new SolidBrush (c);
}
protected SolidBrush GetControlForeBrush (Color c) {
if (c == DefaultControlForeColor)
return ResPool.GetSolidBrush (ColorControlText);
return new SolidBrush (c);
}
#endregion // Internal Methods
#region OwnerDraw Support
public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
{
if (e.State == DrawItemState.Selected) {
e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
return;
}
e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds);
}
public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
{
if (e.State == DrawItemState.Focus)
CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
}
#endregion // OwnerDraw Support
#region ButtonBase
public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
// Draw the button: fill rectangle, draw border, etc.
ButtonBase_DrawButton(button, dc);
// First, draw the image
if ((button.image != null) || (button.image_list != null))
ButtonBase_DrawImage(button, dc);
// Draw the focus rectangle
if (button.has_focus)
ButtonBase_DrawFocus(button, dc);
// Now the text
if (button.text != null && button.text != String.Empty)
ButtonBase_DrawText(button, dc);
}
protected virtual void ButtonBase_DrawButton(ButtonBase button, Graphics dc)
{
Rectangle buttonRectangle;
Rectangle borderRectangle;
dc.FillRectangle(ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
// set up the button rectangle
buttonRectangle = button.ClientRectangle;
if (button.has_focus) {
// shrink the rectangle for the normal button drawing inside the focus rectangle
borderRectangle = Rectangle.Inflate(buttonRectangle, -1, -1);
} else {
borderRectangle = buttonRectangle;
}
if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
DrawFlatStyleButton (dc, borderRectangle, button);
} else {
CPDrawButton(dc, borderRectangle, button.ButtonState);
if (button.has_focus) {
dc.DrawRectangle(ResPool.GetPen(button.ForeColor), borderRectangle);
}
}
}
protected virtual void ButtonBase_DrawImage(ButtonBase button, Graphics dc)
{
// Need to draw a picture
Image i;
int image_x;
int image_y;
int image_width;
int image_height;
int width = button.ClientSize.Width;
int height = button.ClientSize.Height;
if (button.ImageIndex != -1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
i = button.image_list.Images[button.image_index];
} else {
i = button.image;
}
image_width = button.image.Width;
image_height = button.image.Height;
switch (button.image_alignment) {
case ContentAlignment.TopLeft: {
image_x=0;
image_y=0;
break;
}
case ContentAlignment.TopCenter: {
image_x=(width-image_width)/2;
image_y=0;
break;
}
case ContentAlignment.TopRight: {
image_x=width-image_width;
image_y=0;
break;
}
case ContentAlignment.MiddleLeft: {
image_x=0;
image_y=(height-image_height)/2;
break;
}
case ContentAlignment.MiddleCenter: {
image_x=(width-image_width)/2;
image_y=(height-image_height)/2;
break;
}
case ContentAlignment.MiddleRight: {
image_x=width-image_width;
image_y=(height-image_height)/2;
break;
}
case ContentAlignment.BottomLeft: {
image_x=0;
image_y=height-image_height;
break;
}
case ContentAlignment.BottomCenter: {
image_x=(width-image_width)/2;
image_y=height-image_height;
break;
}
case ContentAlignment.BottomRight: {
image_x=width-image_width;
image_y=height-image_height;
break;
}
default: {
image_x=0;
image_y=0;
break;
}
}
if (button.is_pressed) {
image_x+=1;
image_y+=1;
}
if (button.is_enabled) {
dc.DrawImage(i, image_x, image_y);
}
else {
CPDrawImageDisabled(dc, i, image_x, image_y, ColorControl);
}
}
protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc)
{
if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
DrawFlatStyleFocusRectangle (dc, button.ClientRectangle, button, button.ForeColor, button.BackColor);
} else {
Rectangle rect = button.ClientRectangle;
rect.Inflate (-4, -4);
CPDrawFocusRectangle(dc, rect, button.ForeColor, button.BackColor);
}
}
protected virtual void ButtonBase_DrawText(ButtonBase button, Graphics dc)
{
Rectangle buttonRectangle = button.ClientRectangle;
Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
if (button.is_pressed) {
text_rect.X++;
text_rect.Y++;
}
if (button.is_enabled) {
dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
} else {
if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorControl)), text_rect, button.text_format);
} else {
CPDrawStringDisabled(dc, button.text, button.Font, ColorControlText, text_rect, button.text_format);
}
}
}
// draw the flat style part of the rectangle
public void DrawFlatStyleButton (Graphics graphics, Rectangle rectangle, ButtonBase button) {
Color rect_back_color = button.BackColor;
Color rect_fore_color = button.ForeColor;
Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
if (button.Enabled) {
if (button.Capture || button.is_entered) {
if (button.FlatStyle == FlatStyle.Flat) {
// fill the rectangle
graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
// now draw the outer border
if (button.Capture && button.is_entered) {
rect_back_color = ControlPaint.LightLight (rect_back_color);
} else {
rect_back_color = ControlPaint.Light (rect_back_color);
}
// draw rectangle and fill it
graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
} else {
// else it must be a popup button
if (button.Capture && button.is_entered) {
graphics.DrawRectangle(ResPool.GetPen (this.ColorControlText), trace_rectangle);
} else {
// draw a 3d border
CPDrawBorder3D (graphics, rectangle, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, button.BackColor);
graphics.DrawLine ( ResPool.GetPen (this.ColorControlText), trace_rectangle.X, trace_rectangle.Bottom, trace_rectangle.Right, trace_rectangle.Bottom);
graphics.DrawLine ( ResPool.GetPen (this.ColorControlText), trace_rectangle.Right, trace_rectangle.Y, trace_rectangle.Right, trace_rectangle.Bottom);
}
}
// TODO: draw inner focus rectangle
} else {
// popup has a ButtonColorText forecolor, not a button.ForeCOlor
if (button.FlatStyle == FlatStyle.Popup) {
rect_fore_color = this.ColorControlText;
}
// fill then draw outer rect
graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
}
// finally some small tweaks to render radiobutton and checkbox
CheckBox checkbox = button as CheckBox;
RadioButton radiobutton = button as RadioButton;
if ((checkbox != null && checkbox.Checked) ||
(radiobutton != null && radiobutton.Checked)) {
if (button.FlatStyle == FlatStyle.Flat && button.is_entered && !button.Capture) {
// render the hover for flat flatstyle and cheked
graphics.DrawRectangle(ResPool.GetPen (this.ColorControlText), trace_rectangle);
} else if (!button.is_entered && !button.Capture) {
// render the checked state for popup when unhovered
CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
}
}
} else {
// rendering checkbox or radio button style buttons
CheckBox checkbox = button as CheckBox;
RadioButton radiobutton = button as RadioButton;
bool draw_popup_checked = false;
if (button.FlatStyle == FlatStyle.Popup) {
rect_fore_color = this.ColorControlText;
// see if we should draw a disabled checked popup button
draw_popup_checked = ((checkbox != null && checkbox.Checked) ||
(radiobutton != null && radiobutton.Checked));
}
graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
// finally draw the flatstyle checked effect if need
if (draw_popup_checked) {
// render the checked state for popup when unhovered
CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
}
}
}
public override Size ButtonBaseDefaultSize {
get {
return new Size (75, 23);
}
}
#endregion // ButtonBase
#region CheckBox
public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
StringFormat text_format;
Rectangle client_rectangle;
Rectangle text_rectangle;
Rectangle checkbox_rectangle;
int checkmark_size=13;
int checkmark_space = 4;
client_rectangle = checkbox.ClientRectangle;
text_rectangle = client_rectangle;
checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
text_format = new StringFormat();
text_format.Alignment=StringAlignment.Near;
text_format.LineAlignment=StringAlignment.Center;
text_format.HotkeyPrefix = HotkeyPrefix.Show;
/* Calculate the position of text and checkbox rectangle */
if (checkbox.appearance!=Appearance.Button) {
switch(checkbox.check_alignment) {
case ContentAlignment.BottomCenter: {
checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
text_rectangle.X=client_rectangle.X;
text_rectangle.Width=client_rectangle.Width;
text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
break;
}
case ContentAlignment.BottomLeft: {
checkbox_rectangle.X=client_rectangle.Left;
checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
break;
}
case ContentAlignment.BottomRight: {
checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
text_rectangle.X=client_rectangle.X;
text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
break;
}
case ContentAlignment.MiddleCenter: {
checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
text_rectangle.X=client_rectangle.X;
text_rectangle.Width=client_rectangle.Width;
break;
}
default:
case ContentAlignment.MiddleLeft: {
checkbox_rectangle.X=client_rectangle.Left;
checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
break;
}
case ContentAlignment.MiddleRight: {
checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
text_rectangle.X=client_rectangle.X;
text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
break;
}
case ContentAlignment.TopCenter: {
checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
checkbox_rectangle.Y=client_rectangle.Top;
text_rectangle.X=client_rectangle.X;
text_rectangle.Width=client_rectangle.Width;
text_rectangle.Y=checkmark_size+checkmark_space;
text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
break;
}
case ContentAlignment.TopLeft: {
checkbox_rectangle.X=client_rectangle.Left;
text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
break;
}
case ContentAlignment.TopRight: {
checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
text_rectangle.X=client_rectangle.X;
text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
break;
}
}
} else {
text_rectangle.X=client_rectangle.X;
text_rectangle.Width=client_rectangle.Width;
}
/* Set the horizontal alignment of our text */
switch(checkbox.text_alignment) {
case ContentAlignment.BottomLeft:
case ContentAlignment.MiddleLeft:
case ContentAlignment.TopLeft: {
text_format.Alignment=StringAlignment.Near;
break;
}
case ContentAlignment.BottomCenter:
case ContentAlignment.MiddleCenter:
case ContentAlignment.TopCenter: {
text_format.Alignment=StringAlignment.Center;
break;
}
case ContentAlignment.BottomRight:
case ContentAlignment.MiddleRight:
case ContentAlignment.TopRight: {
text_format.Alignment=StringAlignment.Far;
break;
}
}
/* Set the vertical alignment of our text */
switch(checkbox.text_alignment) {
case ContentAlignment.TopLeft:
case ContentAlignment.TopCenter:
case ContentAlignment.TopRight: {
text_format.LineAlignment=StringAlignment.Near;
break;
}
case ContentAlignment.BottomLeft:
case ContentAlignment.BottomCenter:
case ContentAlignment.BottomRight: {
text_format.LineAlignment=StringAlignment.Far;
break;
}
case ContentAlignment.MiddleLeft:
case ContentAlignment.MiddleCenter:
case ContentAlignment.MiddleRight: {
text_format.LineAlignment=StringAlignment.Center;
break;
}
}
ButtonState state = ButtonState.Normal;
if (checkbox.FlatStyle == FlatStyle.Flat) {
state |= ButtonState.Flat;
}
if (checkbox.Checked) {
state |= ButtonState.Checked;
}
if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
state |= ButtonState.Checked;
state |= ButtonState.Pushed;
}
// finally make sure the pushed and inavtive states are rendered
if (!checkbox.Enabled) {
state |= ButtonState.Inactive;
}
else if (checkbox.is_pressed) {
state |= ButtonState.Pushed;
}
// Start drawing
CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
CheckBox_DrawText(checkbox, text_rectangle, dc, text_format);
CheckBox_DrawFocus(checkbox, dc, text_rectangle);
text_format.Dispose ();
}
protected virtual void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
{
dc.FillRectangle (ResPool.GetSolidBrush (checkbox.BackColor), checkbox.ClientRectangle);
// render as per normal button
if (checkbox.appearance==Appearance.Button) {
if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
DrawFlatStyleButton(dc, checkbox.ClientRectangle, checkbox);
} else {
CPDrawButton(dc, checkbox.ClientRectangle, state);
}
} else {
// establish if we are rendering a flat style of some sort
if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
} else {
ControlPaint.DrawCheckBox(dc, checkbox_rectangle, state);
}
}
}
protected virtual void CheckBox_DrawText( CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format )
{
SolidBrush sb;
// offset the text if it's pressed and a button
if (checkbox.Appearance == Appearance.Button) {
if (checkbox.Checked || (checkbox.Capture && checkbox.FlatStyle != FlatStyle.Flat)) {
text_rectangle.X ++;
text_rectangle.Y ++;
}
text_rectangle.Inflate(-4, -4);
}
/* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
if (checkbox.Enabled) {
sb = ResPool.GetSolidBrush(checkbox.ForeColor);
dc.DrawString(checkbox.Text, checkbox.Font, sb, text_rectangle, text_format);
} else if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
dc.DrawString(checkbox.Text, checkbox.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorControl)), text_rectangle, text_format);
} else {
CPDrawStringDisabled(dc, checkbox.Text, checkbox.Font, ColorControlText, text_rectangle, text_format);
}
}
protected virtual void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
{
if (checkbox.Focused) {
if (checkbox.FlatStyle != FlatStyle.Flat) {
DrawInnerFocusRectangle (dc, Rectangle.Inflate (text_rectangle, -1, -1), checkbox.BackColor);
} else {
dc.DrawRectangle (ResPool.GetPen (checkbox.ForeColor), Rectangle.Inflate (text_rectangle, -1, -1));
}
}
}
// renders a checkBox with the Flat and Popup FlatStyle
protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
{
Pen pen;
Rectangle rect;
Rectangle checkbox_rectangle;
Rectangle fill_rectangle;
int lineWidth;
int Scale;
// set up our rectangles first
if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
// clip one pixel from bottom right for non popup rendered checkboxes
checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
fill_rectangle = new Rectangle(checkbox_rectangle.X+1, checkbox_rectangle.Y+1, Math.Max(checkbox_rectangle.Width-3, 0), Math.Max(checkbox_rectangle.Height-3,0));
} else {
// clip two pixels from bottom right for non popup rendered checkboxes
checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
fill_rectangle = new Rectangle(checkbox_rectangle.X+1, checkbox_rectangle.Y+1, Math.Max(checkbox_rectangle.Width-2, 0), Math.Max(checkbox_rectangle.Height-2,0));
}
// if disabled render in disabled state
if (checkbox.Enabled) {
// process the state of the checkbox
if (checkbox.is_entered || checkbox.Capture) {
// decide on which background color to use
if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
} else if (checkbox.FlatStyle == FlatStyle.Flat && !(checkbox.is_entered && checkbox.Capture)) {
graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.Light(checkbox.BackColor)), fill_rectangle);
} else {
// use regular window background color
graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
}
// render the outer border
if (checkbox.FlatStyle == FlatStyle.Flat) {
ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
} else {
// draw sunken effect
CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.All, checkbox.BackColor);
}
} else {
graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
if (checkbox.FlatStyle == FlatStyle.Flat) {
ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
} else {
// draw the outer border
ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
}
}
} else {
if (checkbox.FlatStyle == FlatStyle.Popup) {
graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
}
// draw disabled state,
ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorControlDark, ButtonBorderStyle.Solid);
}
/* Make sure we've got at least a line width of 1 */
lineWidth = Math.Max(3, fill_rectangle.Width/3);
Scale=Math.Max(1, fill_rectangle.Width/9);
// flat style check box is rendered inside a rectangle shifted down by one
rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
if (checkbox.Enabled) {
pen=ResPool.GetPen(checkbox.ForeColor);
} else {
pen=SystemPens.ControlDark;
}
if (checkbox.Checked) {
/* Need to draw a check-mark */
for (int i=0; i<lineWidth; i++) {
graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
graphics.DrawLine(pen, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i, rect.Left+lineWidth/2+6*Scale, rect.Top+lineWidth-2*Scale+i);
}
}
}
#endregion // CheckBox
#region CheckedListBox
public override Rectangle CheckedListBoxCheckRectangle ()
{
return checkbox_rect;
}
public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
{
Color back_color, fore_color;
Rectangle item_rect = e.Bounds;
ButtonState state;
StringFormat string_format = ctrl.GetFormatString ();
/* Draw checkbox */
if ((ctrl.Items.GetListBoxItem (e.Index)).State == CheckState.Checked)
state = ButtonState.Checked;
else
state = ButtonState.Normal;
if (ctrl.ThreeDCheckBoxes == false)
state |= ButtonState.Flat;
ControlPaint.DrawCheckBox (e.Graphics,
item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
checkbox_rect.Width, checkbox_rect.Height,
state);
item_rect.X += checkbox_rect.Width + checkbox_rect.X * 2;
item_rect.Width -= checkbox_rect.Width + checkbox_rect.X * 2;
/* Draw text*/
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
back_color = ThemeEngine.Current.ColorHighlight;
fore_color = ThemeEngine.Current.ColorHighlightText;
}
else {
back_color = e.BackColor;
fore_color = e.ForeColor;
}
e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
(back_color), item_rect);
e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
ThemeEngine.Current.ResPool.GetSolidBrush (fore_color),
item_rect, string_format);
if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, item_rect,
fore_color, back_color);
}
}
#endregion // CheckedListBox
#region ComboBox
// Drawing
public override void DrawComboBoxEditDecorations (Graphics dc, ComboBox ctrl, Rectangle cl)
{
dc.DrawLine (ResPool.GetPen (ColorControlDark), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top
dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
dc.DrawLine (ResPool.GetPen (ColorControl), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
dc.DrawLine (ResPool.GetPen (ColorControlLight), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
dc.DrawLine (ResPool.GetPen (ColorControlDark), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2);
dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + cl.Width - 2, cl.Y, cl.X + cl.Width - 2, cl.Y + cl.Height); //right
dc.DrawLine (ResPool.GetPen (ColorControlLight), cl.X + cl.Width - 1, cl.Y + 1 , cl.X + cl.Width - 1, cl.Y + cl.Height - 1);
}
// Sizing
public override int DrawComboBoxEditDecorationTop () { return 2;}
public override int DrawComboBoxEditDecorationBottom () { return 2;}
public override int DrawComboBoxEditDecorationRight () { return 2;}
public override int DrawComboBoxEditDecorationLeft () { return 2;}
private int DrawComboListBoxDecoration (ComboBoxStyle style)
{
if (style == ComboBoxStyle.Simple)
return 2;
else
return 1;
}
public override int DrawComboListBoxDecorationTop (ComboBoxStyle style)
{
return DrawComboListBoxDecoration (style);
}
public override int DrawComboListBoxDecorationBottom (ComboBoxStyle style)
{
return DrawComboListBoxDecoration (style);
}
public override int DrawComboListBoxDecorationRight (ComboBoxStyle style)
{
return DrawComboListBoxDecoration (style);
}
public override int DrawComboListBoxDecorationLeft (ComboBoxStyle style)
{
return DrawComboListBoxDecoration (style);
}
public override void DrawComboListBoxDecorations (Graphics dc, ComboBox ctrl, Rectangle cl)
{
if (ctrl.DropDownStyle == ComboBoxStyle.Simple) {
DrawComboBoxEditDecorations (dc, ctrl, cl);
}
else {
dc.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorWindowFrame),
cl.X, cl.Y, cl.Width - 1, cl.Height - 1);
}
}
public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
{
Color back_color, fore_color;
Rectangle text_draw = e.Bounds;
StringFormat string_format = new StringFormat ();
string_format.FormatFlags = StringFormatFlags.LineLimit;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
back_color = ThemeEngine.Current.ColorHighlight;
fore_color = ThemeEngine.Current.ColorHighlightText;
}
else {
back_color = e.BackColor;
fore_color = e.ForeColor;
}
e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (back_color), e.Bounds);
if (e.Index != -1) {
e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
ThemeEngine.Current.ResPool.GetSolidBrush (fore_color),
text_draw, string_format);
}
if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
}
string_format.Dispose ();
}
#endregion ComboBox
#region Datagrid
public override int DataGridPreferredColumnWidth { get { return 75;} }
public override int DataGridMinimumColumnCheckBoxHeight { get { return 16;} }
public override int DataGridMinimumColumnCheckBoxWidth { get { return 16;} }
public override Color DataGridAlternatingBackColor { get { return ColorWindow;} }
public override Color DataGridBackColor { get { return ColorWindow;} }
public override Color DataGridBackgroundColor { get { return ColorAppWorkspace;} }
public override Color DataGridCaptionBackColor { get { return ColorActiveCaption;} }
public override Color DataGridCaptionForeColor { get { return ColorActiveCaptionText;} }
public override Color DataGridGridLineColor { get { return ColorControl;} }
public override Color DataGridHeaderBackColor { get { return ColorControl;} }
public override Color DataGridHeaderForeColor { get { return ColorControlText;} }
public override Color DataGridLinkColor { get { return ColorHotTrack;} }
public override Color DataGridLinkHoverColor { get { return ColorHotTrack;} }
public override Color DataGridParentRowsBackColor { get { return ColorControl;} }
public override Color DataGridParentRowsForeColor { get { return ColorWindowText;} }
public override Color DataGridSelectionBackColor { get { return ColorActiveCaption;} }
public override Color DataGridSelectionForeColor { get { return ColorActiveCaptionText;} }
public override void DataGridPaint (PaintEventArgs pe, DataGrid grid)
{
// Draw parent rows
if (pe.ClipRectangle.IntersectsWith (grid.grid_drawing.parent_rows)) {
pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor), grid.grid_drawing.parent_rows);
}
DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, grid);
DataGridPaintColumnsHdrs (pe.Graphics, pe.ClipRectangle, grid);
DataGridPaintRowsHeaders (pe.Graphics, pe.ClipRectangle, grid);
DataGridPaintRows (pe.Graphics, grid.grid_drawing.cells_area, pe.ClipRectangle, grid);
// Paint scrollBar corner
if (grid.vert_scrollbar.Visible && grid.horiz_scrollbar.Visible) {
Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.horiz_scrollbar.Height,
grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.horiz_scrollbar.Height,
grid.horiz_scrollbar.Height, grid.horiz_scrollbar.Height);
if (pe.ClipRectangle.IntersectsWith (corner)) {
pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
corner);
}
}
}
public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
{
Rectangle modified_area = clip;
modified_area.Intersect (grid.grid_drawing.caption_area);
g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor),
modified_area);
g.DrawString (grid.CaptionText, grid.CaptionFont,
ThemeEngine.Current.ResPool.GetSolidBrush (grid.CaptionForeColor),
grid.grid_drawing.caption_area);
}
public override void DataGridPaintColumnsHdrs (Graphics g, Rectangle clip, DataGrid grid)
{
Rectangle columns_area = grid.grid_drawing.columnshdrs_area;
if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header
Rectangle rect_bloc = grid.grid_drawing.columnshdrs_area;
rect_bloc.Width = grid.RowHeaderWidth;
rect_bloc.Height = grid.grid_drawing.columnshdrs_area.Height;
if (clip.IntersectsWith (rect_bloc)) {
if (grid.visiblecolumn_count > 0) {
g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
}else {
g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), rect_bloc);
}
}
columns_area.X += grid.RowHeaderWidth;
columns_area.Width -= grid.RowHeaderWidth;
}
// Set unused area
Rectangle columnshdrs_area_complete = columns_area;
columnshdrs_area_complete.Width = grid.grid_drawing.columnshdrs_maxwidth;
if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
columnshdrs_area_complete.Width -= grid.RowHeaderWidth;
}
// Set column painting
Rectangle rect_columnhdr = new Rectangle ();
int col_pixel;
Region current_clip;
rect_columnhdr.Y = columns_area.Y;
rect_columnhdr.Height = columns_area.Height;
current_clip = new Region (columns_area);
g.Clip = current_clip;
int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
rect_columnhdr.X = columns_area.X + col_pixel - grid.horz_pixeloffset;
rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
if (clip.IntersectsWith (rect_columnhdr) == false)
continue;
grid.CurrentTableStyle.GridColumnStyles[column].PaintHeader (g, rect_columnhdr, column);
}
current_clip.Dispose ();
g.ResetClip ();
// This fills with background colour the unused part in the row headers
if (rect_columnhdr.X + rect_columnhdr.Height < grid.ClientRectangle.X + grid.ClientRectangle.Width) {
Rectangle not_usedarea = columnshdrs_area_complete;
not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;
g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
not_usedarea);
}
}
public override void DataGridPaintRowsHeaders (Graphics g, Rectangle clip, DataGrid grid)
{
Rectangle rowshdrs_area_complete = grid.grid_drawing.rowshdrs_area;
rowshdrs_area_complete.Height = grid.grid_drawing.rowshdrs_maxheight;
Rectangle rect_row = new Rectangle ();
rect_row.X = grid.grid_drawing.rowshdrs_area.X;
int last_y = 0;
int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
rowcnt++;