Paint bug in TDBGrid/TStringGrid while editing lazarus / 31-LCL ---------------------------------------------------------------------- abonic · 2015-12-15 11:13 OS: Windows (10) Lazarus 1.4, 1.6RC1 Problems: 1. Left and top borders of the cell are blue. Selection background is not erased and editor does not fully cover the surface of the cell.   2. Text in cell is on different position than before. Editor ignores TTextLayout. Steps to reproduce: Press F2 in some cell in TDBGrid/TStringGrid control. Possible solution: Replace these two procedures in Grids.pas: (Changes are between {bug fix} and {}) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomGrid.PrepareCanvas(aCol, aRow: Integer; aState: TGridDrawState);var  AColor: TColor;  CurrentTextStyle: TTextStyle;  IsSelected: boolean;  gc: TGridColumn;begin  if DefaultDrawing then begin    Canvas.Pen.Mode := pmCopy;    GetSelectedState(aState, IsSelected);    if IsSelected then begin      {bug fix}      if FEditorMode then        Canvas.Brush.Color := Color      else {}      Canvas.Brush.Color := SelectedColor;      SetCanvasFont(GetColumnFont(aCol, False));      if not IsCellButtonColumn(point(aCol,aRow)) then        Canvas.Font.Color := clHighlightText;      FLastFont:=nil;    end else begin      AColor := GetColumnColor(aCol, gdFixed in AState);      if (gdFixed in AState) and (gdHot in aState) then        aColor := FFixedHotColor;      if not (gdFixed in AState) and (FAlternateColor<>AColor) then begin      if AColor=Color then begin          // column color = grid Color, Allow override color          // 1. default color after fixed rows        // 2. always use absolute alternate color based in odd & even row          if (FAltColorStartNormal and Odd(ARow-FixedRows)) {(1)} or             (not FAltColorStartNormal and Odd(ARow)) {(2)} then            AColor := FAlternateColor;        end;      end;      if (gdRowHighlight in aState) and not (gdFixed in AState) then        Canvas.Brush.Color := ColorToRGB(AColor) xor $1F1F1F      else Canvas.Brush.Color := AColor;      SetCanvasFont(GetColumnFont(aCol, ((gdFixed in aState) and (aRow < FFixedRows))));    end;    CurrentTextStyle := DefaultTextStyle;    CurrentTextStyle.Alignment := BidiFlipAlignment(GetColumnAlignment(aCol, gdFixed in AState), UseRightToLeftAlignment);    CurrentTextStyle.Layout := GetColumnLayout(aCol, gdFixed in AState);    CurrentTextStyle.ShowPrefix := ((gdFixed in aState) and (aRow < FFixedRows)) and GetTitleShowPrefix(aCol);    CurrentTextStyle.RightToLeft := UseRightToLeftReading;    CurrentTextStyle.EndEllipsis := (goCellEllipsis in Options);    gc := ColumnFromGridColumn(aCol);    CurrentTextStyle.SingleLine := (gc = nil) or (not gc.Title.MultiLine);    Canvas.TextStyle := CurrentTextStyle;  end else begin    CurrentTextStyle := DefaultTextStyle;    CurrentTextStyle.Alignment := BidiFlipAlignment(CurrentTextStyle.Alignment, UseRightToLeftAlignment);    CurrentTextStyle.RightToLeft := UseRightToLeftAlignment;    Canvas.TextStyle := CurrentTextStyle;    Canvas.Brush.Color := clWindow;    Canvas.Font.Color := clWindowText;  end;    DoPrepareCanvas(aCol, aRow, aState);end;   procedure TCustomGrid.EditorPos;var  msg: TGridMessage;  CellR: TRect;  {bug fix}  EditorTop: integer; {}begin  {$ifdef dbgGrid} DebugLn('Grid.EditorPos INIT');{$endif}  if FEditor<>nil then begin   // send editor position    Msg.LclMsg.msg:=GM_SETPOS;    Msg.Grid:=Self;    Msg.Col:=FCol;    Msg.Row:=FRow;    FEditor.Dispatch(Msg);     // send editor bounds    CellR:=CellRect(FCol,FRow);     if (CellR.TopFGCache.ClientHeight) or       (UseRightToLeftAlignment and ((CellR.Right-1>FlipX(FGCache.FixedWidth)) or (CellR.Right<0))) or     (not UseRightToLeftAlignment and ((CellR.LeftFGCache.ClientWidth)))    then      // if editor will be out of sight, make the out of sight coords fixed      // this should avoid range check errors on widgetsets that can't handle      // high control coords (like GTK2)      CellR := Bounds(-FEditor.Width-100, -FEditor.Height-100, CellR.Right-CellR.Left, CellR.Bottom- CellR.Top);     if FEditorOptions and EO_AUTOSIZE = EO_AUTOSIZE then begin      {bug fix}      if EditorBorderStyle = bsNone then begin      Dec(CellR.Right);        Dec(CellR.Bottom);      end;      if (FEditor = FStringEditor) then begin        case GetColumnLayout(FCol, False) of        tlTop: EditorTop:=CellR.Top+constCellPadding;        tlCenter: EditorTop:=CellR.Top+(CellR.Bottom-CellR.Top- Canvas.TextHeight(' ')) div 2;        tlBottom: EditorTop:=CellR.Bottom-constCellPadding-Canvas.TextHeight(' ')+1;      end;        if EditorTop>CellR.Top then CellR.Top:=EditorTop;      end;      {if EditorBorderStyle = bsNone then        InflateRect(CellR, -1, -1);}      FEditor.BoundsRect := CellR;    end else begin      Msg.LclMsg.msg:=GM_SETBOUNDS;      Msg.CellRect:=CellR;      Msg.Grid:=Self;      Msg.Col:=FCol;      Msg.Row:=FRow;      FEditor.Dispatch(Msg);    end;  end;  {$ifdef dbgGrid} DebugLn('Grid.EditorPos END');{$endif}end; ---------------------------------------------------------------------- balazsszekely · 2015-12-15 12:08 Hi abonic, Please fill a new issue on the bugtracker: http://bugs.freepascal.org/main_page.php . Attach your solution as a pach: http://wiki.freepascal.org/Creating_A_Patch regards, GetMem ---------------------------------------------------------------------- abonic · 2015-12-15 17:29 Done