Recent

Author Topic: [SOLVED] TCDWidgetSet.DrawFocusRect always returns false  (Read 2143 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
[SOLVED] TCDWidgetSet.DrawFocusRect always returns false
« on: July 08, 2023, 12:13:37 pm »
lcl/interfaces/customdrawn/customdrawnwinapi.inc has function TCDWidgetSet.DrawFocusRect(DC: HDC; const Rect: TRect): boolean;
Code: Pascal  [Select][+][-]
  1. function TCDWidgetSet.DrawFocusRect(DC: HDC; const Rect: TRect): boolean;
  2. var
  3.   LazDC: TLazCanvas absolute DC;
  4. begin
  5.   {$ifdef VerboseCDWinAPI}
  6.     DebugLn(Format('[DrawFocusRect] DC: %x', [PtrUInt(DC)]));
  7.   {$endif}
  8.   Result := False;
  9.  
  10.   if not IsValidDC(DC) then exit;
  11.  
  12.   // Drawer.DrawFocusRect alters the Pen and Brush, so we save the state here
  13.   LazDC.SaveState();
  14.   GetDefaultDrawer().DrawFocusRect(LazDC, Types.Point(Rect.Left, Rect.Top),
  15.     Types.Size(Rect.Right - Rect.Left, Rect.Bottom - Rect.Top));
  16.   LazDC.RestoreState(-1);
  17. end;
  18.  
As can be seen, the function always returns false. If IsValidDC(DC) is true then GetDefaultDrawer().DrawFocusRect is called, which means the function should return true.
The following patch fixes that.
Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi.inc b/lcl/interfaces/customdrawn/customdrawnwinapi.inc
  2. index d64c094dc0..57e37a563b 100644
  3. --- a/lcl/interfaces/customdrawn/customdrawnwinapi.inc
  4. +++ b/lcl/interfaces/customdrawn/customdrawnwinapi.inc
  5. @@ -1086,6 +1086,7 @@ begin
  6.    GetDefaultDrawer().DrawFocusRect(LazDC, Types.Point(Rect.Left, Rect.Top),
  7.      Types.Size(Rect.Right - Rect.Left, Rect.Bottom - Rect.Top));
  8.    LazDC.RestoreState(-1);
  9. +  Result := True;
  10.  end;
  11.  
  12.  function TCDWidgetSet.DrawFrameControl(DC: HDC; const Rect: TRect; uType,
« Last Edit: July 08, 2023, 02:21:34 pm by lagprogramming »

wp

  • Hero Member
  • *****
  • Posts: 12601
Re: TCDWidgetSet.DrawFocusRect always returns false
« Reply #1 on: July 08, 2023, 01:40:33 pm »
Applied, thank you.

 

TinyPortal © 2005-2018