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