File: extendedtabcontrols.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (860 lines) | stat: -rw-r--r-- 24,471 bytes parent folder | download | duplicates (6)
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
unit ExtendedTabControls;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, math,
  // LCL
  ComCtrls, Controls, Toolwin, ImgList, Graphics, Menus, Forms,
  // LazUtils
  LazLoggerBase;

type

  TTabControlToolBarSide = (tsNone, tsLeft, tsRight);

  { TExtendedTabToolbar }

  TExtendedTabToolbar = class(TToolBar)
  protected
    FVertical: Boolean;
    function IsVertical: Boolean; override;
    procedure Loaded; override;
  public
    constructor Create(TheOwner: TComponent); override;
    procedure GetChildren({%H-}Proc: TGetChildProc; {%H-}Root: TComponent); override;
  end;

  { TExtendedTabToolButton }

  TExtendedTabToolButton = class(TToolButton)
  protected
    procedure Loaded; override;
  end;

  TCustomExtendedTabControl = class;

  { TToolbarWrapper }

  TToolbarWrapper = class(TPersistent)
  private
    FOwner: TCustomExtendedTabControl;
    function ToolBar: TToolBar;
    function GetButton(Index: Integer): TToolButton;
    function GetButtonCount: Integer;
    function GetButtonList: TList;
    function GetEdgeInner: TEdgeStyle;
    function GetEdgeOuter: TEdgeStyle;
    function GetEnabled: Boolean;
    function GetFEdgeBorders: TEdgeBorders;
    function GetFlat: Boolean;
    function GetFont: TFont;
    function GetHotImages: TCustomImageList;
    function GetImages: TCustomImageList;
    function GetIndent: Integer;
    function GetList: Boolean;
    function GetOnClick: TNotifyEvent;
    function GetOnContextPopup: TContextPopupEvent;
    function GetOnDblClick: TNotifyEvent;
    function GetPopupMenu: TPopupMenu;
    function GetRowCount: Integer;
    function GetShowCaptions: Boolean;
    function GetShowHint: Boolean;
    function GetWrapable: Boolean;
    procedure SetEdgeBorders(AValue: TEdgeBorders);
    procedure SetEdgeInner(AValue: TEdgeStyle);
    procedure SetEdgeOuter(AValue: TEdgeStyle);
    procedure SetEnabled(AValue: Boolean);
    procedure SetFlat(AValue: Boolean);
    procedure SetFont(AValue: TFont);
    procedure SetHotImages(AValue: TCustomImageList);
    procedure SetImages(AValue: TCustomImageList);
    procedure SetIndent(AValue: Integer);
    procedure SetList(AValue: Boolean);
    procedure SetOnClick(AValue: TNotifyEvent);
    procedure SetOnContextPopup(AValue: TContextPopupEvent);
    procedure SetOnDblClick(AValue: TNotifyEvent);
    procedure SetPopupMenu(AValue: TPopupMenu);
    procedure SetShowCaptions(AValue: Boolean);
    procedure SetShowHint(AValue: Boolean);
    procedure SetWrapable(AValue: Boolean);
  public
    constructor Create(AnAdvTabControl: TCustomExtendedTabControl);
    procedure AcceptButton(AToolButton: TExtendedTabToolButton);
    property ButtonCount: Integer read GetButtonCount;
    property Buttons[Index: Integer]: TToolButton read GetButton;
    property ButtonList: TList read GetButtonList;
    property RowCount: Integer read GetRowCount;
  published
    property EdgeBorders: TEdgeBorders   read GetFEdgeBorders   write SetEdgeBorders  default [ebLeft, ebTop, ebRight, ebBottom];
    property EdgeInner: TEdgeStyle       read GetEdgeInner      write SetEdgeInner    default esRaised;
    property EdgeOuter: TEdgeStyle       read GetEdgeOuter      write SetEdgeOuter    default esLowered;
    property Enabled: Boolean            read GetEnabled        write SetEnabled      default True;
    property Flat: Boolean               read GetFlat           write SetFlat         default True;
    property Font: TFont                 read GetFont           write SetFont;
    property HotImages: TCustomImageList read GetHotImages      write SetHotImages;
    property Images: TCustomImageList    read GetImages         write SetImages;
    property Indent: Integer             read GetIndent         write SetIndent       default 1;
    property List: Boolean               read GetList           write SetList         default False;
    property PopupMenu: TPopupMenu       read GetPopupMenu      write SetPopupMenu;
    property ShowCaptions: Boolean       read GetShowCaptions   write SetShowCaptions default False;
    property ShowHint: Boolean           read GetShowHint       write SetShowHint;
    property Wrapable: Boolean           read GetWrapable       write SetWrapable     default True;
    property OnClick: TNotifyEvent       read GetOnClick        write SetOnClick;
    property OnContextPopup: TContextPopupEvent read GetOnContextPopup write SetOnContextPopup;
    property OnDblClick: TNotifyEvent    read GetOnDblClick     write SetOnDblClick;
  end;


  TCustomExtendedTabSheet = class;

  { TExtendedInternalCustomPage }

  TExtendedInternalCustomPage = class(TCustomPage)
  protected
  public
    RealPage: TCustomPage; // optional TCustomExtendedTabSheet
    destructor Destroy; override;
  end;

  { TExtendedInternalTabControl
    Internal TabControl that displays the tabs
  }

  TExtendedInternalTabControl = class(TNoteBookStringsTabControl)
  protected
    function GetPageClass: TCustomPageClass; override; // TExtendedInternalCustomPage
  end;

  { TExtendedTabControlNoteBookStrings
    List of Tabs (and pages)
    TCustomExtendedTabControl.Tabs
  }

  TExtendedTabControlNoteBookStrings = class(TTabControlNoteBookStrings)
  private
    FShowToolBar: TTabControlToolBarSide;
    FToolBar: TExtendedTabToolbar;
    procedure SetShowToolBar(AValue: TTabControlToolBarSide);
    procedure ToolbarResized(Sender: TObject);
  protected
    function GetInternalTabControllClass: TNoteBookStringsTabControlClass; override; // TExtendedInternalTabControl
    procedure SetToolbar(AToolBar: TExtendedTabToolbar);
    procedure Notification(AComponent: TComponent; Operation: TOperation);
    procedure NBPageChanged(Sender: TObject); override;
  public
    constructor Create(TheTabControl: TTabControl); override;
    destructor Destroy; override;
    function IndexOfPage(const APage: TCustomExtendedTabSheet): Integer;
    procedure Delete(Index: Integer); override;
    procedure TabControlBoundsChange; override;
    property ShowToolBar: TTabControlToolBarSide read FShowToolBar write SetShowToolBar;
    property ToolBar: TExtendedTabToolbar read FToolBar;
  end;


  { TCustomExtendedTabSheet }

  TCustomExtendedTabSheet = class(TCustomPage)
  private
    FInternalTabPage: TExtendedInternalCustomPage;
    procedure SetInternalTabPage(AValue: TExtendedInternalCustomPage);
  protected
    property InternalTabPage: TExtendedInternalCustomPage read FInternalTabPage write SetInternalTabPage;
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    //property TabControl: TCustomExtendedTabControl read GetTabControl write SetTabControl;
    //property TabIndex: Integer read GetTabIndex;
  end;

  TExtendedTabSheet = class(TCustomExtendedTabSheet)
  published
    property BorderWidth;
    property BiDiMode;
    property Caption;
    property ChildSizing;
    property ClientHeight;
    property ClientWidth;
    property Enabled;
    property Font;
    //property Height stored False;
    property ImageIndex;
    //property Left stored False;
    property OnContextPopup;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnHide;
    property OnMouseDown;
    property OnMouseEnter;
    property OnMouseLeave;
    property OnMouseMove;
    property OnMouseUp;
    property OnResize;
    property OnShow;
    property OnStartDrag;
    property PageIndex stored False;
    property ParentBiDiMode;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabVisible default True;
    //property Top stored False;
    //property Width stored False;
  end;

  { TCustomExtendedTabControl }

  TCustomExtendedTabControl = class(TTabControl)
  private
    FToolBarWrapper: TToolbarWrapper;
    function GetActiveTabSheet: TExtendedTabSheet;
    function GetShowToolBar: TTabControlToolBarSide;
    function GetTabSheet(Index: Integer): TExtendedTabSheet;
    procedure SetActivePageComponent(AValue: TCustomPage);
    procedure SetActiveTabSheet(AValue: TExtendedTabSheet);
    procedure SetShowToolBar(AValue: TTabControlToolBarSide);
  protected
    function AdvTabs: TExtendedTabControlNoteBookStrings;
    function CreateTabNoteBookStrings: TTabControlNoteBookStrings; override;

    //procedure AddRemovePageHandle({%H-}APage: TCustomPage); override; // prevent calling widgetset
    //procedure UpdateTabProperties; override;
    procedure InsertPage(APage: TCustomPage; Index: Integer); override;
    procedure RemovePage(Index: Integer); override;
    //PageRemoved // visible = false
    //DoSendPageIndex // prevent

    function  GetChildOwner: TComponent; override;
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;

    function GetPageClass: TCustomPageClass; override;
    function GetListClass: TNBBasePagesClass; override;
    property ActivePageComponent: TCustomPage write SetActivePageComponent;
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
    property ActivePage: TExtendedTabSheet read GetActiveTabSheet write SetActiveTabSheet; experimental; platform;
    property Pages[Index: Integer]: TExtendedTabSheet read GetTabSheet; experimental; platform;
    property ShowToolBar: TTabControlToolBarSide read GetShowToolBar write SetShowToolBar;
    property ToolBar: TToolbarWrapper read FToolBarWrapper;
    property OnChange; // Only pages // TODO: activate for tabs
  end;

  { TExtendedTabControl }

  TExtendedTabControl = class(TCustomExtendedTabControl)
  published
    property ShowToolBar;
    property ToolBar;
  end;

