Return to HTMLbook.c CVS log | Up to [Public] / Amaya / amaya |
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: */ 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; 52: static int ManualFeed; 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: /*---------------------------------------------------------------------- 411: PrintAs prints the document using predefined parameters. 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 || 428: DocumentTypes[doc] == docTextRO || 429: DocumentTypes[doc] == docCSS || 430: DocumentTypes[doc] == docCSSRO); 431: 432: CheckPrintingDocument (doc); 1.49 cvs 433: ustrcpy (viewsToPrint, TEXT("Formatted_view ")); 1.53 cvs 434: if (!textFile && WithToC) 1.49 cvs 435: ustrcat (viewsToPrint, TEXT("Table_of_contents ")); 1.71 ! cvs 436: ! 437: if (textFile) ! 438: { ! 439: if (PageSize == PP_A4) ! 440: { ! 441: if (Orientation == PP_Landscape) ! 442: TtaSetPrintSchema (TEXT("TextFilePL")); ! 443: else ! 444: TtaSetPrintSchema (TEXT("TextFilePP")); ! 445: } ! 446: else ! 447: { ! 448: if (Orientation == PP_Landscape) ! 449: TtaSetPrintSchema (TEXT("TextFileUSL")); ! 450: else ! 451: TtaSetPrintSchema (TEXT("TextFilePPUS")); ! 452: } ! 453: } ! 454: else if (NumberLinks) 1.8 cvs 455: /* display numbered links */ 1.3 cvs 456: { 1.8 cvs 457: /* associate an attribute InternalLink with all anchors refering 458: a target in the same document. This allows P schemas to work 459: properly */ 1.53 cvs 460: SetInternalLinks (DocPrint); 1.3 cvs 461: if (PageSize == PP_A4) 1.71 ! cvs 462: { ! 463: if (Orientation == PP_Landscape) ! 464: TtaSetPrintSchema (TEXT("HTMLPLL")); ! 465: else ! 466: TtaSetPrintSchema (TEXT("HTMLPLP")); ! 467: } 1.3 cvs 468: else 1.71 ! cvs 469: { ! 470: if (Orientation == PP_Landscape) ! 471: TtaSetPrintSchema (TEXT("HTMLUSLL")); ! 472: else ! 473: TtaSetPrintSchema (TEXT("HTMLPLPUS")); ! 474: } 1.49 cvs 475: ustrcat (viewsToPrint, TEXT("Links_view ")); 1.32 cvs 476: } 1.71 ! cvs 477: else if (PageSize == PP_A4) 1.32 cvs 478: { 1.71 ! cvs 479: if (Orientation == PP_Landscape) ! 480: TtaSetPrintSchema (TEXT("HTMLPL")); 1.38 cvs 481: else 1.61 cvs 482: TtaSetPrintSchema (TEXT("HTMLPP")); 1.71 ! cvs 483: } ! 484: else ! 485: { ! 486: if (Orientation == PP_Landscape) ! 487: TtaSetPrintSchema (TEXT("HTMLUSL")); 1.38 cvs 488: else 1.61 cvs 489: TtaSetPrintSchema (TEXT("HTMLPPUS")); 1.71 ! cvs 490: } ! 491: 1.34 cvs 492: /* post or remove the PrintURL attribute */ 1.38 cvs 493: el = TtaGetMainRoot (doc); 494: status = TtaIsDocumentModified (doc); 495: attrType.AttrSSchema = TtaGetDocumentSSchema (doc); 496: if (textFile) 497: attrType.AttrTypeNum = TextFile_ATTR_PrintURL; 498: else 499: attrType.AttrTypeNum = HTML_ATTR_PrintURL; 1.34 cvs 500: attr = TtaGetAttribute (el, attrType); 1.53 cvs 501: if (attr == 0 && PrintURL) 1.34 cvs 502: { 503: attr = TtaNewAttribute (attrType); 1.38 cvs 504: TtaAttachAttribute (el, attr, doc); 1.34 cvs 505: } 1.50 cvs 506: 1.53 cvs 507: if (attr != 0 && !PrintURL) 1.38 cvs 508: TtaRemoveAttribute (el, attr, doc); 1.50 cvs 509: /* get the path dir where css files have to be stored */ 1.53 cvs 510: if (textFile || IgnoreCSS) 1.50 cvs 511: files = NULL; 512: else 513: { 514: TtaGetPrintNames (&files, &dir); 515: /* store css files and get the list of names */ 516: files = CssToPrint (doc, dir); 517: } 1.53 cvs 518: TtaPrint (DocPrint, viewsToPrint, files); 1.50 cvs 519: TtaFreeMemory (files); 1.34 cvs 520: if (!status) 1.38 cvs 521: TtaSetDocumentUnmodified (doc); 1.1 cvs 522: } 523: 1.45 cvs 524: /*---------------------------------------------------------------------- 525: PrintAs prints the document using predefined parameters. 526: ----------------------------------------------------------------------*/ 527: #ifdef __STDC__ 528: void PrintAs (Document doc, View view) 529: #else /* __STDC__ */ 530: void PrintAs (doc, view) 531: Document doc; 532: #endif /* __STDC__ */ 533: { 534: #ifdef _WINDOWS 535: SetupAndPrint (doc, view); 536: #else /* _WINDOWS */ 537: PrintDocument (doc, view); 538: #endif /* _WINDOWS */ 539: } 1.1 cvs 540: 541: /*---------------------------------------------------------------------- 542: CallbackImage manage returns of Picture form. 543: ----------------------------------------------------------------------*/ 544: #ifdef __STDC__ 1.36 cvs 545: void CallbackPrint (int ref, int typedata, STRING data) 1.1 cvs 546: #else /* __STDC__ */ 547: void CallbackPrint (ref, typedata, data) 548: int ref; 549: int typedata; 1.36 cvs 550: STRING data; 1.1 cvs 551: #endif /* __STDC__ */ 552: { 553: int val; 554: 555: val = (int) data; 1.53 cvs 556: switch (ref - BasePrint) 1.1 cvs 557: { 1.69 cvs 558: case FormPrint: 559: TtaDestroyDialogue (BasePrint + FormPrint); 1.1 cvs 560: switch (val) 561: { 562: case 1: 563: /* confirms the paper print option */ 564: /* the other options are not taken into account without this 565: confirmation */ 1.2 cvs 566: TtaSetPrintParameter (PP_Destination, PaperPrint); 567: TtaSetPrintParameter (PP_ManualFeed, ManualFeed); 1.71 ! cvs 568: TtaSetPrintParameter (PP_PagesPerSheet, PagePerSheet); ! 569: TtaSetPrintParameter (PP_Orientation, Orientation); 1.2 cvs 570: TtaSetPrintParameter (PP_PaperSize, PageSize); 1.53 cvs 571: TtaSetPrintCommand (PPrinter); 1.2 cvs 572: TtaSetPsFile (PSdir); 1.40 cvs 573: /* update the environment variable */ 1.53 cvs 574: TtaSetEnvString ("THOTPRINT", PPrinter, TRUE); 1.57 cvs 575: TtaSetEnvInt ("PAPERSIZE", PageSize, TRUE); 1.53 cvs 576: PrintDocument (DocPrint, 1); 1.1 cvs 577: break; 1.2 cvs 578: case 0: 1.40 cvs 579: PaperPrint = (TtaGetPrintParameter (PP_Destination)) ? PP_PRINTER : PP_PS; 1.2 cvs 580: ManualFeed = TtaGetPrintParameter (PP_ManualFeed); 581: PageSize = TtaGetPrintParameter (PP_PaperSize); 1.53 cvs 582: TtaGetPrintCommand (PPrinter); 1.2 cvs 583: TtaGetPsFile (PSdir); 584: break; 1.1 cvs 585: default: 586: break; 587: } 588: break; 1.69 cvs 589: case PrintOptions: 1.1 cvs 590: switch (val) 591: { 592: case 0: 593: /* Manual feed option */ 1.2 cvs 594: if (ManualFeed == PP_ON) 595: ManualFeed = PP_OFF; 596: else 597: ManualFeed = PP_ON; 1.1 cvs 598: break; 599: case 1: 600: /* Toc option */ 1.53 cvs 601: WithToC = !WithToC; 1.1 cvs 602: break; 603: case 2: 1.53 cvs 604: /* NumberLinks option */ 605: NumberLinks = !NumberLinks; 1.34 cvs 606: case 3: 607: /* URL option */ 1.53 cvs 608: PrintURL = !PrintURL; 609: break; 610: case 4: 611: /* CSS option */ 612: IgnoreCSS = !IgnoreCSS; 1.1 cvs 613: break; 614: } 615: break; 1.69 cvs 616: case PaperFormat: 1.1 cvs 617: /* page size submenu */ 618: switch (val) 619: { 620: case 0: 1.2 cvs 621: PageSize = PP_A4; 1.1 cvs 622: break; 623: case 1: 1.2 cvs 624: PageSize = PP_US; 1.1 cvs 625: break; 626: } 627: break; 1.71 ! cvs 628: case PaperOrientation: ! 629: /* orientation submenu */ ! 630: Orientation = val; ! 631: break; ! 632: case PPagesPerSheet: ! 633: /* pages per sheet submenu */ ! 634: switch (val) ! 635: { ! 636: case 0: ! 637: PagePerSheet = 1; ! 638: break; ! 639: case 1: ! 640: PagePerSheet = 2; ! 641: break; ! 642: case 2: ! 643: PagePerSheet = 4; ! 644: break; ! 645: } ! 646: break; 1.69 cvs 647: case PrintSupport: 1.1 cvs 648: /* paper print/save PostScript submenu */ 649: switch (val) 650: { 651: case 0: 1.2 cvs 652: if (PaperPrint == PP_PS) 1.1 cvs 653: { 1.2 cvs 654: PaperPrint = PP_PRINTER; 1.69 cvs 655: #ifndef _WINDOWS 656: TtaSetTextForm (BasePrint + PPrinterName, PPrinter); 657: #endif /* !_WINDOWS */ 1.1 cvs 658: } 659: break; 660: case 1: 1.2 cvs 661: if (PaperPrint == PP_PRINTER) 1.1 cvs 662: { 1.2 cvs 663: PaperPrint = PP_PS; 1.54 cvs 664: # ifndef _WINDOWS 1.69 cvs 665: TtaSetTextForm (BasePrint + PPrinterName, PSdir); 1.54 cvs 666: # endif /* !_WINDOWS */ 1.1 cvs 667: } 668: break; 669: } 670: break; 1.69 cvs 671: case PPrinterName: 1.1 cvs 672: if (data[0] != '\0') 1.2 cvs 673: if (PaperPrint == PP_PRINTER) 1.40 cvs 674: /* text capture zone for the printer name */ 1.53 cvs 675: ustrncpy (PPrinter, data, MAX_PATH); 1.1 cvs 676: else 677: /* text capture zone for the name of the PostScript file */ 1.36 cvs 678: ustrncpy (PSdir, data, MAX_PATH); 1.1 cvs 679: break; 680: } 681: } 682: 683: /*---------------------------------------------------------------------- 684: ----------------------------------------------------------------------*/ 685: #ifdef __STDC__ 686: void InitPrint (void) 687: #else /* __STDC__ */ 688: void InitPrint () 689: #endif /* __STDC__ */ 690: { 1.62 cvs 691: CHAR_T* ptr; 1.1 cvs 692: 1.53 cvs 693: BasePrint = TtaSetCallback (CallbackPrint, PRINT_MAX_REF); 694: DocPrint = 0; 1.1 cvs 695: 696: /* init printer variables */ 697: /* read default printer variable */ 1.52 cvs 698: ptr = TtaGetEnvString ("THOTPRINT"); 1.1 cvs 699: if (ptr == NULL) 1.62 cvs 700: ustrcpy (PPrinter, TEXT("")); 1.1 cvs 701: else 1.62 cvs 702: ustrcpy (PPrinter, ptr); 1.57 cvs 703: TtaGetEnvInt ("PAPERSIZE", &PageSize); 1.2 cvs 704: PaperPrint = PP_PRINTER; 1.53 cvs 705: PrintURL = TRUE; 1.55 cvs 706: IgnoreCSS = FALSE; 1.2 cvs 707: TtaSetPrintParameter (PP_Destination, PaperPrint); 708: TtaSetPrintParameter (PP_PaperSize, PageSize); 1.53 cvs 709: TtaSetPrintCommand (PPrinter); 1.1 cvs 710: } 711: 712: /*---------------------------------------------------------------------- 1.3 cvs 713: SetupAndPrint sets printing parameters and starts the printing process 1.1 cvs 714: ----------------------------------------------------------------------*/ 715: #ifdef __STDC__ 1.38 cvs 716: void SetupAndPrint (Document doc, View view) 1.1 cvs 717: #else 1.38 cvs 718: void SetupAndPrint (doc, view) 719: Document doc; 1.1 cvs 720: View view; 721: #endif 722: { 1.70 cvs 723: #ifndef _WINDOWS 724: CHAR_T bufMenu[MAX_LENGTH]; 1.3 cvs 725: int i; 1.70 cvs 726: #endif /* !_WINDOWS */ 1.47 cvs 727: ThotBool textFile; 1.38 cvs 728: 729: textFile = (DocumentTypes[doc] == docText || 730: DocumentTypes[doc] == docTextRO || 731: DocumentTypes[doc] == docCSS || 732: DocumentTypes[doc] == docCSSRO); 1.1 cvs 733: 734: /* Print form */ 1.38 cvs 735: CheckPrintingDocument (doc); 1.40 cvs 736: 737: /* read the values that the user may have changed thru 738: the configuration menu */ 1.53 cvs 739: TtaGetPrintCommand (PPrinter); 1.40 cvs 740: PageSize = TtaGetPrintParameter (PP_PaperSize); 1.27 cvs 741: 1.70 cvs 742: #ifndef _WINDOWS 1.69 cvs 743: TtaNewSheet (BasePrint + FormPrint, TtaGetViewFrame (doc, view), 1.1 cvs 744: TtaGetMessage (LIB, TMSG_LIB_PRINT), 1.71 ! cvs 745: 1, TtaGetMessage (AMAYA, AM_BUTTON_PRINT), FALSE, 3, 'L', D_CANCEL); 1.1 cvs 746: 747: /* Paper format submenu */ 748: i = 0; 749: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_A4)); 1.36 cvs 750: i += ustrlen (&bufMenu[i]) + 1; 1.1 cvs 751: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_US)); 1.69 cvs 752: TtaNewSubmenu (BasePrint + PaperFormat, BasePrint + FormPrint, 0, 1.1 cvs 753: TtaGetMessage (LIB, TMSG_PAPER_SIZE), 2, bufMenu, NULL, FALSE); 1.2 cvs 754: if (PageSize == PP_US) 1.69 cvs 755: TtaSetMenuForm (BasePrint + PaperFormat, 1); 1.1 cvs 756: else 1.69 cvs 757: TtaSetMenuForm (BasePrint + PaperFormat, 0); 1.1 cvs 758: 1.71 ! cvs 759: /* Orientation submenu */ ! 760: i = 0; ! 761: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (AMAYA, AM_PORTRAIT)); ! 762: i += ustrlen (&bufMenu[i]) + 1; ! 763: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (AMAYA, AM_LANDSCAPE)); ! 764: TtaNewSubmenu (BasePrint + PaperOrientation, BasePrint + FormPrint, 0, ! 765: TtaGetMessage (AMAYA, AM_ORIENTATION), 2, bufMenu, NULL, TRUE); ! 766: if (Orientation == PP_Landscape) ! 767: TtaSetMenuForm (BasePrint + PaperOrientation, 1); ! 768: else ! 769: TtaSetMenuForm (BasePrint + PaperOrientation, 0); ! 770: ! 771: ! 772: /* Pages per sheet submenu */ ! 773: i = 0; ! 774: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_1_PAGE_SHEET)); ! 775: i += ustrlen (&bufMenu[i]) + 1; ! 776: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_2_PAGE_SHEET)); ! 777: i += ustrlen (&bufMenu[i]) + 1; ! 778: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_4_PAGE_SHEET)); ! 779: TtaNewSubmenu (BasePrint + PPagesPerSheet, BasePrint + FormPrint, 0, ! 780: TtaGetMessage (LIB, TMSG_REDUCTION), 3, bufMenu, NULL, TRUE); ! 781: if (PagePerSheet == 1) ! 782: TtaSetMenuForm (BasePrint + PPagesPerSheet, 0); ! 783: else if (PagePerSheet == 2) ! 784: TtaSetMenuForm (BasePrint + PPagesPerSheet, 1); ! 785: else ! 786: TtaSetMenuForm (BasePrint + PPagesPerSheet, 2); ! 787: 1.1 cvs 788: /* Print to paper/ Print to file submenu */ 789: i = 0; 790: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_PRINTER)); 1.36 cvs 791: i += ustrlen (&bufMenu[i]) + 1; 1.1 cvs 792: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_PS_FILE)); 1.69 cvs 793: TtaNewSubmenu (BasePrint + PrintSupport, BasePrint + FormPrint, 0, 1.1 cvs 794: TtaGetMessage (LIB, TMSG_OUTPUT), 2, bufMenu, NULL, TRUE); 1.71 ! cvs 795: ! 796: /* PaperPrint selector */ 1.69 cvs 797: TtaNewTextForm (BasePrint + PPrinterName, BasePrint + FormPrint, NULL, 30, 1, FALSE); 1.2 cvs 798: if (PaperPrint == PP_PRINTER) 1.1 cvs 799: { 1.69 cvs 800: TtaSetMenuForm (BasePrint + PrintSupport, 0); 801: TtaSetTextForm (BasePrint + PPrinterName, PPrinter); 1.1 cvs 802: } 803: else 804: { 1.69 cvs 805: TtaSetMenuForm (BasePrint + PrintSupport, 1); 806: TtaSetTextForm (BasePrint + PPrinterName, PSdir); 1.1 cvs 807: } 808: 1.71 ! cvs 809: /* The toggle */ ! 810: i = 0; ! 811: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (LIB, TMSG_MANUAL_FEED)); ! 812: i += ustrlen (&bufMenu[i]) + 1; ! 813: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_PRINT_TOC)); ! 814: i += ustrlen (&bufMenu[i]) + 1; ! 815: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_NUMBERED_LINKS)); ! 816: i += ustrlen (&bufMenu[i]) + 1; ! 817: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_PRINT_URL)); ! 818: i += ustrlen (&bufMenu[i]) + 1; ! 819: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_WITH_CSS)); ! 820: TtaNewToggleMenu (BasePrint + PrintOptions, BasePrint + FormPrint, ! 821: TtaGetMessage (LIB, TMSG_OPTIONS), 5, bufMenu, NULL, FALSE); ! 822: if (ManualFeed == PP_ON) ! 823: TtaSetToggleMenu (BasePrint + PrintOptions, 0, TRUE); ! 824: else ! 825: TtaSetToggleMenu (BasePrint + PrintOptions, 0, FALSE); ! 826: TtaSetToggleMenu (BasePrint + PrintOptions, 1, WithToC); ! 827: TtaSetToggleMenu (BasePrint + PrintOptions, 2, NumberLinks); ! 828: TtaSetToggleMenu (BasePrint + PrintOptions, 3, PrintURL); ! 829: TtaSetToggleMenu (BasePrint + PrintOptions, 4, IgnoreCSS); ! 830: 1.1 cvs 831: /* activates the Print form */ 1.69 cvs 832: TtaShowDialogue (BasePrint+FormPrint, FALSE); 1.71 ! cvs 833: if (textFile) ! 834: { ! 835: /* invalid dialogue entries */ ! 836: TtaRedrawMenuEntry (BasePrint + PrintOptions, 1, NULL, -1, FALSE); ! 837: TtaRedrawMenuEntry (BasePrint + PrintOptions, 2, NULL, -1, FALSE); ! 838: } 1.70 cvs 839: #else /* _WINDOWS */ 1.69 cvs 840: CreatePrintDlgWindow (TtaGetViewFrame (doc, view), PSdir); 1.70 cvs 841: #endif /* _WINDOWS */ 1.1 cvs 842: } 843: 844: /*---------------------------------------------------------------------- 845: SectionNumbering 846: Execute the "Section Numbering" command 847: ----------------------------------------------------------------------*/ 848: #ifdef __STDC__ 1.38 cvs 849: void SectionNumbering (Document doc, View view) 1.1 cvs 850: #else 1.38 cvs 851: void SectionNumbering (doc, view) 852: Document doc; 1.1 cvs 853: View view; 854: #endif 855: { 1.38 cvs 856: ChangeAttrOnRoot (doc, HTML_ATTR_SectionNumbering); 1.1 cvs 857: } 858: 859: /*---------------------------------------------------------------------- 860: UpdateURLsInSubtree 861: Update NAMEs and URLs in subtree of el element, to take into account 862: the move from one document to another. 863: If a NAME attribute already exists in the new document, it is changed 864: to avoid duplicate names. 865: Transform the HREF and SRC attribute to make them independent from their 866: former base. 867: ----------------------------------------------------------------------*/ 868: #ifdef __STDC__ 869: static void UpdateURLsInSubtree (NotifyElement *event, Element el) 870: #else 871: static void UpdateURLsInSubtree (event, el) 872: NotifyElement *event; 873: Element el; 874: #endif 875: { 876: Element nextEl; 877: 878: nextEl = TtaGetFirstChild (el); 879: while (nextEl != NULL) 880: { 1.58 cvs 881: event->element = nextEl; 882: ElementPasted (event); 1.1 cvs 883: TtaNextSibling (&nextEl); 884: } 885: } 886: 887: 888: /*---------------------------------------------------------------------- 889: MoveDocumentBody 1.58 cvs 890: Copy the elements contained in the BODY of the document sourceDoc at the 891: position of the element el in the document destDoc. 892: Delete the element containing el and all its empty ancestors. 1.1 cvs 893: If deleteTree is TRUE, copied elements are deleted from the source 894: document. 1.58 cvs 895: Return the root element that delimits the new inserted part (a div). 1.1 cvs 896: ----------------------------------------------------------------------*/ 897: #ifdef __STDC__ 1.58 cvs 898: static Element MoveDocumentBody (Element el, Document destDoc, Document sourceDoc, STRING target, STRING url, ThotBool deleteTree) 1.1 cvs 899: #else 1.58 cvs 900: static Element MoveDocumentBody (el, destDoc, sourceDoc, target, url, deleteTree) 901: Element el; 1.12 cvs 902: Document destDoc; 903: Document sourceDoc; 1.36 cvs 904: STRING target; 905: STRING url; 1.47 cvs 906: ThotBool deleteTree; 1.1 cvs 907: #endif 908: { 1.58 cvs 909: Element root, ancestor, elem, firstInserted, div; 1.12 cvs 910: Element lastInserted, srce, copy, old, parent, sibling; 911: ElementType elType; 912: NotifyElement event; 913: int checkingMode; 1.47 cvs 914: ThotBool isID; 1.1 cvs 915: 1.67 cvs 916: div = NULL; 1.13 cvs 917: if (target != NULL) 918: { 919: /* locate the target element within the source document */ 920: root = SearchNAMEattribute (sourceDoc, target, NULL); 921: elType = TtaGetElementType (root); 1.58 cvs 922: isID = (elType.ElTypeNum != HTML_EL_Anchor && elType.ElTypeNum != HTML_EL_MAP); 1.13 cvs 923: } 924: else 925: { 926: isID = FALSE; 927: /* get the BODY element of source document */ 928: root = TtaGetMainRoot (sourceDoc); 929: elType = TtaGetElementType (root); 930: elType.ElTypeNum = HTML_EL_BODY; 931: root = TtaSearchTypedElement (elType, SearchForward, root); 932: } 933: 934: if (root != NULL) 1.12 cvs 935: { 936: /* don't check the abstract tree against the structure schema */ 937: checkingMode = TtaGetStructureChecking (destDoc); 938: TtaSetStructureChecking (0, destDoc); 1.58 cvs 939: /* get elem, the ancestor of el which is a child of a DIV or BODY 1.12 cvs 940: element in the destination document. The copied elements will be 941: inserted just before this element. */ 1.58 cvs 942: elem = el; 1.12 cvs 943: do 1.1 cvs 944: { 1.12 cvs 945: ancestor = TtaGetParent (elem); 946: if (ancestor != NULL) 947: { 948: elType = TtaGetElementType (ancestor); 949: if (elType.ElTypeNum == HTML_EL_BODY || 950: elType.ElTypeNum == HTML_EL_Division) 951: ancestor = NULL; 952: else 953: elem = ancestor; 954: } 1.1 cvs 955: } 1.12 cvs 956: while (ancestor != NULL); 957: parent = TtaGetParent (elem); 1.14 cvs 958: 959: /* insert a DIV element */ 1.15 cvs 960: elType.ElTypeNum = HTML_EL_Division; 1.16 cvs 961: lastInserted = TtaNewElement (destDoc, elType); 962: TtaInsertSibling (lastInserted, elem, TRUE, destDoc); 1.58 cvs 963: /* this delimits the new inserted part of the document */ 1.16 cvs 964: RegisterSubDoc (lastInserted, url); 1.42 cvs 965: CreateTargetAnchor (destDoc, lastInserted, FALSE); 1.58 cvs 966: div = lastInserted; 1.14 cvs 967: 1.12 cvs 968: /* do copy */ 1.16 cvs 969: firstInserted = NULL; 1.17 cvs 970: if (isID) 971: srce = root; 972: else 973: srce = TtaGetFirstChild (root); 1.12 cvs 974: while (srce != NULL) 1.1 cvs 975: { 1.12 cvs 976: copy = TtaCopyTree (srce, sourceDoc, destDoc, parent); 977: if (copy != NULL) 978: { 1.16 cvs 979: if (firstInserted == NULL) 1.12 cvs 980: /* this is the first copied element. Insert it before elem */ 981: { 1.16 cvs 982: TtaInsertFirstChild (©, lastInserted, destDoc); 1.12 cvs 983: firstInserted = copy; 984: } 985: else 986: /* insert the new copied element after the element previously 987: copied */ 988: TtaInsertSibling (copy, lastInserted, FALSE, destDoc); 989: lastInserted = copy; 990: /* update the NAMEs and URLs in the copied element */ 991: event.document = destDoc; 992: event.position = sourceDoc; 993: UpdateURLsInSubtree(&event, copy); 994: } 995: /* get the next element in the source document */ 996: old = srce; 997: TtaNextSibling (&srce); 998: if (deleteTree) 999: TtaDeleteTree (old, sourceDoc); 1.13 cvs 1000: /* Stop here if the target points to a specific element with an ID */ 1001: if (isID) 1002: srce = NULL; 1.1 cvs 1003: } 1.12 cvs 1004: 1005: /* delete the element(s) containing the link to the copied document */ 1.58 cvs 1006: /* delete the parent element of el and all empty ancestors */ 1007: elem = TtaGetParent (el); 1.12 cvs 1008: do 1.1 cvs 1009: { 1.12 cvs 1010: sibling = elem; 1011: TtaNextSibling (&sibling); 1012: if (sibling == NULL) 1013: { 1014: sibling = elem; 1015: TtaPreviousSibling (&sibling); 1016: if (sibling == NULL) 1017: elem = TtaGetParent (elem); 1018: } 1.1 cvs 1019: } 1.12 cvs 1020: while (sibling == NULL); 1021: TtaDeleteTree (elem, destDoc); 1022: /* restore previous chacking mode */ 1.47 cvs 1023: TtaSetStructureChecking ((ThotBool)checkingMode, destDoc); 1.12 cvs 1024: } 1.58 cvs 1025: /* return the address of the new division */ 1026: return (div); 1.1 cvs 1027: } 1028: 1.29 cvs 1029: 1.58 cvs 1030: /*---------------------------------------------------------------------- 1031: CloseMakeBook 1032: ----------------------------------------------------------------------*/ 1.29 cvs 1033: #ifdef __STDC__ 1.58 cvs 1034: static void CloseMakeBook (Document document) 1035: #else 1036: static void CloseMakeBook (document) 1037: Document document; 1038: #endif /* __STDC__ */ 1039: 1040: { 1041: ResetStop (document); 1042: /* update internal links */ 1043: SetInternalLinks (document); 1044: /* if the document changed force the browser mode */ 1045: if (SubDocs) 1046: SetBrowserEditor (document); 1047: /* remove registered sub-documents */ 1048: FreeSubDocTable (); 1049: DocBook = 0; 1050: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), NULL); 1051: } 1052: 1053: 1054: /*---------------------------------------------------------------------- 1055: GetIncludedDocuments_callback finishes the GetIncludedDocuments procedure 1056: ----------------------------------------------------------------------*/ 1057: #ifdef __STDC__ 1058: void GetIncludedDocuments_callback (int newdoc, int status, 1059: STRING urlName, 1060: STRING outputfile, 1.63 cvs 1061: AHTHeaders *http_headers, 1.58 cvs 1062: void * context) 1.29 cvs 1063: #else /* __STDC__ */ 1.58 cvs 1064: void GetIncludedDocuments_callback (newdoc, status, urlName, 1.63 cvs 1065: outputfile, http_headers, 1.58 cvs 1066: context) 1067: int newdoc; 1068: int status; 1.36 cvs 1069: STRING urlName; 1070: STRING outputfile; 1.63 cvs 1071: AHTHeaders *http_headers; 1.58 cvs 1072: void *context; 1.29 cvs 1073: #endif /* __STDC__ */ 1074: { 1.58 cvs 1075: Element link, div; 1076: IncludeCtxt *ctx, *prev; 1.57 cvs 1077: STRING url, ptr; 1.58 cvs 1078: ThotBool found = FALSE; 1.29 cvs 1079: 1080: /* restore GetIncludedDocuments's context */ 1.58 cvs 1081: ctx = (IncludeCtxt *) context; 1.29 cvs 1082: if (!ctx) 1083: return; 1084: 1.58 cvs 1085: div = NULL; 1.29 cvs 1086: link = ctx->link; 1.58 cvs 1087: ptr = ctx->name; 1.29 cvs 1088: url = ctx->url; 1.58 cvs 1089: if (url) 1.29 cvs 1090: { 1.58 cvs 1091: if (newdoc && newdoc != DocBook) 1.29 cvs 1092: { 1.58 cvs 1093: /* it's not the DocBook itself */ 1094: /* copy the target document at the position of the link */ 1095: TtaSetDocumentModified (DocBook); 1096: div = MoveDocumentBody (link, DocBook, newdoc, ptr, url, 1097: (ThotBool)(newdoc == IncludedDocument)); 1.29 cvs 1098: } 1.58 cvs 1099: /* global variables */ 1100: FreeDocumentResource (IncludedDocument); 1101: TtaCloseDocument (IncludedDocument); 1102: IncludedDocument = 0; 1.29 cvs 1103: } 1.58 cvs 1104: 1105: if (div != NULL) 1.29 cvs 1106: { 1.58 cvs 1107: /* new starting point for the search */ 1108: ctx->link = div; 1109: found = GetIncludedDocuments (div, div, DocBook, ctx); 1.29 cvs 1110: } 1.58 cvs 1111: while (!found && ctx) 1112: { 1113: /* this sub-document has no more inclusion, examine the caller */ 1114: div = ctx->div; 1115: link = ctx->link; 1116: prev = ctx->ctxt; 1117: TtaFreeMemory (url); 1.64 cvs 1118: url = NULL; 1.58 cvs 1119: TtaFreeMemory (ctx); 1120: ctx = prev; 1121: found = GetIncludedDocuments (div, link, DocBook, ctx); 1122: } 1123: if (!found) 1124: /* all links are now managed */ 1125: CloseMakeBook (DocBook); 1.29 cvs 1126: } 1127: 1.1 cvs 1128: /*---------------------------------------------------------------------- 1129: GetIncludedDocuments 1.58 cvs 1130: Look forward within the element el, starting from element link, for a 1131: link (A) with attribute rel="chapter" or rel="subdocument" and replace 1132: that link by the contents of the target document. 1133: Return TRUE if one inclusion is launched. 1.1 cvs 1134: ----------------------------------------------------------------------*/ 1135: #ifdef __STDC__ 1.58 cvs 1136: static ThotBool GetIncludedDocuments (Element el, Element link, Document document, IncludeCtxt *prev) 1.1 cvs 1137: #else 1.58 cvs 1138: static ThotBool GetIncludedDocuments (el, link, document, prev) 1139: Element el; 1140: Element link; 1141: Document document; 1142: IncludeCtxt *prev; 1.1 cvs 1143: #endif 1144: { 1.58 cvs 1145: ElementType elType; 1146: Attribute attr; 1147: AttributeType attrType; 1148: Document newdoc; 1149: IncludeCtxt *ctx = NULL; 1150: STRING text, ptr, url = NULL; 1.29 cvs 1151: int length; 1.58 cvs 1152: ThotBool found = FALSE; 1.29 cvs 1153: 1.58 cvs 1154: /* look for anchors with the attribute rel within the element el */ 1155: attr = NULL; 1.61 cvs 1156: attrType.AttrSSchema = TtaGetSSchema (TEXT("HTML"), document); 1.58 cvs 1157: elType.ElSSchema = attrType.AttrSSchema; 1158: elType.ElTypeNum = HTML_EL_Anchor; 1.29 cvs 1159: 1.58 cvs 1160: /* Get only one included file each time */ 1161: while (link && attr == NULL) 1.29 cvs 1162: { 1.58 cvs 1163: link = TtaSearchTypedElementInTree (elType, SearchForward, el, link); 1164: if (link) 1.29 cvs 1165: { 1.58 cvs 1166: attrType.AttrTypeNum = HTML_ATTR_REL; 1167: attr = TtaGetAttribute (link, attrType); 1168: } 1169: if (attr) 1170: { 1171: length = TtaGetTextAttributeLength (attr); 1.49 cvs 1172: text = TtaAllocString (length + 1); 1.58 cvs 1173: TtaGiveTextAttributeValue (attr, text, &length); 1174: /* Valid rel values are rel="chapter" or rel="subdocument" */ 1175: if (ustrcasecmp (text, TEXT("chapter")) && 1176: ustrcasecmp (text, TEXT("subdocument"))) 1177: attr = NULL; 1.29 cvs 1178: TtaFreeMemory (text); 1179: } 1.58 cvs 1180: 1181: if (attr) 1182: { 1183: /* a link with attribute rel="Chapter" has been found */ 1184: attrType.AttrTypeNum = HTML_ATTR_HREF_; 1185: attr = TtaGetAttribute (link, attrType); 1186: } 1187: if (attr) 1188: /* this link has an attribute HREF */ 1189: { 1190: length = TtaGetTextAttributeLength (attr); 1191: text = TtaAllocString (length + 1); 1192: TtaGiveTextAttributeValue (attr, text, &length); 1193: ptr = ustrrchr (text, '#'); 1194: url = text; 1195: if (ptr != NULL) 1196: { 1197: if (ptr == text) 1198: url = NULL; 1199: /* link to a particular position within a remote document */ 1200: ptr[0] = EOS; 1201: ptr = &ptr[1]; 1202: } 1203: 1204: if (url != NULL) 1205: /* this link designates an external document */ 1206: { 1207: /* create a new document and loads the target document */ 1.62 cvs 1208: IncludedDocument = TtaNewDocument (TEXT("HTML"), TEXT("tmp")); 1.58 cvs 1209: if (IncludedDocument != 0) 1210: { 1211: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_FETCHING), url); 1212: ctx = TtaGetMemory (sizeof (IncludeCtxt)); 1213: ctx->div = el; 1214: ctx->link = link; 1215: ctx->url = url; /* the URL of the document */ 1216: ctx->name = ptr; 1217: ctx->ctxt = prev; /* previous context */ 1218: /* Get the reference of the calling document */ 1219: SetStopButton (document); 1220: newdoc = GetHTMLDocument (url, NULL, IncludedDocument, 1221: document, CE_MAKEBOOK, FALSE, 1222: (void *) GetIncludedDocuments_callback, 1223: (void *) ctx); 1224: found = TRUE; 1225: } 1226: } 1227: else 1228: TtaFreeMemory (text); 1229: } 1.29 cvs 1230: } 1.58 cvs 1231: return (found); 1.1 cvs 1232: } 1233: 1234: 1235: /*---------------------------------------------------------------------- 1236: MakeBook 1237: Replace all links in a document which have an attribute REL="chapter" 1.5 cvs 1238: or REL="subdocument" by the corresponding target document. 1.1 cvs 1239: ----------------------------------------------------------------------*/ 1240: #ifdef __STDC__ 1241: void MakeBook (Document document, View view) 1242: #else 1243: void MakeBook (document, view) 1244: Document document; 1245: View view; 1246: #endif 1247: { 1.58 cvs 1248: Element root, body; 1249: ElementType elType; 1.1 cvs 1250: 1.58 cvs 1251: /* stops all current transfers on this document */ 1252: StopTransfer (document, 1); 1253: /* simulate a transfert in the main document */ 1254: DocBook = document; 1255: IncludedDocument = 0; 1256: root = TtaGetMainRoot (document); 1257: elType = TtaGetElementType (root); 1258: elType.ElTypeNum = HTML_EL_BODY; 1259: body = TtaSearchTypedElement (elType, SearchForward, root); 1.29 cvs 1260: 1.58 cvs 1261: if (body) 1262: GetIncludedDocuments (body, body, document, NULL); 1.1 cvs 1263: }