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

1.1       cvs         1: /*
                      2:  *
1.104     vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2004
1.1       cvs         4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
1.65      cvs         7:  
1.1       cvs         8: /*
                      9:  * Initialization functions and button functions of Amaya application.
                     10:  *
                     11:  * Authors: V. Quint, I. Vatton
1.85      cvs        12:  *          R. Guetari (W3C/INRIA) - Windows version.
1.1       cvs        13:  */
                     14: 
                     15: 
                     16: /* Included headerfiles */
1.101     gully      17: #define THOT_EXPORT extern
1.1       cvs        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.101     gully      22: #include "init_f.h"
1.1       cvs        23: 
1.25      cvs        24: /* structure to register sub-documents in MakeBook function*/
                     25: typedef struct _SubDoc
                     26:   {
                     27:      struct _SubDoc  *SDnext;
                     28:      Element          SDel;
1.85      cvs        29:      char            *SDname;
1.25      cvs        30:   }SubDoc;
                     31: 
1.29      cvs        32: /* the structure used for the GetIncludedDocuments_callback function */
1.58      cvs        33: typedef struct _IncludeCtxt
1.53      cvs        34: {
1.58      cvs        35:   Element              div; /* enclosing element for the search */
                     36:   Element              link; /* current processed link */
1.104     vatton     37:   char                *utf8path; /* called url */
1.85      cvs        38:   char                 *name; /* the fragment name */
1.58      cvs        39:   struct _IncludeCtxt  *ctxt; /* the previous context */
                     40: } IncludeCtxt;
1.29      cvs        41: 
1.55      cvs        42: /* shared with windialogapi.c */
                     43: ThotBool         PrintURL;
                     44: ThotBool        NumberLinks;
                     45: ThotBool        WithToC;
                     46: ThotBool         IgnoreCSS;
                     47: 
1.25      cvs        48: static struct _SubDoc  *SubDocs;
1.85      cvs        49: static char             PSfile[MAX_PATH];
                     50: static char             PPrinter[MAX_PATH];
                     51: static char            *DocPrintURL;
1.53      cvs        52: static Document                DocPrint;
1.2       cvs        53: static int              PaperPrint;
1.73      cvs        54: static int              ManualFeed = PP_OFF;
1.71      cvs        55: static int              Orientation;
1.2       cvs        56: static int              PageSize;
1.71      cvs        57: static int              PagePerSheet;
1.1       cvs        58: 
                     59: #include "init_f.h"
                     60: #include "HTMLactions_f.h"
                     61: #include "HTMLbook_f.h"
                     62: #include "HTMLedit_f.h"
1.25      cvs        63: #include "HTMLhistory_f.h"
1.51      cvs        64: #include "UIcss_f.h"
1.1       cvs        65: 
1.103     cvs        66: #ifdef _WINGUI 
1.37      cvs        67: #include "wininclude.h"
1.103     cvs        68: #endif /* _WINGUI */
1.31      cvs        69: 
1.101     gully      70: static ThotBool GetIncludedDocuments (Element el, Element link,
                     71:                                      Document doc, IncludeCtxt *prev);
1.1       cvs        72: /*----------------------------------------------------------------------
1.94      vatton     73:   RedisplayDocument redisplays a view of a document
                     74:   ----------------------------------------------------------------------*/
                     75: void  RedisplayDocument(Document doc, View view)
                     76: {
1.95      vatton     77:   Element             el;
                     78:   int                 position;
                     79:   int                 distance;
                     80: 
                     81:   /* get the current position in the document */
                     82:   position = RelativePosition (doc, &distance);
1.94      vatton     83:   TtaSetDisplayMode (doc, NoComputedDisplay);
                     84:   TtaSetDisplayMode (doc, DisplayImmediately);
1.95      vatton     85:   /* show the document at the same position */
                     86:   el = ElementAtPosition (doc, position);
                     87:   TtaShowElement (doc, view, el, distance);
1.94      vatton     88: }
                     89: 
                     90: 
                     91: /*----------------------------------------------------------------------
1.16      cvs        92:   RegisterSubDoc adds a new entry in SubDoc table.
                     93:   ----------------------------------------------------------------------*/
1.94      vatton     94: static void RegisterSubDoc (Element el, char *url)
1.16      cvs        95: {
                     96:   struct _SubDoc  *entry, *last;
                     97: 
                     98:   if (url == NULL || url[0] == EOS)
                     99:     return;
                    100: 
1.101     gully     101:   entry = (struct _SubDoc *)TtaGetMemory (sizeof (struct _SubDoc));
1.16      cvs       102:   entry->SDnext = NULL;
                    103:   entry->SDel = el;
1.83      cvs       104:   entry->SDname = TtaStrdup (url);
1.16      cvs       105: 
                    106:   if (SubDocs == NULL)
                    107:     SubDocs = entry;
                    108:   else
                    109:     {
                    110:       last = SubDocs;
                    111:       while (last->SDnext != NULL)
                    112:        last = last->SDnext;
                    113:       last->SDnext = entry;
                    114:     }
                    115: }
                    116: 
                    117: 
                    118: /*----------------------------------------------------------------------
                    119:   SearchSubDoc searches whether a document name is registered or not
                    120:   within the SubDoc table.
                    121:   Return the DIV element that correspond to the sub-document or NULL.
                    122:   ----------------------------------------------------------------------*/
1.94      vatton    123: static Element SearchSubDoc (char *url)
1.16      cvs       124: {
                    125:   Element          el;
                    126:   struct _SubDoc  *entry;
1.47      cvs       127:   ThotBool         docFound;
1.16      cvs       128: 
                    129:   if (url == NULL || url[0] == EOS)
                    130:     return (NULL);
                    131: 
                    132:   entry = SubDocs;
                    133:   docFound = FALSE;
                    134:   el = NULL;
                    135:   while (!docFound && entry != NULL)
                    136:     {
1.83      cvs       137:       docFound = (strcmp (url, entry->SDname) == 0);
1.16      cvs       138:       if (!docFound)
                    139:        entry = entry->SDnext;
                    140:       else
                    141:        /* document found -> return the DIV element */
                    142:        el = entry->SDel;
                    143:     }
                    144:   return (el);
                    145: }
                    146: 
                    147: /*----------------------------------------------------------------------
                    148:   FreeSubDocTable frees all entries in SubDoc table.
                    149:   ----------------------------------------------------------------------*/
1.94      vatton    150: static void FreeSubDocTable ()
1.16      cvs       151: {
                    152:   struct _SubDoc  *entry, *last;
                    153: 
                    154:   entry = SubDocs;
                    155:   while (entry != NULL)
                    156:     {
                    157:       last = entry;
                    158:       entry = entry->SDnext;
                    159:       TtaFreeMemory (last->SDname);
                    160:       TtaFreeMemory (last);
                    161:     }
                    162:   SubDocs = NULL;
                    163: }
                    164: 
                    165: 
                    166: /*----------------------------------------------------------------------
1.1       cvs       167:   SetInternalLinks
1.8       cvs       168:   Associate an InternalLink attribute with all anchor (A) elements of the
                    169:   document which designate an element in the same document.
1.1       cvs       170:   InternalLink is a Thot reference attribute that links a source and a
                    171:   target anchor and that allows P schemas to display and print cross-references
                    172:   ----------------------------------------------------------------------*/
1.94      vatton    173: void SetInternalLinks (Document document)
1.1       cvs       174: {
1.32      cvs       175:   Element              el, div, link, target, sibling;
                    176:   ElementType          elType, linkType;
1.16      cvs       177:   Attribute            HrefAttr, IntLinkAttr;
1.17      cvs       178:   Attribute             attr, ExtLinkAttr;
1.16      cvs       179:   AttributeType                attrType;
1.85      cvs       180:   char                *text, *ptr, *url; 
1.83      cvs       181:   char                  number[10];
                    182:   char                  value[MAX_LENGTH];
1.25      cvs       183:   int                  length, i, volume;
                    184:   int                   status, position;
1.47      cvs       185:   ThotBool              split;
1.1       cvs       186: 
1.16      cvs       187:   /* Remember the current status of the document */
                    188:   status = TtaIsDocumentModified (document);
1.32      cvs       189:   el = TtaGetMainRoot (document);
                    190:   volume = TtaGetElementVolume (el);
                    191:   elType = TtaGetElementType (el);
                    192:   elType.ElTypeNum = HTML_EL_AnyLink;
1.16      cvs       193:   attrType.AttrSSchema = elType.ElSSchema;
1.32      cvs       194:   /* looks for all links in the document */
1.16      cvs       195:   link = el;
                    196:   while (link != NULL)
                    197:     {
1.25      cvs       198:       /* display the progression of the work */
                    199:       el = link;
                    200:       position = 0;
                    201:       while (el != NULL)
                    202:        {
                    203:          sibling = el;
                    204:          do
                    205:            {
                    206:              /* add volume of each previous element */
                    207:              TtaPreviousSibling (&sibling);
                    208:              if (sibling != NULL)
                    209:                position += TtaGetElementVolume (sibling);
                    210:            }
                    211:          while (sibling != NULL);
                    212:          el = TtaGetParent (el);
                    213:        }
1.83      cvs       214:       sprintf (number, "%d", position*100/volume);
1.25      cvs       215:       TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_UPDATED_LINK), number);
                    216:       TtaHandlePendingEvents ();
