Ejemplo n.º 1
0
        /// <summary>
        /// Update the new selection. This is called by rule formula view when selection changes.
        /// </summary>
        /// <param name="vwselNew">The new selection.</param>
        private void UpdateSelection(IVwSelection vwselNew)
        {
            CheckDisposed();
            SelectionHelper sel = SelectionHelper.Create(vwselNew, this);

            if (sel != null)
            {
                object ctxt = m_patternControl.GetContext(sel);
                // if context is null then we are trying to select outside of a single context
                if (ctxt == null)
                {
                    if (sel.IsRange)
                    {
                        // ensure that a range selection only occurs within one context
                        object topCtxt    = m_patternControl.GetContext(sel, SelectionHelper.SelLimitType.Top);
                        object bottomCtxt = m_patternControl.GetContext(sel, SelectionHelper.SelLimitType.Bottom);
                        var    limit      = SelectionHelper.SelLimitType.Top;
                        if (topCtxt != null)
                        {
                            limit = SelectionHelper.SelLimitType.Top;
                            ctxt  = topCtxt;
                        }
                        else if (bottomCtxt != null)
                        {
                            limit = SelectionHelper.SelLimitType.Bottom;
                            ctxt  = bottomCtxt;
                        }

                        if (ctxt != null)
                        {
                            IVwSelection newSel = SelectCell(ctxt, limit == SelectionHelper.SelLimitType.Bottom, false);
                            sel.ReduceToIp(limit);
                            IVwSelection otherSel = sel.SetSelection(this, false, false);
                            if (sel.Selection.EndBeforeAnchor)
                            {
                                RootBox.MakeRangeSelection(limit == SelectionHelper.SelLimitType.Top ? newSel : otherSel,
                                                           limit == SelectionHelper.SelLimitType.Top ? otherSel : newSel, true);
                            }
                            else
                            {
                                RootBox.MakeRangeSelection(limit == SelectionHelper.SelLimitType.Top ? otherSel : newSel,
                                                           limit == SelectionHelper.SelLimitType.Top ? newSel : otherSel, true);
                            }
                        }
                    }
                }
                else
                {
                    AdjustSelection(sel);
                }
            }
        }
Ejemplo n.º 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();
                }
            }
        }