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