| 1 | ;; Common Lisp bindings for GTK+ v2.0 |
| 2 | ;; Copyright (C) 1999-2000 Espen S. Johnsen <espejohn@online.no> |
| 3 | ;; |
| 4 | ;; This library is free software; you can redistribute it and/or |
| 5 | ;; modify it under the terms of the GNU Lesser General Public |
| 6 | ;; License as published by the Free Software Foundation; either |
| 7 | ;; version 2 of the License, or (at your option) any later version. |
| 8 | ;; |
| 9 | ;; This library is distributed in the hope that it will be useful, |
| 10 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | ;; Lesser General Public License for more details. |
| 13 | ;; |
| 14 | ;; You should have received a copy of the GNU Lesser General Public |
| 15 | ;; License along with this library; if not, write to the Free Software |
| 16 | ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | |
| 18 | ;; $Id: gtkutils.lisp,v 1.2 2004-10-31 12:05:52 espen Exp $ |
| 19 | |
| 20 | |
| 21 | (in-package "GTK") |
| 22 | |
| 23 | |
| 24 | (defun v-box-new (&optional homogeneous (spacing 0)) |
| 25 | (make-instance 'v-box :homogeneous homogeneous :spacing spacing)) |
| 26 | |
| 27 | (defun create-button (specs &optional callback &rest args) |
| 28 | (destructuring-bind (label &rest initargs) (mklist specs) |
| 29 | (let ((button |
| 30 | (apply #'make-instance 'button :label label :visible t initargs))) |
| 31 | (if callback |
| 32 | (signal-connect |
| 33 | button 'clicked |
| 34 | #'(lambda () |
| 35 | (apply (funcallable callback) args))) |
| 36 | (setf (widget-sensitive-p button) nil)) |
| 37 | button))) |
| 38 | |
| 39 | (defun button-new (label &optional callback) |
| 40 | (let ((button (make-instance 'button :label label))) |
| 41 | (when callback |
| 42 | (signal-connect button 'clicked callback)) |
| 43 | button)) |
| 44 | |
| 45 | (defun label-new (label) |
| 46 | (make-instance 'label :label label)) |
| 47 | |
| 48 | |
| 49 | |
| 50 | (defun %create-toggleable-button (class label callback initstate initargs) |
| 51 | (let ((button |
| 52 | (apply #'make-instance class :label label :active initstate :visible t |
| 53 | initargs))) |
| 54 | (signal-connect |
| 55 | button 'toggled |
| 56 | #'(lambda () |
| 57 | (funcall (funcallable callback) (toggle-button-active-p button)))) |
| 58 | (funcall (funcallable callback) initstate) |
| 59 | button)) |
| 60 | |
| 61 | (defun create-toggle-button (label callback &optional initstate &rest initargs) |
| 62 | (%create-toggleable-button 'toggle-button label callback initstate initargs)) |
| 63 | |
| 64 | (defun create-check-button (label callback &optional initstate &rest initargs) |
| 65 | (%create-toggleable-button 'check-button label callback initstate initargs)) |
| 66 | |
| 67 | (defun create-radio-button-group (specs active &optional callback &rest args) |
| 68 | (let ((group nil) |
| 69 | (i 0)) |
| 70 | (mapcar |
| 71 | #'(lambda (spec) |
| 72 | (destructuring-bind |
| 73 | (label &optional object &rest initargs) (mklist spec) |
| 74 | (let ((button |
| 75 | (apply |
| 76 | #'make-instance 'radio-button |
| 77 | :label label :visible t initargs))) |
| 78 | (when group (%radio-button-set-group button group)) |
| 79 | (setq group (%radio-button-get-group button)) |
| 80 | (cond |
| 81 | (callback |
| 82 | (signal-connect |
| 83 | button 'toggled |
| 84 | #'(lambda () |
| 85 | (when (toggle-button-active-p button) |
| 86 | (apply (funcallable callback) object args))))) |
| 87 | (object |
| 88 | (signal-connect |
| 89 | button 'toggled |
| 90 | #'(lambda () |
| 91 | (apply |
| 92 | (funcallable object) |
| 93 | (toggle-button-active-p button) args))))) |
| 94 | (when (= i active) |
| 95 | (setf (toggle-button-active-p button) t)) |
| 96 | (incf i) |
| 97 | button))) |
| 98 | specs))) |
| 99 | |
| 100 | (defun create-option-menu (specs active &optional callback &rest initargs) |
| 101 | (let ((menu (make-instance 'menu)) |
| 102 | (group nil) |
| 103 | (i 0)) |
| 104 | (dolist (spec specs) |
| 105 | (destructuring-bind (label &optional item-callback) (mklist spec) |
| 106 | (let ((menu-item |
| 107 | (apply |
| 108 | #'make-instance 'radio-menu-item |
| 109 | :label label :active (= i active) initargs))) |
| 110 | (when group (%radio-menu-item-set-group menu-item group)) |
| 111 | (setq group (%radio-menu-item-get-group menu-item)) |
| 112 | (cond |
| 113 | (callback |
| 114 | (signal-connect menu-item 'activated callback :object t)) |
| 115 | (item-callback |
| 116 | (signal-connect menu-item 'toggled item-callback :object t))) |
| 117 | (incf i) |
| 118 | (menu-shell-append menu menu-item)))) |
| 119 | |
| 120 | (make-instance 'option-menu :history active :menu menu))) |
| 121 | |
| 122 | ;; (defun sf (n) |
| 123 | ;; (coerce n 'single-float)) |
| 124 | |
| 125 | (defun adjustment-new (value lower upper step-increment page-increment page-size) |
| 126 | (make-instance 'adjustment |
| 127 | :value value :lower lower :upper upper :step-increment step-increment |
| 128 | :page-increment page-increment :page-size page-size)) |