Example #1
0
        // Token: 0x0600650D RID: 25869 RVA: 0x001C5B40 File Offset: 0x001C3D40
        private static bool DumpFlowDocumentView(XmlTextWriter writer, UIElement element, bool uiElementsOnly)
        {
            FlowDocumentView flowDocumentView = element as FlowDocumentView;
            IScrollInfo      scrollInfo       = flowDocumentView;

            if (scrollInfo.ScrollOwner != null)
            {
                Size size = new Size(scrollInfo.ExtentWidth, scrollInfo.ExtentHeight);
                if (DoubleUtil.AreClose(size, element.DesiredSize))
                {
                    LayoutDump.DumpSize(writer, "Extent", size);
                }
                Point point = new Point(scrollInfo.HorizontalOffset, scrollInfo.VerticalOffset);
                if (!DoubleUtil.IsZero(point.X) || !DoubleUtil.IsZero(point.Y))
                {
                    LayoutDump.DumpPoint(writer, "Offset", point);
                }
            }
            FlowDocumentPage documentPage     = flowDocumentView.Document.BottomlessFormatter.DocumentPage;
            GeneralTransform generalTransform = documentPage.Visual.TransformToAncestor(flowDocumentView);
            Point            point2           = new Point(0.0, 0.0);

            generalTransform.TryTransform(point2, out point2);
            if (!DoubleUtil.IsZero(point2.X) && !DoubleUtil.IsZero(point2.Y))
            {
                LayoutDump.DumpPoint(writer, "PagePosition", point2);
            }
            LayoutDump.DumpFlowDocumentPage(writer, documentPage);
            return(false);
        }
Example #2
0
        // Token: 0x06006FBE RID: 28606 RVA: 0x00201ED0 File Offset: 0x002000D0
        private double GetYOffsetAtNextPage(double offset, int count, out int pagesMoved)
        {
            double num = offset;

            pagesMoved = 0;
            if (this._owner is IScrollInfo && ((IScrollInfo)this._owner).ScrollOwner != null)
            {
                IScrollInfo scrollInfo     = (IScrollInfo)this._owner;
                double      viewportHeight = scrollInfo.ViewportHeight;
                double      extentHeight   = scrollInfo.ExtentHeight;
                if (count > 0)
                {
                    while (pagesMoved < count)
                    {
                        if (!DoubleUtil.LessThanOrClose(offset + viewportHeight, extentHeight))
                        {
                            break;
                        }
                        num += viewportHeight;
                        pagesMoved++;
                    }
                }
                else
                {
                    while (Math.Abs(pagesMoved) < Math.Abs(count) && DoubleUtil.GreaterThanOrClose(offset - viewportHeight, 0.0))
                    {
                        num -= viewportHeight;
                        pagesMoved--;
                    }
                }
            }
            return(num);
        }
Example #3
0
        protected override void OnContentChanged(UIElement oldContent, UIElement newContent)
        {
            var oldScrollContentPresenter = oldContent as ScrollContentPresenter;

            if (oldScrollContentPresenter != null)
            {
                oldScrollContentPresenter.Content.Parent = null;
            }

            var newScrollInfo = newContent as IScrollInfo;

            if (newScrollInfo != null)
            {
                this.scrollInfo = newScrollInfo;

                if (oldContent != null && this.isInsertingScrollContentPresenter)
                {
                    ((ScrollContentPresenter)newContent).Content = oldContent;
                }

                this.isInsertingScrollContentPresenter = false;
            }
            else
            {
                this.isInsertingScrollContentPresenter = true;
                this.Content = new ScrollContentPresenter();
            }
        }
        private double GetViewPortWidth()
        {
            double viewPortWidth = 0;

            IScrollInfo vStackPanel = null;

            // Viewport is only required when UI Virtualization is on
            if (this.IsVirtualizing)
            {
                try
                {
                    vStackPanel = this.DataGridContext.DataGridControl.ItemsHost as IScrollInfo;
                }
                catch (Exception)
                {
                    // Ignore exceptions since it may be called before the ItemsHost Template is applied
                }

                if (vStackPanel != null)
                {
                    // Get the ViewPortWidth
                    viewPortWidth = vStackPanel.ViewportWidth;
                }

                // We use the HeaderFooterItem width when greater than the viewport width
                if ((viewPortWidth == 0) || (this.DataGridContext.FixedHeaderFooterViewPortSize.Width > viewPortWidth))
                {
                    viewPortWidth = this.DataGridContext.FixedHeaderFooterViewPortSize.Width;
                }
            }

            return(viewPortWidth);
        }
