Class XbpPushButton() Foundation

Class function of the XbpPushButton class.

Superclass
Description

The XbpPushbutton class provides the pushbutton dialog element. This dialog element causes an action after the button is clicked with the mouse. The action to be performed is defined in a callback code block assigned to the :activate callback slot or is implemented in the :activate() method of a user defined subclass derived from the XbpPushButton class. For more information on the mechanics of callback methods and callback slots see the section "Basics of Xbase Parts" in the chapter "User interface and dialog concepts" in the Xbase++ documentation.

A pushbutton is a rectangular area on the screen where a character string or bitmap can be displayed. Both text and bitmaps appearing on the face of pushbuttons are referred to as pushbutton captions in Xbase++. Since the caption is part of the system resources of the pushbutton, it must be defined before the:create() method is executed.

Class methods
:new()
Creates an instance of the XbpPushButton 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.

:autoSize
Automatically fits the size of the pushbutton to the caption.
:border
Determines whether a border is displayed for the pushbutton.
:caption
The caption of the pushbutton.
:dllName
Name of the DLL file containing icons or bitmaps
:pointerFocus
Indicates whether the pushbutton receives input focus when the mouse is clicked on it.
:preSelect
Determines whether the pushbutton initially has the input focus.
:visualStyle
Specifies the visual style to use for display.
:drawMode
Specifies the drawing mode of the pushbutton object.
:default
Specifies the pushbutton to be the default button of the form.
:cancel
Specifies the XbpPushbutton to be the cancel button of the form.
Life cycle
:create()
Requests system resources for the XbpPushButton object.
:configure()
Reconfigures the XbpPushButton object after :create() has been executed.
:destroy()
Releases the system resources of the XbpPushButton object.
Manipulation
:setCaption()
Specifies a new caption.
Events
:activate
Executes the method or code block that is linked to the pushbutton.
:draw
Informs the application that an owner-drawn pushbutton object needs to be redrawn.
Examples
Create pushbutton

// In the example, two pushbuttons are created that 
// output text in an XbpCrt window using QOut() 
// after they are "pressed". 

#include "Appevent.ch" 

PROCEDURE Main 
   LOCAL nEvent, mp1, mp2, oXbp 
   SetColor("N/W") 
   CLS 

   // Create first pushbutton, specify position using :create() 
   oXbp := XbpPushButton():new() 
   oXbp:caption := "A" 
   oXbp:create( , , {10,20}, {100,40} ) 
   oXbp:activate := {|| QOut( "Pushbutton A" ) } 

   // Create second pushbutton, specify position using :new() 
   oXbp := XbpPushButton():new( , , {150,20}, {100,40} ) 
   oXbp:caption := "B" 
   oXbp:create() 
   oXbp:activate := {|| QOut( "Pushbutton B" ) } 

   // Event loop = Program navigation 
   nEvent := 0 
   DO WHILE nEvent <> xbeP_Close 
      nEvent := AppEvent( @mp1, @mp2, @oXbp ) 
      oXbp:HandleEvent( nEvent, mp1, mp2 ) 
   ENDDO 
RETURN 
Pushbuttons for database navigation

// The example demonstrates how a user defined 
// class can be defined to perform database 
// operations using default pushbuttons. In the 
// DbPushButton class, the default operations SKIP 
// GO TOP and GO BOTTOM are implemented. 
// Note: The :create() and :configure() methods are 
// not fully implemented in the example. Normally 
// they receive additional parameters like oParent 
// and oOwner. 

#include "Appevent.ch" 

#define DB_PB_GOTOP     1 
#define DB_PB_GOBOTTOM  2 
#define DB_PB_SKIPDOWN  3 
#define DB_PB_SKIPUP    4 

PROCEDURE Main 
   LOCAL nEvent, mp1, mp2, oXbp 
   SetColor("N/W") 
   CLS 

   USE Customer NEW 

   // Create user defined pushbuttons 
   DbPushButton():new( ,, { 10,20}, DB_PB_GOTOP    ):create() 
   DbPushButton():new( ,, {110,20}, DB_PB_SKIPDOWN ):create() 
   DbPushButton():new( ,, {210,20}, DB_PB_SKIPUP   ):create() 
   DbPushButton():new( ,, {310,20}, DB_PB_GOBOTTOM ):create() 

   // Event loop 
   nEvent := 0 
   DO WHILE nEvent <> xbeP_Close 
      nEvent := AppEvent( @mp1, @mp2, @oXbp) 
      oXbp:HandleEvent( nEvent, mp1, mp2 ) 

      ? "The record is:", Recno() 
   ENDDO 

   CLOSE Customer 
RETURN 

// User defined pushbutton for database operations 
CLASS DbPushbutton FROM XbpPushbutton 
   EXPORTED: 
   VAR    type, dbArea  READONLY 
   METHOD init, create, configure, destroy, activate 
ENDCLASS 

// Initialize superclass and this class 
METHOD DbPushbutton:init( oParent, oOwner, aPos, nType ) 
   LOCAL aCaption := {"First", "Last", "Next", "Previous"} 

   ::XbpPushButton:init( oParent, oOwner, aPos ) 
   ::dbArea   := 0 
   ::type     := nType 
   ::caption  := aCaption[ nType ] 
   ::autoSize := .T. 
RETURN self 

// Request system resources 
METHOD DbPushbutton:create() 
   ::XbpPushButton:create() 
   ::dbArea := Select() 
RETURN self 

// Configure system resources 
METHOD DbPushbutton:configure() 
   ::XbpPushButton:configure() 
   ::dbArea := Select() 
RETURN self 

// Destroy system resources 
METHOD DbPushbutton:destroy() 
   ::XbpPushButton:destroy() 
   ::dbArea := 0 
RETURN self 

// Callback method for the event xbeP_Activate 
METHOD DbPushbutton:activate 
   DO CASE 
   CASE ::type == DB_PB_GOTOP 
      ( ::dbArea )->( DbGoTop() ) 
   CASE ::type == DB_PB_GOBOTTOM 
      ( ::dbArea )->( DbGoBottom() ) 
   CASE ::type == DB_PB_SKIPDOWN 
      ( ::dbArea )->( DbSkip(1) ) 
   CASE ::type == DB_PB_SKIPUP 
      ( ::dbArea )->( DbSkip(-1) ) 
   ENDCASE 
RETURN self 
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.