Пример #1
0
		public override Size GetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			if (childBackend == null)
				return base.GetPreferredSize (widthConstraint, heightConstraint);
			var size = childBackend.Frontend.Surface.GetPreferredSize (widthConstraint, heightConstraint, true);
			return size;
		}
Пример #2
0
        public override Size GetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            var r = new System.Drawing.RectangleF(0, 0, widthConstraint.IsConstrained ? (float)widthConstraint.AvailableSize : float.MaxValue, heightConstraint.IsConstrained ? (float)heightConstraint.AvailableSize : float.MaxValue);
            var s = Widget.Cell.CellSizeForBounds(r);

            return(new Size(s.Width, s.Height));
        }
Пример #3
0
        protected override Size OnGetPreferredSize(SizeConstraint w, SizeConstraint h)
        {
            double width  = 0;
            double height = 0;

            if (horizontal)
            {
                width = start_border + end_border;
            }
            else
            {
                height = start_border + end_border;
            }

            foreach (AnimatedWidget widget in Widgets)
            {
                var req = widget.Surface.GetPreferredSize();
                if (horizontal)
                {
                    width += req.Width;
                    height = Math.Max(height, req.Height);
                }
                else
                {
                    width   = Math.Max(width, req.Width);
                    height += req.Height;
                }
            }

            return(new Size(width, height));
        }
        private static Size?CalculateRenderSize(SizeConstraint constraint)
        {
            if (constraint == null)
            {
                return(null);
            }

            if (!constraint.ShouldUsePadding || constraint.Padding.Bottom == 0 && constraint.Padding.Top == 0 && constraint.Padding.Left == 0 && constraint.Padding.Right == 0)
            {
                return(constraint.Size);
            }

            var thickness = constraint.Padding;
            var size      = constraint.Size;
            var width     = size.Width - (int)Math.Round(thickness.Left + thickness.Right);

            if (width < 0)
            {
                width = 0;
            }
            var height = size.Height - (int)Math.Round(thickness.Top + thickness.Bottom);

            if (height < 0)
            {
                height = 0;
            }

            return(new Size(width, height));
        }
Пример #5
0
        protected override Size MeasureSelf(SizeConstraint constraint)
        {
            if (Root == null || Root.Canvas == null || Root.Canvas.IsDisposed)
            {
                /// 測れないので現状維持
                return(constraint.MeasureConstrainedSize(Size));
            }

            if (!IsVisible)
            {
                /// 現状維持
                return(constraint.MeasureConstrainedSize(Size));
            }

            using (var g = Root.Canvas.CreateGraphics())
                using (_ResourceCache.UseResource()) {
                    /// _ImageResourceを参照しておかないとImageSizeが正しく取れないことがある
                    var image = _ImageResource;

                    if (Text != null)
                    {
                        var textSize = MeasureText(g, Text, _FontResource, int.MaxValue);
                        var size     = new Size(
                            ImageSize.Width + Margin + textSize.Width + Padding.Width,
                            Math.Max(ImageSize.Height, textSize.Height) + Padding.Height
                            );
                        return(constraint.MeasureConstrainedSize(size));
                    }
                    else
                    {
                        return(constraint.MeasureConstrainedSize(ImageSize));
                    }
                }
        }
