chiark / gitweb /
Version number increased to 0.92
[clg] / glib / ginterface.lisp
CommitLineData
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
75689fea 23;; $Id: ginterface.lisp,v 1.15 2006-02-26 15:30:01 espen Exp $
573b21cc 24
25(in-package "GLIB")
26
27(use-prefix "g")
28
29;;;;
30
4d83a8a6 31(defclass ginterface ()
32 ())
573b21cc 33
573b21cc 34;;;; Metaclass for interfaces
35
36(eval-when (:compile-toplevel :load-toplevel :execute)
9adccb27 37 (defclass ginterface-class (virtual-slots-class)
4d83a8a6 38 ()))
573b21cc 39
9c03a07c 40(defmethod direct-slot-definition-class ((class ginterface-class) &rest initargs)
41 (case (getf initargs :allocation)
42 (:property (find-class 'direct-property-slot-definition))
43 (t (call-next-method))))
44
45(defmethod effective-slot-definition-class ((class ginterface-class) &rest initargs)
46 (case (getf initargs :allocation)
47 (:property (find-class 'effective-property-slot-definition))
48 (t (call-next-method))))
49
50(defmethod compute-effective-slot-definition-initargs ((class ginterface-class) direct-slotds)
b19bbc94 51 (if (eq (slot-definition-allocation (first direct-slotds)) :property)
9c03a07c 52 (nconc
53 (list :pname (signal-name-to-string
54 (most-specific-slot-value direct-slotds 'pname))
55 :readable (most-specific-slot-value direct-slotds 'readable)
56 :writable (most-specific-slot-value direct-slotds 'writable)
d42f5bdd 57 :construct-only (most-specific-slot-value direct-slotds 'construct))
9c03a07c 58 (call-next-method))
59 (call-next-method)))
60
573b21cc 61
dfa4f314 62(defmethod shared-initialize ((class ginterface-class) names &key name gtype)
63 (declare (ignore names))
735a29da 64 (let* ((class-name (or name (class-name class)))
75689fea 65;; (type-number
66;; (or
67;; (find-type-number class-name)
68;; (register-type class-name
69;; (or (first gtype) (default-type-init-name class-name)))))
70 )
69ade5a6 71; (type-default-interface-ref type-number)
72 )
573b21cc 73 (call-next-method))
74
75
73572c12 76(defmethod validate-superclass ((class ginterface-class) (super standard-class))
573b21cc 77 (subtypep (class-name super) 'ginterface))
78
79
75689fea 80(define-type-method alien-type ((type ginterface))
81 (declare (ignore type))
9adccb27 82 (alien-type 'gobject))
83
75689fea 84(define-type-method size-of ((type ginterface))
85 (declare (ignore type))
9adccb27 86 (size-of 'gobject))
87
75689fea 88(define-type-method from-alien-form ((type ginterface) location)
89 (declare (ignore type))
90 (from-alien-form 'gobject location))
9adccb27 91
75689fea 92(define-type-method from-alien-function ((type ginterface))
93 (declare (ignore type))
9adccb27 94 (from-alien-function 'gobject))
95
75689fea 96(define-type-method to-alien-form ((type ginterface) instance)
97 (declare (ignore type))
98 (to-alien-form 'gobject instance))
9adccb27 99
75689fea 100(define-type-method to-alien-function ((type ginterface))
101 (declare (ignore type))
9adccb27 102 (to-alien-function 'gobject))
103
75689fea 104(define-type-method reader-function ((type ginterface))
105 (declare (ignore type))
c5d37f4a 106 (reader-function 'gobject))
107
75689fea 108(define-type-method writer-function ((type ginterface))
109 (declare (ignore type))
c5d37f4a 110 (writer-function 'gobject))
111
75689fea 112(define-type-method destroy-function ((type ginterface))
113 (declare (ignore type))
c5d37f4a 114 (destroy-function 'gobject))
115
9adccb27 116
573b21cc 117;;;;
118
9c03a07c 119
120(defbinding type-default-interface-ref (type) pointer
121 ((find-type-number type t) type-number))
122
123(defbinding type-default-interface-unref (type) nil
124 ((find-type-number type t) type-number))
125
126(defbinding type-default-interface-peek (type) pointer
127 ((find-type-number type t) type-number))
128
129(defbinding %object-interface-list-properties () pointer
130 (iface pointer)
131 (n-properties unsigned-int :out))
132
133(defun query-object-interface-properties (type &optional inherited-p)
134 (let* ((type-number (find-type-number type))
135 (iface (type-default-interface-ref type-number)))
136 (unwind-protect
137 (multiple-value-bind (array length)
138 (%object-interface-list-properties iface)
21299acf 139 (unless (null-pointer-p array)
140 (unwind-protect
141 (%map-params array length type-number inherited-p)
142 (deallocate-memory array))))
9c03a07c 143; (type-default-interface-unref type-number)
144 )))
145
146
62f12808 147(defun expand-ginterface-type (type forward-p options &rest args)
573b21cc 148 (declare (ignore args))
9c03a07c 149 (let ((class (type-from-number type))
62f12808 150 (slots (getf options :slots)))
9c03a07c 151 `(defclass ,class (,(supertype type))
62f12808 152 ,(unless forward-p
153 (slot-definitions class (query-object-interface-properties type) slots))
9c03a07c 154 (:metaclass ginterface-class)
735a29da 155 (:gtype ,(register-type-as type)))))
573b21cc 156
62f12808 157(defun ginterface-dependencies (type)
21299acf 158 (delete-duplicates
159 (cons
160 (supertype type)
161 (mapcar #'param-value-type (query-object-interface-properties type)))))
573b21cc 162
62f12808 163(register-derivable-type 'ginterface "GInterface" 'expand-ginterface-type 'ginterface-dependencies)