Annotation of libwww/LineMode/src/GridText.c, revision 1.5
1.1 timbl 1: /* Character grid hypertext object
2: ** ===============================
3: */
4:
5: /* Implements:
6: */
7: #include "HText.h"
8:
9: #include <assert.h>
10: #include <ctype.h>
11: #include "HTUtils.h"
12: #include "HTString.h"
13: #include "GridText.h"
14: #include "HTFont.h"
15: #include "HTBrowse.h"
16: #include "HTStream.h"
17:
18:
19: struct _HTStream { /* only know it as object */
20: CONST HTStreamClass * isa;
21: /* ... */
22: };
23:
24: #define MAX_LINE HTScreenWidth /* No point in accumulating more */
25: #ifdef THINK_C
26: #define LOADED_LIMIT 3 /* For now, save last two texts */
27: #else
28: #define LOADED_LIMIT 6 /* For now, save last five texts */
29: #endif
30:
31: /* From main program:
32: */
1.2 timbl 33: extern char * start_reference; /* Template for anchors */
34: extern char * end_reference; /* Template for anchors */
1.1 timbl 35: extern char * end_mark; /* Template for end */
36: extern int HTScreenWidth, /* The screen width */
37: HTScreenHeight; /* The screen height */
38: extern BOOL display_anchors; /* anchor will be shown in text? */
39:
40: #ifdef CURSES
41: #define DISPLAY_LINES (HTScreenHeight)
42: #define TITLE_LINES 0
43: #else
44: #define DISPLAY_LINES (HTScreenHeight - 1) /* Exclude prompt line */
45: #define TITLE_LINES 1
46: #endif
47:
48:
49: /* From default style sheet:
50: */
51: extern HTStyleSheet * styleSheet; /* Default or overridden */
52:
53:
54: /* Exports
55: */
56: PUBLIC HText * HTMainText = 0; /* Equivalent of main window */
57: PUBLIC HTParentAnchor * HTMainAnchor = 0; /* Anchor for HTMainText */
58:
59: typedef struct _line {
60: struct _line *next;
61: struct _line *prev;
62: short unsigned offset; /* Implicit initial spaces */
63: short unsigned size; /* Number of characters */
64: BOOL split_after; /* Can we split after? */
65: BOOL bullet; /* Do we bullet? */
66: char data[1]; /* Space for terminator at least! */
67: } HTLine;
68:
69: #define LINE_SIZE(l) (sizeof(HTLine)+(l)) /* allow for terminator */
70:
71: typedef struct _TextAnchor {
72: struct _TextAnchor * next;
73: int number; /* For user interface */
74: int start; /* Characters */
75: int extent; /* Characters */
76: HTChildAnchor * anchor;
77: } TextAnchor;
78:
79:
80: /* Notes on struct _Htext:
81: ** next_line is valid iff state is false.
82: ** top_of_screen line means the line at the top of the screen
83: ** or just under the title if there is one.
84: */
85: struct _HText {
86: HTParentAnchor * node_anchor;
87: char * title;
88: HTLine * last_line;
89: int lines; /* Number of them */
90: int chars; /* Number of them */
91: TextAnchor * first_anchor; /* Singly linked list */
92: TextAnchor * last_anchor;
93: int last_anchor_number; /* user number */
94: /* For Internal use: */
95: HTStyle * style; /* Current style */
96: int display_on_the_fly; /* Lines left */
1.3 timbl 97: BOOL all_pages; /* Loop on the fly */
1.1 timbl 98: int top_of_screen; /* Line number */
99: HTLine * top_of_screen_line; /* Top */
100: HTLine * next_line; /* Bottom + 1 */
101: int permissible_split; /* in last line */
102: BOOL in_line_1; /* of paragraph */
103: BOOL stale; /* Must refresh */
104:
105: HTStream* target; /* Output stream */
106: HTStreamClass targetClass; /* Output routines */
107: };
108:
109:
110: #define PUTC(c) (*text->targetClass.put_character)(text->target, c)
111: #define PUTS(s) (*text->targetClass.put_string)(text->target, s)
112:
113: /* Boring static variable used for moving cursor across
114: */
115:
116: #define SPACES(n) (&space_string[HTScreenWidth - (n)])
117: /* String containing blank spaces only */
118: PRIVATE char * space_string;
119:
120: PRIVATE HTStyle default_style =
121: { 0, "(Unstyled)", "",
122: (HTFont)0, 1.0, HT_BLACK, 0, 0,
123: 0, 0, 0, HT_LEFT, 1, 0, 0,
124: NO, NO, 0, 0, 0 };
125:
126:
127: PUBLIC void clear_screen NOPARAMS; /* Forward */
128:
129: PRIVATE HTList * loaded_texts; /* A list of all those in memory */
130:
131: /* Creation Method
132: ** ---------------
1.3 timbl 133: **
134: ** Interactive version
135: **
1.1 timbl 136: */
137: PUBLIC HText * HText_new ARGS1(HTParentAnchor *,anchor)
138: {
139: HTLine * line;
140: HText * self = (HText *) malloc(sizeof(*self));
141: if (!self) return self;
142:
143: if (!loaded_texts) loaded_texts = HTList_new();
144: HTList_addObject(loaded_texts, self);
145: if (HTList_count(loaded_texts) >= LOADED_LIMIT) {
146: if (TRACE) fprintf(stderr, "GridText: Freeing off cached doc.\n");
147: HText_free((HText *)HTList_removeFirstObject(loaded_texts));
148: }
149:
150: line = self->last_line = (HTLine *)malloc(LINE_SIZE(MAX_LINE));
151: if (line == NULL) outofmem(__FILE__, "HText_New");
152: line->next = line->prev = line;
153: line->offset = line->size = 0;
154: self->lines = self->chars = 0;
155: self->title = 0;
156: self->first_anchor = self->last_anchor = 0;
157: self->style = &default_style;
158: self->top_of_screen = 0;
159: self->node_anchor = anchor;
160: self->last_anchor_number = 0; /* Numbering of them for references */
161: self->stale = YES;
162:
163: self->target = NULL;
164:
165: HTAnchor_setDocument(anchor, (HyperDoc *)self);
166:
167: clear_screen();
168: HTMainText = self;
169: HTMainAnchor = anchor;
170: self->display_on_the_fly = DISPLAY_LINES;
1.3 timbl 171: self->all_pages = NO; /* One page at a time on the fly */
1.1 timbl 172:
173: if (!space_string) { /* Make a blank line */
174: char *p;
175: space_string = (char *)malloc(HTScreenWidth+1);
176: if (space_string == NULL) outofmem(__FILE__, "HText_New");
177: for (p=space_string; p<space_string+HTScreenWidth; p++)
178: *p = ' '; /* Used for printfs later */
179: space_string[HTScreenWidth] = '\0';
180: }
181:
182: return self;
183: }
184:
185:
186: /* Creation Method 2
187: ** ---------------
188: **
1.4 timbl 189: ** Non-interative OR interactive if stream is NULL
1.1 timbl 190: ** Stream is assumed open and left open.
191: */
192: PUBLIC HText * HText_new2 ARGS2(
193: HTParentAnchor *, anchor,
194: HTStream*, stream)
195:
196: {
1.3 timbl 197: HText * me = HText_new(anchor);
1.1 timbl 198:
199: if (stream) {
1.3 timbl 200: me->target = stream;
201: me->targetClass = *stream->isa; /* copy action procedures */
1.4 timbl 202: me->all_pages = YES; /* Display whole file on the fly */
1.3 timbl 203: }
204: return me;
1.1 timbl 205: }
206:
207:
208: /* Free Entire Text
209: ** ----------------
210: */
211: PUBLIC void HText_free ARGS1(HText *,self)
212: {
213: HTAnchor_setDocument(self->node_anchor, (HyperDoc *)0);
214:
215: while(YES) { /* Free off line array */
216: HTLine * l = self->last_line;
217: l->next->prev = l->prev;
218: l->prev->next = l->next; /* Unlink l */
219: self->last_line = l->prev;
220: free(l);
221: if (l == self->last_line) break; /* empty */
222: };
223:
224: while(self->first_anchor) { /* Free off anchor array */
225: TextAnchor * l = self->first_anchor;
226: self->first_anchor = l->next;
227: free(l);
228: }
229: free(self);
230: }
231:
232:
233: /* Display Methods
234: ** ---------------
235: */
236: /* Clear the screen (on screen-mode systems)
237: ** ----------------
238: */
239: PUBLIC void clear_screen NOARGS
240: {
241: if (TRACE) return; /* in trace mode, don't clear trace away */
242: #ifdef CURSES
243: if (w_text != NULL) {
244: wmove(w_text,0,0);
245: wclear(w_text);
246: }
247: #else
248: #ifdef VM
249: #ifdef NEWLIB
250: int newlib_ncmd = 2;
251: char newlib_cmd[2][80];
252:
253: memset(newlib_cmd, ' ', sizeof(newlib_cmd));
254: strncpy(newlib_cmd[0], "clear", 5); /* Clear screen */
255: strncpy(newlib_cmd[1], "quit", 4); /* Leave newlib */
256: newlib(newlib_cmd, &newlib_ncmd); /* Execute command */
257:
258: #else /* not NEWLIB - real VM */
259: system("CLRSCRN"); /* Clear screen */
260: #endif /* not NEWLIB */
261: #else /* Not VM */
262: /* Do nothing */
263: #endif /* Not VM */
264: #endif /* Not CURSES */
265: if (HTMainText) HTMainText->stale = YES;
266: }
267:
268:
269: /* Output a line
270: ** -------------
271: */
272: PRIVATE void display_line ARGS2(HText *,text, HTLine *,line)
273: {
274: #ifdef CURSES
275: int y, x;
276:
277: waddstr(w_text, SPACES(line->offset));
278: waddstr(w_text, line->data);
279: getyx(w_text, y, x);
280: if (y < DISPLAY_LINES-1) {
281: wmove(w_text, ++y, 0);
282: }
283: #else
284: if (!text->target)
285: printf("%s%s\n", SPACES(line->offset), line->data);
286: else {
287: PUTS(SPACES(line->offset));
288: PUTS(line->data);
289: PUTC('\n');
290: }
291: #endif
292:
293: }
294:
295: /* Output the title line
296: ** ---------------------
297: */
298: PRIVATE void display_title ARGS1(HText *,text)
299: {
300: CONST char * title = HTAnchor_title(text->node_anchor);
301: char percent[20], format[20];
302: if (text->lines > (DISPLAY_LINES-1)) {
303: #ifdef NOPE
304: sprintf(percent, " (p%d of %d)",
305: (text->top_of_screen/(DISPLAY_LINES-1)) + 1,
306: (text->lines-1)/(DISPLAY_LINES-1) + 1);
307: sprintf(percent, " (%d%%)",
308: 100*(text->top_of_screen+DISPLAY_LINES-1)/ /* Seen */
309: (text->lines)); /* Total */
310: #else
311: sprintf(percent, " (%d/%d)",
312: text->top_of_screen+DISPLAY_LINES-1, /* Seen */
313: text->lines); /* Total */
314: #endif
315: } else {
316: percent[0] = 0; /* Null string */
317: }
318:
319: sprintf(format, "%%%d.%ds%%s\n", /* Generate format string */
320: (int)(HTScreenWidth-strlen(percent)),
321: (int)(HTScreenWidth-strlen(percent)) );
322: /* if (TRACE) fprintf(stderr, "FORMAT IS `%s'\n", format); */
323: #ifdef CURSES
324: mvwprintw(w_top, 0, 0, format, title, percent);
325: wrefresh(w_top);
326: #else
327: if (!text->target) printf(format, title, percent);
328: else {
329: char * line = (char*)malloc(HTScreenWidth+10);
330: sprintf(line, format, title, percent);
331: PUTS(line);
332: free(line);
333: }
334: #endif
335: }
336:
337:
338: /* Fill the screen with blank after the file
339: ** --------------------------
340: */
341: PRIVATE void fill_screen ARGS2(HText *, text, int,n)
342: {
343: if (n<=0 || n>1000) return; /* Large value means no pagination */
344: if (text->target) return;
345: #ifdef CURSES
346: waddstr(w_text, end_mark);
347: wclrtobot(w_text);
348: wrefresh(w_text);
349: #else
350: #ifndef VIOLA
351: if (!text->target) printf("%s\n", end_mark);
352: else { PUTS(end_mark); PUTC('\n'); }
353: n--;
354:
355: for (; n; n--) {
356: if (!text->target) printf("\n");
357: else PUTC('\n');
358: }
359: #endif
360: #endif /* Not CURSES */
361: }
362:
363:
364: /* Output a page
365: ** -------------
366: */
367: PRIVATE void display_page ARGS2(HText *,text, int,line_number)
368: {
369: HTLine * line = text->last_line->prev;
370: int i;
371: CONST char * title = HTAnchor_title(text->node_anchor);
372: int lines_of_text = title ? (DISPLAY_LINES-TITLE_LINES) : DISPLAY_LINES;
373: int last_screen = text->lines - lines_of_text;
374:
375: /* Constrain the line number to be within the document
376: */
377: if (text->lines <= lines_of_text) line_number = 0;
378: else if (line_number>last_screen) line_number = last_screen;
379: else if (line_number < 0) line_number = 0;
380:
381: for(i=0, line = text->last_line->next; /* Find line */
382: i<line_number && (line!=text->last_line);
383: i++, line=line->next) /* Loop */ assert(line->next != NULL);
384:
385: while((line!=text->last_line) && (line->size==0)) { /* Skip blank lines */
386: assert(line->next != NULL);
387: line = line->next;
388: line_number ++;
389: }
390:
391: /* Can we just scroll to it?
392: */
393: #ifndef VM /* No scrolling */
394: if (!text->stale && (line_number>=text->top_of_screen) &&
395: (line_number < text->top_of_screen + DISPLAY_LINES)) { /* Yes */
396: lines_of_text = line_number - text->top_of_screen;
397: line = text->next_line;
398: text->top_of_screen = line_number;
399: #ifdef CURSES
400: scrollok(w_text, TRUE);
401: for (i = 0; i < lines_of_text; i++) {
402: scroll(w_text);
403: }
404: #endif
405: } else
406: #endif
407: {
408: clear_screen(); /* No */
409: text->top_of_screen = line_number;
410: if (title) display_title(text);
411: }
412:
413: /* Bug: when we scroll to a part slightly futher down a page which previously
414: fitted all on one screen including the [End], the code below will add an
415: extra [End] to the screen, giving a total of two, one underneath the other.
416: */
417:
418: /* print it
419: */
420: if (line) {
421: for(i=0;
422: (i< lines_of_text) && (line != text->last_line); i++) {
423: assert(line != NULL);
424: display_line(text, line);
425: line = line->next;
426: }
427: fill_screen(text, lines_of_text - i);
428: }
429:
430: text->next_line = line; /* Line after screen */
431: text->stale = NO; /* Display is up-to-date */
432: }
433:
434:
435: /* Object Building methods
436: ** -----------------------
437: **
438: ** These are used by a parser to build the text in an object
439: */
440: PUBLIC void HText_beginAppend ARGS1(HText *,text)
441: {
442: text->permissible_split = 0;
443: text->in_line_1 = YES;
444: }
445:
446:
447: /* Add a new line of text
448: ** ----------------------
449: **
450: ** On entry,
451: **
452: ** split is zero for newline function, else number of characters
453: ** before split.
454: ** text->display_on_the_fly
455: ** may be set to indicate direct output of the finished line.
1.3 timbl 456: ** text->all_pages
457: ** if set indicates all pages are to be done on the fly.
1.1 timbl 458: ** On exit,
459: ** A new line has been made, justified according to the
460: ** current style. Text after the split (if split nonzero)
461: ** is taken over onto the next line.
462: **
463: ** If display_on_the_fly is set, then it is decremented and
464: ** the finished line is displayed.
465: */
466: #define new_line(text) split_line(text, 0)
467:
468: PRIVATE void split_line ARGS2(HText *,text, int,split)
469: {
470: HTStyle * style = text->style;
471: int spare;
472: int indent = text->in_line_1 ? text->style->indent1st
473: : text->style->leftIndent;
474:
475: /* Make new line
476: */
477: HTLine * previous = text->last_line;
478: HTLine * line = (HTLine *) malloc(LINE_SIZE(MAX_LINE));
479:
480: if (line == NULL) outofmem(__FILE__, "split_line");
481: text->lines++;
482:
483: previous->next->prev = line;
484: line->prev = previous;
485: line->next = previous->next;
486: previous->next = line;
487: text->last_line = line;
488: line->size = 0;
489: line->offset = 0;
490:
491: /* Split at required point
492: */
493: if (split) { /* Delete space at "split" splitting line */
494: char * p;
495: previous->data[previous->size] = 0;
496: for (p = &previous->data[split]; *p; p++)
497: if (*p != ' ') break;
498: strcpy(line->data, p);
499: line->size = strlen(line->data);
500: previous->size = split;
501: }
502:
503: /* Economise on space.
504: ** Not on the RS6000 due to a chaotic bug in realloc argument passing.
505: ** Same problem with Ultrix (4.2) : realloc() is not declared properly.
506: */
507: #ifndef AIX
508: #ifndef ultrix
509: while ((previous->size > 0) &&
510: (previous->data[previous->size-1] == ' ')) /* Strip trailers */
511: previous->size--;
512:
513: previous = (HTLine *) realloc (previous, LINE_SIZE(previous->size));
514: if (previous == NULL) outofmem(__FILE__, "split_line");
515: #endif /* ultrix */
516: #endif /* AIX */
517:
518: previous->prev->next = previous; /* Link in new line */
519: previous->next->prev = previous; /* Could be same node of course */
520:
521: /* Terminate finished line for printing
522: */
523: previous->data[previous->size] = 0;
524:
525:
526: /* Align left, right or center
527: */
528:
529: spare = HTScreenWidth -
530: style->rightIndent + style->leftIndent -
531: previous->size; /* @@ first line indent */
532:
533: switch (style->alignment) {
534: case HT_CENTER :
535: previous->offset = previous->offset + indent + spare/2;
536: break;
537: case HT_RIGHT :
538: previous->offset = previous->offset + indent + spare;
539: break;
540: case HT_LEFT :
541: case HT_JUSTIFY : /* Not implemented */
542: default:
543: previous->offset = previous->offset + indent;
544: break;
545: } /* switch */
546:
547: text->chars = text->chars + previous->size + 1; /* 1 for the line */
548: text->in_line_1 = NO; /* unless caller sets it otherwise */
549:
550: /* If displaying as we go, output it:
551: */
552: if (text->display_on_the_fly) {
553: if (text->display_on_the_fly == DISPLAY_LINES) { /* First line */
554: if (previous->size == 0) {
555: text->top_of_screen++; /* Scroll white space off top */
556: return;
557: }
558: if (HTAnchor_title(text->node_anchor)) { /* Title exists */
559: display_title(text);
560: text->display_on_the_fly--;
561: }
562: }
563: display_line(text, previous);
564: text->display_on_the_fly--;
1.3 timbl 565:
566: /* Loop to top of next page? */
567: if (!text->display_on_the_fly && text->all_pages) {
568: PUTS("\f\n"); /* Form feed on its own line a la rfc1111 */
569: text->display_on_the_fly = DISPLAY_LINES;
570: }
1.1 timbl 571: }
572: } /* split_line */
573:
574:
575: /* Allow vertical blank space
576: ** --------------------------
577: */
578: PRIVATE void blank_lines ARGS2(HText *,text, int,newlines)
579: {
580: if (text->last_line->size == 0) { /* No text on current line */
581: HTLine * line = text->last_line->prev;
582: while ((line!=text->last_line) && (line->size == 0)) {
583: if (newlines==0) break;
584: newlines--; /* Don't bother: already blank */
585: line = line->prev;
586: }
587: } else {
588: newlines++; /* Need also to finish this line */
589: }
590:
591: for(;newlines;newlines--) {
592: new_line(text);
593: }
594: text->in_line_1 = YES;
595: }
596:
597:
598: /* New paragraph in current style
599: ** ------------------------------
600: ** See also: setStyle.
601: */
602:
603: PUBLIC void HText_appendParagraph ARGS1(HText *,text)
604: {
605: int after = text->style->spaceAfter;
606: int before = text->style->spaceBefore;
607: blank_lines(text, after>before ? after : before);
608: }
609:
610:
611: /* Set Style
612: ** ---------
613: **
614: ** Does not filter unnecessary style changes.
615: */
616: PUBLIC void HText_setStyle ARGS2(HText *,text, HTStyle *,style)
617: {
618: int after, before;
619:
620: if (!style) return; /* Safety */
621: after = text->style->spaceAfter;
622: before = style->spaceBefore;
623: if (TRACE) fprintf(stderr, "HTML: Change to style %s\n", style->name);
624:
625: blank_lines (text, after>before ? after : before);
626:
627: text->style = style;
628: }
629:
630:
631: /* Append a character to the text object
632: ** -------------------------------------
633: */
634: PUBLIC void HText_appendCharacter ARGS2(HText *,text, char,ch)
635: {
636: HTLine * line = text->last_line;
637: HTStyle * style = text->style;
638: int indent = text->in_line_1 ? style->indent1st : style->leftIndent;
639:
640: /* New Line
641: */
642: if (ch == '\n') {
643: new_line(text);
644: text->in_line_1 = YES; /* First line of new paragraph */
645: return;
646: }
647:
648: /* Tabs
649: */
650:
651: if (ch == '\t') {
652: HTTabStop * tab;
653: int target; /* Where to tab to */
654: int here = line->size + line->offset +indent;
655: if (style->tabs) { /* Use tab table */
656: for (tab = style->tabs;
657: tab->position <= here;
658: tab++)
659: if (!tab->position) {
660: new_line(text);
661: return;
662: }
663: target = tab->position;
664: } else if (text->in_line_1) { /* Use 2nd indent */
665: if (here >= style->leftIndent) {
666: new_line(text); /* wrap */
667: return;
668: } else {
669: target = style->leftIndent;
670: }
671: } else { /* Default tabs align with left indent mod 8 */
672: #ifdef DEFAULT_TABS_8
673: target = ((line->offset + line->size + 8) & (-8))
674: + style->leftIndent;
675: #else
676: new_line(text);
677: return;
678: #endif
679: }
680: if (target > HTScreenWidth - style->rightIndent) {
681: new_line(text);
682: return;
683: } else {
684: text->permissible_split = line->size; /* Can split here */
685: if (line->size == 0) line->offset = line->offset + target - here;
686: else for(; here<target; here++) {
687: line->data[line->size++] = ' '; /* Put character into line */
688: }
689: return;
690: }
691: /*NOTREACHED*/
692: } /* if tab */
693:
694:
695: if (ch==' ') {
696: text->permissible_split = line->size; /* Can split here */
697: }
698:
699: /* Check for end of line
700: */
701: if (indent + line->offset + line->size + style->rightIndent
702: >= HTScreenWidth) {
703: if (style->wordWrap) {
704: split_line(text, text->permissible_split);
705: if (ch==' ') return; /* Ignore space causing split */
706: } else new_line(text);
707: }
708:
709: /* Insert normal characters
710: */
711: if (ch == HT_NON_BREAK_SPACE) {
712: ch = ' ';
713: }
714: {
715: HTLine * line = text->last_line; /* May have changed */
716: HTFont font = style->font;
717: line->data[line->size++] = /* Put character into line */
718: font & HT_CAPITALS ? TOUPPER(ch) : ch;
719: if (font & HT_DOUBLE) /* Do again if doubled */
720: HText_appendCharacter(text, HT_NON_BREAK_SPACE);
721: /* NOT a permissible split */
722: }
723: }
724:
725: /* Anchor handling
726: ** ---------------
727: */
728: /* Start an anchor field
729: */
730: PUBLIC void HText_beginAnchor ARGS2(HText *,text, HTChildAnchor *,anc)
731: {
732: TextAnchor * a = (TextAnchor *) malloc(sizeof(*a));
1.2 timbl 733: char marker[100];
1.1 timbl 734:
735: if (a == NULL) outofmem(__FILE__, "HText_beginAnchor");
736: a->start = text->chars + text->last_line->size;
737: a->extent = 0;
738: if (text->last_anchor) {
739: text->last_anchor->next = a;
740: } else {
741: text->first_anchor = a;
742: }
743: a->next = 0;
744: a->anchor = anc;
745: text->last_anchor = a;
746:
747: if (HTAnchor_followMainLink((HTAnchor*)anc)) {
748: a->number = ++(text->last_anchor_number);
749: } else {
750: a->number = 0;
751: }
1.2 timbl 752:
753: if (start_reference && a->number && display_anchors) {
754: /* If it goes somewhere */
755: sprintf(marker, start_reference, a->number);
756: HText_appendText(text, marker);
757: }
1.1 timbl 758: }
759:
760:
761: PUBLIC void HText_endAnchor ARGS1(HText *,text)
762: {
763: TextAnchor * a = text->last_anchor;
764: char marker[100];
765: if (a->number && display_anchors) { /* If it goes somewhere */
1.2 timbl 766: sprintf(marker, end_reference, a->number);
1.1 timbl 767: HText_appendText(text, marker);
768: }
769: a->extent = text->chars + text->last_line->size - a->start;
770: }
771:
772:
1.5 ! timbl 773: /* IMAGES
! 774: */
! 775: PUBLIC void HText_appendImage ARGS5(
! 776: HText *, text,
! 777: HTChildAnchor *, anc,
! 778: CONST char *, alt,
! 779: int, alignment,
! 780: BOOL, isMap)
! 781: {
! 782: /* HText_beginAnchor(text, anc); */
! 783: HText_appendText(text, alt? alt: "<IMAGE>");
! 784: /* HText_endAnchor(text) */
! 785: }
! 786:
1.1 timbl 787: PUBLIC void HText_appendText ARGS2(HText *,text, CONST char *,str)
788: {
789: CONST char * p;
790: for(p=str; *p; p++) {
791: HText_appendCharacter(text, *p);
792: }
793: }
794:
795:
796: PUBLIC void HText_endAppend ARGS1(HText *,text)
797: {
798: new_line(text);
799:
800: if (text->display_on_the_fly) { /* Not finished? */
801: fill_screen(text, text->display_on_the_fly); /* Finish it */
802: text->display_on_the_fly = 0;
803: text->next_line = text->last_line; /* Bug fix after EvA 920117 */
804: text->stale = NO;
805: }
806: }
807:
808:
809:
810: /* Dump diagnostics to stderr
811: */
812: PUBLIC void HText_dump ARGS1(HText *,text)
813: {
814: fprintf(stderr, "HText: Dump called\n");
815: }
816:
817:
818: /* Return the anchor associated with this node
819: */
820: PUBLIC HTParentAnchor * HText_nodeAnchor ARGS1(HText *,text)
821: {
822: return text->node_anchor;
823: }
824:
825: /* GridText specials
826: ** =================
827: */
828: /* Return the anchor with index N
829: **
830: ** The index corresponds to the number we print in the anchor.
831: */
832: PUBLIC HTChildAnchor * HText_childNumber ARGS2(HText *,text, int,number)
833: {
834: TextAnchor * a;
835: for (a = text->first_anchor; a; a = a->next) {
836: if (a->number == number) return a->anchor;
837: }
838: return (HTChildAnchor *)0; /* Fail */
839: }
840:
841: PUBLIC void HText_setStale ARGS1(HText *,text)
842: {
843: text->stale = YES;
844: }
845:
846: PUBLIC void HText_refresh ARGS1(HText *,text)
847: {
848: if (text->stale) display_page(text, text->top_of_screen);
849: }
850:
851: PUBLIC int HText_sourceAnchors ARGS1(HText *,text)
852: {
853: return text->last_anchor_number;
854: }
855:
856: PUBLIC BOOL HText_canScrollUp ARGS1(HText *,text)
857: {
858: return text->top_of_screen != 0;
859: }
860:
861: PUBLIC BOOL HText_canScrollDown ARGS1(HText *,text)
862: {
863: char * title = text->title;
864: return (text->top_of_screen + DISPLAY_LINES - (title? TITLE_LINES:0) ) <
865: text->lines;
866: }
867:
868: /* Scroll actions
869: */
870: PUBLIC void HText_scrollTop ARGS1(HText *,text)
871: {
872: display_page(text, 0);
873: }
874:
875: PUBLIC void HText_scrollDown ARGS1(HText *,text)
876: {
877: display_page(text, text->top_of_screen + DISPLAY_LINES -1);
878: }
879:
880: PUBLIC void HText_scrollUp ARGS1(HText *,text)
881: {
882: display_page(text, text->top_of_screen - DISPLAY_LINES +1);
883: }
884:
885: PUBLIC void HText_scrollBottom ARGS1(HText *,text)
886: {
887: display_page(text, text->lines - DISPLAY_LINES +1);
888: }
889:
890:
891: /* Browsing functions
892: ** ==================
893: */
894:
895: /* Bring to front and highlight it
896: */
897:
898: PRIVATE int line_for_char ARGS2(HText *,text, int,char_num)
899: {
900: int line_number =0;
901: int characters = 0;
902: HTLine * line = text->last_line->next;
903: for(;;) {
904: if (line == text->last_line) return 0; /* Invalid */
905: characters = characters + line->size + 1;
906: if (characters > char_num) return line_number;
907: line_number ++;
908: line = line->next;
909: }
910: }
911:
912: PUBLIC BOOL HText_select ARGS1(HText *,text)
913: {
914: /* if (text != HTMainText) { Do it anyway to refresh */
915: {
916: HTMainText = text;
917: HTMainAnchor = text->node_anchor;
918: display_page(text, text->top_of_screen);
919: }
920: return YES;
921: }
922:
923: PUBLIC BOOL HText_selectAnchor ARGS2(HText *,text, HTChildAnchor *,anchor)
924: {
925: TextAnchor * a;
926:
927: /* This is done later, hence HText_select is unused in GridText.c
928: Should it be the contrary ? @@@
929: if (text != HTMainText) {
930: HText_select(text);
931: }
932: */
933:
934: for(a=text->first_anchor; a; a=a->next) {
935: if (a->anchor == anchor) break;
936: }
937: if (!a) {
938: if (TRACE) fprintf(stderr, "HText: No such anchor in this text!\n");
939: return NO;
940: }
941:
942: if (text != HTMainText) { /* Comment out by ??? */
943: HTMainText = text; /* Put back in by tbl 921208 */
944: HTMainAnchor = text->node_anchor;
945: }
946:
947: {
948: int l = line_for_char(text, a->start);
949: if (TRACE) fprintf(stderr,
950: "HText: Selecting anchor [%d] at character %d, line %d\n",
951: a->number, a->start, l);
952:
953: if ( !text->stale &&
954: (l >= text->top_of_screen) &&
955: ( l < text->top_of_screen + DISPLAY_LINES-1))
956: return YES;
957:
958: display_page(text, l - (DISPLAY_LINES/3)); /* Scroll to it */
959: }
960:
961: return YES;
962: }
963:
964:
965: /* Editing functions - NOT IMPLEMENTED
966: ** =================
967: **
968: ** These are called from the application. There are many more functions
969: ** not included here from the orginal text object.
970: */
971:
972: /* Style handling:
973: */
974: /* Apply this style to the selection
975: */
976: PUBLIC void HText_applyStyle ARGS2(HText *, me, HTStyle *,style)
977: {
978:
979: }
980:
981:
982: /* Update all text with changed style.
983: */
984: PUBLIC void HText_updateStyle ARGS2(HText *, me, HTStyle *,style)
985: {
986:
987: }
988:
989:
990: /* Return style of selection
991: */
992: PUBLIC HTStyle * HText_selectionStyle ARGS2(
993: HText *,me,
994: HTStyleSheet *,sheet)
995: {
996: return 0;
997: }
998:
999:
1000: /* Paste in styled text
1001: */
1002: PUBLIC void HText_replaceSel ARGS3(
1003: HText *,me,
1004: CONST char *,aString,
1005: HTStyle *,aStyle)
1006: {
1007: }
1008:
1009:
1010: /* Apply this style to the selection and all similarly formatted text
1011: ** (style recovery only)
1012: */
1013: PUBLIC void HTextApplyToSimilar ARGS2(HText *,me, HTStyle *,style)
1014: {
1015:
1016: }
1017:
1018:
1019: /* Select the first unstyled run.
1020: ** (style recovery only)
1021: */
1022: PUBLIC void HTextSelectUnstyled ARGS2(HText *,me, HTStyleSheet *,sheet)
1023: {
1024:
1025: }
1026:
1027:
1028: /* Anchor handling:
1029: */
1030: PUBLIC void HText_unlinkSelection ARGS1(HText *,me)
1031: {
1032:
1033: }
1034:
1035: PUBLIC HTAnchor * HText_referenceSelected ARGS1(HText *,me)
1036: {
1037: return 0;
1038: }
1039:
1040:
1041: #ifdef CURSES
1042: PUBLIC int HText_getTopOfScreen ARGS1(HText *,text)
1043: {
1044: return text->top_of_screen;
1045: }
1046:
1047: PUBLIC int HText_getLines ARGS1(HText *,text)
1048: {
1049: return text->lines;
1050: }
1051: #endif
1052: PUBLIC HTAnchor * HText_linkSelTo ARGS2(HText *,me, HTAnchor *,anchor)
1053: {
1054: return 0;
1055: }
1056:
1057:
Webmaster