Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Goes to the top (beginning of the main stream of the first division) of the current
        /// page.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Forms.KeyEventArgs"/> instance
        /// containing the event data.</param>
        /// <param name="graphics">The graphics.</param>
        /// ------------------------------------------------------------------------------------
        protected void GoToPageTopOrBottom(KeyEventArgs e, IVwGraphics graphics)
        {
            bool fTop = (e.KeyCode == Keys.PageUp);

            // Find the page we're on
            int          iDiv;
            bool         fEndBeforeAnchor;
            int          dyPageScreen;
            IVwSelection vwsel = PubControl.FocusedRootBox.Selection;

            if (vwsel == null || !vwsel.IsValid)
            {
                return;
            }

            Rectangle rcSel = PubControl.GetSelectionRectangle(vwsel, graphics, out fEndBeforeAnchor);
            // JohnT: I think the idea here is that if it's an IP we want it's center, otherwise, we want
            // the endpoint.
            int y = vwsel.IsRange ? (fEndBeforeAnchor ? rcSel.Top : rcSel.Bottom) :
                    (rcSel.Bottom + rcSel.Top) / 2;
            int x = vwsel.IsRange ? (fEndBeforeAnchor ? rcSel.Left : rcSel.Right) :
                    (rcSel.Left + rcSel.Right) / 2;
            bool layedOutPage;
            Page page = PubControl.PageFromPrinterY(x, y, !fTop, PubControl.FocusedStream,
                                                    out dyPageScreen, out iDiv, out layedOutPage);

            if (iDiv < 0 || iDiv >= PubControl.Divisions.Count || page == null)
            {
                return;
            }

            // Destroy the current selection
            PubControl.Divisions[iDiv].MainRootBox.DestroySelection();

            // Now we know the page, so we can put the IP on the first/last line of this page.
            IVwSelection sel = fTop ? page.TopOfPageSelection.Selection :
                               page.BottomOfPageSelection.Selection;

            sel.Install();
            sel.RootBox.Activate(VwSelectionState.vssEnabled);
            PubControl.FocusedRootBox = sel.RootBox;
            PubControl.ScrollSelectionIntoView(sel, VwScrollSelOpts.kssoDefault);
        }
Example #2
0
        /// <summary>
        /// Adjusts the selection.
        /// </summary>
        /// <param name="sel">The selection.</param>
        private void AdjustSelection(SelectionHelper sel)
        {
            IVwSelection anchorSel;
            int          curHvo, curIch, curTag;

            // anchor IP
            if (!GetSelectionInfo(sel, SelectionHelper.SelLimitType.Anchor, out anchorSel, out curHvo, out curIch, out curTag))
            {
                return;
            }

            IVwSelection endSel;
            int          curEndHvo, curEndIch, curEndTag;

            // end IP
            if (!GetSelectionInfo(sel, SelectionHelper.SelLimitType.End, out endSel, out curEndHvo, out curEndIch, out curEndTag))
            {
                return;
            }

            // create range selection
            IVwSelection vwSel = RootBox.MakeRangeSelection(anchorSel, endSel, false);

            if (vwSel != null)
            {
                ITsString tss;
                int       ws;
                bool      prev;

                // only install the adjusted selection if it is different then the current selection
                int wholeHvo, wholeIch, wholeTag, wholeEndHvo, wholeEndIch, wholeEndTag;
                vwSel.TextSelInfo(false, out tss, out wholeIch, out prev, out wholeHvo, out wholeTag, out ws);
                vwSel.TextSelInfo(true, out tss, out wholeEndIch, out prev, out wholeEndHvo, out wholeEndTag, out ws);

                if (wholeHvo != curHvo || wholeEndHvo != curEndHvo || wholeIch != curIch || wholeEndIch != curEndIch ||
                    wholeTag != curTag || wholeEndTag != curEndTag)
                {
                    vwSel.Install();
                }
            }
        }
		/// <summary>
		/// 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.
		/// </summary>
		/// <param name="vwselNew"></param>
		/// <param name="fBundleOnly"></param>
		/// <param name="fSaveGuess">if true, saves guesses; if false, skips guesses but still saves edits.</param>
		/// <returns></returns>
		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;
		}