Пример #6
0
 /// <summary>
 /// Constructor for the ShoppingCartViewModel.
 /// </summary>
 /// <param name="cart">A shopping cart object.</param>
 public ShoppingCartViewModel(ShoppingCartInfo cart)
 {
     // Creates a collection containing all lines from the given shopping cart
     CartItems = cart.CartProducts.Select((cartItemInfo) =>
     {
         return(new ShoppingCartItemViewModel()
         {
             CartItemUnits = cartItemInfo.CartItemUnits,
             SKUName = cartItemInfo.SKU.SKUName,
             TotalPrice = cartItemInfo.TotalPrice,
             CartItemID = cartItemInfo.CartItemID,
             SKUID = cartItemInfo.SKUID,
             SKUImageUrl = string.IsNullOrEmpty(cartItemInfo.SKU.SKUImagePath) ? null : new FileUrl(cartItemInfo.SKU.SKUImagePath, true)
                           .WithSizeConstraint(SizeConstraint.MaxWidthOrHeight(100))
                           .RelativePath
         });
     });
     CurrencyFormatString           = cart.Currency.CurrencyFormatString;
     CouponCodes                    = cart.CouponCodes.AllAppliedCodes.Select(x => x.Code);
     TotalTax                       = cart.TotalTax;
     TotalShipping                  = cart.TotalShipping;
     GrandTotal                     = cart.GrandTotal;
     RemainingAmountForFreeShipping = cart.CalculateRemainingAmountForFreeShipping();
     IsEmpty = cart.IsEmpty;
 }
Пример #7
0
        protected override Size OnGetPreferredSize(SizeConstraint w, SizeConstraint h)
        {
            var    size             = base.OnGetPreferredSize(w, h);
            double descriptionWidth = 1;
            double totalHeight      = yBorder * 2 + 1;

            layout.Text = TitleText;
            var lsize = layout.GetSize();

            totalHeight += lsize.Height;
            xSpacer      = 0;
            foreach (var pair in Items)
            {
                layout.Markup = pair.Key;
                var w1 = layout.GetSize();

                layout.Markup = pair.Value;
                var w2 = layout.GetSize();
                descriptionWidth = System.Math.Max(descriptionWidth, w2.Width);
                xSpacer          = System.Math.Max(xSpacer, w1.Width);

                totalHeight += w2.Height;
            }
            xSpacer += xBorder * 2 + 1;

            return(new Size(descriptionWidth + xSpacer + xBorder * 2 + 1,
                            totalHeight));
        }
Пример #8
0
		public override Size GetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			if (this.direction == Orientation.Vertical)
				return new Size (1, heightConstraint.IsConstrained ? heightConstraint.AvailableSize : 0);
			else
				return new Size (widthConstraint.IsConstrained ? widthConstraint.AvailableSize : 0, 1);
		}
Пример #9
0
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            var lvsize = base.OnGetPreferredSize(widthConstraint, heightConstraint);

            var s = layout.GetSize();

            rowHeight = (int)s.Height + padding;

            visibleRows = 7;//(winHeight + padding - margin * 2) / rowHeight;

            double newHeight;

            if (this.win.DataProvider.Count > this.visibleRows)
            {
                newHeight = (rowHeight * visibleRows) + margin * 2;
            }
            else
            {
                newHeight = (rowHeight * this.win.DataProvider.Count) + margin * 2;
            }

            if (lvsize.Width != listWidth || lvsize.Height != newHeight)
            {
                return(new Size(listWidth, newHeight));
            }
            return(lvsize);
        }
Пример #10
0
        void UpdateChildSize()
        {
            if (child == null)
            {
                return;
            }

            if (Widget.ContentView is CustomClipView)
            {
            }
            else
            {
                NSView      view = (NSView)Widget.DocumentView;
                ViewBackend c    = (ViewBackend)child;
                Size        s;
                if (horizontalScrollPolicy == ScrollPolicy.Never)
                {
                    s = c.Frontend.Surface.GetPreferredSize(SizeConstraint.WithSize(Widget.ContentView.Frame.Width), SizeConstraint.Unconstrained);
                }
                else if (verticalScrollPolicy == ScrollPolicy.Never)
                {
                    s = c.Frontend.Surface.GetPreferredSize(SizeConstraint.Unconstrained, SizeConstraint.WithSize(Widget.ContentView.Frame.Width));
                }
                else
                {
                    s = c.Frontend.Surface.GetPreferredSize();
                }
                var w = Math.Max(s.Width, Widget.ContentView.Frame.Width);
                var h = Math.Max(s.Height, Widget.ContentView.Frame.Height);
                view.Frame = new System.Drawing.RectangleF(view.Frame.X, view.Frame.Y, (float)s.Width, (float)h);
            }
        }
