Inheritance: XwtObject, IDisposable
コード例 #1
0
 public void SetTitle(string label, Xwt.Drawing.Image icon, string accessibilityDescription)
 {
     Title = label;
     Icon  = icon;
     AccessibilityDescription = accessibilityDescription;
     ParentContainer?.SetViewTitle(this, label, icon, accessibilityDescription);
 }
コード例 #2
0
 private void SetValue(ResourceFile item)
 {
     if (item != null)
     {
         if (this._propertyItem != null)
         {
             this.resourceFile = item;
             string arg;
             if (this._propertyItem.ResourceFilterDescriptor == null)
             {
                 arg = ".png,jpg";
             }
             else
             {
                 arg = string.Join(",", this._propertyItem.ResourceFilterDescriptor.FileFilter);
             }
             this.imageWidget.TooltipText = string.Format("{0}{1}\r\n{2}", LanguageInfo.Display_SupportFileTypes, arg, item.FullPath);
             Xwt.Drawing.Image image = (item.PreviewImageInfo == null) ? null : item.PreviewImageInfo.Image;
             if (image != null)
             {
                 this.ScaleImage(image);
             }
             using (CompositeTask.Run(this._propertyItem.DiaplayName))
             {
                 this._propertyItem.SetValue(this._propertyDescriptor.Name, item, null);
             }
         }
     }
 }
コード例 #3
0
ファイル: DrawingConverter.cs プロジェクト: git-thinh/limada
 public static SWM.ImageSource ToWpf(this  Xwt.Drawing.Image value)
 {
     if (value == null)
     {
         return(null);
     }
     return(Toolkit.CurrentEngine.GetNativeImage(value) as SWM.ImageSource);
 }
コード例 #4
0
            public ImageViewWithTooltip(Xwt.Drawing.Image icon)
            {
                this.icon    = icon;
                image        = new Xwt.ImageView(icon);
                this.Content = image;

                MouseEntered += HandleEnterNotifyEvent;
                MouseExited  += HandleLeaveNotifyEvent;
            }
コード例 #5
0
        private void ScaleImage(Xwt.Drawing.Image image)
        {
            double num = (image.Width > image.Height) ? image.Width : image.Height;

            if (num > 46.0)
            {
                double num2 = 46.0 / num;
                image = image.Scale(num2, num2);
            }
            this.imageWidget.Image = image;
            this.imageWidget.QueueDraw();
        }
コード例 #6
0
 internal static XD.Image AsImage(byte[] source)
 {
     Xwt.Drawing.Image result = null;
     using (var stream = new MemoryStream(source)) {
         try {
             stream.Position = 0;
             result          = Xwt.Drawing.Image.FromStream(stream);
         } catch (Exception ex) {
             Trace.TraceError("ConvertedResources.AsImage failed: {0}", ex.Message);
         }
     }
     return(result);
 }
コード例 #7
0
        public StatusBarIcon ShowStatusIcon(Xwt.Drawing.Image pixbuf)
        {
            var icon = new StatusIcon(this)
            {
                Image     = pixbuf,
                Margin    = new Thickness(5, 5, 5, 5),
                MaxWidth  = 16,
                MaxHeight = 16,
            };

            StatusIconsPanel.Children.Add(icon);

            return(icon);
        }
コード例 #8
0
ファイル: GdiConverter.cs プロジェクト: git-thinh/limada
        public static SD.Image ToGdi(this  Xwt.Drawing.Image value)
        {
            if (value == null)
            {
                return(null);
            }
            var image = value.GetBackend() as GdiImage;

            if (image == null)
            {
                return(null);
            }
            return(image.Image);
        }
コード例 #9
0
        public void SetTitle(string label, Xwt.Drawing.Image icon, string accessibilityDescription)
        {
            Title = label;
            Icon  = icon;
            AccessibilityDescription = accessibilityDescription;
            var parent = Parent;

            while (parent != null && !(parent is GtkShellDocumentViewContainer))
            {
                parent = parent.Parent;
            }
            if (parent is GtkShellDocumentViewContainer container)
            {
                container.SetViewTitle(this, label, icon, accessibilityDescription);
            }
        }
