Esempio n. 1
0
/*----------------------------------------------------------------------
  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 */
}
Esempio n. 2
0
/*----------------------------------------------------------------------
  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);
        }
    }
}
Esempio n. 3
0
/*----------------------------------------------------------------------
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 */
}
Esempio n. 4
0
/*----------------------------------------------------------------------
  AttrLangCreated
  A Lang attribute has been created
  -----------------------------------------------------------------------*/
void AttrLangCreated (NotifyAttribute *event)
{
  Element	elem;
  ElementType   elType;
  int		len;
  AttributeType attrType;
  Attribute	attr;
#define ATTRLEN 64
  char	       *value = (char *)TtaGetMemory (ATTRLEN); 

  elem = event->element;
  elType = TtaGetElementType (elem);
  attrType.AttrTypeNum = 0;
  len = ATTRLEN - 1;
  TtaGiveTextAttributeValue (event->attribute, value, &len);
  if (strcasecmp(value, "Symbol") == 0)
    /* it's a character string in the Symbol character set, it's not really
       a language */
    TtaRemoveAttribute (elem, event->attribute, event->document);      
  else
    /* if the LANG attribute is on a text string in a HTML document, create
       a SPAN element that encloses this text string and move the LANG
       attribute to that SPAN element */
    {
      if (event->info == 0 &&
          strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0)
        AttrToSpan (elem, event->attribute, event->document);
    }
  /* if it's the root (HTML, SVG, MathML) element, create a RealLang
     attribute too */
  if (elem == TtaGetRootElement (event->document))
    /* it's the root element */
    {
      if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0)
        attrType.AttrTypeNum = HTML_ATTR_RealLang;
      else if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "SVG") == 0)
        attrType.AttrTypeNum = SVG_ATTR_RealLang;
      else if (strcmp(TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
        attrType.AttrTypeNum = MathML_ATTR_RealLang;
      attrType.AttrSSchema = event->attributeType.AttrSSchema;
      attr = TtaNewAttribute (attrType);
      TtaAttachAttribute (elem, attr, event->document);
      TtaSetAttributeValue (attr, HTML_ATTR_RealLang_VAL_Yes_, elem,
                            event->document);
    }
  TtaFreeMemory (value);
}
Esempio n. 5
0
/*----------------------------------------------------------------------
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 */
}
Esempio n. 6
0
/*-----------------------------------------------------------------------
  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;
}
Esempio n. 7
0
/*----------------------------------------------------------------------
  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 */
}
Esempio n. 8
0
/*-----------------------------------------------------------------------
  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);
}
Esempio n. 9
0
/*----------------------------------------------------------------------
  CheckTemplateAttrInMenu
  Validate the status of an attribute according to xt::atribute rules.
	Return TRUE if the attribute is not valid
  ----------------------------------------------------------------------*/
