/* Text Editor - DMS - June 98 - by Sylvain HUET */ /* Rev. Aug. '98 - by Marc BARILLEY */ /* Rev. May '01 - by Julien ZORKO */ struct Ttext= [ TXT_Alias : S, /* Alias = action name */ TXT_FileName: S, /* Text file */ TXT_Font : S, /* Text font */ TXT_FontSize: I, /* Text font size */ TXT_FwColor : I, /* Text color */ TXT_BgColor : I /* Background Color */ ] mkText;; /* Interface objects */ typeof MainList=ObjList;; /* main interface list */ typeof AddButton = ObjButton;; /* button for adding a text ref. to the list */ typeof DelButton = ObjButton;; /* button for deleting a text from the list */ typeof FwColorLabel = ObjText;; /* Label */ typeof FwColorButton = ObjButton;; /* button for selecting a font color */ typeof FwColorBitmap = ObjBitmap;; /* */ typeof BgColorLabel = ObjText;; /* Label */ typeof BgColorButton = ObjButton;; /* button for selecting a background color */ typeof BgColorBitmap = ObjBitmap;; /* */ typeof FontSizeLabel = ObjText;; typeof FontSizeField = ObjText;; typeof FontLabel = ObjText;; typeof FontField = ObjText;; typeof FileLabel = ObjText;; typeof FilePreviewButton = ObjButton;; typeof FileButton = ObjButton;; typeof FileField = ObjText;; typeof AliasLabel = ObjText;; typeof AliasField = ObjText;; typeof EditWin =ObjWin;; /* Data objects */ typeof TextList = [Ttext r1];; /* Text list */ typeof Selection = Ttext;; typeof Oldpath=S;; /* update list display */ fun UpdateMainList2(textElt , notUsed)= _ADDlist MainList 1000 strcatn (textElt.TXT_Alias)::" ("::(textElt.TXT_FileName)::")"::nil ;; fun UpdateMainList ()= let _GETlist MainList -> [i _] in ( _RSTlist MainList; apply_on_list TextList @UpdateMainList2 nil; _SELlist MainList i ); 0 ;; fun lastslash(s)= let 0-> i in let 0-> l in ( while i fileName in if fileName == nil then nil else let mkText [fileName fileName "Arial" 6 0 0xffffff] -> newText in ( set Oldpath = substr fileName 0 lastslash fileName; set TextList = listcat TextList newText::nil; UpdateMainList; _SELlist MainList (_GETlistCount MainList)-1; set Selection = newText; UpdateEditor ); 0 ;; fun cbClickAddButton ( a, b) = _DLGrflopen (_DLGOpenFile _channel EditWin Oldpath nil "text (*.txt)\0*.TXT\0all (*.*)\0*.*\0\0") @cbAddNewText nil ;; fun cbClickDelButton (x, b)= let _GETlist MainList -> [i _] in let nth_list TextList i -> text in if text.TXT_Alias == nil then nil else ( set TextList = remove_nth_from_list TextList i; UpdateMainList; _SELlist MainList i-1; set Selection = nth_list TextList (i-1); UpdateEditor ) ;; /******************************************************************************* This recusive function loads text parameters from the dmi block in structs l -> [[S r1] r1] : dmi block <- [Ttext r1] : *******************************************************************************/ fun LoadTextList (l)= if l == nil then nil else let l -> [first next] in let first -> [keyword params] in if strcmp keyword "text" then LoadTextList next else let params -> [alias [filename [other _]]] in let mkText [alias filename "Arial" 6 0 0xffffff] -> newText in let strextr other -> paramList in ( set newText.TXT_FwColor = atoi getInfo paramList "fwColor"; set newText.TXT_BgColor = atoi getInfo paramList "bgColor"; set newText.TXT_FontSize = atoi getInfo paramList "fontSize"; set newText.TXT_Font = getInfo paramList "font"; newText::(LoadTextList next) ) ;; fun cbLoad (l) = set TextList = LoadTextList l; UpdateMainList; _SELlist MainList 0; cbClickSelectList MainList nil 0 nil; 0 ;; fun GetFileNameList(l)= if l == nil then nil else let l -> [first next] in (first.TXT_FileName)::(GetFileNameList next) ;; /******************************************************************************* This function writes new text links in the dmi block with the following format text l -> [Ttext r1] : text links list <- [[s r1] r1]: dmi bloc *******************************************************************************/ fun SaveTextList (l)= if l==nil then nil else let l -> [first next] in let strbuild ("font"::(first.TXT_Font)::nil):: ("fontSize"::(itoa first.TXT_FontSize)::nil):: ("fwColor"::(itoa first.TXT_FwColor)::nil):: ("bgColor"::(itoa first.TXT_BgColor)::nil)::nil -> params in ("action"::first.TXT_Alias::nil):: ("text"::(first.TXT_Alias)::(first.TXT_FileName)::params::nil):: (SaveTextList next) ;; fun cbSave (filename, n)= ("register"::(GetFileNameList TextList)):: ("action"::"destroy"::nil):: ("action"::"start"::"start"::nil):: ("zoneC"::"text"::nil):: (SaveTextList TextList) ;; /******************************************************************************* Change forward and backgroud colors callbacks *******************************************************************************/ fun cbNewFwColor (newColor) = if newColor == nil then nil else ( _DRAWrectangle FwColorBitmap 0 0 15 10 DRAW_SOLID 1 0 DRAW_SOLID newColor; _SETbuttonBitmap FwColorButton FwColorBitmap; set Selection.TXT_FwColor = newColor ); 0 ;; fun cbClickFwColorButton (but, param) = let if Selection.TXT_FwColor == nil then 0 else Selection.TXT_FwColor -> currentColor in _CRcolorMap _channel EditWin 0 0 (_locEditor "TEXTED-ChooseFwColor" nil) @cbNewFwColor currentColor; 0 ;; fun cbNewBgColor (newColor) = if newColor == nil then nil else ( _DRAWrectangle BgColorBitmap 0 0 15 10 DRAW_SOLID 1 0 DRAW_SOLID newColor; _SETbuttonBitmap BgColorButton BgColorBitmap; set Selection.TXT_BgColor = newColor ); 0 ;; fun cbClickBgColorButton (but, param) = let if Selection.TXT_BgColor == nil then 0xffffff else Selection.TXT_BgColor -> currentColor in _CRcolorMap _channel EditWin 0 0 (_locEditor "TEXTED-ChooseBgColor" nil) @cbNewBgColor currentColor; 0 ;; fun cbModifyFontSize (text, param) = let _GETtext text -> txt in set Selection.TXT_FontSize = atoi txt; 0 ;; fun cbModifyFont (text, param) = let _GETtext text -> txt in set Selection.TXT_Font = txt; 0 ;; fun cbSetFile (openBox, param, pFile)= let _PtoScol pFile -> fileName in if fileName == nil then nil else ( set Oldpath = substr fileName 0 lastslash fileName; set Selection.TXT_FileName = fileName; UpdateEditor ); 0 ;; fun cbClickFindFile ( a, b) = _DLGrflopen (_DLGOpenFile _channel EditWin Oldpath nil "text (*.txt)\0*.TXT\0all (*.*)\0*.*\0\0") @cbSetFile 0 ;; fun cbResizePreview (win, richText, w, h) = _SIZErichText richText w-2 h-2 1 1 ;; fun cbClickPreviewFile(button, param)= if Selection.TXT_FileName == nil then nil else let _getpack _checkpack Selection.TXT_FileName -> content in if content == nil then ( _DLGMessageBox _channel EditWin "ERROR" strcat "Can not open file : " Selection.TXT_FileName 0; 0 ) else let _CRwindow _channel EditWin 10 10 400 300 WN_MENU|WN_MINBOX+WN_SIZEBOX Selection.TXT_FileName -> win in let _CRrichText _channel win 1 1 398 298 ET_AHSCROLL|ET_AVSCROLL|ET_ALIGN_LEFT|ET_HSCROLL|ET_VSCROLL|ET_DOWN|ET_NOEDIT/*|ET_HIDDEN*/ nil -> richText in ( _SETbkgColorRichText richText Selection.TXT_BgColor; _SETtextRichText richText content Selection.TXT_Font Selection.TXT_FontSize Selection.TXT_FwColor 0; _CBwinSize win @cbResizePreview richText; 0 ); 0 ;; fun cbModifyFile (text, param) = let _GETtext text -> txt in set Selection.TXT_FileName = txt; UpdateMainList; 0 ;; fun cbModifyAlias (text, param) = let _GETtext text -> txt in set Selection.TXT_Alias = txt; UpdateMainList; 0 ;; fun cbSizeEditWin (win, blurp, w, h)= _SIZElist MainList w-165 h-30 5 25; _SIZEbutton AddButton 75 20 w-155 h-25; _SIZEbutton DelButton 75 20 w-80 h-25; _SIZEbutton FwColorButton 25 20 w-30 h-75; _SIZEbutton BgColorButton 25 20 w-30 h-50; _SIZEtext FwColorLabel 125 20 w-155 h-50; _SIZEtext BgColorLabel 125 20 w-155 h-75; _SIZEtext FontSizeLabel 125 20 w-155 h-100; _SIZEtext FontSizeField 25 20 w-30 h-100; _SIZEtext FontLabel 150 20 w-155 h-140; _SIZEtext FontField 150 20 w-155 h-125; _SIZEtext FileLabel 105 20 w-155 h-180; _SIZEbutton FilePreviewButton 20 15 w-25 h-180; _SIZEbutton FileButton 20 15 w-45 h-180; _SIZEtext FileField 150 20 w-155 h-165; _SIZEtext AliasLabel 150 20 w-155 h-220; _SIZEtext AliasField 150 20 w-155 h-205; 0 ;; /******************************************************************************* Interface creation *******************************************************************************/ fun CreateInterface (win, w, h) = _CRtext _channel win 5 5 w-10 20 ET_ALIGN_LEFT (_locEditor "1050-TEXTED-texts" nil); set MainList=_CRlist _channel win 5 25 w-165 h-30 LB_DOWN+LB_VSCROLL; _CBlistClick MainList @cbClickSelectList 0; set AddButton = _CRbutton _channel win w-155 h-25 75 20 0 (_locEditor "1080-TEXTED-add" nil); _CBbutton AddButton @cbClickAddButton 0; set DelButton = _CRbutton _channel win w-80 h-25 75 20 0 (_locEditor "1090-TEXTED-remove" nil); _CBbutton DelButton @cbClickDelButton 0; set BgColorBitmap = _CRbitmap _channel 15 10; _DRAWrectangle BgColorBitmap 0 0 15 10 DRAW_SOLID 1 0 DRAW_SOLID 0xffffff; set BgColorLabel = _CRtext _channel win w-155 h-50 125 20 0 (_locEditor "TEXTED-BgColor" nil); set BgColorButton = _CRbuttonBitmap _channel win BgColorBitmap w-30 h-50 25 20 0; _CBbutton BgColorButton @cbClickBgColorButton 0; set FwColorBitmap = _CRbitmap _channel 15 10; _DRAWrectangle FwColorBitmap 0 0 15 10 DRAW_SOLID 1 0 DRAW_SOLID 0; set FwColorLabel = _CRtext _channel win w-155 h-75 125 20 0 (_locEditor "TEXTED-FwColor" nil); set FwColorButton = _CRbuttonBitmap _channel win FwColorBitmap w-30 h-75 25 20 0; set FontSizeLabel = _CRtext _channel win w-155 h-100 125 20 0 (_locEditor "TEXTED-FontSize" nil); set FontSizeField = _CReditLine _channel win w-30 h-100 25 20 ET_DOWN|ET_NUMBER "0"; _CBtext FontSizeField @cbModifyFontSize nil; set FontLabel = _CRtext _channel win w-155 h-140 150 20 0 (_locEditor "TEXTED-Font" nil); set FontField = _CReditLine _channel win w-155 h-125 150 20 ET_DOWN "Arial"; _CBtext FontField @cbModifyFont nil; set FileLabel = _CRtext _channel win w-155 h-180 105 20 0 (_locEditor "TEXTED-TextFile" nil); set FileButton = _CRbutton _channel win w-45 h-180 20 15 0 "..."; _CBbutton FileButton @cbClickFindFile 0; set FilePreviewButton = _CRbutton _channel win w-25 h-180 20 15 0 "[P]"; _CBbutton FilePreviewButton @cbClickPreviewFile 0; set FileField = _CReditLine _channel win w-155 h-165 150 20 ET_DOWN ""; _CBtext FileField @cbModifyFile nil; set AliasLabel = _CRtext _channel win w-155 h-220 150 20 0 (_locEditor "TEXTED-Alias" nil); set AliasField = _CReditLine _channel win w-155 h-205 150 20 ET_DOWN ""; _CBtext AliasField @cbModifyAlias nil; _CBbutton FwColorButton @cbClickFwColorButton 0; UpdateEditor; /* _ENbutton FwColorButton 0; _ENbutton BgColorButton 0; */ /*_ENtext FileField 0;*/ 0 ;; /******************************************************************************* Initialisation function s -> S : filename <- I : unused *******************************************************************************/ fun IniEditor (s)= let [345 245] -> [w h] in let startEditor _channel nil nil nil w h WN_MENU EDITOR_NORMAL s "dms/interf/text/text.dmc" nil nil @cbLoad @cbSave nil -> ed in ( set EditWin = getEditWin ed; _CBwinSize EditWin @cbSizeEditWin 0; CreateInterface EditWin w h; if s==nil then nil else openDMI ed ); 0 ;;