SIL.FieldWorks.IText.InterlinDocForAnalysis.HandleClickSelection C# (CSharp) Method

HandleClickSelection() protected method

Handles a view selection produced by a click. Return true to suppress normal mouse down handling, indicating that an interlinear bundle has been clicked and the Sandbox moved.
protected HandleClickSelection ( IVwSelection vwselNew, bool fBundleOnly, bool fSaveGuess ) : bool
vwselNew IVwSelection
fBundleOnly bool
fSaveGuess bool if true, saves guesses; if false, skips guesses but still saves edits.
return bool
		protected virtual bool HandleClickSelection(IVwSelection vwselNew, bool fBundleOnly, bool fSaveGuess)
		{
			if (vwselNew == null)
				return false; // couldn't select a bundle!
			// The basic idea is to find the level at which we are displaying the TagAnalysis property.
			int cvsli = vwselNew.CLevels(false);
			cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it.

			// Out variables for AllTextSelInfo.
			int ihvoRoot;
			int tagTextProp;
			int cpropPrevious;
			int ichAnchor;
			int ichEnd;
			int ws;
			bool fAssocPrev;
			int ihvoEnd;
			ITsTextProps ttpBogus;
			// Main array of information retrived from sel that made combo.
			SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(vwselNew, cvsli,
				out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
				out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);

			if (tagTextProp == SegmentTags.kflidFreeTranslation || tagTextProp == SegmentTags.kflidLiteralTranslation
				|| tagTextProp == NoteTags.kflidContent)
			{
				bool fWasFocusBoxInstalled = IsFocusBoxInstalled;
				Rect oldSelLoc = GetPrimarySelRect(vwselNew);
				if (!fBundleOnly)
				{
					if (IsFocusBoxInstalled)
						FocusBox.UpdateRealFromSandbox(null, fSaveGuess, null);
					TryHideFocusBoxAndUninstall();
				}

				// If the selection resulting from the click is still valid, and we just closed the focus box, go ahead and install it;
				// continuing to process the click may not produce the intended result, because
				// removing the focus box can re-arrange things substantially (LT-9220).
				// (However, if we didn't change anything it is necesary to process it normally, otherwise, dragging
				// and shift-clicking in the free translation don't work.)
				if (!vwselNew.IsValid || !fWasFocusBoxInstalled)
					return false;
				// We have destroyed a focus box...but we may not have moved the free translation we clicked enough
				// to cause problems. If not, we'd rather do a normal click, because installing a selection that
				// the root box doesn't think is from mouse down does not allow dragging.
				Rect selLoc = GetPrimarySelRect(vwselNew);
				if (selLoc.top == oldSelLoc.top)
					return false;
				//The following line could quite possibly invalidate the selection as in the case where it creates
				//a translation prompt.
				vwselNew.Install();
				//scroll the current selection into view (don't use vwselNew, it might be invalid now)
				ScrollSelectionIntoView(this.RootBox.Selection, VwScrollSelOpts.kssoDefault);
				return true;
			}

			// Identify the analysis, and the position in m_rgvsli of the property holding it.
			// It is also possible that the analysis is the root object.
			// This is important because although we are currently displaying just an StTxtPara,
			// eventually it might be part of a higher level structure. We want to be able to
			// reproduce everything that gets us down to the analysis.
			int itagAnalysis = -1;
			for (int i = rgvsli.Length; --i >= 0; )
			{
				if (rgvsli[i].tag == SegmentTags.kflidAnalyses)
				{
					itagAnalysis = i;
					break;
				}
			}
			if (itagAnalysis < 0)
			{
				if (!fBundleOnly)
				{
					if (IsFocusBoxInstalled)
						FocusBox.UpdateRealFromSandbox(null, fSaveGuess, null);
					TryHideFocusBoxAndUninstall();
				}

				return false; // Selection is somewhere we can't handle.
			}
			int ianalysis = rgvsli[itagAnalysis].ihvo;
			Debug.Assert(itagAnalysis < rgvsli.Length - 1); // Need different approach if the analysis is the root.
			int hvoSeg = rgvsli[itagAnalysis + 1].hvo;
			var seg = Cache.ServiceLocator.GetObject(hvoSeg) as ISegment;
			Debug.Assert(seg != null);
			// If the mouse click lands on a punctuation form, move to the preceding
			// wordform (if any).  See FWR-815.
			while (seg.AnalysesRS[ianalysis] is IPunctuationForm && ianalysis > 0)
				--ianalysis;
			if (ianalysis == 0 && seg.AnalysesRS[0] is IPunctuationForm)
			{
				if (!fBundleOnly)
					TryHideFocusBoxAndUninstall();
				return false;
			}
			TriggerAnnotationSelected(new AnalysisOccurrence(seg, ianalysis), fSaveGuess);
			return true;
		}
InterlinDocForAnalysis