Пример #11
0
        public Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            var    children = (ChildrenCollection <BoxPlacement>)GetFieldValuePrivate(typeof(Box), owner, "children");
            double spacing  = owner.Spacing;

            Size s     = new Size();
            int  count = 0;

            var visibleChildren = children.Where(b => b.Child.Visible).ToArray();

            Dictionary <BoxPlacement, double> nextsize = null;

            if (direction == Orientation.Horizontal)
            {
                // If the width is constrained then we have a total width, and we can calculate the exact width assigned to each child.
                // We can then use that width as a width constraint for the child.

                if (widthConstraint.IsConstrained)
                {
                    nextsize = CalcDefaultSizes(widthConstraint, heightConstraint, false); // Calculates the width assigned to each child
                }
                foreach (var cw in visibleChildren)
                {
                    // Use the calculated width if available
                    var wsize = cw.Child.Surface.GetPreferredSize(widthConstraint.IsConstrained ? nextsize[cw] : SizeConstraint.Unconstrained, heightConstraint, true);
                    s.Width += wsize.Width;
                    if (wsize.Height > s.Height)
                    {
                        s.Height = wsize.Height;
                    }
                    count++;
                }
                if (count > 0)
                {
                    s.Width += spacing * (double)(count - 1);
                }
            }
            else
            {
                if (heightConstraint.IsConstrained)
                {
                    nextsize = CalcDefaultSizes(widthConstraint, heightConstraint, false);
                }
                foreach (var cw in visibleChildren)
                {
                    var wsize = cw.Child.Surface.GetPreferredSize(widthConstraint, heightConstraint.IsConstrained ? nextsize[cw] : SizeConstraint.Unconstrained, true);
                    s.Height += wsize.Height;
                    if (wsize.Width > s.Width)
                    {
                        s.Width = wsize.Width;
                    }
                    count++;
                }
                if (count > 0)
                {
                    s.Height += spacing * (double)(count - 1);
                }
            }
            return(s);
        }
Пример #12
0
            public void GetHashCode_SameHeight_SameHashCode(int firstConstraintWidth, int secondConstraintWidth)
            {
                var constraint1 = SizeConstraint.Height(firstConstraintWidth);
                var constraint2 = SizeConstraint.Height(secondConstraintWidth);

                Assert.AreEqual(constraint1, constraint2);
            }
Пример #13
0
            public void GetHashCode_DifferentMaxWidthOrHeight_DifferentHashCode(int firstConstraintWidth, int secondConstraintWidth)
            {
                var constraint1 = SizeConstraint.MaxWidthOrHeight(firstConstraintWidth);
                var constraint2 = SizeConstraint.MaxWidthOrHeight(secondConstraintWidth);

                Assert.AreNotEqual(constraint1, constraint2);
            }
