Example #1
0
bool pt_PieceTable::insertStrux(PT_DocPosition dpos,
								PTStruxType pts,
								pf_Frag_Strux ** ppfs_ret)
{
	if(m_pDocument->isMarkRevisions())
	{
		// when the strux is inserted in non-revision mode, it inherits the AP from the previous
		// strux. In revision mode this does not necessarily work because we may need to have a
		// different revision attribute. Consequently, we need to ensure that the AP that gets
		// assigned to the new strux contains all relevant attrs and props from the AP of the
		// previous strux -- we do this by obtaining the index of the AP of the previous strux and
		// running it through _translateRevisionAttribute() which will gives back all attrs and
		// props that need to be passed to _realInsertStrux()
		pf_Frag_Strux * pfsContainer = NULL;
		bool bFoundContainer = _getStruxFromPosition(dpos,&pfsContainer); // the orig. strux
		UT_return_val_if_fail(bFoundContainer, false);
	
		if(isEndFootnote(pfsContainer))
		{
			bFoundContainer = _getStruxFromFragSkip(pfsContainer,&pfsContainer);
			UT_return_val_if_fail(bFoundContainer, false);
		}

		PT_AttrPropIndex indexAP = 0;
		if (pfsContainer->getStruxType() == pts)
		{
			indexAP = pfsContainer->getIndexAP();
		}

		PP_RevisionAttr Revisions(NULL);
		const gchar ** ppRevAttrib = NULL;
		const gchar ** ppRevProps  = NULL;

		_translateRevisionAttribute(Revisions, indexAP, PP_REVISION_ADDITION, ppRevAttrib, ppRevProps, 0, 0);

		//return _realChangeStruxFmt(PTC_AddFmt, dpos, dpos + iLen, ppRevAttrib,ppRevProps,pts);
		return _realInsertStrux(dpos,pts,ppRevAttrib,ppRevProps,ppfs_ret);
	}
	else
	{
		return _realInsertStrux(dpos,pts,0,0,ppfs_ret);
	}
}
Example #2
0
bool pt_PieceTable::insertStrux(PT_DocPosition dpos,
								PTStruxType pts,
								const gchar ** attributes,
								const gchar ** properties,
								pf_Frag_Strux ** ppfs_ret)
{
	if(m_pDocument->isMarkRevisions())
	{
		// This is just like the previous method, except that in addition to calling
		// _translateRevisionAttribute() we also need to set the attrs and props
		// passed to us.
		pf_Frag_Strux * pfsContainer = NULL;
		bool bFoundContainer = _getStruxFromPosition(dpos,&pfsContainer); // the orig. strux
		UT_return_val_if_fail(bFoundContainer, false);
	
		if(isEndFootnote(pfsContainer))
		{
			bFoundContainer = _getStruxFromFragSkip(pfsContainer,&pfsContainer);
			UT_return_val_if_fail(bFoundContainer, false);
		}

		PT_AttrPropIndex indexAP = 0;
		if (pfsContainer->getStruxType() == pts)
		{
			indexAP = pfsContainer->getIndexAP();
		}

		PP_RevisionAttr Revisions(NULL);
		const gchar ** ppRevAttrs = NULL;
		const gchar ** ppRevProps  = NULL;

		_translateRevisionAttribute(Revisions, indexAP, PP_REVISION_ADDITION,
									ppRevAttrs, ppRevProps, NULL, NULL);

		// count original attributes and the revision-inherited attributes
		// and add them to the revision attribute
		UT_uint32 iAttrCount = 0;
		for (; attributes && attributes[iAttrCount]; iAttrCount+=2){}

		UT_uint32 iRevAttrCount = 0;
		for (; ppRevAttrs && ppRevAttrs[iRevAttrCount]; iRevAttrCount+=2){}

		const gchar ** ppRevAttrib = NULL;
		if(iAttrCount + iRevAttrCount > 0)
		{
			ppRevAttrib = new const gchar * [iAttrCount + iRevAttrCount + 1];
			UT_return_val_if_fail( ppRevAttrib, false );

			UT_uint32 i = 0;
			for (i = 0; i < iAttrCount; ++i)
			{
				ppRevAttrib[i] = attributes[i];
			}

			for (; i < iRevAttrCount + iAttrCount; ++i)
			{
				ppRevAttrib[i] = ppRevAttrs[i - iAttrCount];
			}
		
			ppRevAttrib[i]   = NULL;
		}
		
		//return _realChangeStruxFmt(PTC_AddFmt, dpos, dpos + iLen, ppRevAttrib,NULL,pts);
		bool bRet = _realInsertStrux(dpos,pts,ppRevAttrib,properties,ppfs_ret);
		delete [] ppRevAttrib;
		return bRet;
	}
	else
	{
		return _realInsertStrux(dpos,pts,attributes,properties,ppfs_ret);
	}
}
bool pt_PieceTable::insertSpan(PT_DocPosition dpos,
							   const UT_UCSChar * p,
							   UT_uint32 length, fd_Field * pField,
							   bool bAddChangeRec)
{
	if(bAddChangeRec && m_pDocument->isMarkRevisions())
	{
		PP_RevisionAttr Revisions(NULL);
		const gchar ** ppRevAttrib = NULL;
		const gchar ** ppRevProps  = NULL;

		pf_Frag * pf = NULL;
		PT_BlockOffset fragOffset = 0;
		bool bFound = getFragFromPosition(dpos,&pf,&fragOffset);
		UT_return_val_if_fail( bFound, false );

		if(pf->getType() == pf_Frag::PFT_EndOfDoc)
			pf = pf->getPrev();

		UT_return_val_if_fail( pf, false );
		
		PT_AttrPropIndex indexAP = pf->getIndexAP();

		_translateRevisionAttribute(Revisions, indexAP, PP_REVISION_ADDITION, ppRevAttrib, ppRevProps, 0, 0);
		
		//return _realChangeSpanFmt(PTC_AddFmt, dpos, dpos + length, ppRevAttrib, ppRevProps);
		return _realInsertSpan(dpos, p, length, ppRevAttrib, ppRevProps, pField, bAddChangeRec);
	}
	else if(bAddChangeRec)
	{
		// When the revision marking is not on, we need to make sure
		// that the text does not get inserted with a leftover
		// revision attribute (e.g., if we are inserting it next to
		// revisioned text
		const gchar name[] = "revision";
		const gchar * ppRevAttrib[5];
		ppRevAttrib[0] = name;
		ppRevAttrib[1] = NULL;
		ppRevAttrib[2] = NULL;
		ppRevAttrib[3] = NULL;
		ppRevAttrib[4] = NULL;
		
		const gchar * pRevision = NULL;

		// first retrive the fmt we have (_realChangeSpanFmt()) is
		// quite involved, so we want to avoid calling it, if we can)
		pf_Frag * pf1;
		PT_BlockOffset Offset1;

		if(!getFragFromPosition(dpos, &pf1, &Offset1))
			return false;

		const PP_AttrProp * pAP;
		if(_getSpanAttrPropHelper(pf1, &pAP))
		{
		        const gchar * szStyleNameVal = NULL;
		        pAP->getAttribute(PT_STYLE_ATTRIBUTE_NAME,szStyleNameVal);
			if(!pAP->getAttribute(name, pRevision))
			{
			    return _realInsertSpan(dpos, p, length,NULL , NULL, pField, bAddChangeRec);
			}
			if(szStyleNameVal != NULL)
			{
			        ppRevAttrib[2] = PT_STYLE_ATTRIBUTE_NAME;;
				ppRevAttrib[3] = szStyleNameVal;
			  
			}
			//if(!_realChangeSpanFmt(PTC_RemoveFmt, dpos, dpos+length, ppRevAttrib,NULL))
			//	return false;
			return _realInsertSpan(dpos, p, length, ppRevAttrib, NULL, pField, bAddChangeRec);
		}
		else
		{
			// no AP, this is probably OK
			UT_DEBUGMSG(("pt_PieceTable::insertSpan: no AP\n"));
			return _realInsertSpan(dpos, p, length, NULL, NULL, pField, bAddChangeRec);
		}
	}
	else
	{
		return _realInsertSpan(dpos, p, length, NULL, NULL, pField, bAddChangeRec);
	}
}
Example #4
0
bool pt_PieceTable::insertObject(PT_DocPosition dpos,
								 PTObjectType pto,
								 const gchar ** attributes,
								 const gchar ** properties,  pf_Frag_Object ** ppfo)
{
	if(m_pDocument->isMarkRevisions())
	{
		PP_RevisionAttr Revisions(NULL);
		const gchar ** ppRevAttrs  = NULL;
		const gchar ** ppRevProps  = NULL;

		pf_Frag * pf = NULL;
		PT_BlockOffset fragOffset = 0;
		bool bFound = getFragFromPosition(dpos,&pf,&fragOffset);
		UT_return_val_if_fail( bFound, false );

		if(pf->getType() == pf_Frag::PFT_EndOfDoc)
			pf = pf->getPrev();

		UT_return_val_if_fail( pf, false );
		
		PT_AttrPropIndex indexAP = pf->getIndexAP();
		//UT_uint32 length = pf->getLength();
		
		_translateRevisionAttribute(Revisions, indexAP, PP_REVISION_ADDITION,
									ppRevAttrs, ppRevProps, NULL, NULL);

		// count original attributes and the revision-inherited
		// attributes and add them to the revision attribute
		UT_uint32 iAttrCount = 0;
		for (; attributes && attributes[iAttrCount]; iAttrCount+=2){}

		UT_uint32 iRevAttrCount = 0;
		for (; ppRevAttrs && ppRevAttrs[iRevAttrCount]; iRevAttrCount+=2){}

		const gchar ** ppRevAttrib = NULL;
		if(iAttrCount + iRevAttrCount > 0)
		{
			ppRevAttrib = new const gchar * [iAttrCount + iRevAttrCount + 1];
			UT_return_val_if_fail( ppRevAttrib, false );

			UT_uint32 i = 0;
			for (i = 0; i < iAttrCount; ++i)
			{
				ppRevAttrib[i] = attributes[i];
			}

			for (; i < iRevAttrCount + iAttrCount; ++i)
			{
				ppRevAttrib[i] = ppRevAttrs[i - iAttrCount];
			}
		
			ppRevAttrib[i]   = NULL;
		}
		
		//return _realChangeSpanFmt(PTC_AddFmt, dpos, dpos + length,
		//ppRevAttrib, ppRevProps);
		// NB: objects are not supposed to have props, and so do not
		//inherit props ...
		bool bRet =  _realInsertObject(dpos, pto, ppRevAttrib, /*ppRevProps*/properties, ppfo);
		delete [] ppRevAttrib;
		return bRet;
	}
	else
	{
		return _realInsertObject(dpos, pto, attributes, properties, ppfo);
	}
}