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

Contents of /mcclim/frames.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.76 - (show annotations)
Fri Oct 31 19:02:14 2003 UTC (10 years, 5 months ago) by hefner1
Branch: MAIN
Changes since 1.75: +18 -10 lines
In :before method on frame-input-context-track-pointer which handles
presentation highlighting, specialize the stream argument on
output-record-stream.

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

  ViewVC Help
Powered by ViewVC 1.1.5