implementation

{ TExtendedInternalCustomPage }

destructor TExtendedInternalCustomPage.Destroy;
begin
  if RealPage <> nil then
    TCustomExtendedTabSheet(RealPage).InternalTabPage := nil;
  inherited Destroy;
end;

{ TCustomExtendedTabSheet }

procedure TCustomExtendedTabSheet.SetInternalTabPage(AValue: TExtendedInternalCustomPage);
begin
  if FInternalTabPage = AValue then Exit;
  if FInternalTabPage <> nil then
    FInternalTabPage.RealPage := nil;
  FInternalTabPage := AValue;
  if FInternalTabPage <> nil then
    FInternalTabPage.RealPage := Self;
end;

constructor TCustomExtendedTabSheet.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  BorderSpacing.Around := 1;
end;

destructor TCustomExtendedTabSheet.Destroy;
begin
  SetParent(nil);
  InternalTabPage := nil;
  inherited Destroy;
end;

{ TExtendedInternalTabControl }

function TExtendedInternalTabControl.GetPageClass: TCustomPageClass;
begin
  Result := TExtendedInternalCustomPage;
end;

{ TExtendedTabToolButton }

procedure TExtendedTabToolButton.Loaded;
begin
  inherited Loaded;
  if Parent is TExtendedTabControl then
    Parent := TExtendedTabControl(Parent).AdvTabs.ToolBar;