ThotBool CheckTemplateAttrInMenu (NotifyAttribute *event)
{
#ifdef TEMPLATES
  Document      doc = event->document;
  Element       elem, parent = event->element;
  ElementType   elType;
  SSchema       schema;
  AttributeType attrType;
  Attribute     attr;
  char         *attrName;
  char          buffer[MAX_LENGTH];
  int           sz, useAt, type;

  /* Prevent from showing attributes for template instance but not templates. */
  if (IsTemplateInstanceDocument(doc))
    {
      schema = TtaGetSSchema ("Template", doc);
      /* Prevent if attribute's element is not a descendant of xt:use */
      /* Dont prevent if descendant of xt:bag. */
      elem = GetFirstTemplateParentElement (parent);
      if (elem)
        {
          elType = TtaGetElementType (elem);
          if (elType.ElTypeNum == Template_EL_bag)
            return FALSE;	/* let Thot perform normal operation */
          if (elType.ElTypeNum != Template_EL_useSimple)
            return TRUE;
          if (!TtaIsReadOnly (parent))
            return FALSE;	/* let Thot perform normal operation */
        }
      /* Search for the corresponding xt:attribute element*/
      attrName = TtaGetAttributeName (event->attributeType);
      attrType.AttrSSchema = schema;
      for (elem = TtaGetFirstChild (parent); elem; TtaNextSibling (&elem))
        {
          attrType.AttrTypeNum = Template_ATTR_ref_name;
          elType = TtaGetElementType(elem);
          if (elType.ElTypeNum == Template_EL_attribute && elType.ElSSchema == schema)
            {
               attr = TtaGetAttribute(elem, attrType);
               if (attr)
                 {
                   sz = MAX_LENGTH;
                   TtaGiveTextAttributeValue(attr, buffer, &sz);
                   if (!strcmp(buffer, attrName))
                     {
                       /* Process the attribute filtering */
                       /* Get 'useAt' attr value. */
                       attrType.AttrTypeNum = Template_ATTR_useAt;
                       attr = TtaGetAttribute(elem, attrType);
                       if (attr)
                         useAt = TtaGetAttributeValue(attr);
                       else
                         useAt = Template_ATTR_useAt_VAL_required;
                       /* Get 'type' attr value. */
                       attrType.AttrTypeNum = Template_ATTR_type;
                       attr = TtaGetAttribute(elem, attrType);
                       if (attr)
                         type = TtaGetAttributeValue(attr);
                       else
                         type = Template_ATTR_type_VAL_string;

                       event->restr.RestrType = (RestrictionContentType)type;
                       /* If attr is prohibited, dont show it.*/
                       if (useAt == Template_ATTR_useAt_VAL_prohibited)
                           return TRUE;
                       if (useAt == Template_ATTR_useAt_VAL_required)
                         /* Force the usage of this attribute.*/
                         event->restr.RestrFlags |= attr_mandatory;

                       /* Get 'fixed' attr value. */
                       attrType.AttrTypeNum = Template_ATTR_fixed;
                       attr = TtaGetAttribute(elem, attrType);
                       if (attr)
                         {
                           sz = MAX_LENGTH;
                           TtaGiveTextAttributeValue(attr, buffer, &sz);
                           event->restr.RestrFlags |= attr_readonly;
                           event->restr.RestrDefVal = TtaStrdup(buffer);
                           return FALSE;	/* let Thot perform normal operation */
                         }

                       /* Get 'default' attr value.*/
                       attrType.AttrTypeNum = Template_ATTR_defaultAt;
                       attr = TtaGetAttribute(elem, attrType);
                       if (attr)
                         {
                           sz = MAX_LENGTH;
                           TtaGiveTextAttributeValue(attr, buffer, &sz);
                           event->restr.RestrDefVal = TtaStrdup(buffer);
                         }

                       /* Get 'values' attr value.*/
                       attrType.AttrTypeNum = Template_ATTR_values;
                       attr = TtaGetAttribute(elem, attrType);
                       if (attr)
                         {
                           sz = MAX_LENGTH;
                           TtaGiveTextAttributeValue(attr, buffer, &sz);
                           event->restr.RestrEnumVal = TtaStrdup(buffer);
                           event->restr.RestrFlags |= attr_enum;
                         }
                       return FALSE;	/* let Thot perform normal operation */
                     }
                 }
            }
        }
      return TRUE;
    }
#endif /* TEMPLATES */
  return FALSE;
}
Esempio n. 10
0
/*----------------------------------------------------------------------
  SetupListValue
  init the attribut list
  ----------------------------------------------------------------------*/