Пример #14
0
        public override Size Measure(IFigure parent, SizeConstraint constraint)
        {
            if (!parent.Children.Any())
            {
                return(_emptyPreferredSize + _padding.Size);
            }

            var ret = new Size(0, _padding.Top);
            var clientAreaConstraint = constraint.Deflate(_padding.Size);

            foreach (var child in parent.Children)
            {
                if (child.IsVisible)
                {
                    child.Measure(clientAreaConstraint);
                    var prefSize = child.PreferredSize;
                    ret.Width   = Math.Max(prefSize.Width, ret.Width);
                    ret.Height += prefSize.Height + _itemSpace;
                }
            }

            ret.Width  += _padding.Width;
            ret.Height += _padding.Bottom - _itemSpace;
            return(constraint.MeasureConstrainedSize(ret));
        }
		protected override Size OnGetRequiredSize (SizeConstraint widthConstraint)
		{
			var buildOutputNode = GetValue (BuildOutputNodeField);
			var status = GetViewStatus (buildOutputNode);

			double minWidth = ImageSize + ImagePadding + MinLayoutWidth + DefaultInformationContainerWidth;
			if (widthConstraint.IsConstrained)
				minWidth = Math.Max (minWidth, widthConstraint.AvailableSize);

			// in collapsed state we have always the same height and require the minimal width
			// if the layout height has not been calculated yet, use the ImageSize for the height
			if (!status.Expanded) {
				return new Size (minWidth, status.CollapsedRowHeight > -1 ? status.CollapsedRowHeight : ImageSize);
			}

			double maxLayoutWidth;
			if (widthConstraint.IsConstrained)
				maxLayoutWidth = minWidth - ((ImageSize - 3) + ImageSize + ImagePadding + DefaultInformationContainerWidth);
			else
				maxLayoutWidth = status.LastRenderLayoutBounds.Width;

			var layout = status.GetUnconstrainedLayout ();
			layout.Width = maxLayoutWidth;
			var textSize = layout.GetSize ();
			var height = Math.Max (textSize.Height + 2 * status.LayoutYPadding, DefaultRowHeight);

			return new Size (minWidth, height);
		}
Пример #16
0
            public void Equals_DifferentInstancesSameSizes_ReturnsTrue()
            {
                var constraint1 = SizeConstraint.Size(100, 200);
                var constraint2 = SizeConstraint.Size(100, 200);

                Assert.That(constraint1.Equals(constraint2), Is.True);
            }
Пример #17
0
        void Reallocate()
        {
            var contentWidth = (Controller.DefaultPageSize.Width > 0 ? Controller.DefaultPageSize.Width : 660);
            var pageRequest  = currentPageWidget.Surface.GetPreferredSize(true);

            contentWidth = Math.Max(contentWidth, pageRequest.Width);
            pageRequest  = currentPageWidget.Surface.GetPreferredSize(SizeConstraint.WithSize(contentWidth), SizeConstraint.Unconstrained, true);
            var contentHeight   = pageRequest.Height;
            var rightSideWidget = currentPage.GetRightSideWidget() ?? Controller.RightSideWidget;

            if (rightSideWidget != null)
            {
                var widget = (Xwt.Widget)rightSideWidget;
                if (rightSideFrame.Content != widget)
                {
                    rightSideFrame.Content = widget;
                    rightSideFrame.Content.VerticalPlacement = rightSideFrame.Content.HorizontalPlacement = WidgetPlacement.Fill;
                    rightSideFrame.Visible = true;
                }
                Dialog.Width = contentWidth + RightSideWidgetWidth;
            }
            else
            {
                rightSideFrame.Visible = false;
                Dialog.Width           = contentWidth;
            }
            Dialog.Height = Math.Max(contentHeight, Controller.DefaultPageSize.Height) + buttonBox.Size.Height;
        }
Пример #18
0
            public void NotEqualOperator_DifferentInstancesSameSizes_ReturnsFalse()
            {
                var constraint1 = SizeConstraint.Size(100, 200);
                var constraint2 = SizeConstraint.Size(100, 200);

                Assert.That(constraint1 != constraint2, Is.False);
            }
Пример #19
0
            public void NotEqualOperator_DifferentInstancesDifferentSizes_ReturnsTrue()
            {
                var constraint1 = SizeConstraint.Size(100, 200);
                var constraint2 = SizeConstraint.Size(300, 500);

                Assert.That(constraint1 != constraint2, Is.True);
            }
        /// <summary>
        /// Creates a new product model.
        /// </summary>
        /// <param name="productPage">Product's page.</param>
        /// <param name="priceDetail">Price of the product.</param>
        public ProductViewModel(SKUTreeNode productPage, ProductCatalogPrices priceDetail)
        {
            // Fills the page information
            Name             = productPage.DocumentName;
            Description      = productPage.DocumentSKUDescription;
            ShortDescription = productPage.DocumentSKUShortDescription;

            // Fills the SKU information
            SKUInfo sku = productPage.SKU;

            SKUID     = sku.SKUID;
            ImagePath = string.IsNullOrEmpty(sku.SKUImagePath) ? null : new FileUrl(sku.SKUImagePath, true)
                        .WithSizeConstraint(SizeConstraint.MaxWidthOrHeight(400))
                        .RelativePath;

            IsInStock = sku.SKUTrackInventory == TrackInventoryTypeEnum.Disabled ||
                        sku.SKUAvailableItems > 0;

            PriceDetail = new PriceDetailViewModel()
            {
                Price                = priceDetail.Price,
                ListPrice            = priceDetail.ListPrice,
                CurrencyFormatString = priceDetail.Currency.CurrencyFormatString
            };
        }
