Annotation of Amaya/amaya/HTMLbook.c, revision 1.108
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
1.108 ! gully 827: {
! 828: ThotBool created;
! 829: created = CreatePrintDlgWX (BasePrint + FormPrint, TtaGetViewFrame (doc, view), PSfile);
! 830: if (created)
! 831: {
! 832: TtaShowDialogue (BasePrint+FormPrint, FALSE);
! 833: }
! 834: }
! 835:
1.107 carcone 836: #endif /* _WX */
1.1 cvs 837: }
838:
839: /*----------------------------------------------------------------------
840: UpdateURLsInSubtree
841: Update NAMEs and URLs in subtree of el element, to take into account
842: the move from one document to another.
843: If a NAME attribute already exists in the new document, it is changed
844: to avoid duplicate names.
845: Transform the HREF and SRC attribute to make them independent from their
846: former base.
847: ----------------------------------------------------------------------*/
1.99 cvs 848: void UpdateURLsInSubtree (NotifyElement *event, Element el)
1.1 cvs 849: {
1.77 cvs 850: Element nextEl, child;
851: ElementType elType;
852: SSchema HTMLschema;
1.1 cvs 853:
854: nextEl = TtaGetFirstChild (el);
1.82 cvs 855: HTMLschema = TtaGetSSchema ("HTML", event->document);
1.99 cvs 856: if (HTMLschema)
1.1 cvs 857: {
1.99 cvs 858: elType.ElSSchema = HTMLschema;
859: while (nextEl != NULL)
1.77 cvs 860: {
1.99 cvs 861: event->element = nextEl;
1.77 cvs 862: ElementPasted (event);
1.99 cvs 863:
864: /* manage included links and anchors */
865: elType.ElTypeNum = HTML_EL_Anchor;
866: child = TtaSearchTypedElement (elType, SearchInTree, nextEl);
867: while (child)
868: {
869: event->element = child;
870: ElementPasted (event);
871: child = TtaSearchTypedElementInTree (elType, SearchForward, nextEl, child);
872: }
873:
874: /* manage included links and anchors */
875: elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
876: child = TtaSearchTypedElement (elType, SearchInTree, nextEl);
877: while (child)
878: {
879: event->element = child;
880: ElementPasted (event);
881: child = TtaSearchTypedElementInTree (elType, SearchForward, nextEl, child);
882: }
883: TtaNextSibling (&nextEl);
1.77 cvs 884: }
1.1 cvs 885: }
886: }
887:
888:
889: /*----------------------------------------------------------------------
890: MoveDocumentBody
1.58 cvs 891: Copy the elements contained in the BODY of the document sourceDoc at the
892: position of the element el in the document destDoc.
893: Delete the element containing el and all its empty ancestors.
1.1 cvs 894: If deleteTree is TRUE, copied elements are deleted from the source
895: document.
1.58 cvs 896: Return the root element that delimits the new inserted part (a div).
1.1 cvs 897: ----------------------------------------------------------------------*/
1.80 cvs 898: static Element MoveDocumentBody (Element el, Document destDoc,
1.85 cvs 899: Document sourceDoc, char *target,
900: char *url, ThotBool deleteTree)
1.1 cvs 901: {
1.58 cvs 902: Element root, ancestor, elem, firstInserted, div;
1.12 cvs 903: Element lastInserted, srce, copy, old, parent, sibling;
904: ElementType elType;
905: NotifyElement event;
906: int checkingMode;
1.47 cvs 907: ThotBool isID;
1.1 cvs 908:
1.67 cvs 909: div = NULL;
1.13 cvs 910: if (target != NULL)
911: {
912: /* locate the target element within the source document */
1.98 vatton 913: root = SearchNAMEattribute (sourceDoc, target, NULL, NULL);
1.13 cvs 914: elType = TtaGetElementType (root);
1.84 cvs 915: isID = (elType.ElTypeNum != HTML_EL_Anchor &&
916: elType.ElTypeNum != HTML_EL_MAP);
1.13 cvs 917: }
918: else
919: {
920: isID = FALSE;
921: /* get the BODY element of source document */
922: root = TtaGetMainRoot (sourceDoc);
923: elType = TtaGetElementType (root);
924: elType.ElTypeNum = HTML_EL_BODY;
925: root = TtaSearchTypedElement (elType, SearchForward, root);
926: }
927:
928: if (root != NULL)
1.12 cvs 929: {
930: /* don't check the abstract tree against the structure schema */
931: checkingMode = TtaGetStructureChecking (destDoc);
932: TtaSetStructureChecking (0, destDoc);
1.58 cvs 933: /* get elem, the ancestor of el which is a child of a DIV or BODY
1.12 cvs 934: element in the destination document. The copied elements will be
935: inserted just before this element. */
1.58 cvs 936: elem = el;
1.12 cvs 937: do
1.1 cvs 938: {
1.12 cvs 939: ancestor = TtaGetParent (elem);
940: if (ancestor != NULL)
941: {
942: elType = TtaGetElementType (ancestor);
943: if (elType.ElTypeNum == HTML_EL_BODY ||
944: elType.ElTypeNum == HTML_EL_Division)
945: ancestor = NULL;
946: else
947: elem = ancestor;
948: }
1.1 cvs 949: }
1.12 cvs 950: while (ancestor != NULL);
951: parent = TtaGetParent (elem);
1.14 cvs 952:
953: /* insert a DIV element */
1.15 cvs 954: elType.ElTypeNum = HTML_EL_Division;
1.16 cvs 955: lastInserted = TtaNewElement (destDoc, elType);
956: TtaInsertSibling (lastInserted, elem, TRUE, destDoc);
1.58 cvs 957: /* this delimits the new inserted part of the document */
1.16 cvs 958: RegisterSubDoc (lastInserted, url);
1.76 kahan 959: CreateTargetAnchor (destDoc, lastInserted, FALSE, FALSE);
1.58 cvs 960: div = lastInserted;
1.14 cvs 961:
1.12 cvs 962: /* do copy */
1.16 cvs 963: firstInserted = NULL;
1.17 cvs 964: if (isID)
965: srce = root;
966: else
967: srce = TtaGetFirstChild (root);
1.12 cvs 968: while (srce != NULL)
1.1 cvs 969: {
1.12 cvs 970: copy = TtaCopyTree (srce, sourceDoc, destDoc, parent);
971: if (copy != NULL)
972: {
1.16 cvs 973: if (firstInserted == NULL)
1.12 cvs 974: /* this is the first copied element. Insert it before elem */
975: {
1.16 cvs 976: TtaInsertFirstChild (©, lastInserted, destDoc);
1.12 cvs 977: firstInserted = copy;
978: }
979: else
980: /* insert the new copied element after the element previously
981: copied */
982: TtaInsertSibling (copy, lastInserted, FALSE, destDoc);
983: lastInserted = copy;
984: /* update the NAMEs and URLs in the copied element */
1.100 quint 985: event.event = TteElemPaste;
1.12 cvs 986: event.document = destDoc;
1.100 quint 987: event.element = copy;
988: event.elementType = TtaGetElementType (copy);
1.12 cvs 989: event.position = sourceDoc;
1.100 quint 990: event.info = 0;
1.12 cvs 991: UpdateURLsInSubtree(&event, copy);
992: }
993: /* get the next element in the source document */
994: old = srce;
995: TtaNextSibling (&srce);
996: if (deleteTree)
997: TtaDeleteTree (old, sourceDoc);
1.13 cvs 998: /* Stop here if the target points to a specific element with an ID */
999: if (isID)
1000: srce = NULL;
1.1 cvs 1001: }
1.12 cvs 1002:
1003: /* delete the element(s) containing the link to the copied document */
1.58 cvs 1004: /* delete the parent element of el and all empty ancestors */
1005: elem = TtaGetParent (el);
1.12 cvs 1006: do
1.1 cvs 1007: {
1.12 cvs 1008: sibling = elem;
1009: TtaNextSibling (&sibling);
1010: if (sibling == NULL)
1011: {
1012: sibling = elem;
1013: TtaPreviousSibling (&sibling);
1014: if (sibling == NULL)
1015: elem = TtaGetParent (elem);
1016: }
1.1 cvs 1017: }
1.12 cvs 1018: while (sibling == NULL);
1019: TtaDeleteTree (elem, destDoc);
1020: /* restore previous chacking mode */
1.47 cvs 1021: TtaSetStructureChecking ((ThotBool)checkingMode, destDoc);
1.12 cvs 1022: }
1.58 cvs 1023: /* return the address of the new division */
1024: return (div);
1.1 cvs 1025: }
1026:
1.29 cvs 1027:
1.58 cvs 1028: /*----------------------------------------------------------------------
1029: CloseMakeBook
1030: ----------------------------------------------------------------------*/
1031: static void CloseMakeBook (Document document)
1032: {
1033: ResetStop (document);
1034: /* update internal links */
1035: SetInternalLinks (document);
1036: /* if the document changed force the browser mode */
1037: if (SubDocs)
1.106 vatton 1038: /* send a warning to the user to avoid to save this document */;
1.58 cvs 1039: /* remove registered sub-documents */
1040: FreeSubDocTable ();
1041: DocBook = 0;
1042: TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), NULL);
1043: }
1044:
1045:
1046: /*----------------------------------------------------------------------
1047: GetIncludedDocuments_callback finishes the GetIncludedDocuments procedure
1048: ----------------------------------------------------------------------*/
1049: void GetIncludedDocuments_callback (int newdoc, int status,
1.85 cvs 1050: char *urlName,
1051: char *outputfile,
1.63 cvs 1052: AHTHeaders *http_headers,
1.58 cvs 1053: void * context)
1.29 cvs 1054: {
1.58 cvs 1055: Element link, div;
1056: IncludeCtxt *ctx, *prev;
1.104 vatton 1057: char *utf8path, *ptr;
1.58 cvs 1058: ThotBool found = FALSE;
1.29 cvs 1059:
1060: /* restore GetIncludedDocuments's context */
1.58 cvs 1061: ctx = (IncludeCtxt *) context;
1.29 cvs 1062: if (!ctx)
1063: return;
1064:
1.58 cvs 1065: div = NULL;
1.29 cvs 1066: link = ctx->link;
1.58 cvs 1067: ptr = ctx->name;
1.104 vatton 1068: utf8path = ctx->utf8path;
1069: if (utf8path)
1.29 cvs 1070: {
1.58 cvs 1071: if (newdoc && newdoc != DocBook)
1.29 cvs 1072: {
1.58 cvs 1073: /* it's not the DocBook itself */
1074: /* copy the target document at the position of the link */
1075: TtaSetDocumentModified (DocBook);
1.104 vatton 1076: div = MoveDocumentBody (link, DocBook, newdoc, ptr, utf8path,
1.58 cvs 1077: (ThotBool)(newdoc == IncludedDocument));
1.29 cvs 1078: }
1.58 cvs 1079: /* global variables */
1080: FreeDocumentResource (IncludedDocument);
1081: TtaCloseDocument (IncludedDocument);
1082: IncludedDocument = 0;
1.29 cvs 1083: }
1.58 cvs 1084:
1.104 vatton 1085: if (div)
1.29 cvs 1086: {
1.58 cvs 1087: /* new starting point for the search */
1088: ctx->link = div;
1089: found = GetIncludedDocuments (div, div, DocBook, ctx);
1.29 cvs 1090: }
1.104 vatton 1091:
1.58 cvs 1092: while (!found && ctx)
1093: {
1094: /* this sub-document has no more inclusion, examine the caller */
1095: div = ctx->div;
1096: link = ctx->link;
1097: prev = ctx->ctxt;
1.104 vatton 1098: TtaFreeMemory (utf8path);
1099: utf8path = NULL;
1.58 cvs 1100: TtaFreeMemory (ctx);
1101: ctx = prev;
1102: found = GetIncludedDocuments (div, link, DocBook, ctx);
1103: }
1104: if (!found)
1105: /* all links are now managed */
1106: CloseMakeBook (DocBook);
1.29 cvs 1107: }
1108:
1.1 cvs 1109: /*----------------------------------------------------------------------
1110: GetIncludedDocuments
1.58 cvs 1111: Look forward within the element el, starting from element link, for a
1112: link (A) with attribute rel="chapter" or rel="subdocument" and replace
1113: that link by the contents of the target document.
1114: Return TRUE if one inclusion is launched.
1.1 cvs 1115: ----------------------------------------------------------------------*/
1.96 vatton 1116: static ThotBool GetIncludedDocuments (Element el, Element link,
1117: Document doc, IncludeCtxt *prev)
1.1 cvs 1118: {
1.58 cvs 1119: ElementType elType;
1120: Attribute attr;
1121: AttributeType attrType;
1122: Document newdoc;
1123: IncludeCtxt *ctx = NULL;
1.104 vatton 1124: char *utf8path, *ptr;
1.29 cvs 1125: int length;
1.58 cvs 1126: ThotBool found = FALSE;
1.29 cvs 1127:
1.58 cvs 1128: /* look for anchors with the attribute rel within the element el */
1129: attr = NULL;
1.96 vatton 1130: attrType.AttrSSchema = TtaGetSSchema ("HTML", doc);
1.58 cvs 1131: elType.ElSSchema = attrType.AttrSSchema;
1132: elType.ElTypeNum = HTML_EL_Anchor;
1.29 cvs 1133:
1.58 cvs 1134: /* Get only one included file each time */
1135: while (link && attr == NULL)
1.29 cvs 1136: {
1.58 cvs 1137: link = TtaSearchTypedElementInTree (elType, SearchForward, el, link);
1138: if (link)
1.29 cvs 1139: {
1.58 cvs 1140: attrType.AttrTypeNum = HTML_ATTR_REL;
1141: attr = TtaGetAttribute (link, attrType);
1142: }
1143: if (attr)
1144: {
1145: length = TtaGetTextAttributeLength (attr);
1.104 vatton 1146: utf8path = (char *)TtaGetMemory (length + 1);
1147: TtaGiveTextAttributeValue (attr, utf8path, &length);
1.58 cvs 1148: /* Valid rel values are rel="chapter" or rel="subdocument" */
1.104 vatton 1149: if (strcasecmp (utf8path, "chapter") &&
1150: strcasecmp (utf8path, "subdocument"))
1.58 cvs 1151: attr = NULL;
1.104 vatton 1152: TtaFreeMemory (utf8path);
1.29 cvs 1153: }
1.58 cvs 1154:
1155: if (attr)
1156: {
1157: /* a link with attribute rel="Chapter" has been found */
1158: attrType.AttrTypeNum = HTML_ATTR_HREF_;
1159: attr = TtaGetAttribute (link, attrType);
1160: }
1161: if (attr)
1162: /* this link has an attribute HREF */
1163: {
1164: length = TtaGetTextAttributeLength (attr);
1.104 vatton 1165: utf8path = (char *)TtaGetMemory (length + 1);
1166: TtaGiveTextAttributeValue (attr, utf8path, &length);
1167: ptr = strrchr (utf8path, '#');
1168: if (ptr)
1.58 cvs 1169: {
1.104 vatton 1170: /* link to a particular position within a document */
1171: if (ptr == utf8path)
1172: {
1173: /* local link */
1174: TtaFreeMemory (utf8path);
1175: utf8path = NULL;
1176: }
1177: else
1178: {
1179: ptr[0] = EOS;
1180: ptr = &ptr[1];
1181: }
1.58 cvs 1182: }
1183:
1.104 vatton 1184: if (utf8path)
1.58 cvs 1185: /* this link designates an external document */
1186: {
1187: /* create a new document and loads the target document */
1.82 cvs 1188: IncludedDocument = TtaNewDocument ("HTML", "tmp");
1.58 cvs 1189: if (IncludedDocument != 0)
1190: {
1.104 vatton 1191: TtaSetStatus (doc, 1, TtaGetMessage (AMAYA, AM_FETCHING), utf8path);
1.101 gully 1192: ctx = (IncludeCtxt *)TtaGetMemory (sizeof (IncludeCtxt));
1.58 cvs 1193: ctx->div = el;
1194: ctx->link = link;
1.104 vatton 1195: ctx->utf8path = utf8path; /* the URL of the document */
1.58 cvs 1196: ctx->name = ptr;
1197: ctx->ctxt = prev; /* previous context */
1198: /* Get the reference of the calling document */
1.96 vatton 1199: SetStopButton (doc);
1.104 vatton 1200: newdoc = GetAmayaDoc (utf8path, NULL, IncludedDocument,
1.96 vatton 1201: doc, CE_MAKEBOOK, FALSE,
1.101 gully 1202: (void (*)(int, int, char*, char*, const AHTHeaders*, void*)) GetIncludedDocuments_callback,
1.104 vatton 1203: (void *) ctx);
1.58 cvs 1204: found = TRUE;
1205: }
1206: }
1207: else
1.104 vatton 1208: TtaFreeMemory (utf8path);
1.58 cvs 1209: }
1.29 cvs 1210: }
1.58 cvs 1211: return (found);
1.1 cvs 1212: }
1213:
1214:
1215: /*----------------------------------------------------------------------
1216: MakeBook
1217: Replace all links in a document which have an attribute REL="chapter"
1.5 cvs 1218: or REL="subdocument" by the corresponding target document.
1.1 cvs 1219: ----------------------------------------------------------------------*/
1.96 vatton 1220: void MakeBook (Document doc, View view)
1.1 cvs 1221: {
1.58 cvs 1222: Element root, body;
1223: ElementType elType;
1.1 cvs 1224:
1.58 cvs 1225: /* stops all current transfers on this document */
1.96 vatton 1226: StopTransfer (doc, 1);
1.58 cvs 1227: /* simulate a transfert in the main document */
1.96 vatton 1228: DocBook = doc;
1.58 cvs 1229: IncludedDocument = 0;
1.96 vatton 1230: root = TtaGetMainRoot (doc);
1.58 cvs 1231: elType = TtaGetElementType (root);
1232: elType.ElTypeNum = HTML_EL_BODY;
1233: body = TtaSearchTypedElement (elType, SearchForward, root);
1.29 cvs 1234:
1.58 cvs 1235: if (body)
1.96 vatton 1236: GetIncludedDocuments (body, body, doc, NULL);
1.1 cvs 1237: }
1.105 vatton 1238:
1239: /*----------------------------------------------------------------------
1240: ----------------------------------------------------------------------*/
1241: void ReadAsUTF_8 (Document doc, View view)
1242: {
1243: ReparseAs (doc, view, FALSE, UTF_8);
1244: }
1245:
1246: /*----------------------------------------------------------------------
1247: ----------------------------------------------------------------------*/
1248: void ReadAsISO_8859_1 (Document doc, View view)
1249: {
1250: ReparseAs (doc, view, FALSE, ISO_8859_1);
1251: }
1252:
1253: /*----------------------------------------------------------------------
1254: ----------------------------------------------------------------------*/
1255: void ReadAsISO_8859_2 (Document doc, View view)
1256: {
1257: ReparseAs (doc, view, FALSE, ISO_8859_2);
1258: }
1259:
1260: /*----------------------------------------------------------------------
1261: ----------------------------------------------------------------------*/
1262: void ReadAsISO_8859_3 (Document doc, View view)
1263: {
1264: ReparseAs (doc, view, FALSE, ISO_8859_3);
1265: }
1266:
1267: /*----------------------------------------------------------------------
1268: ----------------------------------------------------------------------*/
1269: void ReadAsISO_8859_4 (Document doc, View view)
1270: {
1271: ReparseAs (doc, view, FALSE, ISO_8859_4);
1272: }
1273:
1274: /*----------------------------------------------------------------------
1275: ----------------------------------------------------------------------*/
1276: void ReadAsISO_8859_5 (Document doc, View view)
1277: {
1278: ReparseAs (doc, view, FALSE, ISO_8859_5);
1279: }
1280:
1281: /*----------------------------------------------------------------------
1282: ----------------------------------------------------------------------*/
1283: void ReadAsISO_8859_6 (Document doc, View view)
1284: {
1285: ReparseAs (doc, view, FALSE, ISO_8859_6);
1286: }
1287:
1288: /*----------------------------------------------------------------------
1289: ----------------------------------------------------------------------*/
1290: void ReadAsISO_8859_7 (Document doc, View view)
1291: {
1292: ReparseAs (doc, view, FALSE, ISO_8859_7);
1293: }
1294:
1295: /*----------------------------------------------------------------------
1296: ----------------------------------------------------------------------*/
1297: void ReadAsISO_8859_8 (Document doc, View view)
1298: {
1299: ReparseAs (doc, view, FALSE, ISO_8859_8);
1300: }
1301:
1302: /*----------------------------------------------------------------------
1303: ----------------------------------------------------------------------*/
1304: void ReadAsISO_8859_9 (Document doc, View view)
1305: {
1306: ReparseAs (doc, view, FALSE, ISO_8859_9);
1307: }
1308:
1309: /*----------------------------------------------------------------------
1310: ----------------------------------------------------------------------*/
1311: void ReadAsISO_8859_15 (Document doc, View view)
1312: {
1313: ReparseAs (doc, view, FALSE, ISO_8859_15);
1314: }
1315:
1316: /*----------------------------------------------------------------------
1317: ----------------------------------------------------------------------*/
1318: void ReadAsKOI8_R (Document doc, View view)
1319: {
1320: ReparseAs (doc, view, FALSE, KOI8_R);
1321: }
1322:
1323: /*----------------------------------------------------------------------
1324: ----------------------------------------------------------------------*/
1325: void ReadAsWINDOWS_1250 (Document doc, View view)
1326: {
1327: ReparseAs (doc, view, FALSE, WINDOWS_1250);
1328: }
1329:
1330: /*----------------------------------------------------------------------
1331: ----------------------------------------------------------------------*/
1332: void ReadAsWINDOWS_1251 (Document doc, View view)
1333: {
1334: ReparseAs (doc, view, FALSE, WINDOWS_1251);
1335: }
1336:
1337: /*----------------------------------------------------------------------
1338: ----------------------------------------------------------------------*/
1339: void ReadAsWINDOWS_1252 (Document doc, View view)
1340: {
1341: ReparseAs (doc, view, FALSE, WINDOWS_1252);
1342: }
1343:
1344: /*----------------------------------------------------------------------
1345: ----------------------------------------------------------------------*/
1346: void ReadAsWINDOWS_1253 (Document doc, View view)
1347: {
1348: ReparseAs (doc, view, FALSE, WINDOWS_1253);
1349: }
1350:
1351: /*----------------------------------------------------------------------
1352: ----------------------------------------------------------------------*/
1353: void ReadAsWINDOWS_1254 (Document doc, View view)
1354: {
1355: ReparseAs (doc, view, FALSE, WINDOWS_1254);
1356: }
1357:
1358: /*----------------------------------------------------------------------
1359: ----------------------------------------------------------------------*/
1360: void ReadAsWINDOWS_1255 (Document doc, View view)
1361: {
1362: ReparseAs (doc, view, FALSE, WINDOWS_1255);
1363: }
1364:
1365: /*----------------------------------------------------------------------
1366: ----------------------------------------------------------------------*/
1367: void ReadAsWINDOWS_1256 (Document doc, View view)
1368: {
1369: ReparseAs (doc, view, FALSE, WINDOWS_1256);
1370: }
1371:
1372: /*----------------------------------------------------------------------
1373: ----------------------------------------------------------------------*/
1374: void ReadAsWINDOWS_1257 (Document doc, View view)
1375: {
1376: ReparseAs (doc, view, FALSE, WINDOWS_1257);
1377: }
1378:
1379: /*----------------------------------------------------------------------
1380: ----------------------------------------------------------------------*/
1381: void ReadAsISO_2022_JP (Document doc, View view)
1382: {
1383: ReparseAs (doc, view, FALSE, ISO_2022_JP);
1384: }
1385:
1386: /*----------------------------------------------------------------------
1387: ----------------------------------------------------------------------*/
1388: void ReadAsEUC_JP (Document doc, View view)
1389: {
1390: ReparseAs (doc, view, FALSE, EUC_JP);
1391: }
1392:
1393: /*----------------------------------------------------------------------
1394: ----------------------------------------------------------------------*/
1395: void ReadAsSHIFT_JIS (Document doc, View view)
1396: {
1397: ReparseAs (doc, view, FALSE, SHIFT_JIS);
1398: }
Webmaster