REM getSelectedFont
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
|