Example #4
0
        /// <summary>
        /// If we are in ReadOnlySelect mode, intercept the click, and select the appropriate row
        /// without installing a normal selection.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            //If XmlBrouseView did not receive a mouse down event then we do not want to
            //do anything on the mouseUp because the mouseUp would have come from clicking
            //somewhere else. LT-8939
            if (!m_fMouseUpEnabled)
            {
                return;
            }

            try
            {
                if (m_selectedIndex == -1)
                {
                    return;                     // Can't do much in an empty list, so quit.
                }
                m_fHandlingMouseUp = true;
#pragma warning disable 219
                int oldSelectedIndex = m_selectedIndex;
#pragma warning restore 219

                // Note all the stuff we might want to know about what was clicked that we will
                // use later. We want to get this now before anything changes, because there can
                // be scrolling effects from converting dummy objects to real.
                IVwSelection vwsel            = MakeSelectionAt(e);
                int          newSelectedIndex = GetRowIndexFromSelection(vwsel, true);
                // If we're changing records, we need to do some tricks to keep the selection in the place
                // clicked and the focus here. Save the information we will need.
                SelectionHelper clickSel = null;
                if (newSelectedIndex != SelectedIndex && vwsel != null && SelectionHelper.IsEditable(vwsel))
                {
                    clickSel = SelectionHelper.Create(vwsel, this);
                }
                ITsString tssWord      = null;    // word clicked for click copy
                ITsString tssSource    = null;    // whole source string of clicked cell for click copy
                int       hvoNewSelRow = 0;       // hvo of new selected row (only for click copy)
                int       ichStart     = 0;       // of tssWord in tssSource
                if (ClickCopy != null && e.Button == MouseButtons.Left && newSelectedIndex >= 0)
                {
                    if (vwsel != null && vwsel.SelType == VwSelType.kstText)
                    {
                        int icol = vwsel.get_BoxIndex(false, 3);
                        if (icol != Vc.OverrideAllowEditColumn + 1)
                        {
                            IVwSelection vwSelWord = vwsel.GrowToWord();
                            // GrowToWord() can return a null -- see LT-9163 and LT-9349.
                            if (vwSelWord != null)
                            {
                                vwSelWord.GetSelectionString(out tssWord, " ");
                                tssWord      = StripTrailingNewLine(tssWord);
                                hvoNewSelRow = m_sda.get_VecItem(m_hvoRoot, m_fakeFlid,
                                                                 newSelectedIndex);
                                int  hvoObj, tag, ws;
                                bool fAssocPrev;
                                vwSelWord.TextSelInfo(false, out tssSource, out ichStart, out fAssocPrev, out hvoObj,
                                                      out tag, out ws);
                            }
                        }
                    }
                }

                // We need to manually change the index for ReadOnly views.
                // SimpleRootSite delegates RightMouseClickEvent to our RecordBrowseView parent,
                // which also makes the selection for us..
                if (ReadOnlySelect && e.Button != MouseButtons.Right)
                {
                    if (this.m_xbvvc.HasSelectColumn && e.X < m_xbvvc.SelectColumnWidth)
                    {
                        base.OnMouseUp(e);                         // allows check box to operate.
                    }
                }
                else
                {
                    // If we leave this set, the base method call's side effects like updating the WS combo
                    // don't happen.
                    m_fHandlingMouseUp = false;
                    base.OnMouseUp(e);                     // normal behavior.
                    m_fHandlingMouseUp = true;
                }
                SetSelectedIndex(newSelectedIndex);
                if (tssWord != null)
                {
                    // We're doing click copies; generate an event.
                    // Do this AFTER other actions which may change the current line.
                    ClickCopy(this, new ClickCopyEventArgs(tssWord, hvoNewSelRow, tssSource, ichStart));
                }
                if (clickSel != null)
                {
                    IVwSelection finalSel = null;
                    // There seem to be some cases where the selection helper can't restore the selection.
                    // One that came up in FWR-3666 was clicking on a check box.
                    // If we can't re-establish an editiable selection just let the default behavior continue.
                    try
                    {
                        finalSel = clickSel.MakeRangeSelection(RootBox, false);
                    }
                    catch (Exception)
                    {
                    }
                    if (finalSel != null && SelectionHelper.IsEditable(finalSel))
                    {
                        finalSel.Install();
                        FocusMe();
                    }
                }
            }
            finally
            {
                m_fHandlingMouseUp = false;
                m_fMouseUpEnabled  = false;
            }
        }
Example #5
0
		/// <summary>
		/// 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.
		/// </summary>
		/// <param name="vwselNew"></param>
		/// <param name="fBundleOnly"></param>
		/// <param name="fSaveGuess">if true, saves guesses; if false, skips guesses but still saves edits.</param>
		/// <returns></returns>
		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 == (int)CmAnnotation.CmAnnotationTags.kflidComment)
			{
				bool fWasFocusBoxInstalled = IsFocusBoxInstalled;
				Rect oldSelLoc = GetPrimarySelRect(vwselNew);
				if (!fBundleOnly)
					DestroyFocusBoxAndSetFocus(fSaveGuess);

				// 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;
				vwselNew.Install();
				return true;
			}

			// Identify the twfic, and the position in m_rgvsli of the property holding it.
			// It is also possible that the twfic 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 twfic.
			int itagAnalysis = -1;
			for (int i = rgvsli.Length; --i >= 0; )
			{
				if (rgvsli[i].tag == TagAnalysis)
				{
					itagAnalysis = i;
					break;
				}
			}
			if (itagAnalysis < 0)
			{
				// Go ahead and hide the focus box, since it could try to still the selection back (cf. LT-7968)
				if (!fBundleOnly)
					DestroyFocusBoxAndSetFocus(fSaveGuess);
				return false; // Selection is somewhere we can't handle.
			}
			int hvoAnalysis = rgvsli[itagAnalysis].hvo; // The current analyis object.
			Debug.Assert(itagAnalysis < rgvsli.Length - 1); // Need different approach if the twfic is the root.
			int hvoAnnotation = rgvsli[itagAnalysis + 1].hvo;

			// Launch a combo on the base line.
			//			if (tagTextProp == (int)WfiWordform.WfiWordformTags.kflidForm)
			//			{
			//				// First line: display the in-place combo.
			//				analysisHandler = new ChooseAnalysisHandler(m_fdoCache, hvoSrc, hvoAnalysis);
			//				analysisHandler.AnalysisChosen += analysisChosenDelegate;
			//				analysisHandler.SetupCombo();
			//				analysisHandler.Show(m_site, m_vwselNew);
			//				return;
			//			}

			// Enhance JohnT: if click was on word gloss line, put cursor there instead of default.
			TriggerAnnotationSelected(hvoAnnotation, hvoAnalysis, fSaveGuess);
			//			new HandleSelectionChangeMethod(vwselNew, this)
			//				.Run(ref m_analysisHandler, m_vc.ListManager,
			//					new EventHandler(m_analysisHandler_AnalysisChosen), new AdvanceWordEventHandler(scope_AdvanceWord));
			return true;
		}