コード例 #10
0
 public void Refresh()
 {
     if (this._propertyItem != null)
     {
         this.resourceFile = (this._propertyDescriptor.GetValue(this._propertyItem.Instance) as ResourceFile);
         string arg;
         if (this._propertyItem.ResourceFilterDescriptor == null)
         {
             arg = ".png,jpg";
         }
         else
         {
             arg = string.Join(",", this._propertyItem.ResourceFilterDescriptor.FileFilter);
         }
         if (this.resourceFile != null)
         {
             if (this.resourceFile.IsDefault)
             {
                 this.imageWidget.TooltipText = string.Format("{0}{1}", LanguageInfo.Display_SupportFileTypes, arg);
             }
             else
             {
                 this.imageWidget.TooltipText = string.Format("{0}{1}\r\n{2}", LanguageInfo.Display_SupportFileTypes, arg, this.resourceFile.FullPath);
             }
             Xwt.Drawing.Image image = (this.resourceFile.PreviewImageInfo == null) ? null : this.resourceFile.PreviewImageInfo.Image;
             if (image != null)
             {
                 double width  = this.resourceFile.PreviewImageInfo.Size.Width;
                 double height = this.resourceFile.PreviewImageInfo.Size.Height;
                 this.ScaleImage(image);
                 if (this._propertyDescriptor.Name == "LabelAtlasFileImage_CNB")
                 {
                     this._propertyItem.Instance.GetType().GetProperty("CharWidth").SetValue(this._propertyItem.Instance, (int)(width / 12.0), null);
                     this._propertyItem.Instance.GetType().GetProperty("CharHeight").SetValue(this._propertyItem.Instance, (int)height, null);
                 }
             }
         }
         else
         {
             this.imageWidget.TooltipText = string.Format("{0}{1}", LanguageInfo.Display_SupportFileTypes, arg);
             this.imageWidget.Image       = ImageIcon.GetIcon("CocoStudio.DefaultResource.EditorResource.NormalImage.png");
             this.imageWidget.QueueDraw();
         }
     }
 }
コード例 #11
0
 void DrawIndicator(Cairo.Context cr, Xwt.Drawing.Image img)
 {
     cr.DrawImage(this, img, Math.Round((Allocation.Width - img.Width) / 2), -1);
 }
コード例 #12
0
 public void DrawImage(object backend, Xwt.Drawing.Image img, double x, double y, double alpha)
 {
     throw new NotImplementedException();
 }
コード例 #13
0
ファイル: MessageDialog.cs プロジェクト: wwwK/dotdevelop-xwt
 public static Command AskQuestion(string primaryText, string secondaryText, string title, Drawing.Image icon, int defaultButton, params Command[] buttons)
 {
     return(GenericAlert(RootWindow, icon, primaryText, secondaryText, title, defaultButton, buttons));
 }
コード例 #14
0
ファイル: MessageDialog.cs プロジェクト: wwwK/dotdevelop-xwt
 public static Command AskQuestion(string primaryText, string secondaryText, Drawing.Image icon, int defaultButton, params Command [] buttons)
 {
     return(AskQuestion(primaryText, secondaryText, string.Empty, icon, defaultButton, buttons));
 }
コード例 #15
0
ファイル: MessageDialog.cs プロジェクト: wwwK/dotdevelop-xwt
 public static bool Confirm(string primaryText, string secondaryText, string title, Drawing.Image icon, Command button, bool confirmIsDefault)
 {
     return(GenericAlert(RootWindow, icon, primaryText, secondaryText, title, confirmIsDefault ? 0 : 1, Command.Cancel, button) == button);
 }