1.16      cvs       217:       link = TtaSearchTypedElement (elType, SearchForward, link);
                    218:       if (link != NULL)
1.32      cvs       219:        /* a link has been found */
1.16      cvs       220:        {
1.32      cvs       221:          linkType = TtaGetElementType (link);
                    222:          if (linkType.ElTypeNum == HTML_EL_Anchor)
                    223:             attrType.AttrTypeNum = HTML_ATTR_HREF_;
                    224:          else
                    225:             attrType.AttrTypeNum = HTML_ATTR_cite;
1.16      cvs       226:          HrefAttr = TtaGetAttribute (link, attrType);
                    227:          attrType.AttrTypeNum = HTML_ATTR_InternalLink;
                    228:          IntLinkAttr = TtaGetAttribute (link, attrType);
                    229:          attrType.AttrTypeNum = HTML_ATTR_ExternalLink;
                    230:          ExtLinkAttr = TtaGetAttribute (link, attrType);
                    231:          if (HrefAttr == NULL)
1.32      cvs       232:            /* this element is not a link (no href or cite attribute) */
1.16      cvs       233:            /* remove attributes InternalLink and ExternalLink if they
                    234:               are present */
                    235:            {
1.8       cvs       236:              if (IntLinkAttr != NULL)
1.16      cvs       237:                TtaRemoveAttribute (link, IntLinkAttr, document);
                    238:              if (ExtLinkAttr != NULL)
                    239:                TtaRemoveAttribute (link, ExtLinkAttr, document);          
                    240:            }
                    241:          else
1.32      cvs       242:            /* this element has an HREF or cite attribute */
1.16      cvs       243:            {
                    244:              length = TtaGetTextAttributeLength (HrefAttr);
1.101     gully     245:              text = (char *)TtaGetMemory (length + 1);
1.16      cvs       246:              TtaGiveTextAttributeValue (HrefAttr, text, &length);
                    247: 
                    248:              /* does an external link become an internal link ? */
1.25      cvs       249:              if (document == DocBook && SubDocs != NULL)
1.16      cvs       250:                {
1.83      cvs       251:                  ptr = strrchr (text, '#');
1.16      cvs       252:                  url = text;
1.18      cvs       253:                  split = FALSE;
1.16      cvs       254:                  if (ptr == text)
                    255:                      /* a local link */
                    256:                      url = NULL;
1.17      cvs       257:                  else if (ptr != NULL)
1.16      cvs       258:                    {
                    259:                      /* split url and name part */
                    260:                      ptr[0] = EOS;
                    261:                      split = TRUE;
                    262:                    }
                    263: 
                    264:                  /* Is it a sub-document */
                    265:                  div = SearchSubDoc (url);
                    266:                  if (split)
                    267:                    /* retore the mark */
                    268:                    ptr[0] = '#';
                    269: 
                    270:                  if (div == NULL)
                    271:                    {
                    272:                      /* it's not a sub-document */
                    273:                      if (url == NULL)
                    274:                        /* a local link */
                    275:                        ptr = &text[1];
                    276:                      else
                    277:                        /* still an externa; link */
                    278:                        ptr = NULL;
                    279:                    }
                    280:                  else
                    281:                    {
                    282:                      /* this link becomes internal */
1.17      cvs       283:                      if (ptr != NULL)
1.16      cvs       284:                        {
1.17      cvs       285:                          /* get the target name */
1.83      cvs       286:                          strcpy (value, ptr);
                    287:                          length = strlen (value);
1.17      cvs       288:                          /* check whether the name changed */
                    289:                          i = 0;
1.98      vatton    290:                          target = SearchNAMEattribute (document, &value[1], NULL, NULL);
1.17      cvs       291:                          while (target != NULL)
1.16      cvs       292:                            {
1.17      cvs       293:                              /* is it the right NAME */
                    294:                              if (TtaIsAncestor (target, div))
                    295:                                target = NULL;
                    296:                              else
                    297:                                {
                    298:                                  /* continue the search */
                    299:                                  i++;
1.83      cvs       300:                                  sprintf (&value[length], "%d", i);
1.32      cvs       301:                                  target = SearchNAMEattribute (document,
1.98      vatton    302:                                                        &value[1], NULL, NULL);
1.17      cvs       303:                                }
1.16      cvs       304:                            }
                    305:                        }
1.17      cvs       306:                      else
                    307:                        {
                    308:                          /* get the DIV name */
                    309:                          attrType.AttrTypeNum = HTML_ATTR_ID;
                    310:                          attr = TtaGetAttribute (div, attrType);
                    311:                          length = 200;
                    312:                          value[0] = '#';
                    313:                          TtaGiveTextAttributeValue (attr, &value[1], &length);
                    314:                        }
1.16      cvs       315:                      ptr = &value[1];
                    316:                      TtaSetAttributeText (HrefAttr, value, link, document);
                    317:                    }
                    318:                }
                    319:              else if (text[0] == '#')
                    320:                  ptr = &text[1];
                    321:              else
                    322:                ptr = NULL;
                    323: 
                    324:              if (ptr != NULL)
                    325:                /* it's an internal link. Attach an attribute InternalLink */
                    326:                /* to the link, if this attribute does not exist yet */
                    327:                {
                    328:                  if (IntLinkAttr == NULL)
                    329:                    {
                    330:                      attrType.AttrTypeNum = HTML_ATTR_InternalLink;
                    331:                      IntLinkAttr = TtaNewAttribute (attrType);
                    332:                      TtaAttachAttribute (link, IntLinkAttr, document);
                    333:                    }
                    334:                  /* looks for the target element */
1.98      vatton    335:                  target = SearchNAMEattribute (document, ptr, NULL, NULL);
1.16      cvs       336:                  if (target != NULL)
                    337:                    /* set the Thot link */
1.32      cvs       338:                    TtaSetAttributeReference (IntLinkAttr, link, document,
                    339:                                              target, document);
1.16      cvs       340:                }
                    341:              else
                    342:                /* it's an external link */
                    343:                {
                    344:                  /* Remove the InternalLink attribute if it is present */
                    345:                  if (IntLinkAttr != NULL)
                    346:                    TtaRemoveAttribute (link, IntLinkAttr, document);
                    347:                  /* create an ExternalLink attribute if there is none */
                    348:                  if (ExtLinkAttr == NULL)
                    349:                    {
                    350:                      attrType.AttrTypeNum = HTML_ATTR_ExternalLink;
                    351:                      ExtLinkAttr = TtaNewAttribute (attrType);
                    352:                      TtaAttachAttribute (link, ExtLinkAttr, document);
                    353:                    }
                    354:                }
                    355:              TtaFreeMemory (text);
                    356:            }
                    357:        }
                    358:     }
                    359:   /* Reset document status */
                    360:   if (!status)
                    361:     TtaSetDocumentUnmodified (document);
1.3       cvs       362: }
                    363: 
                    364: /*----------------------------------------------------------------------
                    365:   CheckPrintingDocument reinitialize printing parameters as soon as
                    366:   the printing document changes.
                    367:   ----------------------------------------------------------------------*/
