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; }
/// <summary> /// A default implementation of MeasureOverride to be used by all WPF widgets /// </summary> /// <param name="constraint">Size constraints</param> /// <param name="wpfMeasure">Size returned by the base MeasureOverride</param> /// <returns></returns> public System.Windows.Size MeasureOverride(System.Windows.Size constraint, System.Windows.Size wpfMeasure) { var defNaturalSize = eventSink.GetDefaultNaturalSize(); // -2 means use the WPF default, -1 use the XWT default, any other other value is used as custom natural size var nw = DefaultNaturalWidth; if (nw == -1) { nw = defNaturalSize.Width; if (nw == 0) { nw = wpfMeasure.Width; } wpfMeasure.Width = nw; } else if (nw != -2) { wpfMeasure.Width = nw; } var nh = DefaultNaturalHeight; if (nh == -1) { nh = defNaturalSize.Height; if (nh == 0) { nh = wpfMeasure.Height; } wpfMeasure.Height = nh; } else if (nh != -2) { wpfMeasure.Height = nh; } // If we are calculating the default preferred size of the widget we end here. // See note above about when GetPreferred* methods are called. if (calculatingPreferredSize) { return(wpfMeasure); } if ((enabledEvents & WidgetEvent.PreferredSizeCheck) != 0) { Context.InvokeUserCode(delegate { // Calculate the preferred width through the frontend if there is an overriden OnGetPreferredWidth, but only do it // if we are not given a constraint. If there is a width constraint, we'll use that constraint value for calculating the height var cw = double.IsPositiveInfinity(constraint.Width) ? SizeConstraint.Unconstrained : constraint.Width; var ch = double.IsPositiveInfinity(constraint.Height) ? SizeConstraint.Unconstrained : constraint.Height; var ws = eventSink.GetPreferredSize(cw, ch); wpfMeasure = new System.Windows.Size(ws.Width, ws.Height); }); } return(wpfMeasure); }