示例#1
0
            static NSImage FixImageServiceImage(Xwt.Drawing.Image image, double scale, string[] styles)
            {
                NSImage result = image.WithStyles(styles).ToBitmap(scale).ToNSImage();

                result.Template = true;
                return(result);
            }
示例#2
0
        void SetItemValues(NSMenuItem item, CommandInfo info, bool disabledVisible, string overrideLabel = null)
        {
            item.SetTitleWithMnemonic(GetCleanCommandText(info, overrideLabel));

            bool enabled = info.Enabled && (!IsGloballyDisabled || commandSource == CommandSource.ContextMenu);
            bool visible = info.Visible && (disabledVisible || info.Enabled);

            item.Enabled = enabled;
            item.Hidden  = !visible;

            string fileName = null;
            var    doc      = info.DataItem as Ide.Gui.Document;

            if (doc != null)
            {
                if (doc.IsFile)
                {
                    fileName = doc.FileName;
                }
                else
                {
                    // Designer documents have no file bound to them, but the document name
                    // could be a valid path
                    var docName = doc.Name;
                    if (!string.IsNullOrEmpty(docName) && System.IO.Path.IsPathRooted(docName) && System.IO.File.Exists(docName))
                    {
                        fileName = docName;
                    }
                }
            }
            else if (info.DataItem is NavigationHistoryItem)
            {
                var navDoc = ((NavigationHistoryItem)info.DataItem).NavigationPoint as DocumentNavigationPoint;
                if (navDoc != null)
                {
                    fileName = navDoc.FileName;
                }
            }
            else
            {
                var str = info.DataItem as string;
                if (str != null && System.IO.Path.IsPathRooted(str) && System.IO.File.Exists(str))
                {
                    fileName = str;
                }
            }

            if (!String.IsNullOrWhiteSpace(fileName))
            {
                item.ToolTip = fileName;
                Xwt.Drawing.Image icon = null;
                if (!info.Icon.IsNull)
                {
                    icon = Ide.ImageService.GetIcon(info.Icon, Gtk.IconSize.Menu);
                }
                if (icon == null)
                {
                    icon = Ide.DesktopService.GetIconForFile(fileName, Gtk.IconSize.Menu);
                }
                if (icon != null)
                {
                    var scale = GtkWorkarounds.GetScaleFactor(Ide.IdeApp.Workbench.RootWindow);

                    if (NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle") == "Dark")
                    {
                        icon = icon.WithStyles("dark");
                    }
                    else
                    {
                        icon = icon.WithStyles("-dark");
                    }
                    item.Image          = icon.ToBitmap(scale).ToNSImage();
                    item.Image.Template = true;
                }
            }

            SetAccel(item, info.AccelKey);

            if (info.Checked)
            {
                item.State = NSCellStateValue.On;
            }
            else if (info.CheckedInconsistent)
            {
                item.State = NSCellStateValue.Mixed;
            }
            else
            {
                item.State = NSCellStateValue.Off;
            }
        }
示例#3
0
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            bool needsRefresh = false;

            using (var context = Gdk.CairoHelper.Create(args.Window)) {
                var scalef = GtkWorkarounds.GetScaleFactor(this);
                context.LineWidth = 1;
                var alloc  = Allocation;
                int width  = alloc.Width;
                int height = alloc.Height;
                context.Rectangle(args.Area.X, args.Area.Y, args.Area.Width, args.Area.Height);
                var backgroundColor = Styles.CodeCompletion.BackgroundColor.ToCairoColor();
                var textColor       = Styles.CodeCompletion.TextColor.ToCairoColor();
                var categoryColor   = Styles.CodeCompletion.CategoryColor.ToCairoColor();
                context.SetSourceColor(backgroundColor);
                context.Fill();
                int xpos = iconTextSpacing;
                int yPos = (int)-vadj.Value;
                //when there are no matches, display a message to indicate that the completion list is still handling input
                if (filteredItems.Count == 0)
                {
                    context.Rectangle(0, yPos, width, height - yPos);
                    context.SetSourceColor(backgroundColor);
                    context.Stroke();
                    //TODO: David, line below is simplified noMatchLayout.SetText (DataProvider.ItemCount == 0 ? NoSuggestionsMsg : NoMatchesMsg);
                    noMatchLayout.SetText(NoSuggestionsMsg);
                    int lWidth, lHeight;
                    noMatchLayout.GetPixelSize(out lWidth, out lHeight);
                    context.SetSourceColor(textColor);
                    context.MoveTo((width - lWidth) / 2, yPos + (height - lHeight - yPos) / 2 - lHeight / 2);
                    Pango.CairoHelper.ShowLayout(context, noMatchLayout);
                    return(false);
                }

                Iterate(true, ref yPos, delegate(int index, int itemidx, int ypos) {
                    if (ypos >= height)
                    {
                        return(false);
                    }
                    if (ypos < -rowHeight)
                    {
                        return(true);
                    }
                    xpos                    = iconTextSpacing;
                    var selected            = index == SelectedItemIndex;
                    bool drawIconAsSelected = SelectionEnabled && selected;
                    var item                = filteredItems [index];
                    string markup           = GLib.Markup.EscapeText(item.DisplayText);
                    string description      = "";               //TODO: David DataProvider.GetDescription (item, drawIconAsSelected);

                    if (string.IsNullOrEmpty(description))
                    {
                        layout.SetMarkup(markup);
                    }
                    else
                    {
                        layout.SetMarkup(markup + " " + description);
                    }

                    string text = item.DisplayText;

                    //TODO: David, where do we get HighlightedSpans?
                    //if (!string.IsNullOrEmpty (text) && item.HighlightedSpans.Any ()) {
                    //	Pango.AttrList attrList = layout.Attributes ?? new Pango.AttrList ();
                    //	foreach (var span in item.HighlightedSpans) {
                    //		var bold = new AttrWeight (Weight.Bold);

                    //		bold.StartIndex = (uint)span.Start;
                    //		bold.EndIndex = (uint)span.End;
                    //		attrList.Insert (bold);

                    //		if (!selected) {
                    //			var highlightColor = (selected) ? Styles.CodeCompletion.SelectionHighlightColor : Styles.CodeCompletion.HighlightColor;
                    //			var fg = new AttrForeground ((ushort)(highlightColor.Red * ushort.MaxValue), (ushort)(highlightColor.Green * ushort.MaxValue), (ushort)(highlightColor.Blue * ushort.MaxValue));
                    //			fg.StartIndex = (uint)span.Start;
                    //			fg.EndIndex = (uint)span.End;
                    //			attrList.Insert (fg);
                    //		}
                    //	}
                    //	layout.Attributes = attrList;
                    //}

                    Xwt.Drawing.Image icon = ImageService.GetIcon(GetIcon(item));
                    int iconHeight, iconWidth;
                    if (icon != null)
                    {
                        if (drawIconAsSelected)
                        {
                            icon = icon.WithStyles("sel");
                        }
                        iconWidth  = (int)icon.Width;
                        iconHeight = (int)icon.Height;
                    }
                    else if (!Gtk.Icon.SizeLookup(IconSize.Menu, out iconWidth, out iconHeight))
                    {
                        iconHeight = iconWidth = 24;
                    }

                    int wi, he, typos, iypos;
                    layout.GetPixelSize(out wi, out he);


                    typos = he < rowHeight ? ypos + (int)Math.Ceiling((rowHeight - he) / 2.0) : ypos;
                    if (scalef <= 1.0)
                    {
                        typos -= 1;                         // 1px up on non HiDPI
                    }
                    iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;
                    if (selected)
                    {
                        var barStyle = SelectionEnabled ? Styles.CodeCompletion.SelectionBackgroundColor : Styles.CodeCompletion.SelectionBackgroundInactiveColor;
                        context.SetSourceColor(barStyle.ToCairoColor());

                        if (SelectionEnabled)
                        {
                            context.Rectangle(0, ypos, Allocation.Width, rowHeight);
                            context.Fill();
                        }
                        else
                        {
                            context.LineWidth++;
                            context.Rectangle(0.5, ypos + 0.5, Allocation.Width - 1, rowHeight - 1);
                            context.Stroke();
                            context.LineWidth--;
                        }
                    }

                    if (icon != null)
                    {
                        context.DrawImage(this, icon, xpos, iypos);
                        xpos += iconTextSpacing;
                    }
                    context.SetSourceColor((drawIconAsSelected ? Styles.CodeCompletion.SelectionTextColor : Styles.CodeCompletion.TextColor).ToCairoColor());
                    var textXPos = xpos + iconWidth + 2;
                    context.MoveTo(textXPos, typos);
                    layout.Width     = (int)((Allocation.Width - textXPos) * Pango.Scale.PangoScale);
                    layout.Ellipsize = EllipsizeMode.End;
                    Pango.CairoHelper.ShowLayout(context, layout);
                    int textW, textH;
                    layout.GetPixelSize(out textW, out textH);
                    layout.Width     = -1;
                    layout.Ellipsize = EllipsizeMode.None;

                    layout.SetMarkup("");
                    if (layout.Attributes != null)
                    {
                        layout.Attributes.Dispose();
                        layout.Attributes = null;
                    }

                    string rightText = "";                    //TODO: David DataProvider.GetRightSideDescription (index, drawIconAsSelected);
                    if (!string.IsNullOrEmpty(rightText))
                    {
                        layout.SetMarkup(rightText);

                        int w, h;
                        layout.GetPixelSize(out w, out h);
                        const int leftpadding  = 8;
                        const int rightpadding = 3;
                        w    += rightpadding;
                        w     = Math.Min(w, Allocation.Width - textXPos - textW - leftpadding);
                        wi   += w;
                        typos = h < rowHeight ? ypos + (rowHeight - h) / 2 : ypos;
                        if (scalef <= 1.0)
                        {
                            typos -= 1;                             // 1px up on non HiDPI
                        }
                        context.MoveTo(Allocation.Width - w, typos);
                        layout.Width     = (int)(w * Pango.Scale.PangoScale);
                        layout.Ellipsize = EllipsizeMode.End;

                        Pango.CairoHelper.ShowLayout(context, layout);
                        layout.Width     = -1;
                        layout.Ellipsize = EllipsizeMode.None;
                    }

                    if (Math.Min(maxListWidth, wi + xpos + iconWidth + 2) > listWidth)
                    {
                        box.WidthRequest = listWidth = Math.Min(maxListWidth, wi + xpos + iconWidth + 2 + iconTextSpacing);
                        needsRefresh     = true;
                    }
                    else
                    {
                        //workaround for the vscrollbar display - the calculated width needs to be the width ofthe render region.
                        if (Allocation.Width < listWidth)
                        {
                            if (listWidth - Allocation.Width < 30)
                            {
                                box.WidthRequest = listWidth + listWidth - Allocation.Width;
                                needsRefresh     = true;
                            }
                        }
                    }

                    return(true);
                });

                if (needsRefresh)
                {
                    QueueSpaceReservationStackRefresh();
                }

                return(false);
            }
        }