end;

{ TExtendedTabToolbar }

function TExtendedTabToolbar.IsVertical: Boolean;
begin
  Result := FVertical;
end;

procedure TExtendedTabToolbar.GetChildren(Proc: TGetChildProc; Root: TComponent);
begin
  // toolbuttons are streamed by tabcontrol. that way the designer can see them
end;

procedure TExtendedTabToolbar.Loaded;
begin
  inherited Loaded;
  if Parent is TExtendedTabControl then
    TExtendedTabControl(Parent).AdvTabs.SetToolbar(Self);
end;

constructor TExtendedTabToolbar.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  //ControlStyle := ControlStyle + [csDesignFixedBounds];
  ControlStyle := ControlStyle + [csNoDesignSelectable];
  Align := alCustom;
  AutoSize := True;
end;

{ TToolbarWrapper }

function TToolbarWrapper.GetEdgeInner: TEdgeStyle;
begin
  Result := ToolBar.EdgeInner;
end;

function TToolbarWrapper.ToolBar: TToolBar;
begin
  Result := FOwner.AdvTabs.ToolBar;
end;

function TToolbarWrapper.GetButton(Index: Integer): TToolButton;
begin
  Result := ToolBar.Buttons[Index];
end;

function TToolbarWrapper.GetButtonCount: Integer;
begin
  Result := ToolBar.ButtonCount;
