Пример #1
0
        internal override void AdjustSize()
        {
            if (Resizable || !shown)
            {
                base.AdjustSize();
                shown = true;
                return;
            }
            Size mMinSize, mDecorationsSize;

            Backend.GetMetrics(out mMinSize, out mDecorationsSize);

            var ws = mDecorationsSize;

            if (Content != null)
            {
                IWidgetSurface s = Content.Surface;
                ws += s.GetPreferredSize(true);
            }
            ws.Width  += Padding.HorizontalSpacing;
            ws.Height += Padding.VerticalSpacing;

            if (ws.Width < mMinSize.Width)
            {
                ws.Width = mMinSize.Width;
            }
            if (ws.Height < mMinSize.Height)
            {
                ws.Height = mMinSize.Height;
            }

            Backend.SetSize(ws.Width, ws.Height);
        }
Пример #2
0
        protected override void OnSizeRequested(ref Gtk.Requisition requisition)
        {
            base.OnSizeRequested(ref requisition);
            IWidgetSurface ws = Frontend.Surface;
            int            h, w;

            if (ws.SizeRequestMode == SizeRequestMode.HeightForWidth)
            {
                w = (int)ws.GetPreferredWidth().MinSize;
                h = (int)ws.GetPreferredHeightForWidth(w).MinSize;
            }
            else
            {
                h = (int)ws.GetPreferredHeight().MinSize;
                w = (int)ws.GetPreferredWidthForHeight(h).MinSize;
            }
            if (requisition.Width < w)
            {
                requisition.Width = w;
            }
            if (requisition.Height < h)
            {
                requisition.Height = h;
            }
            foreach (var cr in children)
            {
                cr.Key.SizeRequest();
            }
        }
Пример #3
0
        protected override void OnSizeRequested(ref Gtk.Requisition requisition)
        {
            IWidgetSurface ws = Frontend;
            int            w  = (int)ws.GetPreferredWidth().MinSize;
            int            h  = (int)ws.GetPreferredHeight().MinSize;

            requisition.Width  = w;
            requisition.Height = h;
        }
Пример #4
0
        internal void AdjustSize()
        {
            if (child == null)
            {
                return;
            }

            IWidgetSurface s = child.Surface;

            var size = shown ? Size : initialBounds.Size;

            var w = s.GetPreferredWidth();

            if (!shown && !widthSet)
            {
                size.Width = w.NaturalSize + padding.HorizontalSpacing;
            }

            var h = s.GetPreferredHeightForWidth(size.Width - padding.HorizontalSpacing);

            if (!shown && !heightSet)
            {
                size.Height = h.NaturalSize + padding.VerticalSpacing;
            }

            if (w.MinSize + padding.HorizontalSpacing > size.Width)
            {
                size.Width = w.MinSize + padding.HorizontalSpacing;
            }
            if (h.MinSize + padding.VerticalSpacing > size.Height)
            {
                size.Height = h.MinSize + padding.VerticalSpacing;
            }

            if (!BackendHost.EngineBackend.HandlesSizeNegotiation || !shown)
            {
                shown = true;

                if (size != Size)
                {
                    if (locationSet)
                    {
                        Backend.Bounds = new Rectangle(initialBounds.X, initialBounds.Y, size.Width, size.Height);
                    }
                    else
                    {
                        Size = size + Backend.ImplicitMinSize;
                    }
                }
                else if (locationSet)
                {
                    Backend.Move(initialBounds.X, initialBounds.Y);
                }

                Backend.SetMinSize(Backend.ImplicitMinSize + new Size(w.MinSize + padding.HorizontalSpacing, h.MinSize + padding.VerticalSpacing));
            }
        }
Пример #5
0
        void OnChildPreferredSizeChanged()
        {
            IWidgetSurface surface = this;

            if (Parent != null && resizeRequestQueue.Contains(Parent))
            {
                // Size for this widget will be checked when checking the parent
                surface.ResetCachedSizes();
                return;
            }

            // Determine if the size change of the child implies a size change
            // of this widget. If it does, the size change notification
            // has to be propagated to the parent

            var oldWidth  = width;
            var oldHeight = height;

            surface.ResetCachedSizes();

            bool changed = true;

            if (surface.SizeRequestMode == SizeRequestMode.HeightForWidth)
            {
                var nw = surface.GetPreferredWidth();
                if (nw == oldWidth)
                {
                    var nh = surface.GetPreferredHeightForWidth(Backend.Size.Width);
                    if (nh == oldHeight)
                    {
                        changed = false;
                    }
                }
            }
            else
            {
                var nh = surface.GetPreferredHeight();
                if (nh == oldHeight)
                {
                    var nw = surface.GetPreferredWidthForHeight(Backend.Size.Height);
                    if (nw == oldWidth)
                    {
                        changed = false;
                    }
                }
            }
            if (changed)
            {
                NotifySizeChangeToParent();
            }
            else
            {
                QueueForReallocate(this);
            }
        }
