Annotation of Amaya/amaya/templateUtils.c, revision 1.8

1.3       quint       1: #include "templates.h"
1.1       francesc    2: 
                      3: /*----------------------------------------------------------------------
                      4: GetSchemaFromDocType: Returns the name of the schema corresponding to 
                      5: a doc type.
                      6: ----------------------------------------------------------------------*/
                      7: char *GetSchemaFromDocType (DocumentType docType)
                      8: {
                      9: #ifdef TEMPLATES
                     10:        switch (docType)
                     11:     {
                     12:     case docAnnot :
                     13:                return "Annot";
                     14:     case docBookmark :
                     15:                return "Topics";
                     16:     case docSVG :
                     17:                return "SVG";
                     18:     case docMath :
                     19:                return "MathML";
                     20:     case docXml :
                     21:                return "XML";
                     22:     default :
                     23:                return "HTML";
                     24:     }
                     25: #endif // TEMPLATES
                     26:        return "HTML";
                     27: }
                     28: 
1.5       kia        29: /*----------------------------------------------------------------------
                     30: Set the value of a string attribute 
                     31: ----------------------------------------------------------------------*/
                     32: void SetAttributeStringValue (Element el, int att, char* value)
                     33: {
                     34: #ifdef TEMPLATES
1.7       vatton     35:   Document      doc = TtaGetDocument(el);
                     36:   AttributeType attType;
                     37:   Attribute     attribute;
1.5       kia        38: 
                     39:   attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
                     40:   attType.AttrTypeNum = att;
1.7       vatton     41:   attribute = TtaGetAttribute(el, attType);
                     42:   if (attribute == NULL)
                     43:     {
                     44:       attribute = TtaNewAttribute (attType);
                     45:       TtaAttachAttribute(el, attribute, doc);
                     46:     }
1.5       kia        47:   TtaSetAttributeText(attribute, value, el, doc);
                     48: #endif /* TEMPLATES */
                     49: }
                     50: 
1.1       francesc   51: 
                     52: /*----------------------------------------------------------------------
                     53: Returns the value of a string attribute 
                     54: ----------------------------------------------------------------------*/
1.8     ! kia        55: char *GetAttributeStringValueFromNum (Element el, int att, int* sz)
1.1       francesc   56: {
                     57: #ifdef TEMPLATES
                     58:        AttributeType attType;
                     59:        attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
                     60:        attType.AttrTypeNum = att;
                     61:        
                     62:        Attribute attribute = TtaGetAttribute(el, attType);
                     63:        
                     64:        int size = TtaGetTextAttributeLength(attribute);
                     65:        char *aux = (char*) TtaGetMemory(size+1);
                     66:        TtaGiveTextAttributeValue (attribute, aux, &size);
1.4       kia        67:   if(sz)
                     68:     *sz = size;
1.1       francesc   69:        return aux;
                     70: #else
1.8     ! kia        71:        return NULL;
1.1       francesc   72: #endif /* TEMPLATES */
                     73: }
1.2       francesc   74: 
                     75: /*----------------------------------------------------------------------
                     76: Returns the value of a string attribute 
                     77: ----------------------------------------------------------------------*/
1.4       kia        78: char *GetAttributeStringValue (Element el, Attribute attribute, int* sz)
1.2       francesc   79: {
                     80: #ifdef TEMPLATES
                     81:        int size = TtaGetTextAttributeLength(attribute);
                     82:        char *aux = (char*) TtaGetMemory(size+1);
                     83:        TtaGiveTextAttributeValue (attribute, aux, &size);
1.4       kia        84:   if(sz)
                     85:     *sz = size;
1.2       francesc   86:        return aux;
                     87: #else
1.8     ! kia        88:        return NULL;
1.2       francesc   89: #endif /* TEMPLATES */
                     90: }
1.6       kia        91: 
                     92: 
                     93: /*----------------------------------------------------------------------
                     94: GetFirstEditableElement
                     95: Returns the first descendant element which is modifiable.
                     96: ----------------------------------------------------------------------*/
                     97: Element GetFirstEditableElement (Element el)
                     98: {
                     99:   Element res = NULL;
                    100:   Element current = TtaGetFirstChild(el);
                    101:   
                    102:   while(!res && current)
                    103:   {
                    104:     res = GetFirstEditableElement(current);
                    105:     TtaNextSibling(&current);
                    106:   }
                    107:   
                    108:   if(!res && !TtaIsReadOnly(el))
                    109:     res = el;
                    110:   
                    111:   return res;
                    112: }

Webmaster