end;

function TToolbarWrapper.GetButtonList: TList;
begin
  Result := ToolBar.ButtonList;
end;

function TToolbarWrapper.GetEdgeOuter: TEdgeStyle;
begin
  Result := ToolBar.EdgeOuter;
end;

function TToolbarWrapper.GetEnabled: Boolean;
begin
  Result := ToolBar.Enabled;
end;

function TToolbarWrapper.GetFEdgeBorders: TEdgeBorders;
begin
  Result := ToolBar.EdgeBorders;
end;

function TToolbarWrapper.GetFlat: Boolean;
begin
  Result := ToolBar.Flat;
end;

function TToolbarWrapper.GetFont: TFont;
begin
  Result := ToolBar.Font;
end;

function TToolbarWrapper.GetHotImages: TCustomImageList;
begin
  Result := ToolBar.HotImages;
end;

function TToolbarWrapper.GetImages: TCustomImageList;
begin
  Result := ToolBar.Images;
end;

function TToolbarWrapper.GetIndent: Integer;
begin
  Result := ToolBar.Indent;
end;

function TToolbarWrapper.GetList: Boolean;
begin
  Result := ToolBar.List;
end;

function TToolbarWrapper.GetOnClick: TNotifyEvent;
begin
  Result := ToolBar.OnClick;
end;

function TToolbarWrapper.GetOnContextPopup: TContextPopupEvent;
begin
  Result := ToolBar.OnContextPopup;
end;

function TToolbarWrapper.GetOnDblClick: TNotifyEvent;
begin
  Result := ToolBar.OnDblClick;
end;

function TToolbarWrapper.GetPopupMenu: TPopupMenu;
begin
  Result := ToolBar.PopupMenu;
end;

function TToolbarWrapper.GetRowCount: Integer;
begin
  Result := ToolBar.RowCount;
end;

function TToolbarWrapper.GetShowCaptions: Boolean;
begin
  Result := ToolBar.ShowCaptions;
end;

function TToolbarWrapper.GetShowHint: Boolean;
begin
  Result := ToolBar.ShowHint;
end;

function TToolbarWrapper.GetWrapable: Boolean;
begin
  Result := ToolBar.Wrapable;
end;

procedure TToolbarWrapper.SetEdgeBorders(AValue: TEdgeBorders);
begin
  ToolBar.EdgeBorders := AValue;
end;

procedure TToolbarWrapper.SetEdgeInner(AValue: TEdgeStyle);
begin
  ToolBar.EdgeInner := AValue;
end;

procedure TToolbarWrapper.SetEdgeOuter(AValue: TEdgeStyle);
begin
  ToolBar.EdgeOuter := AValue;
end;

procedure TToolbarWrapper.SetEnabled(AValue: Boolean);
begin
  ToolBar.Enabled := AValue;
end;

procedure TToolbarWrapper.SetFlat(AValue: Boolean);
begin
  ToolBar.Flat := AValue;
end;

procedure TToolbarWrapper.SetFont(AValue: TFont);
begin
  ToolBar.Font := AValue;
end;

procedure TToolbarWrapper.SetHotImages(AValue: TCustomImageList);
begin
  ToolBar.HotImages := AValue;
end;

procedure TToolbarWrapper.SetImages(AValue: TCustomImageList);
begin
  ToolBar.Images := AValue;
end;

procedure TToolbarWrapper.SetIndent(AValue: Integer);
begin
  ToolBar.Indent := AValue;
