Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
DocRecalcLib.txt215 linesDownload Raw Back to DolDoc
1 2#help_index "DolDoc"3 4I64 DocCharDist(CDoc *doc,I64 x,I64 y)5{6#assert FONT_WIDTH==FONT_HEIGHT7  return (SqrI64(doc->x-x)+SqrI64(doc->y-y))*FONT_WIDTH*FONT_WIDTH;8}9 10U0 DocDelToNum(CDoc *doc,I64 num)11{12  CDocEntry *doc_e=doc->head.next,*doc_e2;13  while (num-->0 && doc_e!=doc) {14    doc_e2=doc_e->next;15    if (!(doc_e->de_flags & (DOCEF_HOLD|DOCEF_FILTER_SKIP))) {16      if (doc_e==doc->cur_entry) {17        doc->cur_entry=doc_e2;18        doc->cur_col=doc_e2->min_col;19      }20      DocEntryDel(doc,doc_e);21    }22    doc_e=doc_e2;23  }24}25 26U0 DocDelToEntry(CDoc *doc,CDocEntry *clear_entry,Bool clear_holds)27{28  CDocEntry *doc_e=doc->head.next,*doc_e2;29  while (doc_e!=doc) {30    doc_e2=doc_e->next;31    if (!(doc_e->de_flags & (DOCEF_HOLD|DOCEF_FILTER_SKIP))||clear_holds) {32      if (doc_e==doc->cur_entry) {33        doc->cur_entry=doc_e2;34        doc->cur_col=doc_e2->min_col;35      }36      DocEntryDel(doc,doc_e);37    }38    if (doc_e==clear_entry)39      break;40    doc_e=doc_e2;41  }42}43 44U0 DocBorderLstDraw(CDoc *doc)45{46  CTask *win_task=doc->win_task;47  I64 i,y=-1,attr=win_task->border_attr<<8;48  U64 ch;49  CDoc *tmpl=doc;50  CD3I64 saved_scroll;51  while (tmpl && tmpl->doc_signature==DOC_SIGNATURE_VAL) {52    y+=(Bsr(tmpl->desc)+7)>>3+1; //StrLen+153    tmpl=tmpl->parent_doc;54  }55  tmpl=doc;56  if (y>win_task->win_height)57    y=win_task->win_height;58  WinScrollNull(win_task,&saved_scroll);59  while (tmpl && tmpl->doc_signature==DOC_SIGNATURE_VAL) {60    ch=tmpl->desc;61    i=(Bsr(ch)+7)>>3;   //StrLen62    ch=EndianI64(ch<<((8-i)<<3));63    attr=win_task->border_attr<<8;64    while (i-- && y>0) {65      TextChar(win_task,TRUE,-1,--y,attr+ch&0xFF);66      ch>>=8;67    }68    y--;69    tmpl=tmpl->parent_doc;70  }71  WinScrollRestore(win_task,&saved_scroll);72}73 74public U0 DocTop(CDoc *doc=NULL)75{//Move cursor, cur_entry, to top.76  Bool unlock;77  if (!doc && !(doc=DocPut))78    return;79  unlock=DocLock(doc);80  doc->cur_entry=doc->head.next;81  doc->cur_col=doc->cur_entry->min_col;82  doc->x=0;83  doc->y=0;84  doc->line_start_col=0;85  doc->top_line_num=0;86 87  DocFormFwd(doc);88  DocRecalc(doc);89  if (unlock)90    DocUnlock(doc);91}92 93public U0 DocCenter(CDoc *doc=NULL,I64 recalc_flags=RECALCt_NORMAL)94{//Center win on doc cursor, cur_entry.95  Bool unlock;96  CTask *task;97  if (!doc && !(doc=DocPut))98    return;99  unlock=DocLock(doc);100  task=doc->win_task;101  DocRecalc(doc,recalc_flags);102  if (!(doc->flags&DOCF_BORDER_DOC))103    doc->top_line_num=doc->y-(task->win_height+1)>>1;104  if (unlock)105    DocUnlock(doc);106}107 108public U0 DocBottom(CDoc *doc=NULL)109{//Move cursor, cur_entry, to bottom.110  Bool unlock;111  if (!doc && !(doc=DocPut))112    return;113  unlock=DocLock(doc);114  doc->cur_entry=doc;115  doc->cur_col=0;116  DocRecalc(doc);117  if (unlock)118    DocUnlock(doc);119}120 121public U0 DocClear(CDoc *doc=NULL,Bool clear_holds=FALSE)122{//Clear all doc entries, except +H, hold entries.123  Bool unlock;124  if (!doc && !(doc=DocPut))125    return;126  unlock=DocLock(doc);127  DocBottom(doc);128  if (clear_holds)129    DocPrint(doc,"$CL+H$");130  else131    DocPrint(doc,"$CL$");132  DocRecalc(doc);133  if (unlock)134    DocUnlock(doc);135}136 137public Bool DocCursor(Bool show=OFF,CDoc *doc=NULL)138{//Show or hide cursor.139  if (!doc && !(doc=DocPut))140    return FALSE;141  return !LBEqu(&doc->flags,DOCf_HIDE_CURSOR,!show);142}143 144public Bool DocHighlightCursor(Bool show=OFF,CDoc *doc=NULL)145{//Highlight or Don't highlight cursor.146  if (!doc && !(doc=DocPut))147    return FALSE;148  return !LBEqu(&doc->flags,DOCf_DONT_HIGHLIGHT_CURSOR,!show);149}150 151public Bool DocScroll(Bool val=OFF,CDoc *doc=NULL)152{//Turn scroll bars OFF/ON.153  if (!doc && !(doc=DocPut))154    return FALSE;155  return !LBEqu(&doc->flags,DOCf_NO_SCROLL_BARS,!val);156}157 158public U0 DocCollapse(Bool collapse=TRUE,CDoc *doc=NULL)159{//Collapse or uncollapse all tree widgets.160  CDocEntry *doc_e;161  Bool unlock;162  if (!doc && !(doc=DocPut))163    return;164  unlock=DocLock(doc);165  doc_e=doc->head.next;166  while (doc_e!=doc) {167    if (doc_e->de_flags&DOCEF_TREE)168      BEqu(&doc_e->de_flags,DOCEf_CHECKED_COLLAPSED,collapse);169    doc_e=doc_e->next;170  }171  DocRecalc(doc);172  if (unlock)173    DocUnlock(doc);174}175 176#help_index "DolDoc/Cmd Line (Typically);Cmd Line (Typically)"177public I64 DocMax(I64 i=I64_MAX)178{//Set max document entries. (Cmd line buffer size.)179//Adjusts the size of the cmd line buf.180  //Normally, the cmd line deletes entries181  //when more are added and the old scroll up.182  //See max_entries.183  I64 res;184  CDoc *doc;185  if (doc=DocPut) {186    res=doc->max_entries;187    doc->max_entries=i;188    return res;189  } else190    return 0;191}192 193#help_index "DolDoc/Task;StdOut/Task"194U0 DocUpdateTaskDocs(CTask *task)195{//This is called from GrUpdateTaskWin() by the winmgr at 30fps.196  CDoc *doc;197  CD3I64 saved_scroll;198  if (task->border_src==BDS_CUR_DRV && task->cur_dv)199    task->border_attr=DrvTextAttrGet(Drv2Let(task->cur_dv));200  if (task->title_src==TTS_TASK_NAME)201    StrCpy(task->task_title,task->task_name);202  if ((doc=DocDisplay(task)) && !(doc->flags&DOCF_DONT_SHOW)) {203    if (task->border_src==BDS_ED_FILENAME_DRV)204      task->border_attr=DrvTextAttrGet(*doc->filename.name);205    if (task->title_src==TTS_ED_FILENAME)206      MemCpy(task->task_title,doc->filename.name,STR_LEN-1);207    DocRecalc(doc,RECALCt_TO_SCRN|RECALCF_HAS_CURSOR);208  }209  if ((doc=DocBorder(task)) && !(doc->flags&DOCF_DONT_SHOW)) {210    WinScrollNull(task,&saved_scroll);211    DocRecalc(doc,RECALCt_TO_SCRN);212    WinScrollRestore(task,&saved_scroll);213  }214}215