AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

55

TVFindInRect: Make this public, allow tags with styles

Adding a tag to a style allows a chunk of text to be found later by
the caller by giving it a unique tag in its style.

jcs made amendment 55 over 2 years ago
--- textview.c Fri Nov 15 14:28:25 2024 +++ textview.c Thu Nov 21 10:47:30 2024 @@ -25,24 +25,9 @@ ((one)->font == (two)->font && \ (one)->style == (two)->style && \ (one)->size == (two)->size && \ + (one)->tag == (two)->tag && \ (one)->bitmap_data_size == (two)->bitmap_data_size) -struct TVFindInRectMatch { - BigRect rect; - struct TVChunk *chunk; - struct TVLine *line; - struct TVStyle *style; - struct TVSlab *text_slab; - char *text_slab_data; - unsigned long text_start; - unsigned long text_end; - /* the original rect we were asked to find */ - BigRect findrect; -}; - -typedef Boolean (*TVFindInRectCallback)(struct TVRec *tv, - struct TVFindInRectMatch *match, void *cookie); - struct TVRec * TVLock(TVHandle tvh); void TVUnlock(struct TVRec *); Boolean TVSetupCanvas(struct TVRec *tv); @@ -61,10 +46,10 @@ void TVApplyStyle(struct TVStyle *style); struct TVStyle * TVGetStyle(struct TVRec *tv, TVSlabLocator loc); struct TVStyle * TVFindStyle(struct TVRec *tv, struct TVStyle *style); void TVScrollUnlocked(struct TVRec *tv, long horiz, long vert); +Boolean TVFindInRectLocked(struct TVRec *tv, BigRect *findrect, + long startline, TVFindInRectCallback callback, void *cookie); Boolean TVGetOffsetCallback(struct TVRec *tv, struct TVFindInRectMatch *match, void *cookie); -Boolean TVFindInRect(struct TVRec *tv, BigRect *findrect, long startline, - TVFindInRectCallback callback, void *cookie); Boolean TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch *match, void *cookie); Boolean TVSetTopBottomMatch(struct TVRec *tv, @@ -199,6 +184,7 @@ TVAppendBitMap(TVHandle tvh, BitMap *bitmap, struct TV style->style = bstyle->style; style->size = bstyle->size; style->font_info = bstyle->font_info; + style->tag = bstyle->tag; } tv = TVLock(tvh); @@ -223,6 +209,20 @@ TVCalcLines(TVHandle tvh) } Boolean +TVFindInRect(TVHandle tvh, BigRect *findrect, long startline, + TVFindInRectCallback callback, void *cookie) +{ + struct TVRec *tv; + Boolean ret; + + tv = TVLock(tvh); + ret = TVFindInRectLocked(tv, findrect, startline, callback, cookie); + TVUnlock(tv); + + return ret; +} + +Boolean TVResize(TVHandle tvh) { struct TVRec *tv; @@ -323,7 +323,7 @@ TVResize(TVHandle tvh) visible.left = -(tv->scrolled.left); visible.bottom = visible.top + tv->frame.bottom; visible.right = visible.left + tv->frame.right; - TVFindInRect(tv, &visible, 0, TVDrawMatch, NULL); + TVFindInRectLocked(tv, &visible, 0, TVDrawMatch, NULL); TVRevealCanvas(tv); TVUnlock(tv); @@ -530,7 +530,7 @@ TVGetOffset(TVHandle tvh, Point p) prect.bottom = prect.top; off = 0; - if (!TVFindInRect(tv, &prect, 0, TVGetOffsetCallback, &off)) + if (!TVFindInRectLocked(tv, &prect, 0, TVGetOffsetCallback, &off)) off = -1; TVRevealCanvas(tv); @@ -577,7 +577,7 @@ TVTrackScrollControl(ControlHandle control, short part visible.left = -(tv->scrolled.left); visible.bottom = visible.top + tv->frame.bottom; visible.right = visible.left + tv->frame.right; - TVFindInRect(tv, &visible, 0, TVSetTopBottomMatch, NULL); + TVFindInRectLocked(tv, &visible, 0, TVSetTopBottomMatch, NULL); if (tv->top_line == NULL) { tv->top_line = TVGetLine(tv, nline); @@ -778,7 +778,7 @@ TVUpdate(TVHandle tvh) visible.left = -(tv->scrolled.left); visible.bottom = visible.top + tv->frame.bottom; visible.right = visible.left + tv->frame.right; - TVFindInRect(tv, &visible, 0, TVDrawMatch, NULL); + TVFindInRectLocked(tv, &visible, 0, TVDrawMatch, NULL); TVRevealCanvas(tv); TVUnlock(tv); @@ -1222,6 +1222,7 @@ create_style: tstyle->font = style->font; tstyle->style = style->style; tstyle->size = style->size; + tstyle->tag = style->tag; if (style->bitmap_data_size) { tstyle->font_info = style->font_info; tstyle->bitmap_data_size = style->bitmap_data_size; @@ -1368,7 +1369,7 @@ TVAppendLocked(struct TVRec *tv, struct TVStyle *style if (tv->scrolled.top + redraw.bottom > 0L && tv->scrolled.top + redraw.top < tv->frame.bottom) - TVFindInRect(tv, &redraw, fromline ? fromline->nline : 0, + TVFindInRectLocked(tv, &redraw, fromline ? fromline->nline : 0, TVDrawMatch, NULL); TVRevealCanvas(tv); @@ -1631,9 +1632,9 @@ TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch return false; if (match->line->grew) { - r.left = match->line->rect.left; + r.left = tv->scrolled.left + match->line->rect.left; r.top = tv->scrolled.top + match->line->rect.top; - r.right = match->line->rect.right; + r.right = tv->scrolled.left + match->line->rect.right; r.bottom = tv->scrolled.top + match->line->rect.bottom; EraseRect(&r); match->line->grew = false; @@ -1697,7 +1698,7 @@ TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch } Boolean -TVFindInRect(struct TVRec *tv, BigRect *rect, long startline, +TVFindInRectLocked(struct TVRec *tv, BigRect *rect, long startline, TVFindInRectCallback callback, void *cookie) { struct TVFindInRectMatch match; @@ -1868,7 +1869,7 @@ TVScrollUnlocked(struct TVRec *tv, long horiz, long ve visible.left = -(tv->scrolled.left); visible.bottom = visible.top + tv->frame.bottom; visible.right = visible.left + tv->frame.right; - TVFindInRect(tv, &visible, 0, TVDrawMatch, NULL); + TVFindInRectLocked(tv, &visible, 0, TVDrawMatch, NULL); TVRevealCanvas(tv); return; } @@ -1884,7 +1885,7 @@ TVScrollUnlocked(struct TVRec *tv, long horiz, long ve HUnlock(vacated); DisposeRgn(vacated); - TVFindInRect(tv, &visible, 0, TVDrawMatch, NULL); + TVFindInRectLocked(tv, &visible, 0, TVDrawMatch, NULL); TVRevealCanvas(tv); } --- textview.h Thu Nov 14 13:51:04 2024 +++ textview.h Wed Nov 20 17:07:28 2024 @@ -50,6 +50,7 @@ struct TVStyle { unsigned char font; unsigned char style; unsigned char size; + unsigned long tag; /* these are private and ignored when fed into TVAppend() */ BitMap bitmap; @@ -159,6 +160,22 @@ struct TVRec { }; typedef struct TVRec ** TVHandle; +struct TVFindInRectMatch { + BigRect rect; + struct TVChunk *chunk; + struct TVLine *line; + struct TVStyle *style; + struct TVSlab *text_slab; + char *text_slab_data; + unsigned long text_start; + unsigned long text_end; + /* the original rect we were asked to find */ + BigRect findrect; +}; + +typedef Boolean (*TVFindInRectCallback)(struct TVRec *tv, + struct TVFindInRectMatch *match, void *cookie); + TVHandle TVNew(Rect *view, Rect *padding); void TVDispose(TVHandle tvh); Boolean TVAppend(TVHandle tvh, struct TVStyle *style, char *text, @@ -169,6 +186,8 @@ Boolean TVAppendBitMap(TVHandle tvh, BitMap *bitmap, struct TVStyle *bstyle); void TVAutoCalc(TVHandle tvh, Boolean calc); void TVAutoScroll(TVHandle tvh, Boolean scroll); +Boolean TVFindInRect(TVHandle tvh, BigRect *findrect, long startline, + TVFindInRectCallback callback, void *cookie); void TVLineWrap(TVHandle tvh, Boolean wrap); void TVTabStop(TVHandle tvh, unsigned short tabstop); Boolean TVResize(TVHandle tvh);