rem 'To see how the group namespace works, launch
rem 'two copies of this program. With just one copy, every
rem 'program running will be in the same group.
rem 'Move the top window around and try resizing it. The
rem 'reason that the child window is able to mimic the parent
rem 'is because the parent is setting its size and position
rem 'in the namespace and the child is responding to these
rem 'values being set. Group namespaces are especially
rem 'useful in an MDI, where the children need to communicate
rem 'settings and application behaviour to one another or
rem 'the parent MDI Window.
declare BBjNamespace groupNS!
declare BBjSysGui sysgui!
declare BBjTopLevelWindow win!
sysgui! = BBjAPI().openSysGui("X0")
groupNS! = BBjAPI().getGroupNamespace()
print groupNS!.getName()
rem '*** Parent program ***
if (argc<2) then
win! = sysgui!.addWindow(10,10,160,120,"Namespace Example")
rem 'give the namespace variables an initial value
gosub updateGroupNS
rem 'whenever the parent is moved or resized, update
rem 'the namespace with the values.
win!.setCallback(win!.ON_WINDOW_MOVE,"updateGroupNS")
win!.setCallback(win!.ON_RESIZE,"updateGroupNS")
win!.setCallback(win!.ON_CLOSE,"the_end")
rem 'Scalled BBj programs are in the same group as
rem 'process that invoked them.
status_code = scall(argv(0)+" "+pgm(-2)+" - 2 &")
process_events
else
rem '*** Child Program ***
parentX = 10
parentY = 10
parentWidth = 160
parentHeight = 120
win! = sysgui!.addWindow(
: parentX,
: parentY+parentHeight+50,
: parentWidth,
: parentHeight,
: "Child of Namespace Example")
win!.setResizable(BBjAPI().FALSE)
rem 'Callbacks on the namespace allow the child process
rem 'to respond when the parent sets namespace values.
groupNS!.setCallbackForVariableChange("X","x_changed")
groupNS!.setCallbackForVariableChange("Y","y_changed")
groupNS!.setCallbackForVariableChange("WIDTH","width_changed")
groupNS!.setCallbackForVariableChange("HEIGHT","height_changed")
groupNS!.setCallbackForVariable("BYE","the_end")
process_events
endif
rem 'The parent's X position has been updated, so set the
rem 'X position of the child in response.
x_changed:
x = cast(BBjNumber,groupNS!.getValue("X"))
win!.setLocation(x,win!.getY())
return
rem 'The parent's Y position has been updated, so set the
rem 'Y position of the child in response.
y_changed:
y = cast(BBjNumber,groupNS!.getValue("Y"))
height = cast(BBjNumber,groupNS!.getValue("HEIGHT"))
win!.setLocation(win!.getX(),y+height+50)
return
rem 'The parent's width has been updated, so set the
rem 'width of the child in response.
width_changed:
width = cast(BBjNumber,groupNS!.getValue("WIDTH"))
win!.setSize(width,win!.getHeight())
return
rem 'The parent's height has been updated, so set the
rem 'height and y position of the child in response.
height_changed:
height = cast(BBjNumber,groupNS!.getValue("HEIGHT"))
heightChange = height-win!.getHeight()
win!.setSize(win!.getWidth(),height)
win!.setLocation(win!.getX(),win!.getY()+heightChange)
return
rem 'Set the values in the namespace whenever the parent
rem 'has been moved or resized.
updateGroupNS:
groupNS!.setValue("X",win!.getX())
groupNS!.setValue("Y",win!.getY())
groupNS!.setValue("HEIGHT",win!.getHeight())
groupNS!.setValue("WIDTH",win!.getWidth())
return
rem 'If the parent is closed, tell the child it's time
rem 'to close too, via the namespace.
the_end:
groupNS!.setValue("BYE","true")
release
|