Here is a function from a very old plugin that I used to sell. This function takes a text object, like a paragraph, and finds a condition format and replaces it with another. Of interest to you will be:
Please let me know if you have any questions or comments.
IntT FindChangeCondFmts(F_ObjHandleT oDoc, F_ObjHandleT oTextObj, StringT findFmt,
F_ObjHandleT changeFmtId)
{
UIntT i = 0, j = 0, n = 0;
IntT iBeginOffset = 0, iEndOffset = 0, iOldFound = 0, iCount = 0;
F_IntsT iOldConds, iNewConds;
F_ObjHandleT findFmtId;
F_TextItemsT tTextItems; // Text items returned by F_ApiGetText().
F_TextRangeT tTextRange; // Text range of unique character tag formatting.
F_PropValT pCharProp; // Properties of text range.
F_PropValT pNewProp; // New properties of text range.
// Get the old condition format object.
findFmtId = F_ApiGetNamedObject(oDoc, FO_CondFmt, findFmt);
// Get a list of character property changes.
tTextItems = F_ApiGetText(oDoc, oTextObj, FTI_CharPropsChange);
// Loop through the list of text items.
for (n=0; n < tTextItems.len; n++)
{
// See if the character format has changed.
if (tTextItems.val.u.idata & FTF_CONDITIONTAG)
{
if (tTextItems.val.offset != iBeginOffset)
{
iEndOffset = tTextItems.val.offset;
// Make a text range of the unique tag formatting.
tTextRange.beg.objId = tTextRange.end.objId = oTextObj;
tTextRange.beg.offset = iBeginOffset;
tTextRange.end.offset = iEndOffset;
// Get the text properties at the beginning of the range.
pCharProp = F_ApiGetTextPropVal(oDoc, &tTextRange.beg, FP_InCond);
iOldConds = pCharProp.propVal.u.isval;
if (iOldConds.len)
{
// Initialize the new condition integer list.
iNewConds.val = (IntT *)F_Alloc(sizeof(IntT), NO_DSE);
// Loop through the old conditions and look for the find condition.
for (i = 0, j = 0; i < iOldConds.len; i++)
{
if(iOldConds.val != (IntT)findFmtId)
{
iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);
iNewConds.val = iOldConds.val;
j++;
}
else // Find condition found.
{
if ((IntT)changeFmtId > 0) // Add the change condition to the new list.
{
iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);
iNewConds.val = changeFmtId;
j++;
}
iOldFound = 1; // The old condition was found/changed.
}
}
iNewConds.len = j;
if (iOldFound == 1)
{
// Set up the text property with the new condition list.
pNewProp.propIdent.num = FP_InCond;
pNewProp.propVal.valType = FT_Ints;
pNewProp.propVal.u.isval = iNewConds;
// Apply the new condition list to the text range.
F_ApiSetTextPropVal(oDoc, &tTextRange, &pNewProp);
iCount++;
// Deallocate the property value.
F_ApiDeallocatePropVal(&pNewProp);
}
}
// Deallocate the property value.
F_ApiDeallocatePropVal(&pCharProp);
// Advance the beginning offset variable to the current offset.
iBeginOffset = iEndOffset;
}
}
}
// At the end of the text object, make a text range including the end.
tTextRange.beg.objId = tTextRange.end.objId = oTextObj;
tTextRange.beg.offset = iBeginOffset;
tTextRange.end.offset = FV_OBJ_END_OFFSET;
// Get the text properties at the beginning of the range.
pCharProp = F_ApiGetTextPropVal(oDoc, &tTextRange.beg, FP_InCond);
iOldConds = pCharProp.propVal.u.isval;
if (iOldConds.len)
{
// Initialize the new condition integer list.
iNewConds.val = (IntT *)F_Alloc(sizeof(IntT), NO_DSE);
// Loop through the old conditions and look for the find condition.
for (i = 0, j = 0; i < iOldConds.len; i++)
{
if(iOldConds.val != (IntT)findFmtId)
{
iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);
iNewConds.val = iOldConds.val;
j++;
}
else // Find condition found.
{
if ((IntT)changeFmtId > 0) // Add the change condition to the new list.
{
iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);
iNewConds.val = changeFmtId;
j++;
}
iOldFound = 1; // The old condition was found/changed.
}
}
iNewConds.len = j;
if (iOldFound == 1)
{
// Set up the text property with the new condition list.
pNewProp.propIdent.num = FP_InCond;
pNewProp.propVal.valType = FT_Ints;
pNewProp.propVal.u.isval = iNewConds;
// Apply the new condition list to the text range.
F_ApiSetTextPropVal(oDoc, &tTextRange, &pNewProp);
iCount++;
// Deallocate the property value.
F_ApiDeallocatePropVal(&pNewProp);
}
}
// Deallocate the property value.
F_ApiDeallocatePropVal(&pCharProp);
return(iCount);
}