コード例 #16
0
        public async void RefreshTiles()
        {
            // Cancel previous loads
            if (_tokenSource != null)
            {
                _tokenSource.Cancel();

                while (_tokenSource != null)
                {
                    await Task.Delay(1);
                }
            }

            Spinner spinner = null;

            Application.Invoke(() => {
                // Clear controls
                _buttons.Clear();
                ClearTiles();

                Content     =
                    spinner = new Spinner {
                    Animate   = true,
                    MinHeight = 50,
                    MinWidth  = 50
                };
            });

            while (spinner == null)
            {
                await Task.Delay(5);
            }

            _buttonsPerRow = CalculateButtonsPerRow((float)Size.Width);
            var i = 0;

            _tokenSource = new CancellationTokenSource();

            try {
                var tiles = await LoadTiles(_tokenSource.Token);

                Application.Invoke(() => {
                    foreach (var tile in tiles)
                    {
                        if (tile == null)
                        {
                            continue;
                        }

                        if (i >= _buttonsPerRow)
                        {
                            PushNewRow();
                            i = 0;
                        }

                        try {
                            Xwt.Drawing.Image image = tile.Image?.ToXwtImage()?.ScaleToSize(100);
                            Widget widget           = null;

                            if (ParkitectNexus.Data.Utilities.OperatingSystem.Detect() == SupportedOperatingSystem.Linux)
                            {
                                if (image != null)
                                {
                                    Image lighterImage            = image.WithAlpha(.7f);
                                    var clickableImage            = new ImageView(image);
                                    clickableImage.ButtonPressed += (sender, args) => tile.ClickAction();

                                    clickableImage.MouseEntered += (object sender, EventArgs e) => {
                                        ((ImageView)sender).Image        = lighterImage;
                                        ((Widget)sender).BackgroundColor = Color.FromBytes(255, 255, 255);
                                    };
                                    clickableImage.MouseExited += (object sender, EventArgs e) => {
                                        ((ImageView)sender).Image        = image;
                                        ((Widget)sender).BackgroundColor = tile.BackgroundColor;
                                    };

                                    widget = clickableImage;
                                }
                                else
                                {
                                    var label            = new Label(tile.Text);
                                    label.ButtonPressed += (sender, args) => tile.ClickAction();
                                    label.Wrap           = WrapMode.Word;
                                    label.TextAlignment  = Alignment.Center;

                                    label.MouseEntered += (object sender, EventArgs e) => {
                                        ((Widget)sender).BackgroundColor = Color.FromBytes(255, 255, 255);
                                    };
                                    label.MouseExited += (object sender, EventArgs e) => {
                                        ((Widget)sender).BackgroundColor = tile.BackgroundColor;
                                    };

                                    widget = label;
                                }
                            }
                            else
                            {
                                var button = new Button(image)
                                {
                                    Label           = tile.Image == null ? tile.Text : null,
                                    TooltipText     = tile.Text,
                                    Style           = ButtonStyle.Borderless,
                                    BackgroundColor = tile.BackgroundColor,
                                    ImagePosition   = ContentPosition.Center
                                };
                                Image lighterImage = image.WithAlpha(.7f);

                                button.MouseEntered += (object sender, EventArgs e) => {
                                    ((Button)sender).Image           = lighterImage;
                                    ((Widget)sender).BackgroundColor = Color.FromBytes(255, 255, 255);
                                };
                                button.MouseExited += (object sender, EventArgs e) => {
                                    ((Button)sender).Image           = image;
                                    ((Widget)sender).BackgroundColor = tile.BackgroundColor;
                                };

                                button.Clicked += (sender, args) => tile.ClickAction();

                                widget = button;
                            }

                            widget.WidthRequest    = 100;
                            widget.HeightRequest   = 100;
                            widget.MinWidth        = 0;
                            widget.BackgroundColor = tile.BackgroundColor;

                            _buttons.Add(widget);
                            _rows.Peek().PackStart(widget);
                            i++;
                        } catch (Exception e) {
                            _log.WriteLine("Failed to convert Tile object to UI");
                            _log.WriteException(e);
                        }
                    }

                    Content = _box;
                });
            } catch (TaskCanceledException) {
            } catch (OperationCanceledException) {
            } finally {
                _tokenSource?.Dispose();
                _tokenSource = null;
            }
        }
