From 10aecd20d43ce8a3b41a7105b22201c94c1ad8b1 Mon Sep 17 00:00:00 2001 From: micha Date: Sat, 27 Jan 2007 19:23:13 +0000 Subject: [PATCH] fix TPage.TabVisible icw PageIndex, patch by Luiz (issue #7349) git-svn-id: trunk@10519 - --- lcl/extctrls.pp | 3 ++ lcl/include/customnotebook.inc | 85 ++++++++++++++++++++-------------- lcl/include/custompage.inc | 10 +++- 3 files changed, 61 insertions(+), 37 deletions(-) diff --git a/lcl/extctrls.pp b/lcl/extctrls.pp index 018deca9de..febccc350a 100644 --- a/lcl/extctrls.pp +++ b/lcl/extctrls.pp @@ -151,11 +151,13 @@ type function GetPage(aIndex: Integer): TCustomPage; function GetPageCount : integer; function GetPageIndex: Integer; + function FindVisiblePage(Index: Integer): Integer; procedure InsertPage(APage: TCustomPage; Index: Integer); function IsStoredActivePage: boolean; procedure AddRemovePageHandle(APage: TCustomPage); procedure MoveTab(Sender: TObject; NewIndex: Integer); procedure WSMovePage(APage: TCustomPage; NewIndex: Integer); + procedure PageRemoved(Index: Integer); procedure RemovePage(Index: Integer); procedure SetActivePage(const Value: String); procedure SetActivePageComponent(const AValue: TCustomPage); @@ -267,6 +269,7 @@ type property Enabled; property Images; property OnChangeBounds; + property OnChanging; property OnCloseTabClicked; property OnContextPopup; property OnEnter; diff --git a/lcl/include/customnotebook.inc b/lcl/include/customnotebook.inc index 611dec5c70..145fada2c3 100644 --- a/lcl/include/customnotebook.inc +++ b/lcl/include/customnotebook.inc @@ -353,22 +353,19 @@ end; ------------------------------------------------------------------------------} function TCustomNotebook.GetActivePage: String; begin - if (PageIndex>=0) and (PageIndex= 0) and (FPageIndex < PageCount) then + Result := TCustomPage(FPageList[FPageIndex]).Caption else - Result:=''; + Result := ''; end; {------------------------------------------------------------------------------ function TCustomNotebook.GetActivePageComponent: TCustomPage; ------------------------------------------------------------------------------} function TCustomNotebook.GetActivePageComponent: TCustomPage; -var - i: Integer; begin - i:=PageIndex; - if (i>=0) and (i= 0) and (FPageIndex < PageCount) then + Result:=Page[FPageIndex] else Result:=nil; end; @@ -487,6 +484,44 @@ begin Change; 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); var RealIndex: Integer; @@ -518,7 +553,7 @@ begin end else begin if not (pfAdded in APage.FFlags) then exit; Exclude(APage.FFlags,pfAdded); - TWSCustomNotebookClass(WidgetSetClass).RemovePage(Self, APage.PageIndex); + TWSCustomNotebookClass(WidgetSetClass).RemovePage(Self, APage.VisibleIndex); if APage.HandleAllocated then APage.DestroyHandle; end; @@ -526,7 +561,6 @@ end; procedure TCustomNotebook.RemovePage(Index: Integer); var - NewPageIndex: integer; APage: TCustomPage; begin // 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, ' FPageList.Count=',FPageList.Count,' PageIndex=',PageIndex]); {$ENDIF} - if (Index >= 0) and - (Index < FPageList.Count) then + if (Index >= 0) and (Index < FPageList.Count) then begin APage:=TCustomPage(fPageList[Index]); - NewPageIndex:=PageIndex; - if not (csLoading in ComponentState) then begin - // If that page is showing, then show the next page before deleting it - if (Index = PageIndex) then begin - if NewPageIndex0 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; + APage.FTabVisible:=false; + PageRemoved(Index); + if HandleAllocated then AddRemovePageHandle(APage); - end; FPageList.Delete(Index); APage.Parent:=nil; - if fPageIndex >= Index then - Dec(fPageIndex); + if FPageIndex >= Index then + Dec(FPageIndex); end; {$IFDEF NOTEBOOK_DEBUG} DebugLn(['TCustomNotebook.RemovePage END ',dbgsName(Self),' Index=',Index,' fPageList.Count=',fPageList.Count,' PageIndex=',PageIndex]); diff --git a/lcl/include/custompage.inc b/lcl/include/custompage.inc index 2e4de6d836..d4c1b57d27 100644 --- a/lcl/include/custompage.inc +++ b/lcl/include/custompage.inc @@ -56,8 +56,15 @@ end; procedure TCustomPage.SetTabVisible(const AValue: Boolean); begin 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); + // check if there was no visible tab + if FTabVisible then + if TCustomNotebook(Parent).PageIndex = -1 then + TCustomNotebook(Parent).PageIndex:=PageIndex; end; {------------------------------------------------------------------------------ @@ -98,7 +105,6 @@ begin if i>=0 then begin Include(FFlags,pfRemoving); try - TabVisible := False; ParentNotebook.RemovePage(i); finally Exclude(FFlags,pfRemoving);