LCL: Horizontal and Vertical Spacing for TCoolBar. Issue #27523, patch from Vojtech Cihak

git-svn-id: trunk@47982 -
This commit is contained in:
juha 2015-02-24 22:56:56 +00:00
parent e89f096e51
commit f130692a93
2 changed files with 48 additions and 24 deletions

View File

@ -2331,8 +2331,6 @@ type
cDefWidth = 180; cDefWidth = 180;
cDivider: SmallInt = 2; cDivider: SmallInt = 2;
cGrabIndent: SmallInt = 2; cGrabIndent: SmallInt = 2;
cHorSpacing = 5;
cVertSpacing = 3;
protected protected
FControlLeft: Integer; FControlLeft: Integer;
FControlTop: Integer; FControlTop: Integer;
@ -2405,11 +2403,13 @@ type
FFixedOrder: Boolean; FFixedOrder: Boolean;
FGrabStyle: TGrabStyle; FGrabStyle: TGrabStyle;
FGrabWidth: Integer; FGrabWidth: Integer;
FHorizontalSpacing: Integer;
FImages: TCustomImageList; FImages: TCustomImageList;
FImageChangeLink: TChangeLink; FImageChangeLink: TChangeLink;
FOnChange: TNotifyEvent;
FShowText: Boolean; FShowText: Boolean;
FVertical: Boolean; FVertical: Boolean;
FOnChange: TNotifyEvent; FVerticalSpacing: Integer;
function GetAlign: TAlign; function GetAlign: TAlign;
function RowEndHelper(ALeft, AVisibleIdx: Integer): Boolean; function RowEndHelper(ALeft, AVisibleIdx: Integer): Boolean;
procedure SetBandBorderStyle(AValue: TBorderStyle); procedure SetBandBorderStyle(AValue: TBorderStyle);
@ -2417,12 +2417,16 @@ type
procedure SetBitmap(AValue: TBitmap); procedure SetBitmap(AValue: TBitmap);
procedure SetGrabStyle(AValue: TGrabStyle); procedure SetGrabStyle(AValue: TGrabStyle);
procedure SetGrabWidth(AValue: Integer); procedure SetGrabWidth(AValue: Integer);
procedure SetHorizontalSpacing(AValue: Integer);
procedure SetImages(AValue: TCustomImageList); procedure SetImages(AValue: TCustomImageList);
procedure SetShowText(AValue: Boolean); procedure SetShowText(AValue: Boolean);
procedure SetVertical(AValue: Boolean); procedure SetVertical(AValue: Boolean);
procedure SetVerticalSpacing(AValue: Integer);
protected const protected const
cDefGrabStyle = gsDouble; cDefGrabStyle = gsDouble;
cDefGrabWidth = 10; cDefGrabWidth = 10;
cDefHorSpacing = 5;
cDefVertSpacing = 3;
cNewRowBelow: SmallInt = -1; cNewRowBelow: SmallInt = -1;
cNewRowAbove: SmallInt = -2; cNewRowAbove: SmallInt = -2;
protected protected
@ -2479,9 +2483,11 @@ type
property FixedOrder: Boolean read FFixedOrder write FFixedOrder default False; property FixedOrder: Boolean read FFixedOrder write FFixedOrder default False;
property GrabStyle: TGrabStyle read FGrabStyle write SetGrabStyle default cDefGrabStyle; property GrabStyle: TGrabStyle read FGrabStyle write SetGrabStyle default cDefGrabStyle;
property GrabWidth: Integer read FGrabWidth write SetGrabWidth default cDefGrabWidth; property GrabWidth: Integer read FGrabWidth write SetGrabWidth default cDefGrabWidth;
property HorizontalSpacing: Integer read FHorizontalSpacing write SetHorizontalSpacing default cDefHorSpacing;
property Images: TCustomImageList read FImages write SetImages; property Images: TCustomImageList read FImages write SetImages;
property ShowText: Boolean read FShowText write SetShowText default True; property ShowText: Boolean read FShowText write SetShowText default True;
property Vertical: Boolean read FVertical write SetVertical default False; property Vertical: Boolean read FVertical write SetVertical default False;
property VerticalSpacing: Integer read FVerticalSpacing write SetVerticalSpacing default cDefVertSpacing;
property OnChange: TNotifyEvent read FOnChange write FOnChange; property OnChange: TNotifyEvent read FOnChange write FOnChange;
end; end;
@ -2512,6 +2518,7 @@ type
property Font; property Font;
property GrabStyle; property GrabStyle;
property GrabWidth; property GrabWidth;
property HorizontalSpacing;
property Images; property Images;
property ParentColor; property ParentColor;
property ParentFont; property ParentFont;
@ -2521,6 +2528,7 @@ type
property ShowHint; property ShowHint;
property ShowText; property ShowText;
property Vertical; property Vertical;
property VerticalSpacing;
property Visible; property Visible;
property OnChange; property OnChange;
property OnClick; property OnClick;

