forked from zsdwxm/KernowSoftwareFMX
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ksTabControl.pas
817 lines (712 loc) · 22.7 KB
/
ksTabControl.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
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
{*******************************************************************************
* *
* TksTabControl - tab control component with badge support *
* *
* https://github.com/gmurt/KernowSoftwareFMX *
* *
* Copyright 2015 Graham Murt *
* *
* email: [email protected] *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
*******************************************************************************}
unit ksTabControl;
interface
{$I ksComponents.inc}
uses
Classes, FMX.Types, FMX.Controls, FMX.Graphics, Types, System.UITypes,
FMX.StdCtrls, System.Generics.Collections, FMX.Objects,
System.UIConsts, ksSpeedButton, FMX.Layouts, ksTypes;
type
TksTabControl = class;
TksTabItem = class;
TksTabBarTheme = (ksTbCustom, ksTbLightTabs, ksTbDarkTabs);
TksTabBarPosition = (ksTbpBottom, ksTbpNone);
TksTabBarHighlightStyle = (ksTbHighlightSingleColor, ksTbHighlightFullColour);
TksTabBarClickTabEvent = procedure(Sender: TObject; ATab: TksTabItem) of object;
TksTabItemIcon = (Custom, AlarmClock, BarChart, Barcode, Bell, BookCover, BookCoverMinus, BookCoverPlus, BookCoverTick, BookMark, BookOpen,
Calendar, Camera, Car, Clock, CloudDownload, CloudUpload, Cross, Document, Download, Earth, Email,
Fax, FileList, FileMinus, FilePlus, Files, FileStar, FileTick, Flag, Folder, FolderMinus,
FolderPlus, FolderStar, Home, Inbox, Incoming, ListBullets, ListCheckBoxes, ListImages, ListNumbered, ListTicked,
Location, More, Note, Outgoing,
PaperClip, Photo, PieChart, Pin, Presentation, Search, Settings, Share, ShoppingCart, Spanner, Speaker,
Star, Tablet, Tag, Telephone, Telephone2, TelephoneBook, Tick, Timer, Trash, Upload,
User, UserEdit, UserGroup, Users, UserSearch,
VideoCamera, VideoPlayer, Viewer,
Wifi, Window, Write);
TksTabBarAppearence = class(TPersistent)
private
[weak]FTabControl: TksTabControl;
FSelected: TAlphaColor;
FNormal: TAlphaColor;
FBackground: TAlphaColor;
FBadgeColor: TAlphaColor;
FTheme: TksTabBarTheme;
procedure SetColours(ASelected, ANormal, ABackground, ABadge: TAlphaColor);
procedure SetBackground(const Value: TAlphaColor);
procedure SetNormal(const Value: TAlphaColor);
procedure SetSelected(const Value: TAlphaColor);
procedure SetTheme(const Value: TksTabBarTheme);
procedure Changed;
procedure SetBadgeColor(const Value: TAlphaColor);
public
constructor Create(ATabControl: TksTabControl);
published
property SelectedColor: TAlphaColor read FSelected write SetSelected default claDodgerblue;
property NormalColor: TAlphaColor read FNormal write SetNormal default claDimgray;
property BackgroundColor: TAlphaColor read FBackground write SetBackground default claWhite;
property BadgeColor: TAlphaColor read FBadgeColor write SetBadgeColor default claDodgerblue;
property Theme: TksTabBarTheme read FTheme write SetTheme default ksTbLightTabs;
end;
TksTabItem = class(TControl)
private
FIcon: TBitmap;
FIconType: TksTabItemIcon;
FTabIndex: integer;
FText: string;
FBadgeValue: integer;
FHighlightStyle: TksTabBarHighlightStyle;
procedure SetText(const Value: string);
procedure SetBadgeValue(const Value: integer);
procedure UpdateTabs;
procedure SetIcon(const Value: TBitmap);
procedure SetIconType(const Value: TksTabItemIcon);
procedure SetTabIndex(const Value: integer);
procedure SetHighlightStyle(const Value: TksTabBarHighlightStyle);
public
constructor Create(AOwner: TComponent); override;
procedure BeforeDestruction; override;
destructor Destroy; override;
procedure DrawTab(ACanvas: TCanvas; AIndex: integer; ARect: TRectF);
published
property Text: string read FText write SetText;
property BadgeValue: integer read FBadgeValue write SetBadgeValue;
property Icon: TBitmap read FIcon write SetIcon;
property StandardIcon: TksTabItemIcon read FIconType write SetIconType;
property TabIndex: integer read FTabIndex write SetTabIndex stored False;
property HighlightStyle: TksTabBarHighlightStyle read FHighlightStyle write SetHighlightStyle default ksTbHighlightSingleColor;
end;
TksTabItemList = class(TObjectList<TksTabItem>)
private
[weak]FTabControl: TksTabControl;
protected
procedure Notify(const Value: TksTabItem; Action: TCollectionNotification); override;
public
constructor Create(ATabControl: TksTabControl);
end;
TksTabBar = class(TControl)
private
[weak]FTabControl: TksTabControl;
protected
procedure Paint; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
public
constructor Create(AOwner: TComponent); override;
property Size;
property Width;
property Height;
property Position;
end;
[ComponentPlatformsAttribute(pidWin32 or pidWin64 or
{$IFDEF XE8_OR_NEWER} pidiOSDevice32 or pidiOSDevice64
{$ELSE} pidiOSDevice {$ENDIF} or pidiOSSimulator or pidAndroid)]
TksTabControl = class(TControl, IItemsContainer)
private
FTabBar: TksTabBar;
FTabIndex: integer;
FTabs: TksTabItemList;
FAppearence: TksTabBarAppearence;
FOnChange: TNotifyEvent;
FOnClickTab: TksTabBarClickTabEvent;
FTabPosition: TksTabBarPosition;
procedure SetTabIndex(const Value: integer);
function GetTabRect(AIndex: integer): TRectF;
function GetTabIndexFromXPos(AXPos: single): integer;
function GetTabFromXPos(AXPos: single): TksTabItem;
function GetTabCount: integer;
function GetActiveTab: TksTabItem;
function GetSelectedTab: TksTabItem;
procedure SetTabBarPosition(const Value: TksTabBarPosition);
protected
procedure Resize; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
procedure Paint; override;
procedure DoAddObject(const AObject: TFmxObject); override;
function GetItemsCount: Integer;
function GetItem(const AIndex: Integer): TFmxObject;
function GetObject: TFmxObject;
procedure DoClickTab(ATab: TksTabItem);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure UpdateTabs;
function AddTab: TksTabItem;
procedure PrevTab;
procedure NextTab;
property ActiveTab: TksTabItem read GetActiveTab;
property Tabs: TksTabItemList read FTabs;
property SelectedTab: TksTabItem read GetSelectedTab;
published
property Align;
property Appearence: TksTabBarAppearence read FAppearence write FAppearence;
property TabIndex: integer read FTabIndex write SetTabIndex default -1;
property Margins;
property Position;
property Width;
property Size;
property Height;
property TabPosition: TksTabBarPosition read FTabPosition write SetTabBarPosition default ksTbpBottom;
property Visible;
// events
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnClickTab: TksTabBarClickTabEvent read FOnClickTab write FOnClickTab;
end;
{$R *.dcr}
procedure Register;
implementation
uses SysUtils, Math, FMX.Forms, ksCommon, TypInfo, FMX.Ani, fmx.dialogs;
procedure Register;
begin
RegisterComponents('Kernow Software FMX', [TksTabControl]);
end;
{ TksTabSheTksTabItemet }
procedure TksTabItem.BeforeDestruction;
begin
inherited;
if (Parent is TksTabControl) then
TksTabControl(Parent).Tabs.Remove(Self);
end;
constructor TksTabItem.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FIcon := TBitmap.Create;
ClipChildren := True;
Stored := True;
Locked := True;
HitTest := False;
Text := Name;
FHighlightStyle := ksTbHighlightSingleColor;
end;
destructor TksTabItem.Destroy;
begin
FreeAndNil(FIcon);
inherited;
end;
procedure TksTabItem.DrawTab(ACanvas: TCanvas; AIndex: integer; ARect: TRectF);
var
AAppearence: TksTabBarAppearence;
ABmp: TBitmap;
ADestRect: TRectF;
ABadgeRect: TRectF;
ABadgeBmp: TBitmap;
begin
AAppearence := TksTabControl(Parent).Appearence;
InflateRect(ARect, 0, -3);
ACanvas.Fill.Color := AAppearence.NormalColor;
if AIndex = TksTabControl(Parent).TabIndex then
ACanvas.Fill.Color := AAppearence.SelectedColor;
ACanvas.Font.Size := 11;
ACanvas.FillText(ARect, FText, False, 1, [], TTextAlign.Center, TTextAlign.Trailing);
ABmp := TBitmap.Create;
try
ABmp.Assign(FIcon);
if FHighlightStyle = ksTbHighlightSingleColor then
begin
// single colour selected/unselected icons...
if (AIndex = TksTabControl(Parent).TabIndex) then
ReplaceOpaqueColor(ABmp, AAppearence.SelectedColor)
else
ReplaceOpaqueColor(ABmp, AAppearence.NormalColor);
end
else
begin
// single colour selected/unselected icons...
if (AIndex <> TksTabControl(Parent).TabIndex) then
ReplaceOpaqueColor(ABmp, AAppearence.NormalColor);
end;
ADestRect := RectF(0, 0, 28, 28);
OffsetRect(ADestRect, ARect.Left + ((ARect.Width - 28) / 2), 4);
ACanvas.DrawBitmap(ABmp, RectF(0, 0, ABmp.Width, ABmp.Height), ADestRect, 1, True);
if FBadgeValue > 0 then
begin
ABadgeBmp := GenerateBadge(FBadgeValue, AAppearence.BadgeColor, AAppearence.BackgroundColor, claWhite);
try
ABadgeRect := RectF(ADestRect.Right-9, ADestRect.Top-9, ADestRect.Right+9, ADestRect.Top+9);
OffsetRect(ABadgeRect, -2, 6);
ACanvas.DrawBitmap(ABadgeBmp, RectF(0, 0, ABadgeBmp.Width, ABadgeBmp.Height), ABadgeRect, 1, False);
finally
FreeAndNil(ABadgeBmp);
end;
{ABadgeScale := (GetScreenScale*2);
ABadgeBmp := TBitmap.Create(Round(18 * ABadgeScale), Round(18 * ABadgeScale));
try
ABadgeBmp.Clear(claNull);
ABadgeBmp.Canvas.BeginScene;
ABadgeBmp.Canvas.Fill.Color := AAppearence.BadgeColor;
ABadgeBmp.Canvas.Stroke.Color := AAppearence.BackgroundColor;
ABadgeBmp.Canvas.FillEllipse(RectF(0, 0, ABadgeBmp.Width, ABadgeBmp.Height), 1);
ABadgeBmp.Canvas.StrokeThickness := 1*ABadgeScale;
ABadgeBmp.Canvas.DrawEllipse(RectF(1, 1, ABadgeBmp.Width-1, ABadgeBmp.Height-1), 1);
ABadgeBmp.Canvas.Fill.Color := claWhite;
ABadgeBmp.Canvas.Font.Size := 9*ABadgeScale;
ABadgeBmp.Canvas.FillText(RectF(0, 0, ABadgeBmp.Width, ABadgeBmp.Height), IntToStr(FBadgeValue), False, 1, [], TTextAlign.Center);
ABadgeBmp.Canvas.EndScene;
ABadgeRect := RectF(ADestRect.Right-9, ADestRect.Top-9, ADestRect.Right+9, ADestRect.Top+9);
OffsetRect(ABadgeRect, -2, 6);
ACanvas.DrawBitmap(ABadgeBmp, RectF(0, 0, ABadgeBmp.Width, ABadgeBmp.Height), ABadgeRect, 1, False);
finally
FreeAndNil(ABadgeBmp);
end; }
end;
finally
FreeAndNil(ABmp);
end;
end;
procedure TksTabItem.SetIconType(const Value: TksTabItemIcon);
var
AStream: TResourceStream;
AEnumName: String;
begin
if Value <> TksTabItemIcon.Custom then
begin
AEnumName := GetENumName(TypeInfo(TksTabItemIcon), Ord(Value));
AStream := TResourceStream.Create(HInstance, AEnumName, RT_RCDATA);
try
FIcon.LoadFromStream(AStream);
finally
AStream.Free;
end;
FHighlightStyle := TksTabBarHighlightStyle.ksTbHighlightSingleColor;
end;
FIconType := Value;
UpdateTabs;
end;
procedure TksTabItem.SetBadgeValue(const Value: integer);
begin
if FBadgeValue <> Value then
begin
FBadgeValue := Value;
UpdateTabs;
end;
end;
procedure TksTabItem.SetHighlightStyle(const Value: TksTabBarHighlightStyle);
begin
if FHighlightStyle <> Value then
begin
FHighlightStyle := Value;
UpdateTabs;
end;
end;
procedure TksTabItem.SetIcon(const Value: TBitmap);
begin
FIcon.Assign(Value);
FIconType := TksTabItemIcon.Custom;
UpdateTabs;
end;
procedure TksTabItem.SetTabIndex(const Value: integer);
var
ATabs: TksTabItemList;
ANewIndex: integer;
begin
if FTabIndex <> Value then
begin
ATabs := TksTabControl(Parent).Tabs;
ANewIndex := Value;
if ANewIndex < 0 then FTabIndex := 0;
if ANewIndex > ATabs.Count-1 then ANewIndex := ATabs.Count-1;
ATabs.Move(FTabIndex, ANewIndex);
FTabIndex := ANewIndex;
UpdateTabs;
end;
end;
procedure TksTabItem.SetText(const Value: string);
begin
if FText <> Value then
begin
FText := Value;
UpdateTabs;
end;
end;
procedure TksTabItem.UpdateTabs;
begin
TksTabControl(Parent).UpdateTabs;
end;
{ TksTabControl }
function TksTabControl.AddTab: TksTabItem;
var
ATab: TksTabItem;
begin
ATab := TksTabItem.Create(Self);
AddObject(ATab);
Result := ATab;
end;
constructor TksTabControl.Create(AOwner: TComponent);
begin
inherited;
FTabs := TksTabItemList.Create(Self);
FTabBar := TksTabBar.Create(Self);
FAppearence := TksTabBarAppearence.Create(Self);
SetAcceptsControls(True);
Size.Height := 250;
Size.Width := 250;
FTabBar.Align := TAlignLayout.Bottom;
AddObject(FTabBar);
end;
destructor TksTabControl.Destroy;
begin
FreeAndNil(FTabs);
FAppearence.DisposeOf;
inherited;
end;
procedure TksTabControl.DoAddObject(const AObject: TFmxObject);
var
ATab: TksTabItem;
begin
inherited;
if AObject.ClassType = TksTabItem then
begin
ATab := TksTabItem(AObject);
FTabs.Add(ATab);
if not (csLoading in ComponentState) then
begin
ATab.Text := 'Item '+IntToStr(GetTabCount);
ATab.Name := 'TabItem'+IntToStr(GetTabCount);
end;
UpdateTabs;
Exit;
end;
if (SelectedTab <> nil) and (AObject <> FTabBar) then
begin
SelectedTab.AddObject(AObject);
end;
end;
procedure TksTabControl.DoClickTab(ATab: TksTabItem);
begin
if Assigned(FOnClickTab) then
FOnClickTab(Self, ATab);
end;
function TksTabControl.GetActiveTab: TksTabItem;
begin
if InRange(TabIndex, 0, GetTabCount - 1) then
Result := Tabs[TabIndex]
else
Result := nil;
end;
function TksTabControl.GetItem(const AIndex: Integer): TFmxObject;
begin
Result := Tabs[AIndex];
end;
function TksTabControl.GetItemsCount: Integer;
begin
Result := FTabs.Count;
end;
function TksTabControl.GetObject: TFmxObject;
begin
Result := Self;
end;
function TksTabControl.GetSelectedTab: TksTabItem;
begin
Result := nil;
if (FTabIndex > -1) and (FTabIndex <= FTabs.Count-1) then
Result := FTabs[FTabIndex];
end;
function TksTabControl.GetTabCount: integer;
begin
Result := 0;
if FTabs <> nil then
Result := FTabs.Count;
end;
function TksTabControl.GetTabFromXPos(AXPos: single): TksTabItem;
var
ICount: integer;
begin
Result := nil;
for ICount := 0 to GetTabCount-1 do
begin
if PtInRect(GetTabRect(ICount), PointF(AXPos, 1)) then
begin
Result := Tabs[ICount];
Exit;
end;
end;
end;
function TksTabControl.GetTabIndexFromXPos(AXPos: single): integer;
var
ICount: integer;
begin
Result := -1;
for ICount := 0 to GetTabCount-1 do
begin
if PtInRect(GetTabRect(ICount), PointF(AXPos, 1)) then
begin
Result := ICount;
Exit;
end;
end;
end;
function TksTabControl.GetTabRect(AIndex: integer): TRectF;
var
AWidth: single;
begin
AWidth := Width / GetTabCount;
Result := RectF(0, 0, AWidth, 50);
OffsetRect(Result, AWidth * AIndex, 0)
end;
procedure TksTabControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
inherited;
end;
procedure TksTabControl.NextTab;
begin
TabIndex := TabIndex +1;
end;
procedure TksTabControl.Paint;
var
AState: TCanvasSaveState;
begin
with Canvas do
begin
AState := SaveState;
try
IntersectClipRect(RectF(0, 0, Size.Width, Size.Height));
Fill.Kind := TBrushKind.Solid;
Fill.Color := claWhitesmoke;
FillRect(RectF(0, 0, Size.Width, Size.Height), 0, 0, AllCorners,1);
finally
RestoreState(AState);
end;
AState := SaveState;
try
IntersectClipRect(RectF(0, 0, Size.Width, Size.Height));
Stroke.Kind := TBrushKind.Solid;
Stroke.Color := claSilver;
DrawRect(RectF(0, 0, Size.Width, Size.Height), 0, 0, AllCorners,1);
finally
RestoreState(AState);
end;
end;
if (csDesigning in ComponentState) then
begin
DrawDesignBorder(claDimgray, claDimgray);
Canvas.Fill.Color := claDimgray;;
{$IFDEF MSWINDOWS}
if GetTabCount = 0 then
begin
Canvas.Font.Size := 14;
Canvas.FillText(ClipRect, 'Right-click to add tabs', True, 1, [], TTextAlign.Center);
end;
{$ENDIF}
end;
end;
procedure TksTabControl.PrevTab;
begin
TabIndex := TabIndex -1;
end;
procedure TksTabControl.Resize;
begin
inherited;
UpdateTabs;
Repaint;
end;
procedure TksTabControl.SetTabBarPosition(const Value: TksTabBarPosition);
begin
if FTabPosition <> Value then
begin
FTabPosition := Value;
UpdateTabs;
end;
end;
procedure TksTabControl.SetTabIndex(const Value: integer);
begin
if (Tabs.Count > 0) and ((Value < 0) or (Value > Tabs.Count-1)) then
Exit;
if FTabIndex <> Value then
begin
FTabIndex := Value;
UpdateTabs;
if Assigned(FOnChange) then
FOnChange(Self);
end;
end;
procedure TksTabControl.UpdateTabs;
var
ICount: integer;
ATab: TksTabItem;
begin
for ICount := 0 to GetTabCount-1 do
begin
ATab := Tabs[ICount];
ATab.FTabIndex := ICount;
ATab.Width := Self.Width;
case FTabPosition of
ksTbpBottom: ATab.Height := Self.Height-50;
ksTbpNone: ATab.Height := Self.Height;
end;
ATab.Position.Y := 0;
ATab.Position.X := 0;
ATab.Visible := (ICount = FTabIndex);
end;
Repaint;
end;
{ TksTabBar }
constructor TksTabBar.Create(AOwner: TComponent);
begin
inherited;
FTabControl := (AOwner as TksTabControl);
Size.Height := 50;
Stored := False;
FDesignInteractive := True;
end;
procedure TksTabBar.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single);
var
ATab: TksTabItem;
begin
inherited;
TksTabControl(Parent).TabIndex := TksTabControl(FTabControl).GetTabIndexFromXPos(X);
ATab := TksTabControl(FTabControl).GetTabFromXPos(X);
{$IFDEF MSWINDOWS}
if (csDesigning in ComponentState) and
(TCommonCustomForm(FTabControl.Owner).Designer <> nil) then
begin
if ATab <> nil then
begin
TCommonCustomForm(FTabControl.Owner).Focused := nil;
TCommonCustomForm(FTabControl.Owner).Designer.SelectComponent(ATab);
TCommonCustomForm(FTabControl.Owner).Designer.Modified;
end;
Repaint;
end;
{$ENDIF}
if ATab <> nil then
FTabControl.DoClickTab(ATab);
end;
procedure TksTabBar.Paint;
var
AState: TCanvasSaveState;
ICount: integer;
ARect: TRectF;
ATabControl: TksTabControl;
begin
inherited;
ATabControl := TksTabControl(FTabControl);
with Canvas do
begin
AState := SaveState;
try
ARect := RectF(0, 0, Size.Width, Size.Height);
if (csDesigning in ComponentState) then
InflateRect(ARect, -1, -1);
IntersectClipRect(ARect);
Fill.Kind := TBrushKind.Solid;
Canvas.Clear(ATabControl.Appearence.BackgroundColor);
Stroke.Kind := TBrushKind.Solid;
Stroke.Color := claBlack;
if (csDesigning in ComponentState) then
DrawDesignBorder(claDimgray, claDimgray);
DrawRectSides(ARect, 0, 0, AllCorners,1, [TSide.Top]);
for ICount := 0 to TksTabControl(FTabControl).GetTabCount-1 do
ATabControl.Tabs[ICount].DrawTab(Canvas, ICount, ATabControl.GetTabRect(ICount));
finally
RestoreState(AState);
Font.Size := 10;
end;
end;
end;
{ TksTabBarAppearence }
procedure TksTabBarAppearence.Changed;
begin
TksTabControl(FTabControl).Repaint;
end;
constructor TksTabBarAppearence.Create(ATabControl: TksTabControl);
begin
inherited Create;
FTabControl := ATabControl;
FSelected := claDodgerblue;
FNormal := claDimgray;
FBackground := claWhite;
FBadgeColor := claDodgerblue;
FTheme := ksTbLightTabs;
end;
procedure TksTabBarAppearence.SetBackground(const Value: TAlphaColor);
begin
if FBackground <> Value then
begin
FBackground := Value;
FTheme := ksTbCustom;
Changed;
end;
end;
procedure TksTabBarAppearence.SetBadgeColor(const Value: TAlphaColor);
begin
if FBadgeColor <> Value then
begin
FBadgeColor := Value;
FTheme := ksTbCustom;
Changed;
end;
end;
procedure TksTabBarAppearence.SetColours(ASelected, ANormal, ABackground, ABadge: TAlphaColor);
begin
FSelected := ASelected;
FNormal := ANormal;
FBackground := ABackground;
FBadgeColor := ABadge;
end;
procedure TksTabBarAppearence.SetNormal(const Value: TAlphaColor);
begin
if FNormal <> Value then
begin
FNormal := Value;
FTheme := ksTbCustom;
Changed;
end;
end;
procedure TksTabBarAppearence.SetSelected(const Value: TAlphaColor);
begin
if FSelected <> Value then
begin
FSelected := Value;
FTheme := ksTbCustom;
Changed;
end;
end;
procedure TksTabBarAppearence.SetTheme(const Value: TksTabBarTheme);
begin
if FTheme <> Value then
begin
if Value = ksTbLightTabs then SetColours(claDodgerblue, claGray, claWhite, claDodgerblue);
if Value = ksTbDarkTabs then SetColours(claWhite, claGray, $FF202020, claRed);
FTheme := Value;
Changed;
end;
end;
{ TksTabItemList }
constructor TksTabItemList.Create(ATabControl: TksTabControl);
begin
inherited Create(False);
FTabControl := ATabControl;
end;
procedure TksTabItemList.Notify(const Value: TksTabItem; Action: TCollectionNotification);
begin
inherited;
if csDestroying in FTabControl.ComponentState then
Exit;
if (Action = TCollectionNotification.cnRemoved) and (not (csDesigning in FTabControl.ComponentState)) then
begin
Value.DisposeOf;
end;
end;
initialization
RegisterFmxClasses([TksTabControl, TksTabItem]);
end.