BBjMDI::vetoMDIClose

Description

In BBj 3.0 and higher, this method enables a program running within a BBjMDI window to prevent that MDI window from closing.

Syntax

Return Value

Method

void

vetoMDIClose()

Parameters

None.

Return Value

None.

Remarks

The BBjMDI::vetoMDIClose method can only be invoked within a callback registered through a call to BBjMDI::registerMDIClosingCallback(). Otherwise, this method generates an ERROR = ACCESS.

Example

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

Example - MDI master application

0010 REM MDI.closeAll(x) and MDI.closeAllClients(x)
0020 REM ALIAS X1 MDI
0030 sysgui = unt
0040 open(sysgui)"X1"
0050 MDI! = BBjAPI().getMDI()
0060 REM
0070 REM create an MDI Window
0080 REM
0090 mdi!.createMDIWindow(50, 50, 800, 600, "MDI Window")
0100 REM callback for clicking the 'X'
0110 CALLBACK(ON_CLOSE,APP_CLOSE,mdi!.MDI_CONTEXT)
0120 mdi!.setVisible(1)
0130 X$ = "bbj namespace.bbj -tT1 &"; REM ---namespace.bbj can be found in docs at BBjMDI.vetoMDIClose()load
0140 a = scall(x$)
0150 a = scall(x$)
0160 process_events
0170 REM
0180 REM Callback routine called when the user closes the application window
0190 REM
0200 APP_CLOSE:
    0210 print(0)'FOCUS'(0); input "1 for Clients, 2 for Client&Master, 3 for timed C&M: ",z
    0220 if (z = 1) then res= mdi!.closeAllClients(0); goto LAB; REM CLOSE CLIENTS, WAIT FOREVER
    0230 if (z = 2) then res= mdi!.closeAll(0); goto LAB; REM CLOSE CLIENTS AND MASTER, WAIT FOREVER
    0240 if (z = 3) then res= MDI!.closeAll(5); goto LAB; REM CLOSE CLIENTS AND MASTER, WAIT 5 SECONDS
    0250 LAB: ?"closeAll: RES: =",res; if (res = 1) then escape
    260 return

See Also

BBjAPI

BBjMDI

Object Variables

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