1.89      vatton    368: static void CheckPrintingDocument (Document document)
1.3       cvs       369: {
1.83      cvs       370:   char         docName[MAX_LENGTH];
                    371:   char        *ptr; 
                    372:   char         suffix[MAX_LENGTH];
1.81      cvs       373:   int            lg;
                    374: 
                    375:   if (DocPrint != document || DocPrintURL == NULL ||
1.83      cvs       376:       strcmp(DocPrintURL, DocumentURLs[document]))
1.81      cvs       377:     {
                    378:       /* initialize print parameters */
                    379:       TtaFreeMemory (DocPrintURL);
                    380:       DocPrint = document;
                    381:       DocPrintURL = TtaStrdup (DocumentURLs[document]);
                    382:       
                    383:       /* define the new default PS file */
                    384:       ptr = TtaGetEnvString ("APP_TMPDIR");
                    385:       if (ptr != NULL && TtaCheckDirectory (ptr))
1.83      cvs       386:        strcpy (PSfile, ptr);
1.81      cvs       387:       else
1.83      cvs       388:        strcpy (PSfile, TtaGetDefEnvString ("APP_TMPDIR"));
                    389:       lg = strlen (PSfile);
                    390:       if (PSfile[lg - 1] == DIR_SEP)
                    391:        PSfile[--lg] = EOS;
                    392:       strcpy (docName, TtaGetDocumentName (document));
1.90      vatton    393:       TtaExtractSuffix (docName, suffix);
1.83      cvs       394:       sprintf (&PSfile[lg], "%c%s.ps", DIR_SEP, docName);
1.81      cvs       395:       TtaSetPsFile (PSfile);
                    396:     }
1.3       cvs       397: }
                    398: 
                    399: /*----------------------------------------------------------------------
1.72      cvs       400:    PrintDocument prints the document using predefined parameters.
1.3       cvs       401:    ----------------------------------------------------------------------*/  
1.91      vatton    402: static void PrintDocument (Document doc, View view)
1.3       cvs       403: {
1.34      cvs       404:   AttributeType      attrType;
1.84      cvs       405:   ElementType        elType;
1.34      cvs       406:   Attribute          attr;
1.84      cvs       407:   Element            el, docEl;
1.85      cvs       408:   char              *files, *dir;
1.84      cvs       409:   char               viewsToPrint[MAX_PATH];
1.47      cvs       410:   ThotBool           status, textFile;
1.3       cvs       411: 
1.38      cvs       412:   textFile = (DocumentTypes[doc] == docText ||
1.75      cvs       413:               DocumentTypes[doc] == docSource ||
1.74      cvs       414:              DocumentTypes[doc] == docCSS);
1.38      cvs       415: 
1.81      cvs       416:   /* initialize printing information */
1.75      cvs       417:   CheckPrintingDocument (doc);
1.83      cvs       418:   strcpy (viewsToPrint, "Formatted_view ");
1.75      cvs       419:   if (DocumentTypes[doc] == docHTML && WithToC)
1.83      cvs       420:     strcat (viewsToPrint, "Table_of_contents ");
1.75      cvs       421:   
                    422:   if (textFile)
                    423:     {
                    424:       if (PageSize == PP_A4)
                    425:        {
                    426:          if (Orientation == PP_Landscape)
1.82      cvs       427:            TtaSetPrintSchema ("TextFilePL");
1.75      cvs       428:          else
1.82      cvs       429:            TtaSetPrintSchema ("TextFilePP");
1.75      cvs       430:        }
                    431:       else
                    432:        {
                    433:          if (Orientation == PP_Landscape)
1.82      cvs       434:            TtaSetPrintSchema ("TextFileUSL");
1.75      cvs       435:          else
1.82      cvs       436:            TtaSetPrintSchema ("TextFilePPUS");
1.75      cvs       437:        }
                    438:     }
                    439:   else if (DocumentTypes[doc] == docSVG)
1.88      vatton    440:     TtaSetPrintSchema ("SVGP");
1.75      cvs       441:   else if (DocumentTypes[doc] == docMath)
1.82      cvs       442:     TtaSetPrintSchema ("MathMLP");
1.75      cvs       443:   else if (DocumentTypes[doc] == docAnnot)
1.82      cvs       444:     TtaSetPrintSchema ("AnnotP");
1.75      cvs       445:   else if (DocumentTypes[doc] == docHTML && NumberLinks)
                    446:     /* display numbered links */
                    447:     {
                    448:       /* associate an attribute InternalLink with all anchors refering
                    449:         a target in the same document.  This allows P schemas to work
                    450:         properly */
                    451:       SetInternalLinks (DocPrint);
                    452:       if (PageSize == PP_A4)
                    453:        {
                    454:          if (Orientation == PP_Landscape)
1.82      cvs       455:            TtaSetPrintSchema ("HTMLPLL");
1.75      cvs       456:          else
1.82      cvs       457:            TtaSetPrintSchema ("HTMLPLP");
1.75      cvs       458:        }
                    459:       else
                    460:        {
                    461:          if (Orientation == PP_Landscape)
1.82      cvs       462:            TtaSetPrintSchema ("HTMLUSLL");
1.75      cvs       463:          else
1.82      cvs       464:            TtaSetPrintSchema ("HTMLPLPUS");
1.75      cvs       465:        }
1.83      cvs       466:       strcat (viewsToPrint, "Links_view ");
1.75      cvs       467:     }
                    468:   else if (PageSize == PP_A4)
                    469:     {
                    470:       if (Orientation == PP_Landscape)
1.82      cvs       471:        TtaSetPrintSchema ("HTMLPL");
1.75      cvs       472:       else
1.82      cvs       473:        TtaSetPrintSchema ("HTMLPP");
1.75      cvs       474:     }
                    475:   else
                    476:     {
                    477:       if (Orientation == PP_Landscape)
1.82      cvs       478:        TtaSetPrintSchema ("HTMLUSL");
1.75      cvs       479:       else
1.82      cvs       480:        TtaSetPrintSchema ("HTMLPPUS");
1.75      cvs       481:     }    
                    482:   
                    483:   status = TtaIsDocumentModified (doc);
1.71      cvs       484: 
1.75      cvs       485:   if (textFile || DocumentTypes[doc] == docImage ||
                    486:       DocumentTypes[doc] == docHTML)
                    487:     {
                    488:       /* post or remove the PrintURL attribute */
                    489:       attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
1.84      cvs       490:       elType.ElSSchema = attrType.AttrSSchema;
1.75      cvs       491:       if (textFile)
1.84      cvs       492:        {
                    493:          elType. ElTypeNum = TextFile_EL_TextFile;
                    494:          attrType.AttrTypeNum = TextFile_ATTR_PrintURL;
                    495:        }
1.75      cvs       496:       else
1.84      cvs       497:        {
                    498:          elType. ElTypeNum = HTML_EL_HTML;
                    499:          attrType.AttrTypeNum = HTML_ATTR_PrintURL;
                    500:        }
                    501:       docEl = TtaGetMainRoot (doc);
                    502:       el = TtaSearchTypedElement (elType, SearchForward, docEl);
1.75      cvs       503:       attr = TtaGetAttribute (el, attrType);
                    504:       if (!attr && PrintURL)
                    505:        {
                    506:          attr = TtaNewAttribute (attrType);
                    507:          TtaAttachAttribute (el, attr, doc);
                    508:        }
                    509:       if (attr && !PrintURL)
                    510:        TtaRemoveAttribute (el, attr, doc);
                    511:     }
                    512:   
                    513:   /* get the path dir where css files have to be stored */
1.79      cvs       514:   if ((DocumentTypes[doc] == docHTML || DocumentTypes[doc] == docSVG) &&
1.78      cvs       515:       !IgnoreCSS)
1.75      cvs       516:     {
                    517:       TtaGetPrintNames (&files, &dir);
                    518:       /* store css files and get the list of names */
                    519:       files = CssToPrint (doc, dir);
                    520:     }
                    521:   else
                    522:     files = NULL;
                    523:   TtaPrint (DocPrint, viewsToPrint, files);
                    524:   if (files)
                    525:     TtaFreeMemory (files);
                    526:   if (!status)
                    527:     TtaSetDocumentUnmodified (doc);
1.1       cvs       528: }
                    529: 
1.45      cvs       530: /*----------------------------------------------------------------------
                    531:    PrintAs prints the document using predefined parameters.
                    532:    ----------------------------------------------------------------------*/  
