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

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

Webmaster