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

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

Webmaster