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