forked from JBontes/Life32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewTabset.pas
1360 lines (1189 loc) · 36.5 KB
/
NewTabset.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
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
unit NewTabset;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Consts;
type
TScrollBtn = (sbLeft, sbRight);
TScroller = class(TCustomControl)
private
{ property usage }
FMin: Longint;
FMax: Longint;
FPosition: Longint;
FOnClick: TNotifyEvent;
FChange: Integer;
{ private usage }
Bitmap: TBitmap;
Pressed: Boolean;
Down: Boolean;
Current: TScrollBtn;
pWidth: Integer;
pHeight: Integer;
{ property access methods }
procedure SetMin(Value: Longint);
procedure SetMax(Value: Longint);
procedure SetPosition(Value: Longint);
{ private methods }
function CanScrollLeft: Boolean;
function CanScrollRight: Boolean;
procedure DoMouseDown(X: Integer);
procedure WMLButtonDown(var Message: TWMLButtonDown);
message WM_LBUTTONDOWN;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk);
message WM_LBUTTONDBLCLK;
procedure WMMouseMove(var Message: TWMMouseMove);
message WM_MOUSEMOVE;
procedure WMLButtonUp(var Message: TWMLButtonUp);
message WM_LBUTTONUP;
procedure WMSize(var Message: TWMSize);
message WM_SIZE;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
published
property OnClick: TNotifyEvent read FOnClick write FOnClick;
property Min: Longint read FMin write SetMin default 0;
property Max: Longint read FMax write SetMax default 0;
property Position: Longint read FPosition write SetPosition default 0;
property Change: Integer read FChange write FChange default 1;
end; (**)
TNewTabSet = class;
TTabList = class(TStringList)
private
Tabs: TNewTabSet;
public
procedure Insert(Index: Integer; const S: string); override;
procedure Delete(Index: Integer); override;
function Add(const S: string): Integer; override;
procedure Put(Index: Integer; const S: string); override;
procedure Clear; override;
procedure AddStrings(Strings: TStrings); override;
end; (**)
{ eash TEdgeType is made up of one or two of these parts }
TEdgePart = (epSelectedLeft, epUnselectedLeft, epSelectedRight,
epUnselectedRight);
{ represents the intersection between two tabs, or the edge of a tab }
TEdgeType = (etNone, etFirstIsSel, etFirstNotSel, etLastIsSel, etLastNotSel,
etNotSelToSel, etSelToNotSel, etNotSelToNotSel);
TTabStyle = (tsStandard, tsOwnerDraw);
TTabOrientation = (toUp, toDown);
TMeasureTabEvent = procedure(Sender: TObject; Index: Integer;
var TabWidth: Integer) of object;
TDrawTabEvent = procedure(Sender: TObject; TabCanvas: TCanvas; R: TRect;
Index: Integer; Selected: Boolean) of object;
TTabChangeEvent = procedure(Sender: TObject; NewTab: Integer;
var AllowChange: Boolean) of object;
TNewTabSet = class(TCustomControl)
private
{ property instance variables }
FStartMargin: Integer;
FEndMargin: Integer;
FTabs: TStrings;
FTabIndex: Integer;
FFirstIndex: Integer;
FOrientation: TTabOrientation;
FVisibleTabs: Integer;
FSelectedColor: TColor;
FUnselectedColor: TColor;
FBackgroundColor: TColor;
FDitherBackground: Boolean;
FAutoScroll: Boolean;
FStyle: TTabStyle;
FOwnerDrawHeight: Integer;
FOnMeasureTab: TMeasureTabEvent;
FOnDrawTab: TDrawTabEvent;
FOnChange: TTabChangeEvent;
{ private instance variables }
ImageList: TImageList;
MemBitmap: TBitmap; { used for off-screen drawing }
BrushBitmap: TBitmap; { used for background pattern }
TabPositions: TList;
FTabHeight: Integer;
Scroller: TScroller;
FDoFix: Boolean;
{ property access methods }
procedure SetSelectedColor(Value: TColor);
procedure SetUnselectedColor(Value: TColor);
procedure SetBackgroundColor(Value: TColor);
procedure SetDitherBackground(Value: Boolean);
procedure SetOrientation(Value: TTabOrientation);
procedure SetAutoScroll(Value: Boolean);
procedure SetStartMargin(Value: Integer);
procedure SetEndMargin(Value: Integer);
procedure SetTabIndex(Value: Integer);
procedure SetFirstIndex(Value: Integer);
procedure SetTabList(Value: TStrings);
// function GetTabCount: Integer;
// function GetTabName(Value: Integer): String;
// procedure SetTabName(Value: Integer; const AName: String);
procedure SetTabStyle(Value: TTabStyle);
procedure SetTabHeight(Value: Integer);
{ private methods }
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure PaintEdge(X, Y, H: Integer; Edge: TEdgeType);
procedure CreateBrushPattern(Bitmap: TBitmap);
function CalcTabPositions(Start, Stop: Integer; Canvas: TCanvas;
First: Integer): Integer;
procedure CreateScroller;
procedure InitBitmaps;
procedure DoneBitmaps;
procedure CreateEdgeParts;
procedure FixTabPos;
procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
procedure ScrollClick(Sender: TObject);
procedure ReadIntData(Reader: TReader);
procedure ReadBoolData(Reader: TReader);
protected
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure Paint; override;
procedure DrawTab(TabCanvas: TCanvas; R: TRect; Index: Integer;
Selected: Boolean); virtual;
function CanChange(NewIndex: Integer): Boolean;
procedure MeasureTab(Index: Integer; var TabWidth: Integer); virtual;
procedure DefineProperties(Filer: TFiler); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
function ItemAtPos(Pos: TPoint): Integer;
function ItemRect(Item: Integer): TRect;
procedure SelectNext(Direction: Boolean);
property Canvas;
property FirstIndex: Integer read FFirstIndex write SetFirstIndex default 0;
published
property Align;
property AutoScroll: Boolean read FAutoScroll write SetAutoScroll default True;
property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor default clBtnFace;
property DitherBackground: Boolean read FDitherBackground write SetDitherBackground default True;
property DragMode;
property Enabled;
property EndMargin: Integer read FEndMargin write SetEndMargin default 5;
property Font;
property Orientation: TTabOrientation read FOrientation write SetOrientation;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property StartMargin: Integer read FStartMargin write SetStartMargin default 5;
property SelectedColor: TColor read FSelectedColor write SetSelectedColor default clBtnFace;
property Style: TTabStyle read FStyle write SetTabStyle default tsStandard;
property TabHeight: Integer read FOwnerDrawHeight write SetTabHeight default 20;
property Tabs: TStrings read FTabs write SetTabList;
property TabIndex: Integer read FTabIndex write SetTabIndex default -1;
property UnselectedColor: TColor read FUnselectedColor write SetUnselectedColor default clWindow;
property Visible;
property VisibleTabs: Integer read FVisibleTabs;
property OnClick;
property OnChange: TTabChangeEvent read FOnChange write FOnChange;
property OnDragDrop;
property OnDragOver;
property OnDrawTab: TDrawTabEvent read FOnDrawTab write FOnDrawTab;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMeasureTab: TMeasureTabEvent read FOnMeasureTab write FOnMeasureTab;
property OnStartDrag;
end;
procedure Register;
implementation
uses
System.Types;
procedure Register;
begin
RegisterComponents('Johan',[TNewTabSet]);
end;
const
EdgeWidth = 9; { This controls the angle of the tab edges }
type
TTabPos = record
Size, StartPos: Word;
end;
{ TScroller }
constructor TScroller.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle:= ControlStyle + [csOpaque];
Bitmap:= TBitmap.Create;
pWidth:= 24;
pHeight:= 13;
FMin:= 0;
FMax:= 0;
FPosition:= 0;
FChange:= 1;
end;
destructor TScroller.Destroy;
begin
Bitmap.Free;
inherited Destroy;
end;
procedure TScroller.Paint;
begin
with Canvas do
begin
{ paint left button }
if CanScrollLeft then
begin
if Down and (Current = sbLeft) then
Bitmap.Handle:= LoadBitmap(HInstance, 'SBLEFTDN2')
else Bitmap.Handle:= LoadBitmap(HInstance, 'SBLEFT2');
end
else
Bitmap.Handle:= LoadBitmap(HInstance, 'SBLEFTDIS2');
Draw(0, 0, Bitmap);
{ paint right button }
if CanScrollRight then
begin
if Down and (Current = sbRight) then
Bitmap.Handle:= LoadBitmap(HInstance, 'SBRIGHTDN2')
else Bitmap.Handle:= LoadBitmap(HInstance, 'SBRIGHT2');
end
else
Bitmap.Handle:= LoadBitmap(HInstance, 'SBRIGHTDIS2');
Draw((pWidth div 2) - 1, 0, Bitmap);
end;
end;
procedure TScroller.WMSize(var Message: TWMSize);
begin
inherited;
Width:= pWidth - 1;
Height:= pHeight;
end;
procedure TScroller.SetMin(Value: Longint);
begin
if Value < FMax then FMin:= Value;
end;
procedure TScroller.SetMax(Value: Longint);
begin
if Value > FMin then FMax:= Value;
end;
procedure TScroller.SetPosition(Value: Longint);
begin
if Value <> FPosition then
begin
if Value < Min then Value:= Min;
if Value > Max then Value:= Max;
FPosition:= Value;
Invalidate;
if Assigned(FOnClick) then
FOnClick(Self);
end;
end;
function TScroller.CanScrollLeft: Boolean;
begin
Result:= Position > Min;
end;
function TScroller.CanScrollRight: Boolean;
begin
Result:= Position < Max;
end;
procedure TScroller.DoMouseDown(X: Integer);
begin
if X < pWidth div 2 then Current:= sbLeft
else Current:= sbRight;
case Current of
sbLeft: if not CanScrollLeft then Exit;
sbRight: if not CanScrollRight then Exit;
end;
Pressed:= True;
Down:= True;
Invalidate;
SetCapture(Handle);
end;
procedure TScroller.WMLButtonDown(var Message: TWMLButtonDown);
begin
DoMouseDown(Message.XPos);
end;
procedure TScroller.WMLButtonDblClk(var Message: TWMLButtonDblClk);
begin
DoMouseDown(Message.XPos);
end;
procedure TScroller.WMMouseMove(var Message: TWMMouseMove);
var
P: TPoint;
R: TRect;
begin
if Pressed then
begin
P:= Point(Message.XPos, Message.YPos);
R:= Rect(0, 0, pWidth div 2, pHeight);
if Current = sbRight then OffsetRect(R, pWidth div 2, 0);
if PtInRect(R, P) <> Down then
begin
Down:= not Down;
Invalidate;
end;
end;
end;
procedure TScroller.WMLButtonUp(var Message: TWMLButtonUp);
var
NewPos: Longint;
begin
ReleaseCapture;
Pressed:= False;
if Down then
begin
Down:= False;
NewPos:= Position;
case Current of
sbLeft: Dec(NewPos, Change);
sbRight: Inc(NewPos, Change);
end;
Position:= NewPos;
end;
end;
{ TTabList }
function TTabList.Add(const S: string): Integer;
begin
Result:= inherited Add(S);
if Tabs <> nil then
Tabs.Invalidate;
end;
procedure TTabList.Insert(Index: Integer; const S: string);
begin
inherited Insert(Index, S);
if Tabs <> nil then
begin
if Index <= Tabs.FTabIndex then Inc(Tabs.FTabIndex);
Tabs.Invalidate;
end;
end;
procedure TTabList.Delete(Index: Integer);
var
OldIndex: Integer;
begin
OldIndex:= Tabs.Tabindex;
inherited Delete(Index);
if OldIndex < Count then Tabs.FTabIndex:= OldIndex
else Tabs.FTabIndex:= Count - 1;
Tabs.Invalidate;
Tabs.Invalidate;
if OldIndex = Index then Tabs.Click; { deleted selected tab }
end;
procedure TTabList.Put(Index: Integer; const S: string);
begin
inherited Put(Index, S);
if Tabs <> nil then
Tabs.Invalidate;
end;
procedure TTabList.Clear;
begin
inherited Clear;
Tabs.FTabIndex:= -1;
Tabs.Invalidate;
end;
procedure TTabList.AddStrings(Strings: TStrings);
begin
SendMessage(Tabs.Handle, WM_SETREDRAW, 0, 0);
inherited AddStrings(Strings);
SendMessage(Tabs.Handle, WM_SETREDRAW, 1, 0);
Tabs.Invalidate;
end;
{ TNewTabset }
constructor TNewTabSet.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle:= [csCaptureMouse, csDoubleClicks, csOpaque];
Width:= 185;
Height:= 21;
TabPositions:= TList.Create;
FTabHeight:= 20;
FTabs:= TTabList.Create;
TTabList(FTabs).Tabs:= Self;
InitBitmaps;
CreateScroller;
FTabIndex:= -1;
FFirstIndex:= 0;
FVisibleTabs:= 0; { set by draw routine }
FStartMargin:= 5;
FEndMargin:= 5;
{ initialize default values }
FSelectedColor:= clBtnFace;
FUnselectedColor:= clWindow;
FBackgroundColor:= clBtnFace;
FDitherBackground:= True;
CreateBrushPattern(BrushBitmap);
FAutoScroll:= True;
FStyle:= tsStandard;
FOwnerDrawHeight:= 20;
ParentFont:= False;
Font.Name:= string(DefFontData.Name);
Font.Height:= DefFontData.Height;
Font.Style:= [];
{ create the edge bitmaps }
CreateEdgeParts;
end;
procedure TNewTabSet.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params.WindowClass do
style:= style and not (CS_VREDRAW or CS_HREDRAW);
end;
procedure TNewTabset.CreateScroller;
begin
Scroller:= TScroller.Create(Self);
with Scroller do
begin
Parent:= Self;
Top:= 3;
Min:= 0;
Max:= 0;
Position:= 0;
Visible:= False;
OnClick:= ScrollClick;
end;
end;
procedure TNewTabset.InitBitmaps;
begin
MemBitmap:= TBitmap.Create;
BrushBitmap:= TBitmap.Create;
end;
destructor TNewTabset.Destroy;
begin
FTabs.Free;
TabPositions.Free;
DoneBitmaps;
inherited Destroy;
end;
procedure TNewTabset.DoneBitmaps;
begin
MemBitmap.Free;
BrushBitmap.Free;
ImageList.Free;
end;
procedure TNewTabset.ScrollClick(Sender: TObject);
begin
FirstIndex:= TScroller(Sender).Position;
end;
{ cache the tab position data, and return number of visible tabs }
function TNewTabset.CalcTabPositions(Start, Stop: Integer; Canvas: TCanvas;
First: Integer): Integer;
var
Index: Integer;
TabPos: TTabPos;
W: Integer;
begin
TabPositions.Count:= 0; { erase all previously cached data }
Index:= First;
while (Start < Stop) and (Index < Tabs.Count) do
with Canvas do
begin
TabPos.StartPos:= Start;
W:= TextWidth(Tabs[Index]);
{ Owner }
if (FStyle = tsOwnerDraw) then MeasureTab(Index, W);
TabPos.Size:= W;
Inc(Start, TabPos.Size + EdgeWidth); { next usable position }
if Start <= Stop then
begin
TabPositions.Add(Pointer(TabPos)); { add to list }
Inc(Index);
end;
end;
Result:= Index - First;
end;
function TNewTabset.ItemAtPos(Pos: TPoint): Integer;
var
TabPos: TTabPos;
i: Integer;
found: boolean;
begin
found:= false;
Result:= -1;
if (Pos.Y < 0) or (Pos.Y > ClientHeight) then exit;
i:= 0;
while (i < TabPositions.Count) and not(Found) do begin
Pointer(TabPos):= TabPositions[I];
if (Pos.X >= TabPos.StartPos) and (Pos.X <= TabPos.StartPos + TabPos.Size) then begin
Result:= i+FirstIndex;
end; {if}
inc(i);
end; {while}
end;
function TNewTabset.ItemRect(Item: Integer): TRect;
var
TabPos: TTabPos;
begin
Item:= Item - FirstIndex;
if (TabPositions.Count > 0) and (Item >= 0) and (Item < TabPositions.Count) then begin
Pointer(TabPos):= TabPositions[Item];
Result:= Rect(TabPos.StartPos, 0, TabPos.StartPos + TabPos.Size, FTabHeight);
InflateRect(Result, 1, -2);
end
else Result:= Rect(0, 0, 0, 0);
end;
procedure TNewTabset.Paint;
var
TabStart, LastTabPos: Integer;
TabPos: TTabPos;
Tab: Integer;
Leading: TEdgeType;
Trailing: TEdgeType;
isFirst, isLast, isSelected, isPrevSelected: Boolean;
R: TRect;
Y: integer;
begin
if not HandleAllocated then Exit;
{ Set the size of the off-screen bitmap. Make sure that it is tall enough to
display the entire tab, even if the screen won't display it all. This is
required to avoid problems with using FloodFill. }
MemBitmap.Width:= ClientWidth;
if ClientHeight < FTabHeight + 5 then MemBitmap.Height:= FTabHeight + 5
else MemBitmap.Height:= ClientHeight;
MemBitmap.Canvas.Font:= Self.Canvas.Font;
TabStart:= StartMargin + EdgeWidth; { where does first text appear? }
LastTabPos:= Width - EndMargin; { tabs draw until this position }
Scroller.Left:= Width - Scroller.Width - 2;
{ do initial calculations for how many tabs are visible }
FVisibleTabs:= CalcTabPositions(TabStart, LastTabPos, MemBitmap.Canvas,
FirstIndex);
{ enable the scroller if FAutoScroll = True and not all tabs are visible }
if AutoScroll and (FVisibleTabs < Tabs.Count) then
begin
Dec(LastTabPos, Scroller.Width - 4);
{ recalc the tab positions }
FVisibleTabs:= CalcTabPositions(TabStart, LastTabPos, MemBitmap.Canvas,
FirstIndex);
{ set the scroller's range }
Scroller.Visible:= True;
ShowWindow(Scroller.Handle, SW_SHOW);
Scroller.Min:= 0;
Scroller.Max:= Tabs.Count - VisibleTabs;
Scroller.Position:= FirstIndex;
end
else if VisibleTabs >= Tabs.Count then begin
Scroller.Visible:= False;
ShowWindow(Scroller.Handle, SW_HIDE);
end;
if FDoFix then begin
FixTabPos;
FVisibleTabs:= CalcTabPositions(TabStart, LastTabPos, MemBitmap.Canvas,
FirstIndex);
end;
FDoFix:= False;
{ draw background of tab area }
with MemBitmap.Canvas do begin
Brush.Bitmap:= BrushBitmap;
FillRect(Rect(0, 0, MemBitmap.Width, MemBitmap.Height));
Pen.Width:= 1;
if FOrientation = toDown then begin
Pen.Color:= clBtnShadow;
MoveTo(0, 0);
LineTo(MemBitmap.Width + 1, 0);
Pen.Color:= clWindowFrame;
MoveTo(0, 1);
LineTo(MemBitmap.Width + 1, 1);
end
else begin //toUp
Pen.Color:= clBtnHighLight;
MoveTo(0, MemBitmap.Height-1);
LineTo(MemBitmap.Width + 1, MemBitmap.Height-1);
Pen.Color:= clBtnFace;
MoveTo(0, MemBitmap.Height-2);
LineTo(MemBitmap.Width + 1, MemBitmap.Height-2);
end;
end;
if FOrientation = toDown then Y:= 0 else Y:= MemBitmap.Height - FTabHeight;
for Tab:= 0 to TabPositions.Count - 1 do
begin
Pointer(TabPos):= TabPositions[Tab];
isFirst:= Tab = 0;
isLast:= Tab = VisibleTabs - 1;
isSelected:= Tab + FirstIndex = TabIndex;
isPrevSelected:= (Tab + FirstIndex) - 1 = TabIndex;
{ Rule: every tab paints its leading edge, only the last tab paints a
trailing edge }
Trailing:= etNone;
if isLast then begin
if isSelected then Trailing:= etLastIsSel
else Trailing:= etLastNotSel;
end;
if isFirst then begin
if isSelected then Leading:= etFirstIsSel
else Leading:= etFirstNotSel;
end
else begin { not first }
if isPrevSelected then Leading:= etSelToNotSel
else if isSelected then Leading:= etNotSelToSel
else Leading:= etNotSelToNotSel;
end;
{ draw leading edge }
if Leading <> etNone then
PaintEdge(TabPos.StartPos - EdgeWidth, Y, FTabHeight - 1, Leading);
{ set up the canvas }
R:= Rect(TabPos.StartPos, Y, TabPos.StartPos + TabPos.Size, Y+FTabHeight);
with MemBitmap.Canvas do begin
if isSelected then Brush.Color:= SelectedColor
else Brush.Color:= UnselectedColor;
ExtTextOut(Handle, TabPos.StartPos, 2, ETO_OPAQUE, @R, nil, 0, nil);
end;
{ restore font for drawing the text }
MemBitmap.Canvas.Font:= Self.Canvas.Font;
{ Owner }
if (FStyle = tsOwnerDraw) then
DrawTab(MemBitmap.Canvas, R, Tab + FirstIndex, isSelected)
else begin
with MemBitmap.Canvas do begin
Inc(R.Top, 2);
if FOrientation = toUp then Inc(R.Top);
DrawText(Handle, PChar(Tabs[Tab + FirstIndex]),
Length(Tabs[Tab + FirstIndex]), R, DT_CENTER);
end;
end;
{ draw trailing edge }
if Trailing <> etNone then
PaintEdge(TabPos.StartPos + TabPos.Size, y, FTabHeight - 1, Trailing);
{ draw connecting lines above and below the text }
if Orientation = toDown then with MemBitmap.Canvas do begin
Pen.Color:= clWindowFrame;
MoveTo(TabPos.StartPos, FTabHeight - 1);
LineTo(TabPos.StartPos + TabPos.Size, FTabHeight - 1);
if isSelected then begin
Pen.Color:= clBtnShadow;
MoveTo(TabPos.StartPos, FTabHeight - 2);
LineTo(TabPos.StartPos + TabPos.Size, FTabHeight - 2);
end
else begin
Pen.Color:= clWindowFrame;
MoveTo(TabPos.StartPos, 1);
LineTo(TabPos.StartPos + TabPos.Size, 1);
Pen.Color:= clBtnShadow;
MoveTo(TabPos.StartPos, 0);
LineTo(TabPos.StartPos + TabPos.Size + 1, 0);
end;
end {if with}
else with MemBitmap.Canvas do begin //toUp
Pen.Color:= clWindowFrame;
MoveTo(TabPos.StartPos, MemBitmap.Height - FTabHeight + 0);
LineTo(TabPos.StartPos + TabPos.Size, MemBitmap.Height - FTabHeight + 0);
if isSelected then begin
Pen.Color:= clBtnHighlight;
MoveTo(TabPos.StartPos, MemBitmap.Height - FTabHeight + 1);
LineTo(TabPos.StartPos + TabPos.Size+1, MemBitmap.Height - FTabHeight + 1);
end
else begin
Pen.Color:= clBtnFace;
MoveTo(TabPos.StartPos-1, MemBitmap.Height - 2);
LineTo(TabPos.StartPos + TabPos.Size, MemBitmap.Height - 2);
Pen.Color:= clBtnHighLight;
MoveTo(TabPos.StartPos, MemBitmap.Height - 1);
LineTo(TabPos.StartPos + TabPos.Size + 1, MemBitmap.Height - 1);
end;
end;
end;
{ draw onto the screen }
Canvas.Draw(0, 0, MemBitmap);
end;
procedure TNewTabset.CreateEdgeParts;
var
H: Integer;
Working: TBitmap;
EdgePart: TEdgePart;
MaskColor: TColor;
procedure DrawUL(Canvas: TCanvas);
begin
if FOrientation = toDown then with Canvas do begin
Pen.Color:= clBtnShadow;
PolyLine([Point(0, 0), Point(EdgeWidth + 1, 0)]);
Pen.Color:= UnselectedColor;
Brush.Color:= UnselectedColor;
Polygon([Point(3,1), Point(EdgeWidth - 1, H), Point(EdgeWidth, H),
Point(EdgeWidth, 1), Point(3, 1)]);
Pen.Color:= clWindowFrame;
PolyLine([Point(0, 1), Point(EdgeWidth + 1, 1), Point(3, 1),
Point(EdgeWidth - 1, H), Point(EdgeWidth, H)]);
end
else with Canvas do begin //ToUp
Pen.Color:= clBtnHighLight;
PolyLine([Point(0, H), Point(EdgeWidth + 1, H)]);
Pen.Color:= UnselectedColor;
Brush.Color:= UnselectedColor;
Polygon([Point(3,H-1), Point(EdgeWidth - 1, 0), Point(EdgeWidth, 0),
Point(EdgeWidth, H-1), Point(3, H-1)]);
Pen.Color:= clBtnFace;
PolyLine([Point(0, H-1), Point(EdgeWidth + 1, H-1)]);
Pen.Color:= clWindowFrame;
PolyLine([Point(3, H-1),
Point(EdgeWidth - 1, 0), Point(EdgeWidth, 0)]);
end;
end;
procedure DrawSR(Canvas: TCanvas);
begin
if FOrientation = toDown then with Canvas do begin
Pen.Color:= SelectedColor;
Brush.Color:= SelectedColor;
Polygon([Point(EdgeWidth - 3, 1), Point(2, H), Point(0, H),
Point(0, 0), Point(EdgeWidth + 1, 0)]);
Pen.Color:= clBtnShadow;
PolyLine([Point(EdgeWidth - 3, 0), Point(EdgeWidth + 1, 0),
Point(EdgeWidth - 3, 1), Point(1, H), Point(0, H - 2)]);
Pen.Color:= clWindowFrame;
PolyLine([Point(EdgeWidth, 1), Point(EdgeWidth - 2, 1), Point(2, H),
Point(-1, H)]);
end
else with Canvas do begin //toUp
Pen.Color:= SelectedColor;
Brush.Color:= SelectedColor;
Polygon([Point(EdgeWidth - 3, H-1), Point(2, 0), Point(0, 0),
Point(0, H), Point(EdgeWidth + 1, H)]);
Pen.Color:= clBtnShadow;
PolyLine([Point(EdgeWidth - 3, H-1), Point(1, 0), Point(0, 2)]);
Pen.Color:= clBtnHighLight;
PolyLine([Point(EdgeWidth - 3, H), Point(EdgeWidth + 1, H),
Point(EdgeWidth - 3, H-1)]);
Pen.Color:= clWindowFrame;
PolyLine([Point(EdgeWidth, H-1), Point(EdgeWidth - 2, H-1), Point(2, 0),
Point(-1, 0)]);
Pen.Color:= clBtnFace;
PolyLine([Point(EdgeWidth, H-1), Point(EdgeWidth - 2, H-1)]);
end;
end;
procedure DrawSL(Canvas: TCanvas);
begin
if FOrientation = toDown then with Canvas do begin
Pen.Color:= SelectedColor;
Brush.Color:= SelectedColor;
Polygon([Point(3, 0), Point(EdgeWidth - 1, H), Point(EdgeWidth, H),
Point(EdgeWidth, 0), Point(3, 0)]);
Pen.Color:= clBtnShadow;
PolyLine([Point(0, 0), Point(4, 0)]);
Pen.Color:= clBtnHighlight;
PolyLine([Point(4, 1), Point(EdgeWidth, H + 1)]);
Pen.Color:= clWindowFrame;
PolyLine([Point(0, 1), Point(3, 1), Point(EdgeWidth - 1, H),
Point(EdgeWidth, H)]);
end
else with Canvas do begin //toUp
Pen.Color:= SelectedColor;
Brush.Color:= SelectedColor;
Polygon([Point(3, H), Point(EdgeWidth - 1, 0), Point(EdgeWidth, 0),
Point(EdgeWidth, H), Point(3, H)]);
Pen.Color:= clBtnHighLight;
PolyLine([Point(0, H), Point(4, H)]);
Pen.Color:= clBtnHighlight;
PolyLine([Point(4, H-1), Point(EdgeWidth, -1)]);
Pen.Color:= clBtnFace;
PolyLine([Point(0, H-1), Point(3, H-1)]);
Pen.Color:= clWindowFrame;
PolyLine([Point(3, H-1), Point(EdgeWidth - 1, 0),
Point(EdgeWidth, 0)]);
end;
end;
procedure DrawUR(Canvas: TCanvas);
begin
if FOrientation = toDown then with Canvas do begin
Pen.Color:= clBtnShadow;
PolyLine([Point(-1, 0), Point(EdgeWidth + 1, 0)]);
Pen.Color:= UnselectedColor;
Brush.Color:= UnselectedColor;
Polygon([Point(EdgeWidth - 3, 1), Point(1, H), Point(0, H),
Point(0, 1), Point(EdgeWidth - 3, 1)]);
{ workaround for bug in S3 driver }
Pen.Color:= clBtnShadow;
PolyLine([Point(-1, 0), Point(EdgeWidth + 1, 0)]);
Pen.Color:= clWindowFrame;
PolyLine([Point(0, 1), Point(EdgeWidth + 1, 1), Point(EdgeWidth - 2, 1),
Point(2, H), Point(-1, H)]);
end
else with Canvas do begin
Pen.Color:= clBtnShadow;
PolyLine([Point(-1, H), Point(EdgeWidth + 1, H)]);
Pen.Color:= UnselectedColor;
Brush.Color:= UnselectedColor;
Polygon([Point(EdgeWidth - 3, H-1), Point(1, 0), Point(0, 0),
Point(0, H-1), Point(EdgeWidth - 3, H-1)]);
{ workaround for bug in S3 driver }
Pen.Color:= clBtnHighLight;
PolyLine([Point(-1, H), Point(EdgeWidth + 1, H)]);
Pen.Color:= clBtnFace;
PolyLine([Point(0, H-1), Point(EdgeWidth + 1, H-1)]);
Pen.Color:= clWindowFrame;
PolyLine([Point(EdgeWidth - 2, H-1),
Point(2, 0), Point(-1, 0)]);
end;
end;
var
TempList: TImageList;
SaveHeight: Integer;
begin
MemBitmap.Canvas.Font:= Font;
{ Owner }
SaveHeight:= FTabHeight;
try
if FStyle = tsOwnerDraw then FTabHeight:= FOwnerDrawHeight
else FTabHeight:= MemBitmap.Canvas.TextHeight('T') + 4;
H:= FTabHeight - 1;
TempList:= TImageList.CreateSize(EdgeWidth, FTabHeight); {exceptions}
except
FTabHeight:= SaveHeight;
raise;
end;
ImageList.Free;
ImageList:= TempList;
Working:= TBitmap.Create;
try
Working.Width:= EdgeWidth;
Working.Height:= FTabHeight;
MaskColor:= clOlive;
for EdgePart:= Low(TEdgePart) to High(TEdgePart) do
begin
with Working.Canvas do
begin
Brush.Color:= MaskColor;
Brush.Style:= bsSolid;
FillRect(Rect(0, 0, EdgeWidth, FTabHeight));
end;
case EdgePart of
epSelectedLeft: DrawSL(Working.Canvas);
epUnselectedLeft: DrawUL(Working.Canvas);
epSelectedRight: DrawSR(Working.Canvas);
epUnselectedRight: DrawUR(Working.Canvas);
end;
ImageList.AddMasked(Working, MaskColor);
end;
finally
Working.Free;
end;
end;
procedure TNewTabset.PaintEdge(X, Y, H: Integer; Edge: TEdgeType);
begin
MemBitmap.Canvas.Brush.Color:= clWhite;
MemBitmap.Canvas.Font.Color:= clBlack;
case Edge of
etFirstIsSel:
ImageList.Draw(MemBitmap.Canvas, X, Y, Ord(epSelectedLeft));
etLastIsSel:
ImageList.Draw(MemBitmap.Canvas, X, Y, Ord(epSelectedRight));
etFirstNotSel:
ImageList.Draw(MemBitmap.Canvas, X, Y, Ord(epUnselectedLeft));