Event XbpWindow():wheel Foundation
Mouse wheel is activated.
:wheel := {| aPos, aWheel, self | ... }
:wheel( <aPos>, <aWheel> ) --> self
xbeM_Wheel (1048599)
Constant | Description |
---|---|
XBP_MK_LBUTTON | Left mouse button is pressed |
XBP_MK_MBUTTON | Middle mouse button is pressed |
XBP_MK_RBUTTON | Right mouse button is pressed |
XBP_MK_CONTROL | Ctrl key is pressed |
XBP_MK_SHIFT | Shift key is pressed |
This method returns the object executing the method (self).
The xbeM_Wheel event is generated when the user rotates the mouse wheel. This event is always sent to the Xbase Part that has input focus, no matter whether or not the mouse pointer is located within or outside the area of the Xbase Part. All classes derived from XbpWindow that display data which can be vertically scrolled have a default behavior to process this event. This applies to the following classes:
XbpBrowse |
XbpCombobox (XBPCOMBO_DROPDOWNLIST) |
XbpListbox |
XbpMLE |
XbpQuickBrowse |
XbpSpinbutton |
XbpTreeview |
XbpScrollbar *) |
|
The information in the <aWheel> array can be used for computing how far the content of the window needs to be scrolled to reflect the distance and direction in which the user has spun the mouse wheel. The elements in <aWheel> can be used for implementing both line-wise and pixel-wise (or high-resolution) scrolling.
Implementing line-wise scrolling
If the Xbase Part uses line-wise scrolling, for example, because it displays lines of text, a scrolling operation must be performed for as many lines as reported in the nLines element of the <aWheel> array. The xbeM_Wheel events where this element is zero can be ignored.
...
// Line-wise scrolling: perform scrolling for full lines,
// ignore wheel events for partial lines
aWheel := mp2
nLines := aWheel[3]
// Determine whether page-wise scrolling is configured and
// apply user's "lines to scroll" setting (factor)
IF aWheel[5] == -1
lScrollPage := .T.
ELSE
lScrollPage := .F.
nLines *= aWheel[5]
ENDIF
DO WHILE nLines > 0
IF aWheel[3] > 0
IF lScrollPage
::pageDown() // Move view downwards by one page
ELSE
::down() // Move view downwards by one line
ENDIF
ELSE
IF lScrollPage
::pageUp() // Move view upwards by one page
ELSE
::up() // Move view upwards by one line
ENDIF
ENDIF
nLines--
ENDDO
...
If the Xbase Part supports pixel-wise scrolling, however, the view must be scrolled by as many pixels as specified in the nOffset element of the <aWheel> array. The xbeM_Wheel events where this element is zero can be ignored. Note that fast rotations of the mouse wheel can cause "jumps" in a scrolled view when applying the scroll offsets in one go. For a smooth scrolling experience, it is instead recommended to scroll using a limited/fixed increment. This is outlined in the following code snippet.
...
#define SCROLL_UNIT 2
// Pixel-wise scrolling: scroll view for a number of pixels,
// ignore wheel events for partial rotation
aWheel := mp2
nOffset:= Abs( aWheel[4] )
// Determine whether page-wise scrolling is configured and
// apply user's "lines to scroll" setting (factor). If
// page-wise scrolling is configured, use the window height
// as the scroll unit.
IF aWheel[5] == -1
nUnits := ::currentSize()[2]
ELSE
nUnits := Min( nOffset, SCROLL_UNIT )
nOffset *= aWheel[5]
ENDIF
DO WHILE nOffset > 0
IF aWheel[3] > 0
::scrollDown( nUnits )
ELSE
::scrollUp( nUnits )
ENDIF
nOffset -= nUnits
ENDDO
...
When the first element of <aWheel> is not equal to zero, the $ operator can be used to check which additional keys are pressed while the mouse wheel is rotated. For example:
nEvent := AppEvent( @mp1, @mp2, @oXbp )
IF nEvent == xbeM_Wheel
IF XBP_MK_SHIFT $ mp2[1]
// code for Shift key processing
ENDIF
ENDIF
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.