end;

procedure TToolbarWrapper.SetList(AValue: Boolean);
begin
  ToolBar.List := AValue;
end;

procedure TToolbarWrapper.SetOnClick(AValue: TNotifyEvent);
begin
  ToolBar.OnClick := AValue;
end;

procedure TToolbarWrapper.SetOnContextPopup(AValue: TContextPopupEvent);
begin
  ToolBar.OnContextPopup := AValue;
end;

procedure TToolbarWrapper.SetOnDblClick(AValue: TNotifyEvent);
begin
  ToolBar.OnDblClick := AValue;
end;

procedure TToolbarWrapper.SetPopupMenu(AValue: TPopupMenu);
begin
  ToolBar.PopupMenu := AValue;
end;

procedure TToolbarWrapper.SetShowCaptions(AValue: Boolean);
begin
  ToolBar.ShowCaptions := AValue;
end;

procedure TToolbarWrapper.SetShowHint(AValue: Boolean);
begin
  ToolBar.ShowHint := AValue;
end;

procedure TToolbarWrapper.SetWrapable(AValue: Boolean);
begin
  ToolBar.Wrapable := AValue;
end;

constructor TToolbarWrapper.Create(AnAdvTabControl: TCustomExtendedTabControl);
begin
  inherited Create;
  FOwner := AnAdvTabControl;
  ToolBar;
end;

procedure TToolbarWrapper.AcceptButton(AToolButton: TExtendedTabToolButton);
begin
  AToolButton.Parent := FOwner.AdvTabs.ToolBar;
end;

{ TExtendedTabControlNoteBookStrings }

procedure TExtendedTabControlNoteBookStrings.ToolbarResized(Sender: TObject);
begin
  TabControlBoundsChange;
end;

function TExtendedTabControlNoteBookStrings.GetInternalTabControllClass: TNoteBookStringsTabControlClass;
begin
  Result := TExtendedInternalTabControl;
end;

procedure TExtendedTabControlNoteBookStrings.SetToolbar(AToolBar: TExtendedTabToolbar);
begin
  if FToolBar <> nil then begin
    FToolBar.RemoveFreeNotification(TabControl);
    FreeAndNil(FToolBar);
  end;

  FToolBar := AToolBar;

  if FToolBar <> nil then
    FToolBar.FreeNotification(TabControl);
end;

procedure TExtendedTabControlNoteBookStrings.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  if (Operation = opRemove) and (AComponent = FToolBar) then
    FToolBar := nil;
end;

procedure TExtendedTabControlNoteBookStrings.NBPageChanged(Sender: TObject);
var
  p: TCustomPage;
begin
  p := TExtendedInternalCustomPage(NoteBook.Page[NoteBook.PageIndex]).RealPage;
  TExtendedTabControl(TabControl).ActivePageComponent := p;
end;


constructor TExtendedTabControlNoteBookStrings.Create(TheTabControl: TTabControl);
begin
  FToolBar := TExtendedTabToolbar.Create(TheTabControl.Owner);
  FToolBar.FreeNotification(TheTabControl);
  FToolBar.Parent := TheTabControl;
  FToolBar.OnResize := @ToolbarResized;

  inherited Create(TheTabControl);
end;

destructor TExtendedTabControlNoteBookStrings.Destroy;
begin
  inherited Destroy;
  SetToolbar(nil);
end;

function TExtendedTabControlNoteBookStrings.IndexOfPage(const APage: TCustomExtendedTabSheet): Integer;
begin
  Result := Count - 1;
  while (Result >= 0) and (TExtendedInternalCustomPage(Objects[Result]).RealPage <> APage) do
    dec(Result);
end;

procedure TExtendedTabControlNoteBookStrings.Delete(Index: Integer);
var
  p: TCustomPage;
begin
  p := TExtendedInternalCustomPage(Objects[Index]).RealPage;
  inherited Delete(Index);
  if p <> nil then begin
    p.Parent := nil;
    Application.ReleaseComponent(p);
  end;
end;

