Recent

Author Topic: Paint bug in TDBGrid/TStringGrid while editing  (Read 3543 times)

abonic

  • New member
  • *
  • Posts: 7
Paint bug in TDBGrid/TStringGrid while editing
« on: December 15, 2015, 12:13:28 pm »
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][+][-]
  1. procedure TCustomGrid.PrepareCanvas(aCol, aRow: Integer; aState: TGridDrawState);
  2. var
  3.   AColor: TColor;
  4.   CurrentTextStyle: TTextStyle;
  5.   IsSelected: boolean;
  6.   gc: TGridColumn;
  7. begin
  8.   if DefaultDrawing then begin
  9.     Canvas.Pen.Mode := pmCopy;
  10.     GetSelectedState(aState, IsSelected);
  11.     if IsSelected then begin
  12.       {bug fix}
  13.       if FEditorMode then
  14.         Canvas.Brush.Color := Color
  15.       else {}
  16.         Canvas.Brush.Color := SelectedColor;
  17.       SetCanvasFont(GetColumnFont(aCol, False));
  18.       if not IsCellButtonColumn(point(aCol,aRow)) then
  19.         Canvas.Font.Color := clHighlightText;
  20.       FLastFont:=nil;
  21.     end else begin
  22.       AColor := GetColumnColor(aCol, gdFixed in AState);
  23.       if (gdFixed in AState) and (gdHot in aState) then
  24.         aColor := FFixedHotColor;
  25.       if not (gdFixed in AState) and (FAlternateColor<>AColor) then begin
  26.         if AColor=Color then begin
  27.           // column color = grid Color, Allow override color
  28.           // 1. default color after fixed rows
  29.           // 2. always use absolute alternate color based in odd & even row
  30.           if (FAltColorStartNormal and Odd(ARow-FixedRows)) {(1)} or
  31.              (not FAltColorStartNormal and Odd(ARow)) {(2)} then
  32.               AColor := FAlternateColor;
  33.         end;
  34.       end;
  35.       if (gdRowHighlight in aState) and not (gdFixed in AState) then
  36.         Canvas.Brush.Color := ColorToRGB(AColor) xor $1F1F1F
  37.       else Canvas.Brush.Color := AColor;
  38.       SetCanvasFont(GetColumnFont(aCol, ((gdFixed in aState) and (aRow < FFixedRows))));
  39.     end;
  40.     CurrentTextStyle := DefaultTextStyle;
  41.     CurrentTextStyle.Alignment := BidiFlipAlignment(GetColumnAlignment(aCol, gdFixed in AState), UseRightToLeftAlignment);
  42.     CurrentTextStyle.Layout := GetColumnLayout(aCol, gdFixed in AState);
  43.     CurrentTextStyle.ShowPrefix := ((gdFixed in aState) and (aRow < FFixedRows)) and GetTitleShowPrefix(aCol);
  44.     CurrentTextStyle.RightToLeft := UseRightToLeftReading;
  45.     CurrentTextStyle.EndEllipsis := (goCellEllipsis in Options);
  46.     gc := ColumnFromGridColumn(aCol);
  47.     CurrentTextStyle.SingleLine := (gc = nil) or (not gc.Title.MultiLine);
  48.     Canvas.TextStyle := CurrentTextStyle;
  49.   end else begin
  50.     CurrentTextStyle := DefaultTextStyle;
  51.     CurrentTextStyle.Alignment := BidiFlipAlignment(CurrentTextStyle.Alignment, UseRightToLeftAlignment);
  52.     CurrentTextStyle.RightToLeft := UseRightToLeftAlignment;
  53.     Canvas.TextStyle := CurrentTextStyle;
  54.     Canvas.Brush.Color := clWindow;
  55.     Canvas.Font.Color := clWindowText;
  56.   end;
  57.  
  58.   DoPrepareCanvas(aCol, aRow, aState);
  59. end;  
  60.  
  61. procedure TCustomGrid.EditorPos;
  62. var
  63.   msg: TGridMessage;
  64.   CellR: TRect;
  65.   {bug fix}
  66.   EditorTop: integer; {}
  67. begin
  68.   {$ifdef dbgGrid} DebugLn('Grid.EditorPos INIT');{$endif}
  69.   if FEditor<>nil then begin
  70.  
  71.     // send editor position
  72.     Msg.LclMsg.msg:=GM_SETPOS;
  73.     Msg.Grid:=Self;
  74.     Msg.Col:=FCol;
  75.     Msg.Row:=FRow;
  76.     FEditor.Dispatch(Msg);
  77.  
  78.     // send editor bounds
  79.     CellR:=CellRect(FCol,FRow);
  80.  
  81.     if (CellR.Top<FGCache.FixedHeight) or (CellR.Top>FGCache.ClientHeight) or
  82.        (UseRightToLeftAlignment and ((CellR.Right-1>FlipX(FGCache.FixedWidth)) or (CellR.Right<0))) or
  83.        (not UseRightToLeftAlignment and ((CellR.Left<FGCache.FixedWidth) or (CellR.Left>FGCache.ClientWidth)))
  84.     then
  85.       // if editor will be out of sight, make the out of sight coords fixed
  86.       // this should avoid range check errors on widgetsets that can't handle
  87.       // high control coords (like GTK2)
  88.       CellR := Bounds(-FEditor.Width-100, -FEditor.Height-100, CellR.Right-CellR.Left, CellR.Bottom-CellR.Top);
  89.  
  90.     if FEditorOptions and EO_AUTOSIZE = EO_AUTOSIZE then begin
  91.       {bug fix}
  92.       if EditorBorderStyle = bsNone then begin
  93.         Dec(CellR.Right);
  94.         Dec(CellR.Bottom);
  95.       end;
  96.       if (FEditor = FStringEditor) then begin
  97.         case GetColumnLayout(FCol, False) of
  98.         tlTop: EditorTop:=CellR.Top+constCellPadding;
  99.         tlCenter: EditorTop:=CellR.Top+(CellR.Bottom-CellR.Top-Canvas.TextHeight(' ')) div 2;
  100.         tlBottom: EditorTop:=CellR.Bottom-constCellPadding-Canvas.TextHeight(' ')+1;
  101.         end;
  102.         if EditorTop>CellR.Top then CellR.Top:=EditorTop;
  103.       end;
  104.       {if EditorBorderStyle = bsNone then
  105.         InflateRect(CellR, -1, -1);}
  106.       FEditor.BoundsRect := CellR;
  107.     end else begin
  108.       Msg.LclMsg.msg:=GM_SETBOUNDS;
  109.       Msg.CellRect:=CellR;
  110.       Msg.Grid:=Self;
  111.       Msg.Col:=FCol;
  112.       Msg.Row:=FRow;
  113.       FEditor.Dispatch(Msg);
  114.     end;
  115.   end;
  116.   {$ifdef dbgGrid} DebugLn('Grid.EditorPos END');{$endif}
  117. end;

balazsszekely

  • Guest
Re: Paint bug in TDBGrid/TStringGrid while editing
« Reply #1 on: December 15, 2015, 01:08:36 pm »
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

  • New member
  • *
  • Posts: 7
Re: Paint bug in TDBGrid/TStringGrid while editing
« Reply #2 on: December 15, 2015, 06:29:40 pm »
Done

 

TinyPortal © 2005-2018