Пример #6
0
 void Dump(IWidgetSurface w, int ind)
 {
     if (w == null)
     {
         return;
     }
     Console.WriteLine(new string (' ', ind * 2) + " " + w.GetType().Name + " " + w.GetPreferredWidth() + " " + w.GetPreferredHeight());
     foreach (var c in w.Children)
     {
         Dump(c, ind + 1);
     }
 }
Пример #7
0
        protected virtual void OnChildPreferredSizeChanged(Widget w)
        {
            if (Parent != null && (!widthCached || !heightCached))
            {
                Parent.OnChildPreferredSizeChanged(w);
                return;
            }

            var oldWidth  = width;
            var oldHeight = height;

            bool           notifyParent = Parent != null;
            IWidgetSurface surface      = this;

            surface.ResetCachedSizes();

            if (surface.SizeRequestMode == SizeRequestMode.HeightForWidth)
            {
                var nw = surface.GetPreferredWidth();
                if (nw == oldWidth)
                {
                    var nh = surface.GetPreferredHeightForWidth(Backend.Size.Width);
                    if (nh == oldHeight)
                    {
                        notifyParent = false;
                    }
                }
            }
            else
            {
                var nh = surface.GetPreferredHeight();
                if (nh == oldHeight)
                {
                    var nw = surface.GetPreferredWidthForHeight(Backend.Size.Height);
                    if (nw == oldWidth)
                    {
                        notifyParent = false;
                    }
                }
            }
            if (notifyParent)
            {
                if (Parent != null)
                {
                    Parent.OnChildPreferredSizeChanged(this);
                }
            }
            else
            {
                surface.Reallocate();
            }
        }
Пример #8
0
        WidgetSize GetPreferredLengthForSize(SizeRequestMode mode, Widget w, double width)
        {
            IWidgetSurface surface = w;

            if (mode == SizeRequestMode.WidthForHeight)
            {
                return(surface.GetPreferredWidthForHeight(width));
            }
            else
            {
                return(surface.GetPreferredHeightForWidth(width));
            }
        }
Пример #9
0
        protected virtual void OnPreferredSizeChanged()
        {
            IWidgetSurface surface = this;

            surface.ResetCachedSizes();
            Backend.UpdateLayout();
            if (Parent != null)
            {
                if (resizeRequestQueue.Count == 0)
                {
                    Application.Invoke(DelayedResizeRequest);
                }
                resizeRequestQueue.Add(this);
            }
        }
Пример #10
0
        void AdjustSize()
        {
            IWidgetSurface s = child;
            var            w = s.GetPreferredWidth().MinSize;

            if (w > Width)
            {
                Width = w;
            }
            var h = s.GetPreferredHeightForWidth(Width).MinSize;

            if (h > Height)
            {
                Height = h;
            }
        }
Пример #11
0
        protected virtual void OnPreferredSizeChanged()
        {
            // When the preferred size changes, we reset the sizes we have cached
            // The parent also has to be notified of the size change, since it
            // may imply a change of the size of the parent. However, we don't do
            // it immediately, but we queue the resizing request

            IWidgetSurface surface = this;

            surface.ResetCachedSizes();
            Backend.UpdateLayout();
            if (!Application.EngineBackend.HandlesSizeNegotiation)
            {
                NotifySizeChangeToParent();
            }
        }
Пример #12
0
        void HandleSizeRequested(object o, Gtk.SizeRequestedArgs args)
        {
            IWidgetSurface ws = (IWidgetSurface)Frontend;

            Gtk.Requisition req = args.Requisition;
            int             w   = (int)ws.GetPreferredWidth().MinSize;
            int             h   = (int)ws.GetPreferredHeight().MinSize;

            if (req.Width < w)
            {
                req.Width = w;
            }
            if (req.Height < h)
            {
                req.Height = h;
            }
            args.Requisition = req;
        }
Пример #13
0
        protected override void OnSizeRequested(ref Gtk.Requisition requisition)
        {
            IWidgetSurface ws = Frontend;
            int            w  = (int)ws.GetPreferredWidth().MinSize;
            int            h  = (int)ws.GetPreferredHeight().MinSize;

            if (requisition.Width < w)
            {
                requisition.Width = w;
            }
            if (requisition.Height < h)
            {
                requisition.Height = h;
            }
            foreach (var cr in children)
            {
                cr.Key.SizeRequest();
            }
        }
Пример #14
0
 void Dump(IWidgetSurface w, int ind)
 {
     if (w == null)
         return;
     Console.WriteLine (new string (' ', ind * 2) + " " + w.GetType ().Name + " " + w.GetPreferredWidth () + " " + w.GetPreferredHeight ());
     foreach (var c in w.Children)
         Dump (c, ind + 1);
 }
