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