BBjFontChooser::setSelectedFont

Description

In BBj 7.0 and higher, this method sets the currently selected font in the BBjFontChooser.

Syntax

Return Value

Method

void

setSelectedFont(BBjFont font)

Parameters

Variable

Description

font

The new text to be selected.

Return Value

None.

Remarks

None.

Example

rem 'setSelectedFont

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 = 300
TITLE$="BBjFontChooser"

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

rem 'Add a font chooser on the window
myFontChooser! = myWindow!.addFontChooser(101,0,0,myWindow!.getWidth(),myWindow!.getHeight()-50)

rem 'Instead of OK/Cancel, create a different UI
myFontChooser!.setControlButtonsAreShown(0)

rem 'Create a MenuButton to track recent fonts
myMenuButton! = myWindow!.addMenuButton(102,50,height-40,width-100,30,"Add font to MRU Dropdown")

rem 'Font menu
prev! = null()
item = 1000

rem 'Register the CALLBACK routines
CALLBACK(ON_BUTTON_PUSH,APPROVE,mySysGui!.getContext(),myMenuButton!.getID())
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 'Process Events
process_events

RESIZE:
    if (myWindow!.getHeight()>100 and myWindow!.getWidth()>100) then
        myMenuButton!.setLocation(50,myWindow!.getHeight()-40)
        myMenuButton!.setSize(myWindow!.getWidth()-100,30)
        myFontChooser!.setSize(myWindow!.getWidth(),myWindow!.getHeight()-50)
    endif
return

rem 'Callback routine called when the fontchooser's OK button is pressed
APPROVE:
    Font! = myFontChooser!.getSelectedFont()
    name$ = Font!.getName()
    style = Font!.getStyle()
    size = Font!.getSize()
    if (style = 0) then
        style$="Plain"
    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)
    endif
    info$ = name$+" "+style$+" "+str(size)
    if font!<>prev!
        dropdown! = myMenuButton!.getDropdownMenu()
        if dropdown! = null()
            dropdown! = myMenuButton!.addDropdownMenu()
        endif
        item = item+1
        item! = dropdown!.addMenuItem(item,info$)
        item!.setUserData(font!)
        CALLBACK(ON_POPUP_ITEM_SELECT,menu_item,dropdown!.getID(),item!.getID())
    endif
    prev! = font!
return

rem 'Callback routine called when the user selected an item from the dropdown menu
MENU_ITEM:
    item! = mySysGui!.getLastEvent().getMenuItem()
    font! = item!.getUserData()
    myFontChooser!.setSelectedFont(font!)
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:
release

See Also

BBjAPI

BBjSysGui

BBjWindow

BBjFont

BBjFontChooser

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