Example #5
0
        private double GetViewportWidth()
        {
            // Viewport is only required when UI Virtualization is on.
            if (this.VirtualizationMode == ColumnVirtualizationMode.None)
            {
                return(0d);
            }

            IScrollInfo scrollInfo = null;

            try
            {
                var dataGridContext = this.DataGridContext;
                if (dataGridContext != null)
                {
                    scrollInfo = this.DataGridContext.DataGridControl.ItemsHost as IScrollInfo;
                }
            }
            catch (Exception)
            {
                // Ignore exceptions since it may be called before the ItemsHost Template is applied
            }

            double width = (scrollInfo != null) ? scrollInfo.ViewportWidth : 0d;

            // We use the HeaderFooterItem width when greater than the viewport width.
            return(Math.Max(width, this.DataGridContext.FixedHeaderFooterViewPortSize.Width));
        }
Example #6
0
        void ConfigureContentScrollFacility()
        {
            ScrollContentPresenter scp = FindContentPresenter() as ScrollContentPresenter;

            if (scp == null)
            {
                return;
            }
            scp.HorizontalFitToSpace = HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled;
            scp.VerticalFitToSpace   = VerticalScrollBarVisibility == ScrollBarVisibility.Disabled;

            if (_attachedScrollInfo != null)
            {
                _attachedScrollInfo.Scrolled -= OnScrollInfoScrolled;
            }
            IScrollInfo scrollInfo = FindScrollControl();

            if (_attachedScrollInfo != null && _attachedScrollInfo != scrollInfo)
            {
                _attachedScrollInfo.DoScroll = false;
            }
            if (scrollInfo == null)
            {
                _attachedScrollInfo = null;
                return;
            }
            scrollInfo.DoScroll           = true;
            _attachedScrollInfo           = scrollInfo;
            _attachedScrollInfo.Scrolled += OnScrollInfoScrolled;
        }
Example #7
0
        /// <summary>
        /// Scrolls to the specified line/column.
        /// This method requires that the TextEditor was already assigned a size (WPF layout must have run prior).
        /// </summary>
        /// <param name="line">Line to scroll to.</param>
        /// <param name="column">Column to scroll to (important if wrapping is 'on', and for the horizontal scroll position).</param>
        /// <param name="yPositionMode">The mode how to reference the Y position of the line.</param>
        /// <param name="referencedVerticalViewPortOffset">Offset from the top of the viewport to where the referenced line/column should be positioned.</param>
        /// <param name="minimumScrollFraction">The minimum vertical and/or horizontal scroll offset, expressed as fraction of the height or width of the viewport window, respectively.</param>
        public void ScrollTo(int line, int column, VisualYPosition yPositionMode, double referencedVerticalViewPortOffset, double minimumScrollFraction)
        {
            TextView     textView = textArea.TextView;
            TextDocument document = textView.Document;

            if (scrollViewer != null && document != null)
            {
                if (line < 1)
                {
                    line = 1;
                }
                if (line > document.LineCount)
                {
                    line = document.LineCount;
                }

                IScrollInfo scrollInfo = textView;
                if (!scrollInfo.CanHorizontallyScroll)
                {
                    // Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
                    // to the correct position.
                    // This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
                    VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
                    double     remainingHeight = referencedVerticalViewPortOffset;

                    while (remainingHeight > 0)
                    {
                        DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
                        if (prevLine == null)
                        {
                            break;
                        }
                        vl = textView.GetOrConstructVisualLine(prevLine);
                        remainingHeight -= vl.Height;
                    }
                }

                Point  p           = textArea.TextView.GetVisualPosition(new TextViewPosition(line, Math.Max(1, column)), yPositionMode);
                double verticalPos = p.Y - referencedVerticalViewPortOffset;
                if (Math.Abs(verticalPos - scrollViewer.VerticalOffset) > minimumScrollFraction * scrollViewer.ViewportHeight)
                {
                    scrollViewer.ScrollToVerticalOffset(Math.Max(0, verticalPos));
                }
                if (column > 0)
                {
                    if (p.X > scrollViewer.ViewportWidth - Caret.MinimumDistanceToViewBorder * 2)
                    {
                        double horizontalPos = Math.Max(0, p.X - scrollViewer.ViewportWidth / 2);
                        if (Math.Abs(horizontalPos - scrollViewer.HorizontalOffset) > minimumScrollFraction * scrollViewer.ViewportWidth)
                        {
                            scrollViewer.ScrollToHorizontalOffset(horizontalPos);
                        }
                    }
                    else
                    {
                        scrollViewer.ScrollToHorizontalOffset(0);
                    }
                }
            }
        }
