1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 1999-2001 Espen S. Johnsen <esj@stud.cs.uit.no>
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.
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.
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
18 ;; $Id: gtkaction.lisp,v 1.1 2004/12/04 18:03:21 espen Exp $
25 (defmethod initialize-instance ((action action) &key accelerator)
27 (setf (object-data action 'accelerator) accelerator))
29 (defmethod action-accelerator ((action action))
30 (object-data action 'accelerator))
32 (defbinding (action-is-sensitive-p "gtk_action_is_sensitive") () boolean
35 (defbinding (action-is-visible-p "gtk_action_is_visible") () boolean
38 (defbinding action-activate () nil
44 (defmethod initialize-instance ((action-group action-group) &rest initargs
46 (declare (ignore action actions))
48 (flet ((add-action (action)
49 (action-group-add-action action-group action)))
51 as (initarg value . rest) = initargs then rest
53 (:action (add-action value))
54 (:actions (mapc #'add-action value)))
57 (defbinding action-group-get-action () action
58 (action-group action-group)
61 (defbinding action-group-list-actions () (glist action)
62 (action-group action-group))
64 (defbinding %action-group-add-action () nil
65 (action-group action-group)
68 (defbinding %action-group-add-action-with-accel () nil
69 (action-group action-group)
71 (accelerator (or null string)))
73 (defun action-group-add-action (action-group action)
74 (multiple-value-bind (accelerator accelerator-p)
75 (object-data action 'accelerator)
77 (%action-group-add-action-with-accel action-group action accelerator)
78 (%action-group-add-action action-group action))))
80 (defbinding action-group-remove-action () nil
81 (action-group action-group)
87 (defmethod initialize-instance ((action radio-action) &key group value)
89 (setf (slot-value action '%value) (system:sap-int (proxy-location action)))
90 (setf (object-data action 'radio-action-value) value)
92 (radio-action-add-to-group action group)))
94 (defmethod radio-value-action ((action radio-action))
95 (object-data action 'radio-action-value))
97 (defbinding %radio-action-get-group () pointer
98 (radio-action radio-action))
100 (defbinding %radio-action-set-group () nil
101 (radio-button radio-button)
104 (defun radio-action-add-to-group (action1 action2)
105 "Add ACTION1 to the group which ACTION2 belongs to."
106 (%radio-action-set-group action1 (%radio-action-get-group action2)))
108 (defbinding (radio-action-get-current "gtk_radio_action_get_current_value")
110 (radio-action radio-action))
112 (defun radio-action-get-current-value (action)
113 (radio-value-action (radio-action-get-current action)))
119 (defbinding toggle-action-toggled () nil
120 (toggle-action toggle-action))
126 (defmethod initialize-instance ((ui-manager ui-manager) &rest initargs
127 &key ui action-group)
128 (declare (ignore ui action-group))
130 (mapc #'(lambda (action-group)
131 (ui-manager-insert-action-group ui-manager action-group))
132 (get-all initargs :action-group))
134 (ui-manager-add-ui ui-manager ui))
135 (get-all initargs :ui)))
138 (defbinding ui-manager-insert-action-group
139 (ui-manager action-group &optional (pos :end)) nil
140 (ui-manager ui-manager)
141 (action-group action-group)
147 (defbinding ui-manager-remove-action-group () nil
148 (ui-manager ui-manager)
149 (action-group action-group))
151 (defbinding ui-manager-get-widget () widget
152 (ui-manager ui-manager)
155 (defbinding ui-manager-get-toplevels () (glist widget)
156 (ui-manager ui-manager)
157 (types ui-manager-item-type))
159 (defbinding ui-manager-get-action () action
160 (ui-manager ui-manager)
163 (defbinding %ui-manager-add-ui-from-string (ui-manager ui) int
164 (ui-manager ui-manager)
167 (gerror pointer :out))
169 (defmethod ui-manager-add-ui ((ui-manager ui-manager) (ui-spec string))
170 (let ((id (%ui-manager-add-ui-from-string ui-manager ui-spec)))
172 (error "We need to handle GError in som way"))
175 (defbinding %ui-manager-add-ui-from-file () int
176 (ui-manager ui-manager)
178 (gerror pointer :out))
180 (defmethod ui-manager-add-ui ((ui-manager ui-manager) (path pathname))
181 (let ((id (%ui-manager-add-ui-from-file ui-manager path)))
183 (error "We need to handle GError in som way"))
186 (defbinding %ui-manager-new-merge-id () unsigned-int
187 (ui-manager ui-manager))
189 (defbinding %ui-manager-add-ui () nil
190 (ui-manager ui-manager)
191 (merge-id unsigned-int)
194 (action (or null string))
195 (type ui-manager-item-type)
198 (defvar *valid-ui-elements*
199 '((:ui :menubar :toolbar :popup :accelerator)
200 (:menubar :menuitem :separator :placeholder :menu)
201 (:menu :menuitem :separator :placehoder :menu)
202 (:popup :menuitem :separator :placehoder :menu)
203 (:toolbar :toolitem :separator :placehoder)
204 (:placeholder :menuitem :toolitem :separator :placeholder :menu)
210 (defmethod ui-manager-add-ui ((ui-manager ui-manager) (ui-spec list))
211 (let ((id (%ui-manager-new-merge-id ui-manager)))
213 ((parse-ui-spec (path ui-spec element)
215 for definition in ui-spec
216 do (destructuring-bind (type &optional name &rest rest)
219 ((not (find type (cdr (assoc element *valid-ui-elements*))))
220 (ui-manager-remove-ui ui-manager id)
221 (error "~S not valid subelement in ~S" type element))
222 ((multiple-value-bind (action children)
223 (if (and rest (atom (first rest))
224 (not (keywordp (first rest))))
225 (values (first rest) (rest rest))
227 (%ui-manager-add-ui ui-manager id (or path "/") name action type nil)
229 (parse-ui-spec (concatenate 'string path "/" name)
230 children type)))))))))
231 (parse-ui-spec nil ui-spec :ui))
234 (defbinding ui-manager-remove-ui () nil
235 (ui-manager ui-manager)
236 (merge-id unsigned-int))
238 (defbinding ui-manager-get-ui () string
239 (ui-manager ui-manager))
241 (defbinding ui-manager-ensure-update () nil
242 (ui-manager ui-manager))