Пример #21
0
        protected override Size OnGetRequiredSize(SizeConstraint widthConstraint)
        {
            var node   = GetValue(NodeField);
            var status = GetViewStatus(node);

            TextLayout layout = new TextLayout();

            layout.Text = node.Text;
            var textSize = layout.GetSize();

            var maxWidth = widthConstraint.IsConstrained ? widthConstraint.AvailableSize : status.LastRenderWidth;

            // When in expanded mode, the height of the row depends on the width. Since we don't know the width,
            // let's use the last width that was used for rendering.

            if (status.Expanded && maxWidth > 0 && textSize.Width > maxWidth)
            {
                layout.Width = maxWidth - addImage.Width - MoreLinkSpacing;
                textSize     = layout.GetSize();
            }

            status.LastCalculatedHeight = textSize.Height;

            return(new Size(30, textSize.Height));
        }
Пример #22
0
        void HandleWidgetSizeRequested(object o, Gtk.SizeRequestedArgs args)
        {
            var req = args.Requisition;

            if (!gettingPreferredSize && (enabledEvents & WidgetEvent.PreferredSizeCheck) != 0)
            {
                SizeConstraint wc = SizeConstraint.Unconstrained, hc = SizeConstraint.Unconstrained;
                var            cp = Widget.Parent as IConstraintProvider;
                if (cp != null)
                {
                    cp.GetConstraints(Widget, out wc, out hc);
                }

                ApplicationContext.InvokeUserCode(delegate {
                    var w      = eventSink.GetPreferredSize(wc, hc);
                    req.Width  = (int)w.Width;
                    req.Height = (int)w.Height;
                });
            }

            if (Frontend.MinWidth != -1 && Frontend.MinWidth > req.Width)
            {
                req.Width = (int)Frontend.MinWidth;
            }
            if (Frontend.MinHeight != -1 && Frontend.MinHeight > req.Height)
            {
                req.Height = (int)Frontend.MinHeight;
            }

            args.Requisition = req;
        }
Пример #23
0
        // The GetPreferredSize method is called when the corresponding OnGetPreferredSize method in the
        // XWT widget is not overriden, or if it is overriden and the new implementation calls
        // base.OnGetPreferredSize. For this reason, we have to ensure that the widget's MeasureOverride
        // method doesn't end calling the frontend OnGetPreferredSize method. To avoid it we set
        // the calculatingPreferredSize flag to true, and we check this flag in MeasureOverride

        public virtual Size GetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            SW.Size size;
            Widget.InvalidateMeasure();
            GetWidgetDesiredSize(widthConstraint.IsConstrained ? widthConstraint.AvailableSize : Double.PositiveInfinity, heightConstraint.IsConstrained ? heightConstraint.AvailableSize : Double.PositiveInfinity, out size);
            return(new Size(size.Width, size.Height));
        }
Пример #24
0
            public void Equals_DifferentInstancesDifferentSizes_ReturnsFalse()
            {
                var constraint1 = SizeConstraint.Size(100, 200);
                var constraint2 = SizeConstraint.Size(300, 500);

                Assert.That(constraint1.Equals(constraint2), Is.False);
            }
