/// ----------------------------------------------------------------------------------- /// <summary> /// Sets the number of levels needed to traverse the view objects to reach the /// given limit of the selection. /// </summary> /// ----------------------------------------------------------------------------------- public virtual void SetNumberOfLevels(SelLimitType type, int value) { int iType = GetIndex(type); m_selInfo[iType].rgvsli = new SelLevInfo[value]; for (int i = 0; i < value; i++) m_selInfo[iType].rgvsli[i] = new SelLevInfo(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Returns the contrary limit /// </summary> /// <param name="limit"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private SelLimitType ContraryLimit(SelLimitType limit) { switch(limit) { case SelLimitType.Anchor: return SelLimitType.End; case SelLimitType.End: return SelLimitType.Anchor; case SelLimitType.Top: return SelLimitType.Bottom; case SelLimitType.Bottom: return SelLimitType.Top; } return SelLimitType.Anchor; }
/// ------------------------------------------------------------------------------------ /// <summary> /// This is the workhorse that actually reduces a range selection to a simple insertion /// point, given the specified index to indicate the limit where the IP is to be /// created. /// </summary> /// <param name="limit">The current selection limit to reduce to</param> /// <param name="fMakeVisible">Indicates whether to scroll the IP into view.</param> /// <param name="fInstall">True to install the created selection, false otherwise</param> /// <returns>The selection that was created</returns> /// ------------------------------------------------------------------------------------ public virtual IVwSelection ReduceToIp(SelLimitType limit, bool fMakeVisible, bool fInstall) { SelLimitType newLimit = ContraryLimit(limit); // set the information for the IP for the other limit SetTextPropId(newLimit, GetTextPropId(limit)); SetNumberOfPreviousProps(newLimit, GetNumberOfPreviousProps(limit)); SetIch(newLimit, GetIch(limit)); m_fEndSet = false; SetIhvoRoot(newLimit, GetIhvoRoot(limit)); SetAssocPrev(newLimit, GetAssocPrev(limit)); SetWritingSystem(newLimit, GetWritingSystem(limit)); SetNumberOfLevels(newLimit, GetNumberOfLevels(limit)); SetLevelInfo(newLimit, GetLevelInfo(limit)); return SetSelection(m_rootSite, fInstall, fMakeVisible); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Returns the level number of the specified tag for this selection. /// </summary> /// <param name="tag">The field tag to search for /// (i.e. BaseStText.StTextTags.kflidParagraphs)</param> /// <param name="limitType">The limit of the selection to search for the specified tag /// </param> /// <returns>The level number of the specified tag for this selection, or -1 if it /// could not be found</returns> /// ------------------------------------------------------------------------------------ public int GetLevelForTag(int tag, SelLimitType limitType) { SelLevInfo[] info = GetLevelInfo(limitType); for (int i = 0; i < info.Length; i++) { if (info[i].tag == tag) return i; } return -1; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Reduce a range selection to a simple insertion point, specifying which limit of /// the range selection to use as the position for the new IP. /// </summary> /// <param name="rootSite">The root site</param> /// <param name="limit">Specify Top to place the IP at the top-most limit of the /// selection. Specify Bottom to place the IP at the bottom-most limit of the selection. /// Specify Anchor to place the IP at the point where the user initiated the selection. /// Specify End to place the IP at the point where the user completed the selection. Be /// aware the user may select text in either direction, thus the end of the selection\ /// could be visually before the anchor. For a simple insertion point or a selection /// entirely within a single StText, this parameter doesn't actually make any /// difference.</param> /// <param name="fMakeVisible">Indicates whether to scroll the IP into view.</param> /// ------------------------------------------------------------------------------------ public static SelectionHelper ReduceSelectionToIp(IVwRootSite rootSite, SelLimitType limit, bool fMakeVisible) { return ReduceSelectionToIp(rootSite, limit, fMakeVisible, true); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Sets the array of SelLevInfo. /// </summary> /// <param name="type">type</param> /// <param name="value">The level info</param> /// ----------------------------------------------------------------------------------- public virtual void SetLevelInfo(SelLimitType type, SelLevInfo[] value) { GetSelInfo(type).rgvsli = value; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Returns the selection level info for the specified tag found in the level info for /// this selection. /// </summary> /// <param name="tag">The field tag to search for /// (i.e. BaseStText.StTextTags.kflidParagraphs)</param> /// <param name="limitType">The limit of the selection to search for the specified tag /// </param> /// <returns>The level info for the specified tag</returns> /// <exception cref="Exception">Thrown if the specified tag is not found in the level /// info of the selection</exception> /// ------------------------------------------------------------------------------------ public SelLevInfo GetLevelInfoForTag(int tag, SelLimitType limitType) { SelLevInfo selLevInfo; if (GetLevelInfoForTag(tag, limitType, out selLevInfo)) return selLevInfo; throw new Exception("No selection level had the requested tag."); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Sets the text property that occurs at the indicated end of the selection. /// </summary> /// <param name="type">Anchor or End</param> /// <param name="tagTextProp">Text property</param> /// ----------------------------------------------------------------------------------- public void SetTextPropId(SelLimitType type, int tagTextProp) { GetSelInfo(type).tagTextProp = tagTextProp; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Sets the number of previous elements for the given limit of the selection /// </summary> /// ----------------------------------------------------------------------------------- public virtual void SetNumberOfPreviousProps(SelLimitType type, int value) { GetSelInfo(type).cpropPrevious = value; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Gets the number of previous elements for the given limit of the selection /// </summary> /// <param name="type">Anchor or End</param> /// ----------------------------------------------------------------------------------- public virtual int GetNumberOfPreviousProps(SelLimitType type) { return GetSelInfo(type).cpropPrevious; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Gets the text property that occurs at the indicated end of the selection. /// </summary> /// ----------------------------------------------------------------------------------- public virtual int GetTextPropId(SelLimitType type) { return GetSelInfo(type).tagTextProp; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the index of the root object for the given limit of the selection. This /// is 0 for views that don't display mutliple root objects). /// </summary> /// ------------------------------------------------------------------------------------ public virtual void SetIhvoRoot(SelLimitType type, int value) { GetSelInfo(type).ihvoRoot = value; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the index of the root object for the given limit of the selection. This /// is 0 for views that don't display mutliple root objects). /// </summary> /// <param name="type">Anchor or End</param> /// ------------------------------------------------------------------------------------ public virtual int GetIhvoRoot(SelLimitType type) { return GetSelInfo(type).ihvoRoot; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the internal selection info for the requested end of the selection. /// </summary> /// <param name="type">Anchor or End</param> /// ------------------------------------------------------------------------------------ private SelInfo GetSelInfo(SelLimitType type) { return m_selInfo[GetIndex(type)]; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Indicates whether of not the insertion point should be associated with the /// characters immediately preceding it in the view (default) or not. /// </summary> /// <param name="type">Which end of the selection</param> /// <param name="value"><c>true</c> to associate IP with preceding characters, otherwise /// <c>false</c></param> /// ------------------------------------------------------------------------------------ public virtual void SetAssocPrev(SelLimitType type, bool value) { GetSelInfo(type).fAssocPrev = value; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Gets the 0-based index of the character for the given limit of the selection. /// </summary> /// ----------------------------------------------------------------------------------- public virtual int GetIch(SelLimitType type) { return GetSelInfo(type).ich; }
// /// ----------------------------------------------------------------------------------- // /// <summary> // /// Gets or sets the index of the object containing the selection endpoint. This is // /// -1 by default, but should be set to a valid HVO if the selection spans multiple // /// paragraphs. // /// </summary> // /// ----------------------------------------------------------------------------------- // public int IhvoEndPara // { // get { return m_ihvoEnd; } // set { m_ihvoEnd = value; } // } // /// ----------------------------------------------------------------------------------- // /// <summary> // /// Gets or sets the text props to be used for any text that is entered after the // /// insertion point is set. // /// </summary> // /// ----------------------------------------------------------------------------------- // public ITsTextProps Ttp // { // get { return m_ttp; } // set { m_ttp = value; } // } /// ----------------------------------------------------------------------------------- /// <summary> /// Gets the array of VwSelLevInfo. Array elements should indicate the chain of /// objects that needs to be traversed to get from the root object to object where the /// selection is to be made. The tag for item n should be the flid in which the /// children of the root object are owned. The 0th element of this array must have /// its tag value set to BaseStText.StTextTags.kflidParagraphs. This is set /// automatically whenever the array is resized using Cvsli. /// </summary> /// <param name="type">type</param> /// <returns>The level info</returns> /// ----------------------------------------------------------------------------------- public virtual SelLevInfo[] GetLevelInfo(SelLimitType type) { return GetSelInfo(type).rgvsli; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Sets the 0-based index of the character for the given limit of the selection. /// If appropriate records that the end of the selection has been set explicitly. /// </summary> /// ----------------------------------------------------------------------------------- public virtual void SetIch(SelLimitType type, int value) { if (type == SelLimitType.End) m_fEndSet = true; GetSelInfo(type).ich = value; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines whether the specified flid is located in the level info for the selection /// </summary> /// <param name="flid">The flid.</param> /// <param name="limitType">Type of the limit.</param> /// <returns>true if the specified flid is found, false otherwise</returns> /// ------------------------------------------------------------------------------------ public bool IsFlidInLevelInfo(int flid, SelLimitType limitType) { SelLevInfo[] info = GetLevelInfo(limitType); for (int i = 0; i < info.Length; i++) { if (info[i].tag == flid) return true; } return false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get the writing system associated with the insertion point. /// <p>Note: If you need the writing system for the selection, you should /// use <see cref="GetFirstWsOfSelection"/>.</p> /// </summary> /// <param name="type">Which end of the selection</param> /// <returns>Writing system</returns> /// ------------------------------------------------------------------------------------ public virtual int GetWritingSystem(SelLimitType type) { return GetSelInfo(type).ws; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Retrieves the selection level info for the specified tag found in the level info for /// this selection. /// </summary> /// <param name="tag">The field tag to search for /// (i.e. BaseStText.StTextTags.kflidParagraphs)</param> /// <param name="limitType">The limit of the selection to search for the specified tag /// </param> /// <param name="selLevInfo">The level info for the specified tag, if found; undefined /// otherwise</param> /// <returns><c>true</c>if the specified tag is found; <c>false</c> otherwise</returns> /// ------------------------------------------------------------------------------------ public bool GetLevelInfoForTag(int tag, SelLimitType limitType, out SelLevInfo selLevInfo) { SelLevInfo[] info = GetLevelInfo(limitType); for (int i = 0; i < info.Length; i++) { if (info[i].tag == tag) { selLevInfo = info[i]; return true; } } selLevInfo = new SelLevInfo(); return false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set the writing system associated with the insertion point. /// <p>Note: If you need the writing system for the selection, you should /// use <see cref="GetFirstWsOfSelection"/>.</p> /// </summary> /// <param name="type">Which end of the selection</param> /// <param name="value">Writing system</param> /// ------------------------------------------------------------------------------------ public virtual void SetWritingSystem(SelLimitType type, int value) { GetSelInfo(type).ws = value; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get the TsString of the property where the given selection limit is located. This /// gets the entire TSS of the paragraph, not just the selected portion. /// </summary> /// <param name="limit">the part of the selection where tss is to be retrieved (top, /// bottom, end, anchor)</param> /// <returns> /// the TsString containing the given limit of this Selection, or null if the selection /// is not in a paragraph. /// </returns> /// ------------------------------------------------------------------------------------ public virtual ITsString GetTss(SelLimitType limit) { try { ITsString tss; int ich, hvoObj, tag, ws; bool fAssocPrev; Selection.TextSelInfo(IsEnd(limit), out tss, out ich, out fAssocPrev, out hvoObj, out tag, out ws); return tss; } catch { return null; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get the text props associated with the given end of the selection. /// </summary> /// <param name="type">Which end of the selection</param> /// <returns>Text props associated with the given end of the selection</returns> /// ------------------------------------------------------------------------------------ public virtual ITsTextProps GetSelProps(SelLimitType type) { return GetSelInfo(type).ttpSelProps; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Reduce a range selection to a simple insertion point, specifying which limit of /// the range selection to use as the position for the new IP. /// </summary> /// <param name="rootSite">The root site</param> /// <param name="limit">Specify Top to place the IP at the top-most limit of the /// selection. Specify Bottom to place the IP at the bottom-most limit of the selection. /// Specify Anchor to place the IP at the point where the user initiated the selection. /// Specify End to place the IP at the point where the user completed the selection. Be /// aware the user may select text in either direction, thus the end of the selection\ /// could be visually before the anchor. For a simple insertion point or a selection /// entirely within a single StText, this parameter doesn't actually make any /// difference.</param> /// <param name="fMakeVisible">Indicates whether to scroll the IP into view.</param> /// <param name="fInstall">True to install the created selection, false otherwise</param> /// ------------------------------------------------------------------------------------ public static SelectionHelper ReduceSelectionToIp(IVwRootSite rootSite, SelLimitType limit, bool fMakeVisible, bool fInstall) { SelectionHelper helper = SelectionHelper.Create(rootSite); if (helper == null) return null; return helper.ReduceSelectionToIp(limit, fMakeVisible, fInstall); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set the text props associated with the given end of the selection. /// </summary> /// <param name="type">Which end of the selection</param> /// <param name="value">Properties to set for the selection</param> /// ------------------------------------------------------------------------------------ public virtual void SetSelProps(SelLimitType type, ITsTextProps value) { GetSelInfo(type).ttpSelProps = value; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Reduces this selection to an insertion point at the specified limit. /// Will not install or make visible. /// </summary> /// <param name="limit">The current selection limit to reduce to</param> /// ------------------------------------------------------------------------------------ public virtual void ReduceToIp(SelLimitType limit) { ReduceToIp(limit, false, false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Indicates whether of not the insertion point should be associated with the /// characters immediately preceding it in the view (default) or not. /// </summary> /// <param name="type">Which end of the selection</param> /// <returns><c>true</c> to associate IP with preceding characters, otherwise /// <c>false</c></returns> /// ------------------------------------------------------------------------------------ public virtual bool GetAssocPrev(SelLimitType type) { return GetSelInfo(type).fAssocPrev; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets a (new) selection helper that represents an insertion point at the specified /// limit of this selection /// </summary> /// <param name="limit">Specify Top to place the IP at the top-most limit of the /// selection. Specify Bottom to place the IP at the bottom-most limit of the selection. /// Specify Anchor to place the IP at the point where the user initiated the selection. /// Specify End to place the IP at the point where the user completed the selection. Be /// aware the user may select text in either direction, thus the end of the selection\ /// could be visually before the anchor. For a simple insertion point or a selection /// entirely within a single StText, this parameter doesn't actually make any /// difference.</param> /// <param name="fMakeVisible">Indicates whether to scroll the IP into view.</param> /// <param name="fInstall">True to install the created selection, false otherwise</param> /// ------------------------------------------------------------------------------------ public virtual SelectionHelper ReduceSelectionToIp(SelLimitType limit, bool fMakeVisible, bool fInstall) { SelectionHelper textSelHelper = new SelectionHelper(this); return textSelHelper.ReduceToIp(limit, fMakeVisible, fInstall) == null ? null : textSelHelper; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Gets the number of levels needed to traverse the view objects to reach the /// given limit of the selection. /// </summary> /// ----------------------------------------------------------------------------------- public virtual int GetNumberOfLevels(SelLimitType type) { return GetSelInfo(type).rgvsli.Length; }