/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Attempts to find a pattern match in the view starting from the specified selection.
		/// </summary>
		/// <param name="sel">Starting position</param>
		/// <param name="forward">indicates whether to search forward or backward</param>
		/// ------------------------------------------------------------------------------------
		private void FindFrom(IVwSelection sel, bool forward)
		{
			FindCollectorEnv.LocationInfo startLocation = null;
			if (sel != null)
			{
				SelectionHelper helper = SelectionHelper.Create(sel, m_vwRootsite);
				startLocation = new FindCollectorEnv.LocationInfo(helper);
			}
			FindCollectorEnv.LocationInfo locationInfo = m_findEnvironment.FindNext(startLocation);
			if (locationInfo != null)
			{
				SelectionHelper selHelper = SelectionHelper.Create(m_vwRootsite);
				selHelper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor,
					locationInfo.m_location);
				selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End,
					locationInfo.m_location);
				selHelper.IchAnchor = locationInfo.m_ichMin;
				selHelper.IchEnd = locationInfo.m_ichLim;
				selHelper.SetNumberOfPreviousProps(SelectionHelper.SelLimitType.Anchor,
					locationInfo.m_cpropPrev);
				selHelper.SetNumberOfPreviousProps(SelectionHelper.SelLimitType.End,
					locationInfo.m_cpropPrev);
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, locationInfo.m_tag);
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, locationInfo.m_tag);
				m_vwselPattern = selHelper.SetSelection(m_vwRootsite, true, true,
					VwScrollSelOpts.kssoDefault);
				Debug.Assert(m_vwselPattern != null, "We need a selection after a find!");
			}
		}
		public void Find_FromMiddle()
		{
			CheckDisposed();

			FindCollectorEnv collectorEnv = new FindCollectorEnv(m_vc,
				Cache.MainCacheAccessor, m_para1.OwnerHVO, (int)StTextFrags.kfrText,
				m_pattern, null);

			// Start in the middle
			SelLevInfo[] levInfo = new SelLevInfo[1];
			levInfo[0].hvo = m_para2.Hvo;
			levInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			m_sel = new FindCollectorEnv.LocationInfo(levInfo,
				(int)StTxtPara.StTxtParaTags.kflidContents, 5);

			VerifyFindNext(collectorEnv, m_para2.Hvo, 20, 21);
			VerifyFindNext(collectorEnv, m_para2.Hvo, 27, 28);
			VerifyFindNext(collectorEnv, m_para2.Hvo, 44, 45);
			VerifyFindNext(collectorEnv, m_para2.Hvo, 52, 53);
			VerifyFindNext(collectorEnv, m_para2.Hvo, 64, 65);
			Assert.IsNull(collectorEnv.FindNext(m_sel));

			// Make sure nothing got replaced by accident.
			Assert.AreEqual("This is some text so that we can test the find functionality.",
				m_para1.Contents.Text);
			Assert.AreEqual("Some more text so that we can test the find and replace functionality.",
				m_para2.Contents.Text);
			Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.",
				m_para3.Contents.Text);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Verifies the find next.
		/// </summary>
		/// <param name="collectorEnv">The collector env.</param>
		/// <param name="hvoExpected">The hvo expected.</param>
		/// <param name="ichMinExpected">The ich min expected.</param>
		/// <param name="ichLimExpected">The ich lim expected.</param>
		/// ------------------------------------------------------------------------------------
		private void VerifyFindNext(FindCollectorEnv collectorEnv, int hvoExpected,
			int ichMinExpected, int ichLimExpected)
		{
			FindCollectorEnv.LocationInfo foundLocation = collectorEnv.FindNext(m_sel);
			Assert.IsNotNull(foundLocation);
			Assert.AreEqual(1, foundLocation.m_location.Length);
			Assert.AreEqual(hvoExpected, foundLocation.TopLevelHvo);
			Assert.AreEqual((int)StText.StTextTags.kflidParagraphs, foundLocation.m_location[0].tag);
			Assert.AreEqual((int)StTxtPara.StTxtParaTags.kflidContents, foundLocation.m_tag);
			Assert.AreEqual(ichMinExpected, foundLocation.m_ichMin);
			Assert.AreEqual(ichLimExpected, foundLocation.m_ichLim);
			m_sel = foundLocation;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Attempts to find a pattern match in the view starting from the specified selection.
		/// </summary>
		/// <param name="sel">Starting position</param>
		/// <param name="forward">indicates whether to search forward or backward</param>
		/// ------------------------------------------------------------------------------------
		private void FindFrom(IVwSelection sel, bool forward)
		{
			FindCollectorEnv.LocationInfo startLocation = null;
			var rootSite = ActiveView;
			if (rootSite == null)
				return;

			if (sel != null)
			{
				SelectionHelper helper = SelectionHelper.Create(sel, rootSite);
				startLocation = new FindCollectorEnv.LocationInfo(helper);
			}
			FindCollectorEnv.LocationInfo locationInfo = m_findEnvironment.FindNext(startLocation);
			if (locationInfo != null)
			{
				SelectionHelper selHelper = SelectionHelper.Create(rootSite);
				selHelper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor,
					locationInfo.m_location);
				selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End,
					locationInfo.m_location);
				selHelper.IchAnchor = locationInfo.m_ichMin;
				selHelper.IchEnd = locationInfo.m_ichLim;
				selHelper.SetNumberOfPreviousProps(SelectionHelper.SelLimitType.Anchor,
					locationInfo.m_cpropPrev);
				selHelper.SetNumberOfPreviousProps(SelectionHelper.SelLimitType.End,
					locationInfo.m_cpropPrev);
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, locationInfo.m_tag);
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, locationInfo.m_tag);
				m_vwselPattern = selHelper.SetSelection(rootSite, true, true,
					VwScrollSelOpts.kssoDefault);
				Debug.Assert(m_vwselPattern != null, "We need a selection after a find!");
				//if (Owner != null)
				//    Owner.Activate();
				//if (rootSite is Control)
				//    ((Control) rootSite).Focus();
				rootSite.RootBox.Activate(VwSelectionState.vssOutOfFocus);
			}
		}