Diff for /Amaya/amaya/templates.c between versions 1.205 and 1.206

version 1.205, 2008/09/29 13:28:13 version 1.206, 2008/09/30 09:58:01
Line 4 Line 4
  *  Please first read the full copyright statement in file COPYRIGHT.   *  Please first read the full copyright statement in file COPYRIGHT.
  *   *
  */   */
    
 /*  /*
  * Authors: Francesc Campoy Flores   * Authors: Francesc Campoy Flores
  *          Ă‰milien Kia   *          Ă‰milien Kia
Line 59  ThotBool IsTemplateInstanceDocument(Docu Line 59  ThotBool IsTemplateInstanceDocument(Docu
     return FALSE;      return FALSE;
 #else /* TEMPLATES */  #else /* TEMPLATES */
   return FALSE;    return FALSE;
 #endif /* TEMPLATES */   #endif /* TEMPLATES */
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 75  ThotBool IsTemplateDocument (Document do Line 75  ThotBool IsTemplateDocument (Document do
     return ((t->state & templTemplate) != 0);      return ((t->state & templTemplate) != 0);
   else    else
     return FALSE;      return FALSE;
 #endif /* TEMPLATES */   #endif /* TEMPLATES */
   return FALSE;    return FALSE;
 }  }
   
Line 94  ThotBool IsInternalTemplateDocument(Docu Line 94  ThotBool IsInternalTemplateDocument(Docu
     return FALSE;      return FALSE;
 #else /* TEMPLATES */  #else /* TEMPLATES */
   return FALSE;    return FALSE;
 #endif /* TEMPLATES */   #endif /* TEMPLATES */
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 110  char* GetDocumentInstanceTemplateUrl(Doc Line 110  char* GetDocumentInstanceTemplateUrl(Doc
     return FALSE;      return FALSE;
 #else /* TEMPLATES */  #else /* TEMPLATES */
   return NULL;    return NULL;
 #endif /* TEMPLATES */   #endif /* TEMPLATES */
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 251  static void CopyTemplateRepositoryList ( Line 251  static void CopyTemplateRepositoryList (
                                         Prop_Templates_Path** dst)                                          Prop_Templates_Path** dst)
 {  {
   Prop_Templates_Path *element=NULL, *current=NULL;    Prop_Templates_Path *element=NULL, *current=NULL;
     
   if (*src)    if (*src)
   {    {
     *dst = (Prop_Templates_Path*) TtaGetMemory (sizeof(Prop_Templates_Path));      *dst = (Prop_Templates_Path*) TtaGetMemory (sizeof(Prop_Templates_Path));
     (*dst)->NextPath = NULL;      (*dst)->NextPath = NULL;
     strcpy((*dst)->Path, (*src)->Path);      strcpy((*dst)->Path, (*src)->Path);
       
     element = (*src)->NextPath;      element = (*src)->NextPath;
     current = *dst;      current = *dst;
   }    }
Line 265  static void CopyTemplateRepositoryList ( Line 265  static void CopyTemplateRepositoryList (
   while (element)    while (element)
     {      {
     current->NextPath = (Prop_Templates_Path*) TtaGetMemory (sizeof(Prop_Templates_Path));      current->NextPath = (Prop_Templates_Path*) TtaGetMemory (sizeof(Prop_Templates_Path));
     current = current->NextPath;       current = current->NextPath;
     current->NextPath = NULL;      current->NextPath = NULL;
     strcpy(current->Path, element->Path);      strcpy(current->Path, element->Path);
     element = element->NextPath;      element = element->NextPath;
Line 284  static int LoadTemplateRepositoryList (P Line 284  static int LoadTemplateRepositoryList (P
   unsigned char *c;    unsigned char *c;
   int nb = 0;    int nb = 0;
   FILE *file;    FILE *file;
     
   //clean up the curent list    //clean up the curent list
   FreeTemplateRepositoryList (list);    FreeTemplateRepositoryList (list);
   
Line 304  static int LoadTemplateRepositoryList (P Line 304  static int LoadTemplateRepositoryList (P
     /* Retry to open it.*/      /* Retry to open it.*/
     file = TtaReadOpen ((char *)path);      file = TtaReadOpen ((char *)path);
   }    }
     
   if (file)    if (file)
     {      {
       // read the file        // read the file
Line 321  static int LoadTemplateRepositoryList (P Line 321  static int LoadTemplateRepositoryList (P
               strcpy (element->Path, path);                strcpy (element->Path, path);
   
               if (*list == NULL)                if (*list == NULL)
                 *list = element;                   *list = element;
               else                else
                 current->NextPath = element;                  current->NextPath = element;
               current = element;                current = element;
Line 341  static int LoadTemplateRepositoryList (P Line 341  static int LoadTemplateRepositoryList (P
           element->NextPath = NULL;            element->NextPath = NULL;
   
           if (*list == NULL)            if (*list == NULL)
             *list = element;               *list = element;
           else            else
             current->NextPath = element;              current->NextPath = element;
           nb++;            nb++;
Line 415  void InitTemplates () Line 415  void InitTemplates ()
   
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   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.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 void CreateInstanceOfTemplate (Document doc, char *templatename, char *docname)  void CreateInstanceOfTemplate (Document doc, char *templatename, char *docname)
Line 504  void AllowReloadingTemplate(char* templa Line 504  void AllowReloadingTemplate(char* templa
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   Template_RemoveReference(GetXTigerTemplate (template_url));    Template_RemoveReference(GetXTigerTemplate (template_url));
 #endif /* TEMPLATES */    #endif /* TEMPLATES */
 }  }
   
   
Line 613  ThotBool UseToBeCreated (NotifyElement * Line 613  ThotBool UseToBeCreated (NotifyElement *
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   ElementType   parentType;    ElementType   parentType;
   SSchema       templateSSchema = TtaGetSSchema ("Template", event->document);      SSchema       templateSSchema = TtaGetSSchema ("Template", event->document);
   if (templateSSchema)    if (templateSSchema)
   {    {
     parentType = TtaGetElementType (event->element);      parentType = TtaGetElementType (event->element);
Line 743  static char* QueryStringFromMenu (Docume Line 743  static char* QueryStringFromMenu (Docume
     return NULL;      return NULL;
   giveItems (items, size, &itemlist, &nbitems);    giveItems (items, size, &itemlist, &nbitems);
   menuString = createMenuString (itemlist, nbitems);    menuString = createMenuString (itemlist, nbitems);
   TtaNewScrollPopup (BaseDialog + OptionMenu, TtaGetViewFrame (doc, 1), NULL,     TtaNewScrollPopup (BaseDialog + OptionMenu, TtaGetViewFrame (doc, 1), NULL,
                      nbitems, menuString , NULL, false, 'L');                       nbitems, menuString , NULL, false, 'L');
   TtaFreeMemory (menuString);    TtaFreeMemory (menuString);
   ReturnOption = -1;    ReturnOption = -1;
Line 755  static char* QueryStringFromMenu (Docume Line 755  static char* QueryStringFromMenu (Docume
   {    {
     result = TtaStrdup(itemlist[ReturnOption].label);      result = TtaStrdup(itemlist[ReturnOption].label);
   }    }
     
   TtaFreeMemory (itemlist);    TtaFreeMemory (itemlist);
   return result;    return result;
 }  }
Line 784  char *Template_GetListTypes (XTigerTempl Line 784  char *Template_GetListTypes (XTigerTempl
   Can be called for useEl, useSimple or bag.    Can be called for useEl, useSimple or bag.
   If called for useEl or useSimple, the new element must be added after.    If called for useEl or useSimple, the new element must be added after.
   If called for bag, the element must be added before all.    If called for bag, the element must be added before all.
      
   Shows a menu with all the types that can be used in the bag.    Shows a menu with all the types that can be used in the bag.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 ThotBool BagButtonClicked (NotifyElement *event)  ThotBool BagButtonClicked (NotifyElement *event)
Line 815  ThotBool BagButtonClicked (NotifyElement Line 815  ThotBool BagButtonClicked (NotifyElement
     return FALSE; /* let Thot perform normal operation */      return FALSE; /* let Thot perform normal operation */
   
   TtaCancelSelection (doc);    TtaCancelSelection (doc);
   templateSSchema = TtaGetSSchema ("Template", doc);      templateSSchema = TtaGetSSchema ("Template", doc);
   t = GetXTigerDocTemplate(doc);    t = GetXTigerDocTemplate(doc);
   elType = TtaGetElementType (el);    elType = TtaGetElementType (el);
   while (bagEl &&    while (bagEl &&
Line 859  ThotBool BagButtonClicked (NotifyElement Line 859  ThotBool BagButtonClicked (NotifyElement
                      -> it breaks down views formatting when Enter generates new elements  */                       -> it breaks down views formatting when Enter generates new elements  */
                   TtaSetDisplayMode (doc, DeferredDisplay);                    TtaSetDisplayMode (doc, DeferredDisplay);
   
                 /* Prepare insertion.*/                            /* Prepare insertion.*/
                 oldStructureChecking = TtaGetStructureChecking (doc);                  oldStructureChecking = TtaGetStructureChecking (doc);
                 TtaSetStructureChecking (FALSE, doc);                  TtaSetStructureChecking (FALSE, doc);
                 TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);                  TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
Line 910  ThotBool BagButtonClicked (NotifyElement Line 910  ThotBool BagButtonClicked (NotifyElement
   Can be called for useEl, useSimple or repeat.    Can be called for useEl, useSimple or repeat.
   If called for useEl or useSimple, the new element must be added after.    If called for useEl or useSimple, the new element must be added after.
   If called for repeat, the element must be added before all.    If called for repeat, the element must be added before all.
      
   Shows a menu with all the types that can be used in a use element.    Shows a menu with all the types that can be used in a use element.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 ThotBool RepeatButtonClicked (NotifyElement *event)  ThotBool RepeatButtonClicked (NotifyElement *event)
Line 974  ThotBool RepeatButtonClicked (NotifyElem Line 974  ThotBool RepeatButtonClicked (NotifyElem
                  -> it breaks down views formatting when Enter generates new elements  */                   -> it breaks down views formatting when Enter generates new elements  */
                         TtaSetDisplayMode (doc, DeferredDisplay);                          TtaSetDisplayMode (doc, DeferredDisplay);
   
                       /* Prepare insertion.*/                                  /* Prepare insertion.*/
                       oldStructureChecking = TtaGetStructureChecking (doc);                        oldStructureChecking = TtaGetStructureChecking (doc);
                       TtaSetStructureChecking (FALSE, doc);                        TtaSetStructureChecking (FALSE, doc);
                       TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);                        TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
Line 1044  ThotBool UseButtonClicked (NotifyElement Line 1044  ThotBool UseButtonClicked (NotifyElement
     return TRUE;      return TRUE;
   if (!IsTemplateInstanceDocument (doc))    if (!IsTemplateInstanceDocument (doc))
     return FALSE; /* let Thot perform normal operation */      return FALSE; /* let Thot perform normal operation */
       
   TtaGetActiveView (&doc, &view);    TtaGetActiveView (&doc, &view);
   if (view != 1)    if (view != 1)
     return FALSE; /* let Thot perform normal operation */      return FALSE; /* let Thot perform normal operation */
Line 1069  ThotBool UseButtonClicked (NotifyElement Line 1069  ThotBool UseButtonClicked (NotifyElement
 #ifdef AMAYA_DEBUG  #ifdef AMAYA_DEBUG
       printf("UseButtonClicked : \n  > %s\n", listtypes);        printf("UseButtonClicked : \n  > %s\n", listtypes);
 #endif /* AMAYA_DEBUG */  #endif /* AMAYA_DEBUG */
         
       result = QueryStringFromMenu(doc, listtypes);        result = QueryStringFromMenu(doc, listtypes);
       if (result)        if (result)
       {        {
Line 1080  ThotBool UseButtonClicked (NotifyElement Line 1080  ThotBool UseButtonClicked (NotifyElement
           oldStructureChecking = TtaGetStructureChecking (doc);            oldStructureChecking = TtaGetStructureChecking (doc);
           TtaSetStructureChecking (FALSE, doc);            TtaSetStructureChecking (FALSE, doc);
           TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);            TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
             
           /* Insert */            /* Insert */
           newEl = Template_InsertUseChildren(doc, el, decl);            newEl = Template_InsertUseChildren(doc, el, decl);
           for(child = TtaGetFirstChild(newEl); child; TtaNextSibling(&child))            for(child = TtaGetFirstChild(newEl); child; TtaNextSibling(&child))
           {            {
             TtaRegisterElementCreate(child, doc);              TtaRegisterElementCreate(child, doc);
           }            }
             
           TtaChangeTypeOfElement(el, doc, Template_EL_useSimple);            TtaChangeTypeOfElement(el, doc, Template_EL_useSimple);
           TtaRegisterElementTypeChange(el, Template_EL_useEl, doc);            TtaRegisterElementTypeChange(el, Template_EL_useEl, doc);
             
           /* xt:currentType attribute.*/            /* xt:currentType attribute.*/
           SetAttributeStringValueWithUndo(el, Template_ATTR_currentType, result);            SetAttributeStringValueWithUndo(el, Template_ATTR_currentType, result);
             
           /* Finish insertion. */            /* Finish insertion. */
           TtaCloseUndoSequence(doc);            TtaCloseUndoSequence(doc);
           TtaSetDocumentModified (doc);            TtaSetDocumentModified (doc);
           TtaSetStructureChecking (oldStructureChecking, doc);            TtaSetStructureChecking (oldStructureChecking, doc);
             
           firstEl = GetFirstEditableElement(newEl);            firstEl = GetFirstEditableElement(newEl);
           if (firstEl)            if (firstEl)
           {            {
Line 1145  ThotBool UseSimpleButtonClicked (NotifyE Line 1145  ThotBool UseSimpleButtonClicked (NotifyE
   att = TtaGetAttribute (event->element, attrType);    att = TtaGetAttribute (event->element, attrType);
   if (att)    if (att)
     return OptionButtonClicked (event);      return OptionButtonClicked (event);
     
   parentType = TtaGetElementType (TtaGetParent( event->element));    parentType = TtaGetElementType (TtaGetParent( event->element));
   if (parentType.ElTypeNum == Template_EL_repeat)    if (parentType.ElTypeNum == Template_EL_repeat)
     return RepeatButtonClicked (event);      return RepeatButtonClicked (event);
   else if (parentType.ElTypeNum == Template_EL_bag)    else if (parentType.ElTypeNum == Template_EL_bag)
     return BagButtonClicked (event);      return BagButtonClicked (event);
 #endif /* TEMPLATES */    #endif /* TEMPLATES */
   return FALSE;    return FALSE;
 }  }
   
Line 1233  void Template_FillFromDocument (Document Line 1233  void Template_FillFromDocument (Document
 #ifdef TEMPLATES  #ifdef TEMPLATES
   XTigerTemplate t = GetXTigerTemplate (DocumentURLs[doc]);    XTigerTemplate t = GetXTigerTemplate (DocumentURLs[doc]);
   Element        root;    Element        root;
     
 #ifdef AMAYA_DEBUG  #ifdef AMAYA_DEBUG
   printf("Template_FillFromDocument\n");    printf("Template_FillFromDocument\n");
 #endif  #endif
Line 1245  void Template_FillFromDocument (Document Line 1245  void Template_FillFromDocument (Document
       SetTemplateDocument (t, doc);        SetTemplateDocument (t, doc);
   
       Template_PrepareTemplate(t);        Template_PrepareTemplate(t);
         
       if(IsTemplateInstanceDocument(doc))        if(IsTemplateInstanceDocument(doc))
         {          {
 #ifdef AMAYA_DEBUG  #ifdef AMAYA_DEBUG
Line 1262  void Template_FillFromDocument (Document Line 1262  void Template_FillFromDocument (Document
         printf("  > library\n");          printf("  > library\n");
       else if(t->state&templTemplate)        else if(t->state&templTemplate)
         printf("  > template\n");          printf("  > template\n");
 #endif        #endif
       // Mark loaded        // Mark loaded
       t->state |= templloaded;        t->state |= templloaded;
       TtaSetDocumentUnmodified (doc);        TtaSetDocumentUnmodified (doc);
       UpdateTemplateMenus (doc);        UpdateTemplateMenus (doc);
         
 #ifdef AMAYA_DEBUG    #ifdef AMAYA_DEBUG
       DumpAllDeclarations();        DumpAllDeclarations();
 #endif /* AMAYA_DEBUG */  #endif /* AMAYA_DEBUG */
     }      }
Line 1328  void Template_CheckAndPrepareInstance (c Line 1328  void Template_CheckAndPrepareInstance (c
         {          {
           buffer[res] = EOS;            buffer[res] = EOS;
           begin = strstr (buffer, "<?xtiger");            begin = strstr (buffer, "<?xtiger");
             
           if (begin)            if (begin)
           {            {
             // Search for template version              // Search for template version
Line 1350  void Template_CheckAndPrepareInstance (c Line 1350  void Template_CheckAndPrepareInstance (c
                 template_version = TtaStrdup (content);                  template_version = TtaStrdup (content);
                 *ptr = '"';                  *ptr = '"';
               }                }
              
             // Search for template uri              // Search for template uri
             ptr = strstr (begin, "template");              ptr = strstr (begin, "template");
             if (ptr && ptr[8] != 'V')              if (ptr && ptr[8] != 'V')
Line 1491  ThotBool TemplateElementWillBeCreated (N Line 1491  ThotBool TemplateElementWillBeCreated (N
           (elType.ElTypeNum == Template_EL_useSimple ||            (elType.ElTypeNum == Template_EL_useSimple ||
            elType.ElTypeNum == Template_EL_useEl))             elType.ElTypeNum == Template_EL_useEl))
         return FALSE;          return FALSE;
       return !Template_CanInsertElementInBagElement (event->document, elType, ancestor);              return !Template_CanInsertElementInBagElement (event->document, elType, ancestor);
     }      }
     else if(ancestorType.ElTypeNum == Template_EL_useSimple ||      else if(ancestorType.ElTypeNum == Template_EL_useSimple ||
             ancestorType.ElTypeNum == Template_EL_useEl)              ancestorType.ElTypeNum == Template_EL_useEl)
Line 1505  ThotBool TemplateElementWillBeCreated (N Line 1505  ThotBool TemplateElementWillBeCreated (N
       return !b;        return !b;
     }      }
   }    }
     
   if (elType.ElSSchema == templateSSchema && (    if (elType.ElSSchema == templateSSchema && (
       elType.ElTypeNum == Template_EL_TEXT_UNIT ||         elType.ElTypeNum == Template_EL_TEXT_UNIT ||
       elType.ElTypeNum == Template_EL_component))        elType.ElTypeNum == Template_EL_component))
   {    {
     return FALSE;      return FALSE;
   }    }
     
   // Can not insert.    // Can not insert.
   return TRUE;    return TRUE;
 #endif /* TEMPLATES*/  #endif /* TEMPLATES*/
Line 1535  ThotBool TemplateElementWillBeDeleted (N Line 1535  ThotBool TemplateElementWillBeDeleted (N
   SSchema        templateSSchema;    SSchema        templateSSchema;
   XTigerTemplate t;    XTigerTemplate t;
   ThotBool       selparent = FALSE;    ThotBool       selparent = FALSE;
     
   if(event->info==1)    if(event->info==1)
     return FALSE;      return FALSE;
   
Line 1545  ThotBool TemplateElementWillBeDeleted (N Line 1545  ThotBool TemplateElementWillBeDeleted (N
   templateSSchema = TtaGetSSchema ("Template", event->document);    templateSSchema = TtaGetSSchema ("Template", event->document);
   if (templateSSchema == NULL)    if (templateSSchema == NULL)
     return FALSE; // let Thot do the job      return FALSE; // let Thot do the job
     
   t = GetXTigerDocTemplate(doc);    t = GetXTigerDocTemplate(doc);
   if(Template_IsTemplate(t)||Template_IsLibrary(t))    if(Template_IsTemplate(t)||Template_IsLibrary(t))
     return FALSE; // If template or library, pass to specialized functions.      return FALSE; // If template or library, pass to specialized functions.
Line 1554  ThotBool TemplateElementWillBeDeleted (N Line 1554  ThotBool TemplateElementWillBeDeleted (N
   if (xtElem)    if (xtElem)
   {    {
     xtType = TtaGetElementType(xtElem);      xtType = TtaGetElementType(xtElem);
       
       
   
     if (xtType.ElTypeNum==Template_EL_bag)      if (xtType.ElTypeNum==Template_EL_bag)
     {      {
Line 1581  ThotBool TemplateElementWillBeDeleted (N Line 1581  ThotBool TemplateElementWillBeDeleted (N
         type = GetAttributeStringValueFromNum(xtElem, Template_ATTR_currentType, NULL);          type = GetAttributeStringValueFromNum(xtElem, Template_ATTR_currentType, NULL);
         dec = Template_GetDeclaration(t, type);          dec = Template_GetDeclaration(t, type);
         TtaFreeMemory(type);          TtaFreeMemory(type);
           
         if (dec && dec->nature == XmlElementNat)          if (dec && dec->nature == XmlElementNat)
           return FALSE; // Can remove element only if in xt:use current type is base language element.             return FALSE; // Can remove element only if in xt:use current type is base language element.
         else          else
           return TRUE;            return TRUE;
       }        }
Line 1611  ThotBool TemplateElementWillBeDeleted (N Line 1611  ThotBool TemplateElementWillBeDeleted (N
       return TRUE;        return TRUE;
     }      }
   }    }
     
   //TODO Test if current element is use or repeat.    //TODO Test if current element is use or repeat.
   // Because if an element is delete and it is the unique child of its parent,    // Because if an element is delete and it is the unique child of its parent,
   // the parent intends to destroy itself.     // the parent intends to destroy itself.
     
   return TRUE;    return TRUE;
 #else /* TEMPLATES */  #else /* TEMPLATES */
   return FALSE;    return FALSE;
Line 1668  void CreateTemplateFromDocument(Document Line 1668  void CreateTemplateFromDocument(Document
       DocumentMeta[doc] && DocumentMeta[doc]->full_content_location)        DocumentMeta[doc] && DocumentMeta[doc]->full_content_location)
     {      {
     // use the location instead of the current URI      // use the location instead of the current URI
       
     strcpy (buffer, DocumentMeta[doc]->full_content_location);      strcpy (buffer, DocumentMeta[doc]->full_content_location);
     }      }
   else    else
Line 1711  void UpdateTemplateMenus (Document doc) Line 1711  void UpdateTemplateMenus (Document doc)
       TtaSetItemOn (doc, 1, Tools, BTemplateCreateUseCompBox);        TtaSetItemOn (doc, 1, Tools, BTemplateCreateUseCompBox);
       TtaSetItemOn (doc, 1, Tools, BTemplateCreateRepeat);        TtaSetItemOn (doc, 1, Tools, BTemplateCreateRepeat);
       TtaSetItemOn (doc, 1, Tools, BTemplateCreateRepeatComp);        TtaSetItemOn (doc, 1, Tools, BTemplateCreateRepeatComp);
       TtaSetItemOn (doc, 1, Tools, BTemplateCreateFreeBox);              TtaSetItemOn (doc, 1, Tools, BTemplateCreateFreeBox);
       TtaSetItemOn (doc, 1, Tools, BTemplateCreateUnion);        TtaSetItemOn (doc, 1, Tools, BTemplateCreateUnion);
     }      }
   else    else
Line 1739  void UninstanciateTemplateDocument(Docum Line 1739  void UninstanciateTemplateDocument(Docum
   XTigerTemplate t = GetXTigerDocTemplate(doc);    XTigerTemplate t = GetXTigerDocTemplate(doc);
   if(t)    if(t)
     Template_Close(t);      Template_Close(t);
 #endif /* TEMPLATES */    #endif /* TEMPLATES */
 }  }
   
   
Line 1759  void Template_PrepareInstance(char *file Line 1759  void Template_PrepareInstance(char *file
   t->base_uri        = template_url;    t->base_uri        = template_url;
   t->doc             = doc;    t->doc             = doc;
   t->ref             = 1;    t->ref             = 1;
     
 #endif /* TEMPLATES */  #endif /* TEMPLATES */
 }  }
   
Line 1774  void SetDocumentAsXTigerTemplate(Documen Line 1774  void SetDocumentAsXTigerTemplate(Documen
   XTigerTemplate t = GetXTigerDocTemplate(doc);    XTigerTemplate t = GetXTigerDocTemplate(doc);
   if(t)    if(t)
     t->state |= templTemplate;      t->state |= templTemplate;
 #endif /* TEMPLATES */    #endif /* TEMPLATES */
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 1787  void SetDocumentAsXTigerLibrary(Document Line 1787  void SetDocumentAsXTigerLibrary(Document
   XTigerTemplate t = GetXTigerDocTemplate(doc);    XTigerTemplate t = GetXTigerDocTemplate(doc);
   if(t)    if(t)
     t->state |= templLibrary;      t->state |= templLibrary;
 #endif /* TEMPLATES */    #endif /* TEMPLATES */
 }  }
   
   
Line 1806  void TemplateCreateTextBox(Document doc, Line 1806  void TemplateCreateTextBox(Document doc,
   Element     use;    Element     use;
   char        buffer[128];    char        buffer[128];
   ThotBool    oldStructureChecking;    ThotBool    oldStructureChecking;
     
   char *title = TtaGetMessage (AMAYA, AM_TEMPLATE_USESTRING);    char *title = TtaGetMessage (AMAYA, AM_TEMPLATE_USESTRING);
   char *label = TtaGetMessage (AMAYA, AM_TEMPLATE_LABEL);    char *label = TtaGetMessage (AMAYA, AM_TEMPLATE_LABEL);
   
   if (!TtaGetDocumentAccessMode(doc))    if (!TtaGetDocumentAccessMode(doc))
     return;      return;
     
   if(doc && TtaGetDocumentAccessMode(doc) && sstempl &&    if(doc && TtaGetDocumentAccessMode(doc) && sstempl &&
       IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))        IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))
     {      {
Line 1826  void TemplateCreateTextBox(Document doc, Line 1826  void TemplateCreateTextBox(Document doc,
               selType = TtaGetElementType(selElem);                selType = TtaGetElementType(selElem);
               firstChar = lastChar = 0;                firstChar = lastChar = 0;
             }              }
             
           if(selType.ElTypeNum==1)            if(selType.ElTypeNum==1)
             {              {
               QueryStringFromUser(label, title, buffer, 127);                QueryStringFromUser(label, title, buffer, 127);
Line 1862  void TemplateCreateTextBox(Document doc, Line 1862  void TemplateCreateTextBox(Document doc,
                   if(selType.ElSSchema==sstempl && selType.ElTypeNum==Template_EL_useSimple)                    if(selType.ElSSchema==sstempl && selType.ElTypeNum==Template_EL_useSimple)
                     {                      {
                       SetAttributeStringValue(use, Template_ATTR_types, "string");                        SetAttributeStringValue(use, Template_ATTR_types, "string");
                       SetAttributeStringValue(use, Template_ATTR_title, buffer);                                              SetAttributeStringValue(use, Template_ATTR_title, buffer);
                     }                      }
                 }                  }
                 
               TtaSetStructureChecking (oldStructureChecking, doc);                TtaSetStructureChecking (oldStructureChecking, doc);
                 
             }              }
             
         }          }
     }      }
 #endif /* TEMPLATES */  #endif /* TEMPLATES */
Line 1897  void TemplateCreateFreeBox(Document doc, Line 1897  void TemplateCreateFreeBox(Document doc,
   
   if (!TtaGetDocumentAccessMode(doc))    if (!TtaGetDocumentAccessMode(doc))
     return;      return;
     
   if(doc && TtaGetDocumentAccessMode(doc) && sstempl &&    if(doc && TtaGetDocumentAccessMode(doc) && sstempl &&
       IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))        IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))
     {      {
       TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);        TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
       TtaGiveLastSelectedElement(doc, &selElem2, &firstChar2, &lastChar2);        TtaGiveLastSelectedElement(doc, &selElem2, &firstChar2, &lastChar2);
         
       if(selElem && selElem2)        if(selElem && selElem2)
         {          {
           selType =  TtaGetElementType(selElem);            selType =  TtaGetElementType(selElem);
Line 1912  void TemplateCreateFreeBox(Document doc, Line 1912  void TemplateCreateFreeBox(Document doc,
           QueryStringFromUser(label, title, buffer, 127);            QueryStringFromUser(label, title, buffer, 127);
           bagType.ElSSchema = sstempl;            bagType.ElSSchema = sstempl;
           bagType.ElTypeNum = Template_EL_bag;            bagType.ElTypeNum = Template_EL_bag;
             
           parent  = TtaGetParent(selElem);            parent  = TtaGetParent(selElem);
           parent2 = TtaGetParent(selElem2);            parent2 = TtaGetParent(selElem2);
             
           if(firstChar==0 && firstChar2==0 && parent == parent2)            if(firstChar==0 && firstChar2==0 && parent == parent2)
             {              {
               ThotBool        oldStructureChecking;                ThotBool        oldStructureChecking;
Line 1937  void TemplateCreateFreeBox(Document doc, Line 1937  void TemplateCreateFreeBox(Document doc,
                 {                  {
                   current = selElem;                    current = selElem;
                   TtaNextSibling(&selElem);                    TtaNextSibling(&selElem);
                     
                   TtaRegisterElementDelete (current, doc);                    TtaRegisterElementDelete (current, doc);
                   TtaRemoveTree(current, doc);                    TtaRemoveTree(current, doc);
                   if(child)                    if(child)
Line 1947  void TemplateCreateFreeBox(Document doc, Line 1947  void TemplateCreateFreeBox(Document doc,
                   TtaRegisterElementDelete (current, doc);                    TtaRegisterElementDelete (current, doc);
                   child = current;                    child = current;
                 }                  }
                 
               SetAttributeStringValue(bag, Template_ATTR_types, "any");                SetAttributeStringValue(bag, Template_ATTR_types, "any");
               SetAttributeStringValue(bag, Template_ATTR_title, buffer);                SetAttributeStringValue(bag, Template_ATTR_title, buffer);
               TtaCloseUndoSequence(doc);                TtaCloseUndoSequence(doc);
               TtaSelectElement(doc, bag);                TtaSelectElement(doc, bag);
                 
               TtaSetStructureChecking (oldStructureChecking, doc);                TtaSetStructureChecking (oldStructureChecking, doc);
               TtaSetDisplayMode (doc, dispMode);                TtaSetDisplayMode (doc, dispMode);
             }              }
Line 1977  void TemplateCreateUnion(Document doc, V Line 1977  void TemplateCreateUnion(Document doc, V
   Element     selElem;    Element     selElem;
   ElementType selType;    ElementType selType;
   int         firstChar, lastChar;    int         firstChar, lastChar;
     
     
   if(t && sstempl)    if(t && sstempl)
     {      {
       TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);        TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
Line 1991  void TemplateCreateUnion(Document doc, V Line 1991  void TemplateCreateUnion(Document doc, V
           if(QueryUnionFromUser(proposed, NULL, &name, &types, TRUE))            if(QueryUnionFromUser(proposed, NULL, &name, &types, TRUE))
             {              {
               TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);                TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
       
               head = TemplateFindHead(doc);                head = TemplateFindHead(doc);
               sibling = TtaGetLastChild(head);                sibling = TtaGetLastChild(head);
       
               unionType.ElSSchema = sstempl;                unionType.ElSSchema = sstempl;
               unionType.ElTypeNum = Template_EL_union;                unionType.ElTypeNum = Template_EL_union;
               unionEl = TtaNewElement(doc, unionType);                unionEl = TtaNewElement(doc, unionType);
                 
               if(sibling)                if(sibling)
                 TtaInsertSibling(unionEl, sibling, FALSE, doc);                  TtaInsertSibling(unionEl, sibling, FALSE, doc);
               else                else
Line 2007  void TemplateCreateUnion(Document doc, V Line 2007  void TemplateCreateUnion(Document doc, V
                   TtaInsertFirstChild(&sibling, head, doc);                    TtaInsertFirstChild(&sibling, head, doc);
                 }                  }
               Template_SetName(doc, unionEl, name, TRUE);                Template_SetName(doc, unionEl, name, TRUE);
                 
               SetAttributeStringValue(unionEl, Template_ATTR_includeAt, types);                SetAttributeStringValue(unionEl, Template_ATTR_includeAt, types);
               TtaSetAccessRight(unionEl, ReadOnly, doc);                TtaSetAccessRight(unionEl, ReadOnly, doc);
                 
               TtaRegisterElementCreate(unionEl, doc);                TtaRegisterElementCreate(unionEl, doc);
                 
               TtaSelectElement(doc, unionEl);                TtaSelectElement(doc, unionEl);
               TtaCloseUndoSequence(doc);                TtaCloseUndoSequence(doc);
                 
               Template_DeclareNewUnion (t, name, types, "");                Template_DeclareNewUnion (t, name, types, "");
               TtaFreeMemory(proposed);                TtaFreeMemory(proposed);
               TtaFreeMemory(name);                TtaFreeMemory(name);
               TtaFreeMemory(types);                TtaFreeMemory(types);
             }                        }
         }          }
     }        }
   
 #endif /* TEMPLATES */  #endif /* TEMPLATES */
 }  }
Line 2037  void Template_ModifyUnionElement(Documen Line 2037  void Template_ModifyUnionElement(Documen
   SSchema        sstempl = TtaGetSSchema ("Template", doc);    SSchema        sstempl = TtaGetSSchema ("Template", doc);
   ElementType    unionType;    ElementType    unionType;
   char          *proposed, *checked, *name, *types=NULL;    char          *proposed, *checked, *name, *types=NULL;
     
   if(doc && unionEl && t && sstempl)    if(doc && unionEl && t && sstempl)
     {      {
       unionType = TtaGetElementType(unionEl);        unionType = TtaGetElementType(unionEl);
Line 2082  void TemplateCreateRepeatComp(Document d Line 2082  void TemplateCreateRepeatComp(Document d
   Template_CreateRepeatFromSelection    Template_CreateRepeatFromSelection
   Create a xt:repeat with the selection.    Create a xt:repeat with the selection.
   If selection is empty, insert an inline xt:use.    If selection is empty, insert an inline xt:use.
   If createComp is false, create a xt:use with types at the selected block.     If createComp is false, create a xt:use with types at the selected block.
   If createComp is true, create a component with the selection.    If createComp is true, create a component with the selection.
   Return the xt:use element.    Return the xt:use element.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
Line 2104  Element Template_CreateRepeatFromSelecti Line 2104  Element Template_CreateRepeatFromSelecti
   
   if (!TtaGetDocumentAccessMode(doc))    if (!TtaGetDocumentAccessMode(doc))
     return NULL;      return NULL;
     
   if(doc && TtaGetDocumentAccessMode(doc) && sstempl &&    if(doc && TtaGetDocumentAccessMode(doc) && sstempl &&
       IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))        IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))
     {      {
Line 2118  Element Template_CreateRepeatFromSelecti Line 2118  Element Template_CreateRepeatFromSelecti
   
           repType.ElSSchema = sstempl;            repType.ElSSchema = sstempl;
           repType.ElTypeNum = Template_EL_repeat;            repType.ElTypeNum = Template_EL_repeat;
             
           parent  = TtaGetParent(selElem);            parent  = TtaGetParent(selElem);
           parent2 = TtaGetParent(selElem2);            parent2 = TtaGetParent(selElem2);
   
Line 2130  Element Template_CreateRepeatFromSelecti Line 2130  Element Template_CreateRepeatFromSelecti
                 TtaSetDisplayMode (doc, DeferredDisplay);                  TtaSetDisplayMode (doc, DeferredDisplay);
               oldStructureChecking = TtaGetStructureChecking (doc);                oldStructureChecking = TtaGetStructureChecking (doc);
               TtaSetStructureChecking (FALSE, doc);                TtaSetStructureChecking (FALSE, doc);
                 
               if(selElem==selElem2 && selType.ElSSchema==sstempl &&                 if(selElem==selElem2 && selType.ElSSchema==sstempl &&
                   (selType.ElTypeNum==Template_EL_useEl ||                     (selType.ElTypeNum==Template_EL_useEl ||
                    selType.ElTypeNum==Template_EL_useSimple))                     selType.ElTypeNum==Template_EL_useSimple))
                 use = selElem;                  use = selElem;
               else                else
Line 2140  Element Template_CreateRepeatFromSelecti Line 2140  Element Template_CreateRepeatFromSelecti
               if(use)                if(use)
                 {                  {
                   TtaExtendUndoSequence(doc);                    TtaExtendUndoSequence(doc);
                     
                   rep = TtaNewElement(doc, repType);                    rep = TtaNewElement(doc, repType);
                     
                   TtaInsertSibling(rep, use, FALSE, doc);                    TtaInsertSibling(rep, use, FALSE, doc);
                   SetAttributeStringValue(rep, Template_ATTR_title, buffer);                    SetAttributeStringValue(rep, Template_ATTR_title, buffer);
                   TtaRegisterElementCreate(rep, doc);                    TtaRegisterElementCreate(rep, doc);
                     
                   TtaRegisterElementDelete (use, doc);                    TtaRegisterElementDelete (use, doc);
                   TtaRemoveTree(use, doc);                    TtaRemoveTree(use, doc);
                     
                   TtaInsertFirstChild(&use, rep, doc);                    TtaInsertFirstChild(&use, rep, doc);
                   TtaRegisterElementCreate(use, doc);                    TtaRegisterElementCreate(use, doc);
                     
                   TtaSelectElement(doc, use);                    TtaSelectElement(doc, use);
                   TtaCloseUndoSequence(doc);                    TtaCloseUndoSequence(doc);
                 }                  }
                 
               TtaSetStructureChecking (oldStructureChecking, doc);                TtaSetStructureChecking (oldStructureChecking, doc);
               TtaSetDisplayMode (doc, dispMode);                TtaSetDisplayMode (doc, dispMode);
               return rep;                return rep;
Line 2193  void TemplateCreateUseCompBox(Document d Line 2193  void TemplateCreateUseCompBox(Document d
   Template_CreateInlineUse    Template_CreateInlineUse
   Create an inline xt:use with the selection.    Create an inline xt:use with the selection.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 static ThotBool Template_CreateInlineUse(Document doc)  static Element Template_CreateInlineUse(Document doc)
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   SSchema        sstempl = TtaGetSSchema ("Template", doc);    SSchema        sstempl = TtaGetSSchema ("Template", doc);
   int            firstChar, lastChar;    int            firstChar, lastChar;
   Element        selElem, use;    Element        selElem, use = NULL;
   XTigerTemplate t = GetXTigerDocTemplate(doc);    XTigerTemplate t = GetXTigerDocTemplate(doc);
   char          *proposed, *label = NULL, *types=NULL;    char          *proposed, *label = NULL, *types=NULL;
   ThotBool       option, res = FALSE;    ThotBool       option;
     
   if(t && sstempl)    if(t && sstempl)
     {      {
       proposed = Template_GetInlineLevelDeclarations(t, TRUE, TRUE);        proposed = Template_GetInlineLevelDeclarations(t, TRUE, TRUE);
Line 2211  static ThotBool Template_CreateInlineUse Line 2211  static ThotBool Template_CreateInlineUse
           TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);            TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
   
           GenerateInlineElement(Template_EL_useEl, sstempl, 0, NULL, TRUE);            GenerateInlineElement(Template_EL_useEl, sstempl, 0, NULL, TRUE);
             
           TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);            TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
             
           use = selElem;            use = selElem;
           TtaNextSibling(&use);            TtaNextSibling(&use);
   
           SetAttributeStringValue(use, Template_ATTR_title, label);            SetAttributeStringValue(use, Template_ATTR_title, label);
           SetAttributeStringValue(use, Template_ATTR_types, types);            SetAttributeStringValue(use, Template_ATTR_types, types);
           res = TRUE;  
             
           TtaSelectElement(doc, use);            TtaSelectElement(doc, use);
           TtaCloseUndoSequence(doc);            TtaCloseUndoSequence(doc);
         }          }
         
       TtaFreeMemory(proposed);        TtaFreeMemory(proposed);
       TtaFreeMemory(label);        TtaFreeMemory(label);
       TtaFreeMemory(types);        TtaFreeMemory(types);
       return res;        return use;
     }        }
     
 #endif /* TEMPLATES */  #endif /* TEMPLATES */
   return FALSE;    return FALSE;
    
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   Template_CreateEmptyBlockUse    Template_CreateEmptyBlockUse
   Create a block xt:use with the selection.    Create a block xt:use with the selection.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 static ThotBool Template_CreateEmptyBlockUse(Document doc)  static Element Template_CreateEmptyBlockUse(Document doc)
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   SSchema        sstempl = TtaGetSSchema ("Template", doc);    SSchema        sstempl = TtaGetSSchema ("Template", doc);
Line 2250  static ThotBool Template_CreateEmptyBloc Line 2249  static ThotBool Template_CreateEmptyBloc
   XTigerTemplate t = GetXTigerDocTemplate(doc);    XTigerTemplate t = GetXTigerDocTemplate(doc);
   char          *proposed, *label = NULL, *types=NULL;    char          *proposed, *label = NULL, *types=NULL;
   ThotBool       option, res = FALSE;    ThotBool       option, res = FALSE;
     
     
   if(t && sstempl)    if(t && sstempl)
     {      {
       proposed = Template_GetBlockLevelDeclarations(t, TRUE);        proposed = Template_GetBlockLevelDeclarations(t, TRUE);
Line 2263  static ThotBool Template_CreateEmptyBloc Line 2262  static ThotBool Template_CreateEmptyBloc
           useType.ElSSchema = sstempl;            useType.ElSSchema = sstempl;
           useType.ElTypeNum = Template_EL_useEl;            useType.ElTypeNum = Template_EL_useEl;
           use = TtaNewElement(doc, useType);            use = TtaNewElement(doc, useType);
             
           TtaInsertSibling(use, selElem, FALSE, doc);            TtaInsertSibling(use, selElem, FALSE, doc);
           TtaDeleteTree(selElem, doc);            TtaDeleteTree(selElem, doc);
             
           SetAttributeStringValue(use, Template_ATTR_title, label);            SetAttributeStringValue(use, Template_ATTR_title, label);
           SetAttributeStringValue(use, Template_ATTR_types, types);            SetAttributeStringValue(use, Template_ATTR_types, types);
           TtaRegisterElementCreate(use, doc);            TtaRegisterElementCreate(use, doc);
           res = TRUE;            res = TRUE;
             
           TtaSelectElement(doc, use);            TtaSelectElement(doc, use);
           TtaCloseUndoSequence(doc);            TtaCloseUndoSequence(doc);
   
         }          }
         
       TtaFreeMemory(proposed);        TtaFreeMemory(proposed);
       TtaFreeMemory(label);        TtaFreeMemory(label);
       TtaFreeMemory(types);        TtaFreeMemory(types);
       return res;            return use;
     }        }
     
 #endif /* TEMPLATES */  #endif /* TEMPLATES */
   return FALSE;    return FALSE;
 }  }
Line 2291  static ThotBool Template_CreateEmptyBloc Line 2290  static ThotBool Template_CreateEmptyBloc
   Template_CreateUseFromSelection    Template_CreateUseFromSelection
   Create a xt:use with the selection.    Create a xt:use with the selection.
   If selection is empty, insert an inline xt:use.    If selection is empty, insert an inline xt:use.
   If createComp is false, create a xt:use with types at the selected block.     If createComp is false, create a xt:use with types at the selected block.
   If createComp is true, create a component with the selection.    If createComp is true, create a component with the selection.
   Return the xt:use element.    Return the xt:use element.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 Element Template_CreateUseFromSelection(Document doc, ThotBool createComp)  Element Template_CreateUseFromSelection(Document doc, ThotBool createComp)
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   ThotBool    oldStructureChecking;    ThotBool    oldStructureChecking, option;
   DisplayMode dispMode;    DisplayMode dispMode;
   Element     selElem, selElem2, parent, parent2;    Element     selElem, selElem2, parent, parent2;
   ElementType selType, selType2;    ElementType selType, selType2;
   int         firstChar, lastChar, firstChar2, lastChar2;    int         firstChar, lastChar, firstChar2, lastChar2;
   SSchema     sstempl = TtaGetSSchema ("Template", doc),    SSchema     sstempl = TtaGetSSchema ("Template", doc),
               sshtml  = TtaGetSSchema ("HTML", doc);                sshtml  = TtaGetSSchema ("HTML", doc);
     Attribute   optionAttr;
     XTigerTemplate t;
   
   ElementType useType;    ElementType useType;
   Element     use = NULL, comp, prev;    Element     use = NULL, comp, prev;
     char       *proposed, *checked, *types=NULL;
   char        buffer[128];    char        buffer[128];
   int         sz = 128;    int         sz = 128;
   
   if (!TtaGetDocumentAccessMode(doc))    if (!TtaGetDocumentAccessMode(doc))
     return NULL;      return NULL;
     
   if(doc && TtaGetDocumentAccessMode(doc) && sstempl &&    if(doc && TtaGetDocumentAccessMode(doc) && sstempl &&
       IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))        IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))
     {      {
       TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);        TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
       TtaGiveLastSelectedElement(doc, &selElem2, &firstChar2, &lastChar2);        TtaGiveLastSelectedElement(doc, &selElem2, &firstChar2, &lastChar2);
   
       if(selElem && selElem2)  //      printf(">> %p %d %d %s (%d)\n", selElem, firstChar, lastChar, TtaGetElementTypeName(TtaGetElementType(selElem)), TtaGetElementType(selElem).ElTypeNum);
   //      printf(" > %p %d %d %s (%d)\n", selElem2, firstChar2, lastChar2, TtaGetElementTypeName(TtaGetElementType(selElem2)), TtaGetElementType(selElem2).ElTypeNum);
   
         t = GetXTigerDocTemplate(doc);
   
         if(selElem && selElem2 && t)
         {          {
           selType =  TtaGetElementType(selElem);            selType =  TtaGetElementType(selElem);
           selType2 =  TtaGetElementType(selElem2);            selType2 =  TtaGetElementType(selElem2);
Line 2332  Element Template_CreateUseFromSelection( Line 2339  Element Template_CreateUseFromSelection(
             TtaSetDisplayMode (doc, DeferredDisplay);              TtaSetDisplayMode (doc, DeferredDisplay);
           oldStructureChecking = TtaGetStructureChecking (doc);            oldStructureChecking = TtaGetStructureChecking (doc);
           TtaSetStructureChecking (FALSE, doc);            TtaSetStructureChecking (FALSE, doc);
             
           if(firstChar==0 && firstChar2==0 && parent == parent2)            if(firstChar==0 && firstChar2==0 && parent == parent2)
             {              {
               if(selType.ElSSchema==sshtml && selType.ElTypeNum==HTML_EL_Element)                if(selType.ElSSchema==sstempl)
                 Template_CreateEmptyBlockUse(doc);                  {
                     // The selection is a template element.
                     switch(selType.ElTypeNum)
                     {
                       case Template_EL_useEl:
                       case Template_EL_useSimple:
                         // TODO query to add/remove some types
                         if(TtaGetElementVolume(selElem)==0)
                           {
                             proposed = Template_GetAllDeclarations(t, TRUE, TRUE, TRUE);
                             checked  = GetAttributeStringValueFromNum(selElem, Template_ATTR_types, NULL);
                             option   = GetAttributeIntValueFromNum(selElem, Template_ATTR_option)==Template_ATTR_option_VAL_option_set;
                             if(QueryUseFromUser(proposed, checked, buffer, 128, &types, &option))
                               {
                                 TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
                                 SetAttributeStringValueWithUndo(selElem, Template_ATTR_types, types);
                                 SetAttributeStringValueWithUndo(selElem, Template_ATTR_title, buffer);
                                 if(option)
                                   SetAttributeIntValue(selElem, Template_ATTR_option, Template_ATTR_option_VAL_option_set, TRUE);
                                 else
                                   SetAttributeIntValue(selElem, Template_ATTR_option, Template_ATTR_option_VAL_option_unset, TRUE);
   
                                 TtaCloseUndoSequence(doc);
                               }
                             TtaFreeMemory(proposed);
                             TtaFreeMemory(checked);
                             TtaFreeMemory(types);
                             createComp = FALSE;
                           }
                         break;
                       default:
                         // Do nothing
                         break;
                     }
                   }
                 else if(selType.ElSSchema==sshtml && (selType.ElTypeNum==HTML_EL_Element ||
                     selType.ElTypeNum==HTML_EL_Basic_Elem ||
                     (selType.ElTypeNum==HTML_EL_Paragraph && TtaGetElementVolume(selElem)==0)))
                   {
                     // Create a block-level xt:use instead of selection.
   
                     use = Template_CreateEmptyBlockUse(doc);
                   }
               else                else
                 {                  {
                   prev = selElem;                    prev = selElem;
Line 2344  Element Template_CreateUseFromSelection( Line 2393  Element Template_CreateUseFromSelection(
   
                   if(createComp)                    if(createComp)
                     {                      {
                       // Create a xt:component from selection and create a xt:use using it                         // Create a xt:component from selection and create a xt:use using it
                       comp = Template_CreateComponentFromSelection(doc);                        comp = Template_CreateComponentFromSelection(doc);
                       if(comp)                        if(comp)
                         {                          {
                           TtaExtendUndoSequence(doc);                            TtaExtendUndoSequence(doc);
                             
                           useType.ElSSchema = sstempl;                            useType.ElSSchema = sstempl;
                           useType.ElTypeNum = Template_EL_useEl;                            useType.ElTypeNum = Template_EL_useEl;
                           use = TtaNewElement(doc, useType);                            use = TtaNewElement(doc, useType);
Line 2357  Element Template_CreateUseFromSelection( Line 2406  Element Template_CreateUseFromSelection(
                             TtaInsertSibling(use, prev, FALSE, doc);                              TtaInsertSibling(use, prev, FALSE, doc);
                           else                            else
                             TtaInsertFirstChild(&use, parent, doc);                              TtaInsertFirstChild(&use, parent, doc);
                             
                           GiveAttributeStringValueFromNum(comp, Template_ATTR_name, buffer, &sz);                            GiveAttributeStringValueFromNum(comp, Template_ATTR_name, buffer, &sz);
                           SetAttributeStringValue(use, Template_ATTR_types, buffer);                            SetAttributeStringValue(use, Template_ATTR_types, buffer);
                           TtaRegisterElementCreate(use, doc);                            TtaRegisterElementCreate(use, doc);
                             
                           TtaSelectElement(doc, use);                            TtaSelectElement(doc, use);
   
                           TtaCloseUndoSequence(doc);                            TtaCloseUndoSequence(doc);
                         }                          }
                     }                      }
Line 2370  Element Template_CreateUseFromSelection( Line 2420  Element Template_CreateUseFromSelection(
                     {                      {
                       // Create a xt:use around the selection                        // Create a xt:use around the selection
                       TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);                        TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
                         
                       TtaRegisterElementDelete (selElem, doc);                        TtaRegisterElementDelete (selElem, doc);
                       TtaRemoveTree(selElem, doc);                        TtaRemoveTree(selElem, doc);
   
Line 2381  Element Template_CreateUseFromSelection( Line 2431  Element Template_CreateUseFromSelection(
                         TtaInsertSibling(use, prev, FALSE, doc);                          TtaInsertSibling(use, prev, FALSE, doc);
                       else                        else
                         TtaInsertFirstChild(&use, parent, doc);                          TtaInsertFirstChild(&use, parent, doc);
                         
                       TtaInsertFirstChild(&selElem, use, doc);                        TtaInsertFirstChild(&selElem, use, doc);
                         
                       SetAttributeStringValue(use, Template_ATTR_types, TtaGetElementTypeName(TtaGetElementType(selElem)));                        SetAttributeStringValue(use, Template_ATTR_types, TtaGetElementTypeName(TtaGetElementType(selElem)));
                         
                       TtaRegisterElementCreate(use, doc);                        TtaRegisterElementCreate(use, doc);
                         
                       TtaCloseUndoSequence(doc);                        TtaCloseUndoSequence(doc);
                     }                      }
                 }                  }
             }              }
   /*          else if(selElem==selElem2)
               {
                 printf(">> %d - %d / %d - %d\n", firstChar, lastChar, firstChar2, lastChar2);
               }*/
           else if(lastChar<firstChar)            else if(lastChar<firstChar)
               Template_CreateInlineUse(doc);                use = Template_CreateInlineUse(doc);
             
           TtaSetStructureChecking (oldStructureChecking, doc);            TtaSetStructureChecking (oldStructureChecking, doc);
           TtaSetDisplayMode (doc, dispMode);            TtaSetDisplayMode (doc, dispMode);
             
         }          }
     }      }
   return use;    return use;
Line 2421  Element Template_CreateComponentFromSele Line 2475  Element Template_CreateComponentFromSele
   int         firstChar, lastChar, firstChar2, lastChar2;    int         firstChar, lastChar, firstChar2, lastChar2;
   SSchema     sstempl = TtaGetSSchema ("Template", doc);    SSchema     sstempl = TtaGetSSchema ("Template", doc);
   XTigerTemplate t = GetXTigerDocTemplate(doc);    XTigerTemplate t = GetXTigerDocTemplate(doc);
     
   ElementType compType;    ElementType compType;
   Element     comp = NULL;    Element     comp = NULL;
   char        buffer[128];    char        buffer[128];
Line 2446  Element Template_CreateComponentFromSele Line 2500  Element Template_CreateComponentFromSele
           if(buffer[0]!=EOS)            if(buffer[0]!=EOS)
             {              {
               head = TemplateFindHead(doc);                head = TemplateFindHead(doc);
                 
               compType.ElSSchema = sstempl;                compType.ElSSchema = sstempl;
               compType.ElTypeNum = Template_EL_component;                compType.ElTypeNum = Template_EL_component;
       
               parent  = TtaGetParent(selElem);                parent  = TtaGetParent(selElem);
               parent2 = TtaGetParent(selElem2);                parent2 = TtaGetParent(selElem2);
                 
               if(head && firstChar==0 && firstChar2==0 && parent == parent2)                if(head && firstChar==0 && firstChar2==0 && parent == parent2)
                 {                  {
                   dispMode = TtaGetDisplayMode (doc);                    dispMode = TtaGetDisplayMode (doc);
Line 2460  Element Template_CreateComponentFromSele Line 2514  Element Template_CreateComponentFromSele
                     TtaSetDisplayMode (doc, DeferredDisplay);                      TtaSetDisplayMode (doc, DeferredDisplay);
                   oldStructureChecking = TtaGetStructureChecking (doc);                    oldStructureChecking = TtaGetStructureChecking (doc);
                   TtaSetStructureChecking (FALSE, doc);                    TtaSetStructureChecking (FALSE, doc);
       
                   child = TtaGetLastChild(head);                    child = TtaGetLastChild(head);
                   TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);                    TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
                   comp = TtaNewElement(doc, compType);                    comp = TtaNewElement(doc, compType);
Line 2469  Element Template_CreateComponentFromSele Line 2523  Element Template_CreateComponentFromSele
                   else                    else
                     TtaInsertFirstChild(&comp, head, doc);                      TtaInsertFirstChild(&comp, head, doc);
                   TtaRegisterElementCreate(comp, doc);                    TtaRegisterElementCreate(comp, doc);
                     
                   TtaNextSibling(&selElem2);                    TtaNextSibling(&selElem2);
                   child = NULL;                    child = NULL;
                   while(selElem!=selElem2)                    while(selElem!=selElem2)
                     {                      {
                       current = selElem;                        current = selElem;
                       TtaNextSibling(&selElem);                        TtaNextSibling(&selElem);
                         
                       TtaRegisterElementDelete (current, doc);                        TtaRegisterElementDelete (current, doc);
                       TtaRemoveTree(current, doc);                        TtaRemoveTree(current, doc);
                       if(child)                        if(child)
Line 2488  Element Template_CreateComponentFromSele Line 2542  Element Template_CreateComponentFromSele
                     }                      }
                   if(!Template_SetName(doc, comp, buffer, TRUE))                    if(!Template_SetName(doc, comp, buffer, TRUE))
                       GiveAttributeStringValueFromNum(comp, Template_ATTR_name, buffer, &sz);                        GiveAttributeStringValueFromNum(comp, Template_ATTR_name, buffer, &sz);
                     
                   TtaCloseUndoSequence(doc);                    TtaCloseUndoSequence(doc);
                   TtaSelectElement(doc, comp);                    TtaSelectElement(doc, comp);
                     
                   Template_DeclareNewComponent(t, buffer, comp);                    Template_DeclareNewComponent(t, buffer, comp);
                     
                   TtaSetStructureChecking (oldStructureChecking, doc);                    TtaSetStructureChecking (oldStructureChecking, doc);
                   TtaSetDisplayMode (doc, dispMode);                    TtaSetDisplayMode (doc, dispMode);
                 }                  }
Line 2503  Element Template_CreateComponentFromSele Line 2557  Element Template_CreateComponentFromSele
   return comp;    return comp;
 #else /* TEMPLATES */  #else /* TEMPLATES */
   return NULL;    return NULL;
 #endif /* TEMPLATES */   #endif /* TEMPLATES */
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 2515  ThotBool TemplateComponentWillBeDeleted Line 2569  ThotBool TemplateComponentWillBeDeleted
 #ifdef TEMPLATES  #ifdef TEMPLATES
   XTigerTemplate t = GetXTigerDocTemplate(event->document);    XTigerTemplate t = GetXTigerDocTemplate(event->document);
   char* elemName = GetAttributeStringValueFromNum(event->element, Template_ATTR_name, NULL);    char* elemName = GetAttributeStringValueFromNum(event->element, Template_ATTR_name, NULL);
     
   if(Template_IsUsedComponent(t, event->document, elemName))    if(Template_IsUsedComponent(t, event->document, elemName))
     {      {
       TtaDisplaySimpleMessage (CONFIRM, AMAYA, AM_TEMPLATE_USEDCOMP_CANTREMOVE);        TtaDisplaySimpleMessage (CONFIRM, AMAYA, AM_TEMPLATE_USEDCOMP_CANTREMOVE);
       return TRUE;        return TRUE;
     }      }
 #endif /* TEMPLATES */   #endif /* TEMPLATES */
   return FALSE;    return FALSE;
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   UnionClicked    UnionClicked
   Called when a xt:union is clicked     Called when a xt:union is clicked
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 void UnionClicked(NotifyElement* event)  void UnionClicked(NotifyElement* event)
 {  {
Line 2537  void UnionClicked(NotifyElement* event) Line 2591  void UnionClicked(NotifyElement* event)
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   UnionDoubleClicked    UnionDoubleClicked
   Called when a xt:union is double clicked     Called when a xt:union is double clicked
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 ThotBool UnionDoubleClicked(NotifyElement* event)  ThotBool UnionDoubleClicked(NotifyElement* event)
 {  {
Line 2548  ThotBool UnionDoubleClicked(NotifyElemen Line 2602  ThotBool UnionDoubleClicked(NotifyElemen
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   TemplateNameAttributeDeleted    TemplateNameAttributeDeleted
   Called when a xt:name will be deleted     Called when a xt:name will be deleted
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 ThotBool TemplateNameAttributeDeleted(NotifyAttribute* event)  ThotBool TemplateNameAttributeDeleted(NotifyAttribute* event)
 {  {
Line 2558  ThotBool TemplateNameAttributeDeleted(No Line 2612  ThotBool TemplateNameAttributeDeleted(No
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   TemplateNameAttributeModified    TemplateNameAttributeModified
   Called when a xt:name will be modified     Called when a xt:name will be modified
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 ThotBool TemplateNameAttributeModified(NotifyAttribute* event)  ThotBool TemplateNameAttributeModified(NotifyAttribute* event)
 {  {
Line 2568  ThotBool TemplateNameAttributeModified(N Line 2622  ThotBool TemplateNameAttributeModified(N
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   TemplateNameAttributeCreated    TemplateNameAttributeCreated
   Called when a xt:name have been created     Called when a xt:name have been created
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 void TemplateNameAttributeCreated(NotifyAttribute* event)  void TemplateNameAttributeCreated(NotifyAttribute* event)
 {  {
Line 2584  ThotBool TemplateNameAttrInMenu (NotifyA Line 2638  ThotBool TemplateNameAttrInMenu (NotifyA
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   ElementType type = TtaGetElementType(event->element);    ElementType type = TtaGetElementType(event->element);
   if(type.ElTypeNum==Template_EL_component ||     if(type.ElTypeNum==Template_EL_component ||
       type.ElTypeNum==Template_EL_union)        type.ElTypeNum==Template_EL_union)
     return TRUE;      return TRUE;
 #endif /* TEMPLATES */  #endif /* TEMPLATES */

Removed from v.1.205  
changed lines
  Added in v.1.206


Webmaster