Example #8
0
        protected override void OnMouseWheel(MouseWheelEventArgs e)
        {
            // migration from OnMouseWheel(int numDetents)
            // - no need to check if mouse is over
            // - no need to call base class

            IScrollViewerFocusSupport svfs = FindScrollControl() as IScrollViewerFocusSupport;

            if (svfs == null)
            {
                return;
            }

            int scrollByLines = SystemInformation.MouseWheelScrollLines; // Use the system setting as default.

            IScrollInfo scrollInfo = svfs as IScrollInfo;

            if (scrollInfo != null && scrollInfo.NumberOfVisibleLines != 0) // If ScrollControl can shown less items, use this as limit.
            {
                scrollByLines = scrollInfo.NumberOfVisibleLines;
            }

            int numLines = e.NumDetents * scrollByLines;

            if (numLines < 0)
            {
                svfs.ScrollDown(-1 * numLines);
            }
            else if (numLines > 0)
            {
                svfs.ScrollUp(numLines);
            }
        }
Example #9
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            ScrollViewer sv = TemplateOwner as ScrollViewer;

            if (sv == null)
            {
                return;
            }

            IScrollInfo info = Content as IScrollInfo;

            if (info == null)
            {
                var presenter = Content as ItemsPresenter;
                if (presenter != null)
                {
                    if (presenter._elementRoot == null)
                    {
                        presenter.ApplyTemplate();
                    }
                    info = presenter._elementRoot as IScrollInfo;
                }
            }
            info = info ?? this;
            info.CanHorizontallyScroll  = sv.HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled;
            info.CanVerticallyScroll    = sv.VerticalScrollBarVisibility != ScrollBarVisibility.Disabled;
            info.ScrollOwner            = sv;
            info.ScrollOwner.ScrollInfo = info;
            sv.InvalidateScrollInfo();
        }
Example #10
0
        protected virtual void OnActiveLayoutChanged(DependencyPropertyChangedEventArgs e)
        {
            if (_currentLayoutPanel != null)
            {
                _currentLayoutPanel.DeactivateLayout();
            }
            _currentLayoutPanel = e.NewValue as AnimationPanel;
            if (_currentLayoutPanel != null)
            {
                IScrollInfo info = _currentLayoutPanel as IScrollInfo;
                if (info != null && info.ScrollOwner != null)
                {
                    info.ScrollOwner.InvalidateScrollInfo();
                }

                _currentLayoutPanel.ActivateLayout();
            }

            this.RaiseActiveLayoutChangedEvent();
            this.Dispatcher.BeginInvoke(
                DispatcherPriority.Normal,
                (ThreadStart) delegate()
            {
                this.UpdateSwitchTemplate();
            });
        }
