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