1
{%MainUnit ../extctrls.pp}
2
{******************************************************************************
4
******************************************************************************
6
*****************************************************************************
8
* This file is part of the Lazarus Component Library (LCL) *
10
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
11
* for details about the copyright. *
13
* This program is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
17
*****************************************************************************
20
{******************************************************************************
22
******************************************************************************}
24
{------------------------------------------------------------------------------
26
------------------------------------------------------------------------------}
27
constructor TUNBPages.Create(thePageList: TListWithEvent;
28
theUNotebook: TUntabbedNotebook);
31
fPageList := thePageList;
32
fPageList.OnChange:=@PageListChange;
33
fUNotebook := theUNotebook;
36
{------------------------------------------------------------------------------
37
procedure TUNBPages.PageListChange(Ptr: Pointer; AnAction: TListNotification);
38
------------------------------------------------------------------------------}
39
procedure TUNBPages.PageListChange(Ptr: Pointer; AnAction: TListNotification);
43
{ if (AnAction=lnAdded) then
45
APage:=TObject(Ptr) as TUNBPage;
46
if not (pfInserting in APage.FFlags) then
47
APage.Parent:=fNotebook;
51
{------------------------------------------------------------------------------
53
------------------------------------------------------------------------------}
54
function TUNBPages.Get(Index: Integer): string;
56
if (Index<0) or (Index>=fPageList.Count) then
57
RaiseGDBException('TUNBPages.Get Index out of bounds');
58
Result := TUNBPage(fPageList[Index]).Caption;
61
{------------------------------------------------------------------------------
63
------------------------------------------------------------------------------}
64
function TUNBPages.GetCount: Integer;
66
Result := fPageList.Count;
69
{------------------------------------------------------------------------------
71
------------------------------------------------------------------------------}
72
function TUNBPages.GetObject(Index: Integer): TObject;
74
if (Index<0) or (Index>=fPageList.Count) then
75
RaiseGDBException('TUNBPages.GetObject Index out of bounds');
76
Result := TUNBPage(fPageList[Index]);
79
{------------------------------------------------------------------------------
81
------------------------------------------------------------------------------}
82
procedure TUNBPages.Put(Index: Integer; const S: String);
84
if (Index<0) or (Index>=fPageList.Count) then
85
RaiseGDBException('TUNBPages.Put Index out of bounds');
86
//debugln(['TUNBPages.Put ',DbgSName(FNotebook),' ',Index,' S="',S,'"']);
87
TUNBPage(fPageList[Index]).Caption := S;
90
{------------------------------------------------------------------------------
92
------------------------------------------------------------------------------}
93
procedure TUNBPages.Clear;
95
while fPageList.Count>0 do
96
Delete(fPageList.Count-1);
99
{------------------------------------------------------------------------------
101
------------------------------------------------------------------------------}
102
procedure TUNBPages.Delete(Index: Integer);
106
// Make sure Index is in the range of valid pages to delete
107
if (Index < 0) or (Index >= fPageList.Count) then Exit;
109
APage := TCustomPage(fPageList[Index]);
113
Application.ReleaseComponent(APage);
116
{------------------------------------------------------------------------------
118
------------------------------------------------------------------------------}
119
procedure TUNBPages.Insert(Index: Integer; const S: String);
122
NewOwner: TComponent;
124
NewOwner := FUNotebook.Owner;
125
if NewOwner = nil then
126
NewOwner := FUNotebook;
127
NewPage := TUNBPage.Create(NewOwner);
128
NewPage.Caption := S;
130
FUNoteBook.InsertPage(NewPage,Index);
133
{******************************************************************************
135
******************************************************************************}
137
function TUntabbedNotebook.GetPage(AIndex: Integer): TUNBPage;
139
if (AIndex < 0) or (AIndex >= FPageList.Count) then
140
RaiseGDBException('TUntabbedNotebook.GetCustomPage Index out of bounds');
141
Result := TUNBPage(FPageList.Items[AIndex]);
144
function TUntabbedNotebook.GetPageIndex: Integer;
146
Result := FPageIndex;
149
procedure TUntabbedNotebook.InsertPage(APage: TUNBPage; Index: Integer);
151
if FPageList.IndexOf(APage) >= 0 then Exit;
153
FPageList.Insert(Index, APage);
155
APage.Parent := Self;
156
APage.Align := alClient;
157
APage.Visible := False;
158
APage.ControlStyle := APage.ControlStyle + [csNoDesignVisible];
160
if PageIndex = -1 then SetPageIndex(Index);
163
procedure TUntabbedNotebook.SetPageIndex(AValue: Integer);
165
if (AValue < -1) or (AValue >= Pages.Count) then Exit;
166
if FPageIndex = AValue then exit;
168
// Hide the previously shown page
169
if (FPageIndex >= 0) and (FPageIndex < Pages.Count) then
171
Page[FPageIndex].ControlStyle :=
172
Page[FPageIndex].ControlStyle + [csNoDesignVisible];
173
Page[FPageIndex].Visible := False;
176
// Update the property
177
FPageIndex := AValue;
179
// And show the new one
180
if Assigned(Page[FPageIndex].FOnBeforeShow) then Page[FPageIndex].FOnBeforeShow(Self, Page[FPageIndex], FPageIndex); // OnBeforeShow event
181
Page[FPageIndex].Visible := True;
182
Page[FPageIndex].ControlStyle :=
183
Page[FPageIndex].ControlStyle - [csNoDesignVisible];
184
Page[FPageIndex].Align := alClient;
187
{------------------------------------------------------------------------------
188
TUntabbedNotebook Constructor
189
------------------------------------------------------------------------------}
190
constructor TUntabbedNotebook.Create(TheOwner: TComponent);
194
inherited Create(TheOwner);
196
FPageList := TListWithEvent.Create;
198
FPages := TUNBPages.Create(FPageList, Self);
200
ControlStyle := []; // do not add csAcceptsControls
204
lSize := GetControlClassDefaultSize();
205
SetInitialBounds(0, 0, lSize.CX, lSize.CY);
208
destructor TUntabbedNotebook.Destroy;