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

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

Webmaster