Diff for /Amaya/amaya/templates.c between versions 1.45 and 1.46

version 1.45, 2005/08/23 16:09:16 version 1.46, 2005/10/04 13:40:54
Line 21 Line 21
 #include "css.h"  #include "css.h"
 #include "document.h"  #include "document.h"
 #include "view.h"  #include "view.h"
 #include "wxdialogapi_f.h"  #ifdef TEMPLATES
   #include "Template.h"
   #endif /* TEMPLATES */
   
   #include "AHTURLTools_f.h"
 #include "appdialogue_wx.h"  #include "appdialogue_wx.h"
   #include "css_f.h"
 #include "init_f.h"  #include "init_f.h"
 #include "parser.h"  #include "parser.h"
 #include "tree.h"  #include "HTMLhistory_f.h"
 #include "HTMLimage_f.h"  #include "HTMLimage_f.h"
 #ifdef TEMPLATES  
 #include "Template.h"  
 #endif /* TEMPLATES */  
 #include "HTMLsave_f.h"  #include "HTMLsave_f.h"
   #include "tree.h"
   #include "wxdialogapi_f.h"
   
 /* content of the attr name of the meta tag defining the doc's destination URL */  /* content of the attr name of the meta tag defining the doc's destination URL */
 #define META_TEMPLATE_NAME "AMAYA_TEMPLATE"  #define META_TEMPLATE_NAME "AMAYA_TEMPLATE"
 /* URL of the script providing templates (for reload) */  /* URL of the script providing templates (for reload) */
 static char   *script_URL;  static char   *script_URL;
 #include "init_f.h"  
 #include "css_f.h"  
   
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 51  void NewTemplate (Document doc, View vie Line 53  void NewTemplate (Document doc, View vie
   templateDir = (char *) TtaGetMemory (MAX_LENGTH);    templateDir = (char *) TtaGetMemory (MAX_LENGTH);
   
   // Amaya's templates directory (only french yet)    // Amaya's templates directory (only french yet)
   sprintf ((char *)templateDir, "%s%ctemplates%cfr%c", TtaGetEnvString ("THOTDIR"),DIR_SEP,DIR_SEP,DIR_SEP);    sprintf ((char *)templateDir, "%s%ctemplates%cfr%c",
              TtaGetEnvString ("THOTDIR"),DIR_SEP,DIR_SEP,DIR_SEP);
       
   char s [MAX_LENGTH];    char s [MAX_LENGTH];
       
Line 261  void InitTemplateList () Line 264  void InitTemplateList ()
 #endif /* TEMPLATES */  #endif /* TEMPLATES */
 }  }
   
 /*-------------------------------------------------  /*----------------------------------------------------------------------
  Insert the meta element identifying the template's   Insert the meta element identifying the template's instance
  instance    ----------------------------------------------------------------------*/
 ----------------------------------------------------*/  
 void InsertInstanceMeta (Document newdoc)  void InsertInstanceMeta (Document newdoc)
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
Line 339  void InsertInstanceMeta (Document newdoc Line 341  void InsertInstanceMeta (Document newdoc
 #endif /*TEMPLATES*/  #endif /*TEMPLATES*/
 }  }
   
 /*-----------------------------------------------  
 void UnlockSubtree  
 Set read/write access to an element and all his  
 children  
 -----------------------------------------------*/  
   
 void UnlockSubtree (Document doc, Element el)  
 {  
 #ifdef TEMPLATES  
   TtaSetAccessRight (el, ReadWrite, doc);  
   TtaNextSibling (&el);  
   if (el != NULL)  
     /* The element has at least one sibling */  
     UnlockSubtree (doc, el);  
 #endif /*TEMPLATES*/  
 }  
   
 void UnlockContentElements (Document doc, Element el)  /*----------------------------------------------------------------------
     ----------------------------------------------------------------------*/
   static void UnlockContentElements (Document doc, Element el)
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   ElementType elType;    ElementType elType;
   
   if (el != NULL)     if (el) 
     {      {
       elType = TtaGetElementType (el);        elType = TtaGetElementType (el);
       if (TtaIsLeaf (elType))        if (TtaIsLeaf (elType))
         {          /* It's a content element */
           /* It's a content element */          TtaSetAccessRight (el, ReadWrite, doc);
           TtaSetAccessRight(el, ReadWrite, doc);  
         }  
       else        else
         {          {
           TtaSetAccessRight(el, ReadOnly, doc);            el = TtaGetFirstChild(el);
           UnlockContentElements(doc,TtaGetFirstChild(el));            while (el)
         }              {
       TtaNextSibling(&el);                UnlockContentElements (doc,el);
       if (el != NULL)                TtaNextSibling (&el);
         {              }
           UnlockContentElements(doc,el);  
         }          }
     }      }
 #endif /*TEMPLATES*/  #endif /*TEMPLATES*/
 }  }
   
 /*-----------------------------------------------  /*----------------------------------------------------------------------
 void LockFixedAreas    CheckFreeAreas
 Parse the subtree from el, set read-only access to    Parse the subtree from el, set read-write access to the child elements
 the element and his child when it's not a free_struct    of  free_struct elements.
 element.    ----------------------------------------------------------------------*/
 ------------------------------------------------*/  static void CheckFreeAreas (Document doc, Element el)
   
 void LockFixedAreas (Document doc, Element el)  
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   ElementType elType;    ElementType  elType;
   char *s;    char        *s;
       
   TtaSetAccessRight (el, ReadOnly, doc);    el = TtaGetFirstChild(el);
   elType = TtaGetElementType(el);    while (el)
   s = TtaGetSSchemaName (elType.ElSSchema);  
   if (TtaGetFirstChild(el)!=NULL)  
     {      {
         elType = TtaGetElementType (el);
         s = TtaGetSSchemaName (elType.ElSSchema);
       /* The element is not a leaf */        /* The element is not a leaf */
       if ((strcmp (s,"Template") == 0) &&        if (!strcmp (s,"Template") &&
           (elType.ElTypeNum == Template_EL_FREE_STRUCT))            elType.ElTypeNum == Template_EL_FREE_STRUCT)
         {          /* The element has a free structure */
           /* The element has a free structure */          TtaSetAccessRight (el, ReadWrite, doc);
           UnlockSubtree (doc, TtaGetFirstChild(el));        else if (!strcmp (s,"Template") &&
         }                 elType.ElTypeNum == Template_EL_FREE_CONTENT)
       else if ((strcmp (s,"Template") == 0) &&          /* The element has free content */
                (elType.ElTypeNum == Template_EL_FREE_CONTENT))          UnlockContentElements (doc, el);
         {        else
           /* The element has free content */          /* The element has a fixed structure */
           UnlockContentElements (doc, el);          /* So we look for a free structure in
         }             the subtree */
       else                  CheckFreeAreas(doc, el);
         {        TtaNextSibling (&el);
           /* The element has a fixed structure */  
           /* So we look for a free structure in  
              the subtree */  
           LockFixedAreas (doc, TtaGetFirstChild (el));  
         }  
     }      }
   TtaNextSibling (&el);  
   if (el != NULL)  
     /* The element has at least one sibling */  
     LockFixedAreas (doc, el);  
 #endif /* TEMPLATES */  #endif /* TEMPLATES */
 }  }
   
 /*---------------------------------------------------------------  /*----------------------------------------------------------------------
   Load a template and create the instance file - update images and     Load a template and create the instance file - update images and 
   stylesheets related to the template.    stylesheets related to the template.
   ---------------------------------------------------------------*/    ----------------------------------------------------------------------*/
   
 int CreateInstanceOfTemplate (Document doc, char *templatename, char *docname,  int CreateInstanceOfTemplate (Document doc, char *templatename, char *docname,
                               DocumentType docType)                                DocumentType docType)
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   Element       el;    Element       el;
     char                *s;
   int           newdoc, len;    int           newdoc, len;
   ThotBool      stopped_flag;    ThotBool      stopped_flag;
   
   W3Loading = doc;    if (!IsW3Path (docname) && TtaFileExist (docname))
   BackupDocument = doc;      {
   TtaExtractName (templatename, DirectoryName, DocumentName);        s = (char *)TtaGetMemory (strlen (docname) +
   AddURLInCombobox (docname, NULL, TRUE);                                  strlen (TtaGetMessage (AMAYA, AM_OVERWRITE_CHECK)) + 2);
   //  doc = TtaInitDocument("HTML", templatename, 0);        sprintf (s, TtaGetMessage (AMAYA, AM_OVERWRITE_CHECK), docname);
   newdoc = InitDocAndView (doc,        InitConfirm (0, 0, s);
                            !DontReplaceOldDoc /* replaceOldDoc */,        TtaFreeMemory (s);
                            InNewWindow, /* inNewWindow */        if (!UserAnswer)
                            DocumentName, (DocumentType)docType, 0, FALSE,          return 0;
                            L_Other, (ClickEvent)CE_ABSOLUTE);       }
   
     if (InNewWindow || DontReplaceOldDoc)
       {
         newdoc = InitDocAndView (doc,
                                  !DontReplaceOldDoc /* replaceOldDoc */,
                                  InNewWindow, /* inNewWindow */
                                  DocumentName, (DocumentType)docType, 0, FALSE,
                                  L_Other, (ClickEvent)CE_ABSOLUTE);
         DontReplaceOldDoc = FALSE;
       }
     else
       {
         /* record the current position in the history */
         AddDocHistory (doc, DocumentURLs[doc], 
                        DocumentMeta[doc]->initial_url,
                        DocumentMeta[doc]->form_data,
                        DocumentMeta[doc]->method);
         newdoc = InitDocAndView (doc,
                                  !DontReplaceOldDoc /* replaceOldDoc */,
                                  InNewWindow, /* inNewWindow */
                                  DocumentName, (DocumentType)docType, 0, FALSE,
                                  L_Other, (ClickEvent)CE_ABSOLUTE);
       }
   
     //W3Loading = doc;
     //BackupDocument = doc;
   if (newdoc != 0)    if (newdoc != 0)
     {      {
         TtaExtractName (templatename, DirectoryName, DocumentName);
         //AddURLInCombobox (docname, NULL, TRUE);
         //TtaSetTextZone (newdoc, 1, URL_list);
   #ifdef IV
           if (DocumentMeta[newdoc]->xmlformat && !plainText)
             StartXmlParser (newdoc,       localdoc, documentname, tempdir,
                             pathname, xmlDec, withDoctype, FALSE);
           else
             StartParser (newdoc, localdoc, documentname, tempdir,
                          pathname, plainText, FALSE);
   #endif
       LoadDocument (newdoc, templatename, NULL, NULL, CE_ABSOLUTE,        LoadDocument (newdoc, templatename, NULL, NULL, CE_ABSOLUTE,
                     "", DocumentName, NULL, FALSE, &DontReplaceOldDoc);                      "", DocumentName, NULL, FALSE, &DontReplaceOldDoc);
         InsertInstanceMeta (newdoc);
       InsertInstanceMeta(newdoc);  
               
       /* Update URLs of linked documents */        /* Update URLs of linked documents */
       SetRelativeURLs (newdoc, docname);        SetRelativeURLs (newdoc, docname);
Line 486  int CreateInstanceOfTemplate (Document d Line 496  int CreateInstanceOfTemplate (Document d
         }          }
       /* check parsing errors */        /* check parsing errors */
       CheckParsingErrors (newdoc);        CheckParsingErrors (newdoc);
               /* Set elements access rights according to free_* elements */
       /* Set elements access rights  
          according to free_* elements */  
       el = TtaGetMainRoot (newdoc);        el = TtaGetMainRoot (newdoc);
       LockFixedAreas (newdoc, el);        if (el)
           {
             TtaSetAccessRight (el, ReadOnly, newdoc);
             CheckFreeAreas (newdoc, el);
           }
     }      }
    BackupDocument = 0;     BackupDocument = 0;
    return (newdoc);     return (newdoc);
 #endif /* TEMPLATES */  #endif /* TEMPLATES */
 }  }
   
 /*---------------------------------------------------------------  /*----------------------------------------------------------------------
   Here we put all the actions to performs when we know a document     Here we put all the actions to performs when we know a document 
   is an instance    is an instance
  ---------------------------------------------------------------*/    ----------------------------------------------------------------------*/
   
 void LoadInstanceOfTemplate (Document doc)  void LoadInstanceOfTemplate (Document doc)
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
Line 513  void LoadInstanceOfTemplate (Document do Line 522  void LoadInstanceOfTemplate (Document do
   PInfoPtr            pInfo;    PInfoPtr            pInfo;
   CSSInfoPtr css;    CSSInfoPtr css;
   
   LockFixedAreas (doc, el);    el = TtaGetMainRoot (doc);
     TtaSetAccessRight (el, ReadOnly, doc);
     CheckFreeAreas (doc, el);
   TtaGetEnvBoolean ("SHOW_TEMPLATES", &show);    TtaGetEnvBoolean ("SHOW_TEMPLATES", &show);
   css_url = (char *) TtaGetMemory (MAX_LENGTH);    css_url = (char *) TtaGetMemory (MAX_LENGTH);
   sprintf (css_url, "%s%camaya%chide_template.css", TtaGetEnvString ("THOTDIR"),DIR_SEP,DIR_SEP);    sprintf (css_url, "%s%camaya%chide_template.css", TtaGetEnvString ("THOTDIR"),DIR_SEP,DIR_SEP);
Line 536  void LoadInstanceOfTemplate (Document do Line 547  void LoadInstanceOfTemplate (Document do
 }  }
   
   
 /*---------------------------------------------------------------  /*----------------------------------------------------------------------
   ThotBool isTemplateInstance (Document doc)     ThotBool isTemplateInstance (Document doc) 
   Return true if the document is an instance     Return true if the document is an instance 
  ---------------------------------------------------------------*/    ----------------------------------------------------------------------*/
   
 ThotBool IsTemplateInstance (Document doc)  ThotBool IsTemplateInstance (Document doc)
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES

Removed from v.1.45  
changed lines
  Added in v.1.46


Webmaster