Return to templateUtils.c CVS log | Up to [Public] / Amaya / amaya |
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.13 ! kia 86: /*---------------------------------------------------------------------- ! 87: Returns the value of a string attribute without copy it ! 88: ----------------------------------------------------------------------*/ ! 89: void GiveAttributeStringValueFromNum (Element el, int att, char* buff, int* sz) ! 90: { ! 91: #ifdef TEMPLATES ! 92: AttributeType attType; ! 93: Attribute attribute; ! 94: int size; ! 95: ! 96: attType.AttrSSchema = TtaGetElementType(el).ElSSchema; ! 97: attType.AttrTypeNum = att; ! 98: attribute = TtaGetAttribute(el, attType); ! 99: ! 100: size = TtaGetTextAttributeLength(attribute); ! 101: TtaGiveTextAttributeValue (attribute, buff, &size); ! 102: buff[size] = EOS; ! 103: if(sz) ! 104: *sz = size; ! 105: #endif /* TEMPLATES */ ! 106: } ! 107: ! 108: 1.1 francesc 109: 110: /*---------------------------------------------------------------------- 111: Returns the value of a string attribute 112: ----------------------------------------------------------------------*/ 1.8 kia 113: char *GetAttributeStringValueFromNum (Element el, int att, int* sz) 1.1 francesc 114: { 115: #ifdef TEMPLATES 116: AttributeType attType; 1.12 vatton 117: Attribute attribute; 118: char *aux; 119: int size; 120: 1.1 francesc 121: attType.AttrSSchema = TtaGetElementType(el).ElSSchema; 122: attType.AttrTypeNum = att; 1.12 vatton 123: attribute = TtaGetAttribute(el, attType); 1.1 francesc 124: 1.12 vatton 125: size = TtaGetTextAttributeLength(attribute); 126: aux = (char*) TtaGetMemory(size+1); 1.1 francesc 127: TtaGiveTextAttributeValue (attribute, aux, &size); 1.12 vatton 128: aux[size] = EOS; 1.4 kia 129: if(sz) 130: *sz = size; 1.1 francesc 131: return aux; 132: #else 1.8 kia 133: return NULL; 1.1 francesc 134: #endif /* TEMPLATES */ 135: } 1.2 francesc 136: 137: /*---------------------------------------------------------------------- 138: Returns the value of a string attribute 139: ----------------------------------------------------------------------*/ 1.4 kia 140: char *GetAttributeStringValue (Element el, Attribute attribute, int* sz) 1.2 francesc 141: { 142: #ifdef TEMPLATES 143: int size = TtaGetTextAttributeLength(attribute); 144: char *aux = (char*) TtaGetMemory(size+1); 1.12 vatton 145: 1.2 francesc 146: TtaGiveTextAttributeValue (attribute, aux, &size); 1.12 vatton 147: aux[size] = EOS; 1.4 kia 148: if(sz) 149: *sz = size; 1.2 francesc 150: return aux; 151: #else 1.8 kia 152: return NULL; 1.2 francesc 153: #endif /* TEMPLATES */ 154: } 1.6 kia 155: 156: 157: /*---------------------------------------------------------------------- 158: GetFirstEditableElement 159: Returns the first descendant element which is modifiable. 160: ----------------------------------------------------------------------*/ 161: Element GetFirstEditableElement (Element el) 162: { 163: Element res = NULL; 164: Element current = TtaGetFirstChild(el); 165: 166: while(!res && current) 167: { 168: res = GetFirstEditableElement(current); 169: TtaNextSibling(¤t); 170: } 171: 172: if(!res && !TtaIsReadOnly(el)) 173: res = el; 174: 175: return res; 176: }