Пример #25
0
            public Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
            {
                Size s     = new Size();
                int  count = 0;

                double[] nextsize = null;
                double   spacing  = this.owner.Spacing;

                // If the width is constrained then we have a total width, and we can calculate the exact width assigned to each child.
                // We can then use that width as a width constraint for the child.

                if (widthConstraint.IsConstrained)
                {
                    nextsize = CalcDefaultSizes(widthConstraint, heightConstraint, false); // Calculates the width assigned to each child
                }
                for (var nit = 0; nit < this.owner.Placements.Count; nit++)
                {
                    // Use the calculated width if available
                    var wsize = this.owner.Placements[nit].Child.GetBackend().GetPreferredSize(widthConstraint.IsConstrained ? SizeConstraint.WithSize(nextsize[nit]) : SizeConstraint.Unconstrained, heightConstraint);
                    s.Width += wsize.Width;
                    if (wsize.Height > s.Height)
                    {
                        s.Height = wsize.Height;
                    }
                    count++;
                }
                if (count > 0)
                {
                    s.Width += spacing * (double)(count - 1);
                }
                return(s);
            }
Пример #26
0
            public void GetHashCode_SameSizes_SameHashCode()
            {
                var constraint1 = SizeConstraint.Size(100, 200);
                var constraint2 = SizeConstraint.Size(100, 200);

                Assert.AreEqual(constraint1.GetHashCode(), constraint2.GetHashCode());
            }
Пример #27
0
        public override Size GetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            var s = EventSink.GetDefaultNaturalSize();

            if (child == null)
            {
                return(s);
            }

            if (widthConstraint.IsConstrained)
            {
                s.Width = widthConstraint.AvailableSize;
            }
            if (heightConstraint.IsConstrained)
            {
                s.Height = heightConstraint.AvailableSize;
            }

            var childWidthConstraint  = horizontalScrollPolicy == ScrollPolicy.Never ? widthConstraint : SizeConstraint.Unconstrained;
            var childHeightConstraint = verticalScrollPolicy == ScrollPolicy.Never ? heightConstraint : SizeConstraint.Unconstrained;
            var schild = ((ViewBackend)child).Frontend.Surface.GetPreferredSize(childWidthConstraint, childHeightConstraint, true);

            if (horizontalScrollPolicy == ScrollPolicy.Never)
            {
                s.Width = Math.Max(s.Width, schild.Width);
            }
            if (verticalScrollPolicy == ScrollPolicy.Never)
            {
                s.Height = Math.Max(s.Height, schild.Height);
            }
            return(s);
        }
Пример #28
0
            public void GetHashCode_DifferentSizes_DifferentHashCode()
            {
                var constraint1 = SizeConstraint.Size(100, 200);
                var constraint2 = SizeConstraint.Size(101, 200);

                Assert.AreNotEqual(constraint1.GetHashCode(), constraint2.GetHashCode());
            }
Пример #29
0
        public override void Arrange(IFigure parent)
        {
            var clientArea = _padding.GetClientArea(parent.Bounds);
            var constraint = new SizeConstraint(clientArea.Size);

            var itemTop = parent.Top + _padding.Top;

            foreach (var child in parent.Children)
            {
                if (child.IsVisible)
                {
                    var csize = child.PreferredSize;
                    child.Location = new Point(parent.Left + _padding.Left, itemTop);
                    if (_adjustItemWidth)
                    {
                        child.Width = clientArea.Width;
                    }
                    child.Height = csize.Height;
                    itemTop     += child.Height + ItemSpace;
                }
            }

            if (_extendLast && parent.Children.Count > 0)
            {
                /// 最後のchildを残りいっぱいの大きさにする
                var lastItem = parent.Children.Last();
                lastItem.Height = clientArea.Bottom - lastItem.Top;
            }
        }
Пример #30
0
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            var size    = base.OnGetPreferredSize(widthConstraint, heightConstraint);
            var content = GetContentBound();

            return(content.Size + new Size(10, 10));
        }
