/// ------------------------------------------------------------------------------------ /// <summary> /// Set up the specified overrides (as controlled by the initializer) for the specified /// range of characters in the specified paragraph. Return true if anything changed. /// </summary> /// <param name="para">The paragraph .</param> /// <param name="ichMin">The index (in logical characters, relative to /// para.Contents) of the first character whose properties will be overridden.</param> /// <param name="ichLim">The character "limit" (in logical characters, /// relative to para.Contents) of the text whose properties will be overridden.</param> /// <param name="initializer">A delegate that modifies the display props of characters /// between ichMin and ichLim.</param> /// <param name="sourceRootBox">The source root box.</param> /// <returns><c>true</c> if the text overrides changed; <c>false</c> otherwise.</returns> /// ------------------------------------------------------------------------------------ public bool SetupOverrides(IScrTxtPara para, int ichMin, int ichLim, DispPropInitializer initializer, IVwRootBox sourceRootBox) { // ENHANCE JohnT: if more than one thing uses this at the same time, it may become necessary to // check whether we're setting up the same initializer. I don't know how to do this. Might need // another argument and variable to keep track of a type of override. if (para == m_overridePara && ichMin == m_ichMinOverride && ichLim == m_ichLimOverride) { return(false); } if (m_overridePara != null && m_overridePara.IsValidObject) { // remove the old override. IStTxtPara oldPara = m_overridePara; m_overridePara = null; // remove it so the redraw won't show highlighting! UpdateDisplayOfPara(oldPara, sourceRootBox); } m_ichMinOverride = ichMin; m_ichLimOverride = ichLim; m_overridePara = para; m_overrideInitializer = initializer; if (m_overridePara != null && m_overridePara.IsValidObject) { // show the new override. UpdateDisplayOfPara(m_overridePara, sourceRootBox); } return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make the DispPropOverrides we need to give the specified run of characters the /// display properties defined by the initializer. /// </summary> /// <param name="para">The paragraph.</param> /// <param name="paraMinHighlight">The index (in logical characters, relative to /// para.Contents) of the first character whose properties will be overridden.</param> /// <param name="paraLimHighlight">The character "limit" (in logical characters, /// relative to para.Contents) of the text whose properties will be overridden.</param> /// <param name="initializer">A delegate that modifies the display props of characters /// between ichMin and ichLim.</param> /// ------------------------------------------------------------------------------------ protected void MakeDispPropOverrides(IScrTxtPara para, int paraMinHighlight, int paraLimHighlight, DispPropInitializer initializer) { if (paraLimHighlight < paraMinHighlight) { throw new ArgumentOutOfRangeException("paraLimHighlight", "ParaLimHighlight must be greater or equal to paraMinHighlight"); } int offsetToStartOfParaContents = 0; if (para.Owner is IScrFootnote && para.IndexInOwner == 0) { IScrFootnote footnote = (IScrFootnote)para.Owner; string sMarker = footnote.MarkerAsString; if (sMarker != null) { offsetToStartOfParaContents += sMarker.Length + OneSpaceString.Length; } offsetToStartOfParaContents += footnote.RefAsString.Length; } // Add the needed properties to each run, within our range ITsString tss = para.Contents; TsRunInfo runInfo; int ichOverrideLim; int ichOverrideMin = Math.Min(Math.Max(paraMinHighlight, 0), tss.Length); int prevLim = 0; do { tss.FetchRunInfoAt(ichOverrideMin, out runInfo); ichOverrideLim = Math.Min(paraLimHighlight, runInfo.ichLim); Debug.Assert(ichOverrideLim <= tss.Length, "If we get a run it should be in the bounds of the paragraph"); // Prevent infinite loop in case of bad data in difference if (ichOverrideLim == prevLim) { break; } prevLim = ichOverrideLim; DispPropOverride prop = DispPropOverrideFactory.Create( ichOverrideMin + offsetToStartOfParaContents, ichOverrideLim + offsetToStartOfParaContents); initializer(ref prop); m_DispPropOverrides.Add(prop); // advance Min for next run ichOverrideMin = ichOverrideLim; }while (ichOverrideLim < paraLimHighlight); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make the DispPropOverrides we need to give the specified run of characters the /// display properties defined by the initializer. /// </summary> /// <param name="para">The paragraph.</param> /// <param name="paraMinHighlight">The index (in logical characters, relative to /// para.Contents) of the first character whose properties will be overridden.</param> /// <param name="paraLimHighlight">The character "limit" (in logical characters, /// relative to para.Contents) of the text whose properties will be overridden.</param> /// <param name="initializer">A delegate that modifies the display props of characters /// between ichMin and ichLim.</param> /// ------------------------------------------------------------------------------------ protected void MakeDispPropOverrides(IScrTxtPara para, int paraMinHighlight, int paraLimHighlight, DispPropInitializer initializer) { if (paraLimHighlight < paraMinHighlight) throw new ArgumentOutOfRangeException("paraLimHighlight", "ParaLimHighlight must be greater or equal to paraMinHighlight"); int offsetToStartOfParaContents = 0; if (para.Owner is IScrFootnote && para.IndexInOwner == 0) { IScrFootnote footnote = (IScrFootnote)para.Owner; string sMarker = footnote.MarkerAsString; if (sMarker != null) offsetToStartOfParaContents += sMarker.Length + OneSpaceString.Length; offsetToStartOfParaContents += footnote.RefAsString.Length; } // Add the needed properties to each run, within our range ITsString tss = para.Contents; TsRunInfo runInfo; int ichOverrideLim; int ichOverrideMin = Math.Min(Math.Max(paraMinHighlight, 0), tss.Length); int prevLim = 0; do { tss.FetchRunInfoAt(ichOverrideMin, out runInfo); ichOverrideLim = Math.Min(paraLimHighlight, runInfo.ichLim); Debug.Assert(ichOverrideLim <= tss.Length, "If we get a run it should be in the bounds of the paragraph"); // Prevent infinite loop in case of bad data in difference if (ichOverrideLim == prevLim) break; prevLim = ichOverrideLim; DispPropOverride prop = DispPropOverrideFactory.Create( ichOverrideMin + offsetToStartOfParaContents, ichOverrideLim + offsetToStartOfParaContents); initializer(ref prop); m_DispPropOverrides.Add(prop); // advance Min for next run ichOverrideMin = ichOverrideLim; } while (ichOverrideLim < paraLimHighlight); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set up the specified overrides (as controlled by the initializer) for the specified /// range of characters in the specified paragraph. Return true if anything changed. /// </summary> /// <param name="para">The paragraph .</param> /// <param name="ichMin">The index (in logical characters, relative to /// para.Contents) of the first character whose properties will be overridden.</param> /// <param name="ichLim">The character "limit" (in logical characters, /// relative to para.Contents) of the text whose properties will be overridden.</param> /// <param name="initializer">A delegate that modifies the display props of characters /// between ichMin and ichLim.</param> /// <param name="sourceRootBox">The source root box.</param> /// <returns><c>true</c> if the text overrides changed; <c>false</c> otherwise.</returns> /// ------------------------------------------------------------------------------------ public bool SetupOverrides(IScrTxtPara para, int ichMin, int ichLim, DispPropInitializer initializer, IVwRootBox sourceRootBox) { // ENHANCE JohnT: if more than one thing uses this at the same time, it may become necessary to // check whether we're setting up the same initializer. I don't know how to do this. Might need // another argument and variable to keep track of a type of override. if (para == m_overridePara && ichMin == m_ichMinOverride && ichLim == m_ichLimOverride) return false; if (m_overridePara != null && m_overridePara.IsValidObject) { // remove the old override. IStTxtPara oldPara = m_overridePara; m_overridePara = null; // remove it so the redraw won't show highlighting! UpdateDisplayOfPara(oldPara, sourceRootBox); } m_ichMinOverride = ichMin; m_ichLimOverride = ichLim; m_overridePara = para; m_overrideInitializer = initializer; if (m_overridePara != null && m_overridePara.IsValidObject) { // show the new override. UpdateDisplayOfPara(m_overridePara, sourceRootBox); } return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// privides access to the "MakeDispPropOverrides" method /// </summary> /// <param name="para">The para.</param> /// <param name="paraMinHighlight">The para min highlight.</param> /// <param name="paraLimHighlight">The para lim highlight.</param> /// <param name="initializer">The initializer.</param> /// ------------------------------------------------------------------------------------ public void CallMakeDispPropOverrides(IScrTxtPara para, int paraMinHighlight, int paraLimHighlight, DispPropInitializer initializer) { MakeDispPropOverrides(para, paraMinHighlight, paraLimHighlight, initializer); }
/// ------------------------------------------------------------------------------------ /// <summary> /// privides access to the "MakeDispPropOverrides" method /// </summary> /// <param name="para">The para.</param> /// <param name="paraMinHighlight">The para min highlight.</param> /// <param name="paraLimHighlight">The para lim highlight.</param> /// <param name="initializer">The initializer.</param> /// ------------------------------------------------------------------------------------ public void CallMakeDispPropOverrides(StTxtPara para, int paraMinHighlight, int paraLimHighlight, DispPropInitializer initializer) { MakeDispPropOverrides(para, paraMinHighlight, paraLimHighlight, initializer); }
/// <summary> /// Make the DispPropOverrides we need to give the specified run of characters the display /// properties defined by the initializer. /// </summary> protected void MakeDispPropOverrides(StTxtPara para, int paraMinHighlight, int paraLimHighlight, DispPropInitializer initializer) { if (paraLimHighlight < paraMinHighlight) throw new ArgumentOutOfRangeException("paraLimHighlight", "ParaLimHighlight must be greater or equal to paraMinHighlight"); m_DispPropOverrides.Clear(); // Add the needed properties to each run, within our range ITsString tss = para.Contents.UnderlyingTsString; TsRunInfo runInfo; int ichOverrideLim; int ichOverrideMin = Math.Min(Math.Max(paraMinHighlight, 0), tss.Length); int prevLim = 0; do { tss.FetchRunInfoAt(ichOverrideMin, out runInfo); ichOverrideLim = Math.Min(paraLimHighlight, runInfo.ichLim); Debug.Assert(ichOverrideLim <= tss.Length, "If we get a run it should be in the bounds of the paragraph"); // Prevent infinite loop in case of bad data in difference if (ichOverrideLim == prevLim) break; prevLim = ichOverrideLim; DispPropOverride prop = MakeDispPropOverride(ichOverrideMin, ichOverrideLim); initializer(ref prop); m_DispPropOverrides.Add(prop); // advance Min for next run ichOverrideMin = ichOverrideLim; } while (ichOverrideLim < paraLimHighlight); }