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 12: */ 13: 14: 15: /* Included headerfiles */ 16: #define THOT_EXPORT 17: #include "amaya.h" 18: #include "print.h" 19: 20: #define NumFormPrint 1 21: #define NumMenuOptions 2 22: #define NumMenuPaperFormat 3 23: #define NumMenuSupport 4 24: #define NumZonePrinterName 5 25: #define PRINT_MAX_REF 6 26: 27: /* Thot printer variables */ 1.2 cvs 28: static int PaperPrint; 29: static int ManualFeed; 30: static int PageSize; 31: static char PSdir[MAX_PATH]; 32: static char pPrinter[MAX_PATH]; 1.1 cvs 33: static Document docPrint; 34: static boolean numberLinks; 35: static boolean withToC; 36: static int basePrint; 37: 38: #include "init_f.h" 39: #include "HTMLactions_f.h" 40: #include "HTMLbook_f.h" 41: #include "HTMLedit_f.h" 42: 43: 44: /*---------------------------------------------------------------------- 45: SetInternalLinks 1.8 cvs 46: Associate an InternalLink attribute with all anchor (A) elements of the 47: document which designate an element in the same document. 1.1 cvs 48: InternalLink is a Thot reference attribute that links a source and a 49: target anchor and that allows P schemas to display and print cross-references 1.8 cvs 50: Associate an ExternalLink attribute with all anchor (A) elements of the 51: document which designate an element in another document. 1.1 cvs 52: ----------------------------------------------------------------------*/ 53: #ifdef __STDC__ 1.4 cvs 54: void SetInternalLinks (Document document) 1.1 cvs 55: #else 1.4 cvs 56: void SetInternalLinks (document) 1.1 cvs 57: Document document; 58: #endif 59: { 60: Element root, el; 61: Element link, target; 62: ElementType elType; 1.8 cvs 63: Attribute HrefAttr, IntLinkAttr, ExtLinkAttr; 1.1 cvs 64: AttributeType attrType; 65: int length; 1.3 cvs 66: int status; 67: char *text; 1.1 cvs 68: 1.8 cvs 69: /* Remember the current status of the document */ 1.3 cvs 70: status = TtaIsDocumentModified (document); 1.1 cvs 71: root = TtaGetMainRoot (document); 72: elType = TtaGetElementType (root); 73: elType.ElTypeNum = HTML_EL_BODY; 74: el = TtaSearchTypedElement (elType, SearchForward, root); 75: 76: elType.ElTypeNum = HTML_EL_Anchor; 77: attrType.AttrSSchema = elType.ElSSchema; 78: /* looks for all anchors in the document */ 79: link = el; 80: while (link != NULL) 81: { 82: link = TtaSearchTypedElement (elType, SearchForward, link); 83: if (link != NULL) 84: /* an anchor has been found */ 85: { 86: attrType.AttrTypeNum = HTML_ATTR_HREF_; 87: HrefAttr = TtaGetAttribute (link, attrType); 1.8 cvs 88: attrType.AttrTypeNum = HTML_ATTR_InternalLink; 89: IntLinkAttr = TtaGetAttribute (link, attrType); 90: attrType.AttrTypeNum = HTML_ATTR_ExternalLink; 91: ExtLinkAttr = TtaGetAttribute (link, attrType); 92: if (HrefAttr == NULL) 93: /* this anchor is not a link (no href attribute) */ 94: /* remove attributes InternalLink and ExternalLink if they 95: are present */ 96: { 97: if (IntLinkAttr != NULL) 98: TtaRemoveAttribute (link, IntLinkAttr, document); 99: if (ExtLinkAttr != NULL) 100: TtaRemoveAttribute (link, ExtLinkAttr, document); 101: } 102: else 1.1 cvs 103: /* this anchor has an HREF attribute */ 104: { 105: length = TtaGetTextAttributeLength (HrefAttr); 106: text = TtaGetMemory (length + 1); 107: TtaGiveTextAttributeValue (HrefAttr, text, &length); 108: if (text[0] == '#') 1.8 cvs 109: /* it's an internal link. Attach an attribute InternalLink to */ 1.1 cvs 110: /* the link, if this attribute does not exist yet */ 111: { 112: if (IntLinkAttr == NULL) 113: { 1.8 cvs 114: attrType.AttrTypeNum = HTML_ATTR_InternalLink; 1.1 cvs 115: IntLinkAttr = TtaNewAttribute (attrType); 116: TtaAttachAttribute (link, IntLinkAttr, document); 117: } 118: /* looks for the target element */ 119: target = SearchNAMEattribute (document, &text[1], NULL); 120: if (target != NULL) 121: /* set the Thot link */ 122: TtaSetAttributeReference (IntLinkAttr, link, document, 123: target, document); 124: } 1.8 cvs 125: else 126: /* it's an external link */ 127: { 128: /* Remove the InternalLink attribute if it is present */ 129: if (IntLinkAttr != NULL) 130: TtaRemoveAttribute (link, IntLinkAttr, document); 131: /* create an ExternalLink attribute if there is none */ 132: if (ExtLinkAttr == NULL) 133: { 134: attrType.AttrTypeNum = HTML_ATTR_ExternalLink; 135: ExtLinkAttr = TtaNewAttribute (attrType); 136: TtaAttachAttribute (link, ExtLinkAttr, document); 137: } 138: } 1.1 cvs 139: TtaFreeMemory (text); 140: } 141: } 142: } 1.3 cvs 143: /* Reset document status */ 144: if (!status) 145: TtaSetDocumentUnmodified (document); 146: } 147: 148: /*---------------------------------------------------------------------- 149: CheckPrintingDocument reinitialize printing parameters as soon as 150: the printing document changes. 151: ----------------------------------------------------------------------*/ 152: #ifdef __STDC__ 153: static void CheckPrintingDocument (Document document) 154: #else 155: static void CheckPrintingDocument (document) 156: Document document; 157: #endif 158: { 159: char docName[MAX_LENGTH]; 160: char *ptr, suffix[MAX_LENGTH]; 161: int lg; 162: 163: if (docPrint != document) 164: { 165: /* initialize print parameters */ 166: docPrint = document; 167: 168: /* define the new default PS file */ 169: ptr = TtaGetEnvString ("TMPDIR"); 170: if (ptr != NULL && TtaCheckDirectory (ptr)) 171: { 172: strcpy(PSdir,ptr); 173: lg = strlen(PSdir); 174: if (PSdir[lg - 1] == DIR_SEP) 175: PSdir[--lg] = '\0'; 176: } 177: else 178: { 1.6 cvs 179: # ifdef _WINDOWS 1.3 cvs 180: strcpy (PSdir,"C:\\TEMP"); 1.6 cvs 181: # else /* !_WINDOWS */ 1.3 cvs 182: strcpy (PSdir,"/tmp"); 1.6 cvs 183: # endif /* !_WINDOWS */ 1.3 cvs 184: lg = strlen (PSdir); 185: } 186: strcpy (docName, TtaGetDocumentName (document)); 187: ExtractSuffix (docName, suffix); 188: sprintf (&PSdir[lg], "/%s.ps", docName); 189: TtaSetPsFile (PSdir); 190: /* define the new default PrintSchema */ 191: numberLinks = FALSE; 192: withToC = FALSE; 193: TtaSetPrintSchema (""); 194: /* no manual feed */ 195: ManualFeed = PP_OFF; 196: TtaSetPrintParameter (PP_ManualFeed, ManualFeed); 197: } 198: } 199: 200: 201: /*---------------------------------------------------------------------- 202: PrintAs prints the document using predefined parameters. 203: ----------------------------------------------------------------------*/ 204: #ifdef __STDC__ 205: void PrintAs (Document document, View view) 206: #else /* __STDC__ */ 207: void PrintAs (document, view) 208: Document document; 209: #endif /* __STDC__ */ 210: { 1.9 cvs 211: char viewsToPrint[MAX_PATH]; 1.3 cvs 212: 213: CheckPrintingDocument (document); 214: strcpy (viewsToPrint, "Formatted_view "); 215: if (withToC) 216: strcat (viewsToPrint, "Table_of_contents "); 217: if (numberLinks) 1.8 cvs 218: /* display numbered links */ 1.3 cvs 219: { 1.8 cvs 220: /* associate an attribute InternalLink with all anchors refering 221: a target in the same document. This allows P schemas to work 222: properly */ 223: SetInternalLinks (docPrint); 1.3 cvs 224: if (PageSize == PP_A4) 225: TtaSetPrintSchema ("HTMLPLP"); 226: else 227: TtaSetPrintSchema ("HTMLPLPUS"); 228: strcat (viewsToPrint, "Links_view "); 229: } 230: TtaPrint (docPrint, viewsToPrint); 1.1 cvs 231: } 232: 233: 234: /*---------------------------------------------------------------------- 235: CallbackImage manage returns of Picture form. 236: ----------------------------------------------------------------------*/ 237: #ifdef __STDC__ 238: void CallbackPrint (int ref, int typedata, char *data) 239: #else /* __STDC__ */ 240: void CallbackPrint (ref, typedata, data) 241: int ref; 242: int typedata; 243: char *data; 244: #endif /* __STDC__ */ 245: { 246: int val; 247: 248: val = (int) data; 249: switch (ref - basePrint) 250: { 251: case NumFormPrint: 252: TtaDestroyDialogue (basePrint+NumFormPrint); 253: switch (val) 254: { 255: case 1: 256: /* confirms the paper print option */ 257: /* the other options are not taken into account without this 258: confirmation */ 1.2 cvs 259: TtaSetPrintParameter (PP_Destination, PaperPrint); 260: TtaSetPrintParameter (PP_ManualFeed, ManualFeed); 261: TtaSetPrintParameter (PP_PaperSize, PageSize); 262: TtaSetPrintCommand (pPrinter); 263: TtaSetPsFile (PSdir); 1.3 cvs 264: PrintAs (docPrint, 1); 1.1 cvs 265: break; 1.2 cvs 266: case 0: 267: PaperPrint = TtaGetPrintParameter (PP_Destination); 268: ManualFeed = TtaGetPrintParameter (PP_ManualFeed); 269: PageSize = TtaGetPrintParameter (PP_PaperSize); 270: TtaGetPrintCommand (pPrinter); 271: TtaGetPsFile (PSdir); 272: break; 1.1 cvs 273: default: 274: break; 275: } 276: break; 277: case NumMenuOptions: 278: switch (val) 279: { 280: case 0: 281: /* Manual feed option */ 1.2 cvs 282: if (ManualFeed == PP_ON) 283: ManualFeed = PP_OFF; 284: else 285: ManualFeed = PP_ON; 1.1 cvs 286: break; 287: case 1: 288: /* Toc option */ 289: withToC = !withToC; 290: break; 291: case 2: 1.3 cvs 292: /* numberLinks option */ 1.1 cvs 293: numberLinks = !numberLinks; 294: break; 295: } 296: break; 297: case NumMenuPaperFormat: 298: /* page size submenu */ 299: switch (val) 300: { 301: case 0: 1.2 cvs 302: PageSize = PP_A4; 1.1 cvs 303: break; 304: case 1: 1.2 cvs 305: PageSize = PP_US; 1.1 cvs 306: break; 307: } 308: break; 309: case NumMenuSupport: 310: /* paper print/save PostScript submenu */ 311: switch (val) 312: { 313: case 0: 1.2 cvs 314: if (PaperPrint == PP_PS) 1.1 cvs 315: { 1.2 cvs 316: PaperPrint = PP_PRINTER; 1.1 cvs 317: TtaSetTextForm (basePrint+NumZonePrinterName, pPrinter); 318: } 319: break; 320: case 1: 1.2 cvs 321: if (PaperPrint == PP_PRINTER) 1.1 cvs 322: { 1.2 cvs 323: PaperPrint = PP_PS; 1.1 cvs 324: TtaSetTextForm (basePrint+NumZonePrinterName, PSdir); 325: } 326: break; 327: } 328: break; 329: case NumZonePrinterName: 330: if (data[0] != '\0') 1.2 cvs 331: if (PaperPrint == PP_PRINTER) 1.1 cvs 332: /* text capture zone for the printer name */ 333: strncpy (pPrinter, data, MAX_PATH); 334: else 335: /* text capture zone for the name of the PostScript file */ 336: strncpy (PSdir, data, MAX_PATH); 337: break; 338: } 339: } 340: 341: /*---------------------------------------------------------------------- 342: ----------------------------------------------------------------------*/ 343: #ifdef __STDC__ 344: void InitPrint (void) 345: #else /* __STDC__ */ 346: void InitPrint () 347: #endif /* __STDC__ */ 348: { 349: char *ptr; 350: 351: basePrint = TtaSetCallback (CallbackPrint, PRINT_MAX_REF); 352: docPrint = 0; 353: 354: /* init printer variables */ 355: /* read default printer variable */ 356: ptr = TtaGetEnvString ("THOTPRINT"); 357: if (ptr == NULL) 358: strcpy (pPrinter, ""); 359: else 360: strcpy (pPrinter, ptr); 361: 1.2 cvs 362: PageSize = PP_A4; 363: PaperPrint = PP_PRINTER; 364: TtaSetPrintParameter (PP_Destination, PaperPrint); 365: TtaSetPrintParameter (PP_PaperSize, PageSize); 366: TtaSetPrintCommand (pPrinter); 1.1 cvs 367: } 368: 369: /*---------------------------------------------------------------------- 1.3 cvs 370: SetupAndPrint sets printing parameters and starts the printing process 1.1 cvs 371: ----------------------------------------------------------------------*/ 372: #ifdef __STDC__ 373: void SetupAndPrint (Document document, View view) 374: #else 375: void SetupAndPrint (document, view) 376: Document document; 377: View view; 378: #endif 379: { 1.10 cvs 380: # ifndef _WINDOWS 1.2 cvs 381: char bufMenu[MAX_LENGTH]; 1.3 cvs 382: int i; 1.1 cvs 383: 384: /* Print form */ 1.3 cvs 385: CheckPrintingDocument (document); 1.1 cvs 386: TtaNewSheet (basePrint+NumFormPrint, TtaGetViewFrame (document, view), 387: TtaGetMessage (LIB, TMSG_LIB_PRINT), 1.3 cvs 388: 1, TtaGetMessage (AMAYA, AM_BUTTON_PRINT), FALSE, 2, 'L', D_CANCEL); 1.1 cvs 389: i = 0; 390: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (LIB, TMSG_MANUAL_FEED)); 391: i += strlen (&bufMenu[i]) + 1; 392: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_PRINT_TOC)); 393: i += strlen (&bufMenu[i]) + 1; 394: sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_NUMBERED_LINKS)); 395: TtaNewToggleMenu (basePrint+NumMenuOptions, basePrint+NumFormPrint, 396: TtaGetMessage (LIB, TMSG_OPTIONS), 3, bufMenu, NULL, FALSE); 1.2 cvs 397: if (ManualFeed == PP_ON) 1.1 cvs 398: TtaSetToggleMenu (basePrint+NumMenuOptions, 0, TRUE); 399: if (withToC) 400: TtaSetToggleMenu (basePrint+NumMenuOptions, 1, TRUE); 401: if (numberLinks) 402: TtaSetToggleMenu (basePrint+NumMenuOptions, 2, TRUE); 403: 404: /* Paper format submenu */ 405: i = 0; 406: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_A4)); 407: i += strlen (&bufMenu[i]) + 1; 408: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_US)); 409: TtaNewSubmenu (basePrint+NumMenuPaperFormat, basePrint+NumFormPrint, 0, 410: TtaGetMessage (LIB, TMSG_PAPER_SIZE), 2, bufMenu, NULL, FALSE); 1.2 cvs 411: if (PageSize == PP_US) 1.1 cvs 412: TtaSetMenuForm (basePrint+NumMenuPaperFormat, 1); 413: else 414: TtaSetMenuForm (basePrint+NumMenuPaperFormat, 0); 415: 416: /* Print to paper/ Print to file submenu */ 417: i = 0; 418: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_PRINTER)); 419: i += strlen (&bufMenu[i]) + 1; 420: sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_PS_FILE)); 421: TtaNewSubmenu (basePrint+NumMenuSupport, basePrint+NumFormPrint, 0, 422: TtaGetMessage (LIB, TMSG_OUTPUT), 2, bufMenu, NULL, TRUE); 423: /* text capture zone for the printer name */ 424: TtaNewTextForm (basePrint+NumZonePrinterName, basePrint+NumFormPrint, NULL, 30, 1, FALSE); 425: 426: /* initialization of the PaperPrint selector */ 1.2 cvs 427: if (PaperPrint == PP_PRINTER) 1.1 cvs 428: { 429: TtaSetMenuForm (basePrint+NumMenuSupport, 0); 430: TtaSetTextForm (basePrint+NumZonePrinterName, pPrinter); 431: } 432: else 433: { 434: TtaSetMenuForm (basePrint+NumMenuSupport, 1); 435: TtaSetTextForm (basePrint+NumZonePrinterName, PSdir); 436: } 437: 438: /* activates the Print form */ 1.10 cvs 439: TtaShowDialogue (basePrint+NumFormPrint, FALSE); 440: # else /* _WINDOWS */ 1.11 cvs 441: CreatePrintDlgWindow (TtaGetViewFrame (document, view)); 1.10 cvs 442: # endif /* _WINDOWS */ 1.1 cvs 443: } 444: 445: /*---------------------------------------------------------------------- 446: SectionNumbering 447: Execute the "Section Numbering" command 448: ----------------------------------------------------------------------*/ 449: #ifdef __STDC__ 450: void SectionNumbering (Document document, View view) 451: #else 452: void SectionNumbering (document, view) 453: Document document; 454: View view; 455: #endif 456: { 457: ChangeAttrOnRoot (document, HTML_ATTR_SectionNumbering); 458: } 459: 460: /*---------------------------------------------------------------------- 461: UpdateURLsInSubtree 462: Update NAMEs and URLs in subtree of el element, to take into account 463: the move from one document to another. 464: If a NAME attribute already exists in the new document, it is changed 465: to avoid duplicate names. 466: Transform the HREF and SRC attribute to make them independent from their 467: former base. 468: ----------------------------------------------------------------------*/ 469: #ifdef __STDC__ 470: static void UpdateURLsInSubtree (NotifyElement *event, Element el) 471: #else 472: static void UpdateURLsInSubtree (event, el) 473: NotifyElement *event; 474: Element el; 475: #endif 476: { 477: Element nextEl; 478: 479: event->element = el; 480: ElementPasted (event); 481: nextEl = TtaGetFirstChild (el); 482: while (nextEl != NULL) 483: { 484: UpdateURLsInSubtree (event, nextEl); 485: TtaNextSibling (&nextEl); 486: } 487: } 488: 489: 490: /*---------------------------------------------------------------------- 491: MoveDocumentBody 492: Copy the elements contained in the BODY of document sourceDoc to the 493: position of element *el in document destDoc. 494: Delete the element containing *el and all its empty ancestors. 495: If deleteTree is TRUE, copied elements are deleted from the source 496: document. 497: ----------------------------------------------------------------------*/ 498: #ifdef __STDC__ 1.12 ! cvs 499: static void MoveDocumentBody (Element *el, Document destDoc, ! 500: Document sourceDoc, char *target, boolean deleteTree) 1.1 cvs 501: #else 1.12 ! cvs 502: static void MoveDocumentBody (el, destDoc, sourceDoc, target, deleteTree) ! 503: Element *el; ! 504: Document destDoc; ! 505: Document sourceDoc; ! 506: char *target; ! 507: boolean deleteTree; 1.1 cvs 508: #endif 509: { 1.12 ! cvs 510: Element root, body, ancestor, elem, firstInserted; ! 511: Element lastInserted, srce, copy, old, parent, sibling; ! 512: ElementType elType; ! 513: NotifyElement event; ! 514: int checkingMode; 1.1 cvs 515: 1.12 ! cvs 516: firstInserted = NULL; ! 517: /* get the BODY element of source document */ ! 518: root = TtaGetMainRoot (sourceDoc); ! 519: elType = TtaGetElementType (root); ! 520: elType.ElTypeNum = HTML_EL_BODY; ! 521: body = TtaSearchTypedElement (elType, SearchForward, root); ! 522: if (body != NULL) ! 523: { ! 524: /* don't check the abstract tree against the structure schema */ ! 525: checkingMode = TtaGetStructureChecking (destDoc); ! 526: TtaSetStructureChecking (0, destDoc); ! 527: /* get elem, the ancestor of *el which is a child of a DIV or BODY ! 528: element in the destination document. The copied elements will be ! 529: inserted just before this element. */ ! 530: elem = *el; ! 531: do 1.1 cvs 532: { 1.12 ! cvs 533: ancestor = TtaGetParent (elem); ! 534: if (ancestor != NULL) ! 535: { ! 536: elType = TtaGetElementType (ancestor); ! 537: if (elType.ElTypeNum == HTML_EL_BODY || ! 538: elType.ElTypeNum == HTML_EL_Division) ! 539: ancestor = NULL; ! 540: else ! 541: elem = ancestor; ! 542: } 1.1 cvs 543: } 1.12 ! cvs 544: while (ancestor != NULL); ! 545: parent = TtaGetParent (elem); 1.1 cvs 546: 1.12 ! cvs 547: /* do copy */ ! 548: lastInserted = NULL; ! 549: srce = TtaGetFirstChild (body); ! 550: while (srce != NULL) 1.1 cvs 551: { 1.12 ! cvs 552: copy = TtaCopyTree (srce, sourceDoc, destDoc, parent); ! 553: if (copy != NULL) ! 554: { ! 555: if (lastInserted == NULL) ! 556: /* this is the first copied element. Insert it before elem */ ! 557: { ! 558: TtaInsertSibling (copy, elem, TRUE, destDoc); ! 559: firstInserted = copy; ! 560: } ! 561: else ! 562: /* insert the new copied element after the element previously ! 563: copied */ ! 564: TtaInsertSibling (copy, lastInserted, FALSE, destDoc); ! 565: lastInserted = copy; ! 566: /* update the NAMEs and URLs in the copied element */ ! 567: event.document = destDoc; ! 568: event.position = sourceDoc; ! 569: UpdateURLsInSubtree(&event, copy); ! 570: } ! 571: /* get the next element in the source document */ ! 572: old = srce; ! 573: TtaNextSibling (&srce); ! 574: if (deleteTree) ! 575: TtaDeleteTree (old, sourceDoc); 1.1 cvs 576: } 1.12 ! cvs 577: ! 578: /* delete the element(s) containing the link to the copied document */ ! 579: /* delete the parent element of *el and all empty ancestors */ ! 580: elem = TtaGetParent (*el); ! 581: do 1.1 cvs 582: { 1.12 ! cvs 583: sibling = elem; ! 584: TtaNextSibling (&sibling); ! 585: if (sibling == NULL) ! 586: { ! 587: sibling = elem; ! 588: TtaPreviousSibling (&sibling); ! 589: if (sibling == NULL) ! 590: elem = TtaGetParent (elem); ! 591: } 1.1 cvs 592: } 1.12 ! cvs 593: while (sibling == NULL); ! 594: TtaDeleteTree (elem, destDoc); ! 595: /* restore previous chacking mode */ ! 596: TtaSetStructureChecking (checkingMode, destDoc); ! 597: /* return the address of the first copied element */ ! 598: *el = firstInserted; ! 599: } 1.1 cvs 600: } 601: 602: /*---------------------------------------------------------------------- 603: GetIncludedDocuments 604: Look forward, starting from element el, for a link (A) with attribute 1.5 cvs 605: REL="chapter" or REL="subdocument" and replace that link by the contents 606: of the target document. 1.1 cvs 607: ----------------------------------------------------------------------*/ 608: #ifdef __STDC__ 609: static Element GetIncludedDocuments (Element el, Document document) 610: #else 611: static Element GetIncludedDocuments (el, document) 612: Element el; 613: Document document; 614: #endif 615: { 616: Element link, next; 617: Attribute RelAttr, HrefAttr; 618: AttributeType attrType; 619: int length; 1.12 ! cvs 620: char *text, *ptr, *url; 1.1 cvs 621: Document includedDocument, newdoc; 622: 623: attrType.AttrSSchema = TtaGetDocumentSSchema (document); 624: attrType.AttrTypeNum = HTML_ATTR_REL; 625: link = el; 626: RelAttr = NULL; 1.5 cvs 627: /* looks for an anchor having an attribute REL="chapter" or 628: REL="subdocument" */ 1.1 cvs 629: while (link != NULL && RelAttr == NULL) 630: { 631: TtaSearchAttribute (attrType, SearchForward, link, &link, &RelAttr); 632: if (link != NULL && RelAttr != NULL) 633: { 634: length = TtaGetTextAttributeLength (RelAttr); 635: text = TtaGetMemory (length + 1); 636: TtaGiveTextAttributeValue (RelAttr, text, &length); 1.5 cvs 637: if (strcasecmp (text, "chapter") && strcasecmp (text, "subdocument")) 1.1 cvs 638: RelAttr = NULL; 639: TtaFreeMemory (text); 640: } 641: } 642: 643: if (RelAttr != NULL && link != NULL) 644: /* a link with attribute REL="Chapter" has been found */ 645: { 646: next = link; 647: attrType.AttrTypeNum = HTML_ATTR_HREF_; 648: HrefAttr = TtaGetAttribute (link, attrType); 649: if (HrefAttr != NULL) 650: /* this link has an attribute HREF */ 651: { 652: length = TtaGetTextAttributeLength (HrefAttr); 653: text = TtaGetMemory (length + 1); 654: TtaGiveTextAttributeValue (HrefAttr, text, &length); 655: ptr = strrchr (text, '#'); 1.12 ! cvs 656: url = text; ! 657: if (ptr != NULL) ! 658: { ! 659: if (ptr == text) ! 660: url = NULL; ! 661: /* link to a particular position within a document */ ! 662: ptr[0] = EOS; ! 663: ptr = &ptr[1]; ! 664: } ! 665: ! 666: if (url != NULL) ! 667: /* this link designate an external document */ 1.1 cvs 668: { 669: /* create a new document and loads the target document */ 670: includedDocument = TtaNewDocument ("HTML", "tmp"); 1.12 ! cvs 671: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_FETCHING), url); ! 672: newdoc = GetHTMLDocument (url, NULL, includedDocument, 1.1 cvs 673: document, DC_TRUE); 674: if (newdoc != 0 && newdoc != document) 1.12 ! cvs 675: { 1.1 cvs 676: /* it's not the document itself */ 677: /* copy the target document at the position of the link */ 1.12 ! cvs 678: MoveDocumentBody (&next, document, newdoc, ptr, 1.1 cvs 679: newdoc == includedDocument); 1.12 ! cvs 680: } 1.1 cvs 681: FreeDocumentResource (includedDocument); 682: TtaCloseDocument (includedDocument); 683: } 1.12 ! cvs 684: 1.1 cvs 685: TtaFreeMemory (text); 686: } 687: return (next); 688: } 689: return (NULL); 690: } 691: 692: 693: /*---------------------------------------------------------------------- 694: MakeBook 695: Replace all links in a document which have an attribute REL="chapter" 1.5 cvs 696: or REL="subdocument" by the corresponding target document. 1.1 cvs 697: ----------------------------------------------------------------------*/ 698: #ifdef __STDC__ 699: void MakeBook (Document document, View view) 700: #else 701: void MakeBook (document, view) 702: Document document; 703: View view; 704: #endif 705: { 706: Element root, body, el; 707: ElementType elType; 708: 709: root = TtaGetMainRoot (document); 710: elType = TtaGetElementType (root); 711: elType.ElTypeNum = HTML_EL_BODY; 712: body = TtaSearchTypedElement (elType, SearchForward, root); 713: TtaSetDocumentModified (document); 714: el = body; 715: while (el != NULL) 716: el = GetIncludedDocuments (el, document); 1.7 cvs 717: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), ""); 1.1 cvs 718: } 719: 720: 721: #ifdef R_HTML 722: /*---------------------------------------------------------------------- 723: ----------------------------------------------------------------------*/ 724: #ifdef __STDC__ 725: static void LoadEntity (Document document, char *text) 726: #else 727: static void LoadEntity (document, text) 728: Document document; 729: char *text; 730: #endif 731: { 732: Document includedDocument; 733: Attribute attr; 734: AttributeType attrType; 735: Element el, includedEl; 736: ElementType elType; 737: int length; 738: 739: /* create the temporary document */ 740: includedDocument = TtaNewDocument ("HTML", "tmp"); 741: /* read the temporary document */ 742: includedDocument = GetHTMLDocument (text, NULL, includedDocument, document, DC_TRUE); 743: 744: if (includedDocument != 0) 745: { 746: /* To do: Seach entity in the table */ 747: /* locate the entity in the document */ 748: el = TtaGetMainRoot (document); 749: elType = TtaGetElementType (el); 750: elType.ElTypeNum = HTML_EL_Entity; 751: /* TtaSearchElementByLabel (label, el); */ 752: el = TtaSearchTypedElement (elType, SearchForward, el); 753: /* keep the entity name to know where to insert the sub-tree */ 754: attrType.AttrSSchema = TtaGetDocumentSSchema (document); 755: attrType.AttrTypeNum = HTML_ATTR_entity_name; 756: attr = TtaGetAttribute (el, attrType); 757: if (attr != NULL) 758: { 759: length = TtaGetTextAttributeLength (attr); 760: text = TtaGetMemory (length + 1); 761: TtaGiveTextAttributeValue (attr, text, &length); 762: } 763: /* To do: translate the entity name into element type 764: and search this first element type in included document */ 765: includedEl = TtaGetMainRoot (includedDocument); 766: elType = TtaGetElementType (includedEl); 767: elType.ElTypeNum = HTML_EL_TEXT_UNIT; 768: includedEl = TtaSearchTypedElement (elType, SearchForward, includedEl); 769: /* remove Entity */ 770: /* To do: insert sub-trees */ 771: FreeDocumentResource (includedDocument); 772: TtaCloseDocument (includedDocument); 773: } 774: } 775: #endif /* R_HTML */ 776: 777: 778: /*---------------------------------------------------------------------- 779: ----------------------------------------------------------------------*/ 780: #ifdef __STDC__ 781: void RealTimeHTML (Document document, View view) 782: #else 783: void RealTimeHTML (document, view) 784: Document document; 785: View view; 786: #endif 787: { 788: #ifdef R_HTML 789: Element root, el; 790: ElementType elType; 791: 792: root = TtaGetMainRoot (document); 793: elType = TtaGetElementType (root); 794: elType.ElTypeNum = HTML_EL_Entity; 795: el = TtaSearchTypedElement (elType, SearchForward, root); 796: if (el != NULL) 797: { 798: /* document contains entities */ 799: /* To do -> build table of entities */ 800: 801: /* simulate reception of different entities */ 802: LoadEntity (document, "0/0"); 803: LoadEntity (document, "0/1"); 804: } 805: #endif /* R_HTML */ 806: }