Пример #1
0
        //FIXME: we could use the expose event's clipbox to make the drawing more efficient
        void DrawList(Gdk.EventExpose args)
        {
            var window = args.Window;

            int winWidth, winHeight;

            window.GetSize(out winWidth, out winHeight);

            int ypos      = margin;
            int lineWidth = winWidth - margin * 2;
            int xpos      = margin + padding;

            //avoid recreating the GC objects that we use multiple times
            var textGCNormal = this.Style.TextGC(StateType.Normal);
            var fgGCNormal   = this.Style.ForegroundGC(StateType.Normal);

            int n = 0;

            n = (int)(vadj.Value / rowHeight);

            while (ypos < winHeight - margin && n < win.DataProvider.Count)
            {
                bool hasMarkup = false;
                IMarkupListDataProvider <T> markupListDataProvider = win.DataProvider as IMarkupListDataProvider <T>;
                if (markupListDataProvider != null)
                {
                    if (markupListDataProvider.HasMarkup(n))
                    {
                        layout.SetMarkup(markupListDataProvider.GetMarkup(n) ?? "&lt;null&gt;");
                        hasMarkup = true;
                    }
                }

                if (!hasMarkup)
                {
                    layout.SetText(win.DataProvider.GetText(n) ?? "<null>");
                }

                Gdk.Pixbuf icon = win.DataProvider.GetIcon(n);
                int        iconHeight, iconWidth;

                if (icon != null)
                {
                    iconWidth  = icon.Width;
                    iconHeight = icon.Height;
                }
                else if (!Gtk.Icon.SizeLookup(Gtk.IconSize.Menu, out iconWidth, out iconHeight))
                {
                    iconHeight = iconWidth = 24;
                }

                int wi, he, typos, iypos;
                layout.GetPixelSize(out wi, out he);
                typos = he < rowHeight ? ypos + (rowHeight - he) / 2 : ypos;
                iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;

                if (n == selection)
                {
                    if (!disableSelection)
                    {
                        args.Window.DrawRectangle(this.Style.BaseGC(StateType.Selected),
                                                  true, margin, ypos, lineWidth, he + padding);
                        window.DrawLayout(this.Style.TextGC(StateType.Selected),
                                          xpos + iconWidth + 2, typos, layout);
                    }
                    else
                    {
                        window.DrawRectangle(this.Style.BaseGC(StateType.Selected),
                                             false, margin, ypos, lineWidth, he + padding);
                        window.DrawLayout(textGCNormal, xpos + iconWidth + 2, typos, layout);
                    }
                }
                else
                {
                    window.DrawLayout(textGCNormal, xpos + iconWidth + 2, typos, layout);
                }

                if (icon != null)
                {
                    window.DrawPixbuf(fgGCNormal, icon, 0, 0, xpos, iypos, iconWidth, iconHeight, Gdk.RgbDither.None, 0, 0);
                }

                ypos += rowHeight;
                n++;

                //reset the markup or it carries over to the next SetText
                if (hasMarkup)
                {
                    layout.SetMarkup(string.Empty);
                }
            }
        }
Пример #2
0
        //void SetAdjustments(Rectangle allocation)
        //{
        //    hadj.SetBounds(0, allocation.Width, 0, 0, allocation.Width);
        //    var height = System.Math.Max(allocation.Height, rowHeight * this.win.DataProvider.Count);
        //    vadj.SetBounds(0, height, rowHeight, allocation.Height, allocation.Height);
        //}

        //FIXME: we could use the expose event's clipbox to make the drawing more efficient
        protected override void OnDraw(Context cr, Rectangle dirtyRect)
        {
            var ypos      = margin;
            var lineWidth = Size.Width - margin * 2;
            int xpos      = margin + padding;

            //avoid recreating the GC objects that we use multiple times
            var textColor = Colors.Black;

            int n = 0;

            n = (int)(vadj.Value / rowHeight);

            while (ypos < Size.Height - margin && n < win.DataProvider.Count)
            {
                bool hasMarkup = false;
                IMarkupListDataProvider <T> markupListDataProvider = win.DataProvider as IMarkupListDataProvider <T>;
                if (markupListDataProvider != null)
                {
                    if (markupListDataProvider.HasMarkup(n))
                    {
                        layout.Markup = (markupListDataProvider.GetMarkup(n) ?? "&lt;null&gt;");
                        hasMarkup     = true;
                    }
                }

                if (!hasMarkup)
                {
                    layout.Text = (win.DataProvider.GetText(n) ?? "<null>");
                }

                var icon = win.DataProvider.GetIcon(n);
                int iconHeight, iconWidth;

                if (icon != null)
                {
                    iconWidth  = (int)icon.Width;
                    iconHeight = (int)icon.Height;
                }
                iconHeight = iconWidth = 24;

                var s = layout.GetSize();
                int typos, iypos;
                int he = (int)s.Height;

                typos = he < rowHeight ? ypos + (rowHeight - he) / 2 : ypos;
                iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;

                if (n == selection)
                {
                    if (!disableSelection)
                    {
                        cr.Rectangle(margin, ypos, lineWidth, he + padding);
                        cr.SetColor(Colors.DarkOrange);
                        cr.Fill();

                        cr.SetColor(Colors.White);
                        cr.DrawTextLayout(layout, xpos + iconWidth + 2, typos);
                    }
                    else
                    {
                        cr.Rectangle(margin, ypos, lineWidth, he + padding);
                        cr.SetColor(Colors.OrangeRed);
                        cr.Stroke();

                        cr.SetColor(textColor);
                        cr.DrawTextLayout(layout, xpos + iconWidth + 2, typos);
                    }
                }
                else
                {
                    cr.SetColor(textColor);
                    cr.DrawTextLayout(layout, xpos + iconWidth + 2, typos);
                }

                if (icon != null)
                {
                    cr.DrawImage(icon, xpos, iypos);
                }

                ypos += rowHeight;
                n++;

                //reset the markup or it carries over to the next SetText
                if (hasMarkup)
                {
                    layout.Markup = string.Empty;
                }
            }
        }
