From 2cd3e995969477d1182bdfb14907ecb478031ae6 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sat, 15 Aug 2009 13:39:04 +0000 Subject: [PATCH] Placing a grid editor needs to leave space for various stuff left besides the edited text, e.g. the plus/minus button, an image and level indentation. Fixes issue #1293 . A similar calculation is done in TBaseVirtualTree.GetDisplayRect(), only with lots of more logic. So this change may not be the last in TBaseGridEditorLink.GetCellRect(). --- source/grideditlinks.pas | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/source/grideditlinks.pas b/source/grideditlinks.pas index bcd1b4d1..95206a0c 100644 --- a/source/grideditlinks.pas +++ b/source/grideditlinks.pas @@ -285,21 +285,46 @@ begin end; function TBaseGridEditorLink.GetCellRect(InnerTextBounds: Boolean): TRect; +var + Text: WideString; + CellBounds, TextBounds: TRect; + Ghosted: Boolean; + ImageIndex: Integer; begin // Return the cell's rectangle, relative to the parent form. - Result := FTree.GetDisplayRect(FNode, FColumn, False); - Dec(Result.Bottom, 1); + FTree.GetTextInfo(FNode, FColumn, FCellFont, TextBounds, Text); + CellBounds := FTree.GetDisplayRect(FNode, FColumn, False); + + Inc(CellBounds.Left, Integer(FTree.GetNodeLevel(FNode)) * (Integer(FTree.Indent)+FTree.TextMargin)); + if (toShowRoot in FTree.TreeOptions.PaintOptions) + and (FColumn = FTree.Header.MainColumn) then begin + // Reserve space for plus or minus button + Inc(CellBounds.Left, FTree.Indent); + end; + if Assigned(FTree.Images) and Assigned(FTree.OnGetImageIndex) then begin + // Reserve space for image + ImageIndex := -1; + FTree.OnGetImageIndex(FTree, FNode, ikNormal, FColumn, Ghosted, ImageIndex); + if ImageIndex > -1 then + Inc(CellBounds.Left, FTree.Images.Width+2); + end; + TextBounds.Left := CellBounds.Left + 2*FTree.TextMargin; + if InnerTextBounds then begin - OffsetRect(Result, -Result.Left, -Result.Top); - Inc(Result.Left, 8); - Inc(Result.Top, 2); - Dec(Result.Bottom, 1); + // Inner bounds are considered to be relative to the outer cell bounds + Result := Rect(TextBounds.Left-CellBounds.Left, + TextBounds.Top-CellBounds.Top, + CellBounds.Right-CellBounds.Left, // Far right edge of cell, not of text + CellBounds.Bottom-CellBounds.Top + ); end else begin // Recalculate top left corner of rectangle, so it is relative to the parent form (which is FParentForm) + Result := CellBounds; OffsetRect(Result, FTree.ClientOrigin.X - FParentForm.ClientOrigin.X, FTree.ClientOrigin.Y - FParentForm.ClientOrigin.Y ); + Dec(Result.Bottom, 1); end; end;