1.89      vatton    533: void PrintAs (Document doc, View view)
1.45      cvs       534: {
1.103     cvs       535: #ifdef _WINGUI
1.72      cvs       536:   DocPrint = doc;
                    537:   ReusePrinterDC ();
1.103     cvs       538: #else /* _WINGUI */
1.45      cvs       539:   PrintDocument (doc, view);
1.103     cvs       540: #endif /* _WINGUI */
1.45      cvs       541: }
1.1       cvs       542: 
                    543: /*----------------------------------------------------------------------
1.92      quint     544:    CallbackImage handle return of Print form.                   
1.1       cvs       545:   ----------------------------------------------------------------------*/
1.85      cvs       546: void CallbackPrint (int ref, int typedata, char *data)
1.1       cvs       547: {
                    548:   int                 val;
                    549: 
                    550:   val = (int) data;
1.53      cvs       551:   switch (ref - BasePrint)
1.1       cvs       552:     {
1.69      cvs       553:     case FormPrint:
                    554:       TtaDestroyDialogue (BasePrint + FormPrint);
1.1       cvs       555:       switch (val)
                    556:        {
                    557:        case 1:
1.53      cvs       558:          TtaSetPrintCommand (PPrinter);
1.81      cvs       559:          TtaSetPsFile (PSfile);
1.40      cvs       560:          /* update the environment variable */
1.53      cvs       561:          TtaSetEnvString ("THOTPRINT", PPrinter, TRUE);
                    562:          PrintDocument (DocPrint, 1);
1.1       cvs       563:          break;
                    564:        default:
                    565:          break;
                    566:        }
                    567:       break;
1.69      cvs       568:     case PrintOptions:
1.1       cvs       569:       switch (val)
                    570:        {
                    571:        case 0:
                    572:          /* Manual feed option */
1.2       cvs       573:          if (ManualFeed == PP_ON)
                    574:            ManualFeed = PP_OFF;
                    575:          else
                    576:            ManualFeed = PP_ON;
1.81      cvs       577:          TtaSetPrintParameter (PP_ManualFeed, ManualFeed);
1.1       cvs       578:          break;
                    579:        case 1:
                    580:          /* Toc option */
1.53      cvs       581:          WithToC = !WithToC;
1.1       cvs       582:          break;
                    583:        case 2:
1.53      cvs       584:          /* NumberLinks option */
                    585:          NumberLinks = !NumberLinks;
1.34      cvs       586:        case 3:
                    587:          /* URL option */
1.53      cvs       588:          PrintURL = !PrintURL;
                    589:          break;
                    590:        case 4:
                    591:          /* CSS option */
                    592:          IgnoreCSS = !IgnoreCSS;
1.1       cvs       593:          break;
                    594:        }
                    595:       break;
1.69      cvs       596:     case PaperFormat:
1.1       cvs       597:       /* page size submenu */
                    598:       switch (val)
                    599:        {
                    600:        case 0:
1.2       cvs       601:          PageSize = PP_A4;
1.1       cvs       602:          break;
                    603:        case 1:
1.2       cvs       604:          PageSize = PP_US;
1.1       cvs       605:          break;
                    606:        }
1.81      cvs       607:       TtaSetPrintParameter (PP_PaperSize, PageSize);
1.1       cvs       608:       break;
1.71      cvs       609:     case PaperOrientation:
                    610:       /* orientation submenu */
                    611:       Orientation = val;
1.81      cvs       612:       TtaSetPrintParameter (PP_Orientation, Orientation);
1.71      cvs       613:       break;
                    614:     case PPagesPerSheet:
                    615:       /* pages per sheet submenu */
                    616:       switch (val)
                    617:        {
                    618:        case 0:
                    619:          PagePerSheet = 1;
                    620:          break;
                    621:        case 1:
                    622:          PagePerSheet = 2;
                    623:          break;
                    624:        case 2:
                    625:          PagePerSheet = 4;
                    626:          break;
                    627:        }
1.81      cvs       628:       TtaSetPrintParameter (PP_PagesPerSheet, PagePerSheet);
1.71      cvs       629:       break;
1.69      cvs       630:     case PrintSupport:
1.1       cvs       631:       /* paper print/save PostScript submenu */
                    632:       switch (val)
                    633:        {
                    634:        case 0:
1.2       cvs       635:          if (PaperPrint == PP_PS)
1.1       cvs       636:            {
1.2       cvs       637:              PaperPrint = PP_PRINTER;
1.103     cvs       638: #ifndef _WINGUI
1.69      cvs       639:              TtaSetTextForm (BasePrint + PPrinterName, PPrinter);
1.103     cvs       640: #endif /* !_WINGUI */
1.81      cvs       641:              TtaSetPrintParameter (PP_Destination, PaperPrint);
1.1       cvs       642:            }
                    643:          break;
                    644:        case 1:
1.2       cvs       645:          if (PaperPrint == PP_PRINTER)
1.1       cvs       646:            {
1.2       cvs       647:              PaperPrint = PP_PS;
1.103     cvs       648: #ifndef _WINGUI
1.81      cvs       649:              TtaSetTextForm (BasePrint + PPrinterName, PSfile);
1.103     cvs       650: #endif /* !_WINGUI */
1.81      cvs       651:              TtaSetPrintParameter (PP_Destination, PaperPrint);
1.1       cvs       652:            }
                    653:          break;
                    654:        }
                    655:       break;
1.69      cvs       656:     case PPrinterName:
1.1       cvs       657:       if (data[0] != '\0')
1.80      cvs       658:        {
1.2       cvs       659:        if (PaperPrint == PP_PRINTER)
1.40      cvs       660:            /* text capture zone for the printer name */
1.83      cvs       661:            strncpy (PPrinter, data, MAX_PATH);
1.1       cvs       662:        else
                    663:          /* text capture zone for the name of the PostScript file */
1.83      cvs       664:          strncpy (PSfile, data, MAX_PATH);
1.80      cvs       665:        }
1.1       cvs       666:       break;
                    667:     }
                    668: }
                    669: 
                    670: /*----------------------------------------------------------------------
                    671:   ----------------------------------------------------------------------*/
1.94      vatton    672: void InitPrint (void)
1.1       cvs       673: {
1.83      cvs       674:   char* ptr;
1.1       cvs       675: 
1.101     gully     676:    BasePrint = TtaSetCallback ((Proc)CallbackPrint, PRINT_MAX_REF);
1.53      cvs       677:    DocPrint = 0;
1.81      cvs       678:    DocPrintURL = NULL;
1.1       cvs       679: 
                    680:    /* read default printer variable */
1.52      cvs       681:    ptr = TtaGetEnvString ("THOTPRINT");
1.1       cvs       682:    if (ptr == NULL)
1.83      cvs       683:      strcpy (PPrinter, "");
1.1       cvs       684:    else
1.83      cvs       685:      strcpy (PPrinter, ptr);
1.81      cvs       686:    TtaSetPrintCommand (PPrinter);
1.2       cvs       687:    PaperPrint = PP_PRINTER;
1.81      cvs       688:    TtaSetPrintParameter (PP_Destination, PaperPrint);
                    689: 
                    690:    /* define the new default PrintSchema */
                    691:    NumberLinks = FALSE;
                    692:    WithToC = FALSE;
                    693:    IgnoreCSS = FALSE;
1.53      cvs       694:    PrintURL = TRUE;
1.81      cvs       695:    PageSize = TtaGetPrintParameter (PP_PaperSize);       
1.82      cvs       696:    TtaSetPrintSchema ("");
1.81      cvs       697:    /* no manual feed */
                    698:    ManualFeed = PP_OFF;
                    699:    TtaSetPrintParameter (PP_ManualFeed, ManualFeed);
                    700:    PagePerSheet = 1;
                    701:    TtaSetPrintParameter (PP_PagesPerSheet, PagePerSheet);
1.1       cvs       702: }
                    703: 
                    704: /*----------------------------------------------------------------------
1.3       cvs       705:   SetupAndPrint sets printing parameters and starts the printing process
1.1       cvs       706:   ----------------------------------------------------------------------*/
1.91      vatton    707: void SetupAndPrint (Document doc, View view)
1.1       cvs       708: {
1.103     cvs       709: #ifndef _WINGUI
1.83      cvs       710:   char           bufMenu[MAX_LENGTH];
1.91      vatton    711:   int            i;
1.103     cvs       712: #endif /* _WINGUI */
1.91      vatton    713:   ThotBool       textFile;
1.38      cvs       714: 
1.81      cvs       715:   textFile = (DocumentTypes[doc] == docText || DocumentTypes[doc] == docCSS);
                    716:   /* Print form */
                    717:   CheckPrintingDocument (doc);
1.27      cvs       718: 
1.103     cvs       719: #ifndef _WINGUI
1.81      cvs       720:   TtaNewSheet (BasePrint + FormPrint, TtaGetViewFrame (doc, view), 
                    721:               TtaGetMessage (LIB, TMSG_LIB_PRINT), 1,
                    722:               TtaGetMessage (AMAYA, AM_BUTTON_PRINT), FALSE, 3, 'L', D_CANCEL);
                    723: 
                    724:   /* Paper format submenu */
                    725:   i = 0;
                    726:   sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_A4));