コード例 #17
0
 static ConvertedResources()
 {
     LimadaLogo = AsImage(global::Limaki.View.Resources.Resource.LogoDrop32);
     SubWinIcon = AsImage(global::Limaki.View.Resources.Resource.SubWin);
 }
コード例 #18
0
ファイル: MessageDialog.cs プロジェクト: wwwK/dotdevelop-xwt
 public static bool Confirm(WindowFrame window, string primaryText, string secondaryText, Drawing.Image icon, Command button)
 {
     return(Confirm(window, primaryText, secondaryText, string.Empty, icon, button));
 }
コード例 #19
0
ファイル: MessageDialog.cs プロジェクト: wwwK/dotdevelop-xwt
 public static bool Confirm(string primaryText, string secondaryText, Drawing.Image icon, Command button)
 {
     return(Confirm(RootWindow, primaryText, secondaryText, icon, button));
 }
コード例 #20
0
 public static void ShowMessage(WindowFrame parent, string primaryText, string secondaryText, Drawing.Image icon)
 {
     GenericAlert(parent, icon, primaryText, secondaryText, Command.Ok);
 }
コード例 #21
0
ファイル: MessageDialog.cs プロジェクト: wwwK/dotdevelop-xwt
 public static void ShowMessage(WindowFrame parent, string primaryText, string secondaryText, Drawing.Image icon)
 {
     ShowMessage(parent, primaryText, secondaryText, string.Empty, icon);
 }
コード例 #22
0
ファイル: ImageBox.cs プロジェクト: noah1510/dotdevelop
 public ImageBox(Xwt.Drawing.Image image) : this()
 {
     Image = image;
 }
