Beispiel #1
0
        void SizeRequestGrid(Grid grid, ref Gtk.Requisition req)
        {
            bool visible = true;

            req.Width = req.Height = 0;
            foreach (object obj in grid.lines)
            {
                if (obj is Expander)
                {
                    Gtk.Widget      w = (Gtk.Widget)obj;
                    Gtk.Requisition childreq;

                    childreq = w.SizeRequest();
                    if (req.Width < childreq.Width)
                    {
                        req.Width = childreq.Width;
                    }
                    req.Height += groupPad + childreq.Height;

                    visible = ((Gtk.Expander)obj).Expanded;

                    if (indent == -1)
                    {
                        // Seems like there should be an easier way...
                        int focusWidth      = (int)w.StyleGetProperty("focus-line-width");
                        int focusPad        = (int)w.StyleGetProperty("focus-padding");
                        int expanderSize    = (int)w.StyleGetProperty("expander-size");
                        int expanderSpacing = (int)w.StyleGetProperty("expander-spacing");
                        indent = focusWidth + focusPad + expanderSize + 2 * expanderSpacing;
                    }
                }
                else if (obj is Widget)
                {
                    Gtk.Widget      w = (Gtk.Widget)obj;
                    Gtk.Requisition childreq;

                    childreq = w.SizeRequest();
                    if (lwidth < childreq.Width)
                    {
                        lwidth = childreq.Width;
                    }
                    if (visible)
                    {
                        req.Height += linePad + childreq.Height;
                    }
                }
                else if (obj is Pair)
                {
                    Pair            p = (Pair)obj;
                    Gtk.Requisition lreq, ereq;

                    lreq = p.Label.SizeRequest();
                    ereq = p.Editor.SizeRequest();

                    if (lineHeight == -1)
                    {
                        lineHeight = (int)(1.5 * lreq.Height);
                    }

                    if (lreq.Width > lwidth)
                    {
                        lwidth = lreq.Width;
                    }
                    if (ereq.Width > ewidth)
                    {
                        ewidth = ereq.Width;
                    }

                    if (visible)
                    {
                        req.Height += Math.Max(lineHeight, ereq.Height) + linePad;
                    }
                }
            }

            req.Width   = Math.Max(req.Width, indent + lwidth + hPad + ewidth);
            req.Height += 2 * (int)BorderWidth;
            req.Width  += 2 * (int)BorderWidth;
        }