1.83      cvs       727:   i += strlen (&bufMenu[i]) + 1;
1.81      cvs       728:   sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_US));
                    729:   TtaNewSubmenu (BasePrint + PaperFormat, BasePrint + FormPrint, 0,
                    730:                 TtaGetMessage (LIB, TMSG_PAPER_SIZE), 2, bufMenu, NULL, TRUE);
                    731:   if (PageSize == PP_US)
                    732:     TtaSetMenuForm (BasePrint + PaperFormat, 1);
                    733:   else
                    734:     TtaSetMenuForm (BasePrint + PaperFormat, 0);
                    735:   
                    736:   /* Orientation submenu */
                    737:   i = 0;
                    738:   sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (AMAYA, AM_PORTRAIT));
1.83      cvs       739:   i += strlen (&bufMenu[i]) + 1;
1.81      cvs       740:   sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (AMAYA, AM_LANDSCAPE));
                    741:   TtaNewSubmenu (BasePrint + PaperOrientation, BasePrint + FormPrint, 0,
                    742:                 TtaGetMessage (AMAYA, AM_ORIENTATION), 2, bufMenu, NULL, TRUE);
                    743:   if (Orientation == PP_Landscape)
                    744:     TtaSetMenuForm (BasePrint + PaperOrientation, 1);
                    745:   else
                    746:     TtaSetMenuForm (BasePrint + PaperOrientation, 0);
                    747:   /* Pages per sheet submenu */
                    748:   i = 0;
                    749:   sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_1_PAGE_SHEET));
1.83      cvs       750:   i += strlen (&bufMenu[i]) + 1;
1.81      cvs       751:   sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_2_PAGE_SHEET));
1.83      cvs       752:   i += strlen (&bufMenu[i]) + 1;
1.81      cvs       753:   sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_4_PAGE_SHEET));
                    754:   TtaNewSubmenu (BasePrint + PPagesPerSheet, BasePrint + FormPrint, 0,
                    755:                 TtaGetMessage (LIB, TMSG_REDUCTION), 3, bufMenu, NULL, TRUE);
                    756:   if (PagePerSheet == 1)
                    757:     TtaSetMenuForm (BasePrint + PPagesPerSheet, 0);
                    758:   else if (PagePerSheet == 2)
                    759:     TtaSetMenuForm (BasePrint + PPagesPerSheet, 1);
                    760:   else
                    761:     TtaSetMenuForm (BasePrint + PPagesPerSheet, 2);
                    762:     
                    763:   /* Print to paper/ Print to file submenu */
                    764:   i = 0;
                    765:   sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_PRINTER));
1.83      cvs       766:   i += strlen (&bufMenu[i]) + 1;
1.81      cvs       767:   sprintf (&bufMenu[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_PS_FILE));
                    768:   TtaNewSubmenu (BasePrint + PrintSupport, BasePrint + FormPrint, 0,
                    769:                 TtaGetMessage (LIB, TMSG_OUTPUT), 2, bufMenu, NULL, TRUE);
                    770: 
                    771:   /* PaperPrint selector */
                    772:   TtaNewTextForm (BasePrint + PPrinterName, BasePrint + FormPrint, NULL, 30, 1, TRUE);
                    773:   if (PaperPrint == PP_PRINTER)
                    774:     {
                    775:       TtaSetMenuForm (BasePrint + PrintSupport, 0);
                    776:       TtaSetTextForm (BasePrint + PPrinterName, PPrinter);
                    777:     }
                    778:   else
                    779:     {
                    780:       TtaSetMenuForm (BasePrint + PrintSupport, 1);
                    781:       TtaSetTextForm (BasePrint + PPrinterName, PSfile);
                    782:     }
1.1       cvs       783: 
1.81      cvs       784:   /* The toggle */
                    785:   i = 0;
                    786:   sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (LIB, TMSG_MANUAL_FEED));
1.83      cvs       787:   i += strlen (&bufMenu[i]) + 1;
1.81      cvs       788:   sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_PRINT_TOC));
1.83      cvs       789:   i += strlen (&bufMenu[i]) + 1;
1.81      cvs       790:   sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_NUMBERED_LINKS));
1.83      cvs       791:   i += strlen (&bufMenu[i]) + 1;
1.81      cvs       792:   sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_PRINT_URL));
1.83      cvs       793:   i += strlen (&bufMenu[i]) + 1;
1.81      cvs       794:   sprintf (&bufMenu[i], "%s%s", "T", TtaGetMessage (AMAYA, AM_WITH_CSS));
                    795:   TtaNewToggleMenu (BasePrint + PrintOptions, BasePrint + FormPrint,
                    796:                    TtaGetMessage (LIB, TMSG_OPTIONS), 5, bufMenu, NULL, FALSE);
                    797:   if (ManualFeed == PP_ON)
                    798:     TtaSetToggleMenu (BasePrint + PrintOptions, 0, TRUE);
                    799:   else
                    800:     TtaSetToggleMenu (BasePrint + PrintOptions, 0, FALSE);
                    801:   TtaSetToggleMenu (BasePrint + PrintOptions, 1, WithToC);
                    802:   TtaSetToggleMenu (BasePrint + PrintOptions, 2, NumberLinks);
                    803:   TtaSetToggleMenu (BasePrint + PrintOptions, 3, PrintURL);
                    804:   TtaSetToggleMenu (BasePrint + PrintOptions, 4, IgnoreCSS);
                    805:   
                    806:   /* activates the Print form */
                    807:   TtaShowDialogue (BasePrint+FormPrint, FALSE);
                    808:   if (textFile)
                    809:     {
                    810:       /* invalid dialogue entries */
1.102     gully     811:       TtaRedrawMenuEntry (BasePrint + PrintOptions, 1, NULL, (ThotColor)-1, FALSE);
                    812:       TtaRedrawMenuEntry (BasePrint + PrintOptions, 2, NULL, (ThotColor)-1, FALSE);
1.81      cvs       813:     }
1.103     cvs       814: #else  /* _WINGUI */
1.81      cvs       815:   CreatePrintDlgWindow (TtaGetViewFrame (doc, view), PSfile);
1.103     cvs       816: #endif /* _WINGUI */
1.1       cvs       817: }
                    818: 
                    819: /*----------------------------------------------------------------------
                    820:   UpdateURLsInSubtree
                    821:   Update NAMEs and URLs in subtree of el element, to take into account
                    822:   the move from one document to another.
                    823:   If a NAME attribute already exists in the new document, it is changed
                    824:   to avoid duplicate names.
                    825:   Transform the HREF and SRC attribute to make them independent from their
                    826:   former base.
                    827:   ----------------------------------------------------------------------*/
1.99      cvs       828: void UpdateURLsInSubtree (NotifyElement *event, Element el)
1.1       cvs       829: {
1.77      cvs       830:   Element             nextEl, child;
                    831:   ElementType         elType;
                    832:   SSchema             HTMLschema;
1.1       cvs       833: 
                    834:   nextEl = TtaGetFirstChild (el);
1.82      cvs       835:   HTMLschema = TtaGetSSchema ("HTML", event->document);
1.99      cvs       836:   if (HTMLschema)
1.1       cvs       837:     {
1.99      cvs       838:       elType.ElSSchema = HTMLschema;
                    839:       while (nextEl != NULL)
1.77      cvs       840:        {
1.99      cvs       841:          event->element = nextEl;
1.77      cvs       842:          ElementPasted (event);
1.99      cvs       843:          
                    844:          /* manage included links and anchors */
                    845:          elType.ElTypeNum = HTML_EL_Anchor;
                    846:          child = TtaSearchTypedElement (elType, SearchInTree, nextEl);
                    847:          while (child)
                    848:            {
                    849:              event->element = child;
                    850:              ElementPasted (event);
                    851:              child = TtaSearchTypedElementInTree (elType, SearchForward, nextEl, child);
                    852:            }
                    853:          
                    854:          /* manage included links and anchors */
                    855:          elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
                    856:          child = TtaSearchTypedElement (elType, SearchInTree, nextEl);
                    857:          while (child)
                    858:            {
                    859:              event->element = child;
                    860:              ElementPasted (event);
                    861:              child = TtaSearchTypedElementInTree (elType, SearchForward, nextEl, child);
                    862:            }
                    863:          TtaNextSibling (&nextEl);
1.77      cvs       864:        }
1.1       cvs       865:     }
                    866: }
                    867: 
                    868: 
                    869: /*----------------------------------------------------------------------
                    870:   MoveDocumentBody
1.58      cvs       871:   Copy the elements contained in the BODY of the document sourceDoc at the
                    872:   position of the element el in the document destDoc.
                    873:   Delete the element containing el and all its empty ancestors.
1.1       cvs       874:   If deleteTree is TRUE, copied elements are deleted from the source
                    875:   document.
1.58      cvs       876:   Return the root element that delimits the new inserted part (a div).
1.1       cvs       877:   ----------------------------------------------------------------------*/
1.80      cvs       878: static Element MoveDocumentBody (Element el, Document destDoc,
1.85      cvs       879:                                 Document sourceDoc, char *target,
                    880:                                 char *url, ThotBool deleteTree)
