Recent

Author Topic: TListBox flickers when scrolling (laz 1.4.0)  (Read 24851 times)

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #45 on: October 18, 2015, 04:42:40 pm »
Yes, XP, both 32 and 64bit.
I don't know much about LCL, but isn't it posssible to run default rendering only when OnDrawItem is not assigned and listbox does not have ownerdraw* style?
Something like
Code: Pascal  [Select][+][-]
  1.     WM_ERASEBKGND:
  2.       begin
  3.         WindowInfo := GetWin32WindowInfo(Window);
  4.         if ((WindowsVersion <= wvXP) or not ThemeServices.ThemesEnabled)
  5.            and not (TCustomListBox(WindowInfo^.WinControl).Style in [lbOwnerDrawFixed,lbOwnerDrawVariable]) then
  6.           // Standardbehavior for XP, or no themes
  7.           Result := CallDefaultWindowProc(Window, Msg, WParam, LParam)
  8.         else
  9.         begin
  10.           // Avoid unnecessary background paints to avoid flickering of the listbox
  11.  
  12.           Count := SendMessage(Window, LB_GETCOUNT, 0, 0);
  13.           if Assigned(WindowInfo^.WinControl) and
  14.             (TCustomListBox(WindowInfo^.WinControl).Columns < 2) and
  15.             (Count <> LB_ERR) and (SendMessage(Window, LB_GETITEMRECT, Count - 1, Windows.LParam(@ARect)) <> LB_ERR) then
  16.           begin
  17.             Top := ARect.Bottom;
  18.             Windows.GetClientRect(Window, ARect);
  19.             ARect.Top := Top;
  20.             if not IsRectEmpty(ARect) then
  21.               Windows.FillRect(HDC(WParam), ARect, WindowInfo^.WinControl.Brush.Reference.Handle);
  22.             Result := 1;
  23.           end
  24.           else
  25.             Result := CallDefaultWindowProc(Window, Msg, WParam, LParam);
  26.           Exit;
  27.         end;
  28.       end;    
I have not tested it properly, but it looks harmless to me.
« Last Edit: October 18, 2015, 05:12:12 pm by ncs-sniper »

wp

  • Hero Member
  • *****
  • Posts: 13269
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #46 on: October 18, 2015, 06:25:05 pm »
Code: Pascal  [Select][+][-]
  1.     WM_ERASEBKGND:
  2.       begin
  3.         WindowInfo := GetWin32WindowInfo(Window);
  4.         if ((WindowsVersion <= wvXP) or not ThemeServices.ThemesEnabled) then
  5.         begin
  6.           if Assigned(WindowInfo^.WinControl) and not
  7.              (TCustomListbox(WindowInfo^.WinControl).Style in [lbOwnerDrawFixed, lbOwnerDrawVariable])
  8.           then begin
  9.             // Standardbehavior for XP, or no themes, no OwnerDraw
  10.             Result := CallDefaultWindowProc(Window, Msg, WParam, LParam);
  11.             exit;
  12.           end
  13.         end;
  14.         // Avoid unnecessary background paints to avoid flickering of the listbox
  15.         Count := SendMessage(Window, LB_GETCOUNT, 0, 0);
  16.         if Assigned(WindowInfo^.WinControl) and
  17.           (TCustomListBox(WindowInfo^.WinControl).Columns < 2) and
  18.           (Count <> LB_ERR) and (SendMessage(Window, LB_GETITEMRECT, Count - 1, Windows.LParam(@ARect)) <> LB_ERR) then
  19.         begin
  20.           Top := ARect.Bottom;
  21.           Windows.GetClientRect(Window, ARect);
  22.           ARect.Top := Top;
  23.           if not IsRectEmpty(ARect) then
  24.             Windows.FillRect(HDC(WParam), ARect, WindowInfo^.WinControl.Brush.Reference.Handle);
  25.           Result := 1;
  26.         end
  27.         else
  28.           Result := CallDefaultWindowProc(Window, Msg, WParam, LParam);
  29.         Exit;
  30.       end;
  31.  
This is better, your code may crash if the WinInfo^.WinControl is nil -- no idea, if this can happen.

I don't have XP, only on a virtual machine. The modification seems to run fine there. Please test thoroughly on your "real" XP - there are not so many XP users out there any more. Test also if non-ownerdrawn or unthemed listboxes are painted correctly with erased background. Post the result here, and I'll submit the new version as a patch to bugtracker.

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #47 on: October 18, 2015, 07:27:15 pm »
Ok, will do tonight. But I can test it only on XP SP3 32b, XP 64b in virtual machine, Vista SP2 HomePrem. 32b and Win7 64b virtual (can't remember exact version). Do you thing it will be enough?

wp

  • Hero Member
  • *****
  • Posts: 13269
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #48 on: October 18, 2015, 07:29:53 pm »
Certainly, more than I had expected

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #49 on: October 19, 2015, 07:21:27 pm »
Ok, I have tested it on attached program. I have tried it both with themes enabled and disabled where possible and of course 64bit builds. I have used code from your post with one change - it seems the background painting bug is manifesting itself even on winXP 64bit, which are AFAIK based on Win. Server 2003, so i have changed it like so:
Code: Pascal  [Select][+][-]
  1. WindowsVersion <= wvServer2003

The results are:
Win XP SP3 32b - ok
Win XP 64b in VirtualBox - ok (after the mentioned change)
Win Vista Home Premium SP1 32b - ok
Win 7 Ultimate SP1 64b in VirtualBox - ok

wp

  • Hero Member
  • *****
  • Posts: 13269
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #50 on: October 19, 2015, 07:44:05 pm »
Perfect. I reopened the old bug report, Juha will certainly apply the patch soon.

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #51 on: October 19, 2015, 10:49:02 pm »
Many thanks!

 

TinyPortal © 2005-2018