Example #1
0
        /// <summary>
        /// Recalculate both of the scrollbars' locations and lengths.
        /// Also reposition the corner rectangle.
        /// </summary>
        public void resize()
        {
            // Look up the host metrics once, and use for both scrollbars.
            var hostMetrics = this.workspace_.getMetrics();

            if (hostMetrics == null)
            {
                // Host element is likely not visible.
                return;
            }

            // Only change the scrollbars if there has been a change in metrics.
            var resizeH = false;
            var resizeV = false;

            if (this.oldHostMetrics_ == null ||
                this.oldHostMetrics_.viewWidth != hostMetrics.viewWidth ||
                this.oldHostMetrics_.viewHeight != hostMetrics.viewHeight ||
                this.oldHostMetrics_.absoluteTop != hostMetrics.absoluteTop ||
                this.oldHostMetrics_.absoluteLeft != hostMetrics.absoluteLeft)
            {
                // The window has been resized or repositioned.
                resizeH = true;
                resizeV = true;
            }
            else
            {
                // Has the content been resized or moved?
                if (this.oldHostMetrics_ == null ||
                    this.oldHostMetrics_.contentWidth != hostMetrics.contentWidth ||
                    this.oldHostMetrics_.viewLeft != hostMetrics.viewLeft ||
                    this.oldHostMetrics_.contentLeft != hostMetrics.contentLeft)
                {
                    resizeH = true;
                }
                if (this.oldHostMetrics_ == null ||
                    this.oldHostMetrics_.contentHeight != hostMetrics.contentHeight ||
                    this.oldHostMetrics_.viewTop != hostMetrics.viewTop ||
                    this.oldHostMetrics_.contentTop != hostMetrics.contentTop)
                {
                    resizeV = true;
                }
            }
            if (resizeH)
            {
                this.hScroll.resize(hostMetrics);
            }
            if (resizeV)
            {
                this.vScroll.resize(hostMetrics);
            }

            // Reposition the corner square.
            if (this.oldHostMetrics_ == null ||
                this.oldHostMetrics_.viewWidth != hostMetrics.viewWidth ||
                this.oldHostMetrics_.absoluteLeft != hostMetrics.absoluteLeft)
            {
                this.corner_.SetAttribute("x", this.vScroll.position_.x.ToString());
            }
            if (this.oldHostMetrics_ == null ||
                this.oldHostMetrics_.viewHeight != hostMetrics.viewHeight ||
                this.oldHostMetrics_.absoluteTop != hostMetrics.absoluteTop)
            {
                this.corner_.SetAttribute("y", this.hScroll.position_.y.ToString());
            }

            // Cache the current metrics to potentially short-cut the next resize event.
            this.oldHostMetrics_ = hostMetrics;
        }
Example #2
0
 /// <summary>
 /// Recalculate a vertical scrollbar's location and length.
 /// </summary>
 /// <param name="hostMetrics">A data structure describing all the
 /// required dimensions, possibly fetched from the host object.</param>
 private void resizeVertical_(Metrics hostMetrics)
 {
     // TODO: Inspect metrics to determine if we can get away with just a content
     // resize.
     this.resizeViewVertical(hostMetrics);
 }