/[mcclim]/mcclim/ports.lisp
ViewVC logotype

Contents of /mcclim/ports.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.34 - (hide annotations)
Thu Jul 4 06:57:43 2002 UTC (11 years, 9 months ago) by adejneka
Branch: MAIN
Changes since 1.33: +3 -1 lines
Unified text style mappings across ports.
1 mikemac 1.1 ;;; -*- Mode: Lisp; Package: CLIM-INTERNALS -*-
2    
3 mikemac 1.19 ;;; (c) copyright 1998,1999,2000,2001 by Michael McDonald (mikemac@mikemac.com)
4 cvs 1.5 ;;; (c) copyright 2000 by
5     ;;; Iban Hatchondo (hatchond@emi.u-bordeaux.fr)
6     ;;; Julien Boninfante (boninfan@emi.u-bordeaux.fr)
7     ;;; Robert Strandh (strandh@labri.u-bordeaux.fr)
8 mikemac 1.1
9     ;;; This library is free software; you can redistribute it and/or
10     ;;; modify it under the terms of the GNU Library General Public
11     ;;; License as published by the Free Software Foundation; either
12     ;;; version 2 of the License, or (at your option) any later version.
13     ;;;
14     ;;; This library is distributed in the hope that it will be useful,
15     ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16     ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17     ;;; Library General Public License for more details.
18     ;;;
19     ;;; You should have received a copy of the GNU Library General Public
20     ;;; License along with this library; if not, write to the
21     ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22     ;;; Boston, MA 02111-1307 USA.
23    
24     (in-package :CLIM-INTERNALS)
25    
26 mikemac 1.22 (defvar *default-server-path* NIL)
27    
28 mikemac 1.32 (defvar *server-path-search-order* '(:genera :ms-windows :gtk :clx :x11 :opengl))
29 mikemac 1.22
30     (defun find-default-server-path ()
31     (loop for port in *server-path-search-order*
32     if (get port :port-type)
33     do (return-from find-default-server-path (list port))
34     finally (error "No CLIM backends have been loaded!")))
35 mikemac 1.1
36     (defvar *all-ports* nil)
37    
38     (defclass port ()
39 gilbert 1.21 ()
40     (:documentation
41     "The protocol class that corresponds to a port."))
42    
43     (defclass basic-port (port)
44 mikemac 1.1 ((server-path :initform nil
45     :initarg :server-path
46     :reader port-server-path)
47     (properties :initform nil
48     :initarg :properties)
49     (grafts :initform nil
50     :accessor port-grafts)
51     (frame-managers :initform nil
52     :reader frame-managers)
53     (sheet->mirror :initform (make-hash-table :test #'eq))
54     (mirror->sheet :initform (make-hash-table :test #'eq))
55 cvs 1.10 (pixmap->mirror :initform (make-hash-table :test #'eq))
56     (mirror->pixmap :initform (make-hash-table :test #'eq))
57 mikemac 1.1 (keyboard-input-focus :initform nil
58     :initarg :keyboard-input-focus
59     :accessor port-keyboard-input-focus)
60 gilbert 1.21 (event-process
61     :initform nil
62     :initarg :event-process
63     :accessor port-event-process
64     :documentation "In a multiprocessing environment, the particular process
65     reponsible for calling PROCESS-NEXT-EVENT in a loop.")
66 adejneka 1.34
67 gilbert 1.21 (lock
68     :initform (make-recursive-lock "port lock")
69 mikemac 1.25 :accessor port-lock)
70     (event-count :initform 0)
71 adejneka 1.34 (text-style-mappings :initform (make-hash-table :test #'eq)
72     :reader port-text-style-mappings)
73 mikemac 1.25 ))
74 mikemac 1.1
75     (defun find-port (&key (server-path *default-server-path*))
76 mikemac 1.22 (if (null server-path)
77     (setq server-path (find-default-server-path)))
78     (if (atom server-path)
79     (setq server-path (list server-path)))
80     (setq server-path (funcall (get (first server-path) :server-path-parser) server-path))
81 mikemac 1.1 (loop for port in *all-ports*
82     if (equal server-path (port-server-path port))
83     do (return port)
84     finally (let ((port-type (get (first server-path) :port-type))
85     port)
86     (if (null port-type)
87     (error "Don't know how to make a port of type ~S" server-path))
88     (setq port (funcall 'make-instance port-type :server-path server-path))
89     (push port *all-ports*)
90     (return port))))
91    
92 gilbert 1.21 (defmethod initialize-instance :after ((port basic-port) &rest args)
93     (declare (ignorable args))
94     )
95    
96     (defmethod destroy-port :before ((port basic-port))
97 adejneka 1.33 (when (and *multiprocessing-p* (port-event-process port))
98 gilbert 1.21 (destroy-process (port-event-process port))
99     (setf (port-event-process port) nil)))
100    
101     (defmethod port-lookup-mirror ((port basic-port) (sheet mirrored-sheet-mixin))
102 mikemac 1.1 (gethash sheet (slot-value port 'sheet->mirror)))
103    
104 gilbert 1.21 (defmethod port-lookup-sheet ((port basic-port) mirror)
105 mikemac 1.1 (gethash mirror (slot-value port 'mirror->sheet)))
106    
107 gilbert 1.21 (defmethod port-register-mirror ((port basic-port) (sheet mirrored-sheet-mixin) mirror)
108 mikemac 1.1 (setf (gethash sheet (slot-value port 'sheet->mirror)) mirror)
109     (setf (gethash mirror (slot-value port 'mirror->sheet)) sheet)
110     nil)
111    
112 gilbert 1.21 (defmethod port-unregister-mirror ((port basic-port) (sheet mirrored-sheet-mixin) mirror)
113 mikemac 1.1 (remhash sheet (slot-value port 'sheet->mirror))
114     (remhash mirror (slot-value port 'mirror->sheet))
115     nil)
116    
117 gilbert 1.21 (defmethod realize-mirror ((port basic-port) (sheet mirrored-sheet-mixin))
118 mikemac 1.1 (error "Don't know how to realize the mirror of a generic mirrored-sheet"))
119    
120 gilbert 1.21 (defmethod destroy-mirror ((port basic-port) (sheet mirrored-sheet-mixin))
121 rouanet 1.15 (error "Don't know how to destroy the mirror of a generic mirrored-sheet"))
122 mikemac 1.1
123 gilbert 1.21 (defmethod mirror-transformation ((port basic-port) mirror)
124 rouanet 1.16 (declare (ignore mirror))
125     (error "MIRROR-TRANSFORMATION is not implemented for generic ports"))
126    
127 gilbert 1.21 (defmethod port-properties ((port basic-port) indicator)
128 mikemac 1.1 (with-slots (properties) port
129     (getf properties indicator)))
130    
131 gilbert 1.21 (defmethod (setf port-properties) (value (port basic-port) indicator)
132 mikemac 1.1 (with-slots (properties) port
133     (setf (getf properties indicator) value)))
134    
135 gilbert 1.21 (defmethod get-next-event ((port basic-port) &key wait-function timeout)
136 mikemac 1.1 (declare (ignore wait-function timeout))
137     (error "Calling GET-NEXT-EVENT on a PORT protocol class"))
138    
139 mikemac 1.25 (defmethod get-next-event :after ((port basic-port) &key wait-function timeout)
140     (declare (ignore wait-function timeout))
141     (with-slots (event-count) port
142     (incf event-count)))
143    
144 gilbert 1.21 (defmethod process-next-event ((port basic-port) &key wait-function timeout)
145 moore 1.26 (let ((event (get-next-event port
146     :wait-function wait-function
147     :timeout timeout)))
148 mikemac 1.1 (cond
149     ((null event) nil)
150     ((eq event :timeout) (values nil :timeout))
151     (t
152 moore 1.27 (distribute-event port event)
153 mikemac 1.1 t))))
154    
155 moore 1.27 ;;; Called in the application frame process.
156 moore 1.26 (defmethod port-wait-on-event-processing ((port basic-port) &key wait-function timeout
157     ((:event-count old-count) nil))
158 mikemac 1.25 (declare (ignorable wait-function))
159 moore 1.29 (with-slots (event-count) port
160     (if *multiprocessing-p*
161 moore 1.26 (let ((old-event-count (or old-count event-count))
162 mikemac 1.25 (flag nil))
163 moore 1.27 (flet ((wait-fn ()
164     (when (not (eql old-event-count event-count))
165     (setq flag t))))
166     (if timeout
167     (process-wait-with-timeout "Wait for event" timeout #'wait-fn)
168     (process-wait "Wait for event" #'wait-fn))
169     (if flag
170     event-count
171 moore 1.29 (values nil :timeout))))
172     (multiple-value-bind (result reason)
173     (process-next-event port
174     :wait-function wait-function
175     :timeout timeout)
176     (values (and result event-count) reason)))))
177 mikemac 1.25
178 gilbert 1.21 (defmethod distribute-event ((port basic-port) event)
179 mikemac 1.1 (cond
180     ((typep event 'keyboard-event)
181 moore 1.31 (when (port-keyboard-input-focus port)
182     (setf (slot-value event 'sheet) (port-keyboard-input-focus port)))
183     (dispatch-event (event-sheet event) event))
184 mikemac 1.1 ((typep event 'window-event)
185 brian 1.28 ; (dispatch-event (window-event-mirrored-sheet event) event)
186 cvs 1.4 (dispatch-event (event-sheet event) event))
187 mikemac 1.1 ((typep event 'pointer-event)
188     (dispatch-event (event-sheet event) event))
189 mikemac 1.23 ((typep event 'window-manager-delete-event)
190     ;; not sure where this type of event should get sent - mikemac
191 moore 1.27 ;; This seems fine; will be handled by the top-level-sheet-pane - moore
192     (dispatch-event (event-sheet event) event))
193 mikemac 1.1 ((typep event 'timer-event)
194     (error "Where do we send timer-events?"))
195     (t
196     (error "Unknown event ~S received in DISTRIBUTE-EVENT" event))))
197    
198 gilbert 1.21 (defmacro with-port-locked ((port) &body body)
199     (let ((fn (gensym "CONT.")))
200     `(labels ((,fn ()
201     ,@body))
202     (declare (dynamic-extent #',fn))
203 moore 1.29 (invoke-with-port-locked ,port #',fn))))
204 gilbert 1.21
205     (defmethod invoke-with-port-locked ((port basic-port) continuation)
206     (with-recursive-lock-held ((port-lock port))
207     (funcall continuation)))
208    
209 mikemac 1.1 (defun map-over-ports (function)
210     (mapc function *all-ports*))
211    
212 gilbert 1.21 (defmethod restart-port ((port basic-port))
213 mikemac 1.1 (reset-watcher port :restart)
214     nil)
215    
216 gilbert 1.21 (defmethod destroy-port ((port basic-port))
217 mikemac 1.1 (reset-watcher port :destroy)
218     (setf *all-ports* (remove port *all-ports*)))
219    
220 gilbert 1.21 (defmethod add-watcher ((port basic-port) watcher)
221 mikemac 1.1 (declare (ignore watcher))
222     nil)
223    
224 gilbert 1.21 (defmethod delete-watcher ((port basic-port) watcher)
225 mikemac 1.1 (declare (ignore watcher))
226     nil)
227    
228 gilbert 1.21 (defmethod reset-watcher ((port basic-port) how)
229 mikemac 1.1 (declare (ignore how))
230     nil)
231    
232 gilbert 1.21 (defmethod make-graft ((port basic-port) &key (orientation :default) (units :device))
233 mikemac 1.1 (let ((graft (make-instance 'graft
234     :port port :mirror nil
235     :orientation orientation :units units)))
236     (push graft (port-grafts port))
237     graft))
238    
239 gilbert 1.21 #||
240     (defmethod make-medium ((port basic-port) sheet)
241 rouanet 1.16 (make-instance 'basic-medium :port port :graft (graft sheet) :sheet sheet))
242 gilbert 1.21 ||#
243 mikemac 1.1
244 cvs 1.10 ;;; Pixmap
245    
246 gilbert 1.21 (defmethod port-lookup-mirror ((port basic-port) (pixmap pixmap))
247 cvs 1.10 (gethash pixmap (slot-value port 'pixmap->mirror)))
248    
249 gilbert 1.21 (defmethod port-lookup-pixmap ((port basic-port) mirror)
250 cvs 1.10 (gethash mirror (slot-value port 'mirror->pixmap)))
251    
252 gilbert 1.21 (defmethod port-register-mirror ((port basic-port) (pixmap pixmap) mirror)
253 cvs 1.10 (setf (gethash pixmap (slot-value port 'pixmap->mirror)) mirror)
254     (setf (gethash mirror (slot-value port 'mirror->pixmap)) pixmap)
255     nil)
256    
257 gilbert 1.21 (defmethod port-unregister-mirror ((port basic-port) (pixmap pixmap) mirror)
258 cvs 1.10 (remhash pixmap (slot-value port 'pixmap->mirror))
259     (remhash mirror (slot-value port 'mirror->pixmap))
260     nil)
261    
262 gilbert 1.21 (defmethod realize-mirror ((port basic-port) (pixmap mirrored-pixmap))
263 cvs 1.10 (declare (ignorable port pixmap))
264     (error "Don't know how to realize the mirror on a generic port"))
265    
266 gilbert 1.21 (defmethod destroy-mirror ((port basic-port) (pixmap mirrored-pixmap))
267 cvs 1.10 (declare (ignorable port pixmap))
268 rouanet 1.15 (error "Don't know how to destroy the mirror on a generic port"))
269 cvs 1.10
270 gilbert 1.21 (defmethod port-allocate-pixmap ((port basic-port) sheet width height)
271 mikemac 1.1 (declare (ignore sheet width height))
272 cvs 1.10 (error "ALLOCATE-PIXMAP is not implemented for generic PORTs"))
273 mikemac 1.1
274 gilbert 1.21 (defmethod port-deallocate-pixmap ((port basic-port) pixmap)
275 mikemac 1.1 (declare (ignore pixmap))
276 cvs 1.10 (error "DEALLOCATE-PIXMAP is not implemented for generic PORTs"))

  ViewVC Help
Powered by ViewVC 1.1.5