mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-09 12:35:55 +02:00
LCL: TTAbControl, refactor. There where 2 lists for one purpose. Hiding the 2nd (private use only, no compatibility issues expected) within the 1st.
git-svn-id: trunk@42595 -
This commit is contained in:
parent
32a6a28ad6
commit
04045467f0
@ -270,9 +270,13 @@ type
|
||||
function GetCount: Integer; override;
|
||||
function GetObject(Index: Integer): TObject; override;
|
||||
procedure Put(Index: Integer; const S: String); override;
|
||||
function IndexOfPage(const AnObject: TPersistent): Integer;
|
||||
procedure InsertPage(Index: Integer; const APage: TCustomPage);
|
||||
procedure DeletePage(Index: Integer);
|
||||
function GetPage(Index: Integer): TCustomPage;
|
||||
public
|
||||
constructor Create(thePageList: TListWithEvent;
|
||||
theNotebook: TCustomTabControl);
|
||||
constructor Create(theNotebook: TCustomTabControl);
|
||||
destructor Destroy; override;
|
||||
procedure Clear; override;
|
||||
procedure Delete(Index: Integer); override;
|
||||
procedure Insert(Index: Integer; const S: String); override;
|
||||
@ -326,7 +330,7 @@ type
|
||||
FOwnerDraw: Boolean;
|
||||
FPageIndex: Integer;
|
||||
FPageIndexOnLastChange: integer;// needed for unique OnChange events
|
||||
FPageList: TList; // TListWithEvent of TCustomPage
|
||||
// FPageList: TList; // TListWithEvent of TCustomPage
|
||||
FRaggedRight: Boolean;
|
||||
FScrollOpposite: Boolean;
|
||||
FShowTabs: Boolean;
|
||||
|
@ -17,15 +17,20 @@
|
||||
{------------------------------------------------------------------------------
|
||||
TNBPages Constructor
|
||||
------------------------------------------------------------------------------}
|
||||
constructor TNBPages.Create(thePageList: TListWithEvent;
|
||||
theNotebook: TCustomTabControl);
|
||||
constructor TNBPages.Create(theNotebook: TCustomTabControl);
|
||||
begin
|
||||
inherited Create;
|
||||
FPageList := thePageList;
|
||||
FPageList := TListWithEvent.Create;
|
||||
FPageList.OnChange:=@PageListChange;
|
||||
FNotebook := theNotebook;
|
||||
end;
|
||||
|
||||
destructor TNBPages.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
FreeAndNil(FPageList);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
procedure TNBPages.PageListChange(Ptr: Pointer; AnAction: TListNotification);
|
||||
------------------------------------------------------------------------------}
|
||||
@ -80,6 +85,26 @@ begin
|
||||
TCustomPage(FPageList[Index]).Caption := S;
|
||||
end;
|
||||
|
||||
function TNBPages.IndexOfPage(const AnObject: TPersistent): Integer;
|
||||
begin
|
||||
Result := FPageList.IndexOf(AnObject);
|
||||
end;
|
||||
|
||||
procedure TNBPages.InsertPage(Index: Integer; const APage: TCustomPage);
|
||||
begin
|
||||
FPageList.Insert(Index, APage);
|
||||
end;
|
||||
|
||||
procedure TNBPages.DeletePage(Index: Integer);
|
||||
begin
|
||||
FPageList.Delete(Index);
|
||||
end;
|
||||
|
||||
function TNBPages.GetPage(Index: Integer): TCustomPage;
|
||||
begin
|
||||
Result := TCustomPage(FPageList.Items[Index]);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
TNBPages Clear
|
||||
------------------------------------------------------------------------------}
|
||||
@ -210,10 +235,7 @@ begin
|
||||
fCompStyle := csNoteBook;
|
||||
|
||||
if not FUnPaged then
|
||||
begin
|
||||
FPageList := TListWithEvent.Create;
|
||||
FAccess := TNBPages.Create(TListWithEvent(FPageList), Self);
|
||||
end;
|
||||
FAccess := TNBPages.Create(Self);
|
||||
|
||||
FImageListChangeLink := TChangeLink.Create;
|
||||
FImageListChangeLink.OnChange := @DoImageListChange;
|
||||
@ -293,7 +315,6 @@ begin
|
||||
FImageListChangeLink.Free;
|
||||
Pages.Clear;
|
||||
FreeAndNil(FAccess);
|
||||
FreeAndNil(FPageList);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -355,7 +376,7 @@ begin
|
||||
if FUnPaged then
|
||||
Result := -1
|
||||
else
|
||||
Result:=FPageList.IndexOf(APage);
|
||||
Result:=TNBPages(FAccess).IndexOfPage(APage);
|
||||
end;
|
||||
|
||||
function TCustomTabControl.CustomPage(Index: integer): TCustomPage;
|
||||
@ -500,7 +521,7 @@ end;
|
||||
procedure TCustomTabControl.SetActivePageComponent(const AValue: TCustomPage);
|
||||
begin
|
||||
if not FUnPaged then
|
||||
PageIndex := FPageList.IndexOf(AValue);
|
||||
PageIndex := IndexOf(AValue);
|
||||
end;
|
||||
|
||||
procedure TCustomTabControl.SetImages(const AValue: TCustomImageList);
|
||||
@ -581,7 +602,7 @@ begin
|
||||
else
|
||||
NewZPosition := -1;
|
||||
Include(APage.FFlags, pfInserting);
|
||||
FPageList.Insert(Index, APage);
|
||||
TNBPages(FAccess).InsertPage(Index, APage);
|
||||
Exclude(APage.FFlags, pfInserting);
|
||||
APage.Parent := Self;
|
||||
if NewZPosition >= 0 then
|
||||
@ -728,7 +749,7 @@ begin
|
||||
// Make sure Index is in the range of valid pages to delete
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
DebugLn(['TCustomTabControl.RemovePage A ',dbgsName(Self),' Index=',Index,
|
||||
' FPageList.Count=',PageCount,' PageIndex=',PageIndex]);
|
||||
' FAccess.Count=',PageCount,' PageIndex=',PageIndex]);
|
||||
{$ENDIF}
|
||||
if not FUnPaged and (Index >= 0) and (Index < PageCount) then
|
||||
begin
|
||||
@ -737,13 +758,13 @@ begin
|
||||
if HandleAllocated then
|
||||
AddRemovePageHandle(APage);
|
||||
PageRemoved(Index);
|
||||
FPageList.Delete(Index);
|
||||
TNBPages(FAccess).DeletePage(Index);
|
||||
APage.Parent:=nil;
|
||||
if FPageIndex >= Index then
|
||||
Dec(FPageIndex);
|
||||
end;
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
DebugLn(['TCustomTabControl.RemovePage END ',dbgsName(Self),' Index=',Index,' FPageList.Count=',FPageList.Count,' PageIndex=',PageIndex]);
|
||||
DebugLn(['TCustomTabControl.RemovePage END ',dbgsName(Self),' Index=',Index,' FAccess.Count=',FAccess.Count,' PageIndex=',PageIndex]);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
@ -780,9 +801,9 @@ end;
|
||||
function TCustomTabControl.GetPageCount: integer;
|
||||
begin
|
||||
if FUnPaged then
|
||||
Result := FAccess.Count
|
||||
Result := 0
|
||||
else
|
||||
Result := FPageList.Count;
|
||||
Result := FAccess.Count
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -798,9 +819,14 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
function TCustomTabControl.GetPage(AIndex: Integer): TCustomPage;
|
||||
begin
|
||||
if (AIndex < 0) or (AIndex >= PageCount) then
|
||||
RaiseGDBException('TCustomTabControl.GetCustomPage Index out of bounds');
|
||||
Result := TCustomPage(FPageList.Items[AIndex]);
|
||||
if FUnPaged then
|
||||
Result := nil
|
||||
else
|
||||
begin
|
||||
if (AIndex < 0) or (AIndex >= PageCount) then
|
||||
RaiseGDBException('TCustomTabControl.GetCustomPage Index out of bounds');
|
||||
Result := TNBPages(FAccess).GetPage(AIndex);
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user