| 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.1 2000/10/05 17:21:46 espen Exp $ |
| 19 | |
| 20 | |
| 21 | (in-package "GTK") |
| 22 | |
| 23 | (defun create-button (specs &optional callback &rest args) |
| 24 | (destructuring-bind (label &rest initargs) (mklist specs) |
| 25 | (let ((button |
| 26 | (apply #'make-instance 'button :label label :visible t initargs))) |
| 27 | (if callback |
| 28 | (signal-connect |
| 29 | button 'clicked |
| 30 | #'(lambda () |
| 31 | (apply (funcallable callback) args))) |
| 32 | (setf (widget-sensitive-p button) nil)) |
| 33 | button))) |
| 34 | |
| 35 | (defun %create-toggleable-button (class label callback state args) |
| 36 | (let ((button (make-instance class :label label :active state :visible t))) |
| 37 | (signal-connect |
| 38 | button 'toggled |
| 39 | #'(lambda () |
| 40 | (apply (funcallable callback) (toggle-button-active-p button) args))) |
| 41 | (apply (funcallable callback) state args) |
| 42 | button)) |
| 43 | |
| 44 | (defun create-toggle-button (label callback &optional state &rest args) |
| 45 | (%create-toggleable-button 'toggle-button label callback state args)) |
| 46 | |
| 47 | (defun create-check-button (label callback &optional state &rest args) |
| 48 | (%create-toggleable-button 'check-button label callback state args)) |
| 49 | |
| 50 | (defun create-radio-button-group (specs active &optional callback &rest args) |
| 51 | (let ((group nil) |
| 52 | (i 0)) |
| 53 | (mapcar |
| 54 | #'(lambda (spec) |
| 55 | (destructuring-bind |
| 56 | (label &optional object &rest initargs) (mklist spec) |
| 57 | (let ((button |
| 58 | (apply |
| 59 | #'make-instance 'radio-button |
| 60 | :label label :visible t initargs))) |
| 61 | (when group (%radio-button-set-group button group)) |
| 62 | (setq group (%radio-button-get-group button)) |
| 63 | (cond |
| 64 | (callback |
| 65 | (signal-connect |
| 66 | button 'toggled |
| 67 | #'(lambda () |
| 68 | (when (toggle-button-active-p button) |
| 69 | (apply (funcallable callback) object args))))) |
| 70 | (object |
| 71 | (signal-connect |
| 72 | button 'toggled |
| 73 | #'(lambda () |
| 74 | (apply |
| 75 | (funcallable object) |
| 76 | (toggle-button-active-p button) args))))) |
| 77 | (when (= i active) |
| 78 | (setf (toggle-button-active-p button) t)) |
| 79 | (incf i) |
| 80 | button))) |
| 81 | specs))) |
| 82 | |
| 83 | (defun create-option-menu (specs active &optional callback &rest args) |
| 84 | (let ((menu (make-instance 'menu)) |
| 85 | (group nil) |
| 86 | (i 0)) |
| 87 | (dolist (spec specs) |
| 88 | (destructuring-bind (label &optional object &rest initargs) (mklist spec) |
| 89 | (let ((menu-item |
| 90 | (apply |
| 91 | #'make-instance 'radio-menu-item |
| 92 | :label label :active (= i active) initargs))) |
| 93 | (when group (%radio-menu-item-set-group menu-item group)) |
| 94 | (setq group (%radio-menu-item-get-group menu-item)) |
| 95 | (cond |
| 96 | (callback |
| 97 | (signal-connect |
| 98 | menu-item 'activated |
| 99 | #'(lambda () |
| 100 | (apply (funcallable callback) object args)))) |
| 101 | (object |
| 102 | (signal-connect |
| 103 | menu-item 'toggled |
| 104 | #'(lambda () |
| 105 | (apply |
| 106 | (funcallable object) |
| 107 | (check-menu-item-active-p menu-item) args))))) |
| 108 | (incf i) |
| 109 | (menu-shell-append menu menu-item)))) |
| 110 | |
| 111 | (make-instance 'option-menu :history active :menu menu))) |
| 112 | |