X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/36da40cbf5860b80c9a4bb433084ea7f0759da3b..960aa85cfb98deaa705ab656ab59a5aeef30e5c4:/gtk/gtkutils.lisp diff --git a/gtk/gtkutils.lisp b/gtk/gtkutils.lisp index 94706b1..1e05883 100644 --- a/gtk/gtkutils.lisp +++ b/gtk/gtkutils.lisp @@ -15,7 +15,7 @@ ;; License along with this library; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -;; $Id: gtkutils.lisp,v 1.4 2004-12-04 18:24:01 espen Exp $ +;; $Id: gtkutils.lisp,v 1.7 2005-04-19 08:12:58 espen Exp $ (in-package "GTK") @@ -52,88 +52,28 @@ (defun create-check-button (label callback &optional initstate &rest initargs) (%create-toggleable-button 'check-button label callback initstate initargs)) -(defun create-radio-button-group (specs active &optional callback &rest args) - (let ((group nil) - (i 0)) - (mapcar - #'(lambda (spec) - (destructuring-bind - (label &optional object &rest initargs) (mklist spec) - (let ((button - (apply - #'make-instance 'radio-button - :label label :visible t initargs))) - (when group (%radio-button-set-group button group)) - (setq group (%radio-button-get-group button)) - (cond - (callback - (signal-connect - button 'toggled - #'(lambda () - (when (toggle-button-active-p button) - (apply (funcallable callback) object args))))) - (object - (signal-connect - button 'toggled - #'(lambda () - (apply - (funcallable object) - (toggle-button-active-p button) args))))) - (when (= i active) - (setf (toggle-button-active-p button) t)) - (incf i) - button))) - specs))) - - (defun adjustment-new (value lower upper step-increment page-increment page-size) (make-instance 'adjustment :value value :lower lower :upper upper :step-increment step-increment :page-increment page-increment :page-size page-size)) -(defun create-action (name &optional stock-id label accelerator tooltip - callback &rest initargs) - (let ((action (apply #'make-instance 'action - :name (string name) :stock-id stock-id :label label - :tooltip tooltip :accelerator accelerator initargs))) - (when callback - (signal-connect action 'activate callback)) - action)) - -(defun create-toggle-action (name &optional stock-id label accelerator - tooltip active callback &rest initargs) - (let ((action (apply #'make-instance 'toggle-action - :name (string name) :stock-id stock-id :label label - :tooltip tooltip :active active :accelerator accelerator - initargs))) - (when callback - (signal-connect action 'activate - #'(lambda () - (funcall callback (toggle-action-active-p action)))) - (funcall callback active)) - action)) - -(defun create-radio-actions (specs &optional active callback &rest initargs) - (loop - with group = nil - for spec in specs - collect (destructuring-bind (name &optional stock-id label accelerator - tooltip (value name)) - (mklist spec) - (let ((action (apply #'make-instance 'radio-action - :name (string name) :stock-id stock-id - :label label :tooltip tooltip - :accelerator accelerator initargs))) - (when (equal active value) - (setf (toggle-action-active-p action) t) - (when callback - (funcall callback value))) - - (if (not group) - (setq group action) - (radio-action-add-to-group action group)) - (when callback - (signal-connect action 'activate - #'(lambda () - (funcall callback value)))) - action)))) +(defun make-radio-group (type specs callback &rest initargs) + (let* ((active ()) + (widgets + (loop + for spec in specs + as widget = (apply #'make-instance type (append spec initargs)) + do (when callback + (apply #'add-activate-callback widget (mklist callback))) + (when (and (not active) (getf spec :active)) + (setq active widget)) + collect widget))) + + (let ((active (or active (first widgets)))) + (loop + for widget in widgets + unless (eq widget active) + do (add-to-radio-group widget active)) + (activate-radio-widget active)) + + widgets))