Пример #3
0
        //FIXME: we could use the expose event's clipbox to make the drawing more efficient
        void DrawList(Gdk.EventExpose args)
        {
            var window = args.Window;

            int winWidth, winHeight;

            window.GetSize(out winWidth, out winHeight);

            int ypos      = margin;
            int lineWidth = winWidth - margin * 2;
            int xpos      = margin + padding;

            using (var cr = this.CreateXwtContext()) {
                //avoid recreating the GC objects that we use multiple times
                var textColor = this.Style.Text(StateType.Normal).ToXwtColor();

                int n = 0;
                n = (int)(vadj.Value / rowHeight);

                while (ypos < winHeight - margin && n < win.DataProvider.Count)
                {
                    bool hasMarkup = false;
                    IMarkupListDataProvider <T> markupListDataProvider = win.DataProvider as IMarkupListDataProvider <T>;
                    if (markupListDataProvider != null)
                    {
                        if (markupListDataProvider.HasMarkup(n))
                        {
                            layout.Markup = (markupListDataProvider.GetMarkup(n) ?? "&lt;null&gt;");
                            hasMarkup     = true;
                        }
                    }

                    if (!hasMarkup)
                    {
                        layout.Text = (win.DataProvider.GetText(n) ?? "<null>");
                    }

                    Xwt.Drawing.Image icon = win.DataProvider.GetIcon(n);
                    int iconHeight, iconWidth;

                    if (icon != null)
                    {
                        iconWidth  = (int)icon.Width;
                        iconHeight = (int)icon.Height;
                    }
                    else if (!Gtk.Icon.SizeLookup(Gtk.IconSize.Menu, out iconWidth, out iconHeight))
                    {
                        iconHeight = iconWidth = 24;
                    }

                    var s = layout.GetSize();
                    int typos, iypos;
                    int he = (int)s.Height;

                    typos = he < rowHeight ? ypos + (rowHeight - he) / 2 : ypos;
                    iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;

                    if (n == selection)
                    {
                        if (!disableSelection)
                        {
                            cr.Rectangle(margin, ypos, lineWidth, he + padding);
                            cr.SetColor(this.Style.Base(StateType.Selected).ToXwtColor());
                            cr.Fill();

                            cr.SetColor(this.Style.Text(StateType.Selected).ToXwtColor());
                            cr.DrawTextLayout(layout, xpos + iconWidth + 2, typos);
                        }
                        else
                        {
                            cr.Rectangle(margin, ypos, lineWidth, he + padding);
                            cr.SetColor(this.Style.Base(StateType.Selected).ToXwtColor());
                            cr.Stroke();

                            cr.SetColor(textColor);
                            cr.DrawTextLayout(layout, xpos + iconWidth + 2, typos);
                        }
                    }
                    else
                    {
                        cr.SetColor(textColor);
                        cr.DrawTextLayout(layout, xpos + iconWidth + 2, typos);
                    }

                    if (icon != null)
                    {
                        cr.DrawImage(icon, xpos, iypos);
                    }

                    ypos += rowHeight;
                    n++;

                    //reset the markup or it carries over to the next SetText
                    if (hasMarkup)
                    {
                        layout.Markup = string.Empty;
                    }
                }
            }
        }