Example #11
0
        /// <summary>
        /// Translate the target object to the given x-y positions.
        /// </summary>
        /// <param name="x">The x-cordinate</param>
        /// <param name="y">The y-coordinate</param>
        private void Translate(double x, double y)
        {
            IScrollInfo si = _target as IScrollInfo;

            if (si != null)
            {
                // If the target object is smaller than the current viewport size then ignore this request.
                Size s = this.ContainerSize;
                if (_target.ActualWidth <= s.Width && _target.ActualHeight <= s.Height)
                {
                    x = y = 0;
                }
            }
            if (x > 0)
            {
                x = 0;
            }
            if (y > 0)
            {
                y = 0;
            }

            _translate.X = _offset.X = x;
            _translate.Y = _offset.Y = y;

            // focus rectangles may need to be repainted.
            _target.InvalidateVisual();
        }
Example #12
0
            public void Initialize(IMenuItemContext context, ContextMenu menu)
            {
                var teCtrl = (TextEditorControl)context.CreatorObject.Object;

                if (context.OpenedFromKeyboard)
                {
                    IScrollInfo scrollInfo = teCtrl.TextEditor.TextArea.TextView;
                    var         pos        = teCtrl.TextEditor.TextArea.TextView.GetVisualPosition(teCtrl.TextEditor.TextArea.Caret.Position, VisualYPosition.TextBottom);
                    pos = new Point(pos.X - scrollInfo.HorizontalOffset, pos.Y - scrollInfo.VerticalOffset);

                    menu.HorizontalOffset = pos.X;
                    menu.VerticalOffset   = pos.Y;
                    ContextMenuService.SetPlacement(teCtrl, PlacementMode.Relative);
                    ContextMenuService.SetPlacementTarget(teCtrl, teCtrl.TextEditor.TextArea.TextView);
                    menu.Closed += (s, e2) => {
                        teCtrl.ClearValue(ContextMenuService.PlacementProperty);
                        teCtrl.ClearValue(ContextMenuService.PlacementTargetProperty);
                    };
                }
                else
                {
                    teCtrl.ClearValue(ContextMenuService.PlacementProperty);
                    teCtrl.ClearValue(ContextMenuService.PlacementTargetProperty);
                }
            }
Example #13
0
        // Token: 0x060072C7 RID: 29383 RVA: 0x0020F7F0 File Offset: 0x0020D9F0
        internal static void BringRectIntoViewMinimally(ITextView textView, Rect rect)
        {
            IScrollInfo scrollInfo = textView.RenderScope as IScrollInfo;

            if (scrollInfo != null)
            {
                Rect rect2 = new Rect(scrollInfo.HorizontalOffset, scrollInfo.VerticalOffset, scrollInfo.ViewportWidth, scrollInfo.ViewportHeight);
                rect.X += rect2.X;
                rect.Y += rect2.Y;
                double num  = ScrollContentPresenter.ComputeScrollOffsetWithMinimalScroll(rect2.Left, rect2.Right, rect.Left, rect.Right);
                double num2 = ScrollContentPresenter.ComputeScrollOffsetWithMinimalScroll(rect2.Top, rect2.Bottom, rect.Top, rect.Bottom);
                scrollInfo.SetHorizontalOffset(num);
                scrollInfo.SetVerticalOffset(num2);
                FrameworkElement frameworkElement = FrameworkElement.GetFrameworkParent(textView.RenderScope) as FrameworkElement;
                if (frameworkElement != null)
                {
                    if (scrollInfo.ViewportWidth > 0.0)
                    {
                        rect.X -= num;
                    }
                    if (scrollInfo.ViewportHeight > 0.0)
                    {
                        rect.Y -= num2;
                    }
                    frameworkElement.BringIntoView(rect);
                    return;
                }
            }
            else
            {
                ((FrameworkElement)textView.RenderScope).BringIntoView(rect);
            }
        }
        private IScrollInfo delegateScrollInfo; // one of innerScrollInfo or Content's implementation (when CanContentScroll)

        public ScrollContentPresenter()
        {
            innerScrollInfo    = new InnerScrollInfo();
            delegateScrollInfo = innerScrollInfo;

            AdornerLayer = new AdornerLayer();
            AddVisualChild(AdornerLayer);
        }
        public ScrollContentPresenter()
        {
            innerScrollInfo = new InnerScrollInfo();
            delegateScrollInfo = innerScrollInfo;

            AdornerLayer = new AdornerLayer();
            AddVisualChild(AdornerLayer);
        }