コード例 #23
0
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            using (var context = Gdk.CairoHelper.Create(args.Window)) {
                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 = ColorScheme.CompletionWindow.Color;
                var textColor       = ColorScheme.GetForeground(ColorScheme.CompletionText);
                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();
                    noMatchLayout.SetText(win.DataProvider.ItemCount == 0 ? NoSuggestionsMsg : NoMatchesMsg);
                    int lWidth, lHeight;
                    noMatchLayout.GetPixelSize(out lWidth, out lHeight);
                    context.SetSourceColor(textColor);
                    context.MoveTo((width - lWidth) / 2, yPos + (height - lHeight - yPos) / 2 - lHeight);
                    Pango.CairoHelper.ShowLayout(context, noMatchLayout);
                    return(false);
                }

                var matcher = CompletionMatcher.CreateCompletionMatcher(CompletionString);
                Iterate(true, ref yPos, delegate(Category category, int ypos) {
                    if (ypos >= height)
                    {
                        return;
                    }
                    if (ypos < -rowHeight)
                    {
                        return;
                    }

                    //	window.DrawRectangle (this.Style.BackgroundGC (StateType.Insensitive), true, 0, yPos, width, rowHeight);
                    int x = 2;
                    if (category.CompletionCategory != null && !string.IsNullOrEmpty(category.CompletionCategory.Icon))
                    {
                        var icon = ImageService.GetIcon(category.CompletionCategory.Icon, IconSize.Menu);
                        context.DrawImage(this, icon, 0, ypos);
                        x = (int)icon.Width + 4;
                    }
                    context.Rectangle(0, ypos, Allocation.Width, rowHeight);
                    context.SetSourceColor(backgroundColor);
                    context.Fill();


                    //					layout.SetMarkup ("<span weight='bold' foreground='#AAAAAA'>" + (category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized") + "</span>");
                    //					window.DrawLayout (textGCInsensitive, x - 1, ypos + 1 + (rowHeight - py) / 2, layout);
                    //					layout.SetMarkup ("<span weight='bold'>" + (category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized") + "</span>");
                    categoryLayout.SetMarkup((category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized"));
                    int px, py;
                    categoryLayout.GetPixelSize(out px, out py);
                    context.MoveTo(x, ypos + (rowHeight - py) / 2);
                    context.SetSourceColor(textColor);
                    Pango.CairoHelper.ShowLayout(context, categoryLayout);
                }, delegate(Category curCategory, int item, int itemidx, int ypos) {
                    if (ypos >= height)
                    {
                        return(false);
                    }
                    if (ypos < -rowHeight)
                    {
                        return(true);
                    }
                    const int categoryModeItemIndenting = 0;
                    if (InCategoryMode && curCategory != null && curCategory.CompletionCategory != null)
                    {
                        xpos = iconTextSpacing + categoryModeItemIndenting;
                    }
                    else
                    {
                        xpos = iconTextSpacing;
                    }
                    string markup      = win.DataProvider.HasMarkup(item) ? (win.DataProvider.GetMarkup(item) ?? "&lt;null&gt;") : GLib.Markup.EscapeText(win.DataProvider.GetText(item) ?? "<null>");
                    string description = win.DataProvider.GetDescription(item, item == SelectedItem);

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

                    string text = win.DataProvider.GetText(item);

                    if (!string.IsNullOrEmpty(text))
                    {
                        int [] matchIndices = matcher.GetMatch(text);
                        if (matchIndices != null)
                        {
                            Pango.AttrList attrList = layout.Attributes ?? new Pango.AttrList();
                            for (int newSelection = 0; newSelection < matchIndices.Length; newSelection++)
                            {
                                int idx = matchIndices [newSelection];
                                ChunkStyle stringStyle;
                                if (item == SelectedItem)
                                {
                                    stringStyle = ColorScheme.CompletionSelectedMatchingSubstring;
                                }
                                else
                                {
                                    stringStyle = ColorScheme.CompletionMatchingSubstring;
                                }
                                var highlightColor = (Cairo.Color)ColorScheme.GetForeground(stringStyle);
                                var fg             = new AttrForeground((ushort)(highlightColor.R * ushort.MaxValue), (ushort)(highlightColor.G * ushort.MaxValue), (ushort)(highlightColor.B * ushort.MaxValue));
                                fg.StartIndex      = (uint)idx;
                                fg.EndIndex        = (uint)(idx + 1);
                                attrList.Insert(fg);

                                if (stringStyle.FontWeight != FontWeight.Normal)
                                {
                                    var variant        = new AttrWeight((Pango.Weight)stringStyle.FontWeight);
                                    variant.StartIndex = (uint)idx;
                                    variant.EndIndex   = (uint)(idx + 1);
                                    attrList.Insert(variant);
                                }
                            }
                            layout.Attributes = attrList;
                        }
                    }

                    Xwt.Drawing.Image icon = win.DataProvider.GetIcon(item);
                    int iconHeight, iconWidth;
                    if (icon != null)
                    {
                        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;
                    iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;
                    if (item == SelectedItem)
                    {
                        context.Rectangle(0, ypos, Allocation.Width, rowHeight / 2);
                        var barStyle       = SelectionEnabled ? ColorScheme.CompletionSelectionBarBackground : ColorScheme.CompletionSelectionBarBackgroundInactive;
                        var barBorderStyle = SelectionEnabled ? ColorScheme.CompletionSelectionBarBorder : ColorScheme.CompletionSelectionBarBorderInactive;

                        context.SetSourceColor(barStyle.Color);
                        context.Fill();
                        context.Rectangle(0, ypos + rowHeight / 2, Allocation.Width, rowHeight / 2);
                        context.SetSourceColor(barStyle.SecondColor);
                        context.Fill();

                        context.Rectangle(0.5, ypos + 0.5, Allocation.Width - 1, rowHeight - 1);
                        if (!SelectionEnabled)
                        {
                            context.SetDash(new double[] { 4, 4 }, 0);
                        }
                        context.SetSourceColor(barBorderStyle.Color);
                        context.Stroke();
                    }

                    if (icon != null)
                    {
                        context.DrawImage(this, icon, xpos, iypos);
                        xpos += iconTextSpacing;
                    }
                    context.SetSourceColor(item == SelectedItem ? ColorScheme.GetForeground(ColorScheme.CompletionSelectedText) : textColor);
                    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);
                    layout.Width     = -1;
                    layout.Ellipsize = EllipsizeMode.None;

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

                    string rightText = win.DataProvider.GetRightSideDescription(item, item == SelectedItem);
                    if (!string.IsNullOrEmpty(rightText))
                    {
                        layout.SetMarkup(rightText);
                        int w, h;
                        layout.GetPixelSize(out w, out h);
                        wi   += w;
                        typos = h < rowHeight ? ypos + (rowHeight - h) / 2 : ypos;
                        context.MoveTo(Allocation.Width - w, typos);
                        Pango.CairoHelper.ShowLayout(context, layout);
                    }

                    if (Math.Min(maxListWidth, wi + xpos + iconWidth + 2) > listWidth)
                    {
                        WidthRequest = listWidth = Math.Min(maxListWidth, wi + xpos + iconWidth + 2 + iconTextSpacing);
                        win.ResetSizes();
                    }
                    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)
                            {
                                WidthRequest = listWidth + listWidth - Allocation.Width;
                                win.ResetSizes();
                            }
                        }
                    }

                    return(true);
                });

                return(false);
            }
        }
