public override object FindIcon(Uri path, string ext, string mimetype) { if(mimetype == null) { if(!path.IsFile) throw new ArgumentException(); if(!fileMimeHash.ContainsKey(path.GetScrubbedLocalPath())) { ProcessStartInfo psi = new ProcessStartInfo("xdg-mime", string.Format("query filetype '{0}'", path.GetScrubbedLocalPath())); psi.RedirectStandardOutput = true; psi.UseShellExecute = false; Process p = Process.Start(psi); p.WaitForExit(); StreamReader sr = p.StandardOutput; mimetype = sr.ReadLine(); fileMimeHash[path.GetScrubbedLocalPath()] = mimetype; } else { mimetype = fileMimeHash[path.GetScrubbedLocalPath()]; } } IconSet iconset = new IconSet(); IconSource source = new IconSource(); source.IconName = mimetype.Replace('/', '-'); //"inode-directory"; //Console.WriteLine("{0}: {1}", psi.Arguments, text); iconset.AddSource(source); return iconset; }
public void Add(string name) { IconSet icon_set = new IconSet (); IconSource source = new IconSource (); source.IconName = name; icon_set.AddSource (source); Add (name, icon_set); }
void AddStockIcon(IconFactory factory, string stockId, string filename) { var pixbuf = new Pixbuf(Assembly.GetCallingAssembly(), filename); var source = new IconSource() { Pixbuf = pixbuf, SizeWildcarded = true, Size = IconSize.SmallToolbar}; var set = new IconSet(); set.AddSource(source); factory.Add(stockId, set); }
static void AddToIconFactory(string stockId, Gdk.Pixbuf pixbuf, Gdk.Pixbuf pixbuf2x, Gtk.IconSize iconSize) { Gtk.IconSet iconSet = iconFactory.Lookup(stockId); if (iconSet == null) { iconSet = new Gtk.IconSet(); iconFactory.Add(stockId, iconSet); } Gtk.IconSource source = new Gtk.IconSource(); Gtk.IconSource source2x = null; if (Platform.IsWindows) { var pixel_scale = GtkWorkarounds.GetPixelScale(); source.Pixbuf = pixbuf.ScaleSimple((int)(pixbuf.Width * pixel_scale), (int)(pixbuf.Height * pixel_scale), Gdk.InterpType.Bilinear); } else { source.Pixbuf = pixbuf; } source.Size = iconSize; source.SizeWildcarded = iconSize == Gtk.IconSize.Invalid; if (pixbuf2x != null) { if (GtkWorkarounds.SetSourceScale(source, 1)) { GtkWorkarounds.SetSourceScaleWildcarded(source, false); source2x = new Gtk.IconSource(); source2x.Pixbuf = pixbuf2x; source2x.Size = iconSize; source2x.SizeWildcarded = iconSize == Gtk.IconSize.Invalid; GtkWorkarounds.SetSourceScale(source2x, 2); GtkWorkarounds.SetSourceScaleWildcarded(source2x, false); } } else { GtkWorkarounds.SetSourceScaleWildcarded(source, true); } iconSet.AddSource(source); if (source2x != null) { iconSet.AddSource(source2x); } }
static void AddIcon(string stockid, string resource) { Gtk.IconSet iconset = stock.Lookup (stockid); if (iconset == null) { iconset = new Gtk.IconSet (); Gdk.Pixbuf img = Gdk.Pixbuf.LoadFromResource (resource); IconSource source = new IconSource (); source.Size = Gtk.IconSize.Menu; source.SizeWildcarded = false; source.Pixbuf = img; iconset.AddSource (source); stock.Add (stockid, iconset); } }
private static void LoadIcon(IconSet iconSet, string resourceID, Assembly callingAssembly) { Pixbuf pixbuf1 = ImageIcon.LoadResource(resourceID, callingAssembly); Pixbuf pixbuf2 = ImageIcon.LoadResource2x(resourceID, callingAssembly); IconSource iconSource1 = new IconSource(); ImageIcon.ConfigIconSource(pixbuf1, iconSource1); if (pixbuf2 != null) { GtkWorkarounds.SetSourceScale(iconSource1, 1.0); GtkWorkarounds.SetSourceScaleWildcarded(iconSource1, false); IconSource iconSource2 = new IconSource(); ImageIcon.ConfigIconSource(pixbuf2, iconSource2); GtkWorkarounds.SetSourceScale(iconSource2, ImageIcon.ScaleFactor); GtkWorkarounds.SetSourceScaleWildcarded(iconSource2, false); iconSet.AddSource(iconSource2); } else { iconSet.AddSource(iconSource1); } }
static void AddIcon(IconFactory stock, string stockid, string resource) { Gtk.IconSet iconset = stock.Lookup (stockid); if (iconset != null) return; iconset = new Gtk.IconSet (); Gdk.Pixbuf img = Gdk.Pixbuf.LoadFromResource (resource); IconSource source = new IconSource (); source.Pixbuf = img; iconset.AddSource (source); stock.Add (stockid, iconset); }
static void AddIcon(string stockid, Gtk.IconSize iconSize, string resource) { Gtk.IconSet iconset = stock.Lookup (stockid); if (iconset == null) { iconset = new Gtk.IconSet (); Gdk.Pixbuf img = Gdk.Pixbuf.LoadFromResource (resource); //no scaling in the given size, ... IconSource source = new IconSource (); source.Size = iconSize; source.SizeWildcarded = false; source.Pixbuf = img; iconset.AddSource (source); //... but allow to use the image for all other sizes, too. source = new IconSource (); source.SizeWildcarded = true; source.Pixbuf = img; iconset.AddSource (source); stock.Add (stockid, iconset); } }
protected override void Render (Gdk.Drawable drawable, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (source == null || source is SourceManager.GroupSource) { return; } view = widget as SourceView; bool selected = view != null && view.Selection.IterIsSelected (iter); StateType state = RendererStateToWidgetState (widget, flags); RenderSelection (drawable, background_area, selected, state); int title_layout_width = 0, title_layout_height = 0; int count_layout_width = 0, count_layout_height = 0; int max_title_layout_width; int img_padding = 6; int expander_icon_spacing = 3; int x = cell_area.X; bool np_etc = (source.Order + Depth * 100) < 40; if (!np_etc) { x += Depth * img_padding + (int)Xpad; } else { // Don't indent NowPlaying and Play Queue as much x += Math.Max (0, (int)Xpad - 2); } Gdk.GC main_gc = widget.Style.TextGC (state); // Draw the expander if the source has children double exp_h = (cell_area.Height - 2.0*Ypad) / 3.2; double exp_w = exp_h * 1.6; if (view != null && view.Cr != null && source.Children != null && source.Children.Count > 0) { var r = new Gdk.Rectangle (x, cell_area.Y + (int)((cell_area.Height - exp_h) / 2.0), (int)exp_w, (int)exp_h); view.Theme.DrawArrow (view.Cr, r, source.Expanded ? Math.PI/2.0 : 0.0); } if (!np_etc) { x += (int) exp_w; x += 2; // a little spacing after the expander expander_right_x = x; } // Draw icon Pixbuf icon = SourceIconResolver.ResolveIcon (source, RowHeight); bool dispose_icon = false; if (state == StateType.Insensitive) { // Code ported from gtk_cell_renderer_pixbuf_render() var icon_source = new IconSource () { Pixbuf = icon, Size = IconSize.SmallToolbar, SizeWildcarded = false }; icon = widget.Style.RenderIcon (icon_source, widget.Direction, state, (IconSize)(-1), widget, "SourceRowRenderer"); dispose_icon = true; icon_source.Dispose (); } if (icon != null) { x += expander_icon_spacing; drawable.DrawPixbuf (main_gc, icon, 0, 0, x, Middle (cell_area, icon.Height), icon.Width, icon.Height, RgbDither.None, 0, 0); x += icon.Width; if (dispose_icon) { icon.Dispose (); } } // Setup font info for the title/count, and see if we should show the count bool hide_count = source.EnabledCount <= 0 || source.Properties.Get<bool> ("SourceView.HideCount"); FontDescription fd = widget.PangoContext.FontDescription.Copy (); fd.Weight = (ISource)ServiceManager.PlaybackController.NextSource == (ISource)source ? Pango.Weight.Bold : Pango.Weight.Normal; if (view != null && source == view.NewPlaylistSource) { fd.Style = Pango.Style.Italic; hide_count = true; } Pango.Layout title_layout = new Pango.Layout (widget.PangoContext); Pango.Layout count_layout = null; // If we have a count to draw, setup its fonts and see how wide it is to see if we have room if (!hide_count) { count_layout = new Pango.Layout (widget.PangoContext); count_layout.FontDescription = fd; count_layout.SetMarkup (String.Format ("<span size=\"small\">{0}</span>", source.EnabledCount)); count_layout.GetPixelSize (out count_layout_width, out count_layout_height); } // Hide the count if the title has no space max_title_layout_width = cell_area.Width - x - count_layout_width;//(icon == null ? 0 : icon.Width) - count_layout_width - 10; if (!hide_count && max_title_layout_width <= 0) { hide_count = true; } // Draw the source Name title_layout.FontDescription = fd; title_layout.Width = (int)(max_title_layout_width * Pango.Scale.PangoScale); title_layout.Ellipsize = EllipsizeMode.End; title_layout.SetText (source.Name); title_layout.GetPixelSize (out title_layout_width, out title_layout_height); x += img_padding; drawable.DrawLayout (main_gc, x, Middle (cell_area, title_layout_height), title_layout); title_layout.Dispose (); // Draw the count if (!hide_count) { if (view != null && view.Cr != null) { view.Cr.Color = state == StateType.Normal || (view != null && state == StateType.Prelight) ? view.Theme.TextMidColor : view.Theme.Colors.GetWidgetColor (GtkColorClass.Text, state); view.Cr.MoveTo ( cell_area.X + cell_area.Width - count_layout_width - 2, cell_area.Y + 0.5 + (double)(cell_area.Height - count_layout_height) / 2.0); PangoCairoHelper.ShowLayout (view.Cr, count_layout); } count_layout.Dispose (); } fd.Dispose (); }
static void AddToIconFactory (string stockId, Gdk.Pixbuf pixbuf, Gdk.Pixbuf pixbuf2x, Gtk.IconSize iconSize) { Gtk.IconSet iconSet = iconFactory.Lookup (stockId); if (iconSet == null) { iconSet = new Gtk.IconSet (); iconFactory.Add (stockId, iconSet); } Gtk.IconSource source = new Gtk.IconSource (); Gtk.IconSource source2x = null; if (Platform.IsWindows) { var pixel_scale = GtkWorkarounds.GetPixelScale (); source.Pixbuf = pixbuf.ScaleSimple ((int)(pixbuf.Width * pixel_scale), (int)(pixbuf.Height * pixel_scale), Gdk.InterpType.Bilinear); } else { source.Pixbuf = pixbuf; } source.Size = iconSize; source.SizeWildcarded = iconSize == Gtk.IconSize.Invalid; if (pixbuf2x != null) { if (GtkWorkarounds.SetSourceScale (source, 1)) { GtkWorkarounds.SetSourceScaleWildcarded (source, false); source2x = new Gtk.IconSource (); source2x.Pixbuf = pixbuf2x; source2x.Size = iconSize; source2x.SizeWildcarded = iconSize == Gtk.IconSize.Invalid; GtkWorkarounds.SetSourceScale (source2x, 2); GtkWorkarounds.SetSourceScaleWildcarded (source2x, false); } } else { GtkWorkarounds.SetSourceScaleWildcarded (source, true); } iconSet.AddSource (source); if (source2x != null) iconSet.AddSource (source2x); }
public static void Load(string themePath) { if (themePath == null) throw new ArgumentNullException("themePath"); if (themePath.Length == 0) throw new ArgumentException("Argument is empty", "themePath"); // gtk requires an absolute path if (!Path.IsPathRooted(themePath)) throw new ArgumentException("Path must be absolute", "themePath"); if (!Directory.Exists(themePath)) throw new DirectoryNotFoundException(string.Format("Path to theme \"{0}\" not found", themePath)); //IconSize[] iconSizes = (IconSize[])Enum.GetValues(typeof(IconSize)); // all icon sizes the app uses IconSize[] iconSizes = { IconSize.Menu, /* 16px */ IconSize.LargeToolbar, /* 24px */ IconSize.Button, /* 24px */ IconSize.Dialog /* 48px */ }; Dictionary<string, string> iconNames = GetAllIconNames(); IconFactory fac = new IconFactory(); foreach (KeyValuePair<string, string> namePair in iconNames) { string name = namePair.Key; string nameInCustomTheme = namePair.Value; IconSet iconSet = new IconSet(); bool setHasSources = false; foreach (Gtk.IconSize size in iconSizes) { int sz = IconUtils.GetIconSizeVal(size); string fullPath = Path.Combine(Path.Combine(themePath, sz.ToString()), nameInCustomTheme); if (!File.Exists(fullPath)) { if (Global.EnableDebugging) { Debug.WriteLine(string.Format("IconTheme: could not find custom icon for \"{0}\" (size = {1}), using system default", name, sz)); } continue; } IconSource source = new IconSource(); #if LOAD_PIXBUFS source.Pixbuf = new Gdk.Pixbuf(fullPath); #else source.Filename = fullPath; #endif source.Size = size; //source.IconName = name; source.SizeWildcarded = false; iconSet.AddSource(source); setHasSources = true; } if (setHasSources) fac.Add(name, iconSet); } fac.AddDefault(); // add icon factory to the apps default factories }
public BookmarkAction(Browser browser) : base("Bookmark", "_Bookmark") { this.browser = browser; IconSet bookmark_iconset = new IconSet(); IconSource bookmark_iconsource = new IconSource(); bookmark_iconsource.IconName = "bookmark-new"; bookmark_iconset.AddSource(bookmark_iconsource); browser.factory.Add("summa-bookmark-new", bookmark_iconset); Tooltip = "Bookmark this item"; StockId = "summa-bookmark-new"; Activated += Bookmark; switch(Config.Bookmarker) { case "Native": bookmarker = new NativeBookmarker(); break; case "Dieu": bookmarker = new DieuBookmarker(); break; } }
/// <summary> /// Updates the entire treeview with the latest bugs /// </summary> public void SyncTreeviewWithBugs() { Console.WriteLine ("Syncing treeview with bugs " + SplatterCore.Instance.Queries.Count); // Clear all the items in the store bugStore.Clear(); Gdk.Pixbuf unreadMessageIcon = IconFactory.LookupDefault(Stock.Info).RenderIcon(this.Style, TextDirection.Ltr, StateType.Active, IconSize.Menu, null, null); IconSource sdf = new IconSource(); // Iterate over all the queries and display them foreach(Query q in SplatterCore.Instance.Queries) { TreeIter queryIter = bugStore.AppendValues(null, q.Generator.Title); // Display individual bugs foreach(BugReport bug in q.Bugs) { string rowName = bug.summary; if(bug.BugChangedFlag) { rowName = "<b>" + rowName + "</b>"; } if(bug.NewCommentFlag) { bugStore.AppendValues(queryIter, unreadMessageIcon, rowName); } else { bugStore.AppendValues(queryIter, null, rowName); } } // Check if the query has an expendaded tree if(q.TreeExpanded) { treeview1.ExpandRow(bugStore.GetPath(queryIter) , false); } } }
protected override void Render (Gdk.Drawable drawable, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (source == null) { return; } view = widget as SourceView; bool selected = view != null && view.Selection.IterIsSelected (iter); StateType state = RendererStateToWidgetState (widget, flags); RenderSelection (drawable, background_area, selected, state); int title_layout_width = 0, title_layout_height = 0; int count_layout_width = 0, count_layout_height = 0; int max_title_layout_width; bool hide_counts = source.EnabledCount <= 0; Pixbuf icon = SourceIconResolver.ResolveIcon (source, RowHeight); bool dispose_icon = false; if (state == StateType.Insensitive) { // Code ported from gtk_cell_renderer_pixbuf_render() var icon_source = new IconSource () { Pixbuf = icon, Size = IconSize.SmallToolbar, SizeWildcarded = false }; icon = widget.Style.RenderIcon (icon_source, widget.Direction, state, (IconSize)(-1), widget, "SourceRowRenderer"); dispose_icon = true; icon_source.Dispose (); } FontDescription fd = widget.PangoContext.FontDescription.Copy (); fd.Weight = (ISource)ServiceManager.PlaybackController.NextSource == (ISource)source ? Pango.Weight.Bold : Pango.Weight.Normal; if (view != null && source == view.NewPlaylistSource) { fd.Style = Pango.Style.Italic; hide_counts = true; } Pango.Layout title_layout = new Pango.Layout (widget.PangoContext); Pango.Layout count_layout = null; if (!hide_counts) { count_layout = new Pango.Layout (widget.PangoContext); count_layout.FontDescription = fd; count_layout.SetMarkup (String.Format ("<span size=\"small\">{0}</span>", source.EnabledCount)); count_layout.GetPixelSize (out count_layout_width, out count_layout_height); } max_title_layout_width = cell_area.Width - (icon == null ? 0 : icon.Width) - count_layout_width - 10; if (!hide_counts && max_title_layout_width < 0) { hide_counts = true; } title_layout.FontDescription = fd; title_layout.Width = (int)(max_title_layout_width * Pango.Scale.PangoScale); title_layout.Ellipsize = EllipsizeMode.End; title_layout.SetText (source.Name); title_layout.GetPixelSize (out title_layout_width, out title_layout_height); Gdk.GC main_gc = widget.Style.TextGC (state); drawable.DrawLayout (main_gc, cell_area.X + (icon == null ? 0 : icon.Width) + 6, Middle (cell_area, title_layout_height), title_layout); title_layout.Dispose (); if (icon != null) { drawable.DrawPixbuf (main_gc, icon, 0, 0, cell_area.X, Middle (cell_area, icon.Height), icon.Width, icon.Height, RgbDither.None, 0, 0); if (dispose_icon) { icon.Dispose (); } } if (hide_counts) { fd.Dispose (); return; } if (view != null && view.Cr != null) { view.Cr.Color = state == StateType.Normal || (view != null && state == StateType.Prelight) ? view.Theme.TextMidColor : view.Theme.Colors.GetWidgetColor (GtkColorClass.Text, state); view.Cr.MoveTo ( cell_area.X + cell_area.Width - count_layout_width - 2, cell_area.Y + 0.5 + (double)(cell_area.Height - count_layout_height) / 2.0); PangoCairoHelper.ShowLayout (view.Cr, count_layout); } count_layout.Dispose (); fd.Dispose (); }
private static void ConfigIconSource(Pixbuf pixbuf, IconSource iconSource) { iconSource.Pixbuf = pixbuf; iconSource.Size = IconSize.Button; iconSource.SizeWildcarded = false; }
public static void Initialize() { IconFactory icon_factory = new IconFactory(); icon_factory.AddDefault(); foreach (string item_id in stock_icon_names) { StockItem item = new StockItem(item_id, null, 0, Gdk.ModifierType.ShiftMask, null); IconSet icon_set = null; string file = System.IO.Path.Combine(MainClass.Paths.ResDir, item_id); icon_set = new IconSet(); if (System.IO.File.Exists(file)){ try{ IconSource source = new IconSource(); source.Pixbuf = new Pixbuf(file); source.Size = IconSize.LargeToolbar; icon_set.AddSource(source); }catch(Exception ex){ Tool.Logger.Error(ex.Message); //continue; } } if (icon_set == null) { continue; } icon_factory.Add(item.StockId, icon_set); StockManager.Add(item); } }