Exemple #1
0
/*----------------------------------------------------------------------
  Save an opened document to a specified path in order to open.
  The parameter doc is the original doc to be saved
  The parameter newdoc is the new document
  The parameter newpath is the newdoc URI
  Return the saved localFile (to be freed) or NULL
  ----------------------------------------------------------------------*/
char *SaveDocumentToNewDoc(Document doc, Document newdoc, char* newpath)
{
  ElementType   elType;
  Element       root;
  char         *localFile = NULL, *s;
  ThotBool      res = FALSE;

  localFile = GetLocalPath (newdoc, newpath);

  // apply link changes to the template
    TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
  SetRelativeURLs (doc, newpath, NULL, FALSE, FALSE, FALSE, FALSE);
  // prepare the new document view
  TtaExtractName (newpath, DirectoryName, DocumentName);

  root = TtaGetRootElement(doc);
  elType = TtaGetElementType (root);
  // get the target document type
  s = TtaGetSSchemaName (elType.ElSSchema);
  if (!IsNotHTMLorHTML5 (s))
    {

	  if (TtaGetDocumentProfile(doc) == L_HTML5 || TtaGetDocumentProfile(doc) == L_HTML5_LEGACY)
		 res = TtaExportDocumentWithNewLineNumbers (doc, localFile, "HTML5TX", FALSE);
	  else
	  {
		  /* docType = docHTML; */
		  if (TtaGetDocumentProfile(doc) == L_Xhtml11 ||
			  TtaGetDocumentProfile(doc) == L_Basic)
			res = TtaExportDocumentWithNewLineNumbers (doc, localFile, "HTMLT11", FALSE);
		  else
			res = TtaExportDocumentWithNewLineNumbers (doc, localFile, "HTMLTX", FALSE);
	  }
    }
  else if (strcmp (s, "SVG") == 0)
    /* docType = docSVG; */
    res = TtaExportDocumentWithNewLineNumbers (doc, localFile, "SVGT", FALSE);
  else if (strcmp (s, "MathML") == 0)
    /* docType = docMath; */
    res = TtaExportDocumentWithNewLineNumbers (doc, localFile, "MathMLT", FALSE);
  else
    /* docType = docXml; */
    res = TtaExportDocumentWithNewLineNumbers (doc, localFile, NULL, FALSE);

  // restore the previous state of the template
  TtaCloseUndoSequence (doc);
  TtaUndoNoRedo (doc);
  if (res)
    return localFile;
  else
    {
      TtaFreeMemory (localFile);
      return NULL;
    }
}
/*----------------------------------------------------------------------
  RemoveCurrentAttribut
  params:
  returns:
  ----------------------------------------------------------------------*/
void AmayaAttributeToolPanel::RemoveCurrentAttribute()
{
  PtrElement      pEl;
  Attribute       attr;
  AttributeType   attrType;
  NotifyAttribute notifyAttr;
  int             kind;

  Document     doc = TtaGetDocument((Element)m_firstSel);
  DisplayMode  mode = TtaGetDisplayMode(doc);
  
  DesactivatePanel();

  if (m_currentPane != wxATTR_PANEID_NONE && m_firstSel &&
      m_currentAttElem && m_currentAttElem->val)
    {
      TtaSetDisplayMode(doc, DeferredDisplay);
      TtaOpenUndoSequence(doc, (Element)m_firstSel, (Element)m_lastSel,
                          m_firstChar, m_lastChar);

      /* first selected element */
      pEl = (PtrElement)m_firstSel;
      attr = (Attribute)m_currentAttElem->val;
      TtaGiveAttributeType (attr, &attrType, &kind);
      /* prepare event AttrDelete to be sent to the application */
      notifyAttr.event = TteAttrDelete;
      notifyAttr.document = doc;
      notifyAttr.info = 0; /* not sent by undo */
      notifyAttr.attributeType = attrType;
      while (pEl != NULL)
        {
          if (attr)
            {
              notifyAttr.element = (Element) pEl;
              notifyAttr.attribute = attr;
              if (!CallEventAttribute (&notifyAttr, TRUE))
                /* application accepts */
                {
                  TtaRegisterAttributeDelete(attr, (Element)pEl, doc);
                  TtaRemoveAttribute((Element)pEl, attr, doc);
                  TtaSetDocumentModified(doc);
                  /* send event Attribute deleted */
                  notifyAttr.attribute = NULL;
                  CallEventAttribute (&notifyAttr, FALSE);
                }
            }
          /* next element in the selection */
          pEl = NextInSelection (pEl, (PtrElement)m_lastSel);
          attr = TtaGetAttribute ((Element)pEl, attrType);
        }

      TtaCloseUndoSequence(doc);
      TtaSetDisplayMode(doc, mode);
      ForceAttributeUpdate();
    }
  
  ActivePanel();
  
  /* try to redirect focus to canvas */
  TtaRedirectFocus();  
}