Exemple #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);
        }
Exemple #2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Special handling for Ctrl-Home/End and scrolling the selection into view
 /// </summary>
 /// <param name="e"></param>
 /// <param name="ss"></param>
 /// ------------------------------------------------------------------------------------
 protected override void HandleKeyDown(KeyEventArgs e, VwShiftStatus ss)
 {
     // We dealt with Ctrl-Home/End already in OnKeyDown, so we just make sure that the
     // selection is visible here.
     PubControl.ScrollSelectionIntoView(null, VwScrollSelOpts.kssoDefault);
 }
Exemple #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// User pressed a key.
        /// </summary>
        /// <param name="e"></param>
        /// <returns>
        ///     <c>true</c> if we handled the key, <c>false</c> otherwise (e.g. we're
        /// already at the end of the rootbox and the user pressed down arrow key).
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public override bool OnKeyDown(KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown) &&
                ((e.Modifiers & Keys.Control) == Keys.Control))
            {
                IVwGraphics vg = PubControl.PrinterGraphics;
                try
                {
                    GoToPageTopOrBottom(e, vg);
                }
                finally
                {
                    PubControl.ReleaseGraphics(vg);
                }
            }
            else if ((e.KeyCode == Keys.Home || e.KeyCode == Keys.End) && (e.Modifiers & Keys.Control) != 0)
            {
                // Ctrl-Home needs to go to beginning of first division
                // Ctrl-End needs to go to end of last division
                PubControl.FocusedStream = PubControl.Divisions[
                    (e.KeyCode == Keys.Home) ? 0 : PubControl.Divisions.Count - 1].MainLayoutStream;

                if (PubControl.FocusedRootBox.Selection == null)
                {
                    PubControl.FocusedRootBox.MakeSimpleSel(e.KeyCode == Keys.Home, true, false, true);
                }

                using (new WaitCursor(PubControl.ParentForm))
                {
                    IVwGraphics vg = PubControl.PrinterGraphics;
                    try
                    {
                        while (PubControl.LayoutToPageIfNeeded((e.KeyCode == Keys.Home) ? 0 :
                                                               PubControl.Pages.Count - 1, vg.XUnitsPerInch, vg.YUnitsPerInch))
                        {
                        }
                    }
                    finally
                    {
                        PubControl.ReleaseGraphics(vg);
                    }
                }
                base.OnKeyDown(e);
            }
            else
            {
                if (!base.OnKeyDown(e))
                {
                    // this means that we are already at the beginning or end of the
                    // division. However, if we have more divisions we try there...
                    int iOldDiv = PubControl.DivisionIndexForMainStream(PubControl.FocusedStream);
                    if (iOldDiv < 0)
                    {
                        return(true);
                    }

                    int  iNewDiv;
                    bool fUpwards = false;
                    Keys keyCode  = e.KeyCode;
                    if (keyCode == Keys.Left)
                    {
                        StVc vc = ViewConstructor as StVc;
                        keyCode = (vc != null && vc.RightToLeft) ? Keys.Down : Keys.Up;
                    }
                    else if (keyCode == Keys.Right)
                    {
                        StVc vc = ViewConstructor as StVc;
                        keyCode = (vc != null && vc.RightToLeft) ? Keys.Up : Keys.Down;
                    }
                    switch (keyCode)
                    {
                    case Keys.PageUp:
                    case Keys.Up:
                        iNewDiv  = iOldDiv - 1;
                        fUpwards = true;
                        break;

                    case Keys.Down:
                    case Keys.PageDown:
                        iNewDiv = iOldDiv + 1;
                        break;

                    default:
                        return(false);
                    }
                    if (iNewDiv < 0 || iNewDiv >= PubControl.Divisions.Count)
                    {
                        return(true);
                    }

                    PubControl.FocusedStream = PubControl.Divisions[iNewDiv].MainLayoutStream;
                    // we better destroy the selection or we end up somewhere in the
                    // middle of the rootbox if the selection was previously there.
                    if (fUpwards)
                    {
                        PubControl.FocusedRootBox.MakeSimpleSel(false, true, false, true);
                    }
                    else
                    {
                        PubControl.FocusedRootBox.MakeSimpleSel(true, true, false, true);
                    }

                    if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right ||
                        e.KeyCode == Keys.Up || e.KeyCode == Keys.Left)
                    {
                        // for Down and Up keys we're still not at the right position,
                        // but at least in the correct line.
                        PubControl.ScrollSelectionIntoView(null, VwScrollSelOpts.kssoDefault);
                    }
                    else
                    {
                        if (!base.OnKeyDown(e))
                        {
                            PubControl.FocusedStream = PubControl.Divisions[iOldDiv].MainLayoutStream;
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }