112ac1d3 |
1 | ;; Common Lisp bindings for GTK+ v2.x |
2 | ;; Copyright 2001-2005 Espen S. Johnsen <espen@users.sf.net> |
573b21cc |
3 | ;; |
112ac1d3 |
4 | ;; Permission is hereby granted, free of charge, to any person obtaining |
5 | ;; a copy of this software and associated documentation files (the |
6 | ;; "Software"), to deal in the Software without restriction, including |
7 | ;; without limitation the rights to use, copy, modify, merge, publish, |
8 | ;; distribute, sublicense, and/or sell copies of the Software, and to |
9 | ;; permit persons to whom the Software is furnished to do so, subject to |
10 | ;; the following conditions: |
573b21cc |
11 | ;; |
112ac1d3 |
12 | ;; The above copyright notice and this permission notice shall be |
13 | ;; included in all copies or substantial portions of the Software. |
573b21cc |
14 | ;; |
112ac1d3 |
15 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
16 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
17 | ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
18 | ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
19 | ;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
20 | ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
21 | ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | |
e0912c6b |
23 | ;; $Id: ginterface.lisp,v 1.18 2006-04-26 21:00:22 espen Exp $ |
573b21cc |
24 | |
25 | (in-package "GLIB") |
26 | |
27 | (use-prefix "g") |
28 | |
e0912c6b |
29 | ;;;; Superclass for interfaces |
573b21cc |
30 | |
e0912c6b |
31 | (defclass interface () |
4d83a8a6 |
32 | ()) |
573b21cc |
33 | |
e0912c6b |
34 | |
573b21cc |
35 | ;;;; Metaclass for interfaces |
36 | |
37 | (eval-when (:compile-toplevel :load-toplevel :execute) |
e0912c6b |
38 | (defclass interface-class (virtual-slots-class) |
4d83a8a6 |
39 | ())) |
573b21cc |
40 | |
e0912c6b |
41 | (defmethod direct-slot-definition-class ((class interface-class) &rest initargs) |
9c03a07c |
42 | (case (getf initargs :allocation) |
43 | (:property (find-class 'direct-property-slot-definition)) |
44 | (t (call-next-method)))) |
45 | |
e0912c6b |
46 | (defmethod effective-slot-definition-class ((class interface-class) &rest initargs) |
9c03a07c |
47 | (case (getf initargs :allocation) |
48 | (:property (find-class 'effective-property-slot-definition)) |
49 | (t (call-next-method)))) |
50 | |
e0912c6b |
51 | (defmethod compute-effective-slot-definition-initargs ((class interface-class) direct-slotds) |
b19bbc94 |
52 | (if (eq (slot-definition-allocation (first direct-slotds)) :property) |
9c03a07c |
53 | (nconc |
54 | (list :pname (signal-name-to-string |
55 | (most-specific-slot-value direct-slotds 'pname)) |
56 | :readable (most-specific-slot-value direct-slotds 'readable) |
57 | :writable (most-specific-slot-value direct-slotds 'writable) |
d42f5bdd |
58 | :construct-only (most-specific-slot-value direct-slotds 'construct)) |
9c03a07c |
59 | (call-next-method)) |
60 | (call-next-method))) |
61 | |
573b21cc |
62 | |
e0912c6b |
63 | (defmethod shared-initialize ((class interface-class) names &key name gtype) |
dfa4f314 |
64 | (declare (ignore names)) |
8a2470dd |
65 | (let* ((class-name (or name (class-name class))) |
66 | (type-number |
67 | (or |
68 | (find-type-number class-name) |
69 | (register-type class-name |
70 | (or (first gtype) (default-type-init-name class-name)))))) |
71 | (type-default-interface-ref type-number)) |
573b21cc |
72 | (call-next-method)) |
73 | |
74 | |
e0912c6b |
75 | (defmethod validate-superclass ((class interface-class) (super standard-class)) |
76 | (subtypep (class-name super) 'interface)) |
573b21cc |
77 | |
78 | |
e0912c6b |
79 | (define-type-method alien-type ((type interface)) |
75689fea |
80 | (declare (ignore type)) |
9adccb27 |
81 | (alien-type 'gobject)) |
82 | |
e0912c6b |
83 | (define-type-method size-of ((type interface) &key inlined) |
86d0704b |
84 | (assert-not-inlined type inlined) |
9adccb27 |
85 | (size-of 'gobject)) |
86 | |
e0912c6b |
87 | (define-type-method from-alien-form ((type interface) location &key (ref :copy)) |
75689fea |
88 | (declare (ignore type)) |
86d0704b |
89 | (from-alien-form 'gobject location :ref ref)) |
9adccb27 |
90 | |
e0912c6b |
91 | (define-type-method from-alien-function ((type interface) &key (ref :copy)) |
75689fea |
92 | (declare (ignore type)) |
86d0704b |
93 | (from-alien-function 'gobject :ref ref)) |
9adccb27 |
94 | |
e0912c6b |
95 | (define-type-method to-alien-form ((type interface) instance &optional copy-p) |
75689fea |
96 | (declare (ignore type)) |
86d0704b |
97 | (to-alien-form 'gobject instance copy-p)) |
9adccb27 |
98 | |
e0912c6b |
99 | (define-type-method to-alien-function ((type interface) &optional copy-p) |
75689fea |
100 | (declare (ignore type)) |
86d0704b |
101 | (to-alien-function 'gobject copy-p)) |
9adccb27 |
102 | |
e0912c6b |
103 | (define-type-method reader-function ((type interface) &key ref inlined) |
86d0704b |
104 | (assert-not-inlined type inlined) |
105 | (reader-function 'gobject :ref ref)) |
c5d37f4a |
106 | |
e0912c6b |
107 | (define-type-method writer-function ((type interface) &key temp inlined) |
86d0704b |
108 | (assert-not-inlined type inlined) |
109 | (writer-function 'gobject :temp temp)) |
c5d37f4a |
110 | |
e0912c6b |
111 | (define-type-method destroy-function ((type interface) &key temp inlined) |
86d0704b |
112 | (assert-not-inlined type inlined) |
113 | (destroy-function 'gobject :temp temp)) |
c5d37f4a |
114 | |
9adccb27 |
115 | |
573b21cc |
116 | ;;;; |
117 | |
9c03a07c |
118 | |
119 | (defbinding type-default-interface-ref (type) pointer |
120 | ((find-type-number type t) type-number)) |
121 | |
8a2470dd |
122 | (defbinding type-default-interface-unref () nil |
123 | (iface pointer)) |
9c03a07c |
124 | |
125 | (defbinding type-default-interface-peek (type) pointer |
126 | ((find-type-number type t) type-number)) |
127 | |
128 | (defbinding %object-interface-list-properties () pointer |
129 | (iface pointer) |
130 | (n-properties unsigned-int :out)) |
131 | |
132 | (defun query-object-interface-properties (type &optional inherited-p) |
133 | (let* ((type-number (find-type-number type)) |
134 | (iface (type-default-interface-ref type-number))) |
135 | (unwind-protect |
136 | (multiple-value-bind (array length) |
137 | (%object-interface-list-properties iface) |
21299acf |
138 | (unless (null-pointer-p array) |
139 | (unwind-protect |
140 | (%map-params array length type-number inherited-p) |
141 | (deallocate-memory array)))) |
8a2470dd |
142 | (type-default-interface-unref iface)))) |
9c03a07c |
143 | |
144 | |
e0912c6b |
145 | (defun expand-interface-type (type forward-p options &rest args) |
573b21cc |
146 | (declare (ignore args)) |
9c03a07c |
147 | (let ((class (type-from-number type)) |
62f12808 |
148 | (slots (getf options :slots))) |
9c03a07c |
149 | `(defclass ,class (,(supertype type)) |
62f12808 |
150 | ,(unless forward-p |
151 | (slot-definitions class (query-object-interface-properties type) slots)) |
e0912c6b |
152 | (:metaclass interface-class) |
735a29da |
153 | (:gtype ,(register-type-as type))))) |
573b21cc |
154 | |
e0912c6b |
155 | (defun interface-dependencies (type options) |
21299acf |
156 | (delete-duplicates |
157 | (cons |
158 | (supertype type) |
86d0704b |
159 | (append |
160 | (mapcar #'param-value-type (query-object-interface-properties type)) |
161 | (loop |
162 | for slot in (getf options :slots) |
163 | as type = (getf (rest slot) :type) |
164 | when (and type (symbolp type) (find-type-number type)) |
165 | collect (find-type-number type)))))) |
166 | |
573b21cc |
167 | |
e0912c6b |
168 | (register-derivable-type 'interface "GInterface" 'expand-interface-type 'interface-dependencies) |