private void InitSandbox() { SetSandboxSize(); m_vc.LeftPadding = 0; m_rootb.Reconstruct(); using (new HoldGraphics(this)) { Rectangle rcSrcRoot; Rectangle rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); SelLevInfo[] rgvsli = new SelLevInfo[1]; //rgvsli[1].ihvo = 0; // first morpheme bundle //rgvsli[1].tag = (int)WfiAnalysis.WfiAnalysisTags.kflidMorphBundles; rgvsli[0].ihvo = 0; rgvsli[0].tag = m_tag; IVwSelection sel = null; sel = RootBox.MakeTextSelInObj(0, rgvsli.Length, rgvsli, 0, null, true, false, false, false, false); if (sel == null) { Debug.WriteLine("Could not make selection in InitSandbox"); return; // can't position it accurately. } Rect rcSec; bool fSplit, fEndBeforeAnchor; sel.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out m_rcPrimary, out rcSec, out fSplit, out fEndBeforeAnchor); } SetPadding(); SetSandboxLocation(); }
internal Rectangle GetSelLocation() { using (new HoldGraphics(this)) { Rectangle rcSrcRoot, rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); Rect rcPrimary, rcSec, rcPrimary2; bool fSplit, fEndBeforeAnchor; IVwSelection anchor = RootBox.Selection.EndPoint(false); IVwSelection end = RootBox.Selection.EndPoint(true); anchor.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out rcPrimary, out rcSec, out fSplit, out fEndBeforeAnchor); end.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out rcPrimary2, out rcSec, out fSplit, out fEndBeforeAnchor); int left = Math.Min(rcPrimary.left, rcPrimary2.left); int top = Math.Min(rcPrimary.top, rcPrimary2.top); int width = Math.Max(rcPrimary.right, rcPrimary2.right) - left; int height = Math.Max(rcPrimary.bottom, rcPrimary2.bottom) - top; return(new Rectangle(left, top, width, height)); } }
private void SetContextButtonPosition(IVwSelection sel, int ilineChoice) { Debug.Assert(sel != null || !sel.IsValid, "No selection!"); //sel.GrowToWord(); Rect rcPrimary; Rectangle rcSrcRoot; using (new HoldGraphics(this)) { Rect rcSec; bool fSplit, fEndBeforeAnchor; Rectangle rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); sel.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out rcPrimary, out rcSec, out fSplit, out fEndBeforeAnchor); } CalculateHorizContextButtonPosition(rcPrimary, rcSrcRoot); m_iLineChoice = ilineChoice; if (!Controls.Contains(m_contextButton)) { Controls.Add(m_contextButton); } }
private void SetSandboxLocation() { m_rootb.Reconstruct(); using (new HoldGraphics(this)) { Rectangle rcSrcRoot; Rectangle rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); SelLevInfo[] rgvsli = new SelLevInfo[1]; //rgvsli[1].ihvo = 0; // first morpheme bundle //rgvsli[1].tag = (int)WfiAnalysis.WfiAnalysisTags.kflidMorphBundles; rgvsli[0].ihvo = 0; rgvsli[0].tag = MeVirtualHandler.InstallMe(Cache.VwCacheDaAccessor).Tag; IVwSelection sel = null; sel = RootBox.MakeTextSelInObj(0, rgvsli.Length, rgvsli, 0, null, true, false, false, false, false); if (sel == null) { Debug.WriteLine("Could not make selection in SetSandboxLocation"); m_tryAWordSandbox.Left = 150; return; // can't position it accurately. } Rect rcPrimary, rcSec; bool fSplit, fEndBeforeAnchor; sel.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out rcPrimary, out rcSec, out fSplit, out fEndBeforeAnchor); if (m_vc.RightToLeft) { m_tryAWordSandbox.Left = rcPrimary.right - m_tryAWordSandbox.Width; m_labelWidth = m_rootb.Width - rcPrimary.right; } else { m_tryAWordSandbox.Left = rcPrimary.left; m_labelWidth = rcPrimary.left; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the selection rectangle (in printer pixels). /// </summary> /// <param name="vwsel">The selection.</param> /// <param name="vg">The VwGraphics object.</param> /// <param name="fEndBeforeAnchor"><c>true</c> if the end of the selection is before /// the anchor.</param> /// <returns>The rectangle of the selection in printer pixels.</returns> /// ------------------------------------------------------------------------------------ internal Rectangle GetSelectionRectangle(IVwSelection vwsel, IVwGraphics vg, out bool fEndBeforeAnchor) { Rectangle rcSelPrinter; if (vwsel == null) vwsel = FocusedRootBox.Selection; if (vwsel == null) { Debug.Fail("Couldn't find a selection"); fEndBeforeAnchor = false; return Rectangle.Empty; } // We pass this as source AND destination rectangle to get the selection // location relative to the whole document in printer coordinates. Rect rcSrc = new Rect(0, 0, (int)DpiXPrinter, (int)DpiYPrinter); // Main or only place the selection is (in printer coords, // relative to the rootbox!) // Secondary place if the selection is a split cursor. // true if it is split (if false, do NOT use rcSecondary, it is meaningless). // true if end of selection comes before anchor, so the BOTTOM is what // we want to be sure to see. Rect rcPrimary, rcSecondary; bool fSplit; vwsel.Location(vg, rcSrc, rcSrc, out rcPrimary, out rcSecondary, out fSplit, out fEndBeforeAnchor); rcSelPrinter = Rectangle.FromLTRB(rcPrimary.left, rcPrimary.top, rcPrimary.right, rcPrimary.bottom); int clientWidthPrinter = ConvertScreenDistanceToPrinterX( ClientRectangle.Width, DpiXScreen); int clientHeightPrinter = ConvertScreenDistanceToPrinterY( ClientRectangle.Height, DpiYScreen); if (fSplit) { // try to get the secondary in there also Rectangle rcSel2Printer = Rectangle.FromLTRB( Math.Min(rcSelPrinter.Left, rcSecondary.left), Math.Min(rcSelPrinter.Top, rcSecondary.top), Math.Max(rcSelPrinter.Right, rcSecondary.right), Math.Max(rcSelPrinter.Bottom, rcSecondary.bottom)); if (rcSel2Printer.Width <= clientWidthPrinter && rcSel2Printer.Height <= clientHeightPrinter) rcSelPrinter = rcSel2Printer; } return rcSelPrinter; }
private void SetContextButtonPosition(IVwSelection sel, int ilineChoice) { Debug.Assert(sel != null || !sel.IsValid, "No selection!"); //sel.GrowToWord(); Rect rcPrimary; Rectangle rcSrcRoot; using (new HoldGraphics(this)) { Rect rcSec; bool fSplit, fEndBeforeAnchor; Rectangle rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); sel.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out rcPrimary, out rcSec, out fSplit, out fEndBeforeAnchor); } CalculateHorizContextButtonPosition(rcPrimary, rcSrcRoot); m_iLineChoice = ilineChoice; if (!Controls.Contains(m_contextButton)) Controls.Add(m_contextButton); }
/// <summary> /// Get the primary rectangle occupied by a selection (relative to the top left of the client rectangle). /// </summary> public Rect GetPrimarySelRect(IVwSelection sel) { Rect rcPrimary; using (new HoldGraphics(this)) { Rectangle rcSrcRoot, rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); Rect rcSec; bool fSplit, fEndBeforeAnchor; sel.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out rcPrimary, out rcSec, out fSplit, out fEndBeforeAnchor); } return rcPrimary; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Scroll the selection in to the given client position. /// </summary> /// <param name="sel">The selection</param> /// <param name="dyPos">Position from top of client window where sel should be scrolled</param> /// <returns>True if the selection was scrolled into view, false if this function did /// nothing</returns> /// ------------------------------------------------------------------------------------ public bool ScrollSelectionToLocation(IVwSelection sel, int dyPos) { CheckDisposed(); if (m_rootb == null) return false; if (sel == null) sel = m_rootb.Selection; if (sel == null) return false; using (new HoldGraphics(this)) { // Put IP at top of window. MakeSelectionVisible(sel); Rectangle rcSrcRoot; Rectangle rcDstRoot; // Expand the lazy boxes 1 screen up GetCoordRects(out rcSrcRoot, out rcDstRoot); rcDstRoot.Offset(0, -ClientRectangle.Height); PrepareToDraw(rcSrcRoot, rcDstRoot); // Expand the lazy boxes 1 screen down GetCoordRects(out rcSrcRoot, out rcDstRoot); rcDstRoot.Offset(0, ClientRectangle.Height); PrepareToDraw(rcSrcRoot, rcDstRoot); // Get the difference between where we want the selection to be and its // current position Rect rcPrimary; Rect rcSecondary; bool fSplit; bool fEndBeforeAnchor; GetCoordRects(out rcSrcRoot, out rcDstRoot); sel.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out rcPrimary, out rcSecondary, out fSplit, out fEndBeforeAnchor); int difference = dyPos - rcPrimary.top; // Now move the scroll position so the IP will be where we want it. ScrollPosition = new Point(-ScrollPosition.X, -ScrollPosition.Y - difference); } // If the selection is still not visible (which should only be the case if // we're at the end of the view), just take whatever MakeSelectionVisible() // gives us). if (!IsSelectionVisible(sel) && dyPos >= 0 && dyPos <= ClientHeight) MakeSelectionVisible(sel); //Update(); return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the rectangle of the selection. If it is a split selection we combine the /// two rectangles. /// </summary> /// <param name="vwsel">Selection</param> /// <param name="rcIdeal">Contains the rectangle of the selection on return</param> /// <param name="fEndBeforeAnchor">[Out] <c>true</c> if the end is before the anchor, /// otherwise <c>false</c>.</param> /// ------------------------------------------------------------------------------------ protected internal void SelectionRectangle(IVwSelection vwsel, out Rectangle rcIdeal, out bool fEndBeforeAnchor) { Debug.Assert(vwsel != null); Debug.Assert(m_graphicsManager.VwGraphics != null); Rect rcPrimary; Rect rcSecondary; bool fSplit; Rectangle rcSrcRoot; Rectangle rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); vwsel.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out rcPrimary, out rcSecondary, out fSplit, out fEndBeforeAnchor); rcIdeal = rcPrimary; if (fSplit) { rcIdeal = Rectangle.Union(rcIdeal, rcSecondary); if ((AutoScroll && VScroll && rcIdeal.Height > ClientHeight) || (DoAutoHScroll && rcIdeal.Width > ClientRectangle.Width)) { rcIdeal = rcPrimary; // Revert to just showing main IP. } } }
// We don't need AfVwScrollWnd::ScrollBy - can be done directly in .NET /// ----------------------------------------------------------------------------------- /// <summary> /// Finds the distance between the scroll position and the IP (i.e. the distance /// between the top of the window and the IP). /// </summary> /// <param name="sel">The selection used to get the IP's location. If /// this value is null, the rootsite's current selection will be used.</param> /// ----------------------------------------------------------------------------------- public int IPDistanceFromWindowTop(IVwSelection sel) { CheckDisposed(); if (sel == null && m_rootb != null) sel = m_rootb.Selection; if (sel == null) return 0; using (new HoldGraphics(this)) { Rectangle rcSrcRoot; Rectangle rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); Rect rcPrimary; Rect rcSecondary; bool fSplit; bool fEndBeforeAnchor; sel.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out rcPrimary, out rcSecondary, out fSplit, out fEndBeforeAnchor); return rcPrimary.top; } }