*-- TRAFICOP Program * This is the main program in all modeless applications * It is based on Fox Software's EX1 example code * and uses the Foundation READ technique to handle multi-windowed * applications. * * It uses naming conventions to handle the window types, and the * way that they behave (they inherit their behavior from their type). * * WR = READ Window * WM = MODAL Window * WC = CONTROL Panel * * Note: Special code has been added for Fox Software's Calculator * and Calendar accessories. * CLOSE ALL CLEAR ALL CLEAR *---for cdata window PUBLIC glYesClose glYesClose = .F. *---for cdata window *--PUBLIC memvars that track window/program switching information PUBLIC glEndProg, gcNextProg, glQuitting *--PUBLIC memvars that track window status information PUBLIC glEditable, glOKtoSave *--PUBLIC memvars to enable/disable directional menus PUBLIC gbTop, gbPrior, gbNext, gbBottom, gbList *--PUBLIC memvars used to dim program run commands * Global variable for dimming program\cdata or progam \hdata PUBLIC glCDataWin,glHDataWin DO SetSets && Sets all the SET commands and sysvars *-- Save the old ERROR, RESOURCE and HELP settings lcOldError = ON("ERROR") lcOldReso = SET("RESOURCE",1) lcOldResoS = SET("RESOURCE") lcOldHelp = SET("HELP",1) lcOldHelpS = SET("HELP") IF GETENV("USER") # "FLASH" ON ERROR DO OnError WITH MESSAGE(), MESSAGE(1), LINENO(), ERROR() ENDIF PUSH MENU _MSYSMENU && Save the old menu SET SYSMENU AUTOMATIC glQuitting = .T. && in case we have no control windows, close when new && one is opened. STORE .F. TO glEndProg, glEditable gcNextProg="" glOKtoSave = .T. DO main.mpr CLEAR *IF !glEndProg DO BckGrnd.SPR && Let's user know that they can start. && Calls Foundation READ *ENDIF *READ VALID MyHandler() CLEAR WINDOW ALL CLOSE DATABASES *-- Reset to former HELP, RESOURCE and ERROR SET HELP TO &lcOldHelp SET HELP &lcOldHelpS SET RESOURCE TO &lcOldReso SET RESOURCE &lcOldResoS ON ERROR &lcOldError POP MENU _MSYSMENU CLEAR *-- End program *!********************************************************************* *! *! Function: MYHANDLER() *! *! Called by: EX1.PRG *! *! Calls: EXCUST.SPR *! : EXPARTS.SPR *! : EXINV.SPR *! : EXSMAN.SPR *! *! *!********************************************************************* * The Foundation READ terminates when this routine returns .T. * As long as it returns .F., execution of the Foundation READ will * continue FUNCTION myhandler PRIVATE m.lcCurrSPR, llRetVal llRetVal = .F. && Initialize our RETURN value IF glEndProg RETURN .T. && Only when 'Exit' is selected ENDIF && from the menu. DO CASE && Handles all other cases *IF !EMPTY(gcNextProg) && Launches an SPR which was CASE !EMPTY(gcNextProg) m.lcCurrSPR = gcNextProg && specified from the menu gcNextProg = "" DO (m.lcCurrSPR) *ENDIF CASE UPPER(LEFT(WONTOP(),2)) = "WR" && READ Window DO TRIM(SUBSTR(WONTOP(),3,7))+".SPR" CASE LEFT(WONTOP(),2) = "WC" * * Following code finds the foremost application window, * then launches the .SPR which controls that window. If none * is found, nothing happens. * * It is executed when the control panel is foremost. * m.lcProgram = CurrSPR() IF !EMPTY(m.lcProgram) DO (m.lcProgram) && Launch code to handle foremost ENDIF && application screen ENDCASE RETURN llRetVal *-- PROCEDURE Efface * Routine to decide whether or not to release the control panel. * * EFFACE is called when either the 'Quit' button has been pressed * or a READ window has been manually closed by clicking in the * close box or by selecting 'Close' from the 'File' menu. * * It looks through all the windows that are open, from back to front. * If it finds any of the user application windows (which * will require the control panel) it simply exits. * * Otherwise, it concludes we're finished with the control panel * and releases it. * * The surrounding application insures that WONTOP() is the control panel. PROCEDURE efface PRIVATE lcWindChck m.lcWindChck = UPPER(WCHILD("",0)) DO WHILE !EMPTY(m.lcWindChck) IF LEFT(m.lcWindChck,2) = "WR" RETURN ENDIF m.lcWindChck = UPPER(WCHILD("",1)) ENDDO IF !EMPTY(WONTOP()) && Release a control window if one exists. RELEASE WINDOW (WONTOP()) lnMesgLine = SROWS() - 1 @ lnMesgLine,0 CLEAR TO lnMesgLine,79 && Turn off the "ghost" message ENDIF *!********************************************************************* *! *! Procedure: STOPREAD *! *!********************************************************************* * Routine executed when the DEACTIVATE clause of one of the * application READs is triggered. If it returns .T., the * READ terminates. Otherwise, it returns .F. * * NOTE: the value of 'glQuitting' may have been set to .T. prior to * entering this routine if the user pressed the 'Quit' button to * terminate the read. FUNCTION stopread PARAMETER m.window PRIVATE m.lcWindChck IF NOT WVISIBLE(m.window) && Did window get closed manually? m.lcWindChck = UPPER(WCHILD("",0)) DO WHILE !EMPTY(m.lcWindChck) IF LEFT(m.lcWindChck,2) = "WC" SHOW WINDOW (m.lcWindChck) TOP EXIT ENDIF m.lcWindChck = UPPER(WCHILD("",1)) ENDDO glQuitting = .T. && and act as if 'Quit' was pressed ENDIF *--- Test for a return from the Calculator/Calendar llWREAD = WREAD() IF !WREAD() IF LEFT(UPPER(WONTOP()),8) $ "CALCULATOR/CALENDAR" llWREAD = .T. ELSE IF glEditable ?? CHR(7) WAIT WINDOW NOWAIT "Cannot exit this window until or selected" lcTempWind = WLAST() SHOW WINDOW (lcTempWind) TOP llWREAD = .T. ELSE llWREAD = .F. ENDIF ENDIF ENDIF RETURN glQuitting OR NOT llWREAD && Stop if 'quitting', or && if WONTOP() isn't a READ window. *-- FUNCTION CurrSPR * * This routine finds the current READ and returns * the .SPR file to run. If there is no READ window * it returns a blank. * FUNCTION CurrSPR PRIVATE m.lcProgram, m.lcWindow m.lcProgram = "" m.lcWindow = UPPER(WCHILD("",0)) DO WHILE !EMPTY(m.lcWindow) IF UPPER(LEFT(m.lcWindow,2)) = "WR" m.lcProgram = TRIM(SUBSTR(m.lcWindow,3,7))+".SPR" ENDIF m.lcWindow = WCHILD("",1) ENDDO RETURN m.lcProgram *-- FUNCTION CurrWR * * This routine finds the current READ and returns * the window name. If there is no READ window * it returns a blank. * FUNCTION CurrWR PRIVATE m.lcWindow, m.lcReadWind m.lcWindow = UPPER(WCHILD("",0)) DO WHILE !EMPTY(m.lcWindow) IF UPPER(LEFT(m.lcWindow,2)) = "WR" m.lcReadWind = m.lcWindow ENDIF m.lcWindow = WCHILD("",1) ENDDO RETURN m.lcReadWind