/*---------------------------------------------------------------------- get_char_attribute_from_el: Get a string value from an xml attribute, but stored as an allocated ptr ----------------------------------------------------------------------*/ char *get_char_attribute_from_el (Element el, int Attribut_Type) { #ifdef _SVG int length; char *text = NULL, *ptr; AttributeType attrType; Attribute attr = NULL; ElementType elType = TtaGetElementType (el); attrType.AttrSSchema = elType.ElSSchema; attrType.AttrTypeNum = Attribut_Type; attr = TtaGetAttribute (el, attrType); length = TtaGetTextAttributeLength (attr); if (length == 0) return NULL; text = (char *)TtaGetMemory (length+1); if (text) { /* get the value of the x attribute */ TtaGiveTextAttributeValue (attr, text, &length); /* Parse the attribute value (a number followed by a unit) */ ptr = text; /*TtaFreeMemory (text);*/ } return text; #endif /* _SVG */ }
/*---------------------------------------------------------------------- AttrToSpan If attribute attr is on a text string (elem), create a SPAN element enclosing this text string and move the attribute to that SPAN element. ----------------------------------------------------------------------*/ void AttrToSpan (Element elem, Attribute attr, Document doc) { Element span, parent; Attribute newAttr; AttributeType attrType; ElementType elType; int kind, len, val; char *oldValue; /* [ATTRLEN]; */ elType = TtaGetElementType (elem); if (elType.ElTypeNum == HTML_EL_TEXT_UNIT || elType.ElTypeNum == HTML_EL_Basic_Elem) /* it's a character string */ { parent = TtaGetParent (elem); elType = TtaGetElementType (parent); if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0) /* the parent element is an HTML element */ /* Create a Span element and move the attribute to this Span element */ MakeASpan (elem, &span, doc, NULL); else /* move the attribute to the parent element */ span = parent; if (span != NULL) { TtaGiveAttributeType (attr, &attrType, &kind); newAttr = TtaGetAttribute (span, attrType); if (newAttr == NULL) { newAttr = TtaNewAttribute (attrType); TtaAttachAttribute (span, newAttr, doc); } if (kind == 2) /* it's a text attribute */ { len = TtaGetTextAttributeLength (attr); oldValue = (char *)TtaGetMemory (len + 1); TtaGiveTextAttributeValue (attr, oldValue, &len); TtaSetAttributeText (newAttr, oldValue, span, doc); TtaFreeMemory (oldValue); } else if (kind == 0 || kind == 1) /* enumerate or integer attribute */ { val = TtaGetAttributeValue (attr); TtaSetAttributeValue (newAttr, val, span, doc); } TtaRegisterAttributeCreate (newAttr, span, doc); TtaRegisterAttributeDelete (attr, elem, doc); TtaRemoveAttribute (elem, attr, doc); TtaSelectElement (doc, elem); TtaSetStatusSelectedElement(doc, 1, elem); } } }
/*---------------------------------------------------------------------- Returns the value of a string attribute ----------------------------------------------------------------------*/ char *GetAttributeStringValue (Element el, Attribute attribute, int* sz) { #ifdef TEMPLATES int size = TtaGetTextAttributeLength(attribute); char *aux = (char*) TtaGetMemory(size+1); TtaGiveTextAttributeValue (attribute, aux, &size); aux[size] = EOS; if (sz) *sz = size; return aux; #else return NULL; #endif /* TEMPLATES */ }
/*---------------------------------------------------------------------- Returns the value of a string attribute without copy it ----------------------------------------------------------------------*/ void GiveAttributeStringValueFromNum (Element el, int att, char* buff, int* sz) { #ifdef TEMPLATES AttributeType attType; Attribute attribute; int size; attType.AttrSSchema = TtaGetElementType(el).ElSSchema; attType.AttrTypeNum = att; attribute = TtaGetAttribute(el, attType); size = TtaGetTextAttributeLength(attribute); TtaGiveTextAttributeValue (attribute, buff, &size); buff[size] = EOS; if (sz) *sz = size; #endif /* TEMPLATES */ }
/*----------------------------------------------------------------------- BM_topicGetModelHref returns the URL of the model corresponding to the parent topic -----------------------------------------------------------------------*/ char * BM_topicGetModelHref (Element topic_item) { ElementType elType; Attribute attr; AttributeType attrType; char *buffer = NULL; int length; if (!topic_item) return NULL; elType = TtaGetElementType (topic_item); attrType.AttrSSchema = elType.ElSSchema; attrType.AttrTypeNum = Topics_ATTR_Model_HREF_; attr = TtaGetAttribute (topic_item, attrType); if (attr) { length = TtaGetTextAttributeLength (attr) + 1; buffer = (char *)TtaGetMemory (length); TtaGiveTextAttributeValue (attr, buffer, &length); } return buffer; }
/*---------------------------------------------------------------------- Returns the value of a string attribute or NULL ----------------------------------------------------------------------*/ char *GetAttributeStringValueFromNum (Element el, int att, int* sz) { #ifdef TEMPLATES AttributeType attType; Attribute attribute; char *aux; int size; attType.AttrSSchema = TtaGetElementType(el).ElSSchema; attType.AttrTypeNum = att; attribute = TtaGetAttribute(el, attType); if (attribute == NULL) return NULL; size = TtaGetTextAttributeLength (attribute); aux = (char*) TtaGetMemory (size+1); TtaGiveTextAttributeValue (attribute, aux, &size); aux[size] = EOS; if (sz) *sz = size; return aux; #else return NULL; #endif /* TEMPLATES */ }
/*----------------------------------------------------------------------- BM_AddItem -----------------------------------------------------------------------*/ Element BM_AddItem (Document doc, BookmarkP me) { ElementType elType; Element root, el, rootOfThread; Element item = NULL; Attribute attr; AttributeType attrType; char *url; int i; /* point to the first node */ root = TtaGetRootElement (doc); elType = TtaGetElementType (root); /* point to the home topic */ rootOfThread = TtaGetFirstChild (root); if (!rootOfThread) el = NULL; /* it's the first one in the thread */ else { /* try to find where to insert the element */ attrType.AttrSSchema = elType.ElSSchema; attrType.AttrTypeNum = Topics_ATTR_Model_HREF_; /* for the moment, we suppose that bookmarks always belong to a topic and that this topic is described in the bookmark file */ if (me->parent_url) { root = rootOfThread; TtaSearchAttribute (attrType, SearchForward, root, &el, &attr); while (el) { i = TtaGetTextAttributeLength (attr) + 1; url = (char *)TtaGetMemory (i); TtaGiveTextAttributeValue (attr, url, &i); if (!strcasecmp (url, me->parent_url)) { TtaFreeMemory (url); break; } TtaFreeMemory (url); root = el; TtaSearchAttribute (attrType, SearchForward, root, &el, &attr); } } else el = NULL; if (el == NULL) /* we didn't find the Topic where to store it, so we insert it as a child of the home topic */ el = rootOfThread; } if (me->bm_type == BME_SEEALSO) { /* find the topic content */ el = BM_topicGetCreateContent (doc, el); if (el) { /* find the element to which we must attach the seeAlso */ attrType.AttrTypeNum = Topics_ATTR_Model_HREF_; el = TtaGetFirstChild (el); while (el) { attr = TtaGetAttribute (el, attrType); if (attr) { i = TtaGetTextAttributeLength (attr) + 1; url = (char *)TtaGetMemory (i); TtaGiveTextAttributeValue (attr, url, &i); if (!strcasecmp (url, me->self_url)) { TtaFreeMemory (url); break; } TtaFreeMemory (url); } TtaNextSibling (&el); } } } if (me->bm_type == BME_TOPIC) item = BM_topicAdd (doc, el, me->collapsed); else if (me->bm_type == BME_BOOKMARK) item = BM_bookmarkAdd (doc, el); else if (me->bm_type == BME_SEEALSO) item = BM_seeAlsoAdd (doc, el); else if (me->bm_type == BME_SEPARATOR) item = BM_separatorAdd (doc, el); /* init the thread item elements */ if (item) BM_InitItem (doc, item, me); return (item); }
/*---------------------------------------------------------------------- GetStyleContents returns a buffer that contains the whole text of the style element el. It returns NULL if the element is empty. The buffer should be freed by the caller. ----------------------------------------------------------------------*/ char *GetStyleContents (Element el) { ElementType elType; Element text; Attribute attr; AttributeType attrType; CSSmedia media = CSS_ALL; Language lang; char *buffer, *name; int length, i, j; ThotBool loadcss; buffer = NULL; /* check if we have to load CSS */ TtaGetEnvBoolean ("LOAD_CSS", &loadcss); if (loadcss && el) { /* check the media type of the element */ elType = TtaGetElementType (el); attrType.AttrSSchema = elType.ElSSchema; name = TtaGetSSchemaName (attrType.AttrSSchema); if (!strcmp (name, "HTML")) attrType.AttrTypeNum = HTML_ATTR_media; #ifdef _SVG else if (!strcmp (name, "HTML")) attrType.AttrTypeNum = SVG_ATTR_media; #endif /* _SVG */ else attrType.AttrTypeNum = 0; if (attrType.AttrTypeNum) { attr = TtaGetAttribute (el, attrType); if (attr) { length = TtaGetTextAttributeLength (attr); name = (char *)TtaGetMemory (length + 1); TtaGiveTextAttributeValue (attr, name, &length); media = CheckMediaCSS (name); TtaFreeMemory (name); } } /* get enough space to store UTF-8 characters */ length = TtaGetElementVolume (el) * 6 + 1; if ((media == CSS_ALL || media == CSS_SCREEN) && length > 1) { /* get the length of the included text */ buffer = (char *)TtaGetMemory (length); /* fill the buffer */ elType.ElTypeNum = 1 /* 1 = TEXT_UNIT element */; text = TtaSearchTypedElementInTree (elType, SearchForward, el, el); i = 0; while (text != NULL) { j = length - i; TtaGiveTextContent (text, (unsigned char *)&buffer[i], &j, &lang); i += TtaGetTextLength (text); text = TtaSearchTypedElementInTree (elType, SearchForward, el, text); } buffer[i] = EOS; } } return (buffer); }
/*---------------------------------------------------------------------- AttrMediaChanged: the user has created removed or modified a Media attribute ----------------------------------------------------------------------*/ void AttrMediaChanged (NotifyAttribute *event) { ElementType elType; Element el; Document doc; Attribute attr; AttributeType attrType; CSSInfoPtr css; CSSmedia media; PInfoPtr pInfo; DisplayMode dispMode; char completeURL[MAX_LENGTH]; char tempname[MAX_LENGTH]; char *name2; int length; el = event->element; doc = event->document; attr = event->attribute; elType = TtaGetElementType (el); /* get the new media value */ length = TtaGetTextAttributeLength (attr); name2 = (char *)TtaGetMemory (length + 1); TtaGiveTextAttributeValue (attr, name2, &length); media = CheckMediaCSS (name2); TtaFreeMemory (name2); /* get the CSS URI */ attrType.AttrSSchema = elType.ElSSchema; attrType.AttrTypeNum = HTML_ATTR_HREF_; attr = TtaGetAttribute (el, attrType); if (attr && /* don't manage a document used by make book */ (DocumentMeta[doc] == NULL || DocumentMeta[doc]->method != CE_MAKEBOOK)) { length = TtaGetTextAttributeLength (attr); name2 = (char *)TtaGetMemory (length + 1); TtaGiveTextAttributeValue (attr, name2, &length); /* load the stylesheet file found here ! */ NormalizeURL (name2, doc, completeURL, tempname, NULL); TtaFreeMemory (name2); /* get the right CSS context */ css = SearchCSS (doc, completeURL, el, &pInfo); } else /* get the right CSS context */ css = SearchCSS (doc, NULL, el, &pInfo); if (css && pInfo) { /* avoid too many redisplay */ dispMode = TtaGetDisplayMode (doc); /* something changed and we are not printing */ if (media == CSS_ALL || media == CSS_SCREEN) { if (dispMode != NoComputedDisplay) TtaSetDisplayMode (doc, NoComputedDisplay); LoadStyleSheet (completeURL, doc, el, NULL, NULL, media, pInfo->PiCategory == CSS_USER_STYLE); /* restore the display mode */ if (dispMode != NoComputedDisplay) TtaSetDisplayMode (doc, dispMode); } else { if (media == CSS_PRINT || media == CSS_OTHER) { if (dispMode != NoComputedDisplay) TtaSetDisplayMode (doc, NoComputedDisplay); UnlinkCSS (css, doc, el, TRUE, FALSE, TRUE); /* restore the display mode */ if (dispMode != NoComputedDisplay) TtaSetDisplayMode (doc, dispMode); } /* only update the CSS media info */ pInfo->PiMedia = media; } } }