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

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

Webmaster