BBjFontChooser::cancelSelection

Description

In BBj 7.00 and higher, this method programmatically clicks the BBjFontChooser's [Cancel] button.

Syntax

Return Value

Method

void

cancelSelection()

Parameters

None.

Return Value

None.

Remarks

Although this is a programmatic action, invoking this method causes the BBjFontChooser to dispatch an ON_FONTCHOOSER_CANCEL event. Use this to simulate clicking the [Cancel] button.

Example

rem 'This sample displays a BBjFontChooser in a window, then times out

rem 'after 5 seconds and cancels the selection.
rem 'Obtain the instance of the BBjAPI object
let myAPI! = BBjAPI()

rem 'Open the SysGui device
SYSGUI = UNT
OPEN (SYSGUI)"X0"

rem 'Obtain the instance of the BBjSysGui object
let mySysGui! = myAPI!.getSysGui()

rem 'Set addWindow param values
X = 100
Y = 100
WIDTH = 400
HEIGHT = 250
TITLE$="BBjFontChooser"

rem 'Create a window
myWindow! = mySysGui!.addWindow(X,Y,WIDTH,HEIGHT,TITLE$,$00010003$)

rem 'Create font
myFont! = mySysGui!.makeFont("Times New Roman", 24, mySysGui!.BOLD)

rem 'Add a font chooser on the window
myFontChooser! = myWindow!.addFontChooser(101,0,0,WIDTH,HEIGHT,myFont!)

rem 'Register the CALLBACK routines
CALLBACK(ON_FONTCHOOSER_APPROVE,APPROVE,mySysGui!.getContext(),myFontChooser!.getID())
CALLBACK(ON_FONTCHOOSER_CANCEL,CANCEL,mySysGui!.getContext(),myFontChooser!.getID())
CALLBACK(ON_RESIZE,RESIZE,mySysGui!.getContext())
CALLBACK(ON_CLOSE,CANCEL,mySysGui!.getContext())

rem 'Set timer for approve selection dialog
myAPI!.createTimer("timeout", 5, "CANCEL_FONT")

rem 'Process Events
process_events

RESIZE:
    myFontChooser!.setSize(myWindow!.getWidth(),myWindow!.getHeight())
return

rem 'Callback routine called when the fontchooser's OK button is pressed
APPROVE:
    rem 'Display a message with the approprate font
    gosub FontInfo
    message$="Selected font: "+info$
    GOTO FINISH

FontInfo:
    Font! = myFontChooser!.getSelectedFont()
    name$ = Font!.getName()
    style = Font!.getStyle()
    size = Font!.getSize()
    if (style = 0) then
        style$="Plain"
        html$ = str(size)+"px "+name$
    else
        style$=""
        if (fnIsBitSet(style,Font!.FONT_BOLD)) then
            style$ = style$+"Bold "
        endif
        if (fnIsBitSet(style,Font!.FONT_ITALIC)) then
            style$ = style$+"Italic "
        endif
        style$ = cvs(style$,3)
        html$ = cvs(style$,8)+" "+str(size)+"px "+name$
    endif
    info$ = name$+" "+style$+" "+str(size)
return

def fnIsBitSet(value,bit)
return sgn(dec(and(bin(value,4),bin(bit,4))))
fnend

rem 'Callback routine called when the fontchooser's Cancel button is
rem 'pressed or the window is closed without selecting a font
CANCEL:
    rem 'Display a message notifying of the cancel
    MESSAGE$="No font was chosen!"
    GOTO FINISH

    rem 'Timeout -- cancel font selection

CANCEL_FONT:
    myAPI!.removeTimer("timeout",err = SKIP)
    myFontChooser!.cancelSelection()

SKIP:
return

FINISH:
    myAPI!.removeTimer("timeout",err=*next)
    myWindow!.destroy()

    rem 'Display a message with the selected font
    PRINT MESSAGE$
    WAIT 5
release

See Also

BBjAPI

BBjSysGui

BBjWindow

BBjFontChooser

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.