2005-01-02 19:16:41 +00:00
|
|
|
/* Stock Item and Icon Browser
|
|
|
|
*
|
|
|
|
* This source code for this demo doesn't demonstrate anything
|
|
|
|
* particularly useful in applications. The purpose of the "demo" is
|
|
|
|
* just to provide a handy place to browse the available stock icons
|
|
|
|
* and stock items.
|
|
|
|
*/
|
|
|
|
|
2003-10-30 Daniel Kornhauser Eisenberg <dkor@alum.mit.edu>
* sample/GtkDemo/DemoApplicationWindow.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoButtonBox.cs : New sample,
* sample/GtkDemo/DemoColorSelection.cs : New sample,
* sample/GtkDemo/DemoDialog.cs : New sample,
* sample/GtkDemo/DemoDrawingArea.cs : New sample,
* sample/GtkDemo/DemoEditableCells.cs : New sample, Needs clean up
* sample/GtkDemo/DemoImages.cs : New sample, Unfinished, 75% Done
* sample/GtkDemo/DemoItemFactory.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoListStore.cs : New sample,
* sample/GtkDemo/DemoMain.cs : New sample, Unifnished, 60% Done
* sample/GtkDemo/DemoMenus.cs : New sample,
* sample/GtkDemo/DemoPanes.cs : New sample,
* sample/GtkDemo/DemoPixbuf.cs : New sample, Needs clean up
* sample/GtkDemo/DemoSizeGroup.cs : New sample,
* sample/GtkDemo/DemoStockBrowser.cs : New sample, Unfinished, 20% Done
* sample/GtkDemo/DemoTextView.cs : New sample, Unfinished, 99% Done
* sample/GtkDemo/DemoTreeStore.cs : New sample, Unfinished, 95% Done
* sample/GtkDemo/images : Several Images for the samples
* sample/GtkDemo/Makefile : Very simple Makefile
* sample/GtkDemo/README : Mentions explicitely unfinished state of port
svn path=/trunk/gtk-sharp/; revision=19489
2003-10-30 23:57:41 +00:00
|
|
|
using System;
|
2004-08-28 20:04:41 +00:00
|
|
|
using System.Collections;
|
2005-04-01 21:08:14 +00:00
|
|
|
using System.Reflection;
|
2003-10-30 Daniel Kornhauser Eisenberg <dkor@alum.mit.edu>
* sample/GtkDemo/DemoApplicationWindow.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoButtonBox.cs : New sample,
* sample/GtkDemo/DemoColorSelection.cs : New sample,
* sample/GtkDemo/DemoDialog.cs : New sample,
* sample/GtkDemo/DemoDrawingArea.cs : New sample,
* sample/GtkDemo/DemoEditableCells.cs : New sample, Needs clean up
* sample/GtkDemo/DemoImages.cs : New sample, Unfinished, 75% Done
* sample/GtkDemo/DemoItemFactory.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoListStore.cs : New sample,
* sample/GtkDemo/DemoMain.cs : New sample, Unifnished, 60% Done
* sample/GtkDemo/DemoMenus.cs : New sample,
* sample/GtkDemo/DemoPanes.cs : New sample,
* sample/GtkDemo/DemoPixbuf.cs : New sample, Needs clean up
* sample/GtkDemo/DemoSizeGroup.cs : New sample,
* sample/GtkDemo/DemoStockBrowser.cs : New sample, Unfinished, 20% Done
* sample/GtkDemo/DemoTextView.cs : New sample, Unfinished, 99% Done
* sample/GtkDemo/DemoTreeStore.cs : New sample, Unfinished, 95% Done
* sample/GtkDemo/images : Several Images for the samples
* sample/GtkDemo/Makefile : Very simple Makefile
* sample/GtkDemo/README : Mentions explicitely unfinished state of port
svn path=/trunk/gtk-sharp/; revision=19489
2003-10-30 23:57:41 +00:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
namespace GtkDemo
|
2005-04-01 21:08:14 +00:00
|
|
|
{
|
2004-12-12 22:11:44 +00:00
|
|
|
[Demo ("Stock Item and Icon Browser", "DemoStockBrowser.cs")]
|
2004-08-07 17:06:29 +00:00
|
|
|
public class DemoStockBrowser : Gtk.Window
|
2003-10-30 Daniel Kornhauser Eisenberg <dkor@alum.mit.edu>
* sample/GtkDemo/DemoApplicationWindow.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoButtonBox.cs : New sample,
* sample/GtkDemo/DemoColorSelection.cs : New sample,
* sample/GtkDemo/DemoDialog.cs : New sample,
* sample/GtkDemo/DemoDrawingArea.cs : New sample,
* sample/GtkDemo/DemoEditableCells.cs : New sample, Needs clean up
* sample/GtkDemo/DemoImages.cs : New sample, Unfinished, 75% Done
* sample/GtkDemo/DemoItemFactory.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoListStore.cs : New sample,
* sample/GtkDemo/DemoMain.cs : New sample, Unifnished, 60% Done
* sample/GtkDemo/DemoMenus.cs : New sample,
* sample/GtkDemo/DemoPanes.cs : New sample,
* sample/GtkDemo/DemoPixbuf.cs : New sample, Needs clean up
* sample/GtkDemo/DemoSizeGroup.cs : New sample,
* sample/GtkDemo/DemoStockBrowser.cs : New sample, Unfinished, 20% Done
* sample/GtkDemo/DemoTextView.cs : New sample, Unfinished, 99% Done
* sample/GtkDemo/DemoTreeStore.cs : New sample, Unfinished, 95% Done
* sample/GtkDemo/images : Several Images for the samples
* sample/GtkDemo/Makefile : Very simple Makefile
* sample/GtkDemo/README : Mentions explicitely unfinished state of port
svn path=/trunk/gtk-sharp/; revision=19489
2003-10-30 23:57:41 +00:00
|
|
|
{
|
2005-04-01 21:08:14 +00:00
|
|
|
enum Column {
|
|
|
|
Id,
|
|
|
|
Name,
|
|
|
|
Label,
|
|
|
|
Accel,
|
|
|
|
};
|
2004-08-28 20:51:06 +00:00
|
|
|
|
2005-04-01 21:08:14 +00:00
|
|
|
Label typeLabel, nameLabel, idLabel, accelLabel;
|
|
|
|
Image iconImage;
|
|
|
|
|
|
|
|
public DemoStockBrowser () : base ("Stock Icons and Items")
|
2004-08-28 20:51:06 +00:00
|
|
|
{
|
2005-04-01 21:08:14 +00:00
|
|
|
SetDefaultSize (-1, 500);
|
|
|
|
BorderWidth = 8;
|
2004-08-28 20:51:06 +00:00
|
|
|
|
2005-04-01 21:08:14 +00:00
|
|
|
HBox hbox = new HBox (false, 8);
|
|
|
|
Add (hbox);
|
|
|
|
|
|
|
|
ScrolledWindow sw = new ScrolledWindow ();
|
|
|
|
sw.SetPolicy (PolicyType.Never, PolicyType.Automatic);
|
|
|
|
hbox.PackStart (sw, false, false, 0);
|
|
|
|
|
|
|
|
ListStore model = CreateModel ();
|
|
|
|
|
|
|
|
TreeView treeview = new TreeView (model);
|
|
|
|
sw.Add (treeview);
|
|
|
|
|
|
|
|
TreeViewColumn column = new TreeViewColumn ();
|
|
|
|
column.Title = "Name";
|
|
|
|
CellRenderer renderer = new CellRendererPixbuf ();
|
|
|
|
column.PackStart (renderer, false);
|
|
|
|
column.SetAttributes (renderer, "stock_id", Column.Id);
|
|
|
|
renderer = new CellRendererText ();
|
|
|
|
column.PackStart (renderer, true);
|
|
|
|
column.SetAttributes (renderer, "text", Column.Name);
|
|
|
|
|
|
|
|
treeview.AppendColumn (column);
|
|
|
|
treeview.AppendColumn ("Label", new CellRendererText (), "text", Column.Label);
|
|
|
|
treeview.AppendColumn ("Accel", new CellRendererText (), "text", Column.Accel);
|
|
|
|
treeview.AppendColumn ("ID", new CellRendererText (), "text", Column.Id);
|
|
|
|
|
|
|
|
Alignment align = new Alignment (0.5f, 0.0f, 0.0f, 0.0f);
|
|
|
|
hbox.PackEnd (align, false, false, 0);
|
|
|
|
|
|
|
|
Frame frame = new Frame ("Selected Item");
|
|
|
|
align.Add (frame);
|
|
|
|
|
|
|
|
VBox vbox = new VBox (false, 8);
|
|
|
|
vbox.BorderWidth = 8;
|
|
|
|
frame.Add (vbox);
|
|
|
|
|
|
|
|
typeLabel = new Label ();
|
|
|
|
vbox.PackStart (typeLabel, false, false, 0);
|
|
|
|
iconImage = new Gtk.Image ();
|
|
|
|
vbox.PackStart (iconImage, false, false, 0);
|
|
|
|
accelLabel = new Label ();
|
|
|
|
vbox.PackStart (accelLabel, false, false, 0);
|
|
|
|
nameLabel = new Label ();
|
|
|
|
vbox.PackStart (nameLabel, false, false, 0);
|
|
|
|
idLabel = new Label ();
|
|
|
|
vbox.PackStart (idLabel, false, false, 0);
|
|
|
|
|
|
|
|
treeview.Selection.Mode = Gtk.SelectionMode.Single;
|
|
|
|
treeview.Selection.Changed += new EventHandler (SelectionChanged);
|
|
|
|
|
|
|
|
ShowAll ();
|
2004-08-28 20:51:06 +00:00
|
|
|
}
|
|
|
|
|
2005-04-01 21:08:14 +00:00
|
|
|
private ListStore CreateModel ()
|
2003-10-30 Daniel Kornhauser Eisenberg <dkor@alum.mit.edu>
* sample/GtkDemo/DemoApplicationWindow.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoButtonBox.cs : New sample,
* sample/GtkDemo/DemoColorSelection.cs : New sample,
* sample/GtkDemo/DemoDialog.cs : New sample,
* sample/GtkDemo/DemoDrawingArea.cs : New sample,
* sample/GtkDemo/DemoEditableCells.cs : New sample, Needs clean up
* sample/GtkDemo/DemoImages.cs : New sample, Unfinished, 75% Done
* sample/GtkDemo/DemoItemFactory.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoListStore.cs : New sample,
* sample/GtkDemo/DemoMain.cs : New sample, Unifnished, 60% Done
* sample/GtkDemo/DemoMenus.cs : New sample,
* sample/GtkDemo/DemoPanes.cs : New sample,
* sample/GtkDemo/DemoPixbuf.cs : New sample, Needs clean up
* sample/GtkDemo/DemoSizeGroup.cs : New sample,
* sample/GtkDemo/DemoStockBrowser.cs : New sample, Unfinished, 20% Done
* sample/GtkDemo/DemoTextView.cs : New sample, Unfinished, 99% Done
* sample/GtkDemo/DemoTreeStore.cs : New sample, Unfinished, 95% Done
* sample/GtkDemo/images : Several Images for the samples
* sample/GtkDemo/Makefile : Very simple Makefile
* sample/GtkDemo/README : Mentions explicitely unfinished state of port
svn path=/trunk/gtk-sharp/; revision=19489
2003-10-30 23:57:41 +00:00
|
|
|
{
|
2005-04-01 21:08:14 +00:00
|
|
|
ListStore store = new Gtk.ListStore (typeof (string), typeof(string), typeof(string), typeof(string), typeof (string));
|
2004-08-08 18:30:25 +00:00
|
|
|
|
2005-04-01 21:08:14 +00:00
|
|
|
string[] stockIds = Gtk.Stock.ListIds ();
|
|
|
|
Array.Sort (stockIds);
|
2004-08-08 18:30:25 +00:00
|
|
|
|
2005-04-01 21:08:14 +00:00
|
|
|
// Use reflection to get the list of C# names
|
|
|
|
Hashtable idToName = new Hashtable ();
|
|
|
|
foreach (PropertyInfo info in typeof (Gtk.Stock).GetProperties (BindingFlags.Public | BindingFlags.Static)) {
|
|
|
|
if (info.PropertyType == typeof (string))
|
|
|
|
idToName[info.GetValue (null, null)] = "Gtk.Stock." + info.Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (string id in stockIds) {
|
2004-12-20 19:47:40 +00:00
|
|
|
Gtk.StockItem si;
|
2005-04-01 21:08:14 +00:00
|
|
|
string accel;
|
|
|
|
|
|
|
|
si = Gtk.Stock.Lookup (id);
|
|
|
|
if (si.Keyval != 0)
|
|
|
|
accel = Accelerator.Name (si.Keyval, si.Modifier);
|
|
|
|
else
|
|
|
|
accel = "";
|
|
|
|
|
|
|
|
store.AppendValues (id, idToName[id], si.Label, accel);
|
2003-10-30 Daniel Kornhauser Eisenberg <dkor@alum.mit.edu>
* sample/GtkDemo/DemoApplicationWindow.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoButtonBox.cs : New sample,
* sample/GtkDemo/DemoColorSelection.cs : New sample,
* sample/GtkDemo/DemoDialog.cs : New sample,
* sample/GtkDemo/DemoDrawingArea.cs : New sample,
* sample/GtkDemo/DemoEditableCells.cs : New sample, Needs clean up
* sample/GtkDemo/DemoImages.cs : New sample, Unfinished, 75% Done
* sample/GtkDemo/DemoItemFactory.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoListStore.cs : New sample,
* sample/GtkDemo/DemoMain.cs : New sample, Unifnished, 60% Done
* sample/GtkDemo/DemoMenus.cs : New sample,
* sample/GtkDemo/DemoPanes.cs : New sample,
* sample/GtkDemo/DemoPixbuf.cs : New sample, Needs clean up
* sample/GtkDemo/DemoSizeGroup.cs : New sample,
* sample/GtkDemo/DemoStockBrowser.cs : New sample, Unfinished, 20% Done
* sample/GtkDemo/DemoTextView.cs : New sample, Unfinished, 99% Done
* sample/GtkDemo/DemoTreeStore.cs : New sample, Unfinished, 95% Done
* sample/GtkDemo/images : Several Images for the samples
* sample/GtkDemo/Makefile : Very simple Makefile
* sample/GtkDemo/README : Mentions explicitely unfinished state of port
svn path=/trunk/gtk-sharp/; revision=19489
2003-10-30 23:57:41 +00:00
|
|
|
}
|
2005-04-01 21:08:14 +00:00
|
|
|
|
2003-10-30 Daniel Kornhauser Eisenberg <dkor@alum.mit.edu>
* sample/GtkDemo/DemoApplicationWindow.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoButtonBox.cs : New sample,
* sample/GtkDemo/DemoColorSelection.cs : New sample,
* sample/GtkDemo/DemoDialog.cs : New sample,
* sample/GtkDemo/DemoDrawingArea.cs : New sample,
* sample/GtkDemo/DemoEditableCells.cs : New sample, Needs clean up
* sample/GtkDemo/DemoImages.cs : New sample, Unfinished, 75% Done
* sample/GtkDemo/DemoItemFactory.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoListStore.cs : New sample,
* sample/GtkDemo/DemoMain.cs : New sample, Unifnished, 60% Done
* sample/GtkDemo/DemoMenus.cs : New sample,
* sample/GtkDemo/DemoPanes.cs : New sample,
* sample/GtkDemo/DemoPixbuf.cs : New sample, Needs clean up
* sample/GtkDemo/DemoSizeGroup.cs : New sample,
* sample/GtkDemo/DemoStockBrowser.cs : New sample, Unfinished, 20% Done
* sample/GtkDemo/DemoTextView.cs : New sample, Unfinished, 99% Done
* sample/GtkDemo/DemoTreeStore.cs : New sample, Unfinished, 95% Done
* sample/GtkDemo/images : Several Images for the samples
* sample/GtkDemo/Makefile : Very simple Makefile
* sample/GtkDemo/README : Mentions explicitely unfinished state of port
svn path=/trunk/gtk-sharp/; revision=19489
2003-10-30 23:57:41 +00:00
|
|
|
return store;
|
|
|
|
}
|
2004-08-08 18:30:25 +00:00
|
|
|
|
2005-04-01 21:08:14 +00:00
|
|
|
void SelectionChanged (object o, EventArgs args)
|
2004-08-10 19:50:10 +00:00
|
|
|
{
|
2005-04-01 21:08:14 +00:00
|
|
|
TreeSelection selection = (TreeSelection)o;
|
|
|
|
TreeIter iter;
|
|
|
|
TreeModel model;
|
2004-08-28 20:04:41 +00:00
|
|
|
|
2005-04-01 21:08:14 +00:00
|
|
|
if (selection.GetSelected (out model, out iter)) {
|
|
|
|
string id = (string) model.GetValue (iter, (int)Column.Id);
|
|
|
|
string name = (string) model.GetValue (iter, (int)Column.Name);
|
|
|
|
string label = (string) model.GetValue (iter, (int)Column.Label);
|
|
|
|
string accel = (string) model.GetValue (iter, (int)Column.Accel);
|
|
|
|
|
|
|
|
IconSize size = GetLargestSize (id);
|
|
|
|
bool icon = (size != IconSize.Invalid);
|
|
|
|
|
|
|
|
if (icon && label != null)
|
|
|
|
typeLabel.Text = "Icon and Item";
|
|
|
|
else if (icon)
|
|
|
|
typeLabel.Text = "Icon Only";
|
|
|
|
else if (label != null)
|
|
|
|
typeLabel.Text = "Item Only";
|
|
|
|
else
|
|
|
|
typeLabel.Text = "???????";
|
|
|
|
|
|
|
|
if (name != null)
|
|
|
|
nameLabel.Text = name;
|
|
|
|
else
|
|
|
|
nameLabel.Text = "";
|
|
|
|
|
|
|
|
idLabel.Text = id;
|
|
|
|
|
|
|
|
if (label != null)
|
|
|
|
accelLabel.TextWithMnemonic = label + " " + accel;
|
|
|
|
else
|
|
|
|
accelLabel.Text = "";
|
|
|
|
|
|
|
|
if (icon)
|
|
|
|
iconImage.SetFromStock (id, size);
|
|
|
|
else
|
|
|
|
iconImage.Pixbuf = null;
|
|
|
|
} else {
|
|
|
|
typeLabel.Text = "No selected item";
|
|
|
|
nameLabel.Text = "";
|
|
|
|
idLabel.Text = "";
|
|
|
|
accelLabel.Text = "";
|
|
|
|
iconImage.Pixbuf = null;
|
2004-08-28 20:04:41 +00:00
|
|
|
}
|
2004-08-10 19:50:10 +00:00
|
|
|
}
|
|
|
|
|
2005-04-01 21:08:14 +00:00
|
|
|
// Finds the largest size at which the given image stock id is
|
|
|
|
// available. This would not be useful for a normal application
|
|
|
|
|
|
|
|
private IconSize GetLargestSize (string stockId)
|
2004-08-10 19:50:10 +00:00
|
|
|
{
|
2005-04-01 21:08:14 +00:00
|
|
|
IconSet set = IconFactory.LookupDefault (stockId);
|
|
|
|
if (set == null)
|
|
|
|
return IconSize.Invalid;
|
|
|
|
|
|
|
|
IconSize[] sizes = set.Sizes;
|
|
|
|
IconSize bestSize = IconSize.Invalid;
|
|
|
|
int bestPixels = 0;
|
|
|
|
|
|
|
|
foreach (IconSize size in sizes) {
|
|
|
|
int width, height;
|
|
|
|
Gtk.Icon.SizeLookup (size, out width, out height);
|
|
|
|
if (width * height > bestPixels) {
|
|
|
|
bestSize = size;
|
|
|
|
bestPixels = width * height;
|
|
|
|
}
|
2004-08-28 20:04:41 +00:00
|
|
|
}
|
|
|
|
|
2005-04-01 21:08:14 +00:00
|
|
|
return bestSize;
|
2004-08-10 19:50:10 +00:00
|
|
|
}
|
|
|
|
|
2005-04-01 21:08:14 +00:00
|
|
|
protected override bool OnDeleteEvent (Gdk.Event evt)
|
2003-10-30 Daniel Kornhauser Eisenberg <dkor@alum.mit.edu>
* sample/GtkDemo/DemoApplicationWindow.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoButtonBox.cs : New sample,
* sample/GtkDemo/DemoColorSelection.cs : New sample,
* sample/GtkDemo/DemoDialog.cs : New sample,
* sample/GtkDemo/DemoDrawingArea.cs : New sample,
* sample/GtkDemo/DemoEditableCells.cs : New sample, Needs clean up
* sample/GtkDemo/DemoImages.cs : New sample, Unfinished, 75% Done
* sample/GtkDemo/DemoItemFactory.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoListStore.cs : New sample,
* sample/GtkDemo/DemoMain.cs : New sample, Unifnished, 60% Done
* sample/GtkDemo/DemoMenus.cs : New sample,
* sample/GtkDemo/DemoPanes.cs : New sample,
* sample/GtkDemo/DemoPixbuf.cs : New sample, Needs clean up
* sample/GtkDemo/DemoSizeGroup.cs : New sample,
* sample/GtkDemo/DemoStockBrowser.cs : New sample, Unfinished, 20% Done
* sample/GtkDemo/DemoTextView.cs : New sample, Unfinished, 99% Done
* sample/GtkDemo/DemoTreeStore.cs : New sample, Unfinished, 95% Done
* sample/GtkDemo/images : Several Images for the samples
* sample/GtkDemo/Makefile : Very simple Makefile
* sample/GtkDemo/README : Mentions explicitely unfinished state of port
svn path=/trunk/gtk-sharp/; revision=19489
2003-10-30 23:57:41 +00:00
|
|
|
{
|
2005-04-01 21:08:14 +00:00
|
|
|
Destroy ();
|
|
|
|
return true;
|
2003-10-30 Daniel Kornhauser Eisenberg <dkor@alum.mit.edu>
* sample/GtkDemo/DemoApplicationWindow.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoButtonBox.cs : New sample,
* sample/GtkDemo/DemoColorSelection.cs : New sample,
* sample/GtkDemo/DemoDialog.cs : New sample,
* sample/GtkDemo/DemoDrawingArea.cs : New sample,
* sample/GtkDemo/DemoEditableCells.cs : New sample, Needs clean up
* sample/GtkDemo/DemoImages.cs : New sample, Unfinished, 75% Done
* sample/GtkDemo/DemoItemFactory.cs : New sample, Unfinished, 5% Done
* sample/GtkDemo/DemoListStore.cs : New sample,
* sample/GtkDemo/DemoMain.cs : New sample, Unifnished, 60% Done
* sample/GtkDemo/DemoMenus.cs : New sample,
* sample/GtkDemo/DemoPanes.cs : New sample,
* sample/GtkDemo/DemoPixbuf.cs : New sample, Needs clean up
* sample/GtkDemo/DemoSizeGroup.cs : New sample,
* sample/GtkDemo/DemoStockBrowser.cs : New sample, Unfinished, 20% Done
* sample/GtkDemo/DemoTextView.cs : New sample, Unfinished, 99% Done
* sample/GtkDemo/DemoTreeStore.cs : New sample, Unfinished, 95% Done
* sample/GtkDemo/images : Several Images for the samples
* sample/GtkDemo/Makefile : Very simple Makefile
* sample/GtkDemo/README : Mentions explicitely unfinished state of port
svn path=/trunk/gtk-sharp/; revision=19489
2003-10-30 23:57:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|