lcl: TCoolBar: less autosize updates

git-svn-id: trunk@40501 -
This commit is contained in:
mattias 2013-03-06 23:28:24 +00:00
parent efc032e6cc
commit 76852a3c06
2 changed files with 72 additions and 50 deletions

View File

@ -2279,6 +2279,8 @@ type
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure BeginUpdate; override;
procedure EndUpdate; override;
public public
property Align read GetAlign write SetAlign default alTop; property Align read GetAlign write SetAlign default alTop;
property BandBorderStyle: TBorderStyle read FBandBorderStyle write FBandBorderStyle default bsSingle; property BandBorderStyle: TBorderStyle read FBandBorderStyle write FBandBorderStyle default bsSingle;

View File

@ -187,52 +187,57 @@ end;
procedure TCoolBand.UpdControl(aLabelWidth: integer); procedure TCoolBand.UpdControl(aLabelWidth: integer);
begin begin
if FCoolBar = Nil then Exit; if FCoolBar = Nil then Exit;
Inc(FCoolBar.FUpdateCount); FCoolBar.DisableAlign;
if Assigned(FTextLabel) then try
begin Inc(FCoolBar.FUpdateCount);
if Assigned(FControl) then if Assigned(FTextLabel) then
FTextLabel.Top := FTop+4 // Adjust text position for the control (which is higher).
else
FTextLabel.Top := FTop+1;
if FCoolBar.BiDiMode = bdLeftToRight then
FTextLabel.Left := FCoolBar.GrabLeft + GrabWidth + 6
else
FTextLabel.Left := FCoolBar.GrabLeft - aLabelWidth - 6;
FTextLabel.Visible := FCoolBar.ShowText;
end;
if Assigned(FControl) then
begin
// Calculate left positions and anchoring for text label and control
FControl.Align := alNone; // alCustom does not work here
FControl.Parent := FCoolBar;
FControl.FreeNotification(FCoolBar);
FControl.Top := FTop;
if Assigned(FTextLabel) and FCoolBar.ShowText then
begin begin
if Assigned(FControl) then
FTextLabel.Top := FTop+4 // Adjust text position for the control (which is higher).
else
FTextLabel.Top := FTop+1;
if FCoolBar.BiDiMode = bdLeftToRight then if FCoolBar.BiDiMode = bdLeftToRight then
FTextLabel.Left := FCoolBar.GrabLeft + GrabWidth + 6
else
FTextLabel.Left := FCoolBar.GrabLeft - aLabelWidth - 6;
FTextLabel.Visible := FCoolBar.ShowText;
end;
if Assigned(FControl) then
begin
// Calculate left positions and anchoring for text label and control
FControl.Align := alNone; // alCustom does not work here
FControl.FreeNotification(FCoolBar);
FControl.Top := FTop;
if Assigned(FTextLabel) and FCoolBar.ShowText then
begin begin
FControl.AnchorSide[akRight].Control := Nil; if FCoolBar.BiDiMode = bdLeftToRight then
FControl.AnchorSide[akLeft].Control := FTextLabel; begin
FControl.AnchorSide[akLeft].Side := asrRight; FControl.AnchorSide[akRight].Control := Nil;
FControl.BorderSpacing.Left := 7; FControl.AnchorSide[akLeft].Control := FTextLabel;
FControl.Anchors := [akLeft]; FControl.AnchorSide[akLeft].Side := asrRight;
FControl.BorderSpacing.Left := 7;
FControl.Anchors := [akLeft];
end
else begin
FControl.AnchorSide[akLeft].Control := Nil;
FControl.AnchorSide[akRight].Control := FTextLabel;
FControl.AnchorSide[akRight].Side := asrLeft;
FControl.BorderSpacing.Right := 7;
FControl.Anchors := [akRight];
end;
end end
else begin else
FControl.AnchorSide[akLeft].Control := Nil; ResetControlProps;
FControl.AnchorSide[akRight].Control := FTextLabel; // Make sure other Anchors a Nil
FControl.AnchorSide[akRight].Side := asrLeft; FControl.AnchorSide[akBottom].Control := Nil;
FControl.BorderSpacing.Right := 7; FControl.AnchorSide[akTop].Control := Nil;
FControl.Anchors := [akRight]; FControl.Parent := FCoolBar;
end; SetControlWidth;
end end;
else Dec(FCoolBar.FUpdateCount);
ResetControlProps; finally
// Make sure other Anchors a Nil FCoolBar.EnableAlign;
FControl.AnchorSide[akBottom].Control := Nil;
FControl.AnchorSide[akTop].Control := Nil;
SetControlWidth;
end; end;
Dec(FCoolBar.FUpdateCount);
end; end;
procedure TCoolBand.SetControl(aValue: TControl); procedure TCoolBand.SetControl(aValue: TControl);
@ -241,17 +246,20 @@ var
begin begin
if FControl = aValue then Exit; if FControl = aValue then Exit;
FCoolBar.BeginUpdate; FCoolBar.BeginUpdate;
if Assigned(aValue) then begin try
Band := TCoolBands(Collection).FindBand(aValue); if Assigned(aValue) then begin
if Assigned(Band) and (Band <> Self) then begin Band := TCoolBands(Collection).FindBand(aValue);
Band.ResetControlProps; if Assigned(Band) and (Band <> Self) then begin
Band.SetControl(Nil); // Remove old association Band.ResetControlProps;
Band.SetControl(Nil); // Remove old association
end;
aValue.Parent := Nil;
end; end;
aValue.Parent := Nil; FControl := aValue;
Changed(True);
finally
FCoolBar.EndUpdate;
end; end;
FControl := aValue;
FCoolBar.EndUpdate;
Changed(True);
end; end;
procedure TCoolBand.SetParentColor(aValue: Boolean); procedure TCoolBand.SetParentColor(aValue: Boolean);
@ -486,6 +494,18 @@ begin
inherited Destroy; inherited Destroy;
end; end;
procedure TCustomCoolBar.BeginUpdate;
begin
DisableAlign;
inherited BeginUpdate;
end;
procedure TCustomCoolBar.EndUpdate;
begin
inherited EndUpdate;
EnableAlign;
end;
function TCustomCoolBar.GrabLeft: integer; function TCustomCoolBar.GrabLeft: integer;
begin begin
Result := 2; Result := 2;