Пример #31
0
 protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
 {
     foreach (DockItem item in items.GetVisibleItems())
     {
         item.Panel?.Surface.GetPreferredSize();
     }
     return(items.GetBound(0, 0).Size);
 }
Пример #32
0
 protected override Size OnGetPreferredSize(SizeConstraint width, SizeConstraint height)
 {
     //if (Child != null)
     //    Child.SizeRequest();
     //vScrollBar.SizeRequest();
     //hScrollBar.SizeRequest();
     return(base.OnGetPreferredSize(width, height));
 }
Пример #33
0
		public override Size GetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			var s = base.GetPreferredSize (widthConstraint, heightConstraint);

			// If the label is ellipsized or can wrap then the width can't be dermined unless we have a constraint.
			// If there is no constraint, just return the smallest size
			if (!widthConstraint.IsConstrained && (Wrap != WrapMode.None || Ellipsize != EllipsizeMode.None))
				s.Width = 1;
			return s;
		}
Пример #34
0
		public virtual Size GetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			try {
				SetSizeConstraints (widthConstraint, heightConstraint);
				gettingPreferredSize = true;
				var sr = Widget.SizeRequest ();
				return new Size (sr.Width, sr.Height);
			} finally {
				gettingPreferredSize = false;
			}
		}
Пример #35
0
		public virtual Size GetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			SetSizeConstraints (widthConstraint, heightConstraint);

			int min_width = 0;
			int min_height = 0;

			IWidgetBackend xwt_backend = Widget as IWidgetBackend;
			if (xwt_backend != null) {
				var size = xwt_backend.GetPreferredSize (widthConstraint, heightConstraint);
				min_width = (int)size.Width;
				min_height = (int)size.Height;
			} else {
				int nat_width, nat_height;
				if (widthConstraint.IsConstrained) {
					Widget.GetPreferredHeightForWidth((int)widthConstraint.AvailableSize, out min_height, out nat_height);
				}
				else if (heightConstraint.IsConstrained) {
					Widget.GetPreferredWidthForHeight ((int)heightConstraint.AvailableSize, out min_width, out nat_width);
				} else if ((heightConstraint.IsConstrained) && (widthConstraint.IsConstrained)) {
				} else {
					Widget.GetPreferredHeight (out min_height, out nat_height);
					Widget.GetPreferredWidth (out min_width, out nat_width);
				}
			}

			if ((enabledEvents & WidgetEvent.PreferredSizeCheck) != 0) {
				SizeConstraint wc = SizeConstraint.Unconstrained, hc = SizeConstraint.Unconstrained;
				var cp = Widget.Parent as IConstraintProvider;
				if (cp != null)
					cp.GetConstraints (Widget, out wc, out hc);

				ApplicationContext.InvokeUserCode (delegate {
					var w = eventSink.GetPreferredSize (wc, hc);
					min_width = (int) w.Width;
					min_height = (int) w.Height;
				});
			}

			if (Widget.WidthRequest > min_width)
				min_width = Widget.WidthRequest;
			if (Widget.HeightRequest > min_height)
				min_height = Widget.HeightRequest;

			if (Frontend.MinWidth > 0 && Frontend.MinWidth > min_width)
				min_width = (int) Frontend.MinWidth;

			if (Frontend.MinHeight > 0 && Frontend.MinHeight > min_height)
				min_height = (int) Frontend.MinHeight;

			return new Size(min_width, min_height);
		}
Пример #36
0
		// The size of the container is the size of the child,
		// so we redirect size calculations to the child.

		public override Size GetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			return child != null ? child.Surface.GetPreferredSize (widthConstraint, heightConstraint) : Size.Zero;
		}
Пример #37
0
 public override Size GetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
 {
     return Size.Zero;
 }
Пример #38
0
 public void GetConstraints(Gtk.Widget target, out SizeConstraint width, out SizeConstraint height)
 {
     width = height = SizeConstraint.Unconstrained;
 }
