-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorTabs.pas
214 lines (171 loc) · 5.29 KB
/
ColorTabs.pas
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
unit ColorTabs;
interface
uses
Winapi.Messages,
Vcl.Graphics,
Vcl.ComCtrls;
type
TTabColorControlStyleHook= class(TTabControlStyleHook)
private
class var FUseBorder : Boolean;
protected
class constructor Create;
procedure DrawTab(Canvas: TCanvas; Index: Integer); override;
class property UseBorder : Boolean read FUseBorder write FUseBorder;
end;
implementation
uses
System.Classes,
System.SysUtils,
System.Types,
System.Rtti,
System.Generics.Collections,
Winapi.Windows,
Vcl.Styles,
Vcl.Themes,
Vcl.Controls;
type
TWinControlClass = class(TWinControl);
TCustomTabControlClass = class(TCustomTabControl);
function GetBorderColorTab: TColor;
begin
result:=TStyleManager.ActiveStyle.GetSystemColor(clActiveBorder);
end;
function PageIndexFromTabIndex(const pageControl : TPageControl; const TabIndex: Integer): Integer;
var
i : Integer;
begin
Result := TabIndex;
for i := 0 to Pred(pageControl.PageCount) do
begin
if not pageControl.Pages[i].TabVisible then
Inc(Result);
if TabIndex = pageControl.Pages[i].TabIndex then
break;
end;
end;
// цвет фона табов
function GetColorTab(Index: Integer; MarkRed:boolean ) : TColor;
Const
MaxColors =9;
//Colors : Array [0..MaxColors-1] of TColor = (6512214,16755712,8355381,1085522,115885,1098495,1735163,2248434,4987610);
begin
// if index=3 then
if (index=3) and MarkRed then
Result:=clRed
else
Result:=TStyleManager.ActiveStyle.GetSystemColor(clWindow)//Colors[Index mod MaxColors];
// else
// Result:=clbLUE
end;
function GetColorTextTab(bc:TColor;ThemedTab : TThemedTab) : TColor;
Const
ColorSelected = clYellow;
ColorHot = clGreen;
ColorNormal = clWhite;
begin
Result:=TStyleManager.ActiveStyle.GetSystemColor(clWindow);
case ThemedTab of
ttTabItemSelected,
ttTabItemLeftEdgeSelected,
ttTabItemBothEdgeSelected,
ttTabItemRightEdgeSelected : Result:= TStyleManager.ActiveStyle.GetSystemColor(clInfoText);
ttTabItemHot,
ttTabItemLeftEdgeHot,
ttTabItemBothEdgeHot,
ttTabItemRightEdgeHot : Result := ColorToRGB(bc) xor $00FFFFFF;
ttTabItemNormal,
ttTabItemLeftEdgeNormal,
ttTabItemBothEdgeNormal,
ttTabItemRightEdgeNormal : Result := TStyleManager.ActiveStyle.GetSystemColor(clWindowText);
end;
end;
{ TTabColorControlStyleHook }
class constructor TTabColorControlStyleHook.Create;
begin
FUseBorder:=true;
end;
procedure TTabColorControlStyleHook.DrawTab(Canvas: TCanvas; Index: Integer);
var
LDetails : TThemedElementDetails;
LImageIndex, resi, i : Integer;
LThemedTab : TThemedTab;
LIconRect : TRect;
R, LayoutR : TRect;
LImageW, LImageH: Integer;
LTextX, LTextY: Integer;
LTextColor : TColor;
procedure DrawControlText(const S: string; var R: TRect; Flags: Cardinal);
var
TextFormat: TTextFormatFlags;
begin
Canvas.Font := TWinControlClass(Control).Font;
TextFormat := TTextFormatFlags(Flags);
if (resi=3) and (TWinControlClass(Control).Name='pcMainNoteEdit') then
Canvas.Font.Color := clYellow
else
Canvas.Font.Color := LTextColor;
StyleServices.DrawText(Canvas.Handle, LDetails, S, R, TextFormat, Canvas.Font.Color);
end;
begin
LImageW := 0; LImageH := 0;
R := TabRect[Index];
if R.Left < 0 then Exit;
if Index = TabIndex then
InflateRect(R, 0, 2);
Canvas.Font.Assign(TCustomTabControlClass(Control).Font);
LayoutR := R;
LThemedTab := ttTabDontCare;
//Get the type of the active tab
if Index = TabIndex then
LThemedTab := ttTabItemSelected
else if (Index = HotTabIndex) and MouseInControl then
LThemedTab := ttTabItemHot
else
LThemedTab := ttTabItemNormal;
resi := Index;
for I := 0 to (Control as TPageControl).PageCount-1 do begin
if not (Control as TPageControl).pages[i].TabVisible then
Inc(Resi);
if i>=index then break;
end;
//draw the bkg tab
if StyleServices.Available then
begin
LDetails := StyleServices.GetElementDetails(LThemedTab);//necesary for DrawControlText
if FUseBorder then
begin
InflateRect(R,-1,0);
if TabIndex<>Index then
R.Bottom:=R.Bottom+1
else
R.Bottom:=R.Bottom-1;
Canvas.Brush.Color:=GetBorderColorTab;
Canvas.FillRect(R);
if TabIndex=Index then
begin
InflateRect(R,-1,-1);
R.Bottom:=R.Bottom+1;
end
else
InflateRect(R,-1,-1);
Canvas.Brush.Color:=GetColorTab(resi,TWinControlClass(Control).Name='pcMainNoteEdit');
Canvas.FillRect(R);
end
else
Begin
InflateRect(R,-1,0);//adjust the size of the tab creating blanks space between the tabs
Canvas.Brush.Color:=GetColorTab(resi,TWinControlClass(Control).Name='pcMainNoteEdit');
Canvas.FillRect(R);
end;
end;
//draw the text of the tab
if StyleServices.Available then
begin
LTextColor:=GetColorTextTab(Canvas.Brush.Color,LThemedTab);
if (Index = TabIndex) then
OffsetRect(LayoutR, 0, -1);
DrawControlText(Tabs[Index], LayoutR, DT_VCENTER or DT_CENTER or DT_SINGLELINE or DT_NOCLIP);
end;
end;
end.