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