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