LCL: updating AutoSize=true controls when preferred size changed

git-svn-id: trunk@16087 -
This commit is contained in:
mattias 2008-08-16 18:31:55 +00:00
parent 669af5fc10
commit d27b3adf0d
5 changed files with 75 additions and 25 deletions

View File

@ -1573,6 +1573,7 @@ type
AControlList: TFPList; var ARect: TRect): Boolean; virtual;
procedure DoChildSizingChange(Sender: TObject); virtual;
procedure ResizeDelayedAutoSizeChildren; virtual;
procedure InvalidatePreferredChildSizes;
function CanTab: Boolean; override;
procedure CMShowingChanged(var Message: TLMessage); message CM_SHOWINGCHANGED;
procedure CMVisibleChanged(var TheMessage: TLMessage); message CM_VISIBLECHANGED;

View File

@ -3327,15 +3327,18 @@ begin
end;
if FVisible then
begin
if AsWincontrol <> nil then
if AsWincontrol <> nil then begin
AsWincontrol.InvalidatePreferredChildSizes;
Include(AsWincontrol.FWinControlFlags, wcfReAlignNeeded);
end;
AdjustSize;
if (AsWincontrol <> nil) and (wcfReAlignNeeded in AsWincontrol.FWinControlFlags) then
AsWincontrol.ReAlign;
end;
if cfRequestAlignNeeded in FControlFlags then
RequestAlign;
if AsWincontrol <> nil then
//DebugLn(['TControl.SetVisible ',dbgsName(AsWincontrol)]);
if FVisible and (AsWincontrol <> nil) then
AsWincontrol.ResizeDelayedAutoSizeChildren;
finally
VisibleChanged;

View File

