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