Example #1
0
            public void SetLabel(Gtk.Widget page, Gdk.Pixbuf icon, string label)
            {
                Pango.EllipsizeMode oldMode = Pango.EllipsizeMode.End;

                this.page = page;
                if (Child != null)
                {
                    if (labelWidget != null)
                    {
                        oldMode = labelWidget.Ellipsize;
                    }
                    Gtk.Widget oc = Child;
                    Remove(oc);
                    oc.Destroy();
                }

                Gtk.HBox box = new HBox();
                box.Spacing = 2;

                if (icon != null)
                {
                    tabIcon = new Gtk.Image(icon);
                    tabIcon.Show();
                    box.PackStart(tabIcon, false, false, 0);
                }
                else
                {
                    tabIcon = null;
                }

                if (!string.IsNullOrEmpty(label))
                {
                    labelWidget           = new Gtk.Label(label);
                    labelWidget.UseMarkup = true;
                    labelWidget.Xalign    = 0;
                    box.PackStart(labelWidget, true, true, 0);
                }
                else
                {
                    labelWidget = null;
                }

                Add(box);

                // Get the required size before setting the ellipsize property, since ellipsized labels
                // have a width request of 0
                ShowAll();
                labelWidth = SizeRequest().Width;

                if (labelWidget != null)
                {
                    labelWidget.Ellipsize = oldMode;
                }
                UpdateVisualStyle();
            }
Example #2
0
        public static EllipsizeMode ToXwtValue(this Pango.EllipsizeMode value)
        {
            switch (value)
            {
            case Pango.EllipsizeMode.None: return(Xwt.EllipsizeMode.None);

            case Pango.EllipsizeMode.Start: return(Xwt.EllipsizeMode.Start);

            case Pango.EllipsizeMode.Middle: return(Xwt.EllipsizeMode.Middle);

            case Pango.EllipsizeMode.End: return(Xwt.EllipsizeMode.End);
            }
            throw new NotSupportedException();
        }
Example #3
0
        //TODO: Deprecate Cairo usage entirely
        public Gdk.Rectangle RenderLayoutText(Context cr, String text, int x, int y, int width, int textHeight,
                                              Constants.Color color, Pango.Alignment align, Pango.EllipsizeMode ellipse, int horisontalOffset = 0)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(new Gdk.Rectangle());
            }

            if (layout != null)
            {
                layout.Context.Dispose();
                layout.FontDescription.Dispose();
                layout.Dispose();
            }

            layout = new Pango.Layout(ReferenceWidget.CreatePangoContext());
            layout.FontDescription = new Pango.FontDescription();
            layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(textHeight);

            layout.Width     = Pango.Units.FromPixels(width);
            layout.Ellipsize = ellipse;
            layout.Alignment = align;

            if (ellipse == Pango.EllipsizeMode.None)
            {
                layout.Wrap = Pango.WrapMode.WordChar;
            }

            text = string.Format("<span foreground=\"#{0}\">{1}</span>", color, text);
            layout.SetMarkup(text);

            cr.Rectangle(x, y, width, 155);
            cr.Clip();
            cr.MoveTo(x + horisontalOffset, y);
            Pango.CairoHelper.ShowLayout(cr, layout);
            Pango.Rectangle strong, weak;
            layout.GetCursorPos(layout.Lines [layout.LineCount - 1].StartIndex +
                                layout.Lines [layout.LineCount - 1].Length,
                                out strong, out weak);
            cr.ResetClip();

            return(new Gdk.Rectangle(Pango.Units.ToPixels(weak.X) + x,
                                     Pango.Units.ToPixels(weak.Y) + y,
                                     Pango.Units.ToPixels(weak.Width),
                                     Pango.Units.ToPixels(weak.Height)));
        }