Class XbpSpinButton() Foundation

Class function of the XbpSpinButton class.

Superclass
Description

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 height of the entry field of the spin button is automatically adjusted to the selected font by OS/2. The height cannot be set by the user because the presentation manager does not support this.

Class methods
:new()
Creates an instance of the XbpSpinButton class.
Configuration

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.

:fastSpin
Determines whether fast increment and decrement is turned on.
:increment
Specifies the increment for the value of the spin button.
:master
Defines another spinbutton as master.
:padWithZeros
Fills (or left pads) the numeric value in the entry field of the spinbutton with zeros.
:useUpDownControl
Controls the internal composition of the spin button object.
Runtime Data
:displayPrefix
Defines whether a number format-specific prefix is displayed.
:numberFormat
Selects the number format for display.
Life cycle
:create()
Requests system resources for the XbpSpinButton object.
:configure()
Reconfigures the XbpSpinButton object after :create() has been executed.
:destroy()
Releases the system resources of the XbpSpinButton object.
Increment/Decrement
:spinDown()
Decrements the numeric value by a specific amount.
:spinUp()
Increments the numeric value by a specific amount.
Editing
:editBuffer()
Returns the value in the edit buffer of the spinbutton.
:getData()
Returns the numeric value in the edit buffer of the spinbutton.
:setData()
Sets the value of the edit buffer of the spinbutton.
:setNumLimits()
Defines the range of valid values for the spinbutton.
Events
:down
The numeric value of the spinbutton has been decremented.
:endSpin
Incrementing or decrementing the spinbutton has terminated.
:up
The numeric value of the spinbutton has been incremented.
Examples
Set RGB colors using spinbuttons

// 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 
Feedback

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.