AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

48

*: Add support for inline images!

Move styles to be stored in a slab just like the others so it can
grow as needed and allow BitMap data to be stored there.
 
Fix redrawing of lines when they have to grow due to larger text
added on the same line, now that we're not using the canvas.

jcs made amendment 48 over 2 years ago
--- textview.c Sat Nov 9 00:21:14 2024 +++ textview.c Tue Nov 12 21:28:35 2024 @@ -21,11 +21,11 @@ //#define USE_CANVAS 1 -#define ARE_STYLES_EQUAL(one, two) ((one)->font == (two)->font && \ - (one)->style == (two)->style && (one)->size == (two)->size) -#define IS_STYLE_EMPTY(_style) ((_style)->font == 0 && \ - (_style)->style == 0 && (_style)->size == 0) -#define NO_STYLE 0xff +#define ARE_STYLES_EQUAL(one, two) \ + ((one)->font == (two)->font && \ + (one)->style == (two)->style && \ + (one)->size == (two)->size && \ + (one)->bitmap_data_size == (two)->bitmap_data_size) struct TVFindInRectMatch { BigRect rect; @@ -50,7 +50,7 @@ Handle TVAllocateSlab(struct TVRec *tv, unsigned long Handle *last); Handle TVAllocateLineGroup(struct TVRec *tv, short groupn); struct TVSlab * TVGetTextSlab(struct TVRec *tv, unsigned long addr); -struct TVChunk * TVGetChunk(struct TVRec *tv, TVChunkPtr ptr); +struct TVChunk * TVGetChunk(struct TVRec *tv, TVSlabLocator loc); struct TVChunk * TVCreateChunk(struct TVRec *tv); struct TVLine * TVGetLine(struct TVRec *tv, unsigned long line); Boolean TVAppendLocked(struct TVRec *tv, struct TVStyle *style, char *text, @@ -58,6 +58,7 @@ Boolean TVAppendLocked(struct TVRec *tv, struct TVStyl short TVScrollDivisor(struct TVRec *tv); Boolean TVCalcLinesLocked(struct TVRec *tv, Boolean ignore_dirty); 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 TVGetOffsetCallback(struct TVRec *tv, @@ -77,8 +78,6 @@ TVNew(Rect *view, Rect *padding) TVHandle tvh; struct TVRec *tv; struct TVLine *line; - long width, height; - GrafPtr old_port; tvh = (TVHandle)NewHandleClear(sizeof(struct TVRec)); if (tvh == NULL) @@ -94,7 +93,6 @@ TVNew(Rect *view, Rect *padding) SetRect(&tv->frame, 0, 0, tv->view.right - tv->view.left, tv->view.bottom - tv->view.top); - tv->cur_style = NO_STYLE; tv->linewrap = true; tv->autocalc = true; @@ -106,6 +104,10 @@ TVNew(Rect *view, Rect *padding) tv->bounds.bottom = tv->padding.top + tv->padding.bottom; tv->scrolled = tv->bounds; + if (TVAllocateSlab(tv, TV_STYLE_SLAB_SIZE, &tv->first_style_slab, + &tv->last_style_slab) == NULL) + goto fail; + if (TVAllocateSlab(tv, TV_TEXT_SLAB_SIZE, &tv->first_text_slab, &tv->last_text_slab) == NULL) goto fail; @@ -164,129 +166,34 @@ TVAppendLine(TVHandle tvh, struct TVStyle *style, char } Boolean -TVAppendLocked(struct TVRec *tv, struct TVStyle *style, char *text, - unsigned long length, char terminator) +TVAppendBitMap(TVHandle tvh, BitMap *bitmap) { - struct TVSlab *text_slab; - struct TVChunk *chunk, *prev_chunk; - struct TVStyle *cur_style; - struct TVLine *fromline, *toline; - Handle text_slabh; - RgnHandle vacated; - BigRect redraw; - unsigned long avail, wastop; - short width, prev_style_idx; - char *text_slab_data; - Boolean new_chunk; + struct TVRec *tv; + struct TVStyle *style; + long bitmap_size, width, height; + Boolean ret; - if (terminator) - length++; - - if (length == 0) - return false; + width = bitmap->bounds.right - bitmap->bounds.left; + height = bitmap->bounds.bottom - bitmap->bounds.top; + bitmap_size = ((((width - 1) / (bitmap->rowBytes * 8)) + 1) * 2) * + height; - new_chunk = false; - fromline = TVGetLine(tv, tv->nlines); - - /* setup style */ - prev_style_idx = tv->cur_style; - cur_style = TVFindStyle(tv, style); - if (cur_style == NULL) + style = (struct TVStyle *)NewPtrClear(sizeof(struct TVStyle) + + bitmap_size); + if (style == NULL) return false; - if (tv->cur_style != prev_style_idx) - new_chunk = true; - /* setup text slab */ - HUnlock(tv->last_text_slab); - text_slab = (struct TVSlab *)*(tv->last_text_slab); - - /* setup chunk */ - prev_chunk = NULL; - chunk = TVGetChunk(tv, tv->last_chunk); - - while (length) { - if (chunk == NULL || new_chunk) { - new_chunk = false; - prev_chunk = chunk; - chunk = TVCreateChunk(tv); - if (chunk == NULL) - return false; + style->bitmap_data_size = bitmap_size; + style->bitmap = *bitmap; + memcpy(style->bitmap_data, bitmap->baseAddr, bitmap_size); + style->bitmap.baseAddr = (Ptr)style->bitmap_data; - chunk->start = text_slab->base + text_slab->pos; - chunk->end = chunk->start; - chunk->style = tv->cur_style; - if (prev_chunk) { - chunk->prev_chunk = prev_chunk->ptr; - prev_chunk->next_chunk = chunk->ptr; - } - } - - avail = text_slab->size - text_slab->pos; - if (avail == 0) { - /* new text slab, new chunk */ - chunk->end = text_slab->base + text_slab->pos; - - if ((text_slabh = TVAllocateSlab(tv, TV_TEXT_SLAB_SIZE, - &tv->first_text_slab, &tv->last_text_slab)) == NULL) - return false; - text_slab = (struct TVSlab *)*text_slabh; - - new_chunk = true; - continue; - } - - text_slab_data = text_slab->data + text_slab->pos; - - if (length < avail) - avail = length; - memcpy(text_slab_data, text, avail); - text += avail; - text_slab->pos += avail; - length -= avail; - tv->text_length += avail; - chunk->end += avail; - chunk->need_recalc = true; - - if (length == 0 && terminator) - text_slab->data[text_slab->pos - 1] = terminator; - } + tv = TVLock(tvh); + ret = TVAppendLocked(tv, style, " ", 1, 0); + TVUnlock(tv); - if (!tv->autocalc) - return true; - - if (!TVCalcLinesLocked(tv, false)) - return false; - - /* keep scrolling and redrawing in one CopyBits */ - TVUseCanvas(tv); - - if (tv->autoscroll && tv->scrolled.bottom > tv->frame.bottom) { - wastop = tv->scrolled.top; - tv->scrolled.bottom = tv->frame.bottom; - tv->scrolled.top = tv->scrolled.bottom - tv->bounds.bottom; - vacated = NewRgn(); - ScrollRect(&tv->frame, 0, tv->scrolled.top - wastop, vacated); - DisposeRgn(vacated); - tv->canvas_dirty = true; - } - - if (fromline && fromline->nline == tv->nlines) - toline = fromline; - else - toline = TVGetLine(tv, tv->nlines); - - redraw.top = fromline ? fromline->rect.top : tv->padding.top; - redraw.bottom = toline->rect.bottom; - redraw.left = 0; - redraw.right = tv->frame.right; - - if (tv->scrolled.top + redraw.bottom > 0L && - tv->scrolled.top + redraw.top < tv->frame.bottom) - TVFindInRect(tv, &redraw, fromline ? fromline->nline : 0, - TVDrawMatch, NULL); - - TVRevealCanvas(tv); - return true; + DisposPtr(style); + return ret; } Boolean @@ -753,7 +660,24 @@ TVClear(TVHandle tvh) short n; tv = TVLock(tvh); + + /* free style slabs except first one */ + while (tv->last_style_slab != tv->first_style_slab) { + slabh = tv->last_style_slab; + HLock(slabh); + slab = (struct TVSlab *)*slabh; + tv->last_style_slab = slab->prev_slab; + DisposeHandle(slabh); + } + HLock(tv->first_style_slab); + slab = (struct TVSlab *)*(tv->first_style_slab); + memset(slab->data, 0, slab->size); + slab->pos = 0; + HUnlock(tv->first_text_slab); + + tv->cur_style = 0; + /* free chunk slabs except first one */ while (tv->last_chunk_slab != tv->first_chunk_slab) { slabh = tv->last_chunk_slab; @@ -806,9 +730,6 @@ TVClear(TVHandle tvh) tv->bounds.bottom = tv->padding.top + tv->padding.bottom; tv->scrolled = tv->bounds; - memset(&tv->styles, 0, sizeof(tv->styles)); - tv->cur_style = NO_STYLE; - TVUseCanvas(tv); EraseRect(&tv->frame); tv->canvas_dirty = true; @@ -850,6 +771,7 @@ TVDispose(TVHandle tvh) tv = TVLock(tvh); + DisposeHandle(tv->first_style_slab); DisposeHandle(tv->first_chunk_slab); DisposeHandle(tv->first_text_slab); DisposeHandle(tv->line_groups[0]); @@ -892,6 +814,15 @@ TVUnlock(struct TVRec *tv) return; } + slabh = tv->first_style_slab; + while (slabh) { + HLock(slabh); + slab = (struct TVSlab *)*slabh; + tslabh = slabh; + slabh = slab->next_slab; + HUnlock(tslabh); + } + slabh = tv->first_text_slab; while (slabh) { HLock(slabh); @@ -1067,25 +998,25 @@ TVGetTextSlab(struct TVRec *tv, unsigned long addr) } struct TVChunk * -TVGetChunk(struct TVRec *tv, TVChunkPtr ptr) +TVGetChunk(struct TVRec *tv, TVSlabLocator loc) { Handle slabh; struct TVSlab *slab; char *addr; - if (ptr == 0) + if (loc == 0) return NULL; slabh = tv->first_chunk_slab; while (slabh) { HLock(slabh); slab = (struct TVSlab *)*slabh; - if (slab->id == CHUNKPTR_SLABID(ptr)) + if (slab->id == SLABLOC_SLABID(loc)) break; slabh = slab->next_slab; } - addr = slab->data + CHUNKPTR_OFFSET(ptr); + addr = slab->data + SLABLOC_OFFSET(loc); if ((unsigned long)addr % 2 != 0) { Debugger(); return NULL; @@ -1102,7 +1033,7 @@ TVCreateChunk(struct TVRec *tv) Handle slabh; struct TVSlab *slab; struct TVChunk *chunk; - TVChunkPtr cptr; + TVSlabLocator cloc; slabh = tv->last_chunk_slab; HLock(slabh); @@ -1115,17 +1046,17 @@ TVCreateChunk(struct TVRec *tv) slab = (struct TVSlab *)*slabh; } - SET_CHUNKPTR_SLABID(cptr, slab->id); - SET_CHUNKPTR_OFFSET(cptr, slab->pos); + SET_SLABLOC_SLABID(cloc, slab->id); + SET_SLABLOC_OFFSET(cloc, slab->pos); - chunk = TVGetChunk(tv, cptr); - chunk->ptr = cptr; + chunk = TVGetChunk(tv, cloc); + chunk->loc = cloc; slab->pos += sizeof(struct TVChunk); if (!tv->first_chunk) - tv->first_chunk = cptr; + tv->first_chunk = cloc; - tv->last_chunk = cptr; + tv->last_chunk = cloc; return chunk; } @@ -1164,43 +1095,259 @@ TVApplyStyle(struct TVStyle *style) } struct TVStyle * +TVGetStyle(struct TVRec *tv, TVSlabLocator loc) +{ + Handle slabh; + struct TVSlab *slab; + struct TVStyle *style; + short n; + + slabh = tv->first_style_slab; + while (slabh) { + HLock(slabh); + slab = (struct TVSlab *)*slabh; + + if (slab->id != SLABLOC_SLABID(loc)) { + slabh = slab->next_slab; + continue; + } + + style = (struct TVStyle *)(slab->data + SLABLOC_OFFSET(loc)); + if (style->loc != loc) { + /* locator pointed at bogus style */ + Debugger(); + return NULL; + } + return style; + } + + return NULL; +} + +struct TVStyle * TVFindStyle(struct TVRec *tv, struct TVStyle *style) { - struct TVStyle *cur_style; + Handle slabh; + struct TVSlab *slab; + struct TVStyle *tstyle; short n; - if (tv->cur_style != NO_STYLE) { - cur_style = &tv->styles[tv->cur_style]; + if (style->loc) + return TVGetStyle(tv, style->loc); - if (ARE_STYLES_EQUAL(cur_style, style)) - return cur_style; + slabh = tv->first_style_slab; + while (slabh) { + HLock(slabh); + slab = (struct TVSlab *)*slabh; + tstyle = (struct TVStyle *)(slab->data); + +iterate_slab: + if (tstyle->loc == 0) + goto next_slab; + + if (!ARE_STYLES_EQUAL(tstyle, style)) + goto next_style; + + if (tstyle->bitmap_data_size && + memcmp(tstyle->bitmap_data, style->bitmap.baseAddr, + tstyle->bitmap_data_size) != 0) + goto next_style; + + TVApplyStyle(tstyle); + tv->cur_style = tstyle->loc; + return tstyle; + +next_style: + if (SLABLOC_OFFSET(tstyle->loc) + sizeof(struct TVStyle) + + tstyle->bitmap_data_size + sizeof(struct TVStyle) > slab->size) + goto next_slab; + + tstyle = (struct TVStyle *)((char *)tstyle + + sizeof(struct TVStyle) + tstyle->bitmap_data_size); + if (tstyle->loc == 0) { + if (slab->next_slab) + goto next_slab; + goto create_style; + } + goto iterate_slab; + +next_slab: + slabh = slab->next_slab; } - for (n = 0; n < sizeof(tv->styles) / sizeof(tv->styles[0]); n++) { - if (ARE_STYLES_EQUAL(&tv->styles[n], style)) { - tv->cur_style = n; - return &tv->styles[n]; - } + /* no matching style found, create a new one */ +create_style: + slabh = tv->last_style_slab; + HLock(slabh); + slab = (struct TVSlab *)*slabh; + + if (slab->pos + sizeof(struct TVStyle) + tstyle->bitmap_data_size > + slab->size) { + /* need a new slab */ + slabh = TVAllocateSlab(tv, TV_STYLE_SLAB_SIZE, + &tv->first_style_slab, &tv->last_style_slab); + if (slabh == NULL) + return NULL; + slab = (struct TVSlab *)*slabh; } + + tstyle = (struct TVStyle *)(slab->data + slab->pos); + SET_SLABLOC_SLABID(tstyle->loc, slab->id); + SET_SLABLOC_OFFSET(tstyle->loc, slab->pos); - /* allocate a new one */ - for (n = 0; n < sizeof(tv->styles) / sizeof(tv->styles[0]); n++) { - if (!IS_STYLE_EMPTY(&tv->styles[n])) - continue; + /* only copy over the important fields, rest will stay 0 */ + tstyle->font = style->font; + tstyle->style = style->style; + tstyle->size = style->size; + if (style->bitmap_data_size) { + tstyle->bitmap_data_size = style->bitmap_data_size; + tstyle->bitmap = style->bitmap; + memcpy(tstyle->bitmap_data, style->bitmap.baseAddr, + style->bitmap_data_size); + /* this must be recalculated at draw time once slab is locked */ + tstyle->bitmap.baseAddr = 0; + } + + slab->pos += sizeof(struct TVStyle) + tstyle->bitmap_data_size; + if (slab->pos > slab->size) { + Debugger(); + return NULL; + } + + TVApplyStyle(tstyle); + GetFontInfo(&tstyle->font_info); + tv->cur_style = tstyle->loc; + + return tstyle; +} + +Boolean +TVAppendLocked(struct TVRec *tv, struct TVStyle *style, char *text, + unsigned long length, char terminator) +{ + struct TVSlab *text_slab; + struct TVChunk *chunk, *prev_chunk; + struct TVStyle *cur_style; + struct TVLine *fromline, *toline; + Handle text_slabh; + RgnHandle vacated; + BigRect redraw; + unsigned long avail, wastop; + short width; + TVSlabLocator prev_style; + char *text_slab_data; + Boolean new_chunk; + + if (terminator) + length++; + + if (length == 0) + return false; + + new_chunk = false; + fromline = TVGetLine(tv, tv->nlines); + + /* setup style */ + prev_style = tv->cur_style; + cur_style = TVFindStyle(tv, style); + if (cur_style == NULL) + return false; + TVApplyStyle(cur_style); + tv->cur_style = cur_style->loc; + if (tv->cur_style != prev_style) + new_chunk = true; + + /* setup text slab */ + HUnlock(tv->last_text_slab); + text_slab = (struct TVSlab *)*(tv->last_text_slab); + + /* setup chunk */ + prev_chunk = NULL; + chunk = TVGetChunk(tv, tv->last_chunk); + + while (length) { + if (chunk == NULL || new_chunk) { + new_chunk = false; + prev_chunk = chunk; + chunk = TVCreateChunk(tv); + if (chunk == NULL) + return false; + + chunk->start = text_slab->base + text_slab->pos; + chunk->end = chunk->start; + chunk->style = tv->cur_style; + if (prev_chunk) { + chunk->prev_chunk = prev_chunk->loc; + prev_chunk->next_chunk = chunk->loc; + } + } + + avail = text_slab->size - text_slab->pos; + if (avail == 0) { + /* new text slab, new chunk */ + chunk->end = text_slab->base + text_slab->pos; - /* only copy over the important fields, rest will stay 0 */ - tv->styles[n].font = style->font; - tv->styles[n].style = style->style; - tv->styles[n].size = style->size; - cur_style = &tv->styles[n]; - TVApplyStyle(cur_style); - GetFontInfo(&cur_style->font_info); - tv->cur_style = n; - return cur_style; + if ((text_slabh = TVAllocateSlab(tv, TV_TEXT_SLAB_SIZE, + &tv->first_text_slab, &tv->last_text_slab)) == NULL) + return false; + text_slab = (struct TVSlab *)*text_slabh; + + new_chunk = true; + continue; + } + + text_slab_data = text_slab->data + text_slab->pos; + + if (length < avail) + avail = length; + memcpy(text_slab_data, text, avail); + text += avail; + text_slab->pos += avail; + length -= avail; + tv->text_length += avail; + chunk->end += avail; + chunk->need_recalc = true; + + if (length == 0 && terminator) + text_slab->data[text_slab->pos - 1] = terminator; } - /* no slots left */ - return NULL; + if (!tv->autocalc) + return true; + + if (!TVCalcLinesLocked(tv, false)) + return false; + + /* keep scrolling and redrawing in one CopyBits */ + TVUseCanvas(tv); + + if (tv->autoscroll && tv->scrolled.bottom > tv->frame.bottom) { + wastop = tv->scrolled.top; + tv->scrolled.bottom = tv->frame.bottom; + tv->scrolled.top = tv->scrolled.bottom - tv->bounds.bottom; + vacated = NewRgn(); + ScrollRect(&tv->frame, 0, tv->scrolled.top - wastop, vacated); + DisposeRgn(vacated); + tv->canvas_dirty = true; + } + + if (fromline && fromline->nline == tv->nlines) + toline = fromline; + else + toline = TVGetLine(tv, tv->nlines); + + redraw.top = fromline ? fromline->rect.top : tv->padding.top; + redraw.bottom = toline->rect.bottom; + redraw.left = 0; + redraw.right = tv->frame.right; + + if (tv->scrolled.top + redraw.bottom > 0L && + tv->scrolled.top + redraw.top < tv->frame.bottom) + TVFindInRect(tv, &redraw, fromline ? fromline->nline : 0, + TVDrawMatch, NULL); + + TVRevealCanvas(tv); + return true; } short @@ -1254,7 +1401,7 @@ TVCalcLinesLocked(struct TVRec *tv, Boolean ignore_dir new_line = false; reload_chunk: - style = &tv->styles[chunk->style]; + style = TVGetStyle(tv, chunk->style); if (style == NULL) return false; TVApplyStyle(style); @@ -1304,8 +1451,12 @@ reload_chunk: } line->nline = nline; - height = style->font_info.ascent + style->font_info.descent; + if (style->bitmap_data_size) + height = style->bitmap.bounds.bottom - style->bitmap.bounds.top; + else + height = style->font_info.ascent + style->font_info.descent; + for (n = start; n < chunk->end; n++) { c = text_slab_data[n - text_slab->base]; @@ -1313,14 +1464,17 @@ reload_chunk: new_line = true; width = 0; } else { - if (!(width = style->width_cache[c])) + if (style->bitmap_data_size) + width = style->bitmap.bounds.right - + style->bitmap.bounds.left; + else if (!(width = style->width_cache[c])) width = style->width_cache[c] = CharWidth(c); if (c == '\t' && tv->tabstop) width = CharWidth(' ') * ((n - line->start + 1) % tv->tabstop); - if (c == ' ') { + if (c == ' ' && !style->bitmap_data_size) { tv->last_space = n; space_width = 0; } else if (!new_line && tv->linewrap && @@ -1389,10 +1543,17 @@ reload_chunk: chunk->end_right += width; - if (style->font_info.descent > line->baseline) + if (!style->bitmap_data_size && + style->font_info.descent > line->baseline) { + if (line->baseline) + line->grew = true; line->baseline = style->font_info.descent; - if (line->rect.bottom - line->rect.top < height) + height = style->font_info.ascent + style->font_info.descent; + } + if (line->rect.bottom - line->rect.top < height) { + line->grew = true; line->rect.bottom = line->rect.top + height; + } } line->end = chunk->end; @@ -1424,13 +1585,36 @@ TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch unsigned char c; char *text, *spanstart; short ts; + Rect r; if (match->text_end == match->text_start) return true; + if (match->line->grew) { + r.left = match->line->rect.left; + r.top = tv->scrolled.top + match->line->rect.top; + r.right = match->line->rect.right; + r.bottom = tv->scrolled.top + match->line->rect.bottom; + EraseRect(&r); + match->line->grew = false; + } + MoveTo(match->rect.left, tv->scrolled.top + match->line->rect.bottom - match->line->baseline); - if (tv->tabstop) { + if (match->style->bitmap_data_size) { + r = match->style->bitmap.bounds; + r.left = match->rect.left; + r.right = r.left + (match->style->bitmap.bounds.right - + match->style->bitmap.bounds.left); + r.bottom = tv->scrolled.top + match->line->rect.bottom - + match->line->baseline; + r.top = r.bottom - (match->style->bitmap.bounds.bottom - + match->style->bitmap.bounds.top); + + match->style->bitmap.baseAddr = (QDPtr)match->style->bitmap_data; + CopyBits(&match->style->bitmap, &thePort->portBits, + &match->style->bitmap.bounds, &r, srcOr, NULL); + } else if (tv->tabstop) { text = match->text_slab_data + (match->text_start - match->text_slab->base); spanstart = NULL; @@ -1522,10 +1706,11 @@ prep_chunk: goto draw_done; match.text_slab_data = match.text_slab->data; - match.style = &tv->styles[match.chunk->style]; + match.style = TVGetStyle(tv, match.chunk->style); if (match.style == NULL) goto draw_done; - TVApplyStyle(match.style); + if (!match.style->bitmap_data_size) + TVApplyStyle(match.style); } match.rect.top = match.line->rect.top; --- textview.h Sat Nov 9 00:05:56 2024 +++ textview.h Tue Nov 12 20:55:28 2024 @@ -21,10 +21,10 @@ #include <limits.h> struct BigRect { + long left; long top; long right; long bottom; - long left; }; typedef struct BigRect BigRect; #define BigRectToRect(br, r) SetRect(&(r), (br).left, (br).top, (br).right, (br).bottom) @@ -34,38 +34,43 @@ typedef struct BigRect BigRect; (br).right = (r).right; \ (br).bottom = (r).bottom; ) +/* when storing data in slabs, TVSlabLocator stores slab id and offset */ +typedef unsigned long TVSlabLocator; + +/* high 4 are slab id, low 4 byte offset */ +#define SLABLOC_SLABID(x) (((x) >> 16) & 0xffff) +#define SLABLOC_OFFSET(x) ((x) & 0x0000ffff) + +#define SET_SLABLOC_SLABID(loc, x) \ + { (loc) = ((unsigned long)(x) << 16) | ((loc) & 0xffff); } +#define SET_SLABLOC_OFFSET(loc, x) \ + { (loc) = ((loc) & 0xffff0000) | ((x) & 0x0000ffff); } + struct TVStyle { unsigned char font; unsigned char style; unsigned char size; + BitMap bitmap; /* these are private and ignored when fed into TVAppend() */ struct FontInfo font_info; unsigned char width_cache[256]; + TVSlabLocator loc; + unsigned long bitmap_data_size; + unsigned char bitmap_data[]; }; -typedef unsigned long TVChunkPtr; - -/* high 4 are slab id, low 4 byte offset */ -#define CHUNKPTR_SLABID(x) (((x) >> 16) & 0xffff) -#define CHUNKPTR_OFFSET(x) ((x) & 0x0000ffff) - -#define SET_CHUNKPTR_SLABID(ptr, x) \ - { (ptr) = ((unsigned long)(x) << 16) | ((ptr) & 0xffff); } -#define SET_CHUNKPTR_OFFSET(ptr, x) \ - { (ptr) = ((ptr) & 0xffff0000) | ((x) & 0x0000ffff); } - struct TVChunk { - TVChunkPtr ptr; - TVChunkPtr prev_chunk; - TVChunkPtr next_chunk; + TVSlabLocator loc; + TVSlabLocator prev_chunk; + TVSlabLocator next_chunk; unsigned long start; unsigned long start_line; unsigned long end; unsigned long end_line; unsigned short start_left; unsigned short end_right; - unsigned char style; + TVSlabLocator style; Boolean need_recalc; }; @@ -75,6 +80,7 @@ struct TVLine { BigRect rect; unsigned long nline; unsigned char baseline; + Boolean grew; }; struct TVSlab { @@ -113,8 +119,10 @@ struct TVRec { /* bounds as it is scrolled */ BigRect scrolled; - struct TVStyle styles[32]; - unsigned char cur_style; + Handle first_style_slab; + Handle last_style_slab; +#define TV_STYLE_SLAB_SIZE (sizeof(struct TVStyle) * 16) + TVSlabLocator cur_style; Handle first_text_slab; Handle last_text_slab; @@ -125,8 +133,8 @@ struct TVRec { Handle first_chunk_slab; Handle last_chunk_slab; #define TV_CHUNK_SLAB_SIZE (sizeof(struct TVChunk) * 50) - TVChunkPtr first_chunk; - TVChunkPtr last_chunk; + TVSlabLocator first_chunk; + TVSlabLocator last_chunk; Handle line_groups[32]; #define TV_LINE_GROUP_NLINES 500 @@ -153,6 +161,7 @@ Boolean TVAppend(TVHandle tvh, struct TVStyle *style, unsigned long length); Boolean TVAppendLine(TVHandle tvh, struct TVStyle *style, char *text, unsigned long length); +Boolean TVAppendBitMap(TVHandle tvh, BitMap *bitmap); void TVAutoCalc(TVHandle tvh, Boolean calc); void TVAutoScroll(TVHandle tvh, Boolean scroll); void TVLineWrap(TVHandle tvh, Boolean wrap);