repos
/
qt.gui
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
filehistory
normal
|
plain
|
shade
|
zebra
*SMOKE-MODULE* must be passed instead of *QT-SMOKE*.
Annotate for file src/object.lisp
2010-01-10 tobias
1
(in-package :cl-smoke.qt-impl)
08:52:49 '
2
2009-07-02 tobias
3
(let ((object (make-instance 'qt:object)))
19:12:45 '
4
(defmethod cxx:static-meta-object ((class (eql (find-class 'qt:object))))
'
5
"No OBJECT.STATIC-META-OBJECT (r558420)."
'
6
(cxx:meta-object object))
'
7
(defmethod cxx:static-meta-object ((class cxx:class))
'
8
(cxx:static-meta-object (smoke::find-smoke-class class))))
2010-01-10 tobias
9
08:52:49 '
10
(defmethod documentation :around ((class smoke::smoke-standard-class)
'
11
(doc-type (eql 't)))
'
12
(if (and (subtypep class (find-class 'qt:object))
'
13
(not (subtypep class (find-class 'cxx:class))))
'
14
(format nil "~@[~A~%~]Properties:~%~T~{~<~%~T~0,75:; ~(~A~)~>~}
'
15
'
16
Signals:
'
17
~{~T~A~%~}
'
18
Slots:
'
19
~{~T~A~%~}"
'
20
(call-next-method) (sort (qt:class-direct-properties class) #'string<=)
'
21
(sort (class-signals class) #'string<=)
'
22
(sort (class-slots class) #'string<=))
'
23
(call-next-method)))
'
24
'
25
(defmethod print-object ((object qt:object) stream)
'
26
(if (or (not (slot-boundp object 'pointer))
'
27
(null-pointer-p (pointer object)))
'
28
(call-next-method)
2009-08-02 tobias
29
(print-unreadable-object (object stream :type t :identity t)
11:29:13 '
30
(princ (cxx:object-name object) stream))))
2010-01-10 tobias
31
08:52:49 '
32
(defun meta-object-methods (meta-object &optional (direct-only nil))
'
33
(loop for index from (if direct-only (cxx:method-offset meta-object) 0)
'
34
below (cxx:method-count meta-object)
'
35
collect (cxx:method meta-object index)))
'
36
'
37
'
38
(defun meta-object-signals (meta-object &key all)
'
39
(mapcar #'cxx:signature
'
40
(remove-if-not #'(lambda (m) (enum= qt:meta-method.+signal+
'
41
(cxx:method-type m)))
'
42
(meta-object-methods meta-object (not all)))))
'
43
'
44
(defun class-signals (class &key all)
'
45
(meta-object-signals (cxx:static-meta-object class) :all all))
'
46
'
47
(defun meta-object-slots (meta-object &key all)
'
48
(mapcar #'cxx:signature
'
49
(remove-if-not #'(lambda (m) (enum= qt:meta-method.+slot+
'
50
(cxx:method-type m)))
'
51
(meta-object-methods meta-object (not all)))))
'
52
'
53
'
54
(defun class-slots (class &key all)
'
55
(meta-object-slots (cxx:static-meta-object class) :all all))
'
56
'
57
(defun parent-p (object)
2009-06-21 tobias
58
(not (null-pointer-p (smoke::pointer-call (smoke::make-smoke-method-from-name (find-class 'qt:object)
2009-08-02 tobias
59
"parent")
11:15:21 '
60
(smoke::pointer object)))))
2010-01-10 tobias
61
2009-08-02 tobias
62
(defun find-smoke-parent (object)
11:15:21 '
63
"Returns the first parent of OBJECT or OBJECT that is a Smoke class.
2009-06-21 tobias
64
(the destructed callback is called when the object is freed.)"
2009-08-02 tobias
65
;; FIXME allow usage of non smoke objects by connecting to the
11:15:21 '
66
;; destroyed() signal.
2009-06-21 tobias
67
(declare (optimize (speed 3)))
2010-01-10 tobias
68
(let ((parent (cxx:parent object)))
2009-08-02 tobias
69
(if (not (null-pointer-p (smoke::pointer parent)))
11:15:21 '
70
(if (smoke::has-pointer-p (smoke::pointer parent))
'
71
parent
'
72
(find-smoke-parent parent))
2009-07-08 tobias
73
(error "No smoke parent found."))))
2010-01-10 tobias
74
08:52:49 '
75
(defmethod initialize-instance :after ((object qt:object)
'
76
&key (pointer nil pointer-p) &allow-other-keys)
'
77
"Registers the object to the parent when a parent was set in the constructor
'
78
and the objects metaclass is SMOKE-WRAPPER-CLASS."
2009-06-21 tobias
79
(declare (optimize (speed 3)))
2010-01-10 tobias
80
(when (and (not pointer-p)
08:52:49 '
81
(null-pointer-p (smoke::pointer object)))
'
82
(error "Object ~A has not been constructed" object))
'
83
(when (and (null pointer)
'
84
(not (null-pointer-p (smoke::pointer object)))
'
85
(parent-p object))
'
86
(smoke::transfer-ownership-to object
2009-08-02 tobias
87
(find-smoke-parent object))))
2010-01-10 tobias
88
08:52:49 '
89
(define-condition wrapper-gc (storage-condition)
2009-08-02 tobias
90
((class-name :initarg :class-name
11:15:21 '
91
:documentation "The class name of the gc'ed object.")
2010-01-10 tobias
92
(pointer :initarg :pointer))
08:52:49 '
93
(:report (lambda (condition stream)
2009-08-02 tobias
94
(format stream "The object ~A ~A of type cxx:class
11:15:21 '
95
has a parent but got garbage collected."
'
96
(slot-value condition 'class-name)
'
97
(slot-value condition 'pointer)))))
2010-01-10 tobias
98
2009-08-02 tobias
99
(smoke:eval-startup (:compile-toplevel :execute)
2009-07-22 tobias
100
(defparameter *get-parent*
2009-06-21 tobias
101
(smoke::make-smoke-method-from-name (find-class 'qt:object) "parent"))
2009-07-22 tobias
102
;; FIXME this leaks memory when QCoreApplication::exec is never called,
22:21:01 '
103
;; beause then, deleteLater has no effect.
'
104
(defparameter *delete-later*
2009-06-21 tobias
105
(smoke::make-smoke-method-from-name (find-class 'qt:object) "deleteLater")))
2010-01-10 tobias
106
08:52:49 '
107
(defmethod smoke::make-finalize ((object qt:object))
2009-06-21 tobias
108
"Delete the qt:object OBJECT,
2010-01-10 tobias
109
by calling cxx:delete-later iff it has no parent."
2009-06-21 tobias
110
(let ((pointer (pointer object))
09:29:25 '
111
(class (class-of object))
'
112
(next (call-next-method)))
'
113
(declare (function next))
'
114
(if (typep (class-of object) 'cxx:class)
'
115
#'(lambda ()
'
116
(declare (optimize (speed 3)))
'
117
(handler-case
'
118
(if (null-pointer-p (smoke::pointer-call *get-parent* pointer))
'
119
(smoke::pointer-call *delete-later* pointer)
'
120
(error (make-condition 'wrapper-gc
'
121
:class-name (name class)
'
122
:pointer pointer)))
'
123
(error (condition)
'
124
(smoke::report-finalize-error condition "qt:object wrap"
'
125
(name class) pointer))))
'
126
#'(lambda ()
'
127
(declare (optimize (speed 3)))
'
128
(handler-case
'
129
(if (null-pointer-p (smoke::pointer-call *get-parent* pointer))
2010-01-10 tobias
130
(funcall next)
08:52:49 '
131
(cerror "Ignore" "Finalizer for object with a parent called."))
2009-06-21 tobias
132
(error (condition)
09:29:25 '
133
(smoke::report-finalize-error condition "qt:object"
'
134
(name class) pointer)))))))
2010-01-10 tobias
135
08:52:49 '
136
'
137
;;;
2009-07-22 tobias
138
;;; The event-notify callback get called by QCoreApplication,
22:21:01 '
139
;;; on notification of an event.
2010-01-10 tobias
140
;;;
2009-07-22 tobias
141
;;; The DATA argument is an array of size three, containing the pointers:
2010-01-10 tobias
142
;;; void* receiver
08:52:49 '
143
;;; void* event
'
144
;;; void* result
'
145
;;; in that order.
'
146
;;;
'
147
;;; Returning true marks the event as handled; false on the other hand
'
148
;;; leaves the event processing unchanged.
'
149
;;;
2009-07-22 tobias
150
;;; See: QCoreApplication::notifyInternal(QObject *receiver, QEvent *event)
2010-01-10 tobias
151
08:52:49 '
152
(cffi:defcallback event-notify smoke:cxx-bool
'
153
((data :pointer))
'
154
(declare (optimize (speed 3)))
'
155
(let ((receiver (smoke::get-object (cffi:mem-aref data :pointer 0)))
2009-08-02 tobias
156
(event (make-instance 'qt:event
11:29:02 '
157
:pointer (cffi:mem-aref data :pointer 1))))
2010-01-10 tobias
158
(enum-case (cxx:type event)
08:52:49 '
159
(qt:event.+child-added+
2009-08-02 tobias
160
(let ((child-event (make-instance 'qt:child-event
11:29:02 '
161
:pointer
'
162
(smoke::upcast event (find-class 'qt:child-event)))))
'
163
(tg:cancel-finalization (cxx:child child-event))
'
164
(when (smoke::has-pointer-p (smoke::pointer (cxx:child child-event)))
'
165
(unless receiver
2009-08-02 tobias
166
(setf receiver (find-smoke-parent (cxx:child child-event))))
2009-08-02 tobias
167
(smoke::transfer-ownership-to (cxx:child child-event) receiver))))
2010-01-10 tobias
168
(qt:event.+child-removed+
2009-08-02 tobias
169
(let* ((child-event (make-instance 'qt:child-event
11:29:02 '
170
:pointer (smoke::upcast event
'
171
(find-class 'qt:child-event)))))
2009-07-01 tobias
172
;; We receive child removed events for any QObject, wherter
10:58:06 '
173
;; it was construted by Smoke or not. Only take ownership of objects
2009-07-22 tobias
174
;; that have been constructed by Smoke.
2009-08-02 tobias
175
(when (smoke::has-pointer-p (smoke::pointer (cxx:child child-event)))
11:29:02 '
176
(assert receiver)
'
177
(smoke::take-ownership (cxx:child child-event) receiver))))))
2010-01-10 tobias
178
nil)
08:52:49 '
179
'
180
(eval-when (:compile-toplevel :load-toplevel :execute)
'
181
(cffi:defcfun qt-smoke-register-event-notify :boolean
'
182
(event-notify :pointer)))
'
183
'
184
(defun register-event-notify ()
'
185
(let ((ret (qt-smoke-register-event-notify (cffi:callback event-notify))))
'
186
(unless ret
2009-06-21 tobias
187
(error "The Qt event-notify callback table is full."))))
2010-01-10 tobias
188
2009-08-02 tobias
189
(smoke:eval-startup ()
2010-01-10 tobias
190
(register-event-notify))