Annotation of Amaya/amaya/HTMLbook.c, revision 1.96

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

Webmaster