Class XbpSpinButton() Foundation
Class function of the XbpSpinButton class.
The XbpSpinButton class provides spinbutton objects. These are dialog elements that can increment or decrement an integer value. A spinbutton consists of an entry field with two arrows displayed on pushbuttons at the right edge. This type of entry field allows direct input of numeric values. The arrows increment and decrement the value in the entry field when they are clicked with the mouse. Alternatively, the numeric value can be changed using the Up and Down arrow keys. The range of valid values for the spinbutton is set to 0 to 99999 by default but can be redefined to fit specific situations.
When incrementing, the numeric value in the entry field is reset to the smallest valid value after the largest value has been reached. Similarly, when decrementing the value is set to the largest valid value after the smallest value has been reached.
The instance variables in this group configure system resources. If changes are made to these values, they must either be made before the :create() method is executed or the :configure() method must be used to activate the changes.
// This example shows a typical use for spinbuttons.
// The RGB color values are set using three spinbuttons.
// The color values set using these spinbuttons are
// assigned to LOCAL variables. For the first spinbutton,
// this is done without using a code block for :dataLink.
// The other two spinbuttons have a data code block
// assigned to :dataLink. The current RGB color is displayed
// using the procedure RGB().
#include "Appevent.ch"
#include "Gra.ch"
PROCEDURE Main
LOCAL nEvent, mp1, mp2, oXbp
LOCAL oSpinRed, oSpinGreen, oSpinBlue, bCallback
LOCAL nRed := 0, nGreen := 0, nBlue := 0
SetColor("N/W")
CLS
// Callback code block
bCallback := {|mp1, mp2, oXbp| nRed := oXbp:getData(), ;
RGB( nRed, nGreen, nBlue ) }
// Create spinbutton for red (without using :dataLink)
oSpinRed := XbpSpinButton():new( ,, {100,200}, {100,40} )
oSpinRed:fastSpin := .T.
oSpinRed:create()
oSpinRed:setNumLimits( 0, 255 )
oSpinRed:endSpin := bCallback
oSpinRed:keyboard := bCallback
// Callback code block
bCallback := {|mp1, mp2, oXbp| oXbp:getData(), ;
RGB( nRed, nGreen, nBlue ) }
// Create spinbutton for green (using :dataLink)
oSpinGreen := XbpSpinButton():new( ,, {100,150}, {100,40} )
oSpinGreen:create()
oSpinGreen:setNumLimits( 0, 255 )
oSpinGreen:dataLink := {|x| IIf( x==NIL, nGreen, nGreen := x ) }
oSpinGreen:endSpin := bCallback
oSpinGreen:keyboard := bCallback
// Create spinbutton for blue (using :dataLink)
// (Master is oSpinGreen)
oSpinBlue := XbpSpinButton():new( ,, {100,100}, {100,40} )
oSpinBlue:master := oSpinGreen
oSpinBlue:create()
oSpinBlue:setNumLimits( 0, 255 )
oSpinBlue:dataLink := {|x| IIf( x==NIL, nBlue, nBlue := x ) }
oSpinBlue:endSpin := bCallback
oSpinBlue:keyboard := bCallback
// Event loop
nEvent := 0
DO WHILE nEvent <> xbeP_Close
nEvent := AppEvent( @mp1, @mp2, @oXbp )
oXbp:HandleEvent( nEvent, mp1, mp2 )
ENDDO
RETURN
PROCEDURE RGB( nRed, nGreen, nBlue )
LOCAL oPS := SetAppWindow():presSpace() // presentation space
LOCAL aAttr := Array(GRA_AA_COUNT) // area attributes
LOCAL nMax := oPS:maxColorIndex() // maximum colors
LOCAL aOldAttr, aOldRGB
// Set new RGB color and draw box
aAttr[ GRA_AA_COLOR ] := nMax
aOldAttr := oPS:setAttrArea( aAttr )
aOldRGB := oPS:setColorIndex( nMax, {nRed,nGreen,nBlue} )
GraBox( oPS, {300,100}, {550,240}, GRA_FILL )
oPS:setAttrArea( aOldAttr )
oPS:setColorIndex( nMax, aOldRGB )
RETURN
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.