Пример #15
0
        internal override void AdjustSize()
        {
            Size mMinSize, mDecorationsSize;

            Backend.GetMetrics(out mMinSize, out mDecorationsSize);

            var size = shown ? Size : initialBounds.Size;

            var wc = (shown || widthSet) ? SizeConstraint.WithSize(Math.Max(size.Width - padding.HorizontalSpacing - mDecorationsSize.Width, mMinSize.Width)) : SizeConstraint.Unconstrained;
            var hc = (shown || heightSet) ? SizeConstraint.WithSize(Math.Max(size.Height - padding.VerticalSpacing - mDecorationsSize.Height, mMinSize.Height)) : SizeConstraint.Unconstrained;

            var ws = mDecorationsSize;

            if (child != null)
            {
                IWidgetSurface s = child.Surface;
                ws += s.GetPreferredSize(wc, hc, true);
            }
            ws.Width  += padding.HorizontalSpacing;
            ws.Height += padding.VerticalSpacing;

            if (!shown)
            {
                if (!widthSet)
                {
                    size.Width = ws.Width;
                }
                if (!heightSet)
                {
                    size.Height = ws.Height;
                }
            }

            if (ws.Width < mMinSize.Width)
            {
                ws.Width = mMinSize.Width;
            }
            if (ws.Height < mMinSize.Height)
            {
                ws.Height = mMinSize.Height;
            }

            if (ws.Width > size.Width)
            {
                size.Width = ws.Width;
            }
            if (ws.Height > size.Height)
            {
                size.Height = ws.Height;
            }

            if (!shown)
            {
                shown = true;

                if (!locationSet && initialLocation != WindowLocation.Manual)
                {
                    Point center;
                    if (initialLocation == WindowLocation.CenterScreen || TransientFor == null)
                    {
                        center = Desktop.PrimaryScreen.VisibleBounds.Center;
                    }
                    else
                    {
                        center = TransientFor.ScreenBounds.Center;
                    }
                    initialBounds.X = Math.Round(center.X - size.Width / 2);
                    initialBounds.Y = Math.Round(center.Y - size.Height / 2);
                    locationSet     = true;
                }

                if (size != Size)
                {
                    if (locationSet)
                    {
                        Backend.Bounds = new Rectangle(initialBounds.X, initialBounds.Y, size.Width, size.Height);
                    }
                    else
                    {
                        Backend.SetSize(size.Width, size.Height);
                    }
                }
                else if (locationSet && !shown)
                {
                    Backend.Move(initialBounds.X, initialBounds.Y);
                }
            }
            else
            {
                if (size != Size)
                {
                    Backend.SetSize(size.Width, size.Height);
                }
            }
            Backend.SetMinSize(new Size(ws.Width, ws.Height));
        }
Пример #16
0
        internal override void AdjustSize()
        {
            if (child == null)
            {
                return;
            }

            IWidgetSurface s = child.Surface;

            var size = shown ? Size : initialBounds.Size;

            var wc = (shown || widthSet) ? SizeConstraint.WithSize(size.Width - padding.HorizontalSpacing) : SizeConstraint.Unconstrained;
            var hc = (shown || heightSet) ? SizeConstraint.WithSize(size.Height - padding.VerticalSpacing) : SizeConstraint.Unconstrained;

            var ws = s.GetPreferredSize(wc, hc, true);

            if (!shown)
            {
                if (!widthSet)
                {
                    size.Width = ws.Width + padding.HorizontalSpacing;
                }
                if (!heightSet)
                {
                    size.Height = ws.Height + padding.VerticalSpacing;
                }
            }

            if (ws.Width + padding.HorizontalSpacing > size.Width)
            {
                size.Width = ws.Width + padding.HorizontalSpacing;
            }
            if (ws.Height + padding.VerticalSpacing > size.Height)
            {
                size.Height = ws.Height + padding.VerticalSpacing;
            }

            size += Backend.ImplicitMinSize;

            if (!shown)
            {
                shown = true;

                if (size != Size)
                {
                    if (locationSet)
                    {
                        Backend.Bounds = new Rectangle(initialBounds.X, initialBounds.Y, size.Width, size.Height);
                    }
                    else
                    {
                        Backend.SetSize(size.Width, size.Height);
                    }
                }
                else if (locationSet && !shown)
                {
                    Backend.Move(initialBounds.X, initialBounds.Y);
                }

                Backend.SetMinSize(Backend.ImplicitMinSize + new Size(ws.Width + padding.HorizontalSpacing, ws.Height + padding.VerticalSpacing));
            }
            else
            {
                if (size != Size)
                {
                    Backend.SetSize(size.Width, size.Height);
                }
            }
        }