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