public I8 LtfRunEntry(Ltf *l,LtfEntry *cl,BoolU4 exited,BoolU4 old_preempt) { //Call with preempt off I8 result=-1; I1 ch=l->cmd_I1,*st; I8 cb(Ltf *l,LtfEntry *ll); if (!exited) { if (cl->flags & LTFLF_ESC) { Msg(MSG_KEY_DOWN,CH_ESC,0,1<flags & LTFLF_QUIT) { Msg(MSG_KEY_DOWN,CH_CTRLQ,0,1<best_d=MAX_I8; if (cl->flags & LTFLF_LINK) { try { if (ch==CH_SPACE) { if (l->LeftClickLink) l->LeftClickLink(l,cl,old_preempt); } else if (ch==CH_CR) { if (l->RightClickLink) l->RightClickLink(l,cl,old_preempt); } } catch LtfBottom(l); return 0; } if (ch==CH_SPACE && cl->flags & LTFLF_TREE || cl->btype==LTFT_HIDE_START) cl->flags^=LTFLF_COLLAPSED; if ((cl->btype>=LTFT_BUTTON && cl->btype<=LTFT_MENU_VALUE) || cl->btype==LTFT_PICTURE || cl->btype==LTFT_PICWORD || cl->btype==LTFT_TOP_LEFT_TOOLBAR || cl->btype==LTFT_TOP_RIGHT_TOOLBAR) { if (cl->btype==LTFT_CHECK_BOX) cl->flags^=LTFLF_CHECKED; if (ch==CH_SPACE) { if (cl->flags & LTFLF_LEFT_EXP) { result=cl->left_exp; Msg(MSG_CMD,result,0,1<flags & LTFLF_LEFT_CB) { cb=cl->left_cb; Preempt(old_preempt); result=cb(l,cl); Preempt(OFF); Msg(MSG_CMD,result,0,1<flags & LTFLF_LEFT_MACRO) { if (cl->flags & LTFLF_POPUP) { st=NewStr(cl->left_macro); Preempt(old_preempt); PopUp(st,Fs); Preempt(OFF); Free(st); } else { if (cl->flags & LTFLF_LEFT_AUTO) AutoStr("%s",cl->left_macro); else Auto(cl->left_macro); } } } else if (ch==CH_CR) { if (cl->flags & LTFLF_RIGHT_EXP) { result=cl->right_exp; Msg(MSG_CMD,result,0,1<flags & LTFLF_RIGHT_CB) { cb=cl->right_cb; Preempt(old_preempt); result=cb(l,cl); Preempt(OFF); Msg(MSG_CMD,result,0,1<flags & LTFLF_RIGHT_MACRO) { if (cl->flags & LTFLF_POPUP) { st=NewStr(cl->right_macro); Preempt(old_preempt); PopUp(st,Fs); Preempt(OFF); Free(st); } else { if (cl->flags & LTFLF_RIGHT_AUTO) AutoStr("%s",cl->right_macro); else Auto(cl->right_macro); } } } } l->cmd_I1=CH_SPACE; return result; } I1 *EditOverStrikeCB(Ltf *l,LtfEntry *ll,TssStruct *mem_tss) { Ltf *ltf=ll->user_data; I1 *st=MAlloc(8,mem_tss); nounusedwarn l; st[0]=(ltf->flags & LTFF_OVERSTRIKE) ? 'O':130; st[1]=0; return st; } I1 *EditDollarCB(Ltf *l,LtfEntry *ll,TssStruct *mem_tss) { Ltf *ltf=ll->user_data; I1 *st=MAlloc(8,mem_tss); nounusedwarn l; st[0]=(ltf->flags & LTFF_IN_DOLLAR) ? '$$':130; st[1]=0; return st; } I1 *EditQuotesCB(Ltf *l,LtfEntry *ll,TssStruct *mem_tss) { LexStruct *lx=mem_tss->last_lex; I1 *st=MAlloc(8,mem_tss); nounusedwarn l,ll; st[0]=(lx->flags & LF_IN_QUOTES) ? '"':130; st[1]=0; return st; } I1 *EditBracesCB(Ltf *l,LtfEntry *ll,TssStruct *mem_tss) { LexStruct *lx=mem_tss->last_lex; I1 *st=MAlloc(8,mem_tss); nounusedwarn l,ll; st[0]=(lx->braces_cnt) ? '}':130; st[1]=0; return st; } I1 *EditSemicolonCB(Ltf *l,LtfEntry *ll,TssStruct *mem_tss) { LexStruct *lx=mem_tss->last_lex; I1 *st=MAlloc(8,mem_tss); nounusedwarn l,ll; st[0]=(lx->statement_cnt) ? ';':130; st[1]=0; return st; } I1 *EditPreemptCB(Ltf *l,LtfEntry *ll,TssStruct *mem_tss) { I1 *st=MAlloc(8,mem_tss); nounusedwarn l,ll; st[0]=Bt(&mem_tss->task_flags,TSSf_PREEMPT) ? 'P':130; st[1]=0; return st; } I1 *EditDollarTypeCB(Ltf *l,LtfEntry *ll,TssStruct *mem_tss) { Ltf *ltf=ll->user_data; I1 *src=SysTextSub(ltf->cur_entry->btype,"ST_LTF_CMDS"); I1 *st=MAllocZ(8,mem_tss); nounusedwarn l; if (ltf->cur_entry==ltf) { StrCpy(st,"EOF"); } else if (src) StrCpy(st,src); return st; } public BoolU4 DoLtf(Ltf *l,BoolU4 home=TRUE,I1 *help=NULL,BoolU4 help_is_file=FALSE) { Ltf *menu=NULL,*old_ltf=Fs->cur_ltf,*old_aux=Fs->aux_ltf,*aux; I8 old_attribute=Fs->text_attribute; I8 ch=0; U8 sc=0; LtfEntry *ll; void * old_update=Fs->update_win; BoolU4 old_preempt; if (help && !l->menu_ltf) { if (help_is_file) menu=LtfRead(help); else { menu=LtfNew; menu->text_attribute=l->text_attribute; LtfPutSExt(menu,help); } l->menu_ltf=menu; } l->win_tss=Fs; aux=LtfNew; aux->text_attribute=Fs->border_attribute; LtfPutSExt(aux,"$$CM +TY,0,-1$$"); if (Bt(&Fs->crt_flags,CRTf_HAS_CLOSE_WIN)) LtfPutSExt(aux,"$$TX+RX+BD,\"[X]\"$$"); if (l->menu_ltf) LtfPutSExt(aux,"$$TX+LX+BD,\"MENU\"$$"); ll=LtfPutSExt(aux,"$$DA-T-P+BD+RD+CX+SCX+IV,256,\"%s...\",16$$"); ll->data=&l->filename.name; LtfFormatData(ll); if (l->flags & LTFF_ALLOW_UNDO) { LtfPutSExt(aux,"$$CM+BY+LX,0,1$$"); ll=LtfPutSExt(aux,"$$DA+BD+RD-T,32,\"Undo:%04d\"$$\r\n"); ll->data=&l->undo_cnt; LtfFormatData(ll); } LtfPutSExt(aux,"$$CM+BY+RX,-24,1$$"); ll=LtfPutSExt(aux,"$$TX+BD+DC,\" \"$$"); ll->user_data=l; ll->display_cb=&EditDollarTypeCB; LtfPutSExt(aux,"$$CM+BY+RX,-21,1$$"); ll=LtfPutSExt(aux,"$$TX+BD+DC,\" \"$$"); ll->user_data=l; ll->display_cb=&EditOverStrikeCB; LtfPutSExt(aux,"$$CM+BY+RX,-20,1$$"); //gets merged without this ll=LtfPutSExt(aux,"$$TX+BD+DC,\" \"$$"); ll->user_data=l; ll->display_cb=&EditDollarCB; ll=LtfPutSExt(aux,"$$DA+BD+RD-T,32,\"Line:%04d \"$$"); ll->data=&l->line; LtfFormatData(ll); ll=LtfPutSExt(aux,"$$DA+BD+RD-T,32,\"Col:%04d\"$$\r\n"); ll->data=&l->col; LtfFormatData(ll); old_preempt=Preempt(OFF); aux->recalc_start=aux; LtfRecalc(aux); Fs->aux_ltf=aux; l->recalc_start=l; LtfRecalc(l); if (home) LtfHome(l); Fs->cur_ltf=l; Fs->text_attribute=l->text_attribute; AssignBit(&Fs->crt_flags,CRTf_HAS_MENU,l->menu_ltf); Fs->update_win=&LtfUpdateBothLtf; Bts(&Fs->crt_flags,CRTf_SHOW); do { Preempt(OFF); if (ScanKey(&ch,&sc)) { Preempt(old_preempt); PutKey(ch,sc); LtfRecalc(Fs->cur_ltf); } else { Fs->task_flags|=1<rmt_chnl && !(Fs->parent_tss && Fs->parent_tss->popup_tss==Fs)) { Fs->task_flags|=1<task_flags&=~(1<cur_ltf=old_ltf; Fs->aux_ltf=old_aux; AssignBit(&Fs->crt_flags,CRTf_HAS_MENU,old_ltf->menu_ltf); Fs->text_attribute=old_attribute; Fs->update_win=old_update; LtfDel(aux); if (menu) { l->menu_ltf=NULL; LtfDel(menu); } Preempt(old_preempt); return ch==CH_ESC; } #help_index "Ltf/Input" public BoolU4 DoForm(U1 *D,I1 *class_name, I1 *help=NULL,BoolU4 help_is_file=FALSE, I1 *header=NULL,I1 *footer=NULL) //Supply a class name that has fmtstr definitions //and this routine will allow user input. { BoolU4 result=FALSE,old_preempt; MemberListStruct *ml; LtfEntry *ll; I8 ch=0; ClassStruct *cl=FindLocalHash(class_name,HTT_CLASS); Ltf *l; if (!cl) return FALSE; l=LtfNew; if (header) LtfPutSExt(l,header); l->flags|=LTFF_OVERSTRIKE | LTFF_FORM; ml=cl->member_list; while (ml) { if (ml->fmtstr) { ll=LtfPutSExt(l,ml->fmtstr); ll->data=D+ml->offset; ll->my_format_data=ml->fmtdata; LtfFormatData(ll); } ml=ml->next; } if (footer) LtfPutSExt(l,footer); if (l->dummy.next!=l) { l->flags&=~(LTFF_ATTR_BY_PARTITION | LTFF_ATTR_BY_FILENAME); LtfRecalc(l); if (DoLtf(l,TRUE,help,help_is_file)) { old_preempt=Preempt(OFF); ll=l->dummy.next; while (ll!=l) { if (ll->btype==LTFT_DATA || ll->btype==LTFT_CHECK_BOX) LtfGetData(ll); ll=ll->next; } ll=l->cur_entry; if (ll!=l) LtfRunEntry(l,ll,TRUE,old_preempt); Preempt(old_preempt); result=TRUE; } } LtfDel(l); return result; } void EndDoMenuCb() { WinToTop; throw(EXCEPT_LOCAL); } public I8 DoMenu(Ltf *m,I1 *help=NULL,U8 flags=0) { void *old_end_cb=Fs->end_task_cb; LtfEntry *ll; I8 result=-1; BoolU4 old_preempt; Fs->end_task_cb=&EndDoMenuCb; try { if (m) { m->flags&=~(LTFF_ATTR_BY_PARTITION | LTFF_ATTR_BY_FILENAME); if (DoLtf(m,TRUE,help)) { old_preempt=Preempt(OFF); ll=m->cur_entry; if (ll!=m) result=LtfRunEntry(m,ll,TRUE,old_preempt); Preempt(old_preempt); } } } catch { if (Fs->except_argc==1 && Fs->except_argv[0]==EXCEPT_LOCAL) { if (!(flags & LTFPUF_INTERCEPT_TASK_END)) Exit; Fs->catch_except=TRUE; Preempt(old_preempt); } } Fs->end_task_cb=old_end_cb; return result; } #help_index "Ltf" public I8 PopUp(I1 *msg,TssStruct *parent=NULL,TssStruct **pu_tss=NULL) { U8 result=0; BoolU4 old_preempt=Preempt(OFF); TssCmdStruct *tempc; TssStruct *tss; tss=Spawn(&ServantUserCmdLine,"SYSTEM TASK",parent); if (!parent) { QueueTaskRequest(tss,parent,msg,(1<popup_tss=tss; tempc=QueueTaskRequest(tss,parent,msg, 1<popup_tss=NULL; Kill(tss); if (pu_tss) *pu_tss=NULL; Preempt(old_preempt); return result; } } #help_index "Ltf/Output" public TssStruct *PopUpViewLtf(Ltf *l,I1 *help=NULL) { I1 *buf=MSPrintF("Preempt(ON);DoLtf(0x%X,TRUE,0x%X);",l,help); TssStruct *tss=Spawn(&ServantUserCmdLine,"View",Fs); QueueTaskRequest(tss,NULL,buf,1<user_data0); Exit; } public TssStruct *PopUpViewStr(I1 *msg) { TssStruct *tss; Ltf *l=LtfNew; LtfPrintF(l,msg); tss=PopUpViewLtf(l); tss->user_data0=l; tss->end_task_cb=&PopUpViewStrEndTsk; return tss; } #help_index "Ltf/Input" public I8 PopUpMenu(Ltf *l,I1 *help=NULL,U8 flags=0) { l->flags|=LTFF_MIN_SIZE | LTFF_FORM; return ServantUser("DoMenu(0x%X,0x%X,0x%X);",l,help,flags); } void LTDirEntryToFileLtf(Ltf *l,LTDirEntry *tempm) { LtfEntry *ll; while (tempm) { if (tempm->attr & LT_ATTR_DIR) { ll=LtfPrintF(l,"$$TR,\"%s\"$$",tempm->name); ll->user_data=tempm; LtfPutSExt(l,"\r\n$$ID,+2$$"); if (tempm->sub) LTDirEntryToFileLtf(l,tempm->sub); LtfPutSExt(l,"$$ID,-2$$"); } else LtfPrintF(l,"$$MU,\"%s\",0x%08X$$\r\n", tempm->name,tempm); tempm=tempm->next; } } public I1 *PopUpPickFile(I1 *mask="/*",I1 *flags=NULL) { I1 *result=NULL; LTDirEntry *tempm,*tempm1; U8 f=0; Ltf *l=LtfNew; GetFFlags(&f,SysText("ST_FILE_UTIL_FLAGS"),"+r"); GetFFlags(&f,SysText("ST_FILE_UTIL_FLAGS"),flags); tempm=FindFiles(mask,f); LtfPutSExt(l,"$$TR-C+AL,\"\"$$\r\n"); LtfPutSExt(l,"$$ID,+2$$"); LTDirEntryToFileLtf(l,tempm); LtfPutSExt(l,"$$ID,-2$$"); tempm1=PopUpMenu(l); if (tempm1full_name); else result=NewStr(""); LtfDel(l); DelLTDirList(tempm); return result; } #help_index "Ltf/Output" public void LTDirEntryToDirLtf(Ltf *l,LTDirEntry *tempm) { while (tempm) { LtfPrintF(l,"$$TR,\"\"$$"); LtfPrintF(l,"$$MU,\"%s\",0x%08X$$\r\n", tempm->name,tempm); LtfPutSExt(l,"$$ID,+2$$"); if (tempm->sub) LTDirEntryToDirLtf(l,tempm->sub); LtfPutSExt(l,"$$ID,-2$$"); tempm=tempm->next; } } #help_index "Ltf/Input" public I1 *PopUpPickDir(I1 *mask="/*",I1 *flags=NULL) { //+r=recurse +D=just dirs I1 *result=NULL; LTDirEntry *tempm,*tempm1; U8 f=0; Ltf *l=LtfNew; GetFFlags(&f,SysText("ST_FILE_UTIL_FLAGS"),"+r+D"); GetFFlags(&f,SysText("ST_FILE_UTIL_FLAGS"),flags); tempm=FindFiles(mask,f); LtfPutSExt(l,"$$TR-C+AL,\"\"$$\r\n"); LtfPutSExt(l,"$$ID,+2$$"); LTDirEntryToDirLtf(l,tempm); LtfPutSExt(l,"$$ID,-2$$"); tempm1=PopUpMenu(l); if (tempm1full_name); else result=NewStr(""); LtfDel(l); DelLTDirList(tempm); return result; } #help_index "Ltf" public BoolU4 PopUpCd() { I1 *st=PopUpPickDir; BoolU4 result=Cd(st); Free(st); return result; } #help_index "Ltf/Input" public I1 *PopUpPickListEntry(I1 *lst) { I8 i=0; Ltf *l=LtfNew; while (*lst) { if (*lst=='@') { /* Check for '@' alias list entry*/ i--; lst++; } LtfPrintF(l,"$$MU,\"%s\",0x%08X$$\r\n", lst,i++); lst+=StrLen(lst)+1; } LtfPrintF(l,"$$MU,\"CANCEL\",-1$$\r\n"); i=PopUpMenu(l); LtfDel(l); return i; } public I1 *PopUpPickSysTextSub(I1 *st) { return PopUpPickListEntry(SysText(st)); } public BoolU4 PopUpDoForm(U1 *d,I1 *class_name, I1 *help=NULL,BoolU4 help_is_file=FALSE) { //TODO: add header/footer BoolU4 result; result=ServantUser("DoForm(0x%X,\"%s\",0x%X,%d);",d,class_name,help,help_is_file); return result; } public I8 PopUpOk(I1 *header=NULL,I1 *footer=NULL) { I8 i; Ltf *l=LtfNew; if (header) LtfPutSExt(l,header); LtfPutSExt(l,"$$CM +CX,0,4$$$$BT, \"OKAY\" 1$$"); if (footer) LtfPutSExt(l,footer); i=PopUpMenu(l); LtfDel(l); return i; } public I8 PopUpNoYes(I1 *header=NULL,I1 *footer=NULL) { I8 i; Ltf *l=LtfNew; if (header) LtfPutSExt(l,header); LtfPutSExt(l,"$$CM +LX, 2,4$$$$BT, \"YES\",1$$"); LtfPutSExt(l,"$$CM +LX, 18,0$$$$BT, \"NO\",0$$"); if (footer) LtfPutSExt(l,footer); i=PopUpMenu(l); LtfDel(l); return i; } public I8 PopUpCancelOk(I1 *header=NULL,I1 *footer=NULL) { I8 i; Ltf *l=LtfNew; if (header) LtfPutSExt(l,header); LtfPutSExt(l,"$$CM +LX, 2,4$$$$BT, \"OK\",1$$"); LtfPutSExt(l,"$$CM +LX, 18,0$$$$BT, \"CANCEL\",0$$"); if (footer) LtfPutSExt(l,footer); i=PopUpMenu(l); LtfDel(l); return i; } public I8 PopUpReplaceSkipAllCancel(I1 *header=NULL,I1 *footer=NULL) { I8 i; Ltf *l=LtfNew; if (header) LtfPutSExt(l,header); LtfPutSExt(l,"$$CM +LX,2,4$$$$BT, \"REPLACE\",0$$"); LtfPutSExt(l,"$$CM +LX, 18,0$$$$BT, \"SKIP\",1$$"); LtfPutSExt(l,"$$CM +LX, 2,3$$$$BT, \"ALL\",2$$"); LtfPutSExt(l,"$$CM +LX, 18,0$$$$BT, \"CANCEL\",3$$"); if (footer) LtfPutSExt(l,footer); i=PopUpMenu(l); LtfDel(l); return i; } #help_index "Ltf/Input;Input Pointer" public I8 PopUpInputPointer() { I8 i; Ltf *l=LtfNew; LtfPutSExt(l,"$$CM+LX,2,4$$$$BT,\"Mouse\",IP_MOUSE$$"); LtfPutSExt(l,"$$CM+LX,18,0$$$$BT,\"JoyStick\",IP_JOYSTICK0$$"); i=PopUpMenu(l); switch (i) { case IP_MOUSE: ip_pointer_type=i; break; case IP_JOYSTICK0: ip_pointer_type=i; LoadJoystickCalibration; break; } LtfDel(l); return i; } #help_index "Ltf"