Ejemplo n.º 1
0
/*----------------------------------------------------------------------
  GetParentDiv get the enclosing div if it's only include this element
  or generates an enclosing div.
  ----------------------------------------------------------------------*/
static Element GetParentDiv (Element el, SSchema HTMLschema, Document doc)
{
  Element	 div, prev, next;
  ElementType    elType;

  /* generate a division around this pseudo paragraph */
  div = TtaGetParent (el);
  if (div)
    {
      elType = TtaGetElementType (div);
      prev = next = el;
      if (elType.ElSSchema == HTMLschema &&
          elType.ElTypeNum == HTML_EL_Division)
        {
          TtaPreviousSibling (&prev);
          TtaNextSibling (&next);
        }
      if (prev || next)
        /* this div includes more than the pseudo paragraph */
        div = NULL;
    }
  if (div == NULL)
    {
      elType.ElSSchema = HTMLschema;
      elType.ElTypeNum = HTML_EL_Division;
      div = TtaNewElement (doc, elType);
      TtaInsertSibling (div, el, TRUE, doc);
      TtaRegisterElementCreate (div, doc);
      TtaRegisterElementDelete (el, doc);
      TtaRemoveTree (el, doc);
      TtaInsertFirstChild  (&el, div, doc);
      TtaRegisterElementCreate (el, doc);
    }
  return div;
}
Ejemplo n.º 2
0
/*----------------------------------------------------------------------
  DeleteSpanIfNoAttr
  An attribute has been removed from element el in document doc.
  If element el is a SPAN without any attribute, the SPAN element is
  removed and variables firstChild and lastChild are the first and
  last child of the former SPAN element.
  Otherwise, firstChild and lastChild are NULL.
  -----------------------------------------------------------------------*/
void DeleteSpanIfNoAttr (Element el, Document doc, Element *firstChild,
                         Element *lastChild)
{
  ElementType	elType;
  Element	    span, child, next;
  Attribute	  attr;

  /* if the element is a SPAN without any other attribute, remove the SPAN
     element */
  *firstChild = NULL;
  *lastChild = NULL;
  elType = TtaGetElementType (el);
  if (elType.ElTypeNum == HTML_EL_Span &&
      strcmp(TtaGetSSchemaName (elType.ElSSchema), "HTML") == 0)
    {
      span = el;
      attr = NULL;
      TtaNextAttribute (span, &attr);
      if (attr == NULL)
        {
          TtaRegisterElementDelete (span, doc);
          child = TtaGetFirstChild (span);
          while (child != NULL)
            {
              next = child;
              TtaNextSibling (&next);
              TtaRemoveTree (child, doc);
              TtaInsertSibling (child, span, TRUE, doc);
              TtaRegisterElementCreate (child, doc);
              if (*firstChild == NULL)
                *firstChild = child;
              *lastChild = child;
              child = next;
            }
          TtaDeleteTree (span, doc);
          TtaSelectElement (doc, *firstChild);
          TtaSetStatusSelectedElement(doc, 1, *firstChild);
        }
    }
}
Ejemplo n.º 3
0
/*----------------------------------------------------------------------
  MakeASpan
  if element elem is a text string that is not the single child of a
  Span element, create a span element that contains that text string
  and return TRUE; span contains then the created Span element.
  if the parameter presRule is not NULL and a span is generated, the
  presRule should be moved to the new span.
  -----------------------------------------------------------------------*/
ThotBool MakeASpan (Element elem, Element *span, Document doc, PRule presRule)
{
  ElementType	elType;
  Element       parent, sibling;
  char         *name;
  ThotBool      ret, doit;

  ret = FALSE;
  *span = NULL;
  elType = TtaGetElementType (elem);
  name = TtaGetSSchemaName (elType.ElSSchema);
  if (!strcmp(name, "HTML") || !strcmp(name, "SVG"))
    /* it's an HTML or SVG element */
    if (elType.ElTypeNum == HTML_EL_TEXT_UNIT ||
        elType.ElTypeNum == HTML_EL_Basic_Elem)
      /* it's a text leaf */
      {
        parent = TtaGetParent (elem);
        if (parent != NULL)
          {
            doit = TRUE;
            elType = TtaGetElementType (parent);
            name = TtaGetSSchemaName (elType.ElSSchema);
            if ((elType.ElTypeNum == HTML_EL_Span && !strcmp(name, "HTML"))
#ifdef _SVG
                || (elType.ElTypeNum == SVG_EL_tspan && !strcmp (name, "SVG"))
#endif /* _SVG */
                )
              /* element parent is a span element */
              {
                sibling = elem;
                TtaNextSibling (&sibling);
                if (sibling == NULL)
                  {
                    sibling = elem;
                    TtaPreviousSibling (&sibling);
                    if (sibling == NULL)
                      /* the text leaf is the only child of its span parent.
                         No need to create a new span element */
                      {
                        doit = FALSE;
                        *span = parent;
                        if (presRule)
                          MovePRule (presRule, elem, *span, doc, TRUE);
                        ret = TRUE;
                      }
                  }
              }
            if (doit)
              /* enclose the text leaf within a span element */
              {
#ifdef _SVG
                if (!strcmp (name, "SVG"))
                  elType.ElTypeNum = SVG_EL_tspan;
                else
#endif /* _SVG */
                  elType.ElTypeNum = HTML_EL_Span;
                *span = TtaNewElement (doc, elType);
                TtaInsertSibling (*span, elem, FALSE, doc);
                TtaRegisterElementCreate (*span, doc);
                if (presRule)
                  MovePRule (presRule, elem, *span, doc, TRUE);
                TtaRegisterElementDelete (elem, doc);
                TtaRemoveTree (elem, doc);
                TtaInsertFirstChild (&elem, *span, doc);
                TtaRegisterElementCreate (elem, doc);
                /* mark the document as modified */
                TtaSetDocumentModified (doc);
                ret = TRUE;
              }
          }
      }
  UpdateContextSensitiveMenus (doc, 1);
  return ret;
}
Ejemplo n.º 4
0
/*-----------------------------------------------------------------------
  LINK_RemoveLinkFromSource
  -----------------------------------------------------------------------*/
void LINK_RemoveLinkFromSource (Document source_doc, Element el)
{
  TtaRemoveTree (el, source_doc);
}