FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
flashdevelop/PluginCore/TabControl/CustomTabControl.cs at patch-1 · SandersAlex/flashdevelop · GitHub
SandersAlex
flashdevelop
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
flashdevelop
/
PluginCore
/
TabControl
/
CustomTabControl.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
1397 lines (1199 loc) · 43.6 KB
Breadcrumbs
flashdevelop
/
PluginCore
/
TabControl
/
CustomTabControl.cs
Copy path
File metadata and controls
1397 lines (1199 loc) · 43.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* This code is provided under the Code Project Open Licence (CPOL)
* See http://www.codeproject.com/info/cpol10.aspx for details
*/
using
System
.
Collections
.
Generic
;
using
System
.
ComponentModel
;
using
System
.
Drawing
;
using
System
.
Drawing
.
Drawing2D
;
using
System
.
Drawing
.
Imaging
;
using
System
.
Security
.
Permissions
;
namespace
System
.
Windows
.
Forms
{
[
ToolboxBitmapAttribute
(
typeof
(
TabControl
)
)
]
public
class
CustomTabControl
:
TabControl
{
#region Construction
public
CustomTabControl
(
)
{
this
.
SetStyle
(
ControlStyles
.
UserPaint
|
ControlStyles
.
AllPaintingInWmPaint
|
ControlStyles
.
Opaque
|
ControlStyles
.
ResizeRedraw
,
true
)
;
this
.
_BackBuffer
=
new
Bitmap
(
this
.
Width
,
this
.
Height
)
;
this
.
_BackBufferGraphics
=
Graphics
.
FromImage
(
this
.
_BackBuffer
)
;
this
.
_TabBuffer
=
new
Bitmap
(
this
.
Width
,
this
.
Height
)
;
this
.
_TabBufferGraphics
=
Graphics
.
FromImage
(
this
.
_TabBuffer
)
;
this
.
DisplayStyle
=
TabStyle
.
Default
;
}
protected
override
void
OnCreateControl
(
)
{
base
.
OnCreateControl
(
)
;
this
.
OnFontChanged
(
EventArgs
.
Empty
)
;
}
protected
override
CreateParams
CreateParams
{
[
SecurityPermission
(
SecurityAction
.
LinkDemand
,
Flags
=
SecurityPermissionFlag
.
UnmanagedCode
)
]
get
{
CreateParams
cp
=
base
.
CreateParams
;
if
(
this
.
RightToLeftLayout
)
cp
.
ExStyle
=
cp
.
ExStyle
|
NativeMethods
.
WS_EX_LAYOUTRTL
|
NativeMethods
.
WS_EX_NOINHERITLAYOUT
;
return
cp
;
}
}
protected
override
void
Dispose
(
bool
disposing
)
{
base
.
Dispose
(
disposing
)
;
if
(
disposing
)
{
if
(
this
.
_BackImage
!=
null
)
{
this
.
_BackImage
.
Dispose
(
)
;
}
if
(
this
.
_BackBufferGraphics
!=
null
)
{
this
.
_BackBufferGraphics
.
Dispose
(
)
;
}
if
(
this
.
_BackBuffer
!=
null
)
{
this
.
_BackBuffer
.
Dispose
(
)
;
}
if
(
this
.
_TabBufferGraphics
!=
null
)
{
this
.
_TabBufferGraphics
.
Dispose
(
)
;
}
if
(
this
.
_TabBuffer
!=
null
)
{
this
.
_TabBuffer
.
Dispose
(
)
;
}
if
(
this
.
_StyleProvider
!=
null
)
{
this
.
_StyleProvider
.
Dispose
(
)
;
}
}
}
#endregion
#region Private variables
private
Bitmap
_BackImage
;
private
Bitmap
_BackBuffer
;
private
Graphics
_BackBufferGraphics
;
private
Bitmap
_TabBuffer
;
private
Graphics
_TabBufferGraphics
;
private
int
_oldValue
;
private
Point
_dragStartPosition
=
Point
.
Empty
;
private
TabStyle
_Style
;
private
TabStyleProvider
_StyleProvider
;
private
List
<
TabPage
>
_TabPages
;
#endregion
#region Public properties
[
Category
(
"Appearance"
)
,
DesignerSerializationVisibility
(
DesignerSerializationVisibility
.
Content
)
]
public
TabStyleProvider
DisplayStyleProvider
{
get
{
if
(
this
.
_StyleProvider
==
null
)
{
this
.
DisplayStyle
=
TabStyle
.
Default
;
}
return
this
.
_StyleProvider
;
}
set
{
this
.
_StyleProvider
=
value
;
}
}
[
Category
(
"Appearance"
)
,
DefaultValue
(
typeof
(
TabStyle
)
,
"Default"
)
,
RefreshProperties
(
RefreshProperties
.
All
)
]
public
TabStyle
DisplayStyle
{
get
{
return
this
.
_Style
;
}
set
{
if
(
this
.
_Style
!=
value
)
{
this
.
_Style
=
value
;
this
.
_StyleProvider
=
TabStyleProvider
.
CreateProvider
(
this
)
;
this
.
Invalidate
(
)
;
}
}
}
[
Category
(
"Appearance"
)
,
RefreshProperties
(
RefreshProperties
.
All
)
]
public
new
bool
Multiline
{
get
{
return
base
.
Multiline
;
}
set
{
base
.
Multiline
=
value
;
this
.
Invalidate
(
)
;
}
}
// Hide the Padding attribute so it can not be changed
// We are handling this on the Style Provider
[
Browsable
(
false
)
,
EditorBrowsable
(
EditorBrowsableState
.
Never
)
]
public
new
Point
Padding
{
get
{
return
this
.
DisplayStyleProvider
.
Padding
;
}
set
{
this
.
DisplayStyleProvider
.
Padding
=
value
;
}
}
public
override
bool
RightToLeftLayout
{
get
{
return
base
.
RightToLeftLayout
;
}
set
{
base
.
RightToLeftLayout
=
value
;
this
.
UpdateStyles
(
)
;
}
}
// Hide the HotTrack attribute so it can not be changed
// We are handling this on the Style Provider
[
Browsable
(
false
)
,
EditorBrowsable
(
EditorBrowsableState
.
Never
)
]
public
new
bool
HotTrack
{
get
{
return
this
.
DisplayStyleProvider
.
HotTrack
;
}
set
{
this
.
DisplayStyleProvider
.
HotTrack
=
value
;
}
}
[
Category
(
"Appearance"
)
]
public
new
TabAlignment
Alignment
{
get
{
return
base
.
Alignment
;
}
set
{
base
.
Alignment
=
value
;
switch
(
value
)
{
case
TabAlignment
.
Top
:
case
TabAlignment
.
Bottom
:
this
.
Multiline
=
false
;
break
;
case
TabAlignment
.
Left
:
case
TabAlignment
.
Right
:
this
.
Multiline
=
true
;
break
;
}
}
}
// Hide the Appearance attribute so it can not be changed
// We don't want it as we are doing all the painting.
[
Browsable
(
false
)
,
EditorBrowsable
(
EditorBrowsableState
.
Never
)
]
[
System
.
Diagnostics
.
CodeAnalysis
.
SuppressMessage
(
"Microsoft.Usage"
,
"CA1801:ReviewUnusedParameters"
,
MessageId
=
"value"
)
]
public
new
TabAppearance
Appearance
{
get
{
return
base
.
Appearance
;
}
set
{
// Don't permit setting to other appearances as we are doing all the painting
base
.
Appearance
=
TabAppearance
.
Normal
;
}
}
public
override
Rectangle
DisplayRectangle
{
get
{
// Special processing to hide tabs
if
(
this
.
_Style
==
TabStyle
.
None
)
{
return
new
Rectangle
(
0
,
0
,
Width
,
Height
)
;
}
else
{
int
tabStripHeight
=
0
;
int
itemHeight
=
0
;
if
(
this
.
Alignment
<=
TabAlignment
.
Bottom
)
{
itemHeight
=
this
.
ItemSize
.
Height
;
}
else
{
itemHeight
=
this
.
ItemSize
.
Width
;
}
tabStripHeight
=
5
+
(
itemHeight
*
this
.
RowCount
)
;
Rectangle
rect
=
new
Rectangle
(
4
,
tabStripHeight
,
Width
-
8
,
Height
-
tabStripHeight
-
4
)
;
switch
(
this
.
Alignment
)
{
case
TabAlignment
.
Top
:
rect
=
new
Rectangle
(
4
,
tabStripHeight
,
Width
-
8
,
Height
-
tabStripHeight
-
4
)
;
break
;
case
TabAlignment
.
Bottom
:
rect
=
new
Rectangle
(
4
,
4
,
Width
-
8
,
Height
-
tabStripHeight
-
4
)
;
break
;
case
TabAlignment
.
Left
:
rect
=
new
Rectangle
(
tabStripHeight
,
4
,
Width
-
tabStripHeight
-
4
,
Height
-
8
)
;
break
;
case
TabAlignment
.
Right
:
rect
=
new
Rectangle
(
4
,
4
,
Width
-
tabStripHeight
-
4
,
Height
-
8
)
;
break
;
}
return
rect
;
}
}
}
[
Browsable
(
false
)
]
public
int
ActiveIndex
{
get
{
NativeMethods
.
TCHITTESTINFO
hitTestInfo
=
new
NativeMethods
.
TCHITTESTINFO
(
this
.
PointToClient
(
Control
.
MousePosition
)
)
;
int
index
=
NativeMethods
.
SendMessage
(
this
.
Handle
,
NativeMethods
.
TCM_HITTEST
,
IntPtr
.
Zero
,
NativeMethods
.
ToIntPtr
(
hitTestInfo
)
)
.
ToInt32
(
)
;
if
(
index
==
-
1
)
{
return
-
1
;
}
else
{
if
(
this
.
TabPages
[
index
]
.
Enabled
)
{
return
index
;
}
else
{
return
-
1
;
}
}
}
}
[
Browsable
(
false
)
]
public
TabPage
ActiveTab
{
get
{
int
activeIndex
=
this
.
ActiveIndex
;
if
(
activeIndex
>
-
1
)
{
return
this
.
TabPages
[
activeIndex
]
;
}
else
{
return
null
;
}
}
}
#endregion
#region Extension methods
public
void
HideTab
(
TabPage
page
)
{
if
(
page
!=
null
&&
this
.
TabPages
.
Contains
(
page
)
)
{
this
.
BackupTabPages
(
)
;
this
.
TabPages
.
Remove
(
page
)
;
}
}
public
void
HideTab
(
int
index
)
{
if
(
this
.
IsValidTabIndex
(
index
)
)
{
this
.
HideTab
(
this
.
_TabPages
[
index
]
)
;
}
}
public
void
HideTab
(
string
key
)
{
if
(
this
.
TabPages
.
ContainsKey
(
key
)
)
{
this
.
HideTab
(
this
.
TabPages
[
key
]
)
;
}
}
public
void
ShowTab
(
TabPage
page
)
{
if
(
page
!=
null
)
{
if
(
this
.
_TabPages
!=
null
)
{
if
(
!
this
.
TabPages
.
Contains
(
page
)
&&
this
.
_TabPages
.
Contains
(
page
)
)
{
// Get insert point from backup of pages
int
pageIndex
=
this
.
_TabPages
.
IndexOf
(
page
)
;
if
(
pageIndex
>
0
)
{
int
start
=
pageIndex
-
1
;
// Check for presence of earlier pages in the visible tabs
for
(
int
index
=
start
;
index
>=
0
;
index
--
)
{
if
(
this
.
TabPages
.
Contains
(
this
.
_TabPages
[
index
]
)
)
{
// Set insert point to the right of the last present tab
pageIndex
=
this
.
TabPages
.
IndexOf
(
this
.
_TabPages
[
index
]
)
+
1
;
break
;
}
}
}
// Insert the page, or add to the end
if
(
(
pageIndex
>=
0
)
&&
(
pageIndex
<
this
.
TabPages
.
Count
)
)
{
this
.
TabPages
.
Insert
(
pageIndex
,
page
)
;
}
else
{
this
.
TabPages
.
Add
(
page
)
;
}
}
}
else
{
// If the page is not found at all then just add it
if
(
!
this
.
TabPages
.
Contains
(
page
)
)
{
this
.
TabPages
.
Add
(
page
)
;
}
}
}
}
public
void
ShowTab
(
int
index
)
{
if
(
this
.
IsValidTabIndex
(
index
)
)
{
this
.
ShowTab
(
this
.
_TabPages
[
index
]
)
;
}
}
public
void
ShowTab
(
string
key
)
{
if
(
this
.
_TabPages
!=
null
)
{
TabPage
tab
=
this
.
_TabPages
.
Find
(
delegate
(
TabPage
page
)
{
return
page
.
Name
.
Equals
(
key
,
StringComparison
.
OrdinalIgnoreCase
)
;
}
)
;
this
.
ShowTab
(
tab
)
;
}
}
private
bool
IsValidTabIndex
(
int
index
)
{
this
.
BackupTabPages
(
)
;
return
(
(
index
>=
0
)
&&
(
index
<
this
.
_TabPages
.
Count
)
)
;
}
private
void
BackupTabPages
(
)
{
if
(
this
.
_TabPages
==
null
)
{
this
.
_TabPages
=
new
List
<
TabPage
>
(
)
;
foreach
(
TabPage
page
in
this
.
TabPages
)
{
this
.
_TabPages
.
Add
(
page
)
;
}
}
}
#endregion
#region Drag 'n' Drop
protected
override
void
OnMouseDown
(
MouseEventArgs
e
)
{
base
.
OnMouseDown
(
e
)
;
if
(
this
.
AllowDrop
)
{
this
.
_dragStartPosition
=
new
Point
(
e
.
X
,
e
.
Y
)
;
}
}
protected
override
void
OnMouseUp
(
MouseEventArgs
e
)
{
base
.
OnMouseUp
(
e
)
;
if
(
this
.
AllowDrop
)
{
this
.
_dragStartPosition
=
Point
.
Empty
;
}
}
protected
override
void
OnDragOver
(
DragEventArgs
drgevent
)
{
base
.
OnDragOver
(
drgevent
)
;
if
(
drgevent
.
Data
.
GetDataPresent
(
typeof
(
TabPage
)
)
)
{
drgevent
.
Effect
=
DragDropEffects
.
Move
;
}
else
{
drgevent
.
Effect
=
DragDropEffects
.
None
;
}
}
protected
override
void
OnDragDrop
(
DragEventArgs
drgevent
)
{
base
.
OnDragDrop
(
drgevent
)
;
if
(
drgevent
.
Data
.
GetDataPresent
(
typeof
(
TabPage
)
)
)
{
drgevent
.
Effect
=
DragDropEffects
.
Move
;
TabPage
dragTab
=
(
TabPage
)
drgevent
.
Data
.
GetData
(
typeof
(
TabPage
)
)
;
if
(
this
.
ActiveTab
==
dragTab
)
{
return
;
}
// Capture insert point and adjust for removal of tab
// We cannot assess this after removal as differeing tab sizes will cause
// inaccuracies in the activeTab at insert point.
int
insertPoint
=
this
.
ActiveIndex
;
if
(
dragTab
.
Parent
.
Equals
(
this
)
&&
this
.
TabPages
.
IndexOf
(
dragTab
)
<
insertPoint
)
{
insertPoint
--
;
}
if
(
insertPoint
<
0
)
{
insertPoint
=
0
;
}
// Remove from current position (could be another tabcontrol)
(
(
TabControl
)
dragTab
.
Parent
)
.
TabPages
.
Remove
(
dragTab
)
;
// Add to current position
this
.
TabPages
.
Insert
(
insertPoint
,
dragTab
)
;
this
.
SelectedTab
=
dragTab
;
// deal with hidden tab handling?
}
}
private
void
StartDragDrop
(
)
{
if
(
!
this
.
_dragStartPosition
.
IsEmpty
)
{
TabPage
dragTab
=
this
.
SelectedTab
;
if
(
dragTab
!=
null
)
{
// Test for movement greater than the drag activation trigger area
Rectangle
dragTestRect
=
new
Rectangle
(
this
.
_dragStartPosition
,
Size
.
Empty
)
;
dragTestRect
.
Inflate
(
SystemInformation
.
DragSize
)
;
Point
pt
=
this
.
PointToClient
(
Control
.
MousePosition
)
;
if
(
!
dragTestRect
.
Contains
(
pt
)
)
{
this
.
DoDragDrop
(
dragTab
,
DragDropEffects
.
All
)
;
this
.
_dragStartPosition
=
Point
.
Empty
;
}
}
}
}
#endregion
#region Events
[
Category
(
"Action"
)
]
public
event
ScrollEventHandler
HScroll
;
[
Category
(
"Action"
)
]
public
event
EventHandler
<
TabControlEventArgs
>
TabImageClick
;
[
Category
(
"Action"
)
]
public
event
EventHandler
<
TabControlCancelEventArgs
>
TabClosing
;
#endregion
#region Base class event processing
protected
override
void
OnFontChanged
(
EventArgs
e
)
{
IntPtr
hFont
=
this
.
Font
.
ToHfont
(
)
;
NativeMethods
.
SendMessage
(
this
.
Handle
,
NativeMethods
.
WM_SETFONT
,
hFont
,
(
IntPtr
)
(
-
1
)
)
;
NativeMethods
.
SendMessage
(
this
.
Handle
,
NativeMethods
.
WM_FONTCHANGE
,
IntPtr
.
Zero
,
IntPtr
.
Zero
)
;
this
.
UpdateStyles
(
)
;
if
(
this
.
Visible
)
{
this
.
Invalidate
(
)
;
}
}
protected
override
void
OnResize
(
EventArgs
e
)
{
// Recreate the buffer for manual double buffering
if
(
this
.
Width
>
0
&&
this
.
Height
>
0
)
{
if
(
this
.
_BackImage
!=
null
)
{
this
.
_BackImage
.
Dispose
(
)
;
this
.
_BackImage
=
null
;
}
if
(
this
.
_BackBufferGraphics
!=
null
)
{
this
.
_BackBufferGraphics
.
Dispose
(
)
;
}
if
(
this
.
_BackBuffer
!=
null
)
{
this
.
_BackBuffer
.
Dispose
(
)
;
}
this
.
_BackBuffer
=
new
Bitmap
(
this
.
Width
,
this
.
Height
)
;
this
.
_BackBufferGraphics
=
Graphics
.
FromImage
(
this
.
_BackBuffer
)
;
if
(
this
.
_TabBufferGraphics
!=
null
)
{
this
.
_TabBufferGraphics
.
Dispose
(
)
;
}
if
(
this
.
_TabBuffer
!=
null
)
{
this
.
_TabBuffer
.
Dispose
(
)
;
}
this
.
_TabBuffer
=
new
Bitmap
(
this
.
Width
,
this
.
Height
)
;
this
.
_TabBufferGraphics
=
Graphics
.
FromImage
(
this
.
_TabBuffer
)
;
if
(
this
.
_BackImage
!=
null
)
{
this
.
_BackImage
.
Dispose
(
)
;
this
.
_BackImage
=
null
;
}
}
base
.
OnResize
(
e
)
;
}
protected
override
void
OnParentBackColorChanged
(
EventArgs
e
)
{
if
(
this
.
_BackImage
!=
null
)
{
this
.
_BackImage
.
Dispose
(
)
;
this
.
_BackImage
=
null
;
}
base
.
OnParentBackColorChanged
(
e
)
;
}
protected
override
void
OnParentBackgroundImageChanged
(
EventArgs
e
)
{
if
(
this
.
_BackImage
!=
null
)
{
this
.
_BackImage
.
Dispose
(
)
;
this
.
_BackImage
=
null
;
}
base
.
OnParentBackgroundImageChanged
(
e
)
;
}
private
void
OnParentResize
(
object
sender
,
EventArgs
e
)
{
if
(
this
.
Visible
)
{
this
.
Invalidate
(
)
;
}
}
protected
override
void
OnParentChanged
(
EventArgs
e
)
{
base
.
OnParentChanged
(
e
)
;
if
(
this
.
Parent
!=
null
)
{
this
.
Parent
.
Resize
+=
this
.
OnParentResize
;
}
}
protected
override
void
OnSelecting
(
TabControlCancelEventArgs
e
)
{
base
.
OnSelecting
(
e
)
;
// Do not allow selecting of disabled tabs
if
(
e
.
Action
==
TabControlAction
.
Selecting
&&
e
.
TabPage
!=
null
&&
!
e
.
TabPage
.
Enabled
)
{
e
.
Cancel
=
true
;
}
}
protected
override
void
OnMove
(
EventArgs
e
)
{
if
(
this
.
Width
>
0
&&
this
.
Height
>
0
)
{
if
(
this
.
_BackImage
!=
null
)
{
this
.
_BackImage
.
Dispose
(
)
;
this
.
_BackImage
=
null
;
}
}
base
.
OnMove
(
e
)
;
this
.
Invalidate
(
)
;
}
protected
override
void
OnControlAdded
(
ControlEventArgs
e
)
{
base
.
OnControlAdded
(
e
)
;
if
(
this
.
Visible
)
{
this
.
Invalidate
(
)
;
}
}
protected
override
void
OnControlRemoved
(
ControlEventArgs
e
)
{
base
.
OnControlRemoved
(
e
)
;
if
(
this
.
Visible
)
{
this
.
Invalidate
(
)
;
}
}
[
UIPermission
(
SecurityAction
.
LinkDemand
,
Window
=
UIPermissionWindow
.
AllWindows
)
]
protected
override
bool
ProcessMnemonic
(
char
charCode
)
{
foreach
(
TabPage
page
in
this
.
TabPages
)
{
if
(
IsMnemonic
(
charCode
,
page
.
Text
)
)
{
this
.
SelectedTab
=
page
;
return
true
;
}
}
return
base
.
ProcessMnemonic
(
charCode
)
;
}
protected
override
void
OnSelectedIndexChanged
(
EventArgs
e
)
{
base
.
OnSelectedIndexChanged
(
e
)
;
}
[
SecurityPermission
(
SecurityAction
.
LinkDemand
,
Flags
=
SecurityPermissionFlag
.
UnmanagedCode
)
]
[
System
.
Diagnostics
.
DebuggerStepThrough
(
)
]
protected
override
void
WndProc
(
ref
Message
m
)
{
switch
(
m
.
Msg
)
{
case
NativeMethods
.
WM_HSCROLL
:
// Raise the scroll event when the scroller is scrolled
base
.
WndProc
(
ref
m
)
;
this
.
OnHScroll
(
new
ScrollEventArgs
(
(
(
ScrollEventType
)
NativeMethods
.
LoWord
(
m
.
WParam
)
)
,
_oldValue
,
NativeMethods
.
HiWord
(
m
.
WParam
)
,
ScrollOrientation
.
HorizontalScroll
)
)
;
break
;
// case NativeMethods.WM_PAINT:
//
// // Handle painting ourselves rather than call the base OnPaint.
// CustomPaint(ref m);
// break;
default
:
base
.
WndProc
(
ref
m
)
;
break
;
}
}
protected
override
void
OnMouseClick
(
MouseEventArgs
e
)
{
int
index
=
this
.
ActiveIndex
;
// If we are clicking on an image then raise the ImageClicked event before raising the standard mouse click event
// if there if a handler.
if
(
index
>
-
1
&&
this
.
TabImageClick
!=
null
&&
(
this
.
TabPages
[
index
]
.
ImageIndex
>
-
1
||
!
string
.
IsNullOrEmpty
(
this
.
TabPages
[
index
]
.
ImageKey
)
)
&&
this
.
GetTabImageRect
(
index
)
.
Contains
(
this
.
MousePosition
)
)
{
this
.
OnTabImageClick
(
new
TabControlEventArgs
(
this
.
TabPages
[
index
]
,
index
,
TabControlAction
.
Selected
)
)
;
// Fire the base event
base
.
OnMouseClick
(
e
)
;
}
else
if
(
!
this
.
DesignMode
&&
index
>
-
1
&&
this
.
_StyleProvider
.
ShowTabCloser
&&
this
.
GetTabCloserRect
(
index
)
.
Contains
(
this
.
MousePosition
)
)
{
// If we are clicking on a closer then remove the tab instead of raising the standard mouse click event
// But raise the tab closing event first
TabPage
tab
=
this
.
ActiveTab
;
TabControlCancelEventArgs
args
=
new
TabControlCancelEventArgs
(
tab
,
index
,
false
,
TabControlAction
.
Deselecting
)
;
this
.
OnTabClosing
(
args
)
;
if
(
!
args
.
Cancel
)
{
this
.
TabPages
.
Remove
(
tab
)
;
tab
.
Dispose
(
)
;
}
}
else
{
// Fire the base event
base
.
OnMouseClick
(
e
)
;
}
}
protected
virtual
void
OnTabImageClick
(
TabControlEventArgs
e
)
{
if
(
this
.
TabImageClick
!=
null
)
{
this
.
TabImageClick
(
this
,
e
)
;
}
}
protected
virtual
void
OnTabClosing
(
TabControlCancelEventArgs
e
)
{
if
(
this
.
TabClosing
!=
null
)
{
this
.
TabClosing
(
this
,
e
)
;
}
}
protected
virtual
void
OnHScroll
(
ScrollEventArgs
e
)
{
// repaint the moved tabs
this
.
Invalidate
(
)
;
// Raise the event
if
(
this
.
HScroll
!=
null
)
{
this
.
HScroll
(
this
,
e
)
;
}
if
(
e
.
Type
==
ScrollEventType
.
EndScroll
)
{
this
.
_oldValue
=
e
.
NewValue
;
}
}
protected
override
void
OnMouseMove
(
MouseEventArgs
e
)
{
base
.
OnMouseMove
(
e
)
;
if
(
this
.
_StyleProvider
.
ShowTabCloser
)
{
Rectangle
tabRect
=
this
.
_StyleProvider
.
GetTabRect
(
this
.
ActiveIndex
)
;
if
(
tabRect
.
Contains
(
this
.
MousePosition
)
)
{
this
.
Invalidate
(
)
;
}
}
// Initialise Drag Drop
if
(
this
.
AllowDrop
&&
e
.
Button
==
MouseButtons
.
Left
)
{
this
.
StartDragDrop
(
)
;
}
}
#endregion
#region Basic drawing methods
// private void CustomPaint(ref Message m){
// NativeMethods.PAINTSTRUCT paintStruct = new NativeMethods.PAINTSTRUCT();
// NativeMethods.BeginPaint(m.HWnd, ref paintStruct);
// using (Graphics screenGraphics = this.CreateGraphics()) {
// this.CustomPaint(screenGraphics);
// }
// NativeMethods.EndPaint(m.HWnd, ref paintStruct);
// }
/*protected override void OnPaint(PaintEventArgs e){
// We must always paint the entire area of the tab control
if (e.ClipRectangle.Equals(this.ClientRectangle)){
this.CustomPaint(e.Graphics);
} else {
// it is less intensive to just reinvoke the paint with the whole surface available to draw on.
this.Invalidate();
}
}*/
// HACK: Modded
private
bool
_painting
=
false
;
protected
override
void
OnPaint
(
PaintEventArgs
e
)
{
// We must always paint the entire area of the tab control
if
(
e
.
ClipRectangle
.
Equals
(
this
.
ClientRectangle
)
||
_painting
)
{
_painting
=
false
;
this
.
CustomPaint
(
e
.
Graphics
)
;
}
else
{
// it is less intensive to just reinvoke the paint with the whole surface available to draw on.
_painting
=
true
;
this
.
Invalidate
(
)
;
}
}
private
void
CustomPaint
(
Graphics
screenGraphics
)
{
// We render into a bitmap that is then drawn in one shot rather than using
// double buffering built into the control as the built in buffering
// messes up the background painting.
// Equally the .Net 2.0 BufferedGraphics object causes the background painting
// to mess up, which is why we use this .Net 1.1 buffering technique.
// Buffer code from Gil. Schmidt http://www.codeproject.com/KB/graphics/DoubleBuffering.aspx
if
(
this
.
Width
>
0
&&
this
.
Height
>
0
)
{
if
(
this
.
_BackImage
==
null
)
{
// Cached Background Image
this
.
_BackImage
=
new
Bitmap
(
this
.
Width
,
this
.
Height
)
;
Graphics
backGraphics
=
Graphics
.
FromImage
(
this
.
_BackImage
)
;
backGraphics
.
Clear
(
Color
.
Transparent
)
;
this
.
PaintTransparentBackground
(
backGraphics
,
this
.
ClientRectangle
)
;
}
this
.
_BackBufferGraphics
.
Clear
(
Color
.
Transparent
)
;
this
.
_BackBufferGraphics
.
DrawImageUnscaled
(
this
.
_BackImage
,
0
,
0
)
;
this
.
_TabBufferGraphics
.
Clear
(
Color
.
Transparent
)
;
if
(
this
.
TabCount
>
0
)
{
// When top or bottom and scrollable we need to clip the sides from painting the tabs.
// Left and right are always multiline.
if
(
this
.
Alignment
<=
TabAlignment
.
Bottom
&&
!
this
.
Multiline
)
{
this
.
_TabBufferGraphics
.
Clip
=
new
Region
(
new
RectangleF
(
this
.
ClientRectangle
.
X
+
3
,
this
.
ClientRectangle
.
Y
,
this
.
ClientRectangle
.
Width
-
6
,
this
.
ClientRectangle
.
Height
)
)
;
}
// Draw each tabpage from right to left. We do it this way to handle
// the overlap correctly.
if
(
this
.
Multiline
)
{
for
(
int
row
=
0
;
row
<
this
.
RowCount
;
row
++
)
{
for
(
int
index
=
this
.
TabCount
-
1
;
index
>=
0
;
index
--
)
{
if
(
index
!=
this
.
SelectedIndex
&&
(
this
.
RowCount
==
1
||
this
.
GetTabRow
(
index
)
==
row
)
)
{
this
.
DrawTabPage
(
index
,
this
.
_TabBufferGraphics
)
;
}
}
}
}
else
{
for
(
int
index
=
this
.
TabCount
-
1
;
index
>=
0
;
index
--
)
{
if
(
index
!=
this
.
SelectedIndex
)
{
this
.
DrawTabPage
(
index
,
this
.
_TabBufferGraphics
)
;
}
}
}
// The selected tab must be drawn last so it appears on top.
if
(
this
.
SelectedIndex
>
-
1
)
{
this
.
DrawTabPage
(
this
.
SelectedIndex
,
this
.
_TabBufferGraphics
)
;
}
}
this
.
_TabBufferGraphics
.
Flush
(
)
;
// Paint the tabs on top of the background
// Create a new color matrix and set the alpha value to 0.5
ColorMatrix
alphaMatrix
=
new
ColorMatrix
(
)
;
alphaMatrix
.
Matrix00
=
alphaMatrix
.
Matrix11
=
alphaMatrix
.
Matrix22
=
alphaMatrix
.
Matrix44
=
1
;
alphaMatrix
.
Matrix33
=
this
.
_StyleProvider
.
Opacity
;
// Create a new image attribute object and set the color matrix to
// the one just created
using
(
ImageAttributes
alphaAttributes
=
new
ImageAttributes
(
)
)
{
alphaAttributes
.
SetColorMatrix
(
alphaMatrix
)
;
// Draw the original image with the image attributes specified
this
.
_BackBufferGraphics
.
DrawImage
(
this
.
_TabBuffer
,
new
Rectangle
(
0
,
0
,
this
.
_TabBuffer
.
Width
,
this
.
_TabBuffer
.
Height
)
,
0
,
0
,
this
.
_TabBuffer
.
Width
,
this
.
_TabBuffer
.
Height
,
GraphicsUnit
.
Pixel
,
alphaAttributes
)
;
}
this
.
_BackBufferGraphics
.
Flush
(
)
;
// Now paint this to the screen
// We want to paint the whole tabstrip and border every time
// so that the hot areas update correctly, along with any overlaps
// paint the tabs etc.
if
(
this
.
RightToLeftLayout
)
{
screenGraphics
.
DrawImageUnscaled
(
this
.
_BackBuffer
,
-
1
,
0
)
;
}
else
{
screenGraphics
.
DrawImageUnscaled
(
this
.
_BackBuffer
,
0
,
0
)
;
}
}
}
protected
void
PaintTransparentBackground
(
Graphics
graphics
,
Rectangle
clipRect
)
{
if
(
(
this
.
Parent
!=
null
)
)
{
// Set the cliprect to be relative to the parent
clipRect
.
Offset
(
this
.
Location
)
;
// Save the current state before we do anything.
GraphicsState
state
=
graphics
.
Save
(
)
;
// Set the graphicsobject to be relative to the parent
graphics
.
TranslateTransform
(
(
float
)
-
this
.
Location
.
X
,
(
float
)
-
this
.
Location
.
Y
)
;
graphics
.
SmoothingMode
=
SmoothingMode
.
HighSpeed
;
// Paint the parent
PaintEventArgs
e
=
new
PaintEventArgs
(
graphics
,
clipRect
)
;
try
{
this
.
InvokePaintBackground
(
this
.
Parent
,
e
)
;
this
.
InvokePaint
(
this
.
Parent
,
e
)
;
}
finally
{
// Restore the graphics state and the clipRect to their original locations
graphics
.
Restore
(
state
)
;
clipRect
.
Offset
(
-
this
.
Location
.
X
,
-
this
.
Location
.
Y
)
;
}
}
}
private
void
DrawTabPage
(
int
index
,
Graphics
graphics
)
{
graphics
.
SmoothingMode
=
SmoothingMode
.
HighSpeed
;
// Get TabPageBorder
using
(
GraphicsPath
tabPageBorderPath
=
this
.
GetTabPageBorder
(
index
)
)
{
// Paint the background
using
(
Brush
fillBrush
=
this
.
_StyleProvider
.
GetPageBackgroundBrush
(
index
)
)
{
graphics
.
FillPath
(
fillBrush
,
tabPageBorderPath
)
;
}
if
(
this
.
_Style
!=
TabStyle
.
None
)
{
// Paint the tab
this
.
_StyleProvider
.
PaintTab
(
index
,
graphics
)
;
// Draw any image
this
.
DrawTabImage
(
index
,
graphics
)
;
// Draw the text
this
.
DrawTabText
(
index
,
graphics
)
;
}
// Paint the border
this
.
DrawTabBorder
(
tabPageBorderPath
,
index
,
graphics
)
;
}
}
private
void
DrawTabBorder
(
GraphicsPath
path
,
int
index
,
Graphics
graphics
)
{
graphics
.
SmoothingMode
=
SmoothingMode
.
HighQuality
;
Color
borderColor
;
if
(
index
==
this
.
SelectedIndex
)
{
borderColor
=
this
.
_StyleProvider
.
BorderColorSelected
;
}
else
if
(
this
.
_StyleProvider
.
HotTrack
&&
index
==
this
.
ActiveIndex
)
{
borderColor
=
this
.
_StyleProvider
.
BorderColorHot
;
}
else
{
borderColor
=
this
.
_StyleProvider
.
BorderColor
;
}
using
(
Pen
borderPen
=
new
Pen
(
borderColor
)
)
{
graphics
.
DrawPath
(
borderPen
,
path
)
;
}
}
private
void
DrawTabText
(
int
index
,
Graphics
graphics
)
{
graphics
.
SmoothingMode
=
SmoothingMode
.
HighQuality
;
graphics
.
TextRenderingHint
=
System
.
Drawing
.
Text
.
TextRenderingHint
.
ClearTypeGridFit
;
Rectangle
tabBounds
=
this
.
GetTabTextRect
(
index
)
;
if
(
this
.
SelectedIndex
==
index
)
{
using
(
Brush
textBrush
=
new
SolidBrush
(
this
.
_StyleProvider
.
TextColorSelected
)
)
{
graphics
.
DrawString
(
this
.
TabPages
[
index
]
.
Text
,
this
.
Font
,
textBrush
,
tabBounds
,
this
.
GetStringFormat
(
)
)
;
}
}
else
{
if
(
this
.
TabPages
[
index
]
.
Enabled
)
{
using
(
Brush
textBrush
=
new
SolidBrush
(
this
.
_StyleProvider
.
TextColor
)
)
{
graphics
.
DrawString
(
this
.
TabPages
[
index
]
.
Text
,
this
.
Font
,
textBrush
,
tabBounds
,
this
.
GetStringFormat
(
)
)
;
}
}
else
{
using
(
Brush
textBrush
=
new
SolidBrush
(
this
.
_StyleProvider
.
TextColorDisabled
)
)
{
graphics
.
DrawString
(
this
.
TabPages
[
index
]
.
Text
,
this
.
Font
,
textBrush
,
tabBounds
,
this
.
GetStringFormat
(
)
)
;
}
}
}
}
private
void
DrawTabImage
(
int
index
,
Graphics
graphics
)
{
Image
tabImage
=
null
;
if
(
this
.
TabPages
[
index
]
.
ImageIndex
>
-
1
&&
this
.
ImageList
!=
null
&&
this
.
ImageList
.
Images
.
Count
>
this
.
TabPages
[
index
]
.
ImageIndex
)
{
tabImage
=
this
.
ImageList
.
Images
[
this
.
TabPages
[
index
]
.
ImageIndex
]
;
}
else
if
(
(
!
string
.
IsNullOrEmpty
(
this
.
TabPages
[
index
]
.
ImageKey
)
&&
!
this
.
TabPages
[
index
]
.
ImageKey
.
Equals
(
"(none)"
,
StringComparison
.
OrdinalIgnoreCase
)
)
&&
this
.
ImageList
!=
null
&&
this
.
ImageList
.
Images
.
ContainsKey
(
this
.
TabPages
[
index
]
.
ImageKey
)
)
{
tabImage
=
this
.
ImageList
.
Images
[
this
.
TabPages
[
index
]
.
ImageKey
]
;
}
if
(
tabImage
!=
null
)
{
if
(
this
.
RightToLeftLayout
)
{
tabImage
.
RotateFlip
(
RotateFlipType
.
RotateNoneFlipX
)
;
}
Rectangle
imageRect
=
this
.
GetTabImageRect
(
index
)
;
if
(
this
.
TabPages
[
index
]
.
Enabled
)
{
graphics
.
DrawImage
(
tabImage
,
imageRect
)
;
}
else
{
ControlPaint
.
DrawImageDisabled
(
graphics
,
tabImage
,
imageRect
.
X
,
imageRect
.
Y
,
Color
.
Transparent
)
;
}
}
}
#endregion
#region String formatting
private
StringFormat
GetStringFormat
(
)
{
StringFormat
format
=
null
;
// Rotate Text by 90 degrees for left and right tabs
switch
(
this
.
Alignment
)
{
case
TabAlignment
.
Top
:
case
TabAlignment
.
Bottom
:
format
=
new
StringFormat
(
)
;
break
;
case
TabAlignment
.
Left
:
case
TabAlignment
.
Right
:
format
=
new
StringFormat
(
StringFormatFlags
.
DirectionVertical
)
;
break
;
}
format
.
Alignment
=
StringAlignment
.
Center
;
format
.
LineAlignment
=
StringAlignment
.
Center
;
if
(
this
.
FindForm
(
)
!=
null
&&
this
.
FindForm
(
)
.
KeyPreview
)
{
format
.
HotkeyPrefix
=
System
.
Drawing
.
Text
.
HotkeyPrefix
.
Show
;
}
else
{
format
.
HotkeyPrefix
=
System
.
Drawing
.
Text
.
HotkeyPrefix
.
Hide
;
}
if
(
this
.
RightToLeft
==
RightToLeft
.
Yes
)
{
format
.
FormatFlags
=
format
.
FormatFlags
|
StringFormatFlags
.
DirectionRightToLeft
;
}
return
format
;
}
#endregion
#region Tab borders and bounds properties
private
GraphicsPath
GetTabPageBorder
(
int
index
)
{
GraphicsPath
path
=
new
GraphicsPath
(
)
;
Rectangle
pageBounds
=
this
.
GetPageBounds
(
index
)
;
Rectangle
tabBounds
=
this
.
_StyleProvider
.
GetTabRect
(
index
)
;
this
.
_StyleProvider
.
AddTabBorder
(
path
,
tabBounds
)
;
this
.
AddPageBorder
(
path
,
pageBounds
,
tabBounds
)
;
path
.
CloseFigure
(
)
;
return
path
;
}
public
Rectangle
GetPageBounds
(
int
index
)
{
Rectangle
pageBounds
=
this
.
TabPages
[
index
]
.
Bounds
;
pageBounds
.
Width
+=
1
;
pageBounds
.
Height
+=
1
;
pageBounds
.
X
-=
1
;
pageBounds
.
Y
-=
1
;
if
(
pageBounds
.
Bottom
>
this
.
Height
-
4
)
{
pageBounds
.
Height
-=
(
pageBounds
.
Bottom
-
this
.
Height
+
4
)
;
}
return
pageBounds
;
}
private
Rectangle
GetTabTextRect
(
int
index
)
{
Rectangle
textRect
=
new
Rectangle
(
)
;
using
(
GraphicsPath
path
=
this
.
_StyleProvider
.
GetTabBorder
(
index
)
)
{
RectangleF
tabBounds
=
path
.
GetBounds
(
)
;
textRect
=
new
Rectangle
(
(
int
)
tabBounds
.
X
,
(
int
)
tabBounds
.
Y
,
(
int
)
tabBounds
.
Width
,
(
int
)
tabBounds
.
Height
)
;
// Make it shorter or thinner to fit the height or width because of the padding added to the tab for painting
switch
(
this
.
Alignment
)
{
case
TabAlignment
.
Top
:
textRect
.
Y
+=
4
;
textRect
.
Height
-=
6
;
break
;
case
TabAlignment
.
Bottom
:
textRect
.
Y
+=
2
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL