Make a library with gtkfisheyelist and split main as a demo
authorEnrico Zini <enrico@enricozini.org>
Sun, 13 Dec 2009 11:31:29 +0000 (11:31 +0000)
committerEnrico Zini <enrico@enricozini.org>
Sun, 13 Dec 2009 11:31:29 +0000 (11:31 +0000)
gtkfisheyelist/CMakeLists.txt
gtkfisheyelist/demo.vala [new file with mode: 0644]
gtkfisheyelist/gtkfisheyelistview.vala

index 6de6e7ee6d927f7dd5b804f9193fee82ffdc8de4..5549f3ab851ffd88203c1e7017943c60c844e395 100644 (file)
@@ -9,17 +9,27 @@ pkg_check_modules(GTK REQUIRED gtk+-2.0)
 
 find_program(VALAC valac)
 
-file(GLOB fevala *.vala)
-string(REGEX REPLACE "^.+/(.+)\\.vala$" "${gtkfisheyelist_BINARY_DIR}/\\1.c" fesrc ${fevala})
-string(REGEX REPLACE "^.+/(.+)\\.vala$" "${gtkfisheyelist_BINARY_DIR}/\\1.h" fehdr ${fevala})
+file(GLOB fevala gtkfisheye*.vala)
+file(RELATIVE_PATH fesrc ${gtkfisheyelist_SOURCE_DIR} ${fevala})
+string(REGEX REPLACE "\\.vala$" ".c" fesrc ${fesrc})
+
+file(GLOB demovala demo*.vala)
+file(RELATIVE_PATH demosrc ${gtkfisheyelist_SOURCE_DIR} ${demovala})
+string(REGEX REPLACE "\\.vala$" ".c" demosrc ${demosrc})
 
 add_custom_command(
     DEPENDS ${fevala}
-    OUTPUT ${fesrc} ${fehdr}
-    COMMAND ${VALAC} ${VFLAGS} ${fevala}
+    OUTPUT ${fesrc} gtkfisheyelist.h gtkfisheyelist.vapi
+    COMMAND ${VALAC} ${VFLAGS} -H gtkfisheyelist.h --library=gtkfisheyelist ${fevala}
 )
 
-add_definitions(-Wall -Werror ${GTK_CFLAGS})
+add_custom_command(
+    DEPENDS ${demovala}
+    OUTPUT ${demosrc} ${demohdr}
+    COMMAND ${VALAC} ${VFLAGS} --pkg=gtkfisheyelist --vapidir=${gtkfisheyelist_BINARY_DIR} ${demovala}
+)
+
+add_definitions(-Wall -Werror ${GTK_CFLAGS} -I${gtkfisheyelist_BINARY_DIR})
 link_libraries(${GTK_LDFLAGS})
 
 set_source_files_properties(${fesrc} PROPERTIES GENERATED 1)
@@ -30,6 +40,9 @@ add_library(gtkfisheyelist-static STATIC ${fesrc})
 set_target_properties(gtkfisheyelist PROPERTIES VERSION ${gtkfisheyelist_version} SOVERSION 0 CLEAN_DIRECT_OUTPUT 1)
 set_target_properties(gtkfisheyelist-static PROPERTIES VERSION ${gtkfisheyelist_version} SOVERSION 0 OUTPUT_NAME "gtkfisheyelist" CLEAN_DIRECT_OUTPUT 1)
 
+add_executable(gtkfisheyedemo ${demosrc})
+target_link_libraries(gtkfisheyedemo gtkfisheyelist-static)
+
 set(prefix "${CMAKE_INSTALL_PREFIX}")
 set(exec_prefix "${prefix}/bin")
 set(libdir "${prefix}/lib")
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;
+}
index a09bee9c780e55234519dc8e9be7e71066a29c70..af2673ff509f31f336194adc3807112cc604fdac 100644 (file)
@@ -26,7 +26,6 @@ protected struct FocusInfo
        int renderer;
 }
 
-
 public class FisheyeListView : Gtk.DrawingArea
 {
        protected Gtk.TreeModel model;
@@ -527,65 +526,3 @@ public class FisheyeListView : Gtk.DrawingArea
         * See also http://www.cs.umd.edu/hcil/fisheyemenu/
         */
 }
-
-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;
-}