mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 16:29:38 +02:00
fix TPage.TabVisible icw PageIndex, patch by Luiz (issue #7349)
git-svn-id: trunk@10519 -
This commit is contained in:
parent
c9441238fc
commit
10aecd20d4
@ -151,11 +151,13 @@ type
|
|||||||
function GetPage(aIndex: Integer): TCustomPage;
|
function GetPage(aIndex: Integer): TCustomPage;
|
||||||
function GetPageCount : integer;
|
function GetPageCount : integer;
|
||||||
function GetPageIndex: Integer;
|
function GetPageIndex: Integer;
|
||||||
|
function FindVisiblePage(Index: Integer): Integer;
|
||||||
procedure InsertPage(APage: TCustomPage; Index: Integer);
|
procedure InsertPage(APage: TCustomPage; Index: Integer);
|
||||||
function IsStoredActivePage: boolean;
|
function IsStoredActivePage: boolean;
|
||||||
procedure AddRemovePageHandle(APage: TCustomPage);
|
procedure AddRemovePageHandle(APage: TCustomPage);
|
||||||
procedure MoveTab(Sender: TObject; NewIndex: Integer);
|
procedure MoveTab(Sender: TObject; NewIndex: Integer);
|
||||||
procedure WSMovePage(APage: TCustomPage; NewIndex: Integer);
|
procedure WSMovePage(APage: TCustomPage; NewIndex: Integer);
|
||||||
|
procedure PageRemoved(Index: Integer);
|
||||||
procedure RemovePage(Index: Integer);
|
procedure RemovePage(Index: Integer);
|
||||||
procedure SetActivePage(const Value: String);
|
procedure SetActivePage(const Value: String);
|
||||||
procedure SetActivePageComponent(const AValue: TCustomPage);
|
procedure SetActivePageComponent(const AValue: TCustomPage);
|
||||||
@ -267,6 +269,7 @@ type
|
|||||||
property Enabled;
|
property Enabled;
|
||||||
property Images;
|
property Images;
|
||||||
property OnChangeBounds;
|
property OnChangeBounds;
|
||||||
|
property OnChanging;
|
||||||
property OnCloseTabClicked;
|
property OnCloseTabClicked;
|
||||||
property OnContextPopup;
|
property OnContextPopup;
|
||||||
property OnEnter;
|
property OnEnter;
|
||||||
|
@ -353,22 +353,19 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TCustomNotebook.GetActivePage: String;
|
function TCustomNotebook.GetActivePage: String;
|
||||||
begin
|
begin
|
||||||
if (PageIndex>=0) and (PageIndex<PageCount) then
|
if (FPageIndex >= 0) and (FPageIndex < PageCount) then
|
||||||
Result := TCustomPage(fPageList[PageIndex]).Caption
|
Result := TCustomPage(FPageList[FPageIndex]).Caption
|
||||||
else
|
else
|
||||||
Result:='';
|
Result := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
function TCustomNotebook.GetActivePageComponent: TCustomPage;
|
function TCustomNotebook.GetActivePageComponent: TCustomPage;
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TCustomNotebook.GetActivePageComponent: TCustomPage;
|
function TCustomNotebook.GetActivePageComponent: TCustomPage;
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
begin
|
||||||
i:=PageIndex;
|
if (FPageIndex >= 0) and (FPageIndex < PageCount) then
|
||||||
if (i>=0) and (i<PageCount) then
|
Result:=Page[FPageIndex]
|
||||||
Result:=Page[i]
|
|
||||||
else
|
else
|
||||||
Result:=nil;
|
Result:=nil;
|
||||||
end;
|
end;
|
||||||
@ -487,6 +484,44 @@ begin
|
|||||||
Change;
|
Change;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
function TCustomNotebook.FindVisiblePage(Index: Integer): Integer;
|
||||||
|
|
||||||
|
It tries to find the next (at right) visible page. If no one is found,
|
||||||
|
it tries to to find the previous (at left) visible page.
|
||||||
|
Returns -1 if there's no visible pages.
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
|
||||||
|
function TCustomNotebook.FindVisiblePage(Index: Integer): Integer;
|
||||||
|
begin
|
||||||
|
for Result := Index to FPageList.Count - 1 do
|
||||||
|
if TCustomPage(FPageList[Result]).TabVisible then
|
||||||
|
exit;
|
||||||
|
// if arrived here no visible forward page was found, search backwards
|
||||||
|
for Result := Index - 1 downto 0 do
|
||||||
|
if TCustomPage(FPageList[Result]).TabVisible then
|
||||||
|
exit;
|
||||||
|
Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomNotebook.PageRemoved(Index: Integer);
|
||||||
|
var
|
||||||
|
NewPageIndex: Integer;
|
||||||
|
begin
|
||||||
|
if not (csLoading in ComponentState) then
|
||||||
|
begin
|
||||||
|
// if this page is showing, then show the next page before deleting it
|
||||||
|
if Index = FPageIndex then
|
||||||
|
begin
|
||||||
|
NewPageIndex := FindVisiblePage(Index);
|
||||||
|
if NewPageIndex >= 0 then
|
||||||
|
PageIndex := NewPageIndex
|
||||||
|
else
|
||||||
|
FPageIndex := NewPageIndex;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomNotebook.WSMovePage(APage: TCustomPage; NewIndex: Integer);
|
procedure TCustomNotebook.WSMovePage(APage: TCustomPage; NewIndex: Integer);
|
||||||
var
|
var
|
||||||
RealIndex: Integer;
|
RealIndex: Integer;
|
||||||
@ -518,7 +553,7 @@ begin
|
|||||||
end else begin
|
end else begin
|
||||||
if not (pfAdded in APage.FFlags) then exit;
|
if not (pfAdded in APage.FFlags) then exit;
|
||||||
Exclude(APage.FFlags,pfAdded);
|
Exclude(APage.FFlags,pfAdded);
|
||||||
TWSCustomNotebookClass(WidgetSetClass).RemovePage(Self, APage.PageIndex);
|
TWSCustomNotebookClass(WidgetSetClass).RemovePage(Self, APage.VisibleIndex);
|
||||||
if APage.HandleAllocated then
|
if APage.HandleAllocated then
|
||||||
APage.DestroyHandle;
|
APage.DestroyHandle;
|
||||||
end;
|
end;
|
||||||
@ -526,7 +561,6 @@ end;
|
|||||||
|
|
||||||
procedure TCustomNotebook.RemovePage(Index: Integer);
|
procedure TCustomNotebook.RemovePage(Index: Integer);
|
||||||
var
|
var
|
||||||
NewPageIndex: integer;
|
|
||||||
APage: TCustomPage;
|
APage: TCustomPage;
|
||||||
begin
|
begin
|
||||||
// Make sure Index is in the range of valid pages to delete
|
// Make sure Index is in the range of valid pages to delete
|
||||||
@ -534,36 +568,17 @@ begin
|
|||||||
DebugLn(['TCustomNotebook.RemovePage A ',dbgsName(Self),' Index=',Index,
|
DebugLn(['TCustomNotebook.RemovePage A ',dbgsName(Self),' Index=',Index,
|
||||||
' FPageList.Count=',FPageList.Count,' PageIndex=',PageIndex]);
|
' FPageList.Count=',FPageList.Count,' PageIndex=',PageIndex]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if (Index >= 0) and
|
if (Index >= 0) and (Index < FPageList.Count) then
|
||||||
(Index < FPageList.Count) then
|
|
||||||
begin
|
begin
|
||||||
APage:=TCustomPage(fPageList[Index]);
|
APage:=TCustomPage(fPageList[Index]);
|
||||||
NewPageIndex:=PageIndex;
|
APage.FTabVisible:=false;
|
||||||
if not (csLoading in ComponentState) then begin
|
PageRemoved(Index);
|
||||||
// If that page is showing, then show the next page before deleting it
|
if HandleAllocated then
|
||||||
if (Index = PageIndex) then begin
|
|
||||||
if NewPageIndex<FPageList.Count-1 then
|
|
||||||
// switch current page to next (right) page
|
|
||||||
inc(NewPageIndex)
|
|
||||||
else if FPageList.Count>0 then
|
|
||||||
// switch to previous (left) page
|
|
||||||
dec(NewPageIndex)
|
|
||||||
else
|
|
||||||
// deleting last page
|
|
||||||
NewPageIndex:=-1;
|
|
||||||
|
|
||||||
if NewPageIndex>=0 then
|
|
||||||
PageIndex:=NewPageIndex;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
if HandleAllocated then begin
|
|
||||||
APage.FTabVisible:=false;
|
|
||||||
AddRemovePageHandle(APage);
|
AddRemovePageHandle(APage);
|
||||||
end;
|
|
||||||
FPageList.Delete(Index);
|
FPageList.Delete(Index);
|
||||||
APage.Parent:=nil;
|
APage.Parent:=nil;
|
||||||
if fPageIndex >= Index then
|
if FPageIndex >= Index then
|
||||||
Dec(fPageIndex);
|
Dec(FPageIndex);
|
||||||
end;
|
end;
|
||||||
{$IFDEF NOTEBOOK_DEBUG}
|
{$IFDEF NOTEBOOK_DEBUG}
|
||||||
DebugLn(['TCustomNotebook.RemovePage END ',dbgsName(Self),' Index=',Index,' fPageList.Count=',fPageList.Count,' PageIndex=',PageIndex]);
|
DebugLn(['TCustomNotebook.RemovePage END ',dbgsName(Self),' Index=',Index,' fPageList.Count=',fPageList.Count,' PageIndex=',PageIndex]);
|
||||||
|
@ -56,8 +56,15 @@ end;
|
|||||||
procedure TCustomPage.SetTabVisible(const AValue: Boolean);
|
procedure TCustomPage.SetTabVisible(const AValue: Boolean);
|
||||||
begin
|
begin
|
||||||
if AValue = FTabVisible then exit;
|
if AValue = FTabVisible then exit;
|
||||||
fTabVisible := AValue;
|
FTabVisible := AValue;
|
||||||
|
// if the page is active, set a new pageindex
|
||||||
|
if not FTabVisible then
|
||||||
|
TCustomNotebook(Parent).PageRemoved(PageIndex);
|
||||||
TCustomNotebook(Parent).AddRemovePageHandle(Self);
|
TCustomNotebook(Parent).AddRemovePageHandle(Self);
|
||||||
|
// check if there was no visible tab
|
||||||
|
if FTabVisible then
|
||||||
|
if TCustomNotebook(Parent).PageIndex = -1 then
|
||||||
|
TCustomNotebook(Parent).PageIndex:=PageIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -98,7 +105,6 @@ begin
|
|||||||
if i>=0 then begin
|
if i>=0 then begin
|
||||||
Include(FFlags,pfRemoving);
|
Include(FFlags,pfRemoving);
|
||||||
try
|
try
|
||||||
TabVisible := False;
|
|
||||||
ParentNotebook.RemovePage(i);
|
ParentNotebook.RemovePage(i);
|
||||||
finally
|
finally
|
||||||
Exclude(FFlags,pfRemoving);
|
Exclude(FFlags,pfRemoving);
|
||||||
|
Loading…
Reference in New Issue
Block a user