1.1       cvs       881: {
1.58      cvs       882:   Element         root, ancestor, elem, firstInserted, div;
1.12      cvs       883:   Element          lastInserted, srce, copy, old, parent, sibling;
                    884:   ElementType     elType;
                    885:   NotifyElement    event;
                    886:   int             checkingMode;
1.47      cvs       887:   ThotBool         isID;
1.1       cvs       888: 
1.67      cvs       889:   div = NULL;
1.13      cvs       890:   if (target != NULL)
                    891:     {
                    892:       /* locate the target element within the source document */
1.98      vatton    893:       root = SearchNAMEattribute (sourceDoc, target, NULL, NULL);
1.13      cvs       894:       elType = TtaGetElementType (root);
1.84      cvs       895:       isID = (elType.ElTypeNum != HTML_EL_Anchor &&
                    896:              elType.ElTypeNum != HTML_EL_MAP);
1.13      cvs       897:     }
                    898:   else
                    899:     {
                    900:       isID = FALSE;
                    901:       /* get the BODY element of source document */
                    902:       root = TtaGetMainRoot (sourceDoc);
                    903:       elType = TtaGetElementType (root);
                    904:       elType.ElTypeNum = HTML_EL_BODY;
                    905:       root = TtaSearchTypedElement (elType, SearchForward, root);
                    906:     }
                    907: 
                    908:   if (root != NULL)
1.12      cvs       909:     {
                    910:       /* don't check the abstract tree against the structure schema */
                    911:       checkingMode = TtaGetStructureChecking (destDoc);
                    912:       TtaSetStructureChecking (0, destDoc);
1.58      cvs       913:       /* get elem, the ancestor of el which is a child of a DIV or BODY
1.12      cvs       914:         element in the destination document. The copied elements will be
                    915:         inserted just before this element. */
1.58      cvs       916:       elem = el;
1.12      cvs       917:       do
1.1       cvs       918:        {
1.12      cvs       919:          ancestor = TtaGetParent (elem);
                    920:          if (ancestor != NULL)
                    921:            {
                    922:              elType = TtaGetElementType (ancestor);
                    923:              if (elType.ElTypeNum == HTML_EL_BODY ||
                    924:                  elType.ElTypeNum == HTML_EL_Division)
                    925:                ancestor = NULL;
                    926:              else
                    927:                elem = ancestor;
                    928:            }
1.1       cvs       929:        }
1.12      cvs       930:       while (ancestor != NULL);
                    931:       parent = TtaGetParent (elem);
1.14      cvs       932: 
                    933:       /* insert a DIV element */
1.15      cvs       934:       elType.ElTypeNum = HTML_EL_Division;
1.16      cvs       935:       lastInserted = TtaNewElement (destDoc, elType);
                    936:       TtaInsertSibling (lastInserted, elem, TRUE, destDoc);
1.58      cvs       937:       /* this delimits the new inserted part of the document */
1.16      cvs       938:       RegisterSubDoc (lastInserted, url);
1.76      kahan     939:       CreateTargetAnchor (destDoc, lastInserted, FALSE, FALSE);
1.58      cvs       940:       div = lastInserted;
1.14      cvs       941: 
1.12      cvs       942:       /* do copy */
1.16      cvs       943:       firstInserted = NULL;
1.17      cvs       944:       if (isID)
                    945:        srce = root;
                    946:       else
                    947:        srce = TtaGetFirstChild (root);
1.12      cvs       948:       while (srce != NULL)
1.1       cvs       949:        {
1.12      cvs       950:          copy = TtaCopyTree (srce, sourceDoc, destDoc, parent);
                    951:          if (copy != NULL)
                    952:            {
1.16      cvs       953:              if (firstInserted == NULL)
1.12      cvs       954:                /* this is the first copied element. Insert it before elem */
                    955:                {
1.16      cvs       956:                  TtaInsertFirstChild (&copy, lastInserted, destDoc);
1.12      cvs       957:                  firstInserted = copy;
                    958:                }
                    959:              else
                    960:                /* insert the new copied element after the element previously
                    961:                   copied */
                    962:                TtaInsertSibling (copy, lastInserted, FALSE, destDoc);
                    963:              lastInserted = copy;
                    964:              /* update the NAMEs and URLs in the copied element */
1.100     quint     965:              event.event = TteElemPaste;
1.12      cvs       966:              event.document = destDoc;
1.100     quint     967:              event.element = copy;
                    968:              event.elementType = TtaGetElementType (copy);
1.12      cvs       969:              event.position = sourceDoc;
1.100     quint     970:              event.info = 0;
1.12      cvs       971:              UpdateURLsInSubtree(&event, copy);
                    972:            }
                    973:          /* get the next element in the source document */
                    974:          old = srce;
                    975:          TtaNextSibling (&srce);
                    976:          if (deleteTree)
                    977:            TtaDeleteTree (old, sourceDoc);
1.13      cvs       978:          /* Stop here if the target points to a specific element with an ID */
                    979:          if (isID)
                    980:            srce = NULL;
1.1       cvs       981:        }
1.12      cvs       982:       
                    983:       /* delete the element(s) containing the link to the copied document */
1.58      cvs       984:       /* delete the parent element of el and all empty ancestors */
                    985:       elem = TtaGetParent (el);
1.12      cvs       986:       do
1.1       cvs       987:        {
1.12      cvs       988:          sibling = elem;
                    989:          TtaNextSibling (&sibling);
                    990:          if (sibling == NULL)
                    991:            {
                    992:              sibling = elem;
                    993:              TtaPreviousSibling (&sibling);
                    994:              if (sibling == NULL)
                    995:                elem = TtaGetParent (elem);
                    996:            }
1.1       cvs       997:        }
1.12      cvs       998:       while (sibling == NULL);
                    999:       TtaDeleteTree (elem, destDoc);
                   1000:       /* restore previous chacking mode */
1.47      cvs      1001:       TtaSetStructureChecking ((ThotBool)checkingMode, destDoc);
1.12      cvs      1002:     }
1.58      cvs      1003:   /* return the address of the new division */
                   1004:   return (div);
1.1       cvs      1005: }
                   1006: 
