예제 #1
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);
        }
    }
}
예제 #2
0
/*----------------------------------------------------------------------
  get_intptr_attribute_from_el: Get a int value from an xml attribute,
  but stored as an allocated ptr
  ----------------------------------------------------------------------*/
static int *get_intptr_attribute_from_el (Element el, int Attribut_Type)
{
#ifdef _SVG
  AttributeType attrType;
  Attribute     attr = NULL;
  ElementType   elType = TtaGetElementType (el);
  int          *result;
  
  attrType.AttrSSchema = elType.ElSSchema;
  attrType.AttrTypeNum = Attribut_Type;  
  attr = TtaGetAttribute (el, attrType);
  result = (int *) TtaGetAttributeValue (attr);
  return result;
#endif /* _SVG */
}
예제 #3
0
파일: templateUtils.c 프로젝트: ezura/Amaya
/*----------------------------------------------------------------------
Returns the value of an int attribute
----------------------------------------------------------------------*/
int GetAttributeIntValueFromNum (Element el, int att)
{
#ifdef TEMPLATES
  AttributeType attType;
  Attribute     attribute;

  attType.AttrSSchema = TtaGetElementType (el).ElSSchema;
  attType.AttrTypeNum = att;
  attribute = TtaGetAttribute (el, attType);
  if (attribute)
    return TtaGetAttributeValue (attribute);
  else
    return 0;
#else
  return 0;
#endif /* TEMPLATES */
}
예제 #4
0
파일: templateUtils.c 프로젝트: ezura/Amaya
/*----------------------------------------------------------------------
  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;
}
예제 #5
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);
    }