;;;; CLisp library demo with the Gtk-Server 2.0.7 ;;;; Tested with CLisp 2.35 on Windows and Linux ;;;; ;;;; January 5, 2006 - Leonardo Cecchi (defpackage :gtk-server-demo (:use :common-lisp) (:export :main)) (in-package :gtk-server-demo) (ffi:def-call-out c-gtk (:name "gtk") (:arguments (command-string ffi:c-string)) (:return-type ffi:c-string) #+win32 (:library "gtk-server.dll") #+unix (:library "libgtk-server.so") (:language :stdc) ) (defun gtk (&rest args) "The lisp redefined gtk call. Has a variabile number of arguments" (c-gtk (apply #'concatenate 'string (loop for arg in args collecting arg collecting " ")))) (defun main () "Simple demo with a window and a textbox" (let (window vbox hbox bt-ok bt-cancel entry) ;; Gtk Library Init (gtk "gtk_init NULL NULL") ;; Component creation (setf window (gtk "gtk_window_new 0")) (setf vbox (gtk "gtk_vbox_new 0 2")) (setf hbox (gtk "gtk_hbox_new 0 2")) (setf bt-ok (gtk "gtk_button_new_with_label Ok")) (setf bt-cancel (gtk "gtk_button_new_with_label Cancel")) (setf entry (gtk "gtk_entry_new")) ;; Component packing and adding (gtk "gtk_box_pack_start" hbox bt-ok "1 1 2") (gtk "gtk_box_pack_start" hbox bt-cancel "1 1 2") (gtk "gtk_box_pack_start" vbox entry "0 1 2") (gtk "gtk_box_pack_end" vbox hbox "0 1 2") (gtk "gtk_container_add" window vbox) ;; Component property customization (gtk "gtk_window_set_title" window "\"Demo Window\"") (gtk "gtk_window_set_position" window "1") ;; Show all (gtk "gtk_widget_show_all" window) ;; Event loop (loop for event = (gtk "gtk_server_callback WAIT") when (string= event window) do (return) when (string= event bt-cancel) do (return) when (string= event bt-ok) do (format t "You entered: ~a~%" (gtk "gtk_entry_get_text" entry))) ;; Exit (gtk "gtk_server_exit")))