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