kryslt / KControls

Free components for Delphi and Lazarus, this is the main repository maintained by the original author.
BSD 3-Clause Clear License
59 stars 32 forks source link

Enhancement: #24

Closed AzzaAzza69 closed 4 years ago

AzzaAzza69 commented 4 years ago

First the TKGridCellPainter.DrawCellFocus method should have the logic that decides if it SHOULD paint moved to a separate check, ie. was:

procedure TKGridCellPainter.DrawCellFocus(const ARect: TRect; SkipTest: Boolean);
begin
  if (gdFocused in FState) and (SkipTest or (FGrid.Options * [goRangeSelect, goRowSelect,
    goDrawFocusSelected] = [goDrawFocusSelected])) then
  begin
    // to ensure coming DrawFocusRect will be painted correctly:
    SetBkColor(FCanvas.Handle, $FFFFFF);
    SetTextColor(FCanvas.Handle, 0);
    FCanvas.DrawFocusRect(FCellRect);
  end;
end;

change to:

function TKGridCellPainter.ShouldDrawFocus(): Boolean;
begin
  Result:=(gdFocused in FState) and (FGrid.Options * [goRangeSelect, goRowSelect,
    goDrawFocusSelected] = [goDrawFocusSelected]);
end;

procedure TKGridCellPainter.DrawCellFocus(const ARect: TRect; SkipTest: Boolean);
begin
  if (ShouldDrawFocus() or SkipTest) then
  begin
    // to ensure coming DrawFocusRect will be painted correctly:
    SetBkColor(FCanvas.Handle, $FFFFFF);
    SetTextColor(FCanvas.Handle, 0);    
    FCanvas.DrawFocusRect(ARect);  //  note the use of ARect parameter and not the FCellRect
  end;
end;

And the "hard-coded" call in TKCustomGrid.PaintToCanvas can be replaced (to allow the custom drawing to function) from this:

    // draw a focus rectangle around cells in goRangeSelect and goRowSelect mode
    if not (csDesigning in ComponentState) and (goDrawFocusSelected in FOptions) and
      (FOptions * [goRangeSelect, goRowSelect] <> []) and Focused and not EditorMode then
    begin
      // to ensure coming DrawFocusRect will be painted correctly:
      SetBkColor(DC, $FFFFFF);
      SetTextColor(DC, 0);
      ACanvas.DrawFocusRect(SelectionRect);
    end;

to this:

    // draw a focus rectangle around cells in goRangeSelect and goRowSelect mode
    if not (csDesigning in ComponentState) and (goDrawFocusSelected in FOptions) and
      (FOptions * [goRangeSelect, goRowSelect] <> []) and Focused and not EditorMode then
    begin
      CellPainter.Canvas:=ACanvas;
      CellPainter.DrawCellFocus(SelectionRect, True);
    end;
kryslt commented 4 years ago

Will be fixed.