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

Contents of /mcclim/frames.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.81 - (show annotations)
Mon Nov 10 05:46:32 2003 UTC (10 years, 5 months ago) by moore
Branch: MAIN
Changes since 1.80: +13 -8 lines
Set up an input context for commands when there's no interactor pane.

Be more liberal in accepting clause arguments for tracking-pointer.

Translate from CLIM line-cap names to XLIB names.
1 ;;; -*- Mode: Lisp; Package: CLIM-INTERNALS -*-
2
3 ;;; (c) copyright 1998,1999,2000 by Michael McDonald (mikemac@mikemac.com)
4 ;;; (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
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 ;; *application-frame* is in decls.lisp
27 (defvar *default-frame-manager* nil)
28
29 ;;; Frame-Manager class
30
31 (define-protocol-class frame-manager ()
32 ((port :initarg :port
33 :reader frame-manager-port)
34 (frames :initform nil
35 :reader frame-manager-frames)))
36
37 (defun find-frame-manager (&rest options &key port &allow-other-keys)
38 (declare (special *frame-manager*))
39 (if (boundp '*frame-manager*)
40 *frame-manager*
41 (if (and *default-frame-manager*
42 (frame-manager-p *default-frame-manager*))
43 *default-frame-manager*
44 (first (frame-managers (or port (apply #'find-port options)))))))
45
46 (defmacro with-frame-manager ((frame-manager) &body body)
47 `(let ((*frame-manager* ,frame-manager))
48 (declare (special *frame-manager*))
49 (locally ,@body)))
50
51 ;;; Application-Frame class
52 ;;; XXX All these slots should move to a mixin or to standard-application-frame.
53 ;;; -- moore
54
55 (define-protocol-class application-frame ()
56 ((port :initform nil
57 :initarg :port
58 :accessor port)
59 (graft :initform nil
60 :initarg :graft
61 :accessor graft)
62 (name :initarg :name
63 :reader frame-name)
64 (pretty-name :initarg :pretty-name
65 :accessor frame-pretty-name)
66 (command-table :initarg :command-table
67 :initform nil
68 :accessor frame-command-table)
69 (disabled-commands :initarg :disabled-commands
70 :initform nil
71 :accessor frame-disabled-commands)
72 (pane :reader frame-pane)
73 (panes :initform nil
74 :reader frame-panes)
75 (layouts :initform nil
76 :initarg :layouts
77 :reader frame-layouts)
78 (current-layout :initform nil
79 :initarg :current-layout
80 :reader frame-current-layout)
81 (top-level-sheet :initform nil
82 :reader frame-top-level-sheet)
83 (menu-bar :initarg :menu-bar
84 :initform nil)
85 (calling-frame :initarg :calling-frame
86 :initform nil)
87 (state :initarg :state
88 :initform :disowned
89 :reader frame-state)
90 (manager :initform nil
91 :reader frame-manager
92 :accessor %frame-manager)
93 (keyboard-input-focus :initform nil
94 :accessor keyboard-input-focus)
95 (properties :initarg :properties
96 :initform nil)
97 (top-level :initform '(default-frame-top-level)
98 :initarg :top-level
99 :reader frame-top-level)
100 (hilited-presentation :initform nil
101 :initarg :hilited-presentation
102 :accessor frame-hilited-presentation)
103 (user-supplied-geometry :initform nil
104 :initarg :user-supplied-geometry)
105 (process :reader frame-process :initform (current-process))))
106
107 ;;; Generic operations
108 ; (defgeneric frame-name (frame))
109 ; (defgeneric frame-pretty-name (frame))
110 ; (defgeneric (setf frame-pretty-name) (name frame))
111 ; (defgeneric frame-command-table (frame))
112 ; (defgeneric (setf frame-command-table) (command-table frame))
113 (defgeneric frame-standard-output (frame)
114 (:documentation
115 "Returns the stream that will be used for *standard-output* for the FRAME."))
116 (defgeneric frame-standard-input (frame)
117 (:documentation
118 "Returns the stream that will be used for *standard-input* for the FRAME."))
119 (defgeneric frame-query-io (frame)
120 (:documentation
121 "Returns the stream that will be used for *query-io* for the FRAME."))
122 (defgeneric frame-error-output (frame)
123 (:documentation
124 "Returns the stream that will be used for *error-output* for the FRAME."))
125 (defgeneric frame-pointer-documentation-output (frame)
126 (:documentation
127 "Returns the stream that will be used for *pointer-documentation-output*
128 for the FRAME."))
129 (defgeneric frame-calling-frame (frame)
130 (:documentation
131 "Returns the application frame that invoked the FRAME."))
132 (defgeneric frame-parent (frame)
133 (:documentation
134 "Returns the object that acts as the parent for the FRAME."))
135 ;(defgeneric frame-pane (frame) ; XXX Is it in Spec?
136 ; (:documentation
137 ; "Returns the pane that is the top-level pane in the current layout
138 ;of the FRAME's named panes."))
139 (defgeneric frame-top-level-sheet (frame)
140 (:documentation
141 "Returns the shhet that is the top-level sheet for the FRAME. This
142 is the sheet that has as its descendants all of the panes of the FRAME."))
143 (defgeneric frame-current-panes (frame)
144 (:documentation
145 "Returns a list of those named panes in the FRAME's current layout.
146 If there are no named panes, only the single, top level pane is returned."))
147 (defgeneric get-frame-pane (frame pane-name)
148 (:documentation
149 "Returns the named CLIM stream pane in the FRAME whose name is PANE-NAME."))
150 (defgeneric find-pane-named (frame pane-name)
151 (:documentation
152 "Returns the pane in the FRAME whose name is PANE-NAME."))
153 ;(defgeneric frame-current-layout (frame))
154 ;(defgeneric frame-all-layouts (frame)) ; XXX Is it in Spec?
155 (defgeneric layout-frame (frame &optional width height))
156 (defgeneric frame-exit-frame (condition)
157 (:documentation
158 "Returns the frame that is being exited from associated with the
159 FRAME-EXIT condition."))
160 (defgeneric frame-exit (frame) ; XXX Is it in Spec?
161 (:documentation
162 "Exits from the FRAME."))
163 (defgeneric pane-needs-redisplay (pane))
164 (defgeneric (setf pane-needs-redisplay) (value pane))
165 (defgeneric redisplay-frame-pane (frame pane &key force-p))
166 (defgeneric redisplay-frame-panes (frame &key force-p))
167 (defgeneric frame-replay (frame stream &optional region))
168 (defgeneric notify-user (frame message &key associated-window title
169 documentation exit-boxes name style text-style))
170 ;(defgeneric frame-properties (frame property))
171 ;(defgeneric (setf frame-properties) (value frame property))
172
173 ; extension
174 (defgeneric frame-schedule-timer-event (frame sheet delay token))
175
176 (defgeneric note-input-focus-changed (pane state)
177 (:documentation "Called when a pane receives or loses the keyboard
178 input focus. This is a McCLIM extension."))
179
180 (defclass standard-application-frame (application-frame)
181 ((event-queue :initarg :frame-event-queue
182 :initarg :input-buffer
183 :initform nil
184 :accessor frame-event-queue
185 :documentation "The event queue that, by default, will be
186 shared by all panes in the stream")
187 (documentation-state :accessor frame-documentation-state
188 :initform nil
189 :documentation "Used to keep of track of what
190 needs to be rendered in the pointer documentation frame.")))
191
192 ;;; Support the :input-buffer initarg for compatibility with "real CLIM"
193
194 (defmethod initialize-instance :after ((obj standard-application-frame)
195 &key &allow-other-keys)
196 (unless (frame-event-queue obj)
197 (setf (frame-event-queue obj)
198 (make-instance 'port-event-queue))))
199
200 (defmethod (setf frame-manager) (fm (frame application-frame))
201 (let ((old-manager (frame-manager frame)))
202 (setf (%frame-manager frame) nil)
203 (when old-manager
204 (disown-frame old-manager frame)
205 (setf (slot-value frame 'panes) nil)
206 (setf (slot-value frame 'layouts) nil))
207 (setf (%frame-manager frame) fm)))
208
209 (defmethod (setf frame-current-layout) (name (frame application-frame))
210 (declare (ignore name))
211 (generate-panes (frame-manager frame) frame))
212
213 (defmethod generate-panes :before (fm (frame application-frame))
214 (declare (ignore fm))
215 (when (and (slot-boundp frame 'pane)
216 (frame-pane frame))
217 (sheet-disown-child (frame-top-level-sheet frame) (frame-pane frame))))
218
219 (defmethod generate-panes :after (fm (frame application-frame))
220 (declare (ignore fm))
221 (sheet-adopt-child (frame-top-level-sheet frame) (frame-pane frame))
222 (sheet-adopt-child (graft frame) (frame-top-level-sheet frame))
223 (let* ((space (compose-space (frame-top-level-sheet frame)))
224 (bbox (or (slot-value frame 'user-supplied-geometry)
225 (make-bounding-rectangle 0 0
226 (space-requirement-width space)
227 (space-requirement-height space)))))
228 ;; automatically generates a window-configuation-event
229 ;; which then calls allocate-space
230 ;;
231 ;; Not any longer, we turn of CONFIGURE-NOTIFY events until the
232 ;; window is mapped and do the space allocation now, so that all
233 ;; sheets will have their correct geometry at once. --GB
234 (setf (sheet-region (frame-top-level-sheet frame))
235 bbox)
236 (allocate-space (frame-top-level-sheet frame)
237 (bounding-rectangle-width bbox)
238 (bounding-rectangle-height bbox))
239 ))
240
241 (defmethod layout-frame ((frame application-frame) &optional width height)
242 (let ((pane (frame-pane frame)))
243 (if (and width (not height))
244 (error "LAYOUT-FRAME must be called with both WIDTH and HEIGHT or neither"))
245 (if (and (null width) (null height))
246 (let ((space (compose-space pane)))
247 (setq width (space-requirement-width space))
248 (setq height (space-requirement-height space))))
249 (let ((tpl-sheet (frame-top-level-sheet frame)))
250 (unless (and (= width (bounding-rectangle-width tpl-sheet))
251 (= height (bounding-rectangle-height tpl-sheet)))
252 (resize-sheet (frame-top-level-sheet frame) width height)))
253 (allocate-space pane width height)))
254
255 (defun find-pane-if (predicate panes)
256 "Returns a pane satisfying PREDICATE in the forest growing from PANES"
257 (loop for pane in panes
258 do (map-over-sheets #'(lambda (p)
259 (when (funcall predicate p)
260 (return-from find-pane-if p)))
261 pane)
262 finally (return nil)))
263
264 (defun find-pane-of-type (panes type)
265 (find-pane-if #'(lambda (pane) (typep pane type)) panes))
266
267 (defmethod frame-current-panes ((frame application-frame))
268 (find-pane-if #'(lambda (pane) (pane-name pane))
269 (frame-current-layout frame)))
270
271 (defmethod get-frame-pane ((frame application-frame) pane-name)
272 (find-pane-if #'(lambda (pane)
273 (and (typep pane 'clim-stream-pane)
274 (eq pane-name
275 (pane-name pane))))
276 (frame-panes frame)))
277
278 (defmethod find-pane-named ((frame application-frame) pane-name)
279 (find-pane-if #'(lambda (pane)
280 (eq pane-name
281 (pane-name pane)))
282 (frame-panes frame)))
283
284 (defmethod frame-standard-output ((frame application-frame))
285 (or (find-pane-of-type (frame-panes frame) 'application-pane)
286 (find-pane-of-type (frame-panes frame) 'interactor-pane)))
287
288 (defmethod frame-standard-input ((frame application-frame))
289 (or (find-pane-of-type (frame-panes frame) 'interactor-pane)
290 (frame-standard-output frame)))
291
292 (defmethod frame-query-io ((frame application-frame))
293 (or (frame-standard-input frame)
294 (frame-standard-output frame)))
295
296 (defmethod frame-error-output ((frame application-frame))
297 (frame-standard-output frame))
298
299 (defvar *pointer-documentation-output* nil)
300
301 (defmethod frame-pointer-documentation-output ((frame application-frame))
302 (find-pane-of-type (frame-panes frame) 'pointer-documentation-pane))
303
304 (defmethod redisplay-frame-panes ((frame application-frame) &key force-p)
305 (map-over-sheets
306 (lambda (sheet)
307 (when (typep sheet 'pane)
308 (when (and (typep sheet 'clim-stream-pane)
309 (not (eq :no-clear (pane-redisplay-needed sheet))))
310 (window-clear sheet))
311 (redisplay-frame-pane frame sheet :force-p force-p)))
312 (frame-top-level-sheet frame)))
313
314 ;;; Command loop interface
315
316 (define-condition frame-exit (condition)
317 ((frame :initarg :frame :reader %frame-exit-frame)))
318
319 ;; I make the assumption here that the contents of *application-frame* is
320 ;; the frame the top-level loop is running. With the introduction of
321 ;; window-stream frames that may be sharing the event queue with the main
322 ;; application frame, we need to discriminate between them here to avoid
323 ;; shutting down the application at the wrong time.
324 ;; ...
325 ;; A better way to do this would be to make the handler bound in
326 ;; run-frame-top-level check whether the frame signalled is the one
327 ;; it was invoked on.. -- Hefner
328
329 (defmethod frame-exit ((frame standard-application-frame))
330 (if (eq *application-frame* frame)
331 (signal 'frame-exit :frame frame)
332 (disown-frame (frame-manager frame) frame)))
333
334 (defmethod frame-exit-frame ((c frame-exit))
335 (%frame-exit-frame c))
336
337 (defmethod redisplay-frame-pane ((frame application-frame) pane &key force-p)
338 (declare (ignore pane force-p))
339 nil)
340
341 (defmethod run-frame-top-level ((frame application-frame) &key &allow-other-keys)
342 (handler-bind ((frame-exit #'(lambda (condition)
343 (declare (ignore condition))
344 (return-from run-frame-top-level nil))))
345 (apply (first (frame-top-level frame)) frame (rest (frame-top-level frame)))))
346
347 (defmethod run-frame-top-level :around ((frame application-frame) &key)
348 (let ((*application-frame* frame)
349 (*input-context* nil)
350 (*input-wait-test* nil)
351 (*input-wait-handler* nil)
352 (*pointer-button-press-handler* nil)
353 (original-state (frame-state frame)))
354 (declare (special *input-context* *input-wait-test* *input-wait-handler*
355 *pointer-button-press-handler*))
356 (when (eq (frame-state frame) :disowned) ; Adopt frame into frame manager
357 (adopt-frame (or (frame-manager frame) (find-frame-manager))
358 frame))
359 (unless (or (eq (frame-state frame) :enabled)
360 (eq (frame-state frame) :shrunk))
361 (enable-frame frame))
362 (let ((query-io (frame-query-io frame))
363 (*default-frame-manager* (frame-manager frame)))
364 (unwind-protect
365 (if query-io
366 (with-input-focus (query-io)
367 (call-next-method))
368 (call-next-method))
369 (progn
370 (let ((fm (frame-manager frame)))
371 (case original-state
372 (:disabled
373 (disable-frame frame))
374 (:disowned
375 (disown-frame fm frame)))))))))
376
377 ;;; Defined in incremental-redisplay.lisp
378 (defvar *enable-updating-output*)
379
380 (defun redisplay-changed-panes (frame)
381 (map-over-sheets #'(lambda (pane)
382 (multiple-value-bind (redisplayp clearp)
383 (pane-needs-redisplay pane)
384 (when redisplayp
385 (when (and clearp
386 (or (not (pane-incremental-redisplay
387 pane))
388 (not *enable-updating-output*)))
389 (window-clear pane))
390 (redisplay-frame-pane frame pane)
391 (unless (eq redisplayp :command-loop)
392 (setf (pane-needs-redisplay pane) nil)))))
393 (frame-top-level-sheet frame)))
394
395 (defmethod default-frame-top-level
396 ((frame application-frame)
397 &key (command-parser 'command-line-command-parser)
398 (command-unparser 'command-line-command-unparser)
399 (partial-command-parser
400 'command-line-read-remaining-arguments-for-partial-command)
401 (prompt "Command: "))
402 (loop
403 (let ((*standard-input* (frame-standard-input frame))
404 (*standard-output* (frame-standard-output frame))
405 (*query-io* (frame-query-io frame))
406 (*pointer-documentation-output* (frame-pointer-documentation-output
407 frame))
408 ;; during development, don't alter *error-output*
409 ;; (*error-output* (frame-error-output frame))
410 (*command-parser* command-parser)
411 (*command-unparser* command-unparser)
412 (*partial-command-parser* partial-command-parser)
413 (prompt-style (make-text-style :fix :italic :normal)))
414 (redisplay-changed-panes frame)
415 (if *standard-input*
416 ;; We don't need to turn the cursor on here, as Goatee has its own
417 ;; cursor which will appear. In fact, as a sane interface policy,
418 ;; leave it off by default, and hopefully this doesn't violate the spec.
419 (progn
420 (setf (cursor-visibility (stream-text-cursor *standard-input*)) nil)
421 (when (and prompt (typep *standard-input* 'interactor-pane))
422 (with-text-style (*standard-input* prompt-style)
423 (if (stringp prompt)
424 (write-string prompt *standard-input*)
425 (funcall prompt *standard-input* frame))
426 (finish-output *standard-input*)))
427 (let ((command (read-frame-command frame)))
428 (when (typep *standard-input* 'interactor-pane)
429 (fresh-line *standard-input*))
430 (when command
431 (execute-frame-command frame command))
432 (when (typep *standard-input* 'interactor-pane)
433 (fresh-line *standard-input*))))
434 (simple-event-loop)))))
435
436
437 (defmethod read-frame-command ((frame application-frame)
438 &key (stream *standard-input*))
439 (with-input-context ('menu-item)
440 (object)
441 (read-command (frame-command-table frame) :stream stream)
442 (menu-item
443 (let ((command (command-menu-item-value object)))
444 (if (listp command)
445 command
446 (list command))))))
447
448
449 (defmethod execute-frame-command ((frame application-frame) command)
450 (apply (command-name command) (command-arguments command)))
451
452 (defmethod make-pane-1 ((fm frame-manager) (frame application-frame) type &rest args)
453 `(make-pane-1 ,fm ,frame ',type ,@args))
454
455 (defmethod make-pane-1 :around (fm (frame standard-application-frame) type
456 &rest args
457 &key (input-buffer nil input-buffer-p)
458 &allow-other-keys)
459 (declare (ignore input-buffer))
460 "Default input-buffer to the frame event queue."
461 (if input-buffer-p
462 (call-next-method)
463 (apply #'call-next-method fm frame type
464 :input-buffer (frame-event-queue frame)
465 args)))
466
467 (defmethod adopt-frame ((fm frame-manager) (frame application-frame))
468 (setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
469 (setf (frame-manager frame) fm)
470 (setf (port frame) (frame-manager-port fm))
471 (setf (graft frame) (find-graft :port (port frame)))
472 (let* ((*application-frame* frame)
473 (t-l-s (make-pane-1 fm frame 'top-level-sheet-pane
474 :name 'top-level-sheet
475 ;; enabling should be left to enable-frame
476 :enabled-p nil))
477 #+clim-mp (event-queue (sheet-event-queue t-l-s)))
478 (setf (slot-value frame 'top-level-sheet) t-l-s)
479 (generate-panes fm frame)
480 (setf (slot-value frame 'state) :disabled)
481 #+clim-mp
482 (when (typep event-queue 'port-event-queue)
483 (setf (event-queue-port event-queue)
484 (frame-manager-port fm)))
485 frame))
486
487 (defmethod disown-frame ((fm frame-manager) (frame application-frame))
488 (let* ((t-l-s (frame-top-level-sheet frame))
489 (queue (sheet-event-queue t-l-s)))
490 (when (typep queue 'port-event-queue)
491 (setf (event-queue-port queue) nil)))
492 (setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
493 (sheet-disown-child (graft frame) (frame-top-level-sheet frame))
494 (setf (%frame-manager frame) nil)
495 (setf (slot-value frame 'state) :disowned)
496 (port-force-output (frame-manager-port fm))
497 frame)
498
499 (defgeneric enable-frame (frame))
500 (defgeneric disable-frame (frame))
501
502 (defgeneric note-frame-enabled (frame-manager frame))
503 (defgeneric note-frame-disbled (frame-manager frame))
504
505 (defmethod enable-frame ((frame application-frame))
506 (setf (sheet-enabled-p (frame-top-level-sheet frame)) t)
507 (setf (slot-value frame 'state) :enabled)
508 (note-frame-enabled (frame-manager frame) frame))
509
510 (defmethod disable-frame ((frame application-frame))
511 (setf (sheet-enabled-p (frame-top-level-sheet frame)) nil)
512 (setf (slot-value frame 'state) :disabled)
513 (note-frame-disabled (frame-manager frame) frame))
514
515 (defmethod note-frame-enabled ((fm frame-manager) frame)
516 (declare (ignore frame))
517 t)
518
519 (defmethod note-frame-disabled ((fm frame-manager) frame)
520 (declare (ignore frame))
521 t)
522
523 (defvar *pane-realizer* nil)
524
525 (defmacro with-look-and-feel-realization ((frame-manager frame) &body body)
526 `(let ((*pane-realizer* ,frame-manager)
527 (*application-frame* ,frame))
528 (locally
529 ,@body)))
530
531 ; The menu-bar code in the following two functions is incorrect.
532 ; it needs to be moved to somewhere after the backend, since
533 ; it depends on the backend chosen.
534 ;
535 ; This hack slaps a menu-bar into the start of the application-frame,
536 ; in such a way that it is hard to find.
537 ;
538 ; FIXME
539 (defun make-single-pane-generate-panes-form (class-name menu-bar pane)
540 `(defmethod generate-panes ((fm frame-manager) (frame ,class-name))
541 ; v-- hey, how can this be?
542 (with-look-and-feel-realization (fm frame)
543 (let ((pane ,(cond
544 ((eq menu-bar t)
545 `(vertically () (clim-internals::make-menu-bar
546 ',class-name)
547 ,pane))
548 ((consp menu-bar)
549 `(vertically () (clim-internals::make-menu-bar
550 (make-command-table nil
551 :menu ',menu-bar))
552 ,pane))
553 (menu-bar
554 `(vertically () (clim-internals::make-menu-bar
555 ',menu-bar)
556 ,pane))
557 ;; The form below is unreachable with (listp
558 ;; menu-bar) instead of (consp menu-bar) above
559 ;; --GB
560 (t pane))))
561 (setf (slot-value frame 'pane) pane)))))
562
563 ; could do with some refactoring [BTS] FIXME
564 (defun make-panes-generate-panes-form (class-name menu-bar panes layouts
565 pointer-documentation)
566 (when pointer-documentation
567 (setf panes (append panes
568 '((%pointer-documentation%
569 pointer-documentation-pane)))))
570 `(defmethod generate-panes ((fm frame-manager) (frame ,class-name))
571 (let ((*application-frame* frame))
572 (with-look-and-feel-realization (fm frame)
573 (let ,(loop for (name . form) in panes
574 collect `(,name (or (find-pane-named frame ',name)
575 (let ((pane
576 ,(cond
577 ((and (= (length form) 1)
578 (listp (first form)))
579 (first form))
580 ((keywordp (first form))
581 (let ((maker (intern (concatenate 'string
582 (symbol-name '#:make-clim-)
583 (symbol-name (first form))
584 (symbol-name '#:-pane))
585 :clim)))
586 (if (fboundp maker)
587 `(,maker :name ',name ,@(cdr form))
588 `(make-pane ',(first form)
589 :name ',name ,@(cdr form)))))
590 (t `(make-pane ',(first form) :name ',name ,@(cdr form))))))
591 ;; hmm?! --GB
592 (setf (slot-value pane 'name) ',name)
593 ;;
594 (push pane (slot-value frame 'panes))
595 pane))))
596 ; [BTS] added this, but is not sure that this is correct for adding
597 ; a menu-bar transparently, should also only be done where the
598 ; exterior window system does not support menus
599 ,(if (or menu-bar pointer-documentation)
600 `(setf (slot-value frame 'pane)
601 (ecase (frame-current-layout frame)
602 ,@(mapcar (lambda (layout)
603 `(,(first layout)
604 (vertically ()
605 ,@(cond
606 ((eq menu-bar t)
607 `((clim-internals::make-menu-bar
608 ',class-name)))
609 ((consp menu-bar)
610 `((clim-internals::make-menu-bar
611 (make-command-table
612 nil
613 :menu ',menu-bar))))
614 (menu-bar
615 `((clim-internals::make-menu-bar
616 ',menu-bar)))
617 (t nil))
618 ,@(rest layout)
619 ,@(when pointer-documentation
620 '(%pointer-documentation%)))))
621 layouts)))
622 `(setf (slot-value frame 'pane)
623 (ecase (frame-current-layout frame)
624 ,@layouts))))))))
625
626 (defmacro define-application-frame (name superclasses slots &rest options)
627 (if (null superclasses)
628 (setq superclasses '(standard-application-frame)))
629 (let ((pane nil)
630 (panes nil)
631 (layouts nil)
632 (current-layout nil)
633 (command-table (list name))
634 (menu-bar t)
635 (disabled-commands nil)
636 (command-definer t)
637 (top-level '(default-frame-top-level))
638 (others nil)
639 (command-name (intern (concatenate 'string
640 (symbol-name '#:define-)
641 (symbol-name name)
642 (symbol-name '#:-command))))
643 (pointer-documentation nil)
644 (geometry nil))
645 (loop for (prop . values) in options
646 do (case prop
647 (:pane (setq pane (first values)))
648 (:panes (setq panes values))
649 (:layouts (setq layouts values))
650 (:command-table (setq command-table (first values)))
651 (:menu-bar (setq menu-bar (if (listp values)
652 (first values)
653 values)))
654 (:disabled-commands (setq disabled-commands values))
655 (:command-definer (setq command-definer (first values)))
656 (:top-level (setq top-level (first values)))
657 (:pointer-documentation (setq pointer-documentation (car values)))
658 (:geometry (setq geometry values))
659 (t (push (cons prop values) others))))
660 (if (or (and pane panes)
661 (and pane layouts))
662 (error ":pane cannot be specified along with either :panes or :layouts"))
663 (if pane
664 (setq panes (list 'single-pane pane)
665 layouts `((:default ,(car pane)))))
666 (setq current-layout (first (first layouts)))
667 `(progn
668 (defclass ,name ,superclasses
669 ,slots
670 (:default-initargs
671 :name ',name
672 :pretty-name ,(string-capitalize name)
673 :command-table (find-command-table ',(first command-table))
674 :disabled-commands ',disabled-commands
675 :menu-bar ',menu-bar
676 :current-layout ',current-layout
677 :layouts ',layouts
678 :top-level ',top-level
679 )
680 ,@others)
681 ,@(if geometry
682 `((setf (get ',name 'application-frame-geometry) ',geometry)))
683 ,(if pane
684 (make-single-pane-generate-panes-form name menu-bar pane)
685 (make-panes-generate-panes-form name menu-bar panes layouts
686 pointer-documentation))
687 ,@(if command-table
688 `((define-command-table ,@command-table)))
689 ,@(if command-definer
690 `((defmacro ,command-name (name-and-options arguements &rest body)
691 (let ((name (if (listp name-and-options) (first name-and-options) name-and-options))
692 (options (if (listp name-and-options) (cdr name-and-options) nil))
693 (command-table ',(first command-table)))
694 `(define-command (,name :command-table ,command-table ,@options) ,arguements ,@body))))))))
695
696 (defun get-application-frame-geometry (name indicator)
697 (let ((geometry (get name 'application-frame-geometry)))
698 (if geometry
699 (getf geometry indicator nil))))
700
701 (defun compose-user-supplied-geometry (left top right bottom width height)
702 (flet ((compute-range (min max diff)
703 (cond
704 ((and min max)
705 (values min max))
706 ((and min diff)
707 (values min (+ min diff)))
708 ((and max diff)
709 (values (- max diff) max))
710 (t
711 (values nil nil)))))
712 (multiple-value-bind (x1 x2) (compute-range left right width)
713 (multiple-value-bind (y1 y2) (compute-range top bottom height)
714 (if (and x1 x2 y1 y2)
715 (make-bounding-rectangle x1 y1 x2 y2)
716 nil)))))
717
718 (defun make-application-frame (frame-name
719 &rest options
720 &key (pretty-name
721 (string-capitalize frame-name))
722 (frame-manager nil frame-manager-p)
723 enable
724 (state nil state-supplied-p)
725 (left (get-application-frame-geometry frame-name :left))
726 (top (get-application-frame-geometry frame-name :top))
727 (right (get-application-frame-geometry frame-name :right))
728 (bottom (get-application-frame-geometry frame-name :bottom))
729 (width (get-application-frame-geometry frame-name :width))
730 (height (get-application-frame-geometry frame-name :height))
731 save-under (frame-class frame-name)
732 &allow-other-keys)
733 (declare (ignore save-under))
734 (with-keywords-removed (options (:pretty-name :frame-manager :enable :state
735 :left :top :right :bottom :width :height
736 :save-under :frame-class))
737 (let ((frame (apply #'make-instance frame-class
738 :name frame-name
739 :pretty-name pretty-name
740 :user-supplied-geometry (compose-user-supplied-geometry
741 left top right bottom width height)
742 options)))
743 (when frame-manager-p
744 (adopt-frame frame-manager frame))
745 (cond ((or enable (eq state :enabled))
746 (enable-frame frame))
747 ((and (eq state :disowned)
748 (not (eq (frame-state frame) :disowned)))
749 (disown-frame (frame-manager frame) frame))
750 (state-supplied-p
751 (warn ":state ~S not supported yet." state)))
752 frame)))
753
754 ;;; Menu frame class
755
756 (defclass menu-frame ()
757 ((left :initform 0 :initarg :left)
758 (top :initform 0 :initarg :top)
759 (top-level-sheet :initform nil :reader frame-top-level-sheet)
760 (pane :reader frame-pane :initarg :pane)
761 (graft :initform nil :accessor graft)
762 (manager :initform nil :accessor frame-manager)))
763
764 (defmethod adopt-frame ((fm frame-manager) (frame menu-frame))
765 (setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
766 (setf (frame-manager frame) fm)
767 (let* ((t-l-s (make-pane-1 fm *application-frame*
768 'unmanaged-top-level-sheet-pane
769 :name 'top-level-sheet)))
770 (setf (slot-value frame 'top-level-sheet) t-l-s)
771 (sheet-adopt-child t-l-s (frame-pane frame))
772 (let ((graft (find-graft :port (frame-manager-port fm))))
773 (sheet-adopt-child graft t-l-s)
774 (setf (graft frame) graft))
775 (let ((space (compose-space t-l-s)))
776 (allocate-space (frame-pane frame)
777 (space-requirement-width space)
778 (space-requirement-height space))
779 (setf (sheet-region t-l-s)
780 (make-bounding-rectangle 0 0
781 (space-requirement-width space)
782 (space-requirement-height space))))
783 (setf (sheet-transformation t-l-s)
784 (make-translation-transformation (slot-value frame 'left)
785 (slot-value frame 'top)))))
786
787 (defmethod disown-frame ((fm frame-manager) (frame menu-frame))
788 (setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
789 (sheet-disown-child (graft frame) (frame-top-level-sheet frame))
790 (setf (frame-manager frame) nil))
791
792 (defun make-menu-frame (pane &key (left 0) (top 0))
793 (make-instance 'menu-frame :pane pane :left left :top top))
794
795 ;;; Frames and presentations
796
797 (defmethod frame-find-innermost-applicable-presentation
798 ((frame standard-application-frame) input-context stream x y
799 &key event)
800 (find-innermost-applicable-presentation input-context stream
801 x y
802 :frame frame :event event))
803
804 (defmethod frame-input-context-button-press-handler
805 ((frame standard-application-frame)
806 (stream output-recording-stream)
807 button-press-event)
808 (let ((presentation (find-innermost-applicable-presentation
809 *input-context*
810 stream
811 (pointer-event-x button-press-event)
812 (pointer-event-y button-press-event)
813 :frame frame
814 :event button-press-event)))
815 (when presentation
816 (throw-highlighted-presentation presentation
817 *input-context*
818 button-press-event))))
819
820 (defmethod frame-input-context-button-press-handler
821 ((frame standard-application-frame) stream button-press-event)
822 (declare (ignore stream button-press-event))
823 nil)
824
825 (defgeneric frame-update-pointer-documentation
826 (frame input-context stream event))
827
828 (defconstant +button-documentation+ '((#.+pointer-left-button+ "L")
829 (#.+pointer-middle-button+ "M")
830 (#.+pointer-right-button+ "R")))
831
832 (defconstant +modifier-documentation+
833 '((#.+shift-key+ "sh" "Shift")
834 (#.+control-key+ "c" "Control")
835 (#.+meta-key+ "m" "Meta")
836 (#.+super-key+ "s" "Super")
837 (#.+hyper-key+ "h" "Hyper")))
838
839 ;;; Give a coherent order to sets of modifier combinations. Multi-key combos
840 ;;; come after single keys.
841
842 (defun cmp-modifiers (a b)
843 (let ((cnt-a (logcount a))
844 (cnt-b (logcount b)))
845 (cond ((eql cnt-a cnt-b)
846 (< a b))
847 (t (< cnt-a cnt-b)))))
848
849 (defun print-modifiers (stream modifiers style)
850 (if (zerop modifiers)
851 (when (eq style :long)
852 (write-string "<nothing>" stream))
853 (loop with trailing = nil
854 for (bit short long) in +modifier-documentation+
855 when (logtest bit modifiers)
856 do (progn
857 (format stream "~:[~;-~]~A" trailing (if (eq style :short)
858 short
859 long))
860 (setq trailing t)))))
861
862
863 ;;; We don't actually want to print out the translator documentation and redraw
864 ;;; the pointer documentation window on every motion event. So, we compute a
865 ;;; state object (basically modifier state and a list of the applicable
866 ;;; presentation, translator and input context on each mouse button),
867 ;;; compare it to the previous state object, and only write out documentation
868 ;;; if they are different. I suppose it's possible that this state object
869 ;;; doesn't capture all possible documentation changes -- the doc generator is
870 ;;; a function, after all -- but that's just tough.
871 ;;;
872 ;;; It would be nice to evolve this into a protocol so that elements other than
873 ;;; presentations -- menu choices, for example -- could influence pointer
874 ;;; documentation window.
875
876 (defgeneric frame-compute-pointer-documentation-state
877 (frame input-context stream event)
878 (:documentation
879 "Compute a state object that will be used to generate pointer documentation."))
880
881 (defmethod frame-compute-pointer-documentation-state
882 ((frame standard-application-frame) input-context stream event)
883 (declare (ignore input-context))
884 (let* ((current-modifier (event-modifier-state event))
885 (x (device-event-x event))
886 (y (device-event-y event))
887 (new-translators
888 (loop for (button) in +button-documentation+
889 for context-list = (multiple-value-list
890 (find-innermost-presentation-context
891 input-context
892 stream
893 x y
894 :modifier-state current-modifier
895 :button button))
896 when (car context-list)
897 collect (cons button context-list))))
898 (list current-modifier new-translators)))
899
900 (defgeneric frame-compare-pointer-documentation-state
901 (frame input-context stream old-state new-state))
902
903 (defmethod frame-compare-pointer-documentation-state
904 ((frame standard-application-frame) input-context stream
905 old-state new-state)
906 (declare (ignore input-context stream))
907 (equal old-state new-state))
908
909 (defgeneric frame-print-pointer-documentation
910 (frame input-context stream state event))
911
912 (defmethod frame-print-pointer-documentation
913 ((frame standard-application-frame) input-context stream state event)
914 (unless state
915 (return-from frame-print-pointer-documentation nil))
916 (destructuring-bind (current-modifier new-translators)
917 state
918 (let ((x (device-event-x event))
919 (y (device-event-y event))
920 (pstream *pointer-documentation-output*))
921 (loop for (button presentation translator context)
922 in new-translators
923 for name = (cadr (assoc button +button-documentation+))
924 for first-one = t then nil
925 do (progn
926 (unless first-one
927 (write-string "; " pstream))
928 (unless (zerop current-modifier)
929 (print-modifiers pstream current-modifier :short)
930 (write-string "-" pstream))
931 (format pstream "~A: " name)
932 (document-presentation-translator translator
933 presentation
934 (input-context-type context)
935 *application-frame*
936 event
937 stream
938 x y
939 :stream pstream
940 :documentation-type
941 :pointer))
942 finally (when new-translators
943 (write-char #\. pstream)))
944 ;; Wasteful to do this after doing
945 ;; find-innermost-presentation-context above... look at doing this
946 ;; first and then doing the innermost test.
947 (let ((all-translators (find-applicable-translators
948 (stream-output-history stream)
949 input-context
950 *application-frame*
951 stream
952 x y
953 :for-menu t))
954 (other-modifiers nil))
955 (loop for (translator) in all-translators
956 for gesture = (gesture translator)
957 unless (eq gesture t)
958 do (loop for (name type modifier) in gesture
959 unless (eql modifier current-modifier)
960 do (pushnew modifier other-modifiers)))
961 (when other-modifiers
962 (setf other-modifiers (sort other-modifiers #'cmp-modifiers))
963 (terpri pstream)
964 (write-string "To see other commands, press " pstream)
965 (loop for modifier-tail on other-modifiers
966 for (modifier) = modifier-tail
967 for count from 0
968 do (progn
969 (if (null (cdr modifier-tail))
970 (progn
971 (when (> count 1)
972 (write-char #\, pstream))
973 (when (> count 0)
974 (write-string " or " pstream)))
975 (when (> count 0)
976 (write-string ", " pstream)))
977 (print-modifiers pstream modifier :long)))
978 (write-char #\. pstream))))))
979
980 (defmethod frame-update-pointer-documentation
981 ((frame standard-application-frame) input-context stream event)
982 (when *pointer-documentation-output*
983 (with-accessors ((frame-documentation-state frame-documentation-state))
984 frame
985 (let ((new-state (frame-compute-pointer-documentation-state frame
986 input-context
987 stream
988 event)))
989 (unless (frame-compare-pointer-documentation-state
990 frame
991 input-context
992 stream
993 frame-documentation-state
994 new-state)
995 (window-clear *pointer-documentation-output*)
996 (frame-print-pointer-documentation frame
997 input-context
998 stream
999 new-state
1000 event)
1001 (setq frame-documentation-state new-state))))))
1002
1003 ;;; A hook for applications to draw random strings in the
1004 ;;; *pointer-documentation-output* without screwing up the real pointer
1005 ;;; documentation too badly.
1006
1007 (defgeneric frame-display-pointer-documentation-string
1008 (frame documentation-stream string))
1009
1010 (defmethod frame-display-pointer-documentation-string
1011 ((frame standard-application-frame) documentation-stream string)
1012 (when *pointer-documentation-output*
1013 (with-accessors ((frame-documentation-state frame-documentation-state))
1014 frame
1015 (unless (frame-compare-pointer-documentation-state
1016 frame nil documentation-stream frame-documentation-state string)
1017 (window-clear documentation-stream)
1018 (write-string string documentation-stream)
1019 (setq frame-documentation-state string)))))
1020
1021 (defmethod frame-input-context-track-pointer
1022 ((frame standard-application-frame)
1023 input-context
1024 (stream output-recording-stream) event)
1025 (declare (ignore input-context event))
1026 nil)
1027
1028 (defmethod frame-input-context-track-pointer
1029 ((frame standard-application-frame) input-context stream event)
1030 (declare (ignore input-context stream event))
1031 nil)
1032
1033 (defun frame-highlight-at-position (frame stream x y &optional (modifier 0)
1034 (input-context *input-context*))
1035 (flet ((maybe-unhighlight (presentation)
1036 (when (and (frame-hilited-presentation frame)
1037 (not (eq presentation
1038 (car (frame-hilited-presentation frame)))))
1039 (highlight-presentation-1 (car (frame-hilited-presentation frame))
1040 (cdr (frame-hilited-presentation frame))
1041 :unhighlight))))
1042 (if (output-recording-stream-p stream)
1043 (let ((presentation (find-innermost-applicable-presentation
1044 input-context
1045 stream
1046 x y
1047 :frame frame
1048 :modifier-state modifier)))
1049 (maybe-unhighlight presentation)
1050 (if presentation
1051 (when (not (eq presentation
1052 (car (frame-hilited-presentation frame))))
1053 (setf (frame-hilited-presentation frame)
1054 (cons presentation stream))
1055 (highlight-presentation-1 presentation stream :highlight))
1056 (setf (frame-hilited-presentation frame) nil)))
1057 (progn
1058 (maybe-unhighlight nil)
1059 (setf (frame-hilited-presentation frame) nil)))))
1060
1061 (defmethod frame-input-context-track-pointer :before
1062 ((frame standard-application-frame) input-context
1063 (stream output-recording-stream) event)
1064 (frame-highlight-at-position frame stream
1065 (device-event-x event)
1066 (device-event-y event)
1067 (event-modifier-state event)
1068 input-context)
1069 (frame-update-pointer-documentation frame input-context stream event))
1070
1071 (defun simple-event-loop ()
1072 "An simple event loop for applications that want all events to be handled by
1073 handle-event methods"
1074 (let ((queue (frame-event-queue *application-frame*)))
1075 (loop for event = (event-queue-read queue)
1076 ;; EVENT-QUEUE-READ in single-process mode calls PROCESS-NEXT-EVENT itself.
1077 do (handle-event (event-sheet event) event))))
1078
1079 ;;; Am I missing something? Does this need to do more? - moore
1080 (defmacro with-application-frame ((frame) &body body)
1081 `(let ((,frame *application-frame*))
1082 ,@body))
1083
1084
1085 (defmethod note-input-focus-changed (pane state)
1086 (declare (ignore pane state)))
1087
1088 (defmethod (setf keyboard-input-focus) :after (focus frame)
1089 (set-port-keyboard-focus focus (port frame)))
1090
1091 ;;; This might do something more useful someday.
1092
1093 (defgeneric reset-frame (frame &rest args))
1094
1095 (defmethod reset-frame ((frame t) &rest args)
1096 (declare (ignore args))
1097 nil)

  ViewVC Help
Powered by ViewVC 1.1.5