1.29      cvs      1007: 
1.58      cvs      1008: /*----------------------------------------------------------------------
                   1009:   CloseMakeBook
                   1010:   ----------------------------------------------------------------------*/
                   1011: static void CloseMakeBook (Document document)
                   1012: {
                   1013:   ResetStop (document);
                   1014:   /* update internal links */
                   1015:   SetInternalLinks (document);
                   1016:   /* if the document changed force the browser mode */
                   1017:   if (SubDocs)
1.101     gully    1018:     SetBrowserEditor (document,0);
1.58      cvs      1019:   /* remove registered  sub-documents */
                   1020:   FreeSubDocTable ();
                   1021:   DocBook = 0;
                   1022:   TtaSetStatus (document, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), NULL);
                   1023: }
                   1024: 
                   1025: 
                   1026: /*----------------------------------------------------------------------
                   1027:   GetIncludedDocuments_callback finishes the GetIncludedDocuments procedure
                   1028:   ----------------------------------------------------------------------*/
                   1029: void   GetIncludedDocuments_callback (int newdoc, int status, 
1.85      cvs      1030:                                      char *urlName,
                   1031:                                      char *outputfile, 
1.63      cvs      1032:                                      AHTHeaders *http_headers,
1.58      cvs      1033:                                      void * context)
1.29      cvs      1034: {
1.58      cvs      1035:   Element              link, div;
                   1036:   IncludeCtxt          *ctx, *prev;
1.104     vatton   1037:   char                *utf8path, *ptr;
1.58      cvs      1038:   ThotBool              found = FALSE;
1.29      cvs      1039: 
                   1040:   /* restore GetIncludedDocuments's context */
1.58      cvs      1041:   ctx = (IncludeCtxt *) context;  
1.29      cvs      1042:   if (!ctx)
                   1043:     return;
                   1044: 
1.58      cvs      1045:   div = NULL;
1.29      cvs      1046:   link = ctx->link;
1.58      cvs      1047:   ptr = ctx->name;
1.104     vatton   1048:   utf8path = ctx->utf8path;
                   1049:   if (utf8path)
1.29      cvs      1050:     {
1.58      cvs      1051:       if (newdoc && newdoc != DocBook)
1.29      cvs      1052:        {
1.58      cvs      1053:          /* it's not the DocBook itself */
                   1054:          /* copy the target document at the position of the link */
                   1055:          TtaSetDocumentModified (DocBook);
1.104     vatton   1056:          div = MoveDocumentBody (link, DocBook, newdoc, ptr, utf8path,
1.58      cvs      1057:                                  (ThotBool)(newdoc == IncludedDocument));
1.29      cvs      1058:        }
1.58      cvs      1059:       /* global variables */
                   1060:       FreeDocumentResource (IncludedDocument);
                   1061:       TtaCloseDocument (IncludedDocument);
                   1062:       IncludedDocument = 0;
1.29      cvs      1063:     }
1.58      cvs      1064: 
1.104     vatton   1065:   if (div)
1.29      cvs      1066:     {
1.58      cvs      1067:       /* new starting point for the search */
                   1068:       ctx->link = div;
                   1069:       found = GetIncludedDocuments (div, div, DocBook, ctx);
1.29      cvs      1070:     }
1.104     vatton   1071: 
1.58      cvs      1072:   while (!found && ctx)
                   1073:     {
                   1074:       /* this sub-document has no more inclusion, examine the caller */
                   1075:       div = ctx->div;
                   1076:       link = ctx->link;
                   1077:       prev = ctx->ctxt;
1.104     vatton   1078:       TtaFreeMemory (utf8path);
                   1079:       utf8path = NULL;
1.58      cvs      1080:       TtaFreeMemory (ctx);
                   1081:       ctx = prev;
                   1082:       found = GetIncludedDocuments (div, link, DocBook, ctx);
                   1083:     }
                   1084:   if (!found)
                   1085:     /* all links are now managed */
                   1086:     CloseMakeBook (DocBook);
1.29      cvs      1087: }
                   1088: 
1.1       cvs      1089: /*----------------------------------------------------------------------
                   1090:   GetIncludedDocuments
1.58      cvs      1091:   Look forward within the element el, starting from element link, for a 
                   1092:   link (A) with attribute rel="chapter" or rel="subdocument" and replace
                   1093:   that link by the contents of the target document.
                   1094:   Return TRUE if one inclusion is launched.
1.1       cvs      1095:   ----------------------------------------------------------------------*/
1.96      vatton   1096: static ThotBool GetIncludedDocuments (Element el, Element link,
                   1097:                                      Document doc, IncludeCtxt *prev)