コード例 #24
0
 public void AddImage(Xwt.Drawing.Image image)
 {
     data [TransferDataType.Image] = image;
 }
コード例 #25
0
ファイル: MessageDialog.cs プロジェクト: wwwK/dotdevelop-xwt
 public static bool Confirm(WindowFrame window, string primaryText, string secondaryText, string title, Drawing.Image icon, Command button)
 {
     return(GenericAlert(window, icon, primaryText, secondaryText, title, Command.Cancel, button) == button);
 }
コード例 #26
0
			public ImageViewWithTooltip (Xwt.Drawing.Image icon)
			{
				this.icon = icon;
				image = new Xwt.ImageView (icon);
				this.Content = image;

				MouseEntered += HandleEnterNotifyEvent;
				MouseExited += HandleLeaveNotifyEvent;
			}
コード例 #27
0
ファイル: MessageDialog.cs プロジェクト: wwwK/dotdevelop-xwt
 public static bool Confirm(string primaryText, string secondaryText, Drawing.Image icon, Command button, bool confirmIsDefault)
 {
     return(Confirm(primaryText, secondaryText, string.Empty, icon, button, confirmIsDefault));
 }
コード例 #28
0
ファイル: MessageDialog.cs プロジェクト: wwwK/dotdevelop-xwt
 public static void ShowMessage(string primaryText, string secondaryText, string title, Drawing.Image icon)
 {
     ShowMessage(RootWindow, primaryText, secondaryText, title, icon);
 }
コード例 #29
0
 public void SetViewTitle(GtkShellDocumentViewItem view, string label, Xwt.Drawing.Image icon, string accessibilityDescription)
 {
 }
