public override Size GetPreferredSizeCore(Size proposedSize) { if (this.GetBitState(IsScrollingStateKey)) { return(this.Size); } if (this.viewport == null) { return(base.GetPreferredSizeCore(proposedSize)); } if (this.AutoSize && this.AutoSizeMode == RadAutoSizeMode.WrapAroundChildren) { Size viewportSize = this.viewport.GetPreferredSize(proposedSize); Size extentSize = this.UsePhysicalScrolling ? viewportSize : ((IRadScrollViewport)this.viewport).GetExtentSize(); ScrollFlags sf = GetScrollingNeeds(extentSize, this.MaxSize); Size scollBarsSize = GetScrollBarsSize(sf); return(Size.Add(viewportSize, scollBarsSize)); } else { return(base.GetPreferredSizeCore(proposedSize)); } }
/// <summary> /// Set visible and enabled state of the ScrollBars. /// </summary> private void ResetScrollState(ScrollFlags flags) { bool isHorizScrollNeeded = (flags & ScrollFlags.Horizontal) == ScrollFlags.Horizontal; bool isVertScrollNeeded = (flags & ScrollFlags.Vertical) == ScrollFlags.Vertical; switch (this.horizontalScrollState) { case ScrollState.AlwaysShow: this.horizontalScrollBar.Enabled = isHorizScrollNeeded; this.horizontalScrollBar.Visibility = ElementVisibility.Visible; break; case ScrollState.AlwaysHide: this.horizontalScrollBar.Enabled = isHorizScrollNeeded; this.horizontalScrollBar.Visibility = ElementVisibility.Collapsed; break; case ScrollState.AutoHide: if (isHorizScrollNeeded) { this.horizontalScrollBar.Enabled = true; } this.horizontalScrollBar.Visibility = isHorizScrollNeeded ? ElementVisibility.Visible : ElementVisibility.Collapsed; break; } switch (this.verticalScrollState) { case ScrollState.AlwaysShow: this.verticalScrollBar.Enabled = isVertScrollNeeded; this.verticalScrollBar.Visibility = ElementVisibility.Visible; break; case ScrollState.AlwaysHide: this.verticalScrollBar.Enabled = isVertScrollNeeded; this.verticalScrollBar.Visibility = ElementVisibility.Collapsed; break; case ScrollState.AutoHide: if (isVertScrollNeeded) { this.verticalScrollBar.Enabled = true; } this.verticalScrollBar.Visibility = isVertScrollNeeded ? ElementVisibility.Visible : ElementVisibility.Collapsed; break; } if ((horizontalScrollBar.Visibility == ElementVisibility.Collapsed) || (verticalScrollBar.Visibility == ElementVisibility.Collapsed)) { this.blankSpot.Visibility = ElementVisibility.Collapsed; } else { this.blankSpot.Visibility = ElementVisibility.Visible; } }
/// <summary> /// sets or erases the given scroll flags /// </summary> public void SetScrollFlags(ScrollFlags flags, bool value) { if (value) { _flags |= flags; } else { _flags &= ~flags; } }
public void ResetLayout() { if (this.UseNewLayoutSystem) { this.InvalidateMeasure(); this.InvalidateArrange(); } else { IRadScrollViewport scrollViewport = this.viewport as IRadScrollViewport; if (scrollViewport != null) { scrollViewport.InvalidateViewport(); } if (this.viewport == null) { this.horizontalScrollBar.Visibility = ElementVisibility.Collapsed; this.verticalScrollBar.Visibility = ElementVisibility.Collapsed; return; } // Init size members (clientSize, viewportSize, extentSize) this.clientSize = this.Parent.FieldSize; Size preferredViewportSize = this.viewport.GetPreferredSize(this.clientSize); this.extentSize = this.UsePhysicalScrolling ? preferredViewportSize : ((IRadScrollViewport)this.viewport).GetExtentSize(); ScrollFlags sf = GetScrollingNeeds(this.extentSize, this.clientSize); Size scrollBarsSize = GetScrollBarsSize(sf); this.viewportSize = Size.Subtract(this.clientSize, scrollBarsSize); // Viewport Point startPoint = new Point(base.RightToLeft ? scrollBarsSize.Width : 0, 0); Rectangle viewportRect = new Rectangle(startPoint, this.UsePhysicalScrolling ? this.extentSize : this.viewportSize); this.viewport.SetBounds(viewportRect); ResetScrollState(sf); ResetScrollPos(); OnSizeHScroll(this.clientSize); OnSizeVScroll(this.clientSize); OnSizeBlankSpot(this.clientSize); } }
private Size GetScrollBarsSize(ScrollFlags flags) { int vertical = 0; if ((this.horizontalScrollState == ScrollState.AlwaysShow) || (this.horizontalScrollState == ScrollState.AutoHide && (flags & ScrollFlags.Horizontal) == ScrollFlags.Horizontal)) { vertical = this.scrollThicknessCache; } int horizontal = 0; if ((this.verticalScrollState == ScrollState.AlwaysShow) || (this.verticalScrollState == ScrollState.AutoHide && (flags & ScrollFlags.Vertical) == ScrollFlags.Vertical)) { horizontal = this.scrollThicknessCache; } return(new Size(horizontal, vertical)); }
/// <summary> /// sets or erases the given scroll flags /// </summary> public void SetScrollFlags(ScrollFlags flags, bool value) { if (value) _flags |= flags; else _flags &= ~flags; }
private ScrollFlags GetScrollingNeeds(Size extentSize, Size clientSize) { // Check where is (Bottom, Right) point of extentSize in clientSize // There are 9 posible positions - labeled with areas from A to I: // // Vertical ScrollBar // ^ // (0,0) | // +-----+---+ // Viewport Rectangle <- | | | // | | | // | A | B | C // +-----+---+ // Horizontal ScrollBar <- | D | E | F // +-----+---+ // G H I bool oldHorizScrollNeeded = this.GetBitState(IsHorizScrollNeededStateKey); bool oldVerticalScrollNeeded = this.GetBitState(IsVertScrollNeededStateKey); this.BitState[IsHorizScrollNeededStateKey] = false; this.BitState[IsVertScrollNeededStateKey] = false; // Check cases when (Bottom, Right) of the Extent is on different areas // according Client rectangle if (extentSize.Width > clientSize.Width) {// Point C, F and I this.BitState[IsHorizScrollNeededStateKey] = true; if (extentSize.Height > clientSize.Height - scrollThicknessCache) {// Points F and I this.BitState[IsVertScrollNeededStateKey] = true; } } else if (extentSize.Width > clientSize.Width - scrollThicknessCache) { // Points B, E and H if (extentSize.Height > clientSize.Height) { // Point H this.BitState[IsHorizScrollNeededStateKey] = true; this.BitState[IsVertScrollNeededStateKey] = true; } else if (extentSize.Height > clientSize.Height - scrollThicknessCache) {// Point E if ( this.verticalScrollState != ScrollState.AlwaysHide && this.horizontalScrollState != ScrollState.AlwaysHide && (this.horizontalScrollState != ScrollState.AutoHide || this.verticalScrollState != ScrollState.AutoHide) && ( ( this.verticalScrollBar.Visibility != ElementVisibility.Collapsed && this.verticalScrollState == ScrollState.AlwaysShow ) || ( this.horizontalScrollBar.Visibility != ElementVisibility.Collapsed && this.horizontalScrollState == ScrollState.AlwaysShow ) ) ) { this.BitState[IsHorizScrollNeededStateKey] = true; this.BitState[IsVertScrollNeededStateKey] = true; } } else {// Point B if (this.verticalScrollState == ScrollState.AlwaysShow) { this.BitState[IsHorizScrollNeededStateKey] = true; } } } else { // Point A, D and G if (extentSize.Height > clientSize.Height) { // Point G this.BitState[IsVertScrollNeededStateKey] = true; } else if (extentSize.Height > clientSize.Height - scrollThicknessCache) {// Point D if (this.horizontalScrollState == ScrollState.AlwaysShow) { this.BitState[IsVertScrollNeededStateKey] = true; } } } bool horizNeedChanged = oldHorizScrollNeeded != this.GetBitState(IsHorizScrollNeededStateKey); bool vertNeedChanged = oldVerticalScrollNeeded != this.GetBitState(IsVertScrollNeededStateKey); if (horizNeedChanged || vertNeedChanged) { OnScrollNeedsChanged(new ScrollNeedsEventArgs(oldHorizScrollNeeded, this.GetBitState(IsHorizScrollNeededStateKey), oldVerticalScrollNeeded, this.GetBitState(IsVertScrollNeededStateKey))); } ScrollFlags res = 0; if (this.GetBitState(IsHorizScrollNeededStateKey)) { res |= ScrollFlags.Horizontal; } if (this.GetBitState(IsVertScrollNeededStateKey)) { res |= ScrollFlags.Vertical; } return(res); }
protected override SizeF ArrangeOverride(SizeF finalSize) { IRadScrollViewport scrollViewport = this.viewport as IRadScrollViewport; if (scrollViewport != null) { scrollViewport.InvalidateViewport(); } if (this.viewport == null) { base.ArrangeOverride(finalSize); this.horizontalScrollBar.Visibility = ElementVisibility.Collapsed; this.verticalScrollBar.Visibility = ElementVisibility.Collapsed; return(finalSize); } // Init size members (clientSize, viewportSize, extentSize) this.clientSize = Size.Round(finalSize); //TODO: //changed this.viewport.DesiziredSize to this.viewport.Size //MUST be tested Size preferredViewportSize = Size.Round(this.viewport.DesiredSize); this.extentSize = this.UsePhysicalScrolling ? preferredViewportSize : ((IRadScrollViewport)this.viewport).GetExtentSize(); ScrollFlags sf = GetScrollingNeeds(this.extentSize, this.clientSize); Size scrollBarsSize = GetScrollBarsSize(sf); this.viewportSize = Size.Subtract(this.clientSize, scrollBarsSize); // Sets Visibility and Enabled properties of the scrollbars and the blankspot ResetScrollState(sf); // !!! blankSpotSize is non-empty ONLY when both scrollbars are visible Size blankSpotSize = Size.Empty; if (this.BlankSpot.Visibility == ElementVisibility.Visible) { blankSpotSize = scrollBarsSize; } float viewportLeftPos = this.RightToLeft ? scrollBarsSize.Width : 0; float horizontalScrollLeftPos = this.RightToLeft ? scrollBarsSize.Width : 0; float verticalScrollLeftPos = this.RightToLeft ? 0 : finalSize.Width - scrollBarsSize.Width; float blankSpotLeftPos = this.RightToLeft ? 0 : finalSize.Width - blankSpotSize.Width; RectangleF viewportRect = new RectangleF( viewportLeftPos, 0, this.viewportSize.Width, this.viewportSize.Height); RectangleF vertScrollRect = new RectangleF( verticalScrollLeftPos, 0, scrollBarsSize.Width, Math.Max(0, finalSize.Height - scrollBarsSize.Height)); RectangleF horizScrollRect = new RectangleF( horizontalScrollLeftPos, finalSize.Height - scrollBarsSize.Height, Math.Max(0, finalSize.Width - scrollBarsSize.Width), scrollBarsSize.Height); RectangleF blankSpotRectRect = new RectangleF( blankSpotLeftPos, finalSize.Height - blankSpotSize.Height, blankSpotSize.Width, blankSpotSize.Height); this.viewport.Arrange(viewportRect); this.VerticalScrollBar.Arrange(vertScrollRect); this.HorizontalScrollBar.Arrange(horizScrollRect); this.BlankSpot.Arrange(blankSpotRectRect); ResetScrollPos(); return(finalSize); }