@ -249,18 +249,24 @@ begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TCustomNotebook.DoCreateWnd ',dbgsName(Self),' HandleAllocated=',HandleAllocated]);
{$ENDIF}
fAddingPages:=true;
for i := 0 to FPageList.Count -1 do begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TCustomNotebook.DoCreateWnd ',dbgsName(Self),' Page.Caption=',Page[i].Caption,' pfAdded=',pfAdded in Page[i].Flags]);
{$ENDIF}
lPage := Page[i];
AddRemovePageHandle(lPage);
end;
fAddingPages:=false;
DisableAlign;
try
fAddingPages:=true;
for i := 0 to FPageList.Count -1 do begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TCustomNotebook.DoCreateWnd ',dbgsName(Self),' Page.Caption=',Page[i].Caption,' pfAdded=',pfAdded in Page[i].Flags]);
{$ENDIF}
lPage := Page[i];
AddRemovePageHandle(lPage);
end;
fAddingPages:=false;
DoSendShowTabs;
DoSendPageIndex;
DoSendShowTabs;
DoSendPageIndex;
ReAlign;
finally
EnableAlign;
end;
end;
{------------------------------------------------------------------------------
@ -429,7 +435,7 @@ end;
procedure TCustomNotebook.SetPageIndex(AValue: Integer);
begin
if (csLoading in ComponentState) then FLoadedPageIndex:=AValue;
//debugln('TCustomNotebook.SetPageIndex A ',dbgsName(Self),' AValue=',dbgs(AValue),' fPageIndex=',dbgs(fPageIndex),' PageCount=',dbgs(PageCount),' HandleAllocated=',dbgs(HandleAllocated));
//debugln('TCustomNotebook.SetPageIndex A ',dbgsName(Self),' AValue=',dbgs(AValue),' fPageIndex=',dbgs(fPageIndex),' PageCount=',dbgs(PageCount),' HandleAllocated=',dbgs(HandleAllocated),' ',dbgs(ComponentState));
if (AValue < 0) or (AValue >= PageCount) then exit;
if fPageIndex = AValue then exit;
if not CanChangePageIndex then exit;
@ -787,7 +793,6 @@ end;
procedure TCustomNotebook.CNNotify(var Message: TLMNotify);
var
OldPageIndex: LongInt;
APage: TCustomPage;
begin
with Message do
case NMHdr^.code of
@ -807,13 +812,7 @@ begin
if csDesigning in ComponentState then
OwnerFormDesignerModified(Self);
//DebugLn(['TCustomNotebook.CNNotify ',DbgSName(Page[PageIndex]),' ',Page[PageIndex].Visible]);
ResizeDelayedAutoSizeChildren;
Change;
if FPageIndex>=0 then begin
APage:=Page[FPageIndex];
// update FShowing
APage.UpdateShowing;
end;
end;
end;
end;
@ -861,6 +860,7 @@ begin
end;
end else begin
CurPage.Visible := true;
//DebugLn(['TCustomNotebook.ShowCurrentPage CurPage.AutoSizeDelayed=',CurPage.AutoSizeDelayed,' ',dbgs(CurPage.ComponentState),' ',CurPage.HandleAllocated]);
end;
FPageIndexOnLastShow:=fPageIndex;
CurPage.DoShow;
@ -868,7 +868,7 @@ begin
(FPageIndexOnLastChange <> FPageIndex) then
begin
// Page[FPageIndexOnLastChange].Visible := False; <-- this will be better,
// but this is not work on gtk (tab hides too)
// but this does not work on gtk (tab hides too)
Page[FPageIndexOnLastChange].DoHide;
end;
end;

View File

@ -27,6 +27,7 @@
{off $DEFINE VerboseAutoSizeCtrlData}
{off $DEFINE VerboseMouseBugfix}
{off $DEFINE VerboseCanAutoSize}
{off $DEFINE VerboseSizeMsg}
{off $DEFINE CHECK_POSITION}
@ -2901,11 +2902,16 @@ begin
try
for i:=0 to ControlCount-1 do begin
Child:=Controls[i];
if Child.AutoSizeDelayed then continue;
if Child.AutoSizeDelayed then begin
//DebugLn(['TWinControl.ResizeDelayedAutoSizeChildren Child.AutoSizeDelayed Child=',dbgsName(Child)]);
continue;
end;
//DebugLn(['TWinControl.ResizeDelayedAutoSizeChildren ',dbgsName(Child),' AutoSize=',Child.AutoSize,' cfAutoSizeNeeded=',cfAutoSizeNeeded in Child.FControlFlags]);
if cfRequestAlignNeeded in Child.FControlFlags then
Child.RequestAlign;
if cfAutoSizeNeeded in Child.FControlFlags then
if (cfAutoSizeNeeded in Child.FControlFlags)
or (Child.AutoSize and (not (cfPreferredSizeValid in Child.FControlFlags))) then
Child.AdjustSize;
if Child is TWinControl then begin
@ -2920,6 +2926,20 @@ begin
end;
end;
procedure TWinControl.InvalidatePreferredChildSizes;
var
AControl: TControl;
i: Integer;
begin
for i:=0 to ControlCount-1 do begin
AControl:=Controls[i];
Exclude(AControl.FControlFlags,cfPreferredSizeValid);
Exclude(AControl.FControlFlags,cfPreferredMinSizeValid);
if AControl is TWinControl then
TWinControl(AControl).InvalidatePreferredChildSizes;
end;
end;
{-------------------------------------------------------------------------------
procedure TWinControl.DoAutoSize;
@ -3771,7 +3791,7 @@ begin
if not HandleAllocated then Exit;
//DebugLn('TWinControl.UpdateShowing A ',Name,':',ClassName,' FShowing=',dbgs(FShowing),' bShow=',dbgs(bShow));
//DebugLn('TWinControl.UpdateShowing A ',dbgsName(Self),' FShowing=',dbgs(FShowing),' bShow=',dbgs(bShow));
if FShowing = bShow then Exit;
FShowing := bShow;

View File

@ -232,6 +232,7 @@ function DbgS(const p: TPoint): string; overload;
function DbgS(const p: pointer): string; overload;
function DbgS(const e: extended; MaxDecimals: integer = 999): string; overload;
function DbgS(const b: boolean): string; overload;
function DbgS(const s: TComponentState): string; overload;
function DbgSName(const p: TObject): string; overload;
function DbgSName(const p: TClass): string; overload;
function DbgStr(const StringWithSpecialChars: string): string; overload;
@ -1615,6 +1616,31 @@ begin
if b then Result:='True' else Result:='False';
end;
function DbgS(const s: TComponentState): string;
procedure Add(const a: string);
begin
if Result<>'' then
Result:=Result+',';
Result:=Result+a;
end;
begin
Result:='';
if csLoading in s then Add('csLoading');
if csReading in s then Add('csReading');
if csWriting in s then Add('csWriting');
if csDestroying in s then Add('csDestroying');
if csDesigning in s then Add('csDesigning');
if csAncestor in s then Add('csAncestor');
if csUpdating in s then Add('csUpdating');
if csFixups in s then Add('csFixups');
if csFreeNotification in s then Add('csFreeNotification');
if csInline in s then Add('csInline');
if csDesignInstance in s then Add('csDesignInstance');
Result:='['+Result+']';
end;
function DbgSName(const p: TObject): string;
begin
if p=nil then