repos
/
qt.gui
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
filehistory
normal
|
plain
|
shade
|
zebra
:qt and :qt-impl packages to prevent collision with :cl symbols and fix object with non smoke parent.
Annotate for file src/signal-slot/signal.lisp
2009-06-11 tobias
1
(in-package :cl-smoke.qt-impl)
2009-07-01 tobias
2
(declaim (optimize (debug 3)))
2010-01-10 tobias
3
08:52:49 '
4
(defclass qsignal-mixin ()
'
5
((signal-object :accessor signal-object
'
6
:initarg :signal-object
'
7
:initform (make-instance 'signal-object)))
'
8
(:documentation "in SB-PCL you can not have both
'
9
FUNCALLABLE-STANDARD-CLASS and STANDARD-CLASS,
'
10
thus QSIGNAL is split in three classes.
'
11
'
12
See:
'
13
http://www.sbcl.org/manual/Metaobject-Protocol.html#index-validate_002dsuperclass-164"))
'
14
2009-06-11 tobias
15
(defclass signal-object (qt:object)
2010-01-10 tobias
16
((argument-types :accessor argument-types
08:52:49 '
17
:initarg :argument-types
'
18
:documentation "List of the argument types"))
'
19
(:documentation "Qt Signal object.")
'
20
(:metaclass cxx:class))
'
21
'
22
#+cmu (defmethod closer-mop:validate-superclass ((class closer-mop:funcallable-standard-class)
'
23
(superclass standard-class))
'
24
t)
'
25
'
26
(defclass qsignal (closer-mop:funcallable-standard-object qsignal-mixin)
'
27
()
'
28
(:metaclass closer-mop:funcallable-standard-class)
'
29
(:documentation "A funcallable Qt signal.
'
30
The argument types can be supplied by the :METHOD-TYPES initarg.
'
31
Calling an instance emits the signal."))
'
32
2009-06-11 tobias
33
(defun qt:make-signal (&rest argument-types)
2010-01-10 tobias
34
"Returns a funcallable signal. When ARGUMENT-TYPES are not
08:52:49 '
35
specified, they are determined when the first connection is made."
'
36
(if argument-types
'
37
(make-instance 'qsignal :argument-types argument-types)
'
38
(make-instance 'qsignal)))
'
39
'
40
(defmethod id ((qsignal signal-object))
'
41
(cxx:method-count (cxx:meta-object qsignal)))
'
42
'
43
(defmethod initialize-instance :after ((object qsignal) &rest initargs
'
44
&key (argument-types nil arg-types-p)
'
45
&allow-other-keys)
'
46
(declare (ignore initargs))
'
47
(when arg-types-p
'
48
(setf (argument-types (signal-object object))
'
49
argument-types))
'
50
(closer-mop:set-funcallable-instance-function object
'
51
#'(lambda (&rest args)
2009-07-22 tobias
52
(apply #'emit (signal-object object) args)))
22:21:01 '
53
)
2010-01-10 tobias
54
08:52:49 '
55
(defun find-slot-id (receiver slot)
'
56
"Returns the ID of RECEIVER from SLOT."
2009-07-01 tobias
57
;; For efficency assume that SLOT is normalized and fallback
10:58:06 '
58
;; to normalzing when not. (Just like Qt does.)
2010-01-10 tobias
59
(let ((id (cxx:index-of-slot (cxx:meta-object receiver)
08:52:49 '
60
slot)))
'
61
(when (< id 0)
'
62
(setf id (cxx:index-of-slot (cxx:meta-object receiver)
2009-06-11 tobias
63
(cxx:data (qt:meta-object.normalized-signature slot)))))
2010-01-10 tobias
64
(when (< id 0)
08:52:49 '
65
(error "No slot ~S for class ~S.
'
66
The valid slots are: ~{~<~%~T~0,75:;~A ~>~}"
'
67
slot (class-of receiver)
'
68
(class-slots (class-of receiver))))
'
69
id))
'
70
'
71
'
72
(defun make-lisp-object (object)
2009-07-22 tobias
73
(smoke::make-cleanup-pointer (make-cxx-lisp-object object)
22:21:01 '
74
#'qt-smoke-free-lisp-object))
2010-01-10 tobias
75
08:52:49 '
76
'
77
(defun convert-arguments (arguments types)
'
78
"Returns a list of ARGUMENTS converted to TYPES."
'
79
(mapcar #'(lambda (argument type)
'
80
(if (typep type 'smoke::smoke-type)
'
81
(smoke::convert-argument argument type)
'
82
(progn (assert (typep argument type)
'
83
()
'
84
"The argument ~S is not of type ~S.")
'
85
(make-lisp-object argument))))
'
86
arguments types))
'
87
'
88
(defun emit (qsignal &rest arguments)
'
89
"Emits the signal QSIGNAL."
2009-07-22 tobias
90
;;; The first element of args would be used for the return value
22:21:01 '
91
;;; by QMetaObject::invokeMethod(), but for signal-slot connection
'
92
;;; it is ignored.
2009-07-02 tobias
93
(let ((types (argument-types qsignal)))
19:12:45 '
94
(smoke::with-stack (stack (convert-arguments arguments types)
'
95
types)
'
96
(cffi:with-foreign-object (args :pointer (1+ (length arguments)))
'
97
(loop for i from 1 to (smoke::size stack)
'
98
for type in (argument-types qsignal)
'
99
do
2010-01-10 tobias
100
(setf (mem-aref args :pointer i)
08:52:49 '
101
(if (or (not (typep type (find-class 'smoke::smoke-type)))
'
102
(= 0 (smoke::type-id type))
'
103
(= 13 (smoke::type-id type)))
'
104
(foreign-slot-value
2009-07-08 tobias
105
(mem-aref (pointer stack)
2010-01-10 tobias
106
'smoke::smoke-stack-item
08:52:49 '
107
i)
'
108
'smoke::smoke-stack-item 'smoke::voidp)
'
109
(foreign-slot-pointer
2009-07-08 tobias
110
(mem-aref (pointer stack)
2010-01-10 tobias
111
'smoke::smoke-stack-item
08:52:49 '
112
i)
'
113
'smoke::smoke-stack-item 'smoke::voidp))))
2009-07-02 tobias
114
(setf (mem-aref args :pointer 0)
19:12:45 '
115
(null-pointer))
2009-06-11 tobias
116
(qt:meta-object.activate qsignal (cxx:meta-object qsignal)
2009-07-02 tobias
117
(id qsignal)
19:12:45 '
118
args)))))
2010-01-10 tobias
119
2009-06-11 tobias
120
(defmethod qt:disconnect-all ((qsignal qsignal))
2010-01-10 tobias
121
(unless (disconnect-id (signal-object qsignal)
08:52:49 '
122
(id (signal-object qsignal))
'
123
0
'
124
0)))