52deb7e5 |
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 | |
36da40cb |
18 | ;; $Id: gtkutils.lisp,v 1.4 2004-12-04 18:24:01 espen Exp $ |
52deb7e5 |
19 | |
20 | |
21 | (in-package "GTK") |
22 | |
1a1949c7 |
23 | (defun create-button (specs &optional callback &key object) |
52deb7e5 |
24 | (destructuring-bind (label &rest initargs) (mklist specs) |
25 | (let ((button |
26 | (apply #'make-instance 'button :label label :visible t initargs))) |
27 | (if callback |
1a1949c7 |
28 | (signal-connect button 'clicked callback :object object) |
52deb7e5 |
29 | (setf (widget-sensitive-p button) nil)) |
30 | button))) |
31 | |
1047e159 |
32 | |
1a1949c7 |
33 | (defun create-label (label &rest args) |
34 | (apply #'make-instance 'label :label label args)) |
1047e159 |
35 | |
36 | |
1a1949c7 |
37 | ;; TODO: same syntax as create-button |
1047e159 |
38 | (defun %create-toggleable-button (class label callback initstate initargs) |
39 | (let ((button |
40 | (apply #'make-instance class :label label :active initstate :visible t |
41 | initargs))) |
52deb7e5 |
42 | (signal-connect |
43 | button 'toggled |
44 | #'(lambda () |
1047e159 |
45 | (funcall (funcallable callback) (toggle-button-active-p button)))) |
46 | (funcall (funcallable callback) initstate) |
52deb7e5 |
47 | button)) |
48 | |
1047e159 |
49 | (defun create-toggle-button (label callback &optional initstate &rest initargs) |
50 | (%create-toggleable-button 'toggle-button label callback initstate initargs)) |
52deb7e5 |
51 | |
1047e159 |
52 | (defun create-check-button (label callback &optional initstate &rest initargs) |
53 | (%create-toggleable-button 'check-button label callback initstate initargs)) |
52deb7e5 |
54 | |
55 | (defun create-radio-button-group (specs active &optional callback &rest args) |
56 | (let ((group nil) |
57 | (i 0)) |
58 | (mapcar |
59 | #'(lambda (spec) |
60 | (destructuring-bind |
61 | (label &optional object &rest initargs) (mklist spec) |
62 | (let ((button |
63 | (apply |
64 | #'make-instance 'radio-button |
65 | :label label :visible t initargs))) |
66 | (when group (%radio-button-set-group button group)) |
67 | (setq group (%radio-button-get-group button)) |
68 | (cond |
69 | (callback |
70 | (signal-connect |
71 | button 'toggled |
72 | #'(lambda () |
73 | (when (toggle-button-active-p button) |
74 | (apply (funcallable callback) object args))))) |
75 | (object |
76 | (signal-connect |
77 | button 'toggled |
78 | #'(lambda () |
79 | (apply |
80 | (funcallable object) |
81 | (toggle-button-active-p button) args))))) |
82 | (when (= i active) |
83 | (setf (toggle-button-active-p button) t)) |
84 | (incf i) |
85 | button))) |
86 | specs))) |
87 | |
1047e159 |
88 | |
89 | (defun adjustment-new (value lower upper step-increment page-increment page-size) |
90 | (make-instance 'adjustment |
91 | :value value :lower lower :upper upper :step-increment step-increment |
92 | :page-increment page-increment :page-size page-size)) |
36da40cb |
93 | |
94 | (defun create-action (name &optional stock-id label accelerator tooltip |
95 | callback &rest initargs) |
96 | (let ((action (apply #'make-instance 'action |
97 | :name (string name) :stock-id stock-id :label label |
98 | :tooltip tooltip :accelerator accelerator initargs))) |
99 | (when callback |
100 | (signal-connect action 'activate callback)) |
101 | action)) |
102 | |
103 | (defun create-toggle-action (name &optional stock-id label accelerator |
104 | tooltip active callback &rest initargs) |
105 | (let ((action (apply #'make-instance 'toggle-action |
106 | :name (string name) :stock-id stock-id :label label |
107 | :tooltip tooltip :active active :accelerator accelerator |
108 | initargs))) |
109 | (when callback |
110 | (signal-connect action 'activate |
111 | #'(lambda () |
112 | (funcall callback (toggle-action-active-p action)))) |
113 | (funcall callback active)) |
114 | action)) |
115 | |
116 | (defun create-radio-actions (specs &optional active callback &rest initargs) |
117 | (loop |
118 | with group = nil |
119 | for spec in specs |
120 | collect (destructuring-bind (name &optional stock-id label accelerator |
121 | tooltip (value name)) |
122 | (mklist spec) |
123 | (let ((action (apply #'make-instance 'radio-action |
124 | :name (string name) :stock-id stock-id |
125 | :label label :tooltip tooltip |
126 | :accelerator accelerator initargs))) |
127 | (when (equal active value) |
128 | (setf (toggle-action-active-p action) t) |
129 | (when callback |
130 | (funcall callback value))) |
131 | |
132 | (if (not group) |
133 | (setq group action) |
134 | (radio-action-add-to-group action group)) |
135 | (when callback |
136 | (signal-connect action 'activate |
137 | #'(lambda () |
138 | (funcall callback value)))) |
139 | action)))) |