View File

@ -74,7 +74,7 @@ begin
if Assigned(FControl) and FControl.AutoSize then begin if Assigned(FControl) and FControl.AutoSize then begin
FControl.GetPreferredSize(w, h); FControl.GetPreferredSize(w, h);
if FCoolBar.Vertical then w := h; if FCoolBar.Vertical then w := h;
inc(w, CalcControlLeft+cHorSpacing+cDivider); inc(w, CalcControlLeft+FCoolBar.HorizontalSpacing+cDivider);
Width := Math.max(FMinWidth, w); Width := Math.max(FMinWidth, w);
end; end;
end; end;
@ -82,19 +82,19 @@ end;
function TCoolBand.CalcControlLeft: Integer; function TCoolBand.CalcControlLeft: Integer;
var aImageSize, xHelp: Integer; var aImageSize, xHelp: Integer;
begin begin
Result := cGrabIndent+FCoolBar.GrabWidth+cHorSpacing; Result := cGrabIndent+FCoolBar.GrabWidth+FCoolBar.HorizontalSpacing;
xHelp := Result; xHelp := Result;
if (Text <> '') and FCoolBar.ShowText then if (Text <> '') and FCoolBar.ShowText then
inc(Result, FTextWidth+cHorSpacing); inc(Result, FTextWidth+FCoolBar.HorizontalSpacing);
if Assigned(FCoolBar.Images) then begin if Assigned(FCoolBar.Images) then begin
if not FCoolBar.Vertical then if not FCoolBar.Vertical then
aImageSize := FCoolBar.Images.Width aImageSize := FCoolBar.Images.Width
else else
aImageSize := FCoolBar.Images.Height; aImageSize := FCoolBar.Images.Height;
if ImageIndex >= 0 then if ImageIndex >= 0 then
inc(Result, aImageSize+cHorSpacing); inc(Result, aImageSize+FCoolBar.HorizontalSpacing);
end; end;
if Result = xHelp then inc(Result, cHorSpacing); if Result = xHelp then inc(Result, FCoolBar.HorizontalSpacing);
end; end;
function TCoolBand.CalcPreferredHeight: Integer; function TCoolBand.CalcPreferredHeight: Integer;
@ -102,24 +102,24 @@ begin
Result := FMinHeight; Result := FMinHeight;
if not FCoolBar.Vertical then begin if not FCoolBar.Vertical then begin
if Assigned(FControl) then if Assigned(FControl) then
Result := max(Result, FControl.Height+2*cVertSpacing); Result := max(Result, FControl.Height+2*FCoolBar.VerticalSpacing);
if Assigned(FCoolBar.Images) and (ImageIndex >= 0) then if Assigned(FCoolBar.Images) and (ImageIndex >= 0) then
Result := max(Result, FCoolBar.Images.Height+2*cVertSpacing); Result := max(Result, FCoolBar.Images.Height+2*FCoolBar.VerticalSpacing);
end else begin end else begin
if Assigned(FControl) then if Assigned(FControl) then
Result := max(Result, FControl.Width+2*cVertSpacing); Result := max(Result, FControl.Width+2*FCoolBar.VerticalSpacing);
if Assigned(FCoolBar.Images) and (ImageIndex >= 0) then if Assigned(FCoolBar.Images) and (ImageIndex >= 0) then
Result := max(Result, FCoolBar.Images.Width+2*cVertSpacing); Result := max(Result, FCoolBar.Images.Width+2*FCoolBar.VerticalSpacing);
end; end;
if FCoolBar.FShowText then if FCoolBar.FShowText then
Result := max(Result, FCoolBar.FTextHeight+2*cVertSpacing); Result := max(Result, FCoolBar.FTextHeight+2*FCoolBar.VerticalSpacing);
//DebugLn('CalcPreferredHeight ', CalcPreferredHeightHor); //DebugLn('CalcPreferredHeight ', CalcPreferredHeightHor);
end; end;
function TCoolBand.CalcPreferredWidth: Integer; function TCoolBand.CalcPreferredWidth: Integer;
begin begin
Result := CalcControlLeft; Result := CalcControlLeft;
if Assigned(Control) then inc(Result, Control.Width+cHorSpacing); if Assigned(Control) then inc(Result, Control.Width+FCoolBar.HorizontalSpacing);
inc(Result, cDivider); inc(Result, cDivider);
Result := max(FMinWidth, Result); Result := max(FMinWidth, Result);
end; end;
@ -357,9 +357,11 @@ begin
FBorderWidth := 2; FBorderWidth := 2;
FGrabStyle := cDefGrabStyle; FGrabStyle := cDefGrabStyle;
FGrabWidth := cDefGrabWidth; FGrabWidth := cDefGrabWidth;
FHorizontalSpacing := cDefHorSpacing;
FImageChangeLink := TChangeLink.Create; FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := @BitmapOrImageListChange; FImageChangeLink.OnChange := @BitmapOrImageListChange;
FShowText := True; FShowText := True;
FVerticalSpacing := cDefVertSpacing;
end; end;
destructor TCustomCoolBar.Destroy; destructor TCustomCoolBar.Destroy;
@ -430,6 +432,14 @@ begin
Invalidate; Invalidate;
end; end;
procedure TCustomCoolBar.SetHorizontalSpacing(AValue: Integer);
begin
if FHorizontalSpacing=AValue then Exit;
FHorizontalSpacing:=AValue;
CalculateAndAlign;
Invalidate;
end;
procedure TCustomCoolBar.SetImages(AValue: TCustomImageList); procedure TCustomCoolBar.SetImages(AValue: TCustomImageList);
begin begin
if Assigned(FImages) then if Assigned(FImages) then
@ -461,6 +471,14 @@ begin
Invalidate; Invalidate;
end; end;
procedure TCustomCoolBar.SetVerticalSpacing(AValue: Integer);
begin
if FVerticalSpacing=AValue then Exit;
FVerticalSpacing:=AValue;
CalculateAndAlign;
Invalidate;
end;
procedure TCustomCoolBar.AlignControls(AControl: TControl; var RemainingClientRect: TRect); procedure TCustomCoolBar.AlignControls(AControl: TControl; var RemainingClientRect: TRect);
var aAnchor: TAnchorKind; var aAnchor: TAnchorKind;
i: Integer; i: Integer;
@ -478,12 +496,10 @@ begin
Bands[i].FControl.Anchors := [akTop, aAnchor]; Bands[i].FControl.Anchors := [akTop, aAnchor];
if not Vertical then begin if not Vertical then begin
Bands[i].FControl.AnchorParallel(aAnchor, Bands[i].FControlLeft, Self); Bands[i].FControl.AnchorParallel(aAnchor, Bands[i].FControlLeft, Self);
//if Bands[i].FControl.Top <> (Bands[i].FControlTop+FBorderTop) then Bands[i].FControl.AnchorParallel(akTop, Bands[i].FControlTop, Self);
Bands[i].FControl.AnchorParallel(akTop, Bands[i].FControlTop, Self);
end else begin end else begin
Bands[i].FControl.AnchorParallel(akTop, Bands[i].FControlLeft, Self); Bands[i].FControl.AnchorParallel(akTop, Bands[i].FControlLeft, Self);
//if Bands[i].FControl.Left <> (Bands[i].FControlTop+FBorderLeft) then Bands[i].FControl.AnchorParallel(aAnchor, Bands[i].FControlTop, Self);
Bands[i].FControl.AnchorParallel(aAnchor, Bands[i].FControlTop, Self);
end; end;
end; end;
inherited AlignControls(AControl, RemainingClientRect); inherited AlignControls(AControl, RemainingClientRect);
@ -576,7 +592,7 @@ begin
FVisiBands[i].FTop := Width-aTop-FVisiBands[i].Height; FVisiBands[i].FTop := Width-aTop-FVisiBands[i].Height;
if Assigned(FVisiBands[i].Control) then begin if Assigned(FVisiBands[i].Control) then begin
x := FVisiBands[i].CalcControlLeft; x := FVisiBands[i].CalcControlLeft;
aWidth := FVisiBands[i].Width-x-TCoolBand.cHorSpacing-TCoolBand.cDivider; aWidth := FVisiBands[i].Width-x-HorizontalSpacing-TCoolBand.cDivider;
if not FRightToLeft then begin if not FRightToLeft then begin
inc(x, aLeft); inc(x, aLeft);
if not Vertical then if not Vertical then
@ -586,7 +602,7 @@ begin
FVisiBands[i].FControlLeft := x-aBorderLeft; FVisiBands[i].FControlLeft := x-aBorderLeft;
end else begin end else begin
if not Vertical then begin if not Vertical then begin
x := FVisiBands[i].FLeft+TCoolBand.cDivider+TCoolBand.cHorSpacing; x := FVisiBands[i].FLeft+TCoolBand.cDivider+HorizontalSpacing;
FVisiBands[i].Control.Left := x; FVisiBands[i].Control.Left := x;
FVisiBands[i].FControlLeft := Width-x-Bands[i].FControl.Width-aBorderLeft; FVisiBands[i].FControlLeft := Width-x-Bands[i].FControl.Width-aBorderLeft;
end else begin end else begin
@ -1195,9 +1211,9 @@ begin
else else
PaintGrabber(Rect(aTop+2, x, aTop+FVisiBands[i].FHeight-3, x+GrabWidth-1)); PaintGrabber(Rect(aTop+2, x, aTop+FVisiBands[i].FHeight-3, x+GrabWidth-1));
if not FRightToLeft or Vertical then if not FRightToLeft or Vertical then
x := x+GrabWidth+TCoolBand.cHorSpacing x := x+GrabWidth+HorizontalSpacing
else else
x := x-TCoolBand.cHorSpacing; x := x-HorizontalSpacing;
//paint Image //paint Image
if Assigned(FImages) and (FVisiBands[i].ImageIndex >= 0) then begin if Assigned(FImages) and (FVisiBands[i].ImageIndex >= 0) then begin
if FRightToLeft and not Vertical then dec(x, FImages.Width); if FRightToLeft and not Vertical then dec(x, FImages.Width);
@ -1210,9 +1226,9 @@ begin
Point(aTop+(FVisiBands[i].FHeight-FImages.Width) div 2, x), Point(aTop+(FVisiBands[i].FHeight-FImages.Width) div 2, x),
FImages, FVisiBands[i].ImageIndex); FImages, FVisiBands[i].ImageIndex);
if not FRightToLeft or Vertical then if not FRightToLeft or Vertical then
inc(x, FImages.Width+TCoolBand.cHorSpacing) inc(x, FImages.Width+HorizontalSpacing)
else else
dec(x, TCoolBand.cHorSpacing); dec(x, HorizontalSpacing);
end; end;
//paint Text //paint Text
if FShowText then begin if FShowText then begin