void AmayaAttributeToolPanel::SetupListValue(DLList attrList)
{
  ForwardIterator iter;
  DLListNode      node;
  PtrAttrListElem elem;
  TtAttribute    *pAttr;
  long            index;
  char            buffer[MAX_TXT_LEN];
  int             size;
  AttributeType   type;

  m_pAttrList->DeleteAllItems();
  m_pNewAttrChoice->Clear();
  
  m_pVPanelSizer->Hide((size_t)0);
  
  if (m_attrList)
    DLList_Destroy(m_attrList);
  m_attrList = attrList;
  if (attrList)
    {
      iter = DLList_GetForwardIterator(attrList);
      ITERATOR_FOREACH(iter, DLListNode, node)
      {
        elem = (PtrAttrListElem)node->elem;
        if (elem)
          {
            if (elem->val)
              {
                index = m_pAttrList->InsertItem(m_pAttrList->GetItemCount(),
                            TtaConvMessageToWX(AttrListElem_GetName(elem)));
                switch(AttrListElem_GetType(elem))
                {
                  case AtNumAttr:
                    m_pAttrList->SetItem(index, 1, 
                        wxString::Format(wxT("%d"),
                            TtaGetAttributeValue((Attribute)elem->val)));
                    break;
                  case AtTextAttr:
                    size = MAX_TXT_LEN;
                    TtaGiveTextAttributeValue((Attribute)elem->val, buffer, &size);
                    m_pAttrList->SetItem(index, 1, TtaConvMessageToWX(buffer));
                    break;
                  case AtEnumAttr:
                    type.AttrSSchema = (int*) elem->pSS;
                    type.AttrTypeNum = elem->num;
                    pAttr = AttrListElem_GetTtAttribute(elem);
                    if (pAttr->AttrNEnumValues == 1 &&
                        !strcasecmp (pAttr->AttrEnumValue[0], "yes"))
                      // this is a boolean value
                      m_pAttrList->SetItem(index, 1, TtaConvMessageToWX(pAttr->AttrName));
                     else
                     m_pAttrList->SetItem(index, 1, TtaConvMessageToWX(
                            TtaGetAttributeValueName(type, 
                                TtaGetAttributeValue((Attribute)elem->val))));
                    break;
                  case AtReferenceAttr:
                  default:
                    break;
                }
                if (AttrListElem_IsNew(elem))
                  m_pAttrList->SetItemTextColour(index, COLOR_NEW);
                else if (AttrListElem_IsReadOnly(elem))
                  m_pAttrList->SetItemTextColour(index, COLOR_READONLY);
                else if (AttrListElem_IsMandatory(elem))
                  m_pAttrList->SetItemTextColour(index, COLOR_MANDATORY);
                m_pAttrList->SetItemData(index, (long)elem);
              }
            else
              {
                index = m_pNewAttrChoice->Append(
                            TtaConvMessageToWX(AttrListElem_GetName(elem)));
                m_pNewAttrChoice->SetClientData(index, (void*)elem);
              }
            
          }
      }
      TtaFreeMemory(iter);
    }
Esempio n. 11
0
/*----------------------------------------------------------------------
  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);
}
Esempio n. 12
0
/*----------------------------------------------------------------------
  GetPExtension returns the Presentation Extension Schema associated with
  the document doc and the structure sSchema
  At the same time, this funciton updates the css context.
  ----------------------------------------------------------------------*/
PSchema GetPExtension (Document doc, SSchema sSchema, CSSInfoPtr css,
                       Element link)
{
  CSSInfoPtr          oldcss;
  PInfoPtr            pInfo, oldInfo;
  PISchemaPtr         pIS, oldIS;
  PSchema             pSchema, nSchema, prevS;
  Element             prevEl, nextEl;
  ElementType	      elType, styleType, linkType, piType;
  AttributeType       attrType;
  Attribute           attr;
  char                buffer[MAX_LENGTH];
  char               *name, pname[30];
  int                 length;
  ThotBool            found, before;

  if (css == NULL)
    return NULL;

  if (sSchema == NULL)
    sSchema = TtaGetDocumentSSchema (doc);
  pInfo = css->infos[doc];
  /* generate the presentation schema name */
  if (css->url)
    {
      length = strlen (css->url);
      if (length > 29)
        {
          strcpy (pname, "...");
          strcat (pname, &css->url[length-26]);
        }
      else
        strcpy (pname, css->url);
    }
  else
    pname[0] = EOS;
  nextEl = NULL;
  found = FALSE;
  pIS = NULL;
  while (pInfo && !found)
    {
      if (pInfo->PiLink == link)
        {
          /* look for the list of document schemas */
          pIS = pInfo->PiSchemas;
          while (pIS && !found)
            {
              if (sSchema == pIS->PiSSchema)
                {
                  if (pIS->PiPSchema)
                    /* the pschema is already known */
                    return (pIS->PiPSchema);
                }
              else
                pIS = pIS->PiSNext;
            }
          found = TRUE;
        }
      if (!found)
        /* next info context */
        pInfo = pInfo->PiNext;
    }

  if (pInfo == NULL)
    {
      /* add the presentation info block for the current document style */
      pInfo = AddInfoCSS (doc, css, CSS_DOCUMENT_STYLE, CSS_ALL, link);
      pIS = NULL;
      if (pInfo == NULL)
        return NULL;
    }

  if (pIS == NULL)
    {
      /* add the schema info */
      pIS = (PISchemaPtr) TtaGetMemory (sizeof (PISchema));
      pIS->PiSNext = pInfo->PiSchemas;
      pInfo->PiSchemas = pIS;
      pIS->PiSSchema = sSchema;
      pIS->PiPSchema = NULL;
    }

  /* create the presentation schema for this structure */
  nSchema = TtaNewPSchema (sSchema, pInfo->PiCategory == CSS_USER_STYLE);
  pSchema = TtaGetFirstPSchema (doc, sSchema);
  pIS->PiPSchema = nSchema;
  /* chain the presentation schema at the right position */
  prevS = NULL;
  before = FALSE;
  if (pInfo->PiCategory == CSS_USER_STYLE || pSchema == NULL)
    {
      /* add in first position and last priority */
      /* link the new presentation schema */
      TtaAddPSchema (nSchema, pSchema, TRUE, doc, sSchema, pname);
    }
  else if (pInfo->PiCategory == CSS_DOCUMENT_STYLE ||
           pInfo->PiCategory == CSS_EXTERNAL_STYLE)
    {
      /* check the order among its external style sheets */
      if (pInfo->PiLink)
        {
          /* look for the previous link with rel="STYLESHEET" */
          prevEl = pInfo->PiLink;
          nextEl = pInfo->PiLink;
          elType = TtaGetElementType (prevEl);
          name = TtaGetSSchemaName (elType.ElSSchema);
          styleType.ElSSchema = elType.ElSSchema;
          linkType.ElSSchema = elType.ElSSchema;
          piType.ElSSchema = elType.ElSSchema;
          attrType.AttrSSchema = elType.ElSSchema;
          if (!strcmp (name, "MathML"))
            {
              linkType.ElTypeNum = MathML_EL_XMLPI;
              styleType.ElTypeNum = MathML_EL_XMLPI;
              piType.ElTypeNum = MathML_EL_XMLPI;
              attrType.AttrTypeNum = HTML_ATTR_REL;
            }
#ifdef _SVG
          /* if it's a SVG document, remove the style defined in the SVG DTD */
          else if (!strcmp (name, "SVG"))
            {
              linkType.ElTypeNum = SVG_EL_XMLPI;
              styleType.ElTypeNum = SVG_EL_style__;
              piType.ElTypeNum = SVG_EL_XMLPI;
              attrType.AttrTypeNum = 0;
            }
#endif /* _SVG */
          else
            {
              linkType.ElTypeNum = HTML_EL_LINK;
              styleType.ElTypeNum = HTML_EL_STYLE_;
              piType.ElTypeNum = HTML_EL_XMLPI;
              attrType.AttrTypeNum = HTML_ATTR_REL;
            }

          /* look for a previous style item (link, style, PI) */
          found = FALSE;
          while (!found && prevEl)
            {
              prevEl = TtaSearchElementAmong5Types (linkType, styleType, piType,
                                                    linkType, styleType,
                                                    SearchBackward, prevEl);
              if (prevEl)
                {
                  if (attrType.AttrTypeNum == 0)
                    found = TRUE;
                  else
                    {
                      elType = TtaGetElementType (prevEl);
                      if (elType.ElTypeNum == linkType.ElTypeNum)
                        {
                          attr = TtaGetAttribute (prevEl, attrType);
                          if (attr)
                            {
                              /* get a buffer for the attribute value */
                              length = MAX_LENGTH;
                              TtaGiveTextAttributeValue (attr, buffer, &length);
                              found = (!strcasecmp (buffer, "STYLESHEET") ||
                                       !strcasecmp (buffer, "STYLE"));
                            }
                        }
                      else
                        found = TRUE;
                    }
                }
              if (found)
                {
                  /* there is another linked CSS style sheet before */
                  oldcss = CSSList;
                  found = FALSE;
                  /* search that previous CSS context */
                  while (oldcss && !found)
                    {
                      oldInfo = oldcss->infos[doc];
                      while (oldInfo && !found)
                        {
                          if (oldInfo != pInfo && oldInfo->PiLink == prevEl)
                            {
                              oldIS = oldInfo->PiSchemas;
                              while (oldIS && oldIS->PiSSchema != sSchema)
                                oldIS = oldIS->PiSNext;
                              if (oldIS && oldIS->PiPSchema)
                                {
                                  /* link after that presentation schema */
                                  before = FALSE;
                                  prevS = oldIS->PiPSchema;
                                  found = TRUE;
                                }
                            }
                          if (!found)
                            oldInfo = oldInfo->PiNext;
                        }
                      if (!found)
                        /* it's not the the previous style sheet */
                        oldcss = oldcss->NextCSS;
                    }
                }
            }

          /* look for a next style item (link, style, PI) */
          while (!found && nextEl)
            {
              nextEl = TtaSearchElementAmong5Types (linkType, styleType, piType,
                                                    linkType, styleType,
                                                    SearchForward, nextEl);
              if (nextEl)
                {
                  if (attrType.AttrTypeNum == 0)
                    found = TRUE;
                  else
                    {
                      elType = TtaGetElementType (nextEl);
                      if (elType.ElTypeNum == linkType.ElTypeNum)
                        {
                          attr = TtaGetAttribute (nextEl, attrType);
                          if (attr)
                            {
                              /* get a buffer for the attribute value */
                              length = MAX_LENGTH;
                              TtaGiveTextAttributeValue (attr, buffer, &length);
                              found = (!strcasecmp (buffer, "STYLESHEET") ||
                                       !strcasecmp (buffer, "STYLE"));
                            }
                        }
                      else
                        found = TRUE;
                    }
                }
              if (found)
                {
                  /* there is another linked CSS style sheet before */
                  oldcss = CSSList;
                  found = FALSE;
                  /* search that previous CSS context */
                  while (oldcss && !found)
                    {
                      oldInfo = oldcss->infos[doc];
                      while (oldInfo && !found)
                        {
                          if (oldInfo != pInfo && oldInfo->PiLink == nextEl)
                            {
                              oldIS = oldInfo->PiSchemas;
                              while (oldIS && oldIS->PiSSchema != sSchema)
                                oldIS = oldIS->PiSNext;
                              if (oldIS && oldIS->PiPSchema)
                                {
                                  /* link after that presentation schema */
                                  before = TRUE;
                                  prevS = oldIS->PiPSchema;
                                  found = TRUE;
                                }
                            }
                          if (!found)
                            oldInfo = oldInfo->PiNext;
                        }
                      if (!found)
                        /* it's not the the previous style sheet */
                        oldcss = oldcss->NextCSS;
                    }
                }
            }
	 
          if (!found)
            {
              /* look for CSS_USER_STYLE */
              oldcss = CSSList;
              while (oldcss && !found)
                {
                  oldInfo = oldcss->infos[doc];
                  while (oldInfo && !found)
                    {
                      if (oldInfo != pInfo &&
                          oldInfo->PiCategory == CSS_USER_STYLE)
                        {
                          oldIS = oldInfo->PiSchemas;
                          while (oldIS && oldIS->PiSSchema != sSchema)
                            oldIS = oldIS->PiSNext;
                          if (oldIS && oldIS->PiPSchema)
                            {
                              /* add after that schema with a higher priority */
                              prevS = oldIS->PiPSchema;
                              before = FALSE;
                              found = TRUE;
                            }
                        }
                      if (!found)
                        oldInfo = oldInfo->PiNext;
                    }
                  if (!found)
                    /* it's not the the previous style sheet */
                    oldcss = oldcss->NextCSS;
                }
            }
          if (found)
            /* link the new presentation schema */
            TtaAddPSchema (nSchema, prevS, before, doc, sSchema, pname);
          else
            TtaAddPSchema (nSchema, pSchema, TRUE, doc, sSchema, pname);
        }
      else
        {
          /* link the new presentation schema */
          TtaAddPSchema (nSchema, pSchema, TRUE, doc, sSchema, pname);
        }
    }
  return (nSchema);
}
Esempio n. 13
0
/*----------------------------------------------------------------------
  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;
        }
    }
}