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

Contents of /mcclim/frames.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.73 - (show annotations)
Sun Sep 28 15:24:03 2003 UTC (10 years, 6 months ago) by hefner1
Branch: MAIN
Changes since 1.72: +19 -17 lines
In DEFAULT-FRAME-TOP-LEVEL, if there is no interactor pane to use, call
SIMPLE-EVENT-LOOP.
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
106 ;;; Generic operations
107 ; (defgeneric frame-name (frame))
108 ; (defgeneric frame-pretty-name (frame))
109 ; (defgeneric (setf frame-pretty-name) (name frame))
110 ; (defgeneric frame-command-table (frame))
111 ; (defgeneric (setf frame-command-table) (command-table frame))
112 (defgeneric frame-standard-output (frame)
113 (:documentation
114 "Returns the stream that will be used for *standard-output* for the FRAME."))
115 (defgeneric frame-standard-input (frame)
116 (:documentation
117 "Returns the stream that will be used for *standard-input* for the FRAME."))
118 (defgeneric frame-query-io (frame)
119 (:documentation
120 "Returns the stream that will be used for *query-io* for the FRAME."))
121 (defgeneric frame-error-output (frame)
122 (:documentation
123 "Returns the stream that will be used for *error-output* for the FRAME."))
124 (defgeneric frame-pointer-documentation-output (frame)
125 (:documentation
126 "Returns the stream that will be used for *pointer-documentation-output*
127 for the FRAME."))
128 (defgeneric frame-calling-frame (frame)
129 (:documentation
130 "Returns the application frame that invoked the FRAME."))
131 (defgeneric frame-parent (frame)
132 (:documentation
133 "Returns the object that acts as the parent for the FRAME."))
134 ;(defgeneric frame-pane (frame) ; XXX Is it in Spec?
135 ; (:documentation
136 ; "Returns the pane that is the top-level pane in the current layout
137 ;of the FRAME's named panes."))
138 (defgeneric frame-top-level-sheet (frame)
139 (:documentation
140 "Returns the shhet that is the top-level sheet for the FRAME. This
141 is the sheet that has as its descendants all of the panes of the FRAME."))
142 (defgeneric frame-current-panes (frame)
143 (:documentation
144 "Returns a list of those named panes in the FRAME's current layout.
145 If there are no named panes, only the single, top level pane is returned."))
146 (defgeneric get-frame-pane (frame pane-name)
147 (:documentation
148 "Returns the named CLIM stream pane in the FRAME whose name is PANE-NAME."))
149 (defgeneric find-pane-named (frame pane-name)
150 (:documentation
151 "Returns the pane in the FRAME whose name is PANE-NAME."))
152 ;(defgeneric frame-current-layout (frame))
153 ;(defgeneric frame-all-layouts (frame)) ; XXX Is it in Spec?
154 (defgeneric layout-frame (frame &optional width height))
155 (defgeneric frame-exit-frame (condition)
156 (:documentation
157 "Returns the frame that is being exited from associated with the
158 FRAME-EXIT condition."))
159 (defgeneric frame-exit (frame) ; XXX Is it in Spec?
160 (:documentation
161 "Exits from the FRAME."))
162 (defgeneric pane-needs-redisplay (pane))
163 (defgeneric (setf pane-needs-redisplay) (value pane))
164 (defgeneric redisplay-frame-pane (frame pane &key force-p))
165 (defgeneric redisplay-frame-panes (frame &key force-p))
166 (defgeneric frame-replay (frame stream &optional region))
167 (defgeneric notify-user (frame message &key associated-window title
168 documentation exit-boxes name style text-style))
169 ;(defgeneric frame-properties (frame property))
170 ;(defgeneric (setf frame-properties) (value frame property))
171
172 ; extension
173 (defgeneric frame-schedule-timer-event (frame sheet delay token))
174
175 (defgeneric note-input-focus-changed (pane state)
176 (:documentation "Called when a pane receives or loses the keyboard
177 input focus. This is a McCLIM extension."))
178
179 (defclass standard-application-frame (application-frame)
180 ((event-queue :initarg :frame-event-queue
181 :initarg :input-buffer
182 :initform nil
183 :accessor frame-event-queue
184 :documentation "The event queue that, by default, will be
185 shared by all panes in the stream")
186 (documentation-state :accessor frame-documentation-state
187 :initform nil
188 :documentation "Used to keep of track of what
189 needs to be rendered in the pointer documentation frame.")))
190
191 ;;; Support the :input-buffer initarg for compatibility with "real CLIM"
192
193 (defmethod initialize-instance :after ((obj standard-application-frame)
194 &key &allow-other-keys)
195 (unless (frame-event-queue obj)
196 (setf (frame-event-queue obj)
197 (make-instance 'port-event-queue :port (port obj)))))
198
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)
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 (unwind-protect
364 (if query-io
365 (with-input-focus (query-io)
366 (call-next-method))
367 (call-next-method))
368 (progn
369 (let ((fm (frame-manager frame)))
370 (case original-state
371 (:disabled
372 (disable-frame frame))
373 (:disowned
374 (disown-frame (frame-manager frame) frame)))
375 (port-force-output (frame-manager-port fm))))))))
376
377 (defun redisplay-changed-panes (frame)
378 (map-over-sheets #'(lambda (pane)
379 (multiple-value-bind (redisplayp clearp)
380 (pane-needs-redisplay pane)
381 (when redisplayp
382 (when (and clearp
383 (or (not (pane-incremental-redisplay
384 pane))
385 (not *enable-updating-output*)))
386 (window-clear pane))
387 (redisplay-frame-pane frame pane)
388 (unless (eq redisplayp :command-loop)
389 (setf (pane-needs-redisplay pane) nil)))))
390 (frame-top-level-sheet frame)))
391
392 (defmethod default-frame-top-level
393 ((frame application-frame)
394 &key (command-parser 'command-line-command-parser)
395 (command-unparser 'command-line-command-unparser)
396 (partial-command-parser
397 'command-line-read-remaining-arguments-for-partial-command)
398 (prompt "Command: "))
399 (loop
400 (let ((*standard-input* (frame-standard-input frame))
401 (*standard-output* (frame-standard-output frame))
402 (*query-io* (frame-query-io frame))
403 (*pointer-documentation-output* (frame-pointer-documentation-output
404 frame))
405 ;; during development, don't alter *error-output*
406 ;; (*error-output* (frame-error-output frame))
407 (*command-parser* command-parser)
408 (*command-unparser* command-unparser)
409 (*partial-command-parser* partial-command-parser)
410 (prompt-style (make-text-style :fix :italic :normal)))
411 (redisplay-changed-panes frame)
412 (if *standard-input*
413 ;; We don't need to turn the cursor on here, as Goatee bhas its own
414 ;; cursor which will appear. In fact, as a sane interface policy,
415 ;; leave it off by default, and hopefully this doesn't violate the spec.
416 (progn
417 (setf (cursor-visibility (stream-text-cursor *standard-input*)) nil)
418 (when prompt
419 (with-text-style (*standard-input* prompt-style)
420 (if (stringp prompt)
421 (write-string prompt *standard-input*)
422 (funcall prompt *standard-input* frame))
423 (finish-output *standard-input*)))
424 (let ((command (read-frame-command frame)))
425 (fresh-line *standard-input*)
426 (when command
427 (execute-frame-command frame command))
428 (fresh-line *standard-input*)))
429 (simple-event-loop)))))
430
431
432 (defmethod read-frame-command ((frame application-frame)
433 &key (stream *standard-input*))
434 (with-input-context ('menu-item)
435 (object)
436 ;; Is this the intended behavior of interactor-panes
437 ;; (vs. application panes)?
438 (if (typep stream 'interactor-pane)
439 (read-command (frame-command-table frame) :stream stream)
440 (loop (read-gesture :stream stream)))
441 (menu-item
442 (let ((command (command-menu-item-value object)))
443 (if (listp command)
444 command
445 (list command))))))
446
447
448 (defmethod execute-frame-command ((frame application-frame) command)
449 (apply (command-name command) (command-arguments command)))
450
451 (defmethod make-pane-1 ((fm frame-manager) (frame application-frame) type &rest args)
452 `(make-pane-1 ,fm ,frame ',type ,@args))
453
454 (defmethod make-pane-1 :around (fm (frame standard-application-frame) type
455 &rest args
456 &key (input-buffer nil input-buffer-p)
457 &allow-other-keys)
458 "Default input-buffer to the frame event queue."
459 (if input-buffer-p
460 (call-next-method)
461 (apply #'call-next-method fm frame type
462 :input-buffer (frame-event-queue frame)
463 args)))
464
465 (defmethod adopt-frame ((fm frame-manager) (frame application-frame))
466 (setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
467 (setf (frame-manager frame) fm)
468 (setf (port frame) (frame-manager-port fm))
469 (setf (graft frame) (find-graft :port (port frame)))
470 (let* ((*application-frame* frame)
471 (t-l-s (make-pane-1 fm frame 'top-level-sheet-pane
472 :name 'top-level-sheet
473 ;; enabling should be left to enable-frame
474 :enabled-p nil)))
475 (setf (slot-value frame 'top-level-sheet) t-l-s)
476 (generate-panes fm frame)
477 (setf (slot-value frame 'state) :disabled)
478 frame))
479
480 (defmethod disown-frame ((fm frame-manager) (frame application-frame))
481 (setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
482 (sheet-disown-child (graft frame) (frame-top-level-sheet frame))
483 (setf (%frame-manager frame) nil)
484 (setf (slot-value frame 'state) :disowned)
485 frame)
486
487 (defgeneric enable-frame (frame))
488 (defgeneric disable-frame (frame))
489
490 (defgeneric note-frame-enabled (frame-manager frame))
491 (defgeneric note-frame-disbled (frame-manager frame))
492
493 (defmethod enable-frame ((frame application-frame))
494 (setf (sheet-enabled-p (frame-top-level-sheet frame)) t)
495 (setf (slot-value frame 'state) :enabled)
496 (note-frame-enabled (frame-manager frame) frame))
497
498 (defmethod disable-frame ((frame application-frame))
499 (setf (sheet-enabled-p (frame-top-level-sheet frame)) nil)
500 (setf (slot-value frame 'state) :disabled)
501 (note-frame-disabled (frame-manager frame) frame))
502
503 (defmethod note-frame-enabled ((fm frame-manager) frame)
504 (declare (ignore frame))
505 t)
506
507 (defmethod note-frame-disabled ((fm frame-manager) frame)
508 t)
509
510 (defvar *pane-realizer* nil)
511
512 (defmacro with-look-and-feel-realization ((frame-manager frame) &body body)
513 `(let ((*pane-realizer* ,frame-manager)
514 (*application-frame* ,frame))
515 (locally
516 ,@body)))
517
518 ; The menu-bar code in the following two functions is incorrect.
519 ; it needs to be moved to somewhere after the backend, since
520 ; it depends on the backend chosen.
521 ;
522 ; This hack slaps a menu-bar into the start of the application-frame,
523 ; in such a way that it is hard to find.
524 ;
525 ; FIXME
526 (defun make-single-pane-generate-panes-form (class-name menu-bar pane)
527 `(defmethod generate-panes ((fm frame-manager) (frame ,class-name))
528 ; v-- hey, how can this be?
529 (with-look-and-feel-realization (fm frame)
530 (let ((pane ,(cond
531 ((eq menu-bar t)
532 `(vertically () (clim-internals::make-menu-bar
533 ',class-name)
534 ,pane))
535 ((consp menu-bar)
536 `(vertically () (clim-internals::make-menu-bar
537 (make-command-table nil
538 :menu ',menu-bar))
539 ,pane))
540 (menu-bar
541 `(vertically () (clim-internals::make-menu-bar
542 ',menu-bar)
543 ,pane))
544 ;; The form below is unreachable with (listp
545 ;; menu-bar) instead of (consp menu-bar) above
546 ;; --GB
547 (t pane))))
548 (setf (slot-value frame 'pane) pane)))))
549
550 ; could do with some refactoring [BTS] FIXME
551 (defun make-panes-generate-panes-form (class-name menu-bar panes layouts
552 pointer-documentation)
553 (when pointer-documentation
554 (setf panes (append panes
555 '((%pointer-documentation%
556 pointer-documentation-pane)))))
557 `(defmethod generate-panes ((fm frame-manager) (frame ,class-name))
558 (let ((*application-frame* frame))
559 (with-look-and-feel-realization (fm frame)
560 (let ,(loop for (name . form) in panes
561 collect `(,name (or (find-pane-named frame ',name)
562 (let ((pane
563 ,(cond
564 ((and (= (length form) 1)
565 (listp (first form)))
566 (first form))
567 ((keywordp (first form))
568 (let ((maker (intern (concatenate 'string
569 (symbol-name '#:make-clim-)
570 (symbol-name (first form))
571 (symbol-name '#:-pane))
572 :clim)))
573 (if (fboundp maker)
574 `(,maker :name ',name ,@(cdr form))
575 `(make-pane ',(first form)
576 :name ',name ,@(cdr form)))))
577 (t `(make-pane ',(first form) :name ',name ,@(cdr form))))))
578 ;; hmm?! --GB
579 (setf (slot-value pane 'name) ',name)
580 ;;
581 (push pane (slot-value frame 'panes))
582 pane))))
583 ; [BTS] added this, but is not sure that this is correct for adding
584 ; a menu-bar transparently, should also only be done where the
585 ; exterior window system does not support menus
586 ,(if (or menu-bar pointer-documentation)
587 `(setf (slot-value frame 'pane)
588 (ecase (frame-current-layout frame)
589 ,@(mapcar (lambda (layout)
590 `(,(first layout)
591 (vertically ()
592 ,@(cond
593 ((eq menu-bar t)
594 `((clim-internals::make-menu-bar
595 ',class-name)))
596 ((consp menu-bar)
597 `((clim-internals::make-menu-bar
598 (make-command-table
599 nil
600 :menu ',menu-bar))))
601 (menu-bar
602 `((clim-internals::make-menu-bar
603 ',menu-bar)))
604 (t nil))
605 ,@(rest layout)
606 ,@(when pointer-documentation
607 '(%pointer-documentation%)))))
608 layouts)))
609 `(setf (slot-value frame 'pane)
610 (ecase (frame-current-layout frame)
611 ,@layouts))))))))
612
613 (defmacro define-application-frame (name superclasses slots &rest options)
614 (if (null superclasses)
615 (setq superclasses '(standard-application-frame)))
616 (let ((pane nil)
617 (panes nil)
618 (layouts nil)
619 (current-layout nil)
620 (command-table (list name))
621 (menu-bar t)
622 (disabled-commands nil)
623 (command-definer t)
624 (top-level '(default-frame-top-level))
625 (others nil)
626 (command-name (intern (concatenate 'string
627 (symbol-name '#:define-)
628 (symbol-name name)
629 (symbol-name '#:-command))))
630 (pointer-documentation nil)
631 (geometry nil))
632 (loop for (prop . values) in options
633 do (case prop
634 (:pane (setq pane (first values)))
635 (:panes (setq panes values))
636 (:layouts (setq layouts values))
637 (:command-table (setq command-table (first values)))
638 (:menu-bar (setq menu-bar (if (listp values)
639 (first values)
640 values)))
641 (:disabled-commands (setq disabled-commands values))
642 (:command-definer (setq command-definer (first values)))
643 (:top-level (setq top-level (first values)))
644 (:pointer-documentation (setq pointer-documentation (car values)))
645 (:geometry (setq geometry values))
646 (t (push (cons prop values) others))))
647 (if (or (and pane panes)
648 (and pane layouts))
649 (error ":pane cannot be specified along with either :panes or :layouts"))
650 (if pane
651 (setq panes (list 'single-pane pane)
652 layouts `((:default ,(car pane)))))
653 (setq current-layout (first (first layouts)))
654 `(progn
655 (defclass ,name ,superclasses
656 ,slots
657 (:default-initargs
658 :name ',name
659 :pretty-name ,(string-capitalize name)
660 :command-table (find-command-table ',(first command-table))
661 :disabled-commands ',disabled-commands
662 :menu-bar ',menu-bar
663 :current-layout ',current-layout
664 :layouts ',layouts
665 :top-level ',top-level
666 )
667 ,@others)
668 ,@(if geometry
669 `((setf (get ',name 'application-frame-geometry) ',geometry)))
670 ,(if pane
671 (make-single-pane-generate-panes-form name menu-bar pane)
672 (make-panes-generate-panes-form name menu-bar panes layouts
673 pointer-documentation))
674 ,@(if command-table
675 `((define-command-table ,@command-table)))
676 ,@(if command-definer
677 `((defmacro ,command-name (name-and-options arguements &rest body)
678 (let ((name (if (listp name-and-options) (first name-and-options) name-and-options))
679 (options (if (listp name-and-options) (cdr name-and-options) nil))
680 (command-table ',(first command-table)))
681 `(define-command (,name :command-table ,command-table ,@options) ,arguements ,@body))))))))
682
683 (defun get-application-frame-geometry (name indicator)
684 (let ((geometry (get name 'application-frame-geometry)))
685 (if geometry
686 (getf geometry indicator nil))))
687
688 (defun compose-user-supplied-geometry (left top right bottom width height)
689 (flet ((compute-range (min max diff)
690 (cond
691 ((and min max)
692 (values min max))
693 ((and min diff)
694 (values min (+ min diff)))
695 ((and max diff)
696 (values (- max diff) max))
697 (t
698 (values nil nil)))))
699 (multiple-value-bind (x1 x2) (compute-range left right width)
700 (multiple-value-bind (y1 y2) (compute-range top bottom height)
701 (if (and x1 x2 y1 y2)
702 (make-bounding-rectangle x1 y1 x2 y2)
703 nil)))))
704
705 (defun make-application-frame (frame-name
706 &rest options
707 &key (pretty-name
708 (string-capitalize frame-name))
709 (frame-manager nil frame-manager-p)
710 enable
711 (state nil state-supplied-p)
712 (left (get-application-frame-geometry frame-name :left))
713 (top (get-application-frame-geometry frame-name :top))
714 (right (get-application-frame-geometry frame-name :right))
715 (bottom (get-application-frame-geometry frame-name :bottom))
716 (width (get-application-frame-geometry frame-name :width))
717 (height (get-application-frame-geometry frame-name :height))
718 save-under (frame-class frame-name)
719 &allow-other-keys)
720 (declare (ignore save-under))
721 (with-keywords-removed (options (:pretty-name :frame-manager :enable :state
722 :left :top :right :bottom :width :height
723 :save-under :frame-class))
724 (let ((frame (apply #'make-instance frame-class
725 :name frame-name
726 :pretty-name pretty-name
727 :user-supplied-geometry (compose-user-supplied-geometry
728 left top right bottom width height)
729 options)))
730 (when frame-manager-p
731 (adopt-frame frame-manager frame))
732 (cond ((or enable (eq state :enabled))
733 (enable-frame frame))
734 ((and (eq state :disowned)
735 (not (eq (frame-state frame) :disowned)))
736 (disown-frame (frame-manager frame) frame))
737 (state-supplied-p
738 (warn ":state ~S not supported yet." state)))
739 frame)))
740
741 ;;; Menu frame class
742
743 (defclass menu-frame ()
744 ((left :initform 0 :initarg :left)
745 (top :initform 0 :initarg :top)
746 (top-level-sheet :initform nil :reader frame-top-level-sheet)
747 (pane :reader frame-pane :initarg :pane)
748 (graft :initform nil :accessor graft)
749 (manager :initform nil :accessor frame-manager)))
750
751 (defmethod adopt-frame ((fm frame-manager) (frame menu-frame))
752 (setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
753 (setf (frame-manager frame) fm)
754 (let* ((t-l-s (make-pane-1 fm *application-frame*
755 'unmanaged-top-level-sheet-pane
756 :name 'top-level-sheet)))
757 (setf (slot-value frame 'top-level-sheet) t-l-s)
758 (sheet-adopt-child t-l-s (frame-pane frame))
759 (let ((graft (find-graft :port (frame-manager-port fm))))
760 (sheet-adopt-child graft t-l-s)
761 (setf (graft frame) graft))
762 (let ((space (compose-space t-l-s)))
763 (allocate-space (frame-pane frame)
764 (space-requirement-width space)
765 (space-requirement-height space))
766 (setf (sheet-region t-l-s)
767 (make-bounding-rectangle 0 0
768 (space-requirement-width space)
769 (space-requirement-height space))))
770 (setf (sheet-transformation t-l-s)
771 (make-translation-transformation (slot-value frame 'left)
772 (slot-value frame 'top)))))
773
774 (defmethod disown-frame ((fm frame-manager) (frame menu-frame))
775 (setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
776 (sheet-disown-child (graft frame) (frame-top-level-sheet frame))
777 (setf (frame-manager frame) nil))
778
779 (defun make-menu-frame (pane &key (left 0) (top 0))
780 (make-instance 'menu-frame :pane pane :left left :top top))
781
782 ;;; Frames and presentations
783
784 (defmethod frame-find-innermost-applicable-presentation
785 ((frame standard-application-frame) input-context stream x y
786 &key event)
787 (find-innermost-applicable-presentation input-context stream
788 x y
789 :frame frame :event event))
790
791 (defmethod frame-input-context-button-press-handler
792 ((frame standard-application-frame)
793 (stream output-recording-stream)
794 button-press-event)
795 (let ((presentation (find-innermost-applicable-presentation
796 *input-context*
797 stream
798 (pointer-event-x button-press-event)
799 (pointer-event-y button-press-event)
800 :frame frame
801 :event button-press-event)))
802 (when presentation
803 (throw-highlighted-presentation presentation
804 *input-context*
805 button-press-event))))
806
807 (defmethod frame-input-context-button-press-handler
808 ((frame standard-application-frame) stream button-press-event)
809 (declare (ignore stream button-press-event))
810 nil)
811
812 (defgeneric frame-update-pointer-documentation
813 (frame input-context stream event))
814
815 (defconstant +button-documentation+ '((#.+pointer-left-button+ "L")
816 (#.+pointer-middle-button+ "M")
817 (#.+pointer-right-button+ "R")))
818
819 (defconstant +modifier-documentation+
820 '((#.+shift-key+ "sh" "Shift")
821 (#.+control-key+ "c" "Control")
822 (#.+meta-key+ "m" "Meta")
823 (#.+super-key+ "s" "Super")
824 (#.+hyper-key+ "h" "Hyper")))
825
826 ;;; Give a coherent order to sets of modifier combinations. Multi-key combos
827 ;;; come after single keys.
828
829 (defun cmp-modifiers (a b)
830 (let ((cnt-a (logcount a))
831 (cnt-b (logcount b)))
832 (cond ((eql cnt-a cnt-b)
833 (< a b))
834 (t (< cnt-a cnt-b)))))
835
836 (defun print-modifiers (stream modifiers style)
837 (if (zerop modifiers)
838 (when (eq style :long)
839 (write-string "<nothing>" stream))
840 (loop with trailing = nil
841 for (bit short long) in +modifier-documentation+
842 when (logtest bit modifiers)
843 do (progn
844 (format stream "~:[~;-~]~A" trailing (if (eq style :short)
845 short
846 long))
847 (setq trailing t)))))
848
849
850 ;;; We don't actually want to print out the translator documentation and redraw
851 ;;; the pointer documentation window on every motion event. So, we compute a
852 ;;; state object (basically modifier state and a list of the applicable
853 ;;; presentation, translator and input context on each mouse button),
854 ;;; compare it to the previous state object, and only write out documentation
855 ;;; if they are different. I suppose it's possible that this state object
856 ;;; doesn't capture all possible documentation changes -- the doc generator is
857 ;;; a function, after all -- but that's just tough.
858 ;;;
859 ;;; It would be nice to evolve this into a protocol so that elements other than
860 ;;; presentations -- menu choices, for example -- could influence pointer
861 ;;; documentation window.
862
863 (defgeneric frame-compute-pointer-documentation-state
864 (frame input-context stream event)
865 (:documentation
866 "Compute a state object that will be used to generate pointer documentation."))
867
868 (defmethod frame-compute-pointer-documentation-state
869 ((frame standard-application-frame) input-context stream event)
870 (let* ((current-modifier (event-modifier-state event))
871 (x (device-event-x event))
872 (y (device-event-y event))
873 (new-translators
874 (loop for (button) in +button-documentation+
875 for context-list = (multiple-value-list
876 (find-innermost-presentation-context
877 input-context
878 stream
879 x y
880 :modifier-state current-modifier
881 :button button))
882 when (car context-list)
883 collect (cons button context-list))))
884 (list current-modifier new-translators)))
885
886 (defgeneric frame-compare-pointer-documentation-state
887 (frame input-context stream old-state new-state))
888
889 (defmethod frame-compare-pointer-documentation-state
890 ((frame standard-application-frame) input-context stream
891 old-state new-state)
892 (equal old-state new-state))
893
894 (defgeneric frame-print-pointer-documentation
895 (frame input-context stream state event))
896
897 (defmethod frame-print-pointer-documentation
898 ((frame standard-application-frame) input-context stream state event)
899 (unless state
900 (return-from frame-print-pointer-documentation nil))
901 (destructuring-bind (current-modifier new-translators)
902 state
903 (let ((x (device-event-x event))
904 (y (device-event-y event))
905 (pstream *pointer-documentation-output*))
906 (loop for (button presentation translator context)
907 in new-translators
908 for name = (cadr (assoc button +button-documentation+))
909 for first-one = t then nil
910 do (progn
911 (unless first-one
912 (write-string "; " pstream))
913 (unless (zerop current-modifier)
914 (print-modifiers pstream current-modifier :short)
915 (write-string "-" pstream))
916 (format pstream "~A: " name)
917 (document-presentation-translator translator
918 presentation
919 (input-context-type context)
920 *application-frame*
921 event
922 stream
923 x y
924 :stream pstream
925 :documentation-type
926 :pointer))
927 finally (when new-translators
928 (write-char #\. pstream)))
929 ;; Wasteful to do this after doing
930 ;; find-innermost-presentation-context above... look at doing this
931 ;; first and then doing the innermost test.
932 (let ((all-translators (find-applicable-translators
933 (stream-output-history stream)
934 input-context
935 *application-frame*
936 stream
937 x y
938 :for-menu t))
939 (other-modifiers nil))
940 (loop for (translator) in all-translators
941 for gesture = (gesture translator)
942 unless (eq gesture t)
943 do (loop for (name type modifier) in gesture
944 unless (eql modifier current-modifier)
945 do (pushnew modifier other-modifiers)))
946 (when other-modifiers
947 (setf other-modifiers (sort other-modifiers #'cmp-modifiers))
948 (terpri pstream)
949 (write-string "To see other commands, press " pstream)
950 (loop for modifier-tail on other-modifiers
951 for (modifier) = modifier-tail
952 for count from 0
953 do (progn
954 (if (null (cdr modifier-tail))
955 (progn
956 (when (> count 1)
957 (write-char #\, pstream))
958 (when (> count 0)
959 (write-string " or " pstream)))
960 (when (> count 0)
961 (write-string ", " pstream)))
962 (print-modifiers pstream modifier :long)))
963 (write-char #\. pstream))))))
964
965 (defmethod frame-update-pointer-documentation
966 ((frame standard-application-frame) input-context stream event)
967 (when *pointer-documentation-output*
968 (with-accessors ((frame-documentation-state frame-documentation-state))
969 frame
970 (let ((new-state (frame-compute-pointer-documentation-state frame
971 input-context
972 stream
973 event)))
974 (unless (frame-compare-pointer-documentation-state
975 frame
976 input-context
977 stream
978 frame-documentation-state
979 new-state)
980 (window-clear *pointer-documentation-output*)
981 (frame-print-pointer-documentation frame
982 input-context
983 stream
984 new-state
985 event)
986 (setq frame-documentation-state new-state))))))
987
988 (defmethod frame-input-context-track-pointer
989 ((frame standard-application-frame)
990 input-context
991 (stream output-recording-stream) event)
992 (declare (ignore input-context event))
993 nil)
994
995 (defmethod frame-input-context-track-pointer
996 ((frame standard-application-frame) input-context stream event)
997 (declare (ignore input-context stream event))
998 nil)
999
1000 (defmethod frame-input-context-track-pointer :before
1001 ((frame standard-application-frame) input-context stream event)
1002 (flet ((maybe-unhighlight (presentation)
1003 (when (and (frame-hilited-presentation frame)
1004 (not (eq presentation
1005 (car (frame-hilited-presentation frame)))))
1006 (highlight-presentation-1 (car (frame-hilited-presentation frame))
1007 (cdr (frame-hilited-presentation frame))
1008 :unhighlight))))
1009 (if (output-recording-stream-p stream)
1010 (let ((presentation (find-innermost-applicable-presentation
1011 input-context
1012 stream
1013 (device-event-x event)
1014 (device-event-y event)
1015 :frame frame
1016 :modifier-state (event-modifier-state event))))
1017 (maybe-unhighlight presentation)
1018 (if presentation
1019 (when (not (eq presentation
1020 (car (frame-hilited-presentation frame))))
1021 (setf (frame-hilited-presentation frame)
1022 (cons presentation stream))
1023 (highlight-presentation-1 presentation stream :highlight))
1024 (setf (frame-hilited-presentation frame) nil)))
1025 (progn
1026 (maybe-unhighlight nil)
1027 (setf (frame-hilited-presentation frame) nil))))
1028 (frame-update-pointer-documentation frame input-context stream event))
1029
1030 (defun simple-event-loop ()
1031 "An simple event loop for applications that want all events to be handled by
1032 handle-event methods"
1033 (let ((queue (frame-event-queue *application-frame*)))
1034 (loop for event = (event-queue-read queue)
1035 ;; EVENT-QUEUE-READ in single-process mode calls PROCESS-NEXT-EVENT itself.
1036 do (handle-event (event-sheet event) event))))
1037
1038 ;;; Am I missing something? Does this need to do more? - moore
1039 (defmacro with-application-frame ((frame) &body body)
1040 `(let ((,frame *application-frame*))
1041 ,@body))
1042
1043
1044 (defmethod note-input-focus-changed (pane state)
1045 (declare (ignore pane state)))
1046
1047 (defmethod (setf keyboard-input-focus) :after (focus frame)
1048 (set-port-keyboard-focus focus (port frame)))
1049

  ViewVC Help
Powered by ViewVC 1.1.5