;; hack1.ffi				-*- Scheme -*-

;; Copyright (C) 2018 Matthew R. Wette
;;
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
;; License as published by the Free Software Foundation; either
;; version 3 of the License, or (at your option) any later version.
;;
;; This library 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
;; Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public License
;; along with this library; if not, see <http://www.gnu.org/licenses/>

;; This illustrates use of `#:api-code' option which allows user to generate
;; the equivalent of a custom include file.

(define-ffi-module (ffi hack1)
  #:pkg-config "gtk+-2.0"
  ;;#:def-types '("GtkWidget" "GtkContainer")
  #|
  #:api-code "
  #include <gtk/gtk.h>
  void gtk_init(int *argc, char ***argv);
  gulong g_signal_connect_data(gpointer instance, 
                               const gchar *detailed_signal,
                               GCallback c_handler, gpointer data, 
                               GClosureNotify destroy_data, 
                               GConnectFlags connect_flags);
  void gtk_container_set_border_width(GtkContainer *container,
				      guint border_width);
  void gtk_container_add(GtkContainer *container, GtkWidget *widget);
  void gtk_widget_show(GtkWidget *widget);
  void gtk_widget_destroy(GtkWidget *widget);
  void gtk_main(void);
  void gtk_main_quit(void);
  "
  |#
  #:include '("gtk/gtk.h" "glib-object.h")
  #:inc-filter (lambda (file-spec path-spec)
		 (or (string=? file-spec "<glibconfig.h>")
		     (string-contains path-spec "glib/" 0)
		     (string-contains path-spec "gobject/" 0)
		     ;;(string-contains path-spec "pango/" 0)
		     ;;(string-contains path-spec "gdk/" 0)
		     (string-contains path-spec "gtk/" 0)
		     ))
  #:decl-filter (lambda (name)
		  (member name '("gtk_init" "gtk_main" "gtk_main_quit"
				 "g_signal_connect_data"
				 "gtk_container_add" "gtk_container_set_border"
				 "gtk_widget_show" "gtk_widget_destroy"
				 )))
  )

(define-public (g_signal_connect instance detailed_signal c_handler data)
  (g_signal_connect_data instance detailed_signal c_handler data NULL 0))

;; --- last line ---
