Hi All
As of CodeJock 15.3.1 used in VDF 17.1, there is a new scrolling event in the Report Control class which can be used to determine where you have scrolled. Using this event we have been able to get the scroll bar working better when moving the thumb to the bottom or top in a data aware grid with dynamic data (not static).
So when you drag the thumb to the bottom, it will now move to the last record like doing a control end, same with dragging the thumb to the top it will behave like doing a control home. So it doesn't load all the records it just caches the data needed. Dragging the thumb within the scrollbar still just works with the cached data, this behaviour hasn't changed.
So far our testing has been positive, however the code below is supplied as is.
Here are the required classes ...
Code:
// Idle handler to either move to the first or last row when the
// scrollbar thumb is dragged to the very top or bottom respectively
// done here as the scroll event can be called multiple times and we
// only want to do this once and also when the grid has finished doing
// all it's stuff
Class ctaGridScrollingIdleHander is a cIdleHandler
// Construct_Object:
//
Procedure Construct_Object
Forward Send Construct_Object
Property Boolean pbTop False
Property Boolean pbFound_Last False
End_Procedure // Construct_Object
// OnIdle:
//
Procedure OnIdle
Boolean bLoadedAllData
Get AllDataIsLoaded Of (phoDataSource(Self)) To bLoadedAllData
If (pbTop(Self)) Begin
If (NOT(bLoadedAllData)) Send MoveToFirstRow
Set pbFound_Last To False
End
Else Begin
If (NOT(bLoadedAllData)) Send MoveToLastRow
Set pbFound_Last To True
End
Set pbEnabled To False
End_Procedure // OnIdle
End_Class // ctaGridScrollingIdleHander
Code:
Class ctaGridScrolling_Mixin is a Mixin
// Define_ctaGridScrolling_Mixin:
//
Procedure Define_ctaGridScrolling_Mixin
{ DesignTime=False }
Property Boolean pbLegacy_Scrolling True
{ DesignTime=False }
Property Handle pohScrolling_Idle_Handler 0
{ DesignTime=False }
Property Boolean pbIgnore_Scroll False
{ DesignTime=False }
Property Boolean pbActive_Drag False
End_Procedure // Define_ctaGridScrolling_Mixin
// ReSynchToDataSource:
// Ignore the scrolling logic when resyncing the data source
//
Procedure ReSynchToDataSource
If (pbLegacy_Scrolling(Self)) Set pbIgnore_Scroll To True
Forward Send ReSynchToDataSource
If (pbLegacy_Scrolling(Self)) Set pbIgnore_Scroll To False
End_Procedure // ReSynchToDataSource
// OnComMouseDown:
// Clicking on a row may cause the Scroll event to be called in these cases
// we can disable the idle handler and ignore this behaviour, note the scroll
// event method is called before this one so we disable the idle handler rather than
// set the pbIgnore_Scroll property to false
//
Procedure OnComMouseDown Short llButton Short llShift Integer llx Integer lly
If (pbLegacy_Scrolling(Self)) Begin
If (pbEnabled(pohScrolling_Idle_Handler(Self))) Set pbEnabled Of (pohScrolling_Idle_Handler(Self)) To False
End
Forward Send OnComMouseDown llButton llShift llx lly
End_Procedure // OnComMouseDown
// Dragging_Scrollbar:
// Returns if we are moving the scrollbar with the mouse
//
Function Dragging_Scrollbar Returns Boolean
tWinPoint ltPoint
tWinRect ltRect
Boolean bRetval bSwap
Integer iVoid iScrollbarLeft iState iRptL iRptT iRptR iRptB
Move (GetSystemMetrics(SM_SWAPBUTTON)) To bSwap
If (NOT(bSwap)) Move (GetKeyState(VK_LBUTTON)) To iState
Else Move (GetKeyState(VK_RBUTTON)) To iState
// 0x0000 - not pressed, not toggled 0
// 0x8000 - Pressed, not toggled 32768
// 0x0001 - not pressed, toggled 1
// 0x8001 - Pressed, toggled 32769
If ((iState IAND 32768) = 32768) Begin
Get pbActive_Drag To bRetval
If (NOT(bRetval)) Begin
Move (GetWindowRect(Window_Handle(Self), AddressOf(ltRect))) To iVoid
Move (GetCursorPos(AddressOf(ltPoint))) To iVoid
Send ComGetElementRect xtpReportElementRectReportArea (&iRptL) (&iRptT) (&iRptR) (&iRptB)
Move (ltRect.Right - ((ltRect.Right - ltRect.Left) - iRptR)) To iScrollbarLeft
Move (ltPoint.x > iScrollbarLeft AND ltPoint.x < ltRect.right AND ltPoint.y > ltRect.top AND ltPoint.y < ltRect.bottom) To bRetval
Set pbActive_Drag To bRetval
End
End
Else Begin
Set pbActive_Drag To False
Move (False) To bRetval
End
Function_Return bRetval
End_Function // Dragging_Scrollbar
// OnComVScroll:
// The section is always 1 whilst the position is the position of the scroll thumb
//
Procedure OnComVScroll Integer llSection Integer llPosition
Boolean bSwap bClicked
Integer iState
Handle ohDataSource ohScrollingIdler
If (pbLegacy_Scrolling(Self) AND Dragging_Scrollbar(Self)) Begin
If (NOT(pbIgnore_Scroll(Self))) Begin
Set pbIgnore_Scroll To True
Get phoDataSource To ohDataSource
Get pohScrolling_Idle_Handler To ohScrollingIdler
// Don't do anything if there are no records
If (RowCount(ohDataSource) > 0) Begin
// If the thumb is pulled to the top and the selected row is not the first in the
// data source then enable the idle handler to move to the first row
If (llPosition = 0) Begin
If (SelectedRow(ohDataSource) > 0) Begin
Set pbEnabled Of ohScrollingIdler To True
Set pbTop Of ohScrollingIdler To True
End
End
// else if the we pull the thumb to the bottom which is the position + displayable rows
// greater than the rows in the data source then enable the idle handler to move
// to the last row. N.b. piLastVisibleRowCount is one based
Else Begin
If ((llPosition + piLastVisibleRowCount(Self)) > RowCount(ohDataSource)) Begin
Set pbEnabled Of ohScrollingIdler To True
Set pbTop Of ohScrollingIdler To False
End
End
End
Set pbIgnore_Scroll To False
End
End
End_Procedure // OnComVScroll
// End_Define_ctaGridScrolling_Mixin:
//
Procedure End_Define_ctaGridScrolling_Mixin
Handle ohId
If (pbStaticData(Self)) Set pbLegacy_Scrolling To False
If (pbLegacy_Scrolling(Self)) Begin
Get CreateNamed (RefClass(ctaGridScrollingIdleHander)) "oGridScrollbarIdleHandler" To ohId
Set pohScrolling_Idle_Handler To ohId
End
End_Procedure // End_Define_ctaGridScrolling_Mixin
End_Class // ctaGridScrolling_Mixin
Code:
Class _ctaDbCJGridPromptList is a cDbCJGridPromptList
// Construct_Object:
//
Procedure Construct_Object
Forward Send Construct_Object
Send Define_ctaGridScrolling_Mixin
End_Procedure // Construct_Object
Import_Class_Protocol ctaGridScrolling_Mixin
// End_Construct_Object:
//
Procedure End_Construct_Object
Forward Send End_Construct_Object
Send End_Define_ctaGridScrolling_Mixin
End_Procedure // End_Construct_Object
End_Class // _ctaDbCJGridPromptList
Class ctaDbCJGridPromptList is a _ctaDbCJGridPromptList
End_Class // ctaDbCJGridPromptList
Code:
Class _ctaDbCJGrid is a cDbCJGrid
// Construct_Object:
//
Procedure Construct_Object
Forward Send Construct_Object
Send Define_ctaGridScrolling_Mixin
End_Procedure // Construct_Object
Import_Class_Protocol ctaGridScrolling_Mixin
// End_Construct_Object:
//
Procedure End_Construct_Object
Forward Send End_Construct_Object
Send End_Define_ctaGridScrolling_Mixin
End_Procedure // End_Construct_Object
End_Class // _ctaDbCJGrid
Class ctaDbCJGrid is a _ctaDbCJGrid
End_Class // ctaDbCJGrid