Annotation of libwww/LineMode/src/GridText.c, revision 1.8
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);
1.8 ! frystyk 230: if (self == HTMainText) /* Henrik 24/02-94 */
! 231: HTMainText = NULL;
1.1 timbl 232: }
233:
234:
235: /* Display Methods
236: ** ---------------
237: */
238: /* Clear the screen (on screen-mode systems)
239: ** ----------------
240: */
241: PUBLIC void clear_screen NOARGS
242: {
1.8 ! frystyk 243:
1.1 timbl 244: if (TRACE) return; /* in trace mode, don't clear trace away */
245: #ifdef CURSES
246: if (w_text != NULL) {
247: wmove(w_text,0,0);
248: wclear(w_text);
249: }
250: #else
251: #ifdef VM
252: #ifdef NEWLIB
253: int newlib_ncmd = 2;
254: char newlib_cmd[2][80];
255:
256: memset(newlib_cmd, ' ', sizeof(newlib_cmd));
257: strncpy(newlib_cmd[0], "clear", 5); /* Clear screen */
258: strncpy(newlib_cmd[1], "quit", 4); /* Leave newlib */
259: newlib(newlib_cmd, &newlib_ncmd); /* Execute command */
260:
261: #else /* not NEWLIB - real VM */
262: system("CLRSCRN"); /* Clear screen */
263: #endif /* not NEWLIB */
264: #else /* Not VM */
265: /* Do nothing */
266: #endif /* Not VM */
267: #endif /* Not CURSES */
268: if (HTMainText) HTMainText->stale = YES;
269: }
270:
271:
272: /* Output a line
273: ** -------------
274: */
275: PRIVATE void display_line ARGS2(HText *,text, HTLine *,line)
276: {
277: #ifdef CURSES
278: int y, x;
279:
280: waddstr(w_text, SPACES(line->offset));
281: waddstr(w_text, line->data);
282: getyx(w_text, y, x);
283: if (y < DISPLAY_LINES-1) {
284: wmove(w_text, ++y, 0);
285: }
286: #else
287: if (!text->target)
288: printf("%s%s\n", SPACES(line->offset), line->data);
289: else {
290: PUTS(SPACES(line->offset));
291: PUTS(line->data);
292: PUTC('\n');
293: }
294: #endif
295:
296: }
297:
298: /* Output the title line
299: ** ---------------------
300: */
301: PRIVATE void display_title ARGS1(HText *,text)
302: {
303: CONST char * title = HTAnchor_title(text->node_anchor);
304: char percent[20], format[20];
305: if (text->lines > (DISPLAY_LINES-1)) {
306: #ifdef NOPE
307: sprintf(percent, " (p%d of %d)",
308: (text->top_of_screen/(DISPLAY_LINES-1)) + 1,
309: (text->lines-1)/(DISPLAY_LINES-1) + 1);
310: sprintf(percent, " (%d%%)",
311: 100*(text->top_of_screen+DISPLAY_LINES-1)/ /* Seen */
312: (text->lines)); /* Total */
313: #else
314: sprintf(percent, " (%d/%d)",
315: text->top_of_screen+DISPLAY_LINES-1, /* Seen */
316: text->lines); /* Total */
317: #endif
318: } else {
319: percent[0] = 0; /* Null string */
320: }
321:
322: sprintf(format, "%%%d.%ds%%s\n", /* Generate format string */
323: (int)(HTScreenWidth-strlen(percent)),
324: (int)(HTScreenWidth-strlen(percent)) );
325: /* if (TRACE) fprintf(stderr, "FORMAT IS `%s'\n", format); */
326: #ifdef CURSES
327: mvwprintw(w_top, 0, 0, format, title, percent);
328: wrefresh(w_top);
329: #else
330: if (!text->target) printf(format, title, percent);
331: else {
332: char * line = (char*)malloc(HTScreenWidth+10);
333: sprintf(line, format, title, percent);
334: PUTS(line);
335: free(line);
336: }
337: #endif
338: }
339:
340:
341: /* Fill the screen with blank after the file
342: ** --------------------------
343: */
344: PRIVATE void fill_screen ARGS2(HText *, text, int,n)
345: {
346: if (n<=0 || n>1000) return; /* Large value means no pagination */
347: if (text->target) return;
348: #ifdef CURSES
349: waddstr(w_text, end_mark);
350: wclrtobot(w_text);
351: wrefresh(w_text);
352: #else
353: #ifndef VIOLA
354: if (!text->target) printf("%s\n", end_mark);
355: else { PUTS(end_mark); PUTC('\n'); }
356: n--;
357:
358: for (; n; n--) {
359: if (!text->target) printf("\n");
360: else PUTC('\n');
361: }
362: #endif
363: #endif /* Not CURSES */
364: }
365:
366:
367: /* Output a page
368: ** -------------
369: */
370: PRIVATE void display_page ARGS2(HText *,text, int,line_number)
371: {
372: HTLine * line = text->last_line->prev;
373: int i;
374: CONST char * title = HTAnchor_title(text->node_anchor);
375: int lines_of_text = title ? (DISPLAY_LINES-TITLE_LINES) : DISPLAY_LINES;
376: int last_screen = text->lines - lines_of_text;
377:
378: /* Constrain the line number to be within the document
379: */
380: if (text->lines <= lines_of_text) line_number = 0;
381: else if (line_number>last_screen) line_number = last_screen;
382: else if (line_number < 0) line_number = 0;
383:
384: for(i=0, line = text->last_line->next; /* Find line */
385: i<line_number && (line!=text->last_line);
386: i++, line=line->next) /* Loop */ assert(line->next != NULL);
387:
388: while((line!=text->last_line) && (line->size==0)) { /* Skip blank lines */
389: assert(line->next != NULL);
390: line = line->next;
391: line_number ++;
392: }
393:
394: /* Can we just scroll to it?
395: */
396: #ifndef VM /* No scrolling */
397: if (!text->stale && (line_number>=text->top_of_screen) &&
398: (line_number < text->top_of_screen + DISPLAY_LINES)) { /* Yes */
399: lines_of_text = line_number - text->top_of_screen;
400: line = text->next_line;
401: text->top_of_screen = line_number;
402: #ifdef CURSES
403: scrollok(w_text, TRUE);
404: for (i = 0; i < lines_of_text; i++) {
405: scroll(w_text);
406: }
407: #endif
408: } else
409: #endif
410: {
411: clear_screen(); /* No */
412: text->top_of_screen = line_number;
413: if (title) display_title(text);
414: }
415:
416: /* Bug: when we scroll to a part slightly futher down a page which previously
417: fitted all on one screen including the [End], the code below will add an
418: extra [End] to the screen, giving a total of two, one underneath the other.
419: */
420:
421: /* print it
422: */
423: if (line) {
424: for(i=0;
425: (i< lines_of_text) && (line != text->last_line); i++) {
426: assert(line != NULL);
427: display_line(text, line);
428: line = line->next;
429: }
430: fill_screen(text, lines_of_text - i);
431: }
432:
433: text->next_line = line; /* Line after screen */
434: text->stale = NO; /* Display is up-to-date */
435: }
436:
437:
438: /* Object Building methods
439: ** -----------------------
440: **
441: ** These are used by a parser to build the text in an object
442: */
443: PUBLIC void HText_beginAppend ARGS1(HText *,text)
444: {
445: text->permissible_split = 0;
446: text->in_line_1 = YES;
447: }
448:
449:
450: /* Add a new line of text
451: ** ----------------------
452: **
453: ** On entry,
454: **
455: ** split is zero for newline function, else number of characters
456: ** before split.
457: ** text->display_on_the_fly
458: ** may be set to indicate direct output of the finished line.
1.3 timbl 459: ** text->all_pages
460: ** if set indicates all pages are to be done on the fly.
1.1 timbl 461: ** On exit,
462: ** A new line has been made, justified according to the
463: ** current style. Text after the split (if split nonzero)
464: ** is taken over onto the next line.
465: **
466: ** If display_on_the_fly is set, then it is decremented and
467: ** the finished line is displayed.
468: */
469: #define new_line(text) split_line(text, 0)
470:
471: PRIVATE void split_line ARGS2(HText *,text, int,split)
472: {
473: HTStyle * style = text->style;
474: int spare;
475: int indent = text->in_line_1 ? text->style->indent1st
476: : text->style->leftIndent;
1.7 frystyk 477:
1.1 timbl 478: /* Make new line
479: */
480: HTLine * previous = text->last_line;
481: HTLine * line = (HTLine *) malloc(LINE_SIZE(MAX_LINE));
482:
483: if (line == NULL) outofmem(__FILE__, "split_line");
484: text->lines++;
485:
486: previous->next->prev = line;
487: line->prev = previous;
488: line->next = previous->next;
489: previous->next = line;
490: text->last_line = line;
491: line->size = 0;
492: line->offset = 0;
493:
494: /* Split at required point
495: */
496: if (split) { /* Delete space at "split" splitting line */
497: char * p;
498: previous->data[previous->size] = 0;
499: for (p = &previous->data[split]; *p; p++)
500: if (*p != ' ') break;
501: strcpy(line->data, p);
502: line->size = strlen(line->data);
503: previous->size = split;
504: }
505:
506: /* Economise on space.
507: ** Not on the RS6000 due to a chaotic bug in realloc argument passing.
508: ** Same problem with Ultrix (4.2) : realloc() is not declared properly.
509: */
510: #ifndef AIX
511: #ifndef ultrix
512: while ((previous->size > 0) &&
513: (previous->data[previous->size-1] == ' ')) /* Strip trailers */
514: previous->size--;
1.7 frystyk 515:
1.1 timbl 516: previous = (HTLine *) realloc (previous, LINE_SIZE(previous->size));
517: if (previous == NULL) outofmem(__FILE__, "split_line");
518: #endif /* ultrix */
519: #endif /* AIX */
520:
521: previous->prev->next = previous; /* Link in new line */
522: previous->next->prev = previous; /* Could be same node of course */
523:
524: /* Terminate finished line for printing
525: */
526: previous->data[previous->size] = 0;
1.7 frystyk 527:
1.1 timbl 528: /* Align left, right or center
529: */
530:
531: spare = HTScreenWidth -
532: style->rightIndent + style->leftIndent -
533: previous->size; /* @@ first line indent */
534:
535: switch (style->alignment) {
536: case HT_CENTER :
537: previous->offset = previous->offset + indent + spare/2;
538: break;
539: case HT_RIGHT :
540: previous->offset = previous->offset + indent + spare;
541: break;
542: case HT_LEFT :
543: case HT_JUSTIFY : /* Not implemented */
544: default:
545: previous->offset = previous->offset + indent;
546: break;
547: } /* switch */
548:
549: text->chars = text->chars + previous->size + 1; /* 1 for the line */
550: text->in_line_1 = NO; /* unless caller sets it otherwise */
551:
552: /* If displaying as we go, output it:
553: */
554: if (text->display_on_the_fly) {
555: if (text->display_on_the_fly == DISPLAY_LINES) { /* First line */
556: if (previous->size == 0) {
557: text->top_of_screen++; /* Scroll white space off top */
558: return;
559: }
560: if (HTAnchor_title(text->node_anchor)) { /* Title exists */
561: display_title(text);
562: text->display_on_the_fly--;
563: }
564: }
565: display_line(text, previous);
566: text->display_on_the_fly--;
1.3 timbl 567:
568: /* Loop to top of next page? */
569: if (!text->display_on_the_fly && text->all_pages) {
570: PUTS("\f\n"); /* Form feed on its own line a la rfc1111 */
571: text->display_on_the_fly = DISPLAY_LINES;
572: }
1.1 timbl 573: }
574: } /* split_line */
575:
576:
577: /* Allow vertical blank space
578: ** --------------------------
579: */
580: PRIVATE void blank_lines ARGS2(HText *,text, int,newlines)
581: {
582: if (text->last_line->size == 0) { /* No text on current line */
583: HTLine * line = text->last_line->prev;
584: while ((line!=text->last_line) && (line->size == 0)) {
585: if (newlines==0) break;
586: newlines--; /* Don't bother: already blank */
587: line = line->prev;
588: }
589: } else {
590: newlines++; /* Need also to finish this line */
591: }
592:
593: for(;newlines;newlines--) {
594: new_line(text);
595: }
596: text->in_line_1 = YES;
597: }
598:
599:
600: /* New paragraph in current style
601: ** ------------------------------
602: ** See also: setStyle.
603: */
604:
605: PUBLIC void HText_appendParagraph ARGS1(HText *,text)
606: {
607: int after = text->style->spaceAfter;
608: int before = text->style->spaceBefore;
609: blank_lines(text, after>before ? after : before);
610: }
611:
612:
613: /* Set Style
614: ** ---------
615: **
616: ** Does not filter unnecessary style changes.
617: */
618: PUBLIC void HText_setStyle ARGS2(HText *,text, HTStyle *,style)
619: {
620: int after, before;
621:
622: if (!style) return; /* Safety */
623: after = text->style->spaceAfter;
624: before = style->spaceBefore;
625: if (TRACE) fprintf(stderr, "HTML: Change to style %s\n", style->name);
626:
627: blank_lines (text, after>before ? after : before);
628:
629: text->style = style;
630: }
631:
632:
633: /* Append a character to the text object
634: ** -------------------------------------
635: */
636: PUBLIC void HText_appendCharacter ARGS2(HText *,text, char,ch)
637: {
638: HTLine * line = text->last_line;
639: HTStyle * style = text->style;
640: int indent = text->in_line_1 ? style->indent1st : style->leftIndent;
641:
642: /* New Line
643: */
644: if (ch == '\n') {
645: new_line(text);
646: text->in_line_1 = YES; /* First line of new paragraph */
647: return;
648: }
649:
650: /* Tabs
651: */
652:
653: if (ch == '\t') {
654: HTTabStop * tab;
655: int target; /* Where to tab to */
656: int here = line->size + line->offset +indent;
657: if (style->tabs) { /* Use tab table */
658: for (tab = style->tabs;
659: tab->position <= here;
660: tab++)
661: if (!tab->position) {
662: new_line(text);
663: return;
664: }
665: target = tab->position;
666: } else if (text->in_line_1) { /* Use 2nd indent */
667: if (here >= style->leftIndent) {
668: new_line(text); /* wrap */
669: return;
670: } else {
671: target = style->leftIndent;
672: }
673: } else { /* Default tabs align with left indent mod 8 */
674: #ifdef DEFAULT_TABS_8
675: target = ((line->offset + line->size + 8) & (-8))
676: + style->leftIndent;
677: #else
678: new_line(text);
679: return;
680: #endif
681: }
682: if (target > HTScreenWidth - style->rightIndent) {
683: new_line(text);
684: return;
685: } else {
686: text->permissible_split = line->size; /* Can split here */
687: if (line->size == 0) line->offset = line->offset + target - here;
688: else for(; here<target; here++) {
689: line->data[line->size++] = ' '; /* Put character into line */
690: }
691: return;
692: }
693: /*NOTREACHED*/
694: } /* if tab */
695:
696:
697: if (ch==' ') {
698: text->permissible_split = line->size; /* Can split here */
699: }
700:
701: /* Check for end of line
702: */
703: if (indent + line->offset + line->size + style->rightIndent
704: >= HTScreenWidth) {
705: if (style->wordWrap) {
1.7 frystyk 706: if(text->permissible_split > line->size) /* HENRIK 21/02-94 */
707: text->permissible_split = line->size;
1.1 timbl 708: split_line(text, text->permissible_split);
709: if (ch==' ') return; /* Ignore space causing split */
710: } else new_line(text);
711: }
712:
713: /* Insert normal characters
714: */
715: if (ch == HT_NON_BREAK_SPACE) {
716: ch = ' ';
717: }
718: {
719: HTLine * line = text->last_line; /* May have changed */
720: HTFont font = style->font;
721: line->data[line->size++] = /* Put character into line */
722: font & HT_CAPITALS ? TOUPPER(ch) : ch;
723: if (font & HT_DOUBLE) /* Do again if doubled */
724: HText_appendCharacter(text, HT_NON_BREAK_SPACE);
725: /* NOT a permissible split */
726: }
727: }
728:
729: /* Anchor handling
730: ** ---------------
731: */
732: /* Start an anchor field
733: */
734: PUBLIC void HText_beginAnchor ARGS2(HText *,text, HTChildAnchor *,anc)
735: {
736: TextAnchor * a = (TextAnchor *) malloc(sizeof(*a));
1.2 timbl 737: char marker[100];
1.1 timbl 738:
739: if (a == NULL) outofmem(__FILE__, "HText_beginAnchor");
740: a->start = text->chars + text->last_line->size;
741: a->extent = 0;
742: if (text->last_anchor) {
743: text->last_anchor->next = a;
744: } else {
745: text->first_anchor = a;
746: }
747: a->next = 0;
748: a->anchor = anc;
749: text->last_anchor = a;
750:
751: if (HTAnchor_followMainLink((HTAnchor*)anc)) {
752: a->number = ++(text->last_anchor_number);
753: } else {
754: a->number = 0;
755: }
1.2 timbl 756:
757: if (start_reference && a->number && display_anchors) {
758: /* If it goes somewhere */
759: sprintf(marker, start_reference, a->number);
760: HText_appendText(text, marker);
761: }
1.1 timbl 762: }
763:
764:
765: PUBLIC void HText_endAnchor ARGS1(HText *,text)
766: {
767: TextAnchor * a = text->last_anchor;
768: char marker[100];
769: if (a->number && display_anchors) { /* If it goes somewhere */
1.2 timbl 770: sprintf(marker, end_reference, a->number);
1.1 timbl 771: HText_appendText(text, marker);
772: }
773: a->extent = text->chars + text->last_line->size - a->start;
774: }
775:
776:
1.5 timbl 777: /* IMAGES
778: */
779: PUBLIC void HText_appendImage ARGS5(
780: HText *, text,
781: HTChildAnchor *, anc,
782: CONST char *, alt,
1.6 frystyk 783: /* int, alignment, */
784: /* HENRIK */
785: CONST char*, alignment,
1.5 timbl 786: BOOL, isMap)
787: {
788: /* HText_beginAnchor(text, anc); */
789: HText_appendText(text, alt? alt: "<IMAGE>");
790: /* HText_endAnchor(text) */
791: }
792:
1.1 timbl 793: PUBLIC void HText_appendText ARGS2(HText *,text, CONST char *,str)
794: {
795: CONST char * p;
796: for(p=str; *p; p++) {
797: HText_appendCharacter(text, *p);
798: }
799: }
800:
801:
802: PUBLIC void HText_endAppend ARGS1(HText *,text)
803: {
804: new_line(text);
805:
806: if (text->display_on_the_fly) { /* Not finished? */
807: fill_screen(text, text->display_on_the_fly); /* Finish it */
808: text->display_on_the_fly = 0;
809: text->next_line = text->last_line; /* Bug fix after EvA 920117 */
810: text->stale = NO;
811: }
812: }
813:
814:
815:
816: /* Dump diagnostics to stderr
817: */
818: PUBLIC void HText_dump ARGS1(HText *,text)
819: {
820: fprintf(stderr, "HText: Dump called\n");
821: }
822:
823:
824: /* Return the anchor associated with this node
825: */
826: PUBLIC HTParentAnchor * HText_nodeAnchor ARGS1(HText *,text)
827: {
828: return text->node_anchor;
829: }
830:
831: /* GridText specials
832: ** =================
833: */
834: /* Return the anchor with index N
835: **
836: ** The index corresponds to the number we print in the anchor.
837: */
838: PUBLIC HTChildAnchor * HText_childNumber ARGS2(HText *,text, int,number)
839: {
840: TextAnchor * a;
841: for (a = text->first_anchor; a; a = a->next) {
842: if (a->number == number) return a->anchor;
843: }
844: return (HTChildAnchor *)0; /* Fail */
845: }
846:
847: PUBLIC void HText_setStale ARGS1(HText *,text)
848: {
849: text->stale = YES;
850: }
851:
852: PUBLIC void HText_refresh ARGS1(HText *,text)
853: {
854: if (text->stale) display_page(text, text->top_of_screen);
855: }
856:
857: PUBLIC int HText_sourceAnchors ARGS1(HText *,text)
858: {
859: return text->last_anchor_number;
860: }
861:
862: PUBLIC BOOL HText_canScrollUp ARGS1(HText *,text)
863: {
864: return text->top_of_screen != 0;
865: }
866:
867: PUBLIC BOOL HText_canScrollDown ARGS1(HText *,text)
868: {
869: char * title = text->title;
870: return (text->top_of_screen + DISPLAY_LINES - (title? TITLE_LINES:0) ) <
871: text->lines;
872: }
873:
874: /* Scroll actions
875: */
876: PUBLIC void HText_scrollTop ARGS1(HText *,text)
877: {
878: display_page(text, 0);
879: }
880:
881: PUBLIC void HText_scrollDown ARGS1(HText *,text)
882: {
883: display_page(text, text->top_of_screen + DISPLAY_LINES -1);
884: }
885:
886: PUBLIC void HText_scrollUp ARGS1(HText *,text)
887: {
888: display_page(text, text->top_of_screen - DISPLAY_LINES +1);
889: }
890:
891: PUBLIC void HText_scrollBottom ARGS1(HText *,text)
892: {
893: display_page(text, text->lines - DISPLAY_LINES +1);
894: }
895:
896:
897: /* Browsing functions
898: ** ==================
899: */
900:
901: /* Bring to front and highlight it
902: */
903:
904: PRIVATE int line_for_char ARGS2(HText *,text, int,char_num)
905: {
906: int line_number =0;
907: int characters = 0;
908: HTLine * line = text->last_line->next;
909: for(;;) {
910: if (line == text->last_line) return 0; /* Invalid */
911: characters = characters + line->size + 1;
912: if (characters > char_num) return line_number;
913: line_number ++;
914: line = line->next;
915: }
916: }
917:
918: PUBLIC BOOL HText_select ARGS1(HText *,text)
919: {
920: /* if (text != HTMainText) { Do it anyway to refresh */
921: {
922: HTMainText = text;
923: HTMainAnchor = text->node_anchor;
924: display_page(text, text->top_of_screen);
925: }
926: return YES;
927: }
928:
929: PUBLIC BOOL HText_selectAnchor ARGS2(HText *,text, HTChildAnchor *,anchor)
930: {
931: TextAnchor * a;
932:
933: /* This is done later, hence HText_select is unused in GridText.c
934: Should it be the contrary ? @@@
935: if (text != HTMainText) {
936: HText_select(text);
937: }
938: */
939:
940: for(a=text->first_anchor; a; a=a->next) {
941: if (a->anchor == anchor) break;
942: }
943: if (!a) {
944: if (TRACE) fprintf(stderr, "HText: No such anchor in this text!\n");
945: return NO;
946: }
947:
948: if (text != HTMainText) { /* Comment out by ??? */
949: HTMainText = text; /* Put back in by tbl 921208 */
950: HTMainAnchor = text->node_anchor;
951: }
952:
953: {
954: int l = line_for_char(text, a->start);
955: if (TRACE) fprintf(stderr,
956: "HText: Selecting anchor [%d] at character %d, line %d\n",
957: a->number, a->start, l);
958:
959: if ( !text->stale &&
960: (l >= text->top_of_screen) &&
961: ( l < text->top_of_screen + DISPLAY_LINES-1))
962: return YES;
963:
964: display_page(text, l - (DISPLAY_LINES/3)); /* Scroll to it */
965: }
966:
967: return YES;
968: }
969:
970:
971: /* Editing functions - NOT IMPLEMENTED
972: ** =================
973: **
974: ** These are called from the application. There are many more functions
975: ** not included here from the orginal text object.
976: */
977:
978: /* Style handling:
979: */
980: /* Apply this style to the selection
981: */
982: PUBLIC void HText_applyStyle ARGS2(HText *, me, HTStyle *,style)
983: {
984:
985: }
986:
987:
988: /* Update all text with changed style.
989: */
990: PUBLIC void HText_updateStyle ARGS2(HText *, me, HTStyle *,style)
991: {
992:
993: }
994:
995:
996: /* Return style of selection
997: */
998: PUBLIC HTStyle * HText_selectionStyle ARGS2(
999: HText *,me,
1000: HTStyleSheet *,sheet)
1001: {
1002: return 0;
1003: }
1004:
1005:
1006: /* Paste in styled text
1007: */
1008: PUBLIC void HText_replaceSel ARGS3(
1009: HText *,me,
1010: CONST char *,aString,
1011: HTStyle *,aStyle)
1012: {
1013: }
1014:
1015:
1016: /* Apply this style to the selection and all similarly formatted text
1017: ** (style recovery only)
1018: */
1019: PUBLIC void HTextApplyToSimilar ARGS2(HText *,me, HTStyle *,style)
1020: {
1021:
1022: }
1023:
1024:
1025: /* Select the first unstyled run.
1026: ** (style recovery only)
1027: */
1028: PUBLIC void HTextSelectUnstyled ARGS2(HText *,me, HTStyleSheet *,sheet)
1029: {
1030:
1031: }
1032:
1033:
1034: /* Anchor handling:
1035: */
1036: PUBLIC void HText_unlinkSelection ARGS1(HText *,me)
1037: {
1038:
1039: }
1040:
1041: PUBLIC HTAnchor * HText_referenceSelected ARGS1(HText *,me)
1042: {
1043: return 0;
1044: }
1045:
1046:
1047: #ifdef CURSES
1048: PUBLIC int HText_getTopOfScreen ARGS1(HText *,text)
1049: {
1050: return text->top_of_screen;
1051: }
1052:
1053: PUBLIC int HText_getLines ARGS1(HText *,text)
1054: {
1055: return text->lines;
1056: }
1057: #endif
1058: PUBLIC HTAnchor * HText_linkSelTo ARGS2(HText *,me, HTAnchor *,anchor)
1059: {
1060: return 0;
1061: }
1062:
1063:
Webmaster