コード例 #30
0
ファイル: ListWidget.cs プロジェクト: wjohnke/CSS18
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            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();
                    noMatchLayout.SetText(DataProvider.ItemCount == 0 ? NoSuggestionsMsg : NoMatchesMsg);
                    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(CategorizedCompletionItems category, int ypos) {
                    if (ypos >= height)
                    {
                        return;
                    }
                    if (ypos < -rowHeight)
                    {
                        return;
                    }

                    //	window.DrawRectangle (this.Style.BackgroundGC (StateType.Insensitive), true, 0, yPos, width, rowHeight);
                    int x = 2;
                    if (category.CompletionCategory != null && !string.IsNullOrEmpty(category.CompletionCategory.Icon))
                    {
                        var icon = ImageService.GetIcon(category.CompletionCategory.Icon, IconSize.Menu);
                        context.DrawImage(this, icon, 0, ypos);
                        x = (int)icon.Width + 4;
                    }
                    context.Rectangle(0, ypos, Allocation.Width, rowHeight);
                    context.SetSourceColor(backgroundColor);
                    context.Fill();


                    //					layout.SetMarkup ("<span weight='bold' foreground='#AAAAAA'>" + (category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized") + "</span>");
                    //					window.DrawLayout (textGCInsensitive, x - 1, ypos + 1 + (rowHeight - py) / 2, layout);
                    //					layout.SetMarkup ("<span weight='bold'>" + (category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized") + "</span>");
                    categoryLayout.SetMarkup((category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized"));
                    int px, py;
                    categoryLayout.GetPixelSize(out px, out py);
                    context.MoveTo(x, ypos + (rowHeight - py) / 2);
                    context.SetSourceColor(categoryColor);
                    Pango.CairoHelper.ShowLayout(context, categoryLayout);
                }, delegate(CategorizedCompletionItems curCategory, int item, int itemidx, int ypos) {
                    if (ypos >= height)
                    {
                        return(false);
                    }
                    if (ypos < -rowHeight)
                    {
                        return(true);
                    }
                    const int categoryModeItemIndenting = 0;
                    if (InCategoryMode && curCategory != null && curCategory.CompletionCategory != null)
                    {
                        xpos = iconTextSpacing + categoryModeItemIndenting;
                    }
                    else
                    {
                        xpos = iconTextSpacing;
                    }
                    bool drawIconAsSelected = SelectionEnabled && item == SelectedItemIndex;
                    string markup           = DataProvider.HasMarkup(item) ? (DataProvider.GetMarkup(item) ?? "&lt;null&gt;") : GLib.Markup.EscapeText(DataProvider.GetText(item) ?? "<null>");
                    string description      = DataProvider.GetDescription(item, drawIconAsSelected);

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

                    string text = DataProvider.GetText(item);

                    if (!string.IsNullOrEmpty(text))
                    {
                        int [] matchIndices = DataProvider.GetHighlightedTextIndices(item);
                        if (matchIndices != null)
                        {
                            Pango.AttrList attrList = layout.Attributes ?? new Pango.AttrList();
                            for (int newSelection = 0; newSelection < matchIndices.Length; newSelection++)
                            {
                                int idx  = matchIndices [newSelection];
                                var bold = new AttrWeight(Weight.Bold);

                                bold.StartIndex = (uint)idx;
                                bold.EndIndex   = (uint)(idx + 1);
                                attrList.Insert(bold);

                                if (item != SelectedItemIndex)
                                {
                                    var highlightColor = (item == SelectedItemIndex) ? 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)idx;
                                    fg.EndIndex        = (uint)(idx + 1);
                                    attrList.Insert(fg);
                                }
                            }
                            layout.Attributes = attrList;
                        }
                    }

                    Xwt.Drawing.Image icon = DataProvider.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 (item == SelectedItemIndex)
                    {
                        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 = DataProvider.GetRightSideDescription(item, 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)
                    {
                        WidthRequest = listWidth = Math.Min(maxListWidth, wi + xpos + iconWidth + 2 + iconTextSpacing);
                        win.ResetSizes();
                    }
                    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)
                            {
                                WidthRequest = listWidth + listWidth - Allocation.Width;
                                win.ResetSizes();
                            }
                        }
                    }

                    return(true);
                });

                return(false);
            }
        }
コード例 #31
0
ファイル: MessageDialog.cs プロジェクト: wwwK/dotdevelop-xwt
 public static void ShowMessage(WindowFrame parent, string primaryText, string secondaryText, string title, Drawing.Image icon)
 {
     if (string.IsNullOrEmpty(title))
     {
         title = parent?.Title ?? Application.TranslationCatalog.GetString("Information");
     }
     GenericAlert(parent, icon, primaryText, secondaryText, title, Command.Ok);
 }