Example #16
0
        protected void UpdateCanScroll()
        {
            IScrollInfo si = _itemsHostPanel as IScrollInfo;

            if (si != null)
            {
                si.DoScroll = _doScroll;
            }
        }
Example #17
0
        protected void DetachScrolling()
        {
            IScrollInfo si = _itemsHostPanel as IScrollInfo;

            if (si != null)
            {
                si.Scrolled -= OnItemsPanelScrolled; // Repeat the Scrolled event to our subscribers
            }
        }
Example #18
0
        private static void OnActualViewboxChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            (d as ZoomableCanvas)?.InvalidateReality();
            IScrollInfo scrollInfo = d as IScrollInfo;

            if (scrollInfo != null && scrollInfo.ScrollOwner != null)
            {
                scrollInfo.ScrollOwner.InvalidateScrollInfo();
            }
        }
Example #19
0
        private static void OnScrollOffsetChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            PreviewPanelBase ppanel = obj as PreviewPanelBase;

            if (ppanel != null && ppanel._scroll != null)
            {
                ScrollContentPresenter scp = UITools.FindVisualChild <ScrollContentPresenter>(ppanel._scroll);
                Panel       vsp            = UITools.FindVisualChild <Panel>(scp);
                IScrollInfo isi            = (IScrollInfo)vsp;
                isi.SetHorizontalOffset(ppanel.ScrollOffset);
            }
        }
        void IScrollInfo.PageUp()
        {
            IScrollInfo realImplementation = Content as IScrollInfo;

            if (realImplementation != null)
            {
                realImplementation.PageUp();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
        void IScrollInfo.MouseWheelRight()
        {
            IScrollInfo realImplementation = Content as IScrollInfo;

            if (realImplementation != null)
            {
                realImplementation.MouseWheelRight();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
        void IScrollInfo.SetVerticalOffset(double offset)
        {
            IScrollInfo realImplementation = Content as IScrollInfo;

            if (realImplementation != null)
            {
                realImplementation.SetVerticalOffset(offset);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #23
0
 private static void HandleAutoScroll(IScrollInfo element, DragPosition position)
 {
     if (((element.CanHorizontallyScroll) || (element.CanVerticallyScroll)) && element is Visual && element is IInputElement)
     {
         Visual Child = ((Visual)element).GetHitChild(position.GetPosition((IInputElement)element));
         if (Child is IInputElement)
         {
             Point Position        = position.GetPosition((IInputElement)Child);
             Rect  RectangleToShow = Helper.GetRectangleToShowFromDragPosition(Position);
             element.MakeVisible(Child, RectangleToShow);
         }
     }
 }
        Rect IScrollInfo.MakeVisible(Visual visual, Rect rectangle)
        {
            IScrollInfo realImplementation = Content as IScrollInfo;

            if (realImplementation != null)
            {
                return(realImplementation.MakeVisible(visual, rectangle));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #25
0
        //		TextBlock textBlock;
        /// <summary>
        /// Is called after the template was applied.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            scrollViewer = (ScrollViewer)base.GetTemplateChild("PART_ScrollViewer");
            IScrollInfo sc = ViewArea as IScrollInfo;

            if (sc != null)
            {
                sc.ScrollOwner = scrollViewer;
            }
            //			textBlock = (TextBlock)Template.FindName("PART_ColumnHeader", this);
            //
            //			textBlock.Text=s_colheader;
        }
Example #26
0
        /// <summary>
        /// Returns the control which is responsible for the scrolling.
        /// </summary>
        /// <remarks>
        /// Depending on our property <see cref="CanContentScroll"/>, either our content presenter's content will
        /// do the scrolling (<c>CanContentScroll == true</c>, i.e. logical scrolling) or the content presenter itself
        /// (<c>CanContentScroll == false</c>, i.e. physical scrolling).
        /// </remarks>
        /// <returns>The control responsible for doing the scrolling.</returns>
        protected IScrollInfo FindScrollControl()
        {
            ScrollContentPresenter scp = FindContentPresenter() as ScrollContentPresenter;

            if (scp == null)
            {
                return(null);
            }
            IScrollInfo scpContentSI = scp.TemplateControl as IScrollInfo;

            if (CanContentScroll && scpContentSI != null)
            {
                return(scpContentSI);
            }
            return(scp);
        }
Example #27
0
            public void NotifyDrag(DragPosition position)
            {
                FrameworkElement Element = this.element;

                if (this.element is IScrollInfo)
                {
                    Helper.HandleAutoScroll((IScrollInfo)Element, position);
                }
                if (this.element is ScrollViewer)
                {
                    IScrollInfo Scroller = this.element.GetVisualDescendantsDepthFirst <IScrollInfo>().FirstOrDefault();
                    if (Scroller != null)
                    {
                        Helper.HandleAutoScroll(Scroller, position);
                    }
                }
            }
Example #28
0
        protected override void OnApplyTemplate()
#endif
        {
            base.OnApplyTemplate();

            ScrollViewer sv = null;

            for (DependencyObject parent = VisualTreeHelper.GetParent(this); parent != null; parent = VisualTreeHelper.GetParent(parent))
            {
                sv = parent as ScrollViewer;
                if (sv != null)
                {
                    break;
                }
            }

            if (sv == null)
            {
                return;
            }

            IScrollInfo info = Content as IScrollInfo;

            if (info == null)
            {
                var presenter = Content as ItemsPresenter;
                if (presenter != null)
                {
                    presenter.ApplyTemplate();
                    if (presenter.TemplateChild != null)
                    {
                        info = presenter.TemplateChild as IScrollInfo;
                    }
                }
            }
            info = info ?? this;
            info.CanHorizontallyScroll  = sv.HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled;
            info.CanVerticallyScroll    = sv.VerticalScrollBarVisibility != ScrollBarVisibility.Disabled;
            info.ScrollOwner            = sv;
            info.ScrollOwner.ScrollInfo = info;
            sv.InvalidateScrollInfo();
        }
Example #29
0
        static void OnMouseMove(object sender, MouseEventArgs e)
        {
            ScrollContentPresenter p = getScrollContentPresenter(sender);

            if (GetIsDragging(p))
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    //0.5: Auto Scroll
                    Point       mousePos = e.GetPosition(p);
                    IScrollInfo isInfo   = UITools.FindVisualChild <Panel>(p) as IScrollInfo;
                    ListView    lv       = UITools.FindAncestor <ListView>(p);

                    if (isInfo.CanHorizontallyScroll)
                    {
                        if (mousePos.X < 0)
                        {
                            isInfo.SetHorizontalOffset(isInfo.HorizontalOffset - 1);
                        }
                        else if (mousePos.X > lv.ActualWidth)
                        {
                            isInfo.SetHorizontalOffset(isInfo.HorizontalOffset + 1);
                        }
                    }
                    if (isInfo.CanVerticallyScroll)
                    {
                        if (mousePos.Y < 0)
                        {
                            isInfo.SetVerticalOffset(isInfo.VerticalOffset - 1);
                        }
                        else if (mousePos.Y > lv.ActualHeight) //isInfo.ViewportHeight is bugged.
                        {
                            isInfo.SetVerticalOffset(isInfo.VerticalOffset + 1);
                        }
                    }

                    UpdatePosition(p, true);
                }
            }
        }
Example #30
0
        void TextViewScrollOffsetChanged(object sender, EventArgs e)
        {
            // Workaround for crash #1580 (reproduction steps unknown):
            // NullReferenceException in System.Windows.Window.CreateSourceWindow()
            if (!sourceIsInitialized)
            {
                return;
            }

            IScrollInfo scrollInfo  = this.TextArea.TextView;
            Rect        visibleRect = new Rect(scrollInfo.HorizontalOffset, scrollInfo.VerticalOffset, scrollInfo.ViewportWidth, scrollInfo.ViewportHeight);

            // close completion window when the user scrolls so far that the anchor position is leaving the visible area
            if (visibleRect.Contains(visualLocation) || visibleRect.Contains(visualLocationTop))
            {
                UpdatePosition();
            }
            else
            {
                Close();
            }
        }
        /// <summary>
        ///     Helper method which scrolls item at given index into view.
        ///     Can be used as a dispatcher operation.
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private object ScrollContainerIntoView(object arg)
        {
            int index = (int)arg;
            FrameworkElement element = ItemContainerGenerator.ContainerFromIndex(index) as FrameworkElement;

            if (element != null)
            {
                element.BringIntoView();

                // If there is a margin on TabHeader on the end, BringIntoView call
                // may not scroll to the end. Explicitly scroll to end in such cases.
                IScrollInfo scrollInfo = InternalItemsHost as IScrollInfo;
                if (scrollInfo != null)
                {
                    ScrollViewer scrollViewer = scrollInfo.ScrollOwner;
                    if (scrollViewer != null)
                    {
                        Ribbon ribbon = RibbonControlService.GetRibbon(this);
                        if (ribbon != null)
                        {
                            int displayIndex = ribbon.GetTabDisplayIndexForIndex(index);
                            if (displayIndex == 0)
                            {
                                // If this tab header is the first tab header displayed
                                // then scroll to the left end.
                                scrollViewer.ScrollToLeftEnd();
                            }
                            else if (ribbon.GetTabIndexForDisplayIndex(displayIndex + 1) < 0)
                            {
                                // If this tab header is the last tab header displayed
                                // then scroll to the right end.
                                scrollViewer.ScrollToRightEnd();
                            }
                        }
                    }
                }
            }
            return(null);
        }
Example #32
0
		/// <inheritdoc/>
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			scrollInfo = textView;
			ApplyScrollInfo();
		}
Example #33
0
    void ConfigureContentScrollFacility()
    {
      ScrollContentPresenter scp = FindContentPresenter() as ScrollContentPresenter;
      if (scp == null)
        return;
      scp.HorizontalFitToSpace = HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled;
      scp.VerticalFitToSpace = VerticalScrollBarVisibility == ScrollBarVisibility.Disabled;

      if (_attachedScrollInfo != null)
        _attachedScrollInfo.Scrolled -= OnScrollInfoScrolled;
      IScrollInfo scrollInfo = FindScrollControl();
      if (_attachedScrollInfo != null && _attachedScrollInfo != scrollInfo)
        _attachedScrollInfo.DoScroll = false;
      if (scrollInfo == null)
      {
        _attachedScrollInfo = null;
        return;
      }
      scrollInfo.DoScroll = true;
      _attachedScrollInfo = scrollInfo;
      _attachedScrollInfo.Scrolled += OnScrollInfoScrolled;
    }
        /// <summary>
        /// Overrides the base class implementation of <see cref="M:System.Windows.FrameworkElement.MeasureOverride(System.Windows.Size)" /> to measure the size of the <see cref="T:System.Windows.Controls.ItemsPresenter" /> object and return proper sizes to the layout engine.
        /// </summary>
        /// <param name="constraint">Constraint size is an "upper limit." The return value should not exceed this size.</param>
        /// <returns>The desired size.</returns>
        protected override Size MeasureOverride(Size constraint)
        {
            if (_childElement == null) _childElement = (VisualTreeHelper.GetChildrenCount(this) > 0) ? VisualTreeHelper.GetChild(this, 0) as UIElement : null;
            if (_childElement == null) return base.MeasureOverride(constraint);
            _childElement.Measure(constraint);

            if (_childScrollInfo == null)
            {
                _childScrollInfo = _childElement as IScrollInfo;
                if (_childScrollInfo != null && _childScrollInfo.ScrollOwner == null && _scrollOwner != null)
                {
                    _childScrollInfo.ScrollOwner = _scrollOwner;
                    _scrollOwner.InvalidateScrollInfo();
                }
            }

            return _childElement.DesiredSize;
        }
Example #35
0
        protected override void OnContentChanged(IElement oldContent, IElement newContent)
        {
            var oldScrollContentPresenter = oldContent as ScrollContentPresenter;
            if (oldScrollContentPresenter != null)
            {
                oldScrollContentPresenter.Content.VisualParent = null;
            }

            var newScrollInfo = newContent as IScrollInfo;
            if (newScrollInfo != null)
            {
                this.scrollInfo = newScrollInfo;

                if (oldContent != null && this.isInsertingScrollContentPresenter)
                {
                    ((ScrollContentPresenter)newContent).Content = oldContent;
                }

                this.isInsertingScrollContentPresenter = false;
            }
            else
            {
                this.isInsertingScrollContentPresenter = true;
                this.Content = new ScrollContentPresenter();
            }
        }
Example #36
0
        //自动滚动
        public void AutoScroll(MouseEventArgs e)
        {
            var scrollViewer = DiagramControl.Template.FindName("DesignerScrollViewer", DiagramControl) as ScrollViewer;
            if (scrollViewer == null) return;
            var parent = e.OriginalSource as DependencyObject;
            while (parent != null)
            {
                _scrollInfo = parent as IScrollInfo;
                if (_scrollInfo != null && _scrollInfo.ScrollOwner == scrollViewer)
                {
                    break;
                }
                _scrollInfo = null;
                parent = VisualTreeHelper.GetParent(parent);
            }

            UIElement scrollable = _scrollInfo as UIElement;
            if (scrollable != null)
            {
                var mousePos = e.GetPosition(scrollable);

                #region Vertical

                var v = 40;
                if (mousePos.Y < v)
                {
                    var delta = (mousePos.Y - v) / 1; //translate back to original unit
                    _scrollInfo.SetVerticalOffset(_scrollInfo.VerticalOffset + delta);
                }
                else if (mousePos.Y > (scrollable.RenderSize.Height - v))
                {
                    var delta = (mousePos.Y + v - scrollable.RenderSize.Height) / 1; //translate back to original unit
                    _scrollInfo.SetVerticalOffset(_scrollInfo.VerticalOffset + delta);
                }
                #endregion

                #region Horizontal
                var h = 200;
                if (mousePos.X < h)
                {
                    var delta = (mousePos.X - h) / 1; //translate back to original unit
                    _scrollInfo.SetHorizontalOffset(_scrollInfo.HorizontalOffset + delta);
                }
                else if (mousePos.X > (scrollable.RenderSize.Width - h))
                {
                    var delta = (mousePos.X + h - scrollable.RenderSize.Width) / 1; //translate back to original unit
                    _scrollInfo.SetHorizontalOffset(_scrollInfo.HorizontalOffset + delta);
                }
                #endregion
            }
        }
 private void OnCanContentScrollChanged(DependencyPropertyChangedEventArgs e)
 {
     delegateScrollInfo = GetDelegateScrollInfo();
 }
 protected override void OnContentChanged(DependencyPropertyChangedEventArgs e)
 {
     base.OnContentChanged(e);
     delegateScrollInfo = GetDelegateScrollInfo();
 }
        /// <summary>
        /// Wrapper around IScrollInfo.MakeVisible
        /// </summary>
        /// <param name="scrollInfo">The IScrollInfo to call MakeVisible on</param>
        /// <param name="visual">visual parameter for call to MakeVisible</param>
        /// <param name="rectangle">rectangle parameter for call to MakeVisible</param>
        /// <returns>Rectangle representing visible portion of visual relative to scrollInfo's viewport</returns>
        private static Rect MakeVisible(IScrollInfo scrollInfo, Visual visual, Rect rectangle)
        {
            // 




            Rect result;

            if(scrollInfo.GetType() == typeof(System.Windows.Controls.ScrollContentPresenter))
            {
                result = ((ScrollContentPresenter)scrollInfo).MakeVisible(visual, rectangle, false);
            }
            else
            {
                result = scrollInfo.MakeVisible(visual, rectangle);
            }

            return result;
        }
 internal void SetScrollInfo(IScrollInfo info)
 {
     ScrollInfo = info;
 }