Annotation of Amaya/amaya/templateUtils.c, revision 1.12
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;
1.12 ! vatton 94: Attribute attribute;
! 95: char *aux;
! 96: int size;
! 97:
1.1 francesc 98: attType.AttrSSchema = TtaGetElementType(el).ElSSchema;
99: attType.AttrTypeNum = att;
1.12 ! vatton 100: attribute = TtaGetAttribute(el, attType);
1.1 francesc 101:
1.12 ! vatton 102: size = TtaGetTextAttributeLength(attribute);
! 103: aux = (char*) TtaGetMemory(size+1);
1.1 francesc 104: TtaGiveTextAttributeValue (attribute, aux, &size);
1.12 ! vatton 105: aux[size] = EOS;
1.4 kia 106: if(sz)
107: *sz = size;
1.1 francesc 108: return aux;
109: #else
1.8 kia 110: return NULL;
1.1 francesc 111: #endif /* TEMPLATES */
112: }
1.2 francesc 113:
114: /*----------------------------------------------------------------------
115: Returns the value of a string attribute
116: ----------------------------------------------------------------------*/
1.4 kia 117: char *GetAttributeStringValue (Element el, Attribute attribute, int* sz)
1.2 francesc 118: {
119: #ifdef TEMPLATES
120: int size = TtaGetTextAttributeLength(attribute);
121: char *aux = (char*) TtaGetMemory(size+1);
1.12 ! vatton 122:
1.2 francesc 123: TtaGiveTextAttributeValue (attribute, aux, &size);
1.12 ! vatton 124: aux[size] = EOS;
1.4 kia 125: if(sz)
126: *sz = size;
1.2 francesc 127: return aux;
128: #else
1.8 kia 129: return NULL;
1.2 francesc 130: #endif /* TEMPLATES */
131: }
1.6 kia 132:
133:
134: /*----------------------------------------------------------------------
135: GetFirstEditableElement
136: Returns the first descendant element which is modifiable.
137: ----------------------------------------------------------------------*/
138: Element GetFirstEditableElement (Element el)
139: {
140: Element res = NULL;
141: Element current = TtaGetFirstChild(el);
142:
143: while(!res && current)
144: {
145: res = GetFirstEditableElement(current);
146: TtaNextSibling(¤t);
147: }
148:
149: if(!res && !TtaIsReadOnly(el))
150: res = el;
151:
152: return res;
153: }
Webmaster