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

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

Webmaster