procedure TExtendedTabControlNoteBookStrings.SetShowToolBar(AValue: TTabControlToolBarSide);
begin
  if FShowToolBar = AValue then Exit;
  FShowToolBar := AValue;
  TabControlBoundsChange;
end;

procedure TExtendedTabControlNoteBookStrings.TabControlBoundsChange;
var
  NewTop, NewHeight, NewLeft, NewWidth, TBOffs: LongInt;
begin
  inherited TabControlBoundsChange;

  NoteBook.TabPosition:=TabControl.TabPosition;
  FToolBar.Visible := ShowToolBar <> tsNone;
  if FToolBar.Visible then
    FToolBar.ControlStyle := FToolBar.ControlStyle-[csNoDesignVisible]
  else
    FToolBar.ControlStyle := FToolBar.ControlStyle+[csNoDesignVisible];
  FToolBar.FVertical := TabPosition in [tpLeft,tpRight];

  case TabControl.TabPosition of
  tpTop,tpBottom:
    begin
      NewHeight:=TabControl.TabHeight;
      if NewHeight<=0 then
        NewHeight:=NoteBook.GetMinimumTabHeight;
      NewHeight:=min(TabControl.ClientHeight,NewHeight);

      if FToolBar.Visible then begin
        FToolBar.Constraints.MaxHeight := Max(0, NewHeight - 2);
        FToolBar.Constraints.MinHeight := Max(0, NewHeight - 2);
        FToolBar.Constraints.MaxWidth  := 0;
        FToolBar.Constraints.MinWidth  := 0;
      end;

      if TabControl.TabPosition=tpTop then begin
        NewTop := 0;
        TBOffs := 0;
      end
      else begin
        NewTop := TabControl.ClientHeight - NewHeight;
        TBOffs := 2;
      end;

      NewLeft := 0;
      NewWidth := TabControl.ClientWidth;

      case ShowToolBar of
        tsLeft: begin
            NewLeft := FToolBar.Width;
            NewWidth := Max(TabControl.ClientWidth div 2, NewWidth - FToolBar.Width);
            FToolBar.SetBounds(0, NewTop+TBOffs, FToolBar.Width, NewHeight - 2 + TBOffs);
          end;
        tsRight: begin
            NewWidth := Max(TabControl.ClientWidth div 2, TabControl.ClientWidth - FToolBar.Width);
            FToolBar.SetBounds(NewWidth, NewTop+TBOffs, FToolBar.Width, NewHeight - 2 + TBOffs);
          end;
      end;
      NoteBook.SetBounds(NewLeft, NewTop, NewWidth ,NewHeight);
    end;

  tpLeft,tpRight:
    begin
      NewWidth := TabControl.TabWidth;
      if NewWidth<=0 then
        NewWidth:=NoteBook.GetMinimumTabWidth;
      NewWidth:=Min(TabControl.ClientWidth,NewWidth);

      if FToolBar.Visible then begin
        FToolBar.Constraints.MaxHeight := 0;
        FToolBar.Constraints.MinHeight := 0;
        FToolBar.Constraints.MaxWidth  := Max(0, NewWidth-2);
        FToolBar.Constraints.MinWidth  := Max(0, NewWidth-2);
      end;

      if TabControl.TabPosition=tpLeft then begin
        NewLeft := 0;
        TBOffs := 0;
      end
      else begin
        NewLeft := TabControl.ClientWidth - NewWidth;
        TBOffs := 2;
      end;

      NewTop := 0;
      NewHeight := TabControl.ClientHeight;

      case ShowToolBar of
        tsLeft: begin
            NewTop := Max(TabControl.ClientHeight div 2, FToolBar.Height);
            NewHeight := NewHeight - FToolBar.Height;
            FToolBar.SetBounds(NewLeft+TBOffs, 0, NewWidth - 2 + TBOffs, FToolBar.Height);
          end;
        tsRight: begin
            NewHeight := Max(TabControl.ClientHeight div 2, TabControl.ClientWidth - FToolBar.Height);
            FToolBar.SetBounds(NewLeft+TBOffs, NewHeight, NewWidth - 2 + TBOffs, FToolBar.Height);
          end;
      end;

      NoteBook.SetBounds(NewLeft, NewTop, NewWidth ,NewHeight);

    end;
  end;

  TabControl.Invalidate;
