From 8e7348d260cffa10d089496c544548207f968745 Mon Sep 17 00:00:00 2001 From: John Luke Date: Sun, 8 Aug 2004 18:30:25 +0000 Subject: [PATCH] implement Progressive image loader and part of the stock browser svn path=/trunk/gtk-sharp/; revision=32053 --- sample/GtkDemo/DemoImages.cs | 31 ++++++++++++++++--------- sample/GtkDemo/DemoStockBrowser.cs | 36 +++++++++++++++++++++++++----- sample/GtkDemo/TODO | 2 +- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/sample/GtkDemo/DemoImages.cs b/sample/GtkDemo/DemoImages.cs index 891113cc6..673d9b753 100644 --- a/sample/GtkDemo/DemoImages.cs +++ b/sample/GtkDemo/DemoImages.cs @@ -37,6 +37,7 @@ namespace GtkDemo { private static Gtk.Image progressiveImage; private VBox vbox; + BinaryReader imageStream; public DemoImages () : base ("images") { @@ -133,20 +134,30 @@ namespace GtkDemo * The timeout simply simulates a slow data source by inserting * pauses in the reading process. */ - timeout_id = GLib.Timeout.Add(150, new GLib.TimeoutHandler(ProgressiveTimeout)); + timeout_id = GLib.Timeout.Add (150, new GLib.TimeoutHandler (ProgressiveTimeout)); } static Gdk.PixbufLoader pixbufLoader; - // TODO: Finish this callback - // Decide if we want to perform crazy error handling - private bool ProgressiveTimeout() + // TODO: Decide if we want to perform crazy error handling + private bool ProgressiveTimeout () { - Gtk.Image imageStream = new Gtk.Image ("images/alphatest.png"); - pixbufLoader = new Gdk.PixbufLoader (); - pixbufLoader.AreaPrepared += new EventHandler (ProgressivePreparedCallback); - pixbufLoader.AreaUpdated += new AreaUpdatedHandler (ProgressiveUpdatedCallback); - return true; + if (imageStream == null) { + imageStream = new BinaryReader (new StreamReader ("images/alphatest.png").BaseStream); + pixbufLoader = new Gdk.PixbufLoader (); + pixbufLoader.AreaPrepared += new EventHandler (ProgressivePreparedCallback); + pixbufLoader.AreaUpdated += new AreaUpdatedHandler (ProgressiveUpdatedCallback); + } + + if (imageStream.PeekChar () != -1) { + byte[] bytes = imageStream.ReadBytes (256); + pixbufLoader.Write (bytes, (uint) bytes.Length); + return true; // leave the timeout active + } + else { + imageStream.Close (); + return false; // removes the timeout + } } static void ProgressivePreparedCallback (object obj, EventArgs args) @@ -158,7 +169,7 @@ namespace GtkDemo static void ProgressiveUpdatedCallback (object obj, AreaUpdatedArgs args) { - + progressiveImage.QueueDraw (); } } } diff --git a/sample/GtkDemo/DemoStockBrowser.cs b/sample/GtkDemo/DemoStockBrowser.cs index b7118bc28..f896aab2a 100644 --- a/sample/GtkDemo/DemoStockBrowser.cs +++ b/sample/GtkDemo/DemoStockBrowser.cs @@ -30,7 +30,10 @@ namespace GtkDemo list.AppendColumn ("Name", new CellRendererText (), "text", 1); list.AppendColumn ("Label", new CellRendererText (), "text", 2); list.AppendColumn ("Accel", new CellRendererText (), "text", 3); + list.AppendColumn ("ID", new CellRendererText (), "text", 4); list.Model = CreateStore (); + + list.Selection.Changed += new EventHandler (OnSelectionChanged); scrolledWindow.Add (list); Frame frame = new Frame (); @@ -41,17 +44,38 @@ namespace GtkDemo private ListStore CreateStore () { - // image, name, label, accel - ListStore store = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof(string), typeof(string), typeof(string)); - - for (int i =1; i < 10; i++) + // image, name, label, accel, id + ListStore store = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof(string), typeof(string), typeof(string), typeof (string)); + + string[] stock_ids = Gtk.Stock.ListIds (); + + foreach (string s in stock_ids) { - Image icon = new Image ("images/MonoIcon.png"); - store.AppendValues (icon, "Gtk.Stock.Ok", "Ok", "_Ok"); + Gtk.StockItem si; + /* Gtk.Stock.Lookup is not being generated + if (Gtk.Stock.Lookup (out si)) { + Image icon = new Image (s, IconSize.Menu); + store.AppendValues (si.Pixbuf, si.Label, "Ok", "_Ok", si.StockId); + } + else { + Console.WriteLine ("StockItem {0} could not be found.", s); + } + */ } return store; } + + void OnSelectionChanged (object o, EventArgs args) + { + TreeIter iter; + TreeModel model; + + if (((TreeSelection) o).GetSelected (out model, out iter)) + { + // update the frame + } + } private void WindowDelete (object o, DeleteEventArgs args) { diff --git a/sample/GtkDemo/TODO b/sample/GtkDemo/TODO index aad5dba45..f3a452e2a 100644 --- a/sample/GtkDemo/TODO +++ b/sample/GtkDemo/TODO @@ -9,7 +9,7 @@ DemoIconFactory - almost everything DemoImages - - fix the progressive loading image + - improve the Progressive Image loading and error handling DemoStockBrowser - almost everything