]> ToastFreeware Gitweb - gregoa/zavai.git/blobdiff - gtkfisheyelist/demo.vala
Make a library with gtkfisheyelist and split main as a demo
[gregoa/zavai.git] / gtkfisheyelist / demo.vala
diff --git a/gtkfisheyelist/demo.vala b/gtkfisheyelist/demo.vala
new file mode 100644 (file)
index 0000000..64c7290
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Demo for FisheyeListView
+ *
+ * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+using GLib;
+
+public class Fisheye : Gtk.Window
+{
+       Gtk.ListStore model;
+       FisheyeListView flv;
+
+       public Fisheye()
+       {
+               title = "Fisheye";
+               destroy += Gtk.main_quit;
+
+               flv = new FisheyeListView();
+               add(flv);
+
+               model = new Gtk.ListStore(1, typeof(string));
+               Gtk.TreeIter iter;
+               var infd = FileStream.open("/tmp/names", "r");
+               if (infd == null)
+               {
+                       for (int i = 0; i < 300; ++i)
+                       {
+                               model.append(out iter);
+                               model.set(iter, 0, "Antani %d".printf(i), -1);
+                       }
+               } else {
+                       char buf[255];
+                       while (true)
+                       {
+                               string line = infd.gets(buf);
+                               if (line == null)
+                                       break;
+                               model.append(out iter);
+                               model.set(iter, 0, line, -1);
+                       }
+               }
+
+               flv.set_model(model);
+
+               flv.row_activated += on_row_activated;
+       }
+
+       public void on_row_activated(Gtk.TreePath path)
+       {
+               Gtk.TreeIter iter;
+               model.get_iter(out iter, path);
+               string val;
+               model.get(iter, 0, out val, -1);
+               stdout.printf("Clicked on %s\n", val);
+       }
+}
+
+static int main (string[] args) {
+       Gtk.init (ref args);
+
+       var fe = new Fisheye();
+       fe.set_size_request(200, 300);
+       fe.show_all();
+
+       Gtk.main();
+
+       return 0;
+}