rem 'namespace.bbj
sysgui = unt
open (sysgui)"X0"
api! = BBjAPI()
sysgui! = api!.getSysGui()
rem 'retrieve a namespace, get value of count
if (api!.isInMDI()) then
sharedNS! = api!.getGroupNamespace()
prefix$ = "basis.eng.test.namespace"
else
if (argc < 2) then
rem 'run from command line with no namespace name
prefix$ = "basis.eng.test.namespace"
sharedNSName$ = "test"
sharedNS! = api!.getNamespace(prefix$, sharedNSName$, 1)
else
rem 'run from command line with a namespace name
prefix$ = argv(1)
sharedNSName$ = "test"
sharedNS! = api!.getNamespace(prefix$, sharedNSName$, 1)
endif
endif
rem 'retrieve count from sharedNS! and use it to create our name
count = sharedNS!.getValue("count", err = setCount)
privateNS! = api!.getNewNamespace(prefix$)
privateNS!.setValue("count",0)
name$ = "client-" + privateNS!.getName()
rem 'retrieve position from sharedNS! and increment it
sharedNS!.setLock("x", 500, err = onLocked)
x = sharedNS!.getValue("x", err = setXY)
sharedNS!.setValue("x", x+50)
sharedNS!.removeLock("x")
sharedNS!.setLock("y", 500, err = onLocked)
y = sharedNS!.getValue("y", err = setXY)
sharedNS!.setValue("y", y+50)
sharedNS!.removeLock("y")
rem 'create window
window! = sysgui!.addWindow(x,y,300,200,name$)
rem 'add some static text fields
window!.addStaticText(101,5,50,290,30,"sharedCount: ")
window!.addStaticText(102,5,70,290,30,"privateCount: ")
rem 'add buttons and callbacks
plus! = window!.addButton(1,5,10,90,30,"Increment")
minus! = window!.addButton(2,105,10,90,30,"Decrement")
break! = window!.addButton(3,5,110,90,30,"Break")
sharedCount! = window!.addStaticText(103,200,50,290,15,str(count))
privateCount! = window!.addStaticText(104,200,70,290,15,str(0))
break!.setCallback(break!.ON_BUTTON_PUSH,"onBreak")
rem 'set callback for controls
plus!.setCallback(plus!.ON_BUTTON_PUSH, "onPlus")
minus!.setCallback(plus!.ON_BUTTON_PUSH, "onMinus")
window!.setCallback(window!.ON_ACTIVATE, "onActivate")
rem 'set callback that is to be called when count changes
sharedNS!.setCallbackForVariable("count", "showCount")
privateNS!.setCallbackForVariable("count", "showCount")
rem 'call onActivate to set tell others we have activated
gosub onActivate
callback(ON_CLOSE,done,sysgui!.getContext())
rem 'if running in MDI, register a callback for MDI closing
if (api!.isInMDI()) then
mdi! = api!.getMDI()
mdi!.registerMDIClosingCallback("mdiClosingCallback")
endif
process_events
rem 'our callbacks
onPlus:
sharedNS!.setLock("count",1500,err = onLocked)
sharedNS!.setValue("count", 1 + sharedNS!.getValue("count"))
sharedNS!.removeLock("count")
privateNS!.setLock("count",1500,err = onLocked)
privateNS!.setValue("count", 1 + privateNS!.getValue("count"))
privateNS!.removeLock("count")
return
onMinus:
sharedNS!.setLock("count",1500,err = onLocked)
sharedNS!.setValue("count", -1 + sharedNS!.getValue("count"))
sharedNS!.removeLock("count")
privateNS!.setLock("count",1500,err = onLocked)
privateNS!.setValue("count", -1 + privateNS!.getValue("count"))
privateNS!.removeLock("count")
return
onActivate:
sharedNS!.setValue("activeClientNS", privateNS!.getName())
sharedNS!.setValue("activeClientName",name$)
return
showCount:
sharedcount!.setText(str(sharedNS!.getValue("count")))
privatecount!.setText(str(privateNS!.getValue("count")))
return
onBreak:
escape
return
done:
release
setXY:
x = 100
y = 100
sharedNS!.setValue("x", x)
sharedNS!.setValue("y", y)
retry
setCount:
count = 0
sharedNS!.setValue("count", count)
retry
onLocked:
print "lock error"
escape
retry
m
rem 'callback to be run when MDI attempts to close
mdiClosingCallback:
print 'EE', 'ask'("MDI is attempting to close",3,"What do you want to do?","Veto close:1","Accept close:2","release:3")
print 'BE'
read(0,siz = 1,err = askCancelled)response
print "answer is " , response
print 'BE'
switch response
case 1
mdi!.vetoMDIClose()
break
case 2
mdi!.approveMDIClose()
break
case 3
gosub done
break
swend
return
askCancelled:
print "ask was cancelled or else closeAll() timed out"
mdi!.approveMDIClose(err=*next)
return
|