/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ /* */ fun getevents(l)= let sizelist l -> size in let nil -> ndata in let 0 -> i in ( while i < size do ( let nth_list l i -> elem in set ndata = ["EVENT" elem]::ndata; set i = i + 1; ); ndata; );; fun cbCloseEdit(p)= let p -> [xmldata winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 eventlistMark ctrlListen] in let XMLgetMarkByValue xmldata "wordlist" -> eventlistMark in let XMLgetMarksParamByValueFromMarkSons eventlistMark "event" "value" -> leventval in let getEdCtrlCheckState ctrlenableReco -> initStartReco in let getEdCtrlCheckState ctrlenableDict -> initStartDict in let getEdCtrlCheckState ctrlListen -> listen in ["xmldata" (strtoweb XMLserialize xmldata)]:: ["enableReco" itoa initStartReco]:: ["enableDict" itoa initStartDict]:: ["listen" itoa listen]:: (getevents leventval);; fun AddwordList(p, fathermark)= let p -> [xmldata winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 eventlistMark ctrlVolume] in let getEdCtrlTextLineValue ctrladdword -> value in if (value == nil) || (!strcmp "" strtrim value) then nil else let getEdCtrlListElems ctrlword -> lelem in if (isStringInListi lelem (strtrim value)) then nil else ( addEdCtrlList ctrlword value nil nil; setEdCtrlTextLineValue ctrladdword nil; setEdctrlTextLineFocus ctrladdword; XMLaddMark xmldata "word" fathermark ["value" (strtrim value)]::nil nil; // get the new element position in list and select the new added element let (getEdCtrlListNbElems ctrlword) - 1 -> npos in selectEdCtrlListByPos ctrlword npos; ); 0;; fun cbAddwordList(ctrlstr, p, fathermark)= AddwordList p fathermark; 0;; fun cbAddwordValide(ctrlstr, value, p, fathermark)= AddwordList p fathermark; 0;; fun cbDelwordList(ctrlstr, p, fathermark)= let p -> [xmldata winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 eventlistMark ctrlVolume] in let getSelectedEdCtrlList ctrlword -> [name _ _] in let XMLgetMarkByValueAndParamValueFromMark fathermark "word" "value" name -> wordmark in ( XMLdelMark xmldata wordmark; delEdCtrlList ctrlword name; ); 0;; /*=== Click event et implémenter la liste word ===*/ fun cbClickevent(ctrlstr, pos, elem, lval, type, p) = let p -> [xmldata winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 eventlistMark ctrlVolume] in if elem == nil then ( resetEdCtrlList ctrlword; setEdCtrlButtonEnable ctrlbtnadd2 0; setEdCtrlButtonEnable ctrlbtndel2 0; setEdCtrlTextLineEnable ctrladdword 0; 0; ) else ( if ((elem == nil) || (!strcmp "" (strtrim elem))) then nil else ( let XMLgetMarkByValue xmldata "wordlist" -> eventlistMark in let XMLgetMarkByValueAndParamValueFromMark eventlistMark "event" "value" elem -> eventmark in let XMLgetMarksParamByValueFromMarkSons eventmark "word" "value" -> lwordval in ( fillEdCtrlList ctrlword lwordval; setEdCtrlListEnable ctrlword 1; setEdCtrlButtonEnable ctrlbtnadd2 1; setEdCtrlButtonEnable ctrlbtndel2 1; setEdCtrlTextLineEnable ctrladdword 1; //setEdctrlTextLineFocus ctrladdword; setEdCtrlButtonCb ctrlbtnadd2 mkfun2 (mkfun3 @cbAddwordList eventmark) p ; setEdCtrlButtonCb ctrlbtndel2 mkfun2 (mkfun3 @cbDelwordList eventmark) p ; setEdCtrlTextLineCbValidate ctrladdword mkfun3 (mkfun4 @cbAddwordValide eventmark) p; ); ); 0; ); 0;; fun addenventList(p)= let p -> [xmldata winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 eventlistMark ctrlVolume] in let getEdCtrlTextLineValue ctrladdevent -> value in if (value == nil) || (!strcmp "" strtrim value) then nil else let getEdCtrlListElems ctrlevent -> lelem in if (isStringInListi lelem (strtrim value)) then nil else ( addEdCtrlList ctrlevent value nil nil; setEdCtrlTextLineValue ctrladdevent nil; setEdctrlTextLineFocus ctrladdevent; XMLaddMark xmldata "event" eventlistMark ["value" (strtrim value)]::nil nil; /*get the new element position in list and select the new added element*/ let (getEdCtrlListNbElems ctrlevent) - 1 -> npos in selectEdCtrlListByPos ctrlevent npos; /* simulate the click callback*/ cbClickevent ctrlevent nil value nil nil p; ); 0;; fun cbAddeventList(ctrlstr, p)= addenventList(p); 0;; fun cbAddeventValide(ctrlstr, value, p)= addenventList(p); 0;; fun cbDeleventList(ctrlstr, p)= let p -> [xmldata winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 eventlistMark ctrlVolume] in let getSelectedEdCtrlList ctrlevent -> [name _ _] in if name == nil then nil else ( let XMLgetMarkByValueAndParamValueFromMark eventlistMark "event" "value" name -> eventmark in ( XMLdelMark xmldata eventmark; delEdCtrlList ctrlevent name; /*get the new selected element after delete*/ let getSelectedEdCtrlList ctrlevent -> [elem lval type] in /*simulate the click callback*/ cbClickevent ctrlevent nil elem lval type p; ); ); 0;; /*=============================== CB Load and export XML ============================================*/ fun cbDlgGetPath(dlg, p, pfile)= let p -> [_ winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 _ _] in ( if pfile == nil then nil else let _PtoScol pfile -> file in let (XMLload file) -> xmldata in if file == nil || xmldata == nil then ( _DLGMessageBox _channel winstr.EDW_win (loc "OS3DSPEECHRECOGNITION_0003") (loc "OS3DSPEECHRECOGNITION_0009") 0; 0; ) else ( let if (XMLgetMarkByValue xmldata "wordlist") == nil then (XMLaddMark xmldata "wordlist" nil nil nil) else (XMLgetMarkByValue xmldata "wordlist") -> eventlistMark in let XMLgetMarksParamByValueFromMarkSons eventlistMark "event" "value" -> leventval in ( mutate p <- [xmldata _ _ _ _ _ _ _ _ _ eventlistMark _]; fillEdCtrlList ctrlevent leventval; let getSelectedEdCtrlList ctrlevent -> [name _ _] in if name == nil then ( setEdCtrlListEnable ctrlword 0; setEdCtrlButtonEnable ctrlbtnadd2 0; setEdCtrlButtonEnable ctrlbtndel2 0; setEdCtrlTextLineEnable ctrladdword 0; 0; ) else ( cbClickevent ctrlevent 0 name nil nil p; 0; ); ); 0; ); ); 0;; fun cbLoadFileXML(ctrlbtn, p)= let p -> [xmldata winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 eventlistMark ctrlVolume] in _DLGrflopen _DLGOpenFile _channel winstr.EDW_win nil nil "Xml file\0*.xml\0All\0*.*\0\0" @cbDlgGetPath p; 0;; fun cbDlgSaveXml(dlg, p, wfile)= let p -> [xmldata winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 eventlistMark ctrlVolume] in let _PtoScol (_WtoP wfile) -> file in if wfile == nil then nil else if file == nil then ( _DLGMessageBox _channel winstr.EDW_win (loc "OS3DSPEECHRECOGNITION_0003") (loc "OS3DSPEECHRECOGNITION_0009") 0; 0; ) else let getFileExt file -> ext in let if !strcmpi "xml" ext then file else strcat file ".xml" -> file in ( XMLwrite xmldata file; 0; ); 0;; fun cbExportXML(ctrlstr, p, inst)= let p -> [xmldata winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 eventlistMark ctrlVolume] in _DLGrflsave _DLGSaveFile _channel winstr.EDW_win nil (strcat (getPluginInstanceName inst) ".xml") "Xml file\0*.xml\0All\0*.*\0\0" @cbDlgSaveXml p; 0;; /*===================================================================================================*/ fun dynamicedit(winstr, inst, viewstr, applybtn)= // let _GETscreenSize -> [sw sh] in let [400 330] -> [iw ih] in let getPluginInstanceUserActions inst -> levent in let getPluginInstanceUserEvents inst -> lword in ( setEdWindowSize winstr iw ih; /*implémenter les valeur enregistrés dans les differents composants*/ let XMLloadString webtostr (getPluginInstanceParam inst "xmldata") -> xmldata in let if xmldata == nil then XMLcreate nil nil else xmldata -> xmldata in let if (XMLgetMarkByValue xmldata "wordlist") == nil then (XMLaddMark xmldata "wordlist" nil nil nil) else (XMLgetMarkByValue xmldata "wordlist") -> eventlistMark in let XMLgetMarksParamByValueFromMarkSons eventlistMark "event" "value" -> leventval in let atoi (getPluginInstanceParam inst "enableReco") -> initStartReco in let if initStartReco == nil then 1 else initStartReco -> initStartReco in let atoi (getPluginInstanceParam inst "enableDict") -> initEnableDict in let if initEnableDict == nil then 0 else initEnableDict -> initEnableDict in let (getPluginInstanceParam inst "path") -> path in let atoi (getPluginInstanceParam inst "listen") -> listen in let if listen == nil then 1 else listen -> listen in /*Création les différents composants*/ let crEdCtrlLabel winstr 10 12 (iw / 2 - 20) 20 (loc "OS3DSPEECHRECOGNITION_0004") nil -> labelc1 in let crEdCtrlLabel winstr (iw / 2) + 10 10 (iw / 2 - 20) 20 (loc "OS3DSPEECHRECOGNITION_0008") nil -> labelc2 in let crEdCtrlList winstr 10 35 (iw / 2 - 10) 150 LB_BORDER|LB_VSCROLL|ET_TABFOCUS EDWIN_RESIZE_MW|EDWIN_RESIZE_MH -> ctrlevent in let crEdCtrlList winstr (iw / 2) + 10 35 (iw / 2 - 10) 150 LB_BORDER|LB_VSCROLL|ET_TABFOCUS EDWIN_RESIZE_MW|EDWIN_RESIZE_MH -> ctrlword in let crEdCtrlTextLine winstr 10 190 (iw / 2 - 60) 20 nil nil EDWIN_RESIZE_MW -> ctrladdevent in let crEdCtrlTextLine winstr (iw / 2) + 10 190 (iw / 2 - 60) 20 nil nil EDWIN_RESIZE_MW -> ctrladdword in let crEdCtrlButton winstr (iw / 2 - 45) 190 20 20 "+" EDWIN_RESIZE_MW -> ctrlbtnadd1 in let crEdCtrlButton winstr (iw / 2 - 20) 190 20 20 "-" EDWIN_RESIZE_MW -> ctrlbtndel1 in let crEdCtrlButton winstr (iw / 2) + 10 + (iw / 2 - 55) 190 20 20 "+" EDWIN_RESIZE_MW -> ctrlbtnadd2 in let crEdCtrlButton winstr (iw / 2) + 10 + (iw / 2 - 30) 190 20 20 "-" EDWIN_RESIZE_MW -> ctrlbtndel2 in let crEdCtrlButton winstr (iw / 2 - 140) 220 120 20 (loc "OS3DSPEECHRECOGNITION_0006") nil -> ctrlLoadXML in let crEdCtrlButton winstr (iw / 2 + 30) 220 120 20 (loc "OS3DSPEECHRECOGNITION_0005") nil -> ctrlbExportXML in let crEdCtrlCheck winstr 10 255 280 20 (loc "OS3DSPEECHRECOGNITION_0007") EDWIN_RESIZE_MW -> ctrllisten in let crEdCtrlCheck winstr 10 285 280 20 (loc "OS3DSPEECHRECOGNITION_0001") EDWIN_RESIZE_MW -> ctrlenableDict in let crEdCtrlCheck winstr 10 310 280 20 (loc "OS3DSPEECHRECOGNITION_0002") EDWIN_RESIZE_MW -> ctrlenableReco in let [xmldata winstr ctrlenableReco ctrlenableDict ctrlevent ctrladdevent ctrlword ctrladdword ctrlbtnadd2 ctrlbtndel2 eventlistMark ctrllisten] -> p in ( setEdCtrlButtonCb ctrlbtnadd1 mkfun2 @cbAddeventList p; setEdCtrlButtonCb ctrlbtndel1 mkfun2 @cbDeleventList p; /*== CB Load and export XML ==*/ setEdCtrlButtonCb ctrlLoadXML mkfun2 @cbLoadFileXML p; setEdCtrlButtonCb ctrlbExportXML mkfun2 mkfun3 @cbExportXML inst p; setEdCtrlCheckState ctrlenableDict initEnableDict; setEdCtrlCheckState ctrlenableReco initStartReco; setEdCtrlCheckState ctrllisten listen; fillEdCtrlList ctrlevent leventval; let getSelectedEdCtrlList ctrlevent -> [name _ _] in if name == nil then ( setEdCtrlListEnable ctrlword 0; setEdCtrlButtonEnable ctrlbtnadd2 0; setEdCtrlButtonEnable ctrlbtndel2 0; setEdCtrlTextLineEnable ctrladdword 0; 0; ) else ( cbClickevent ctrlevent 0 name nil nil p; 0; ); setEdCtrlListCbClick ctrlevent mkfun6 @cbClickevent p; setEdCtrlTextLineCbValidate ctrladdevent mkfun3 @cbAddeventValide p; [mkfun1 @cbCloseEdit p nil]; ); );;