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

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

Webmaster