Annotation of Amaya/amaya/templateUtils.c, revision 1.6
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
35: Document doc = TtaGetDocument(el);
36:
37: AttributeType attType;
38: attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
39: attType.AttrTypeNum = att;
40:
41: Attribute attribute = TtaGetAttribute(el, attType);
42:
43: TtaSetAttributeText(attribute, value, el, doc);
44: #endif /* TEMPLATES */
45: }
46:
1.1 francesc 47:
48: /*----------------------------------------------------------------------
49: Returns the value of a string attribute
50: ----------------------------------------------------------------------*/
1.4 kia 51: char *GetAttributeStringValue (Element el, int att, int* sz)
1.1 francesc 52: {
53: #ifdef TEMPLATES
54: AttributeType attType;
55: attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
56: attType.AttrTypeNum = att;
57:
58: Attribute attribute = TtaGetAttribute(el, attType);
59:
60: int size = TtaGetTextAttributeLength(attribute);
61: char *aux = (char*) TtaGetMemory(size+1);
62: TtaGiveTextAttributeValue (attribute, aux, &size);
1.4 kia 63: if(sz)
64: *sz = size;
1.1 francesc 65: return aux;
66: #else
67: return '\0';
68: #endif /* TEMPLATES */
69: }
1.2 francesc 70:
71: /*----------------------------------------------------------------------
72: Returns the value of a string attribute
73: ----------------------------------------------------------------------*/
1.4 kia 74: char *GetAttributeStringValue (Element el, Attribute attribute, int* sz)
1.2 francesc 75: {
76: #ifdef TEMPLATES
77: int size = TtaGetTextAttributeLength(attribute);
78: char *aux = (char*) TtaGetMemory(size+1);
79: TtaGiveTextAttributeValue (attribute, aux, &size);
1.4 kia 80: if(sz)
81: *sz = size;
1.2 francesc 82: return aux;
83: #else
84: return '\0';
85: #endif /* TEMPLATES */
86: }
1.6 ! kia 87:
! 88:
! 89: /*----------------------------------------------------------------------
! 90: GetFirstEditableElement
! 91: Returns the first descendant element which is modifiable.
! 92: ----------------------------------------------------------------------*/
! 93: Element GetFirstEditableElement (Element el)
! 94: {
! 95: Element res = NULL;
! 96: Element current = TtaGetFirstChild(el);
! 97:
! 98: while(!res && current)
! 99: {
! 100: res = GetFirstEditableElement(current);
! 101: TtaNextSibling(¤t);
! 102: }
! 103:
! 104: if(!res && !TtaIsReadOnly(el))
! 105: res = el;
! 106:
! 107: return res;
! 108: }
Webmaster