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