internal static VBox CreateCategory(string categoryName, string categoryContentMarkup, Cairo.Color foreColor, Pango.FontDescription font)
        {
            var vbox = new VBox();

            vbox.Spacing = 8;

            if (categoryName != null)
            {
                var catLabel = new FixedWidthWrapLabel();
                catLabel.Markup = categoryName;
                catLabel.ModifyFg(StateType.Normal, foreColor.ToGdkColor());
                catLabel.FontDescription        = font.Copy();
                catLabel.FontDescription.Weight = Pango.Weight.Bold;
                catLabel.FontDescription.Size   = catLabel.FontDescription.Size + (int)(1 * Pango.Scale.PangoScale);
                vbox.PackStart(catLabel, false, true, 0);
            }

            var  contentLabel = new FixedWidthWrapLabel();
            HBox hbox         = new HBox();

            // hbox.PackStart (new Label(), false, true, 10);


            contentLabel.Wrap               = Pango.WrapMode.WordChar;
            contentLabel.Spacing            = 1;
            contentLabel.BreakOnCamelCasing = false;
            contentLabel.BreakOnPunctuation = false;
            contentLabel.MaxWidth           = 400;
            contentLabel.Markup             = categoryContentMarkup.Trim();
            contentLabel.ModifyFg(StateType.Normal, foreColor.ToGdkColor());
            contentLabel.FontDescription = font;

            hbox.PackStart(contentLabel, true, true, 0);
            vbox.PackStart(hbox, true, true, 0);

            return(vbox);
        }
Exemplo n.º 2
0
        void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y)
        {
            if (!heightMeasured)
            {
                return;
            }

            Pango.Layout layout       = new Pango.Layout(PangoContext);
            TableRow     lastCategory = null;

            Pango.FontDescription defaultFont = new Pango.FontDescription();
            Pango.FontDescription changedFont = defaultFont.Copy();
            defaultFont.Weight = Pango.Weight.Bold;

            foreach (var r in rowList)
            {
                int w, h;
                layout.SetText(r.Label);
                if (r.IsDefaultValue && (r.Expanded || HasDefaultValue(r.ChildRows)))
                {
                    layout.FontDescription = changedFont;
                }
                else
                {
                    layout.FontDescription = defaultFont;
                }
                layout.GetPixelSize(out w, out h);
                int indent = 0;

                if (r.IsCategory)
                {
                    var rh = h + CategoryTopBottomPadding * 2;
                    ctx.Rectangle(0, y, Allocation.Width, rh);
                    using (var gr = new LinearGradient(0, y, 0, rh)) {
                        gr.AddColorStop(0, new Cairo.Color(248d / 255d, 248d / 255d, 248d / 255d));
                        gr.AddColorStop(1, new Cairo.Color(240d / 255d, 240d / 255d, 240d / 255d));
                        ctx.SetSource(gr);
                        ctx.Fill();
                    }

                    if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand)
                    {
                        ctx.MoveTo(0, y + 0.5);
                        ctx.LineTo(Allocation.Width, y + 0.5);
                    }
                    ctx.MoveTo(0, y + rh - 0.5);
                    ctx.LineTo(Allocation.Width, y + rh - 0.5);
                    ctx.SetSourceColor(DividerColor);
                    ctx.Stroke();

                    ctx.MoveTo(x, y + CategoryTopBottomPadding);
                    ctx.SetSourceColor(CategoryLabelColor);
                    Pango.CairoHelper.ShowLayout(ctx, layout);

                    var img  = r.Expanded ? discloseUp : discloseDown;
                    var area = GetCategoryArrowArea(r);

                    CairoHelper.SetSourcePixbuf(ctx, img, area.X + (area.Width - img.Width) / 2, area.Y + (area.Height - img.Height) / 2);
                    ctx.Paint();

                    y           += rh;
                    lastCategory = r;
                }
                else
                {
                    var cell = GetCell(r);
                    r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject;
                    var state = r.Enabled ? State : Gtk.StateType.Insensitive;
                    ctx.Save();

                    if (r == lastEditorRow)
                    {
                        ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                        ctx.SetSourceColor(new Cairo.Color(0.8, 0.9, 1.0, 1));
                        ctx.Fill();


                        //int dividerX = (int)((double)Allocation.Width * dividerPosition);
                        //var cell = GetCell(r);
                        //cell.GetSize(Allocation.Width - dividerX, out w, out eh);
                        //eh = Math.Max(h + PropertyTopBottomPadding * 2, eh);
                        //r.EditorBounds = new Gdk.Rectangle(dividerX + PropertyContentLeftPadding, y, Allocation.Width - dividerX - PropertyContentLeftPadding, eh);

                        //var bounds = new Gdk.Rectangle(dividerX + 1, r.EditorBounds.Y, Allocation.Width - dividerX - 1, r.EditorBounds.Height);

                        //ctx.MoveTo(bounds.Right, bounds.Y+1);
                        //ctx.LineTo(bounds.X, bounds.Y+1);
                        //ctx.MoveTo(bounds.Right, bounds.Bottom);
                        //ctx.LineTo(bounds.X, bounds.Bottom);

                        //ctx.Stroke();

                        //ctx.Rectangle(dividerX + 1, r.EditorBounds.Y, Allocation.Width - dividerX - 1, r.EditorBounds.Height);
                        //ctx.SetSourceColor(new Cairo.Color(0.8, 0.9, 1.0, 1));
                        //ctx.Fill();
                    }

                    if (r.ChildRows != null && r.ChildRows.Count > 0)
                    {
                        var img = r.Expanded ? arrowLeft : arrowRight;
                        CairoHelper.SetSourcePixbuf(ctx, img, 2, y + (h + PropertyTopBottomPadding * 2) / 2 - img.Height / 2);
                        ctx.Paint();
                    }

                    ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                    ctx.Clip();
                    ctx.MoveTo(x, y + PropertyTopBottomPadding);
                    ctx.SetSourceColor(Style.Text(state).ToCairoColor());
                    Pango.CairoHelper.ShowLayout(ctx, layout);
                    ctx.Restore();

                    if (r != currentEditorRow)
                    {
                        cell.Render(GdkWindow, ctx, r.EditorBounds, state);
                    }

                    y     += r.EditorBounds.Height;
                    indent = PropertyIndent;
                }

                if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand))
                {
                    int py = y;

                    ctx.Save();
                    if (r.AnimatingExpand)
                    {
                        ctx.Rectangle(0, y, Allocation.Width, r.AnimationHeight);
                    }
                    else
                    {
                        ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height);
                    }

                    ctx.Clip();
                    Draw(ctx, r.ChildRows, dividerX, x + indent, ref y);
                    ctx.Restore();

                    if (r.AnimatingExpand)
                    {
                        y = py + r.AnimationHeight;
                        // Repaing the background because the cairo clip doesn't work for gdk primitives
                        int dx = (int)((double)Allocation.Width * dividerPosition);
                        ctx.Rectangle(0, y, dx, Allocation.Height - y);
                        ctx.SetSourceColor(LabelBackgroundColor);
                        ctx.Fill();
                        ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
                        ctx.SetSourceRGB(1, 1, 1);
                        ctx.Fill();
                    }
                }
            }
        }