Recent

Author Topic: Assistance with StringGrid scrollbar bug  (Read 4866 times)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Assistance with StringGrid scrollbar bug
« on: September 14, 2014, 11:34:09 pm »
In response to JuhaManninen's call to arms, I dove into Mantis.  I've found a bug that I feel I'm right on the verge of fixing, I'm just stuck at the last moment and need some help :-)

All the pertinent details are in:
http://bugs.freepascal.org/view.php?id=19982

Turns out we've a bug in TCustomGrid - there's some whitespace that only appears under certain circumstances, and I don't think we're dealing with that.  Ignore my comment in the bugtracker - I'm not going to bed until this is busted :-)

I've got the scrollbar now correctly sizing when white space appears.  Problem is, this now means the scrollbar doesn't fully represent the grid - it represents the grid + the whitespace.  When I then move the scrollbar, there's a chance there won't be any whitespace left on the screen, and so maybe the scrollbar isn't needed anymore.

So, in Procedure TCustomGrid.WMHScroll(Var message: TLMHScroll);, when we receive SB_ENDSCROLL, I'm now recalculating if we need the scrollbar or not. 

And I've stepped through the code.  It works.  Horizontal scrollbar is now correctly calculated to be hidden, and when I call UpdateSBVisibility, I can confirm that the following function is called with the correct values.
function ShowScrollBar(Handle: HWND; wBar: Integer; bShow: Boolean): Boolean;

Problem is, the sodding scrollbar doesn't vanish.  However, if I then click anywhere on the grid, the scrollbar immediately vanishes.

I'm thinking this perhaps has something to do with me sending one message (whatever the scrollbar hide message is) while in the middle of processing another (SB_ENDSCROLL).

Does this sound plausible to anyone?  Doesn't to me, but I can't think of any other reason the scrollbar is remaining visible...

I've included a screendump showing some relevant debug info...

Here's the code I'm currently calling in Procedure TCustomGrid.WMHScroll(Var message: TLMHScroll);
Code: [Select]
    SB_ENDSCROLL:
    begin
      ResetSizes;
      UpdateSBVisibility;
      Invalidate;
      Exit;
    end;   
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

jesusr

  • Sr. Member
  • ****
  • Posts: 499
Re: Assistance with StringGrid scrollbar bug
« Reply #1 on: September 14, 2014, 11:48:54 pm »
What Lazarus version/revision are you using?, What grid are you testing?

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: Assistance with StringGrid scrollbar bug
« Reply #2 on: September 14, 2014, 11:53:08 pm »
I'm doing my experimental code in Lazarus 1.2.4 (I've got that running from a USB key and can use it at a decent workstation).  If I do get this fixed I plan to then move across to my diddly notebook, port my changes to the SVN build (from a few weeks ago) and create a diff from there.

I'm doing all my testing with a TStringGrid.  I was able to confirm that the issue in TDBGrid is more easily reproducible in a TStringGrid (no need for the DB layer), so I'm working with that for now.  I won't upload any patches without confirming my working theory that the two issues are identical.

UPDATE:  I've now retested with a TDBGrid, and confirmed my theory that it's a bug in TCustomGrid.  Surprisingly, my code is fully working in TDBGrid (scrollbar hides when I tell it to), so it's only TStringGrid that the scrollbar is remaining visible after being told to go away....
« Last Edit: September 14, 2014, 11:57:10 pm by Mike.Cornflake »
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

jesusr

  • Sr. Member
  • ****
  • Posts: 499
Re: Assistance with StringGrid scrollbar bug
« Reply #3 on: September 14, 2014, 11:57:03 pm »
I ask because I cannot reproduce bug 19982 in trunk, however I found another bug which makes the grid to crash when the last column in dbgrid is too big (or so it appears) I'm tracking down that.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: Assistance with StringGrid scrollbar bug
« Reply #4 on: September 14, 2014, 11:59:17 pm »
I was able to reproduce the bug in SVN 45863.  Took me a while to reproduce though.  The amount of white space available has to be equal to the amount the thumb can grow by before it's reproducible.  The project I've uploaded to the bug tracker has all the column widths arranged just right so it's easy to see.
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: Assistance with StringGrid scrollbar bug
« Reply #5 on: September 15, 2014, 12:03:16 am »
If you're interested, so far my changes are (of course I'll upload a proper diff once everything is fully tested):
in TCustomGrid.GetSBRanges
Code: [Select]
        HsbRange := GridWidth - GetBorderWidth;

changed to

        If (MaxClientXY.x<ClientWidth) Then
          HsbRange := GridWidth - GetBorderWidth + (ClientWidth-MaxClientXY.x)
        Else
          HsbRange := GridWidth - GetBorderWidth;
And

Code: [Select]
    HsbPage := ClientWidth;

changed to

     If MaxClientXY.x<ClientWidth Then
      HsbPage := ClientWidth - (ClientWidth-MaxClientXY.x)
    Else
      HsbPage := ClientWidth; 

(And the code already posted in Procedure TCustomGrid.WMHScroll)
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

jesusr

  • Sr. Member
  • ****
  • Posts: 499
Re: Assistance with StringGrid scrollbar bug
« Reply #6 on: September 15, 2014, 12:15:37 am »
any help is welcome, just be sure you update to current trunk revision, 45863 is too old. Once you update, try again to reproduce the problems.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: Assistance with StringGrid scrollbar bug
« Reply #7 on: September 15, 2014, 12:19:01 am »
any help is welcome, just be sure you update to current trunk revision, 45863 is too old. Once you update, try again to reproduce the problems.
OK.  In that case it'll be two or three weeks before I'm in a position to upload anything.  I'm working in the north sea on a vessel that's got lots of internet ports blocked - including the ones used by SVN.
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

 

TinyPortal © 2005-2018