AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

29

Fix wrapping on a new chunk at the end of a line, expose TVCalcLines


jcs made amendment 29 over 2 years ago
--- textview.c Mon Oct 21 13:10:31 2024 +++ textview.c Mon Oct 21 15:27:03 2024 @@ -52,7 +52,7 @@ struct TVSlab * TVGetTextSlab(struct TVRec *tv, unsign struct TVChunk * TVGetChunk(struct TVRec *tv, TVChunkPtr ptr); struct TVChunk * TVCreateChunk(struct TVRec *tv); struct TVLine * TVGetLine(struct TVRec *tv, unsigned long line); -Boolean TVCalcLines(struct TVRec *tv); +Boolean TVCalcLinesLocked(struct TVRec *tv); void TVApplyStyle(struct TVStyle *style); struct TVStyle * TVFindStyle(struct TVRec *tv, struct TVStyle *style); void TVScrollUnlocked(struct TVRec *tv, short horiz, short vert); @@ -186,6 +186,9 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te prev_chunk = NULL; chunk = TVGetChunk(tv, tv->last_chunk); + if (length == 0) + length = strlen(text); + while (length) { if (chunk == NULL || new_chunk) { new_chunk = false; @@ -228,7 +231,7 @@ TVAppend(TVHandle tvh, struct TVStyle *style, char *te chunk->dirty = true; } - if (TVCalcLines(tv)) { + if (TVCalcLinesLocked(tv)) { visible.top = -(tv->scrolled.top); visible.left = -(tv->scrolled.left); visible.bottom = visible.top + tv->view_height; @@ -242,6 +245,19 @@ append_done: return ret; } +Boolean +TVCalcLines(TVHandle tvh) +{ + struct TVRec *tv; + Boolean ret; + + tv = TVLock(tvh); + ret = TVCalcLinesLocked(tv); + TVUnlock(tv); + + return ret; +} + void TVAutoScroll(TVHandle tvh, Boolean scroll) { @@ -557,9 +573,19 @@ void TVUpdate(TVHandle tvh) { struct TVRec *tv; + BigRect visible; + Boolean ignore = true; tv = TVLock(tvh); TVUseCanvas(tv); + + EraseRect(&tv->canvas->portRect); + visible.top = -(tv->scrolled.top); + visible.left = -(tv->scrolled.left); + visible.bottom = visible.top + tv->view_height; + visible.right = visible.left + (tv->view.right - tv->view.left); + TVFindInRect(tv, &visible, TVDrawMatch, &ignore); + TVRevealCanvas(tv); TVUnlock(tv); } @@ -853,7 +879,7 @@ TVFindStyle(struct TVRec *tv, struct TVStyle *style) } Boolean -TVCalcLines(struct TVRec *tv) +TVCalcLinesLocked(struct TVRec *tv) { struct TVSlab *text_slab; struct TVChunk *chunk, *tchunk, *last_chunk, *prev_chunk, *next_chunk; @@ -948,11 +974,15 @@ TVCalcLines(struct TVRec *tv) } else if (chunk->end_right + width >= max_right) { new_line = true; if (last_space) { - /* TODO: what if this crosses chunks? */ + /* break after the last space */ n = last_space + 1; chunk->end_right -= space_width; c = text_slab_data[n]; - } + } else if (chunk->start > line->start) { + n = chunk->start; + chunk->end_right = chunk->start_left; + c = text_slab_data[n]; + } /* otherwise, hard-break this long word */ } } --- textview.h Fri Oct 18 22:16:18 2024 +++ textview.h Mon Oct 21 13:29:29 2024 @@ -136,6 +136,7 @@ void TVClick(TVHandle tvh, Point p, Boolean extend); unsigned long TVGetOffset(TVHandle tvh, Point p); void TVScroll(TVHandle tvh, short horiz, short vert); void TVClear(TVHandle tvh); +Boolean TVCalcLines(TVHandle tvh); void TVSetTrackScrollControl(TVHandle tvh); pascal void TVTrackScrollControl(ControlHandle control, short part);