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

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.11    ! kia        60: /*----------------------------------------------------------------------
        !            61: Set the value of a string attribute and registering it in undo sequence.
        !            62: ----------------------------------------------------------------------*/
        !            63: void SetAttributeStringValueWithUndo (Element el, int att, char* value)
        !            64: {
        !            65: #ifdef TEMPLATES
        !            66:   Document      doc = TtaGetDocument(el);
        !            67:   AttributeType attType;
        !            68:   Attribute     attribute;
        !            69: 
        !            70:   if (doc == 0 || !TtaGetDocumentAccessMode(doc))
        !            71:     return;
        !            72:   attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
        !            73:   attType.AttrTypeNum = att;
        !            74:   attribute = TtaGetAttribute(el, attType);
        !            75:   if (attribute == NULL)
        !            76:     {
        !            77:       attribute = TtaNewAttribute (attType);
        !            78:       TtaAttachAttribute(el, attribute, doc);
        !            79:       TtaRegisterAttributeCreate(attribute, el, doc);
        !            80:     }
        !            81:   TtaSetAttributeText(attribute, value, el, doc);
        !            82:   TtaRegisterAttributeReplace(attribute, el, doc);
        !            83: #endif /* TEMPLATES */
        !            84: }
        !            85: 
1.1       francesc   86: 
                     87: /*----------------------------------------------------------------------
                     88: Returns the value of a string attribute 
                     89: ----------------------------------------------------------------------*/
1.8       kia        90: char *GetAttributeStringValueFromNum (Element el, int att, int* sz)
1.1       francesc   91: {
                     92: #ifdef TEMPLATES
                     93:        AttributeType attType;
                     94:        attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
                     95:        attType.AttrTypeNum = att;
                     96:        
                     97:        Attribute attribute = TtaGetAttribute(el, attType);
                     98:        
                     99:        int size = TtaGetTextAttributeLength(attribute);
                    100:        char *aux = (char*) TtaGetMemory(size+1);
                    101:        TtaGiveTextAttributeValue (attribute, aux, &size);
1.4       kia       102:   if(sz)
                    103:     *sz = size;
1.1       francesc  104:        return aux;
                    105: #else
1.8       kia       106:        return NULL;
1.1       francesc  107: #endif /* TEMPLATES */
                    108: }
1.2       francesc  109: 
                    110: /*----------------------------------------------------------------------
                    111: Returns the value of a string attribute 
                    112: ----------------------------------------------------------------------*/
1.4       kia       113: char *GetAttributeStringValue (Element el, Attribute attribute, int* sz)
1.2       francesc  114: {
                    115: #ifdef TEMPLATES
                    116:        int size = TtaGetTextAttributeLength(attribute);
                    117:        char *aux = (char*) TtaGetMemory(size+1);
                    118:        TtaGiveTextAttributeValue (attribute, aux, &size);
1.4       kia       119:   if(sz)
                    120:     *sz = size;
1.2       francesc  121:        return aux;
                    122: #else
1.8       kia       123:        return NULL;
1.2       francesc  124: #endif /* TEMPLATES */
                    125: }
1.6       kia       126: 
                    127: 
                    128: /*----------------------------------------------------------------------
                    129: GetFirstEditableElement
                    130: Returns the first descendant element which is modifiable.
                    131: ----------------------------------------------------------------------*/
                    132: Element GetFirstEditableElement (Element el)
                    133: {
                    134:   Element res = NULL;
                    135:   Element current = TtaGetFirstChild(el);
                    136:   
                    137:   while(!res && current)
                    138:   {
                    139:     res = GetFirstEditableElement(current);
                    140:     TtaNextSibling(&current);
                    141:   }
                    142:   
                    143:   if(!res && !TtaIsReadOnly(el))
                    144:     res = el;
                    145:   
                    146:   return res;
                    147: }

Webmaster