1.1       cvs      1098: {
1.58      cvs      1099:   ElementType           elType;
                   1100:   Attribute            attr;
                   1101:   AttributeType                attrType;
                   1102:   Document             newdoc;
                   1103:   IncludeCtxt          *ctx = NULL;
1.104     vatton   1104:   char                *utf8path, *ptr;
1.29      cvs      1105:   int                  length;
1.58      cvs      1106:   ThotBool              found = FALSE;
1.29      cvs      1107: 
1.58      cvs      1108:   /* look for anchors with the attribute rel within the element  el */
                   1109:   attr = NULL;
1.96      vatton   1110:   attrType.AttrSSchema = TtaGetSSchema ("HTML", doc);
1.58      cvs      1111:   elType.ElSSchema = attrType.AttrSSchema;
                   1112:   elType.ElTypeNum = HTML_EL_Anchor;
1.29      cvs      1113: 
1.58      cvs      1114:   /* Get only one included file each time */
                   1115:   while (link && attr == NULL)
1.29      cvs      1116:     {
1.58      cvs      1117:       link = TtaSearchTypedElementInTree (elType, SearchForward, el, link);
                   1118:       if (link)
1.29      cvs      1119:        {
1.58      cvs      1120:          attrType.AttrTypeNum = HTML_ATTR_REL;
                   1121:          attr = TtaGetAttribute (link, attrType);
                   1122:        }
                   1123:       if (attr)
                   1124:        {
                   1125:          length = TtaGetTextAttributeLength (attr);
1.104     vatton   1126:          utf8path = (char *)TtaGetMemory (length + 1);
                   1127:          TtaGiveTextAttributeValue (attr, utf8path, &length);
1.58      cvs      1128:          /* Valid rel values are rel="chapter" or rel="subdocument" */
1.104     vatton   1129:          if (strcasecmp (utf8path, "chapter") &&
                   1130:              strcasecmp (utf8path, "subdocument"))
1.58      cvs      1131:            attr = NULL;
1.104     vatton   1132:          TtaFreeMemory (utf8path);
1.29      cvs      1133:        }
1.58      cvs      1134:   
                   1135:       if (attr)
                   1136:        {
                   1137:          /* a link with attribute rel="Chapter" has been found */
                   1138:          attrType.AttrTypeNum = HTML_ATTR_HREF_;
                   1139:          attr = TtaGetAttribute (link, attrType);
                   1140:        }
                   1141:       if (attr)
                   1142:        /* this link has an attribute HREF */
                   1143:        {
                   1144:          length = TtaGetTextAttributeLength (attr);
1.104     vatton   1145:          utf8path = (char *)TtaGetMemory (length + 1);
                   1146:          TtaGiveTextAttributeValue (attr, utf8path, &length);
                   1147:          ptr = strrchr (utf8path, '#');
                   1148:          if (ptr)
1.58      cvs      1149:            {
1.104     vatton   1150:              /* link to a particular position within a document */
                   1151:              if (ptr == utf8path)
                   1152:                {
                   1153:                  /* local link */
                   1154:                  TtaFreeMemory (utf8path);
                   1155:                  utf8path = NULL;
                   1156:                }
                   1157:              else
                   1158:                {
                   1159:                  ptr[0] = EOS;
                   1160:                  ptr = &ptr[1];
                   1161:                }
1.58      cvs      1162:            }
                   1163:                  
1.104     vatton   1164:          if (utf8path)
1.58      cvs      1165:            /* this link designates an external document */
                   1166:            {
                   1167:              /* create a new document and loads the target document */
1.82      cvs      1168:              IncludedDocument = TtaNewDocument ("HTML", "tmp");
1.58      cvs      1169:              if (IncludedDocument != 0)
                   1170:                {
1.104     vatton   1171:                  TtaSetStatus (doc, 1, TtaGetMessage (AMAYA, AM_FETCHING), utf8path);
1.101     gully    1172:                  ctx = (IncludeCtxt *)TtaGetMemory (sizeof (IncludeCtxt));
1.58      cvs      1173:                  ctx->div =  el;
                   1174:                  ctx->link = link;
1.104     vatton   1175:                  ctx->utf8path = utf8path; /* the URL of the document */
1.58      cvs      1176:                  ctx->name = ptr;
                   1177:                  ctx->ctxt = prev; /* previous context */
                   1178:                  /* Get the reference of the calling document */
1.96      vatton   1179:                  SetStopButton (doc);
1.104     vatton   1180:                  newdoc = GetAmayaDoc (utf8path, NULL, IncludedDocument,
1.96      vatton   1181:                                        doc, CE_MAKEBOOK, FALSE, 
1.101     gully    1182:                                        (void (*)(int, int, char*, char*, const AHTHeaders*, void*)) GetIncludedDocuments_callback,
1.104     vatton   1183:                                        (void *) ctx);
1.58      cvs      1184:                  found = TRUE;
                   1185:                }
                   1186:            }
                   1187:          else
1.104     vatton   1188:            TtaFreeMemory (utf8path);
1.58      cvs      1189:        }
1.29      cvs      1190:     }
1.58      cvs      1191:   return (found);
1.1       cvs      1192: }
                   1193: 
                   1194: 
                   1195: /*----------------------------------------------------------------------
                   1196:   MakeBook
                   1197:   Replace all links in a document which have an attribute REL="chapter"
1.5       cvs      1198:   or REL="subdocument" by the corresponding target document.
1.1       cvs      1199:   ----------------------------------------------------------------------*/
1.96      vatton   1200: void MakeBook (Document doc, View view)
1.1       cvs      1201: {
1.58      cvs      1202:   Element          root, body;
                   1203:   ElementType      elType;
1.1       cvs      1204: 
1.58      cvs      1205:   /* stops all current transfers on this document */
1.96      vatton   1206:   StopTransfer (doc, 1);
1.58      cvs      1207:   /* simulate a transfert in the main document */
1.96      vatton   1208:   DocBook = doc;
1.58      cvs      1209:   IncludedDocument = 0;
1.96      vatton   1210:   root = TtaGetMainRoot (doc);
1.58      cvs      1211:   elType = TtaGetElementType (root);
                   1212:   elType.ElTypeNum = HTML_EL_BODY;
                   1213:   body = TtaSearchTypedElement (elType, SearchForward, root);
1.29      cvs      1214: 
1.58      cvs      1215:   if (body)
1.96      vatton   1216:     GetIncludedDocuments (body, body, doc, NULL);
1.1       cvs      1217: }
1.105   ! vatton   1218: 
        !          1219: /*----------------------------------------------------------------------
        !          1220:   ----------------------------------------------------------------------*/
        !          1221: void ReadAsUTF_8 (Document doc, View view)
        !          1222: {
        !          1223:   ReparseAs (doc, view, FALSE, UTF_8);
        !          1224: }
        !          1225: 
        !          1226: /*----------------------------------------------------------------------
        !          1227:   ----------------------------------------------------------------------*/
        !          1228: void ReadAsISO_8859_1 (Document doc, View view)
        !          1229: {
        !          1230:   ReparseAs (doc, view, FALSE, ISO_8859_1);
        !          1231: }
        !          1232: 
        !          1233: /*----------------------------------------------------------------------
        !          1234:   ----------------------------------------------------------------------*/
        !          1235: void ReadAsISO_8859_2 (Document doc, View view)
        !          1236: {
        !          1237:   ReparseAs (doc, view, FALSE, ISO_8859_2);
        !          1238: }
        !          1239: 
        !          1240: /*----------------------------------------------------------------------
        !          1241:   ----------------------------------------------------------------------*/
        !          1242: void ReadAsISO_8859_3 (Document doc, View view)
        !          1243: {
        !          1244:   ReparseAs (doc, view, FALSE, ISO_8859_3);
        !          1245: }
        !          1246: 
        !          1247: /*----------------------------------------------------------------------
        !          1248:   ----------------------------------------------------------------------*/
        !          1249: void ReadAsISO_8859_4 (Document doc, View view)
        !          1250: {
        !          1251:   ReparseAs (doc, view, FALSE, ISO_8859_4);
        !          1252: }
        !          1253: 
        !          1254: /*----------------------------------------------------------------------
        !          1255:   ----------------------------------------------------------------------*/
        !          1256: void ReadAsISO_8859_5 (Document doc, View view)
        !          1257: {
        !          1258:   ReparseAs (doc, view, FALSE, ISO_8859_5);
        !          1259: }
        !          1260: 
        !          1261: /*----------------------------------------------------------------------
        !          1262:   ----------------------------------------------------------------------*/
        !          1263: void ReadAsISO_8859_6 (Document doc, View view)
        !          1264: {
        !          1265:   ReparseAs (doc, view, FALSE, ISO_8859_6);
        !          1266: }
        !          1267: 
        !          1268: /*----------------------------------------------------------------------
        !          1269:   ----------------------------------------------------------------------*/
        !          1270: void ReadAsISO_8859_7 (Document doc, View view)
        !          1271: {
        !          1272:   ReparseAs (doc, view, FALSE, ISO_8859_7);
        !          1273: }
        !          1274: 
        !          1275: /*----------------------------------------------------------------------
        !          1276:   ----------------------------------------------------------------------*/
        !          1277: void ReadAsISO_8859_8 (Document doc, View view)
        !          1278: {
        !          1279:   ReparseAs (doc, view, FALSE, ISO_8859_8);
        !          1280: }
        !          1281: 
        !          1282: /*----------------------------------------------------------------------
        !          1283:   ----------------------------------------------------------------------*/
        !          1284: void ReadAsISO_8859_9 (Document doc, View view)
        !          1285: {
        !          1286:   ReparseAs (doc, view, FALSE, ISO_8859_9);
        !          1287: }
        !          1288: 
        !          1289: /*----------------------------------------------------------------------
        !          1290:   ----------------------------------------------------------------------*/
        !          1291: void ReadAsISO_8859_15 (Document doc, View view)
        !          1292: {
        !          1293:   ReparseAs (doc, view, FALSE, ISO_8859_15);
        !          1294: }
        !          1295: 
        !          1296: /*----------------------------------------------------------------------
        !          1297:   ----------------------------------------------------------------------*/
        !          1298: void ReadAsKOI8_R (Document doc, View view)
        !          1299: {
        !          1300:   ReparseAs (doc, view, FALSE, KOI8_R);
        !          1301: }
        !          1302: 
        !          1303: /*----------------------------------------------------------------------
        !          1304:   ----------------------------------------------------------------------*/
        !          1305: void ReadAsWINDOWS_1250 (Document doc, View view)
        !          1306: {
        !          1307:   ReparseAs (doc, view, FALSE, WINDOWS_1250);
        !          1308: }
        !          1309: 
        !          1310: /*----------------------------------------------------------------------
        !          1311:   ----------------------------------------------------------------------*/
        !          1312: void ReadAsWINDOWS_1251 (Document doc, View view)
        !          1313: {
        !          1314:   ReparseAs (doc, view, FALSE, WINDOWS_1251);
        !          1315: }
        !          1316: 
        !          1317: /*----------------------------------------------------------------------
        !          1318:   ----------------------------------------------------------------------*/
        !          1319: void ReadAsWINDOWS_1252 (Document doc, View view)
        !          1320: {
        !          1321:   ReparseAs (doc, view, FALSE, WINDOWS_1252);
        !          1322: }
        !          1323: 
        !          1324: /*----------------------------------------------------------------------
        !          1325:   ----------------------------------------------------------------------*/
        !          1326: void ReadAsWINDOWS_1253 (Document doc, View view)
        !          1327: {
        !          1328:   ReparseAs (doc, view, FALSE, WINDOWS_1253);
        !          1329: }
        !          1330: 
        !          1331: /*----------------------------------------------------------------------
        !          1332:   ----------------------------------------------------------------------*/
        !          1333: void ReadAsWINDOWS_1254 (Document doc, View view)
        !          1334: {
        !          1335:   ReparseAs (doc, view, FALSE, WINDOWS_1254);
        !          1336: }
        !          1337: 
        !          1338: /*----------------------------------------------------------------------
        !          1339:   ----------------------------------------------------------------------*/
        !          1340: void ReadAsWINDOWS_1255 (Document doc, View view)
        !          1341: {
        !          1342:   ReparseAs (doc, view, FALSE, WINDOWS_1255);
        !          1343: }
        !          1344: 
        !          1345: /*----------------------------------------------------------------------
        !          1346:   ----------------------------------------------------------------------*/
        !          1347: void ReadAsWINDOWS_1256 (Document doc, View view)
        !          1348: {
        !          1349:   ReparseAs (doc, view, FALSE, WINDOWS_1256);
        !          1350: }
        !          1351: 
        !          1352: /*----------------------------------------------------------------------
        !          1353:   ----------------------------------------------------------------------*/
        !          1354: void ReadAsWINDOWS_1257 (Document doc, View view)
        !          1355: {
        !          1356:   ReparseAs (doc, view, FALSE, WINDOWS_1257);
        !          1357: }
        !          1358: 
        !          1359: /*----------------------------------------------------------------------
        !          1360:   ----------------------------------------------------------------------*/
        !          1361: void ReadAsISO_2022_JP (Document doc, View view)
        !          1362: {
        !          1363:   ReparseAs (doc, view, FALSE, ISO_2022_JP);
        !          1364: }
        !          1365: 
        !          1366: /*----------------------------------------------------------------------
        !          1367:   ----------------------------------------------------------------------*/
        !          1368: void ReadAsEUC_JP (Document doc, View view)
        !          1369: {
        !          1370:   ReparseAs (doc, view, FALSE, EUC_JP);
        !          1371: }
        !          1372: 
        !          1373: /*----------------------------------------------------------------------
        !          1374:   ----------------------------------------------------------------------*/
        !          1375: void ReadAsSHIFT_JIS (Document doc, View view)
        !          1376: {
        !          1377:   ReparseAs (doc, view, FALSE, SHIFT_JIS);
        !          1378: }

Webmaster