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

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

Webmaster