end;

{ TExtendedTabControl }

function TCustomExtendedTabControl.GetShowToolBar: TTabControlToolBarSide;
begin
  Result := AdvTabs.ShowToolBar;
end;

function TCustomExtendedTabControl.GetTabSheet(Index: Integer): TExtendedTabSheet;
begin
  Result:=TExtendedTabSheet(inherited Page[Index]);
end;

function TCustomExtendedTabControl.GetActiveTabSheet: TExtendedTabSheet;
begin
  Result:=TExtendedTabSheet(inherited ActivePageComponent);
end;

procedure TCustomExtendedTabControl.SetActivePageComponent(AValue: TCustomPage);
var
  i: Integer;
begin
  inherited ActivePageComponent := AValue;
  for i := 0 to PageCount - 1 do
    Page[i].Visible := Page[i] = AValue;
end;

procedure TCustomExtendedTabControl.SetActiveTabSheet(AValue: TExtendedTabSheet);
begin
  ActivePageComponent := AValue;
end;

procedure TCustomExtendedTabControl.SetShowToolBar(AValue: TTabControlToolBarSide);
begin
  AdvTabs.ShowToolBar := AValue;
end;

function TCustomExtendedTabControl.AdvTabs: TExtendedTabControlNoteBookStrings;
begin
  Result := TExtendedTabControlNoteBookStrings(Tabs);
end;

function TCustomExtendedTabControl.CreateTabNoteBookStrings: TTabControlNoteBookStrings;
begin
  Result := TExtendedTabControlNoteBookStrings.Create(Self);
end;

procedure TCustomExtendedTabControl.InsertPage(APage: TCustomPage; Index: Integer);
begin
  inherited InsertPage(APage, Index);
  if Index >= Tabs.Count then
    Index := Tabs.Add(APage.Caption)
  else
    Tabs.Insert(Index, APage.Caption);
  TCustomExtendedTabSheet(APage).InternalTabPage := TExtendedInternalCustomPage(Tabs.Objects[Index]);
end;

procedure TCustomExtendedTabControl.RemovePage(Index: Integer);
var
  i: Integer;
  ThePage: TCustomExtendedTabSheet;
begin
  ThePage := TCustomExtendedTabSheet(CustomPage(Index));
  if ThePage.InternalTabPage <> nil then begin
    i := AdvTabs.IndexOfPage(ThePage);
    ThePage.InternalTabPage := nil;
    if i >= 0 then
      Tabs.Delete(i);
  end;
  inherited RemovePage(Index);
end;

function TCustomExtendedTabControl.GetChildOwner: TComponent;
begin
  Result := inherited GetChildOwner;
  //Result := Self;
end;

procedure TCustomExtendedTabControl.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
  I : Integer;
  Control : TControl;
begin
  inherited GetChildren(Proc, Root);

  //if Owner = Root then
  //  Proc(AdvTabs.ToolBar);


  if (Owner <> Root) or (AdvTabs = nil) or (AdvTabs.ToolBar = nil) then
    exit;
  for I := 0 to AdvTabs.ToolBar.ControlCount-1 do
  begin
    Control := AdvTabs.ToolBar.Controls[i];
    Proc(Control);
  end;
end;

procedure TCustomExtendedTabControl.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if AdvTabs <> nil then
    AdvTabs.Notification(AComponent, Operation);
end;

function TCustomExtendedTabControl.GetPageClass: TCustomPageClass;
begin
  Result := TExtendedTabSheet;
end;

function TCustomExtendedTabControl.GetListClass: TNBBasePagesClass;
begin
  Result := TNBPages;
end;

constructor TCustomExtendedTabControl.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  FToolBarWrapper := TToolbarWrapper.Create(Self);
end;

destructor TCustomExtendedTabControl.Destroy;
begin
  inherited Destroy;
  FreeAndNil(FToolBarWrapper);
end;

end.