コード例 #1
0
        void CalcTextWidth()
        {
            using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) {
                char accel;

                string text = GLib.Markup.EscapeText(item.Text.Replace("\n", ""));
                if (item.Mnemonic.HasValue)
                {
                    layout.SetMarkupWithAccel(text, '_', out accel);
                }
                else
                {
                    layout.SetMarkup(text);
                }
                layout.FontDescription = Style.FontDescription;
                layout.Ellipsize       = Pango.EllipsizeMode.End;
                layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(FontSize);
                layout.FontDescription.Weight       = Pango.Weight.Bold;

                Pango.Rectangle logical, ink;
                layout.GetPixelExtents(out ink, out logical);

                TextWidth  = Math.Min(MaxWidth, Math.Max(MinWidth, logical.Width));
                HasTooltip = TextWidth < logical.Width;

                layout.Context.Dispose();
            }

            SetSize();
        }
コード例 #2
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            if (!IsRealized)
            {
                return(false);
            }

            Gdk.Rectangle allocation = Allocation;

            int pixbufSize = allocation.Height - IconBuffer * 2;

            if (item.ShowIcons && (icon_surface == null || (icon_surface.Height != pixbufSize && icon_surface.Width != pixbufSize)))
            {
                if (icon_surface != null)
                {
                    icon_surface.Dispose();
                }
                if (emblem_surface != null)
                {
                    emblem_surface.Dispose();
                }

                if (item.ForcePixbuf == null)
                {
                    icon_surface = LoadIcon(item.Icon, pixbufSize);
                }
                else
                {
                    icon_surface = LoadIcon(item.ForcePixbuf, pixbufSize);
                }

                if (!string.IsNullOrEmpty(item.Emblem))
                {
                    emblem_surface = LoadIcon(item.Emblem, pixbufSize);
                }
            }

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                if (Selected && !item.Disabled)
                {
                    cr.Rectangle(allocation.X, allocation.Y, allocation.Width, allocation.Height);
                    cr.Color = TextColor.SetAlpha(.1);
                    cr.Fill();
                }

                if (item.ShowIcons)
                {
                    PlaceSurface(cr, icon_surface, allocation);
                    cr.PaintWithAlpha(item.Disabled ? 0.5 : 1);

                    if (item.Bold)
                    {
                        cr.Operator = Operator.Add;
                        PlaceSurface(cr, icon_surface, allocation);
                        cr.PaintWithAlpha(.8);
                        cr.Operator = Operator.Over;
                    }

                    if (!string.IsNullOrEmpty(item.Emblem))
                    {
                        PlaceSurface(cr, emblem_surface, allocation);
                        cr.Paint();
                    }
                }

                using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) {
                    char   accel;
                    string text = GLib.Markup.EscapeText(item.Text.Replace("\n", ""));
                    if (item.Mnemonic.HasValue)
                    {
                        layout.SetMarkupWithAccel(text, '_', out accel);
                    }
                    else
                    {
                        layout.SetMarkup(text);
                    }
                    layout.Width           = Pango.Units.FromPixels(TextWidth);
                    layout.FontDescription = Style.FontDescription;
                    layout.Ellipsize       = Pango.EllipsizeMode.End;
                    layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(FontSize);
                    layout.FontDescription.Weight       = Pango.Weight.Bold;

                    Pango.Rectangle logical, ink;
                    layout.GetPixelExtents(out ink, out logical);

                    int offset = Padding;
                    if (MenuShowingIcons)
                    {
                        offset += MenuHeight + Padding;
                    }
                    cr.MoveTo(allocation.X + offset, allocation.Y + (allocation.Height - logical.Height) / 2);
                    Pango.CairoHelper.LayoutPath(cr, layout);
                    cr.Color = TextColor.SetAlpha(item.Disabled ? 0.5 : 1);
                    cr.Fill();

                    layout.Context.Dispose();
                }

                (cr.Target as IDisposable).Dispose();
            }

            return(true);
        }