/***************************************************************************************/ /* */ /* SCS editor Version 2 */ /* File : EditorsMachine.pkg */ /* Version : 3 juillet 2000 */ /* SCOL machine for running module editors. */ /* */ /***************************************************************************************/ /* Here is the list of the runing editors identified by a key, * and a channel in which it is opened. * It is used to avoid to launch the same editor several times. */ var EDITOR_CLOSE = 0b00000001;; var EDITOR_MINIMIZE = 0b00000010;; var EDITOR_RESTORE = 0b00000100;; var EDITOR_MAXIMIZE = 0b00001000;; var EDITOR_SAVE = 0b00010000;; var EDITOR_HIDE = 0b00100000;; var EDITOR_UNHIDE = 0b01000000;; var EDITOR_TOP = 0b10000000;; var MOD_BLOCK_DMI = "dmi";; var DEFCOM_BLOCK_SIZE = 1024;; var MODULE_MODIFIED_NAME = 0b1;; struct EditorCore = [ EDICOkey : I ,/* module key */ EDICOname : S ,/* module name */ EDICOclassName : S ,/* class name */ EDICOclassFile : S ,/* class file (with path) */ EDICOclassVersion : [S r1] ,/* calss version */ EDICObitmap : S ,/* bitmap filename */ EDICOhelp : S ,/* help file name */ EDICOchannel : Chn ,/* channel in which the editor is opened */ EDICOdefinitions : [[S [[S r1] r1]] r1] ,/* module definitions */ EDICOmainWin : ObjWin ,/* main editor window */ EDICOcbModified : fun[EditorCore] I /* callback used when a module parameter has been modified */ ] mkEditorCore ;; struct EditorsMachine = [ EDMAedList : [EditorCore r1] ,/* opened editors list */ EDMAcancel : I ,/* cancel launch */ EDMAbuffer : S ,/* buffer for large definition blocks transfer */ EDMAchannel : Chn ,/* machine channel for com with the editors manager*/ EDMAmainWin : ObjWin /* Application window (mother of all the editor windows)*/ ] mkEditorsMachine ;; typeof EdMa = EditorsMachine;; defcom SeditorsMachineStarted = EditorsMachineStarted;; defcom SeditorStarted = EditorStarted I;; defcom SeditorClosed = EditorClosed I I I;; defcom SsetDefBlock = SetDefBlock I S S;; defcom SsetModuleNameAndApply = SetModuleNameAndApply I S;; defcom SsetModuleBitmap = SetModuleBitmap I S;; defcom SresetDefinitions = ResetDefinitions I;; defcom SsendKeyboardEvent = SendKeyboardEvent I I I;; /**************************************************************************************** Communication functions ****************************************************************************************/ fun _connected () = _on _channel SeditorsMachineStarted []; 0 ;; fun _closed () = _closemachine; 0 ;; fun _GetEditorByChn (edList, chn) = let edList -> [first next] in if first == nil then nil else if first.EDICOchannel==chn then first else _GetEditorByChn next chn ;; fun _GetEditorByKey (edList, key) = let edList -> [first next] in if first == nil then nil else if first.EDICOkey==key then first else _GetEditorByKey next key ;; fun _RemoveEditorByKey (edList, key) = let edList -> [first next] in if first == nil then nil else if first.EDICOkey==key then next else first::(_RemoveEditorByKey next key) ;; fun _RemoveEditorByChn (edList, chn) = let edList -> [first next] in if first == nil then nil else if first.EDICOchannel==chn then next else first::(_RemoveEditorByChn next chn) ;; /*************************************************************************************** * * The following functions are called by the Editors Manager * ***************************************************************************************/ /*************************************************************************************** * * Function which allow to run a new editor window * * IniEditor to initialize a new editor * then LoadDefBlock * to load definitions block * then RunEditor to launch the editor script * ***************************************************************************************/ fun __IniEditor (key) = let _GetEditorByKey EdMa.EDMAedList key -> edico in if edico != nil then 0 else let mkEditorCore [key nil nil nil nil nil nil nil nil nil nil] -> newCoed in ( set EdMa.EDMAedList = newCoed::EdMa.EDMAedList; 0 ) ;; fun __ResetEditor (key) = let _GetEditorByKey EdMa.EDMAedList key -> edico in if edico != nil then ( set edico.EDICOdefinitions = nil; set EdMa.EDMAbuffer = nil; 0 ) else 0 ;; fun __RunEditor (key, moduleName, script, className, classPath, bitmapFile, helpFile) = let _GetEditorByKey EdMa.EDMAedList key -> edico in if edico==nil then nil else let hd strextr className -> cn in if edico.EDICOchannel == nil then let _openchannel nil script _envchannel _channel -> cc in ( set edico.EDICOchannel = cc; set edico.EDICOname = moduleName; set edico.EDICObitmap = bitmapFile; set edico.EDICOhelp = helpFile; set edico.EDICOclassName = hd cn; set edico.EDICOclassFile = classPath; set edico.EDICOclassVersion = tl cn; set EdMa.EDMAcancel = nil; _scriptc cc "IniEditor \"\""; _on _channel SeditorStarted [key]; if EdMa.EDMAcancel != nil then _on EdMa.EDMAchannel SeditorClosed [key nil nil] else nil; /*_TOPwindow _SETfocus EdMa.EDMAmainWin;*/ _TOPwindow _SETfocus _ENwindow edico.EDICOmainWin 1; 0 ) else ( set edico.EDICOname = moduleName; set edico.EDICObitmap = bitmapFile; set edico.EDICOhelp = helpFile; set edico.EDICOclassName = hd cn; set edico.EDICOclassFile = classPath; set edico.EDICOclassVersion = tl cn; exec edico.EDICOcbModified with [edico]; 0 ); 0 ;; /**************************************************************************************** * function to load the definition blocks * the defName and the key must be nil while the defBlockPacket is not the last. ****************************************************************************************/ fun __LoadDefBlock (key, defName, defBlockPacket) = if key!=nil && defName!=nil then let _GetEditorByKey EdMa.EDMAedList key -> edico in let strextr (strcat EdMa.EDMAbuffer defBlockPacket) -> defBlock in ( set edico.EDICOdefinitions = [defName defBlock]::edico.EDICOdefinitions; set EdMa.EDMAbuffer = nil; 0 ) else ( set EdMa.EDMAbuffer = strcat EdMa.EDMAbuffer defBlockPacket; 0 ) ;; fun _SendDef (key, defName, defString) = let strlen defString -> ll in if ll > DEFCOM_BLOCK_SIZE then let substr defString 0 DEFCOM_BLOCK_SIZE -> sdef in let substr defString DEFCOM_BLOCK_SIZE ll-DEFCOM_BLOCK_SIZE -> ndef in ( _on EdMa.EDMAchannel SsetDefBlock [nil nil sdef]; _SendDef key defName ndef; 0 ) else ( _on EdMa.EDMAchannel SsetDefBlock [key defName defString]; 0 ) ;; fun _SaveDefinitionsBlock (key, definitions) = let definitions -> [first next] in if first==nil then nil else let first -> [defName defBlock] in ( _SendDef key defName (strbuild defBlock); _SaveDefinitionsBlock key next; 0 ) ;; /**************************************************************************************** * * Functions to control the editor windows * ****************************************************************************************/ fun _SaveEditor (edico) = if edico==nil then nil else if edico.EDICOdefinitions==nil then nil else ( set edico.EDICOdefinitions = _SetDefLine edico.EDICOdefinitions MOD_BLOCK_DMI "bitmap" edico.EDICObitmap::nil; _on EdMa.EDMAchannel SresetDefinitions [edico.EDICOkey]; /* reset the module definitions in the SCS */ _SaveDefinitionsBlock edico.EDICOkey edico.EDICOdefinitions; /* save all the editor definitions (dmi & custom ones)*/ _on EdMa.EDMAchannel SsetModuleBitmap [edico.EDICOkey edico.EDICObitmap]; /* save the module icone */ _on EdMa.EDMAchannel SsetModuleNameAndApply [edico.EDICOkey edico.EDICOname]; /* save the module name */ 0 ) ;; fun __EDITOR_ControlWindow (key, flag) = let _GetEditorByKey EdMa.EDMAedList key -> edico in if edico.EDICOmainWin == nil then nil else ( if flag&EDITOR_SAVE then ( _SaveEditor edico;0) else 0; if flag&EDITOR_HIDE then ( _SHOWwindow edico.EDICOmainWin WINDOW_HIDDEN;0) else if flag&EDITOR_UNHIDE then ( _SHOWwindow edico.EDICOmainWin WINDOW_UNHIDDEN;0) else 0; if flag&EDITOR_CLOSE then let _GETwindowExSizePosition edico.EDICOmainWin -> [_ _ x y] in ( _on EdMa.EDMAchannel SeditorClosed [edico.EDICOkey x y]; set EdMa.EDMAedList = _RemoveEditorByKey EdMa.EDMAedList key; _SHOWwindow edico.EDICOmainWin WINDOW_HIDDEN; _DSwindow edico.EDICOmainWin; _killchannel edico.EDICOchannel; 0 ) else if flag&EDITOR_MINIMIZE then ( _SHOWwindow edico.EDICOmainWin WINDOW_MINIMIZED;0) else if flag&EDITOR_RESTORE then ( _SHOWwindow edico.EDICOmainWin WINDOW_RESTORED;0) else 0; if flag&EDITOR_TOP then ( /*_TOPwindow _SETfocus EdMa.EDMAmainWin;*/ _TOPwindow _SETfocus edico.EDICOmainWin;0) else 0 ) ;; fun __EDITOR_MoveWindow (key, posx, posy) = let _GetEditorByKey EdMa.EDMAedList key -> edico in if edico.EDICOmainWin == nil then nil else _MVwindow edico.EDICOmainWin posx posy ;; /**************************************************************************************** * * Functions for the editor: * * . proto EDITOR_CreateCore = fun [ObjWin mainWin] EditorCore : Create and get a new editor core structure for an editor window. * . proto EDITOR_GetCore = fun [] EditorCore : Get the editor core structure * . proto EDITOR_Save = fun [] I : Set the definitions block and module name in the dms structure. (for Apply button) * . proto EDITOR_Close = fun [] I : Close the editor without saving changes in the dms structure (for Cancel button) * . proto EDITOR_KeyDown = fun [I I] I: send a keydown event to the main window * . proto EDITOR_KeyUp = fun [I I] I: send a keyup event to the main window * ****************************************************************************************/ fun EDITOR_CreateCore (mainWin) = let _GetEditorByChn EdMa.EDMAedList _channel -> edico in ( set edico.EDICOmainWin = mainWin; edico ) ;; fun EDITOR_Save () = let _GetEditorByChn EdMa.EDMAedList _channel -> edico in _SaveEditor edico ;; fun EDITOR_Close () = let _GetEditorByChn EdMa.EDMAedList _channel -> edico in let _GETwindowExSizePosition edico.EDICOmainWin -> [_ _ x y] in ( _on EdMa.EDMAchannel SeditorClosed [edico.EDICOkey x y]; set EdMa.EDMAedList = _RemoveEditorByChn EdMa.EDMAedList _channel; _SHOWwindow edico.EDICOmainWin WINDOW_HIDDEN; _DSwindow edico.EDICOmainWin ); set EdMa.EDMAcancel = 1; _closechannel; 0 ;; fun EDITOR_CBmodified (f,param) = let _GetEditorByChn EdMa.EDMAedList _channel -> edico in set edico.EDICOcbModified = mknode f param; 0 ;; fun EDITOR_WinMother () = EdMa.EDMAmainWin;; fun EDITOR_KeyDown (scancode,asciicode) = _on EdMa.EDMAchannel SsendKeyboardEvent [1 scancode asciicode];; fun EDITOR_KeyUp (scancode,asciicode) = _on EdMa.EDMAchannel SsendKeyboardEvent [0 scancode asciicode];; /****************************************************************************/ /* */ /* fun endEditor ( ) -> u0 */ /* */ /* Editeur signale au SCSeditor de fermer le channel d'edition */ /* */ /* (from DMS/SCS/scs.main.pkg (844) */ /****************************************************************************/ fun endEditor () = EDITOR_Close;; /* from SCS 1, scs.main.pkg (809) */ fun updateEditor (s)= EDITOR_Save;; /*##########################################################################*/ /***************************************************************************************** * * Function called when the Editors Machine is created * *****************************************************************************************/ fun main (port) = let _openchannel port nil _envchannel _channel -> cc in /* let _CRwindow _channel nil 0 0 0 0 WN_HIDDEN|WN_NOCAPTION nil -> win in*/ set EdMa = mkEditorsMachine [ nil nil nil cc /*win*/nil]; _SETdefaultFont _CRfont _channel 14 0 0 "Arial"; PARAMS_Init; KEYBOARD_Init; _IniHelp ; GRAPHICDRESSING_InitDressing; GRAPHICDRESSING_SetTheme PARAMS_GetS SCSparameters "SCSDATA_SKIN"; GRAPHICDRESSING_SetLocaleFunction @_locSCS; GRAPHICDRESSING_SetBackgroundColor GD_DEFAULT_BACKGROUNDCOLOR ;;