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