Annotation of Amaya/amaya/HTMLbook.c, revision 1.52
1.1 cvs 1: /*
2: *
3: * (c) COPYRIGHT MIT and INRIA, 1996.
4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
8: /*
9: * Initialization functions and button functions of Amaya application.
10: *
11: * Authors: V. Quint, I. Vatton
1.49 cvs 12: * R. Guetari (W3C/INRIA) - Unicode and Windows version.
1.1 cvs 13: */
14:
15:
16: /* Included headerfiles */
17: #define THOT_EXPORT
18: #include "amaya.h"
1.44 cvs 19: #include "AHTURLTools_f.h"
1.1 cvs 20: #include "print.h"
1.51 cvs 21: #include "css.h"
1.1 cvs 22:
23: #define NumFormPrint 1
24: #define NumMenuOptions 2
25: #define NumMenuPaperFormat 3
26: #define NumMenuSupport 4
27: #define NumZonePrinterName 5
28: #define PRINT_MAX_REF 6
29:
1.25 cvs 30: /* structure to register sub-documents in MakeBook function*/
31: typedef struct _SubDoc
32: {
33: struct _SubDoc *SDnext;
34: Element SDel;
1.36 cvs 35: STRING SDname;
1.25 cvs 36: }SubDoc;
37:
1.29 cvs 38: /* the structure used for the GetIncludedDocuments_callback function */
39: typedef struct _GetIncludedDocuments_context {
40: Element link, next;
41: Attribute RelAttr, HrefAttr;
1.36 cvs 42: STRING url, ptr, text;
1.29 cvs 43: Document document;
44: } GetIncludedDocuments_context;
45:
1.25 cvs 46: static struct _SubDoc *SubDocs;
1.2 cvs 47: static int PaperPrint;
48: static int ManualFeed;
49: static int PageSize;
1.50 cvs 50: static CHAR_T PSdir[MAX_PATH];
51: static CHAR_T pPrinter[MAX_PATH];
1.1 cvs 52: static Document docPrint;
1.47 cvs 53: static ThotBool numberLinks;
54: static ThotBool withToC;
55: static ThotBool printURL;
1.1 cvs 56: static int basePrint;
57:
58: #include "init_f.h"
59: #include "HTMLactions_f.h"
60: #include "HTMLbook_f.h"
61: #include "HTMLedit_f.h"
1.25 cvs 62: #include "HTMLhistory_f.h"
1.51 cvs 63: #include "UIcss_f.h"
1.1 cvs 64:
1.31 cvs 65: #ifdef _WINDOWS
1.37 cvs 66: #include "wininclude.h"
1.31 cvs 67: #endif /* _WINDOWS */
68:
1.29 cvs 69: /*-----------------------------------------------------------------------
70: Function prototypes
71: ----------------------------------------------------------------------*/
72: #ifdef __STDC__
73: static void GetIncludedDocuments (Element el, Document document);
74: void MakeBook_callback (Document document);
75: #else
76: static void GetIncludedDocuments (/* el, document */);
77: void MakeBook_callback (/* Document document */);
78: #endif
1.1 cvs 79:
80: /*----------------------------------------------------------------------
1.16 cvs 81: RegisterSubDoc adds a new entry in SubDoc table.
82: ----------------------------------------------------------------------*/
83: #ifdef __STDC__
1.36 cvs 84: static void RegisterSubDoc (Element el, STRING url)
1.16 cvs 85: #else
86: static void RegisterSubDoc (el, url)
87: Element el;
1.36 cvs 88: STRING url;
1.16 cvs 89: #endif
90: {
91: struct _SubDoc *entry, *last;
92:
93: if (url == NULL || url[0] == EOS)
94: return;
95:
96: entry = TtaGetMemory (sizeof (struct _SubDoc));
97: entry->SDnext = NULL;
98: entry->SDel = el;
99: entry->SDname = TtaStrdup (url);
100:
101: if (SubDocs == NULL)
102: SubDocs = entry;
103: else
104: {
105: last = SubDocs;
106: while (last->SDnext != NULL)
107: last = last->SDnext;
108: last->SDnext = entry;
109: }
110: }
111:
112:
113: /*----------------------------------------------------------------------
114: SearchSubDoc searches whether a document name is registered or not
115: within the SubDoc table.
116: Return the DIV element that correspond to the sub-document or NULL.
117: ----------------------------------------------------------------------*/
118: #ifdef __STDC__
1.36 cvs 119: static Element SearchSubDoc (STRING url)
1.16 cvs 120: #else
121: static Element SearchSubDoc (url)
1.36 cvs 122: STRING url;
1.16 cvs 123: #endif
124: {
125: Element el;
126: struct _SubDoc *entry;
1.47 cvs 127: ThotBool docFound;
1.16 cvs 128:
129: if (url == NULL || url[0] == EOS)
130: return (NULL);
131:
132: entry = SubDocs;
133: docFound = FALSE;
134: el = NULL;
135: while (!docFound && entry != NULL)
136: {
1.36 cvs 137: docFound = (ustrcmp (url, entry->SDname) == 0);
1.16 cvs 138: if (!docFound)
139: entry = entry->SDnext;
140: else
141: /* document found -> return the DIV element */
142: el = entry->SDel;
143: }
144: return (el);
145: }
146:
147: /*----------------------------------------------------------------------
148: FreeSubDocTable frees all entries in SubDoc table.
149: ----------------------------------------------------------------------*/
150: static void FreeSubDocTable ()
151: {
152: struct _SubDoc *entry, *last;
153:
154: entry = SubDocs;
155: while (entry != NULL)
156: {
157: last = entry;
158: entry = entry->SDnext;
159: TtaFreeMemory (last->SDname);
160: TtaFreeMemory (last);
161: }
162: SubDocs = NULL;
163: }
164:
165:
166:
167: /*----------------------------------------------------------------------
1.1 cvs 168: SetInternalLinks
1.8 cvs 169: Associate an InternalLink attribute with all anchor (A) elements of the
170: document which designate an element in the same document.
1.1 cvs 171: InternalLink is a Thot reference attribute that links a source and a
172: target anchor and that allows P schemas to display and print cross-references
173: ----------------------------------------------------------------------*/
174: #ifdef __STDC__
1.4 cvs 175: void SetInternalLinks (Document document)
1.1 cvs 176: #else
1.4 cvs 177: void SetInternalLinks (document)
1.1 cvs 178: Document document;
179: #endif
180: {
1.32 cvs 181: Element el, div, link, target, sibling;
182: ElementType elType, linkType;
1.16 cvs 183: Attribute HrefAttr, IntLinkAttr;
1.17 cvs 184: Attribute attr, ExtLinkAttr;
1.16 cvs 185: AttributeType attrType;
1.36 cvs 186: STRING text, ptr, url;
1.43 cvs 187: CHAR_T number[10];
188: CHAR_T value[MAX_LENGTH];
1.25 cvs 189: int length, i, volume;
190: int status, position;
1.47 cvs 191: ThotBool split;
1.1 cvs 192:
1.16 cvs 193: /* Remember the current status of the document */
194: status = TtaIsDocumentModified (document);
1.32 cvs 195: el = TtaGetMainRoot (document);
196: volume = TtaGetElementVolume (el);
197: elType = TtaGetElementType (el);
198: elType.ElTypeNum = HTML_EL_AnyLink;
1.16 cvs 199: attrType.AttrSSchema = elType.ElSSchema;
1.32 cvs 200: /* looks for all links in the document */
1.16 cvs 201: link = el;
202: while (link != NULL)
203: {
1.25 cvs 204: /* display the progression of the work */
205: el = link;
206: position = 0;
207: while (el != NULL)
208: {
209: sibling = el;
210: do
211: {
212: /* add volume of each previous element */
213: TtaPreviousSibling (&sibling);
214: if (sibling != NULL)
215: position += TtaGetElementVolume (sibling);
216: }
217: while (sibling != NULL);
218: el = TtaGetParent (el);
219: }
1.49 cvs 220: usprintf (number, TEXT("%d"), position*100/volume);
1.25 cvs 221: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_UPDATED_LINK), number);
222: TtaHandlePendingEvents ();
1.16 cvs 223: link = TtaSearchTypedElement (elType, SearchForward, link);
224: if (link != NULL)
1.32 cvs 225: /* a link has been found */
1.16 cvs 226: {
1.32 cvs 227: linkType = TtaGetElementType (link);
228: if (linkType.ElTypeNum == HTML_EL_Anchor)
229: attrType.AttrTypeNum = HTML_ATTR_HREF_;
230: else
231: attrType.AttrTypeNum = HTML_ATTR_cite;
1.16 cvs 232: HrefAttr = TtaGetAttribute (link, attrType);
233: attrType.AttrTypeNum = HTML_ATTR_InternalLink;
234: IntLinkAttr = TtaGetAttribute (link, attrType);
235: attrType.AttrTypeNum = HTML_ATTR_ExternalLink;
236: ExtLinkAttr = TtaGetAttribute (link, attrType);
237: if (HrefAttr == NULL)
1.32 cvs 238: /* this element is not a link (no href or cite attribute) */
1.16 cvs 239: /* remove attributes InternalLink and ExternalLink if they
240: are present */
241: {
1.8 cvs 242: if (IntLinkAttr != NULL)
1.16 cvs 243: TtaRemoveAttribute (link, IntLinkAttr, document);
244: if (ExtLinkAttr != NULL)
245: TtaRemoveAttribute (link, ExtLinkAttr, document);
246: }
247: else
1.32 cvs 248: /* this element has an HREF or cite attribute */
1.16 cvs 249: {
250: length = TtaGetTextAttributeLength (HrefAttr);
1.49 cvs 251: text = TtaAllocString (length + 1);
1.16 cvs 252: TtaGiveTextAttributeValue (HrefAttr, text, &length);
253:
254: /* does an external link become an internal link ? */
1.25 cvs 255: if (document == DocBook && SubDocs != NULL)
1.16 cvs 256: {
1.36 cvs 257: ptr = ustrrchr (text, '#');
1.16 cvs 258: url = text;
1.18 cvs 259: split = FALSE;
1.16 cvs 260: if (ptr == text)
261: /* a local link */
262: url = NULL;
1.17 cvs 263: else if (ptr != NULL)
1.16 cvs 264: {
265: /* split url and name part */
266: ptr[0] = EOS;
267: split = TRUE;
268: }
269:
270: /* Is it a sub-document */
271: div = SearchSubDoc (url);
272: if (split)
273: /* retore the mark */
274: ptr[0] = '#';
275:
276: if (div == NULL)
277: {
278: /* it's not a sub-document */
279: if (url == NULL)
280: /* a local link */
281: ptr = &text[1];
282: else
283: /* still an externa; link */
284: ptr = NULL;
285: }
286: else
287: {
288: /* this link becomes internal */
1.17 cvs 289: if (ptr != NULL)
1.16 cvs 290: {
1.17 cvs 291: /* get the target name */
1.36 cvs 292: ustrcpy (value, ptr);
293: length = ustrlen (value);
1.17 cvs 294: /* check whether the name changed */
295: i = 0;
296: target = SearchNAMEattribute (document, &value[1], NULL);
297: while (target != NULL)
1.16 cvs 298: {
1.17 cvs 299: /* is it the right NAME */
300: if (TtaIsAncestor (target, div))
301: target = NULL;
302: else
303: {
304: /* continue the search */
305: i++;
1.49 cvs 306: usprintf (&value[length], TEXT("%d"), i);
1.32 cvs 307: target = SearchNAMEattribute (document,
308: &value[1], NULL);
1.17 cvs 309: }
1.16 cvs 310: }
311: }
1.17 cvs 312: else
313: {
314: /* get the DIV name */
315: attrType.AttrTypeNum = HTML_ATTR_ID;
316: attr = TtaGetAttribute (div, attrType);
317: length = 200;
318: value[0] = '#';
319: TtaGiveTextAttributeValue (attr, &value[1], &length);
320: }
1.16 cvs 321: ptr = &value[1];
322: TtaSetAttributeText (HrefAttr, value, link, document);
323: }
324: }
325: else if (text[0] == '#')
326: ptr = &text[1];
327: else
328: ptr = NULL;
329:
330: if (ptr != NULL)
331: /* it's an internal link. Attach an attribute InternalLink */
332: /* to the link, if this attribute does not exist yet */
333: {
334: if (IntLinkAttr == NULL)
335: {
336: attrType.AttrTypeNum = HTML_ATTR_InternalLink;
337: IntLinkAttr = TtaNewAttribute (attrType);
338: TtaAttachAttribute (link, IntLinkAttr, document);
339: }
340: /* looks for the target element */
341: target = SearchNAMEattribute (document, ptr, NULL);
342: if (target != NULL)
343: /* set the Thot link */
1.32 cvs 344: TtaSetAttributeReference (IntLinkAttr, link, document,
345: target, document);
1.16 cvs 346: }
347: else
348: /* it's an external link */
349: {
350: /* Remove the InternalLink attribute if it is present */
351: if (IntLinkAttr != NULL)
352: TtaRemoveAttribute (link, IntLinkAttr, document);
353: /* create an ExternalLink attribute if there is none */
354: if (ExtLinkAttr == NULL)
355: {
356: attrType.AttrTypeNum = HTML_ATTR_ExternalLink;
357: ExtLinkAttr = TtaNewAttribute (attrType);
358: TtaAttachAttribute (link, ExtLinkAttr, document);
359: }
360: }
361: TtaFreeMemory (text);
362: }
363: }
364: }
365: /* Reset document status */
366: if (!status)
367: TtaSetDocumentUnmodified (document);
1.3 cvs 368: }
369:
370: /*----------------------------------------------------------------------
371: CheckPrintingDocument reinitialize printing parameters as soon as
372: the printing document changes.
373: ----------------------------------------------------------------------*/
374: #ifdef __STDC__
375: static void CheckPrintingDocument (Document document)
376: #else
377: static void CheckPrintingDocument (document)
378: Document document;
379: #endif
380: {
1.43 cvs 381: CHAR_T docName[MAX_LENGTH];
1.36 cvs 382: STRING ptr;
1.43 cvs 383: CHAR_T suffix[MAX_LENGTH];
1.3 cvs 384: int lg;
385:
386: if (docPrint != document)
387: {
388: /* initialize print parameters */
389: docPrint = document;
390:
391: /* define the new default PS file */
1.52 ! cvs 392: ptr = TtaGetEnvString ("APP_TMPDIR");
1.3 cvs 393: if (ptr != NULL && TtaCheckDirectory (ptr))
1.50 cvs 394: ustrcpy(PSdir, ptr);
1.44 cvs 395: else
1.49 cvs 396: ustrcpy (PSdir, TtaGetDefEnvString (TEXT("APP_TMPDIR")));
1.36 cvs 397: lg = ustrlen(PSdir);
1.3 cvs 398: if (PSdir[lg - 1] == DIR_SEP)
1.44 cvs 399: PSdir[--lg] = EOS;
400:
1.36 cvs 401: ustrcpy (docName, TtaGetDocumentName (document));
1.3 cvs 402: ExtractSuffix (docName, suffix);
1.49 cvs 403: usprintf (&PSdir[lg], TEXT("%c%s.ps"), DIR_SEP, docName);
1.3 cvs 404: TtaSetPsFile (PSdir);
405: /* define the new default PrintSchema */
406: numberLinks = FALSE;
407: withToC = FALSE;
1.34 cvs 408: printURL = TRUE;
1.49 cvs 409: TtaSetPrintSchema (_EMPTYSTR_);
1.3 cvs 410: /* no manual feed */
411: ManualFeed = PP_OFF;
412: TtaSetPrintParameter (PP_ManualFeed, ManualFeed);
413: }
414: }
415:
416:
417: /*----------------------------------------------------------------------
418: PrintAs prints the document using predefined parameters.
419: ----------------------------------------------------------------------*/
420: #ifdef __STDC__
1.45 cvs 421: static void PrintDocument (Document doc, View view)
1.3 cvs 422: #else /* __STDC__ */
1.45 cvs 423: static void PrintDocument (doc, view)
1.38 cvs 424: Document doc;
1.3 cvs 425: #endif /* __STDC__ */
426: {
1.34 cvs 427: AttributeType attrType;
428: Attribute attr;
429: Element el;
1.50 cvs 430: STRING files, dir;
431: CHAR_T viewsToPrint[MAX_PATH];
1.47 cvs 432: ThotBool status, textFile;
1.3 cvs 433:
1.38 cvs 434: textFile = (DocumentTypes[doc] == docText ||
435: DocumentTypes[doc] == docTextRO ||
436: DocumentTypes[doc] == docCSS ||
437: DocumentTypes[doc] == docCSSRO);
438:
439: CheckPrintingDocument (doc);
1.49 cvs 440: ustrcpy (viewsToPrint, TEXT("Formatted_view "));
1.38 cvs 441: if (!textFile && withToC)
1.49 cvs 442: ustrcat (viewsToPrint, TEXT("Table_of_contents "));
1.38 cvs 443: if (!textFile && numberLinks)
1.8 cvs 444: /* display numbered links */
1.3 cvs 445: {
1.8 cvs 446: /* associate an attribute InternalLink with all anchors refering
447: a target in the same document. This allows P schemas to work
448: properly */
449: SetInternalLinks (docPrint);
1.3 cvs 450: if (PageSize == PP_A4)
1.49 cvs 451: TtaSetPrintSchema (TEXT("HTMLPLP"));
1.3 cvs 452: else
1.49 cvs 453: TtaSetPrintSchema (TEXT("HTMLPLPUS"));
454: ustrcat (viewsToPrint, TEXT("Links_view "));
1.32 cvs 455: }
456: else
457: {
458: if (PageSize == PP_A4)
1.38 cvs 459: {
460: if (textFile)
1.49 cvs 461: TtaSetPrintSchema (TEXT("TextFilePP"));
1.38 cvs 462: else
1.49 cvs 463: TtaSetPrintSchema (TEXT("HTMLPP"));
1.38 cvs 464: }
1.32 cvs 465: else
1.38 cvs 466: {
467: if (textFile)
1.49 cvs 468: TtaSetPrintSchema (TEXT("TextFilePPUS"));
1.38 cvs 469: else
1.49 cvs 470: TtaSetPrintSchema (TEXT("HTMLPPUS"));
1.38 cvs 471: }
1.3 cvs 472: }
1.34 cvs 473: /* post or remove the PrintURL attribute */
1.38 cvs 474: el = TtaGetMainRoot (doc);
475: status = TtaIsDocumentModified (doc);
476: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
477: if (textFile)
478: attrType.AttrTypeNum = TextFile_ATTR_PrintURL;
479: else
480: attrType.AttrTypeNum = HTML_ATTR_PrintURL;
1.34 cvs 481: attr = TtaGetAttribute (el, attrType);
482: if (attr == 0 && printURL)
483: {
484: attr = TtaNewAttribute (attrType);
1.38 cvs 485: TtaAttachAttribute (el, attr, doc);
1.34 cvs 486: }
1.50 cvs 487:
1.34 cvs 488: if (attr != 0 && !printURL)
1.38 cvs 489: TtaRemoveAttribute (el, attr, doc);
1.50 cvs 490: /* get the path dir where css files have to be stored */
491: if (textFile)
492: files = NULL;
493: else
494: {
495: TtaGetPrintNames (&files, &dir);
496: /* store css files and get the list of names */
497: files = CssToPrint (doc, dir);
498: }
499: TtaPrint (docPrint, viewsToPrint, files);
500: TtaFreeMemory (files);
1.34 cvs 501: if (!status)
1.38 cvs 502: TtaSetDocumentUnmodified (doc);
1.1 cvs 503: }
504:
1.45 cvs 505: /*----------------------------------------------------------------------
506: PrintAs prints the document using predefined parameters.
507: ----------------------------------------------------------------------*/
508: #ifdef __STDC__
509: void PrintAs (Document doc, View view)
510: #else /* __STDC__ */
511: void PrintAs (doc, view)
512: Document doc;
513: #endif /* __STDC__ */
514: {
515: #ifdef _WINDOWS
516: SetupAndPrint (doc, view);
517: #else /* _WINDOWS */
518: PrintDocument (doc, view);
519: #endif /* _WINDOWS */
520: }
1.1 cvs 521:
522: /*----------------------------------------------------------------------
523: CallbackImage manage returns of Picture form.
524: ----------------------------------------------------------------------*/
525: #ifdef __STDC__
1.36 cvs 526: void CallbackPrint (int ref, int typedata, STRING data)
1.1 cvs 527: #else /* __STDC__ */
528: void CallbackPrint (ref, typedata, data)
529: int ref;
530: int typedata;
1.36 cvs 531: STRING data;
1.1 cvs 532: #endif /* __STDC__ */
533: {
534: int val;
535:
536: val = (int) data;
537: switch (ref - basePrint)
538: {
539: case NumFormPrint:
540: TtaDestroyDialogue (basePrint+NumFormPrint);
541: switch (val)
542: {
543: case 1:
544: /* confirms the paper print option */
545: /* the other options are not taken into account without this
546: confirmation */
1.2 cvs 547: TtaSetPrintParameter (PP_Destination, PaperPrint);
548: TtaSetPrintParameter (PP_ManualFeed, ManualFeed);
549: TtaSetPrintParameter (PP_PaperSize, PageSize);
550: TtaSetPrintCommand (pPrinter);
551: TtaSetPsFile (PSdir);
1.40 cvs 552: /* update the environment variable */
1.52 ! cvs 553: TtaSetEnvString ("THOTPRINT", pPrinter, TRUE);
1.49 cvs 554: TtaSetEnvInt (_PAPERSIZE_EVAR_, PageSize, TRUE);
1.46 cvs 555: PrintDocument (docPrint, 1);
1.1 cvs 556: break;
1.2 cvs 557: case 0:
1.40 cvs 558: PaperPrint = (TtaGetPrintParameter (PP_Destination)) ? PP_PRINTER : PP_PS;
1.2 cvs 559: ManualFeed = TtaGetPrintParameter (PP_ManualFeed);
560: PageSize = TtaGetPrintParameter (PP_PaperSize);
561: TtaGetPrintCommand (pPrinter);
562: TtaGetPsFile (PSdir);
563: break;
1.1 cvs 564: default:
565: break;
566: }
567: break;
568: case NumMenuOptions:
569: switch (val)
570: {
571: case 0:
572: /* Manual feed option */
1.2 cvs 573: if (ManualFeed == PP_ON)
574: ManualFeed = PP_OFF;
575: else
576: ManualFeed = PP_ON;
1.1 cvs 577: break;
578: case 1:
579: /* Toc option */
580: withToC = !withToC;
581: break;
582: case 2:
1.3 cvs 583: /* numberLinks option */
1.1 cvs 584: numberLinks = !numberLinks;
1.34 cvs 585: case 3:
586: /* URL option */
587: printURL = !printURL;
1.1 cvs 588: break;
589: }
590: break;
591: case NumMenuPaperFormat:
592: /* page size submenu */
593: switch (val)
594: {
595: case 0:
1.2 cvs 596: PageSize = PP_A4;
1.1 cvs 597: break;
598: case 1:
1.2 cvs 599: PageSize = PP_US;
1.1 cvs 600: break;
601: }
602: break;
603: case NumMenuSupport:
604: /* paper print/save PostScript submenu */
605: switch (val)
606: {
607: case 0:
1.2 cvs 608: if (PaperPrint == PP_PS)
1.1 cvs 609: {
1.2 cvs 610: PaperPrint = PP_PRINTER;
1.1 cvs 611: TtaSetTextForm (basePrint+NumZonePrinterName, pPrinter);
612: }
613: break;
614: case 1:
1.2 cvs 615: if (PaperPrint == PP_PRINTER)
1.1 cvs 616: {
1.2 cvs 617: PaperPrint = PP_PS;
1.1 cvs 618: TtaSetTextForm (basePrint+NumZonePrinterName, PSdir);
619: }
620: break;
621: }
622: break;
623: case NumZonePrinterName:
624: if (data[0] != '\0')
1.2 cvs 625: if (PaperPrint == PP_PRINTER)
1.40 cvs 626: /* text capture zone for the printer name */
627: ustrncpy (pPrinter, data, MAX_PATH);
1.1 cvs 628: else
629: /* text capture zone for the name of the PostScript file */
1.36 cvs 630: ustrncpy (PSdir, data, MAX_PATH);
1.1 cvs 631: break;
632: }
633: }
634:
635: /*----------------------------------------------------------------------
636: ----------------------------------------------------------------------*/
637: #ifdef __STDC__
638: void InitPrint (void)
639: #else /* __STDC__ */
640: void InitPrint ()
641: #endif /* __STDC__ */
642: {
1.36 cvs 643: STRING ptr;
1.1 cvs 644:
645: basePrint = TtaSetCallback (CallbackPrint, PRINT_MAX_REF);
646: docPrint = 0;
647:
648: /* init printer variables */
649: /* read default printer variable */
1.52 ! cvs 650: ptr = TtaGetEnvString ("THOTPRINT");
1.1 cvs 651: if (ptr == NULL)
1.49 cvs 652: ustrcpy (pPrinter, _EMPTYSTR_);
1.1 cvs 653: else
1.36 cvs 654: ustrcpy (pPrinter, ptr);
1.49 cvs 655: TtaGetEnvInt (_PAPERSIZE_EVAR_, &PageSize);
1.2 cvs 656: PaperPrint = PP_PRINTER;
1.35 cvs 657: printURL = TRUE;
1.2 cvs 658: TtaSetPrintParameter (PP_Destination, PaperPrint);
659: TtaSetPrintParameter (PP_PaperSize, PageSize);
660: TtaSetPrintCommand (pPrinter);
1.1 cvs 661: }
662:
663: /*----------------------------------------------------------------------
1.3 cvs 664: SetupAndPrint sets printing parameters and starts the printing process
1.1 cvs 665: ----------------------------------------------------------------------*/
666: #ifdef __STDC__
1.38 cvs 667: void SetupAndPrint (Document doc, View view)
1.1 cvs 668: #else
1.38 cvs 669: void SetupAndPrint (doc, view)
670: Document doc;
1.1 cvs 671: View view;
672: #endif
673: {
1.10 cvs 674: # ifndef _WINDOWS
1.43 cvs 675: CHAR_T bufMenu[MAX_LENGTH];
1.3 cvs 676: int i;
1.27 cvs 677: # endif /* !_WINDOWS */
1.47 cvs 678: ThotBool textFile;
1.38 cvs 679:
680: textFile = (DocumentTypes[doc] == docText ||
681: DocumentTypes[doc] == docTextRO ||
682: DocumentTypes[doc] == docCSS ||
683: DocumentTypes[doc] == docCSSRO);
1.1 cvs 684:
685: /* Print form */
1.38 cvs 686: CheckPrintingDocument (doc);
1.40 cvs 687:
688: /* read the values that the user may have changed thru
689: the configuration menu */
690: TtaGetPrintCommand (pPrinter);
691: PageSize = TtaGetPrintParameter (PP_PaperSize);
1.27 cvs 692:
693: # ifndef _WINDOWS
1.38 cvs 694: TtaNewSheet (basePrint+NumFormPrint, TtaGetViewFrame (doc, view),
1.1 cvs 695: TtaGetMessage (LIB, TMSG_LIB_PRINT),
1.3 cvs 696: 1, TtaGetMessage (AMAYA, AM_BUTTON_PRINT), FALSE, 2, 'L', D_CANCEL);
1.1 cvs 697: i = 0;
698: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (LIB, TMSG_MANUAL_FEED));
1.36 cvs 699: i += ustrlen (&bufMenu[i]) + 1;
1.1 cvs 700: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_PRINT_TOC));
1.36 cvs 701: i += ustrlen (&bufMenu[i]) + 1;
1.1 cvs 702: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_NUMBERED_LINKS));
1.36 cvs 703: i += ustrlen (&bufMenu[i]) + 1;
1.34 cvs 704: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_PRINT_URL));
1.1 cvs 705: TtaNewToggleMenu (basePrint+NumMenuOptions, basePrint+NumFormPrint,
1.34 cvs 706: TtaGetMessage (LIB, TMSG_OPTIONS), 4, bufMenu, NULL, FALSE);
1.2 cvs 707: if (ManualFeed == PP_ON)
1.1 cvs 708: TtaSetToggleMenu (basePrint+NumMenuOptions, 0, TRUE);
709: if (withToC)
710: TtaSetToggleMenu (basePrint+NumMenuOptions, 1, TRUE);
711: if (numberLinks)
712: TtaSetToggleMenu (basePrint+NumMenuOptions, 2, TRUE);
1.34 cvs 713: if (printURL)
714: TtaSetToggleMenu (basePrint+NumMenuOptions, 3, TRUE);
1.1 cvs 715:
716: /* Paper format submenu */
717: i = 0;
718: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_A4));
1.36 cvs 719: i += ustrlen (&bufMenu[i]) + 1;
1.1 cvs 720: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_US));
721: TtaNewSubmenu (basePrint+NumMenuPaperFormat, basePrint+NumFormPrint, 0,
722: TtaGetMessage (LIB, TMSG_PAPER_SIZE), 2, bufMenu, NULL, FALSE);
1.2 cvs 723: if (PageSize == PP_US)
1.1 cvs 724: TtaSetMenuForm (basePrint+NumMenuPaperFormat, 1);
725: else
726: TtaSetMenuForm (basePrint+NumMenuPaperFormat, 0);
727:
728: /* Print to paper/ Print to file submenu */
729: i = 0;
730: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_PRINTER));
1.36 cvs 731: i += ustrlen (&bufMenu[i]) + 1;
1.1 cvs 732: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_PS_FILE));
733: TtaNewSubmenu (basePrint+NumMenuSupport, basePrint+NumFormPrint, 0,
734: TtaGetMessage (LIB, TMSG_OUTPUT), 2, bufMenu, NULL, TRUE);
735: /* text capture zone for the printer name */
736: TtaNewTextForm (basePrint+NumZonePrinterName, basePrint+NumFormPrint, NULL, 30, 1, FALSE);
737:
738: /* initialization of the PaperPrint selector */
1.2 cvs 739: if (PaperPrint == PP_PRINTER)
1.1 cvs 740: {
741: TtaSetMenuForm (basePrint+NumMenuSupport, 0);
742: TtaSetTextForm (basePrint+NumZonePrinterName, pPrinter);
743: }
744: else
745: {
746: TtaSetMenuForm (basePrint+NumMenuSupport, 1);
747: TtaSetTextForm (basePrint+NumZonePrinterName, PSdir);
748: }
749:
750: /* activates the Print form */
1.10 cvs 751: TtaShowDialogue (basePrint+NumFormPrint, FALSE);
752: # else /* _WINDOWS */
1.38 cvs 753: CreatePrintDlgWindow (TtaGetViewFrame (doc, view), PSdir, basePrint, NumMenuSupport, NumMenuOptions, NumMenuPaperFormat, NumZonePrinterName, NumFormPrint);
1.10 cvs 754: # endif /* _WINDOWS */
1.38 cvs 755: if (textFile)
756: {
757: /* invalid dialogue entries */
758: TtaRedrawMenuEntry (basePrint+NumMenuOptions, 1, NULL, -1, FALSE);
759: TtaRedrawMenuEntry (basePrint+NumMenuOptions, 2, NULL, -1, FALSE); }
1.1 cvs 760: }
761:
762: /*----------------------------------------------------------------------
763: SectionNumbering
764: Execute the "Section Numbering" command
765: ----------------------------------------------------------------------*/
766: #ifdef __STDC__
1.38 cvs 767: void SectionNumbering (Document doc, View view)
1.1 cvs 768: #else
1.38 cvs 769: void SectionNumbering (doc, view)
770: Document doc;
1.1 cvs 771: View view;
772: #endif
773: {
1.38 cvs 774: ChangeAttrOnRoot (doc, HTML_ATTR_SectionNumbering);
1.1 cvs 775: }
776:
777: /*----------------------------------------------------------------------
778: UpdateURLsInSubtree
779: Update NAMEs and URLs in subtree of el element, to take into account
780: the move from one document to another.
781: If a NAME attribute already exists in the new document, it is changed
782: to avoid duplicate names.
783: Transform the HREF and SRC attribute to make them independent from their
784: former base.
785: ----------------------------------------------------------------------*/
786: #ifdef __STDC__
787: static void UpdateURLsInSubtree (NotifyElement *event, Element el)
788: #else
789: static void UpdateURLsInSubtree (event, el)
790: NotifyElement *event;
791: Element el;
792: #endif
793: {
794: Element nextEl;
795:
796: event->element = el;
797: ElementPasted (event);
798: nextEl = TtaGetFirstChild (el);
799: while (nextEl != NULL)
800: {
801: UpdateURLsInSubtree (event, nextEl);
802: TtaNextSibling (&nextEl);
803: }
804: }
805:
806:
807: /*----------------------------------------------------------------------
808: MoveDocumentBody
809: Copy the elements contained in the BODY of document sourceDoc to the
810: position of element *el in document destDoc.
811: Delete the element containing *el and all its empty ancestors.
812: If deleteTree is TRUE, copied elements are deleted from the source
813: document.
814: ----------------------------------------------------------------------*/
815: #ifdef __STDC__
1.47 cvs 816: static void MoveDocumentBody (Element *el, Document destDoc, Document sourceDoc, STRING target, STRING url, ThotBool deleteTree)
1.1 cvs 817: #else
1.16 cvs 818: static void MoveDocumentBody (el, destDoc, sourceDoc, target, url, deleteTree)
1.12 cvs 819: Element *el;
820: Document destDoc;
821: Document sourceDoc;
1.36 cvs 822: STRING target;
823: STRING url;
1.47 cvs 824: ThotBool deleteTree;
1.1 cvs 825: #endif
826: {
1.14 cvs 827: Element root, ancestor, elem, firstInserted;
1.12 cvs 828: Element lastInserted, srce, copy, old, parent, sibling;
829: ElementType elType;
830: NotifyElement event;
831: int checkingMode;
1.47 cvs 832: ThotBool isID;
1.1 cvs 833:
1.13 cvs 834: if (target != NULL)
835: {
836: /* locate the target element within the source document */
837: root = SearchNAMEattribute (sourceDoc, target, NULL);
838: elType = TtaGetElementType (root);
839: isID = (elType.ElTypeNum != HTML_EL_Anchor
840: && elType.ElTypeNum != HTML_EL_MAP);
841: }
842: else
843: {
844: isID = FALSE;
845: /* get the BODY element of source document */
846: root = TtaGetMainRoot (sourceDoc);
847: elType = TtaGetElementType (root);
848: elType.ElTypeNum = HTML_EL_BODY;
849: root = TtaSearchTypedElement (elType, SearchForward, root);
850: }
851:
852: if (root != NULL)
1.12 cvs 853: {
854: /* don't check the abstract tree against the structure schema */
855: checkingMode = TtaGetStructureChecking (destDoc);
856: TtaSetStructureChecking (0, destDoc);
857: /* get elem, the ancestor of *el which is a child of a DIV or BODY
858: element in the destination document. The copied elements will be
859: inserted just before this element. */
860: elem = *el;
861: do
1.1 cvs 862: {
1.12 cvs 863: ancestor = TtaGetParent (elem);
864: if (ancestor != NULL)
865: {
866: elType = TtaGetElementType (ancestor);
867: if (elType.ElTypeNum == HTML_EL_BODY ||
868: elType.ElTypeNum == HTML_EL_Division)
869: ancestor = NULL;
870: else
871: elem = ancestor;
872: }
1.1 cvs 873: }
1.12 cvs 874: while (ancestor != NULL);
875: parent = TtaGetParent (elem);
1.14 cvs 876:
877: /* insert a DIV element */
1.15 cvs 878: elType.ElTypeNum = HTML_EL_Division;
1.16 cvs 879: lastInserted = TtaNewElement (destDoc, elType);
880: TtaInsertSibling (lastInserted, elem, TRUE, destDoc);
881: RegisterSubDoc (lastInserted, url);
1.42 cvs 882: CreateTargetAnchor (destDoc, lastInserted, FALSE);
1.14 cvs 883:
1.12 cvs 884: /* do copy */
1.16 cvs 885: firstInserted = NULL;
1.17 cvs 886: if (isID)
887: srce = root;
888: else
889: srce = TtaGetFirstChild (root);
1.12 cvs 890: while (srce != NULL)
1.1 cvs 891: {
1.12 cvs 892: copy = TtaCopyTree (srce, sourceDoc, destDoc, parent);
893: if (copy != NULL)
894: {
1.16 cvs 895: if (firstInserted == NULL)
1.12 cvs 896: /* this is the first copied element. Insert it before elem */
897: {
1.16 cvs 898: TtaInsertFirstChild (©, lastInserted, destDoc);
1.12 cvs 899: firstInserted = copy;
900: }
901: else
902: /* insert the new copied element after the element previously
903: copied */
904: TtaInsertSibling (copy, lastInserted, FALSE, destDoc);
905: lastInserted = copy;
906: /* update the NAMEs and URLs in the copied element */
907: event.document = destDoc;
908: event.position = sourceDoc;
909: UpdateURLsInSubtree(&event, copy);
910: }
911: /* get the next element in the source document */
912: old = srce;
913: TtaNextSibling (&srce);
914: if (deleteTree)
915: TtaDeleteTree (old, sourceDoc);
1.13 cvs 916: /* Stop here if the target points to a specific element with an ID */
917: if (isID)
918: srce = NULL;
1.1 cvs 919: }
1.12 cvs 920:
921: /* delete the element(s) containing the link to the copied document */
922: /* delete the parent element of *el and all empty ancestors */
923: elem = TtaGetParent (*el);
924: do
1.1 cvs 925: {
1.12 cvs 926: sibling = elem;
927: TtaNextSibling (&sibling);
928: if (sibling == NULL)
929: {
930: sibling = elem;
931: TtaPreviousSibling (&sibling);
932: if (sibling == NULL)
933: elem = TtaGetParent (elem);
934: }
1.1 cvs 935: }
1.12 cvs 936: while (sibling == NULL);
937: TtaDeleteTree (elem, destDoc);
938: /* restore previous chacking mode */
1.47 cvs 939: TtaSetStructureChecking ((ThotBool)checkingMode, destDoc);
1.12 cvs 940: /* return the address of the first copied element */
941: *el = firstInserted;
942: }
1.1 cvs 943: }
944:
1.29 cvs 945:
946: #ifdef __STDC__
947: void GetIncludedDocuments_callback (int newdoc, int status,
1.36 cvs 948: STRING urlName,
949: STRING outputfile,
950: STRING content_type,
1.29 cvs 951: void * context)
952: #else /* __STDC__ */
953: void GetIncludedDocuments_callback (newdoc, status, urlName,
954: outputfile, content_type,
955: context)
956: int newdoc;
957: int status;
1.36 cvs 958: STRING urlName;
959: STRING outputfile;
960: STRING content_type;
1.29 cvs 961: void *context;
962: #endif /* __STDC__ */
963: {
964: Element link, next;
965: Attribute RelAttr, HrefAttr;
1.36 cvs 966: STRING url, ptr, text;
1.29 cvs 967: Document document;
968: GetIncludedDocuments_context *ctx;
969:
970: /* restore GetIncludedDocuments's context */
971: ctx = (GetIncludedDocuments_context *) context;
972:
973: if (!ctx)
974: return;
975:
976: RelAttr = ctx->RelAttr;
977: link = ctx->link;
978: HrefAttr = ctx->HrefAttr;
979: url = ctx->url;
980: ptr = ctx->ptr;
981: document = ctx->document;
982: next = ctx->next;
983: text = ctx->text;
984:
985: TtaFreeMemory (ctx);
986:
987: if (RelAttr != NULL && link != NULL)
988: {
989: if (HrefAttr != NULL)
990: {
991: if (url != NULL)
992: {
993: if (newdoc != 0 && newdoc != document)
994: {
995: /* it's not the document itself */
996: /* copy the target document at the position of the link */
997: MoveDocumentBody (&next, document, newdoc, ptr, url,
1.47 cvs 998: (ThotBool)(newdoc == IncludedDocument));
1.29 cvs 999: }
1000: /* global variables */
1001: FreeDocumentResource (IncludedDocument);
1002: TtaCloseDocument (IncludedDocument);
1003: IncludedDocument = 0;
1004: }
1005: TtaFreeMemory (text);
1006: }
1007: }
1008:
1009: if (next != NULL && DocBook == document)
1010: {
1011: SetStopButton (document);
1012: GetIncludedDocuments (next, document);
1013: }
1014: else
1015: MakeBook_callback (document);
1016: }
1017:
1.1 cvs 1018: /*----------------------------------------------------------------------
1019: GetIncludedDocuments
1020: Look forward, starting from element el, for a link (A) with attribute
1.5 cvs 1021: REL="chapter" or REL="subdocument" and replace that link by the contents
1022: of the target document.
1.1 cvs 1023: ----------------------------------------------------------------------*/
1024: #ifdef __STDC__
1.29 cvs 1025: static void GetIncludedDocuments (Element el, Document document)
1.1 cvs 1026: #else
1.29 cvs 1027: static void GetIncludedDocuments (el, document)
1.1 cvs 1028: Element el;
1029: Document document;
1030: #endif
1031: {
1.29 cvs 1032: Element link, next;
1033: Attribute RelAttr, HrefAttr = NULL;
1034: AttributeType attrType;
1035: int length;
1.36 cvs 1036: STRING text, ptr, url = NULL;
1.29 cvs 1037: Document newdoc;
1.47 cvs 1038: ThotBool call_callback = FALSE;
1.29 cvs 1039: GetIncludedDocuments_context *ctx = NULL;
1040:
1041: link = el;
1042: RelAttr = NULL;
1043: next = NULL;
1044:
1045: ctx = TtaGetMemory (sizeof (GetIncludedDocuments_context));
1046: memset (ctx, 0, sizeof (GetIncludedDocuments_context));
1047:
1048: attrType.AttrSSchema = TtaGetDocumentSSchema (document);
1049: attrType.AttrTypeNum = HTML_ATTR_REL;
1050:
1051:
1052: /* looks for an anchor having an attribute REL="chapter" or
1053: REL="subdocument" */
1054: while (link != NULL && RelAttr == NULL)
1055: {
1056: TtaSearchAttribute (attrType, SearchForward, link, &link, &RelAttr);
1057: if (link != NULL && RelAttr != NULL)
1058: {
1059: length = TtaGetTextAttributeLength (RelAttr);
1.49 cvs 1060: text = TtaAllocString (length + 1);
1.29 cvs 1061: TtaGiveTextAttributeValue (RelAttr, text, &length);
1.49 cvs 1062: if (ustrcasecmp (text, TEXT("chapter")) && ustrcasecmp (text, TEXT("subdocument")))
1.29 cvs 1063: RelAttr = NULL;
1064: TtaFreeMemory (text);
1065: }
1066: }
1067:
1068: ctx->RelAttr = RelAttr;
1069: ctx->link = link;
1070: ctx->document = document;
1071: ctx->HrefAttr = HrefAttr;
1.1 cvs 1072:
1.29 cvs 1073: if (RelAttr != NULL && link != NULL)
1074: /* a link with attribute REL="Chapter" has been found */
1075: {
1076: next = link;
1077: ctx->next =next;
1078: attrType.AttrTypeNum = HTML_ATTR_HREF_;
1079: HrefAttr = TtaGetAttribute (link, attrType);
1080: if (HrefAttr != NULL)
1.1 cvs 1081: /* this link has an attribute HREF */
1082: {
1083: length = TtaGetTextAttributeLength (HrefAttr);
1.49 cvs 1084: text = TtaAllocString (length + 1);
1.1 cvs 1085: TtaGiveTextAttributeValue (HrefAttr, text, &length);
1.36 cvs 1086: ptr = ustrrchr (text, '#');
1.12 cvs 1087: url = text;
1088: if (ptr != NULL)
1089: {
1090: if (ptr == text)
1091: url = NULL;
1.16 cvs 1092: /* link to a particular position within a remote document */
1.12 cvs 1093: ptr[0] = EOS;
1094: ptr = &ptr[1];
1095: }
1.29 cvs 1096:
1097: ctx->url = url;
1098: ctx->ptr = ptr;
1099: ctx->text = text;
1100: ctx->HrefAttr = HrefAttr;
1.12 cvs 1101:
1102: if (url != NULL)
1.29 cvs 1103: /* this link designates an external document */
1.1 cvs 1104: {
1105: /* create a new document and loads the target document */
1.49 cvs 1106: IncludedDocument = TtaNewDocument (TEXT("HTML"), TEXT("tmp"));
1.30 cvs 1107: if (IncludedDocument != 0)
1108: {
1109: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_FETCHING), url);
1110: newdoc = GetHTMLDocument (url, NULL, IncludedDocument,
1.29 cvs 1111: document, CE_MAKEBOOK, FALSE,
1112: (void *) GetIncludedDocuments_callback,
1113: (void *) ctx);
1.30 cvs 1114: }
1.1 cvs 1115: }
1.29 cvs 1116: else
1117: call_callback = TRUE;
1118: }
1119: else
1120: call_callback = TRUE;
1121: }
1122: else
1123: call_callback = TRUE;
1124:
1125: if (call_callback)
1126: GetIncludedDocuments_callback (document, -1, url, NULL, NULL,
1127: (void *) ctx);
1.1 cvs 1128: }
1129:
1130:
1131: /*----------------------------------------------------------------------
1.29 cvs 1132: MakeBook_callback
1133: ----------------------------------------------------------------------*/
1134: #ifdef __STDC__
1135: void MakeBook_callback (Document document)
1136: #else
1137: void MakeBook_callback (Document document)
1138: #endif /* __STDC__ */
1139:
1140: {
1141: ResetStop (document);
1142: /* update internal links */
1143: SetInternalLinks (document);
1144: /* remove registered sub-documents */
1145: FreeSubDocTable ();
1146: DocBook = 0;
1.39 cvs 1147: SetBrowserEditor (document);
1.29 cvs 1148: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), NULL);
1149: }
1150:
1151: /*----------------------------------------------------------------------
1.1 cvs 1152: MakeBook
1153: Replace all links in a document which have an attribute REL="chapter"
1.5 cvs 1154: or REL="subdocument" by the corresponding target document.
1.1 cvs 1155: ----------------------------------------------------------------------*/
1156: #ifdef __STDC__
1157: void MakeBook (Document document, View view)
1158: #else
1159: void MakeBook (document, view)
1160: Document document;
1161: View view;
1162: #endif
1163: {
1164: Element root, body, el;
1165: ElementType elType;
1166:
1.24 cvs 1167: /* stops all current transfers on this document */
1.25 cvs 1168: StopTransfer (document, 1);
1169: /* simulate a transfert in the main document */
1170: ActiveMakeBook (document);
1.1 cvs 1171: root = TtaGetMainRoot (document);
1172: elType = TtaGetElementType (root);
1173: elType.ElTypeNum = HTML_EL_BODY;
1174: body = TtaSearchTypedElement (elType, SearchForward, root);
1175: TtaSetDocumentModified (document);
1176: el = body;
1.29 cvs 1177:
1178: if (el != NULL && DocBook == document)
1179: GetIncludedDocuments (el, document);
1180: else
1181: MakeBook_callback (document);
1.1 cvs 1182: }
1.29 cvs 1183:
1184:
1185:
1186:
1187:
1188:
1189:
1190:
1191:
1192:
Webmaster