Пример #39
0
		public override Size GetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint) {
			Size preSize = base.GetPreferredSize(widthConstraint, heightConstraint);

			if(Button.Content is string) {
				string label = (string)Button.Content;
				System.Windows.Media.FormattedText formattedText = new System.Windows.Media.FormattedText(label, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
									new Typeface(Button.FontFamily, Button.FontStyle, Button.FontWeight, Button.FontStretch), Button.FontSize, null);
				double formattedTextWidth = formattedText.WidthIncludingTrailingWhitespace;
				preSize.Width = formattedTextWidth + 10;
			}

			return preSize;
		}
Пример #40
0
 // The GetPreferredSize method is called when the corresponding OnGetPreferredSize method in the
 // XWT widget is not overriden, or if it is overriden and the new implementation calls
 // base.OnGetPreferredSize. For this reason, we have to ensure that the widget's MeasureOverride
 // method doesn't end calling the frontend OnGetPreferredSize method. To avoid it we set
 // the calculatingPreferredSize flag to true, and we check this flag in MeasureOverride
 public virtual Size GetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
 {
     SW.Size size;
     Widget.InvalidateMeasure ();
     GetWidgetDesiredSize (widthConstraint.IsConstrained ? widthConstraint.AvailableSize : Double.PositiveInfinity, heightConstraint.IsConstrained ? heightConstraint.AvailableSize : Double.PositiveInfinity, out size);
     return new Size (size.Width, size.Height);
 }
Пример #41
0
		public override Size GetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			if (panel1.HasWidget && panel2.HasWidget) {
				double w, h;
				if (direction == Orientation.Horizontal) {
					var s1 = panel1.WidgetSurface.GetPreferredSize (SizeConstraint.Unconstrained, heightConstraint);
					var s2 = panel2.WidgetSurface.GetPreferredSize (SizeConstraint.Unconstrained, heightConstraint);
					w = s1.Width + s2.Width + SplitterSize;
					h = Math.Max (s1.Height, s2.Height);
				}
				else {
					var s1 = panel1.WidgetSurface.GetPreferredSize (widthConstraint, SizeConstraint.Unconstrained);
					var s2 = panel2.WidgetSurface.GetPreferredSize (widthConstraint, SizeConstraint.Unconstrained);
					h = s1.Height + s2.Height + SplitterSize;
					w = Math.Max (s1.Width, s2.Width);
				}
				if (direction == Orientation.Horizontal && widthConstraint.IsConstrained && w > widthConstraint.AvailableSize)
					w = widthConstraint.AvailableSize;
				if (direction == Orientation.Vertical && heightConstraint.IsConstrained && h > heightConstraint.AvailableSize)
					h = heightConstraint.AvailableSize;
				return new Size (w, h);
			}
			else if (panel1.HasWidget)
				return panel1.WidgetSurface.GetPreferredSize (widthConstraint, heightConstraint);
			else if (panel2.HasWidget)
				return panel2.WidgetSurface.GetPreferredSize (widthConstraint, heightConstraint);
			else
				return Size.Zero;
		}
Пример #42
0
		public void GetConstraints (Gtk.Widget target, out SizeConstraint width, out SizeConstraint height)
		{
			width = RequestedSize.Width;
			height = RequestedSize.Height;
		}
Пример #43
0
		public void GetConstraints (Gtk.Widget target, out SizeConstraint width, out SizeConstraint height)
		{
			backend.GetConstraints (this, out width, out height);
		}
Пример #44
0
		public override Size GetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint) {
			Size baseSize = base.GetPreferredSize(widthConstraint, heightConstraint);
			Size outputSize = new Size(longestItemWidth > 0 ? longestItemWidth + COMBO_BOX_STARTING_WIDTH : baseSize.Width, baseSize.Height);
			return outputSize;
		}
Пример #45
0
		Size IWidgetBackend.GetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			return Surface.GetPreferredSize (widthConstraint, heightConstraint);
		}