void HandleWidgetSizeAllocated(object o, Gtk.SizeAllocatedArgs args) { if ((enabledEvents & sizeCheckEvents) == 0) { // If no sizing event is set, it means this handler was set because there is a min size. // In that case, there isn't any thing left to do here return; } Toolkit.Invoke(delegate { if (sizeCheckStep == SizeCheckStep.SizeRequest) { Console.WriteLine("SizeRequest not called. Should not happen"); } else if (sizeCheckStep == SizeCheckStep.PreAllocate || sizeCheckStep == SizeCheckStep.AdjustSize) { if (EventSink.GetSizeRequestMode() == SizeRequestMode.HeightForWidth) { realRequestedWidth = args.Allocation.Width; Toolkit.Invoke(delegate { realRequestedHeight = (int)eventSink.OnGetPreferredHeightForWidth(args.Allocation.Width).MinSize; }); sizeCheckStep = SizeCheckStep.AdjustSize; Widget.QueueResize(); } else { realRequestedHeight = args.Allocation.Height; Toolkit.Invoke(delegate { realRequestedWidth = (int)eventSink.OnGetPreferredWidthForHeight(args.Allocation.Height).MinSize; }); sizeCheckStep = SizeCheckStep.AdjustSize; Widget.QueueResize(); } } }); }
void HandleWidgetSizeRequested(object o, Gtk.SizeRequestedArgs args) { if (gettingPreferredSize) { return; } var req = args.Requisition; if ((enabledEvents & sizeCheckEvents) == 0) { // If no sizing event is set, it means this handler was set because there is a min size. if (Frontend.MinWidth != -1) { req.Width = (int)Frontend.MinWidth; } if (Frontend.MinHeight != -1) { req.Height = (int)Frontend.MinHeight; } return; } if (sizeCheckStep == SizeCheckStep.AdjustSize) { req.Width = realRequestedWidth; req.Height = realRequestedHeight; sizeCheckStep = SizeCheckStep.FinalAllocate; } else { Toolkit.Invoke(delegate { if (EventSink.GetSizeRequestMode() == SizeRequestMode.HeightForWidth) { if ((enabledEvents & WidgetEvent.PreferredWidthCheck) != 0) { var w = eventSink.OnGetPreferredWidth(); req.Width = (int)w.MinSize; } if ((enabledEvents & WidgetEvent.PreferredHeightForWidthCheck) != 0) { if (doubleSizeRequestCheckSupported) { sizeCheckStep = SizeCheckStep.PreAllocate; realRequestedWidth = req.Width; // Store the width, since it will be used in the next iteration } else { var h = eventSink.OnGetPreferredHeightForWidth(req.Width); req.Height = (int)h.MinSize; sizeCheckStep = SizeCheckStep.FinalAllocate; } } else if ((enabledEvents & WidgetEvent.PreferredHeightCheck) != 0) { var h = eventSink.OnGetPreferredHeight(); req.Height = (int)h.MinSize; sizeCheckStep = SizeCheckStep.FinalAllocate; } } else { if ((enabledEvents & WidgetEvent.PreferredHeightCheck) != 0) { var h = eventSink.OnGetPreferredHeight(); req.Height = (int)h.MinSize; } if ((enabledEvents & WidgetEvent.PreferredWidthForHeightCheck) != 0) { if (doubleSizeRequestCheckSupported) { sizeCheckStep = SizeCheckStep.PreAllocate; realRequestedHeight = req.Height; // Store the height, since it will be used in the next iteration } else { var w = eventSink.OnGetPreferredWidthForHeight(req.Height); req.Width = (int)w.MinSize; sizeCheckStep = SizeCheckStep.FinalAllocate; } } else if ((enabledEvents & WidgetEvent.PreferredWidthCheck) != 0) { var w = eventSink.OnGetPreferredWidth(); req.Width = (int)w.MinSize; sizeCheckStep = SizeCheckStep.FinalAllocate; } } }); } 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) { // Calculate the natural size, if that's what is being measured if (gettingNaturalSize) { 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); } Context.InvokeUserCode(delegate { if (eventSink.GetSizeRequestMode() == SizeRequestMode.HeightForWidth) { // 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 if ((enabledEvents & WidgetEvent.PreferredWidthCheck) != 0 && constraint.Width == Double.PositiveInfinity) { var ws = eventSink.OnGetPreferredWidth(); wpfMeasure.Width = constraint.Width = gettingNaturalSize ? ws.NaturalSize : ws.MinSize; } // Now calculate the preferred height for that width, also using the override if available if ((enabledEvents & WidgetEvent.PreferredHeightForWidthCheck) != 0) { var ws = eventSink.OnGetPreferredHeightForWidth(constraint.Width); wpfMeasure.Height = gettingNaturalSize ? ws.NaturalSize : ws.MinSize; } } else { // Calculate the preferred height through the frontend, if there is an overriden OnGetPreferredHeight if ((enabledEvents & WidgetEvent.PreferredHeightCheck) != 0 && constraint.Height == Double.PositiveInfinity) { var ws = eventSink.OnGetPreferredHeight(); wpfMeasure.Height = constraint.Height = gettingNaturalSize ? ws.NaturalSize : ws.MinSize; } // Now calculate the preferred width for that height, also using the override if available if ((enabledEvents & WidgetEvent.PreferredWidthForHeightCheck) != 0) { var ws = eventSink.OnGetPreferredWidthForHeight(constraint.Height); wpfMeasure.Width = gettingNaturalSize ? ws.NaturalSize : ws.MinSize; } } }); return(wpfMeasure); }