/* SendToBME.rexx */
/* Copyright 1994 Soft-Logik Publishing Corporation */
/* May not be distributed without Soft-Logik Publishing Corporation's express written permission */
/* $VER: 1.0 alpha 1 */

OPTIONS RESULTS
TRACE OFF

/* Make sure rexx support is opened */
IF ~SHOW('L','rexxsupport.library') THEN
   CALL ADDLIB('rexxsupport.library',0,-30)

ADDRESS 'PAGESTREAM'

/* Check and see if one picture is selected */
getobject type objtype
if objtype~=12 then do
    ADDRESS 'PAGESTREAM'
    allocarexxrequester '"Send to Editor Error!"' 368 59
    reqhandle=result
    addarexxgadget reqhandle EXIT 286 42 70 label "_Exit"
        Exithandle=result
    addarexxgadget reqhandle TEXT 8 10 352 border none string "'One picture must be selected to edit in BME.'"
    addarexxgadget reqhandle TEXT 8 20 352 border none string "'Select only one picture and try again.'"
    doarexxrequester reqhandle
    freearexxrequester reqhandle
    EXIT
end

/* Export the picture to a temp file */
'lockinterface true'
'exportgraphic file t:HotLinkedPicture filter iffilbm status force'
'editpicture external file t:HotLinkedPicture'
'refresh wait'

/* set the default BME path */
bmepath='PageStream3:BME'

/* If BME doesn't exist in the default path, ask the user where it is */
if ~exists('PageStream3:BME') then do
    getfile TITLE "'Please locate BME'" load path "'PageStream3:'" file BME posbutton 'Ok' negbutton 'Cancel'
    if RC=10 then signal cancel
    bmepath=result
end

/* Run BME */
ADDRESS COMMAND
'run >nil:' bmepath

/* Wait until the ARexx port shows up */
do 20
    if ~show(P, 'BME') then call delay(50)
end

/* If the ARexx port didn't show up, alert the user and exit */
if ~show(P, 'BME') then do
    ADDRESS 'PAGESTREAM'
    geterrorstring
    ErrorMsg='Error: '||result
    allocarexxrequester '"Send to Editor Error!"' 368 59
    reqhandle=result
    addarexxgadget reqhandle EXIT 286 42 70 label "_Exit"
        Exithandle=result
    addarexxgadget reqhandle TEXT 8 10 352 border none string "'BME could not be started.'"
    addarexxgadget reqhandle TEXT 8 20 352 border none string ErrorMsg
    doarexxrequester reqhandle
    freearexxrequester reqhandle
    'refresh continue'
    'lockinterface false'
    EXIT
end

ADDRESS 'BME'
'screentofront'
'open t:HotLinkedPicture'

/* While the user is in BME, let's get some info about the pic from PageStream */
ADDRESS 'PAGESTREAM'
getpicture position pstem frame fflag contentoffset cstem contentscale cstem rotation rstem about rstem constrain cflag print pflag

/* Wait for the user to finish in BME */
do forever
    if show(P, 'BME') then call delay(50)
        else signal update
end

/* update pgs and exit */
UPDATE:
ADDRESS 'PAGESTREAM'
'screentofront'
/*'editpicture path t:HotLinkedPicture'
'editpicture internal'*/

'deleteobject'
'placegraphic file t:HotLinkedPicture filter iffilbm'
editpicture position pstem.left pstem.top pstem.right pstem.bottom skew rstem.slant rstem.twist
if fflag=ON then editpicture framed contentoffset cstem.x cstem.y contentscale cstem.h cstem.v
editpicture
signal cancel

CANCEL:
ADDRESS 'PAGESTREAM'
'refresh continue'
'lockinterface false'
ADDRESS COMMAND
'delete t:HotLinkedPicture'
EXIT
