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

Contents of /mcclim/frames.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.130 - (show annotations)
Sun Jan 27 22:24:07 2008 UTC (6 years, 2 months ago) by thenriksen
Branch: MAIN
Changes since 1.129: +116 -104 lines
Added some amazing hacks to pointer-documentation-panes for the notion of a "background message".

This is the beginning of extending pointer-documentation-panes into
more generally useful minibuffer-like panes.

For now, this just means that the Listener shows arglists and other
things for Drei commands. It's still a little flickery, though.
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 ;;; (c) copyright 2004 by
9 ;;; Gilbert Baumann <unk6@rz.uni-karlsruhe.de>
10
11 ;;; This library is free software; you can redistribute it and/or
12 ;;; modify it under the terms of the GNU Library General Public
13 ;;; License as published by the Free Software Foundation; either
14 ;;; version 2 of the License, or (at your option) any later version.
15 ;;;
16 ;;; This library is distributed in the hope that it will be useful,
17 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;;; Library General Public License for more details.
20 ;;;
21 ;;; You should have received a copy of the GNU Library General Public
22 ;;; License along with this library; if not, write to the
23 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;;; Boston, MA 02111-1307 USA.
25
26 (in-package :clim-internals)
27
28 ;; *application-frame* is in decls.lisp
29 (defvar *default-frame-manager* nil)
30
31 ;;; Frame-Manager class
32
33 ;; FIXME: The spec says the port must "conform to options".
34 ;; I've added a check that the ports match, but we've no
35 ;; protocol for testing the other options. -Hefner
36 (defun find-frame-manager (&rest options &key port &allow-other-keys)
37 (declare (special *frame-manager*))
38 (if (and (boundp '*frame-manager*)
39 (or (null port)
40 (eql port (frame-manager-port *frame-manager*))))
41 *frame-manager*
42 (if (and *default-frame-manager*
43 (frame-manager-p *default-frame-manager*)
44 (or (null port)
45 (eql port (frame-manager-port *default-frame-manager*))))
46 *default-frame-manager*
47 (first (frame-managers (or port (apply #'find-port options)))))))
48
49 (defmacro with-frame-manager ((frame-manager) &body body)
50 `(let ((*frame-manager* ,frame-manager))
51 (declare (special *frame-manager*))
52 (locally ,@body)))
53
54 ;;; XXX These should force the redisplay of the menu bar. They don't
55 ;;; yet.
56
57 (defmethod note-command-enabled (frame-manager frame command-name)
58 (declare (ignore frame-manager frame command-name))
59 nil)
60
61 (defmethod note-command-disabled (frame-manager frame command-name)
62 (declare (ignore frame-manager frame command-name))
63 nil)
64
65 ;;; Application-Frame class
66 ;;; XXX All these slots should move to a mixin or to standard-application-frame.
67 ;;; -- moore
68
69 ; extension
70 (defgeneric frame-schedule-timer-event (frame sheet delay token))
71
72 (defgeneric note-input-focus-changed (pane state)
73 (:documentation "Called when a pane receives or loses the keyboard
74 input focus. This is a McCLIM extension."))
75
76 (defclass standard-application-frame (application-frame
77 presentation-history-mixin)
78 ((port :initform nil
79 :initarg :port
80 :accessor port)
81 (graft :initform nil
82 :initarg :graft
83 :accessor graft)
84 (name :initarg :name
85 :reader frame-name)
86 (pretty-name :initarg :pretty-name
87 :accessor frame-pretty-name)
88 (command-table :initarg :command-table
89 :initform nil
90 :accessor frame-command-table)
91 (named-panes :accessor frame-named-panes :initform nil)
92 (panes :initform nil :reader frame-panes
93 :documentation "The tree of panes in the current layout.")
94 (layouts :initform nil
95 :initarg :layouts
96 :reader frame-layouts)
97 (current-layout :initform nil
98 :initarg :current-layout
99 :accessor frame-current-layout)
100 (panes-for-layout :initform nil :accessor frame-panes-for-layout
101 :documentation "alist of names and panes (as returned by make-pane)")
102 (top-level-sheet :initform nil
103 :reader frame-top-level-sheet)
104 (menu-bar :initarg :menu-bar
105 :initform nil)
106 (state :initarg :state
107 :initform :disowned
108 :reader frame-state)
109 (manager :initform nil
110 :reader frame-manager
111 :accessor %frame-manager)
112 (properties :accessor %frame-properties
113 :initarg :properties
114 :initform nil)
115 (top-level :initform '(default-frame-top-level)
116 :initarg :top-level
117 :reader frame-top-level)
118 (top-level-lambda :initarg :top-level-lambda
119 :reader frame-top-level-lambda)
120 (hilited-presentation :initform nil
121 :initarg :hilited-presentation
122 :accessor frame-hilited-presentation)
123 (process :accessor frame-process :initform nil)
124 (client-settings :accessor client-settings :initform nil)
125 (event-queue :initarg :frame-event-queue
126 :initarg :input-buffer
127 :initform nil
128 :accessor frame-event-queue
129 :documentation "The event queue that, by default, will be
130 shared by all panes in the stream")
131 (documentation-state :accessor frame-documentation-state
132 :initform nil
133 :documentation "Used to keep of track of what
134 needs to be rendered in the pointer documentation frame.")
135 (calling-frame :reader frame-calling-frame
136 :initarg :calling-frame
137 :initform nil
138 :documentation "The frame that is the parent of this
139 frame, if any")
140 (disabled-commands :accessor disabled-commands
141 :accessor frame-disabled-commands
142 :initarg :disabled-commands
143 :initform nil
144 :documentation "A list of command names that have been
145 disabled in this frame")
146 (documentation-record :accessor documentation-record
147 :initform nil
148 :documentation "updating output record for pointer
149 documentation produced by presentations.")
150 (geometry-left :accessor geometry-left
151 :initarg :left
152 :initform nil)
153 (geometry-right :accessor geometry-right
154 :initarg :right
155 :initform nil)
156 (geometry-top :accessor geometry-top
157 :initarg :top
158 :initform nil)
159 (geometry-bottom :accessor geometry-bottom
160 :initarg :bottom
161 :initform nil)
162 (geometry-width :accessor geometry-width
163 :initarg :width
164 :initform nil)
165 (geometry-height :accessor geometry-height
166 :initarg :height
167 :initform nil)))
168
169 (defmethod frame-geometry* ((frame standard-application-frame))
170 "-> width height &optional top left"
171 (let ((pane (frame-top-level-sheet frame)))
172 ;(destructuring-bind (&key left top right bottom width height) (frame-geometry frame)
173 (with-slots (geometry-left geometry-top geometry-right
174 geometry-bottom geometry-width
175 geometry-height) frame
176 ;; Find width and height from looking at the respective options
177 ;; first, then at left/right and top/bottom and finally at what
178 ;; compose-space says.
179 (let* ((width (or geometry-width
180 (and geometry-left geometry-right
181 (- geometry-right geometry-left))
182 (space-requirement-width (compose-space pane))))
183 (height (or geometry-height
184 (and geometry-top geometry-bottom (- geometry-bottom geometry-top))
185 (space-requirement-height (compose-space pane))))
186 ;; See if a position is wanted and return left, top.
187 (left (or geometry-left
188 (and geometry-right (- geometry-right geometry-width))))
189 (top (or geometry-top
190 (and geometry-bottom (- geometry-bottom geometry-height)))))
191 (values width height left top)))))
192
193 ;;; Support the :input-buffer initarg for compatibility with "real CLIM"
194
195 (defmethod initialize-instance :after ((obj standard-application-frame)
196 &key &allow-other-keys)
197 (when (and (frame-calling-frame obj)
198 (null (frame-event-queue obj)))
199 (setf (frame-event-queue obj)
200 (frame-event-queue (frame-calling-frame obj))))
201 (unless (frame-event-queue obj)
202 (setf (frame-event-queue obj)
203 (make-instance 'port-event-queue))))
204
205 (defmethod (setf frame-manager) (fm (frame application-frame))
206 (let ((old-manager (frame-manager frame)))
207 (setf (%frame-manager frame) nil)
208 (when old-manager
209 (disown-frame old-manager frame)
210 (setf (slot-value frame 'panes) nil)
211 (setf (slot-value frame 'layouts) nil))
212 (setf (%frame-manager frame) fm)))
213
214 (define-condition frame-layout-changed (condition)
215 ((frame :initarg :frame :reader frame-layout-changed-frame)))
216
217 (defmethod (setf frame-current-layout) :after (name (frame application-frame))
218 (declare (ignore name))
219 (when (frame-manager frame)
220 (generate-panes (frame-manager frame) frame)
221 (multiple-value-bind (w h) (frame-geometry* frame)
222 (layout-frame frame w h))
223 (signal 'frame-layout-changed :frame frame)))
224
225 (defmethod generate-panes :before (fm (frame application-frame))
226 (declare (ignore fm))
227 (when (and (frame-panes frame)
228 (eq (sheet-parent (frame-panes frame))
229 (frame-top-level-sheet frame)))
230 (sheet-disown-child (frame-top-level-sheet frame) (frame-panes frame)))
231 (loop
232 for (nil . pane) in (frame-panes-for-layout frame)
233 for parent = (sheet-parent pane)
234 if parent
235 do (sheet-disown-child parent pane)))
236
237 (defmethod generate-panes :after (fm (frame application-frame))
238 (declare (ignore fm))
239 (sheet-adopt-child (frame-top-level-sheet frame) (frame-panes frame))
240 (unless (sheet-parent (frame-top-level-sheet frame))
241 (sheet-adopt-child (graft frame) (frame-top-level-sheet frame)))
242 ;; Find the size of the new frame
243 (multiple-value-bind (w h x y) (frame-geometry* frame)
244 (declare (ignore x y))
245 ;; automatically generates a window-configuation-event
246 ;; which then calls allocate-space
247 ;;
248 ;; Not any longer, we turn off CONFIGURE-NOTIFY events until the
249 ;; window is mapped and do the space allocation now, so that all
250 ;; sheets will have their correct geometry at once. --GB
251 (setf (sheet-region (frame-top-level-sheet frame))
252 (make-bounding-rectangle 0 0 w h))
253 (allocate-space (frame-top-level-sheet frame) w h) ))
254
255 (defmethod layout-frame ((frame application-frame) &optional width height)
256 (let ((pane (frame-panes frame)))
257 (when (and (or width height)
258 (not (and width height)))
259 (error "LAYOUT-FRAME must be called with both WIDTH and HEIGHT or neither"))
260 (if (and (null width) (null height))
261 (let ((space (compose-space pane))) ;I guess, this might be wrong. --GB 2004-06-01
262 (setq width (space-requirement-width space))
263 (setq height (space-requirement-height space))))
264 (let ((tpl-sheet (frame-top-level-sheet frame)))
265 (unless (and (= width (bounding-rectangle-width tpl-sheet))
266 (= height (bounding-rectangle-height tpl-sheet)))
267 (resize-sheet (frame-top-level-sheet frame) width height)))
268 (allocate-space pane width height)))
269
270 (defun find-pane-if (predicate panes)
271 "Returns a pane satisfying PREDICATE in the forest growing from PANES"
272 (map-over-sheets #'(lambda (p)
273 (when (funcall predicate p)
274 (return-from find-pane-if p)))
275 panes)
276 nil)
277
278 (defun find-pane-of-type (panes type)
279 (find-pane-if #'(lambda (pane) (typep pane type)) panes))
280
281 ;;; There are several ways to do this; this isn't particularly efficient, but
282 ;;; it shouldn't matter much. If it does, it might be better to map over the
283 ;;; panes in frame-named-panes looking for panes with parents.
284 (defmethod frame-current-panes ((frame application-frame))
285 (let ((panes nil)
286 (named-panes (frame-named-panes frame)))
287 (map-over-sheets #'(lambda (p)
288 (when (member p named-panes)
289 (push p panes)))
290 (frame-panes frame))
291 panes))
292
293 (defmethod get-frame-pane ((frame application-frame) pane-name)
294 (let ((pane (find-pane-named frame pane-name)))
295 (if (typep pane 'clim-stream-pane)
296 pane
297 nil)))
298
299 (defmethod find-pane-named ((frame application-frame) pane-name)
300 (find pane-name (frame-named-panes frame) :key #'pane-name))
301
302 (defmethod frame-standard-output ((frame application-frame))
303 (or (find-pane-of-type (frame-panes frame) 'application-pane)
304 (find-pane-of-type (frame-panes frame) 'interactor-pane)))
305
306 (defmethod frame-standard-input ((frame application-frame))
307 (or (find-pane-of-type (frame-panes frame) 'interactor-pane)
308 (frame-standard-output frame)))
309
310 (defmethod frame-query-io ((frame application-frame))
311 (or (frame-standard-input frame)
312 (frame-standard-output frame)))
313
314 (defmethod frame-error-output ((frame application-frame))
315 (frame-standard-output frame))
316
317 (defvar *pointer-documentation-output* nil)
318
319 (defmethod frame-pointer-documentation-output ((frame application-frame))
320 (find-pane-of-type (frame-panes frame) 'pointer-documentation-pane))
321
322 #+nil
323 (defmethod redisplay-frame-panes ((frame application-frame) &key force-p)
324 (map-over-sheets
325 (lambda (sheet)
326 (when (typep sheet 'pane)
327 (when (and (typep sheet 'clim-stream-pane)
328 (not (eq :no-clear (pane-redisplay-needed sheet))))
329 (window-clear sheet))
330 (redisplay-frame-pane frame sheet :force-p force-p)))
331 (frame-top-level-sheet frame)))
332
333 (defmethod redisplay-frame-panes ((frame application-frame) &key force-p)
334 (map-over-sheets (lambda (sheet)
335 (redisplay-frame-pane frame sheet :force-p force-p))
336 (frame-top-level-sheet frame)))
337
338
339 (defmethod frame-replay (frame stream &optional region)
340 (declare (ignore frame))
341 (stream-replay stream region))
342
343 (defmethod frame-properties ((frame application-frame) property)
344 (getf (%frame-properties frame) property))
345
346 (defmethod (setf frame-properties) (value (frame application-frame) property)
347 (setf (getf (%frame-properties frame) property) value))
348
349 ;;; Command loop interface
350
351 (define-condition frame-exit (condition)
352 ((frame :initarg :frame :reader %frame-exit-frame)))
353
354 ;; I make the assumption here that the contents of *application-frame* is
355 ;; the frame the top-level loop is running. With the introduction of
356 ;; window-stream frames that may be sharing the event queue with the main
357 ;; application frame, we need to discriminate between them here to avoid
358 ;; shutting down the application at the wrong time.
359 ;; ...
360 ;; A better way to do this would be to make the handler bound in
361 ;; run-frame-top-level check whether the frame signalled is the one
362 ;; it was invoked on.. -- Hefner
363
364 (defmethod frame-exit ((frame standard-application-frame))
365 (if (eq *application-frame* frame)
366 (signal 'frame-exit :frame frame)
367 (disown-frame (frame-manager frame) frame)))
368
369 (defmethod frame-exit-frame ((c frame-exit))
370 (%frame-exit-frame c))
371
372 (defmethod redisplay-frame-pane ((frame application-frame) pane &key force-p)
373 (declare (ignore pane force-p))
374 nil)
375
376 (defgeneric medium-invoke-with-possible-double-buffering (frame pane medium continuation))
377
378 (defmethod medium-invoke-with-possible-double-buffering (frame pane medium continuation)
379 (funcall continuation))
380
381 (defgeneric invoke-with-possible-double-buffering (frame pane continuation))
382
383 (defmethod invoke-with-possible-double-buffering (frame pane continuation)
384 (declare (ignore frame pane))
385 (funcall continuation))
386
387 (defmethod invoke-with-possible-double-buffering (frame (pane sheet-with-medium-mixin) continuation)
388 (medium-invoke-with-possible-double-buffering frame pane (sheet-medium pane) continuation))
389
390 (defmacro with-possible-double-buffering ((frame pane) &body body)
391 `(invoke-with-possible-double-buffering ,frame ,pane (lambda () ,@body)))
392
393 (defmethod redisplay-frame-pane :around ((frame application-frame) pane
394 &key force-p)
395 (let ((pane-object (if (typep pane 'pane)
396 pane
397 (find-pane-named frame pane))))
398 (multiple-value-bind (redisplayp clearp)
399 (pane-needs-redisplay pane-object)
400 (when force-p
401 (setq redisplayp (or redisplayp t)
402 clearp t))
403 (when redisplayp
404 (let ((hilited (frame-hilited-presentation frame)))
405 (when hilited
406 (highlight-presentation-1 (car hilited) (cdr hilited) :unhighlight)
407 (setf (frame-hilited-presentation frame) nil)))
408 (with-possible-double-buffering (frame pane-object)
409 (when clearp
410 (window-clear pane-object))
411 (call-next-method))
412 (unless (or (eq redisplayp :command-loop) (eq redisplayp :no-clear))
413 (setf (pane-needs-redisplay pane-object) nil))))))
414
415 (defmethod run-frame-top-level ((frame application-frame)
416 &key &allow-other-keys)
417 (letf (((frame-process frame) (current-process)))
418 (handler-case
419 (funcall (frame-top-level-lambda frame) frame)
420 (frame-exit ()
421 nil))))
422
423
424 (defmethod run-frame-top-level :around ((frame application-frame) &key)
425 (let ((*application-frame* frame)
426 (*input-context* nil)
427 (*input-wait-test* nil)
428 (*input-wait-handler* nil)
429 (*pointer-button-press-handler* nil)
430 (original-state (frame-state frame)))
431 (declare (special *input-context* *input-wait-test* *input-wait-handler*
432 *pointer-button-press-handler*))
433 (when (eq (frame-state frame) :disowned) ; Adopt frame into frame manager
434 (adopt-frame (or (frame-manager frame) (find-frame-manager))
435 frame))
436 (unless (or (eq (frame-state frame) :enabled)
437 (eq (frame-state frame) :shrunk))
438 (enable-frame frame))
439 (unwind-protect
440 (loop
441 for query-io = (frame-query-io frame)
442 for *default-frame-manager* = (frame-manager frame)
443 do (handler-case
444 (return (if query-io
445 (with-input-focus (query-io)
446 (call-next-method))
447 (call-next-method)))
448 (frame-layout-changed () nil)))
449 (let ((fm (frame-manager frame)))
450 (case original-state
451 (:disabled
452 (disable-frame frame))
453 (:disowned
454 (disown-frame fm frame)))))))
455
456 (defparameter +default-prompt-style+ (make-text-style :fix :italic :normal))
457
458 (defmethod default-frame-top-level
459 ((frame application-frame)
460 &key (command-parser 'command-line-command-parser)
461 (command-unparser 'command-line-command-unparser)
462 (partial-command-parser
463 'command-line-read-remaining-arguments-for-partial-command)
464 (prompt "Command: "))
465 ;; Give each pane a fresh start first time through.
466 (let ((first-time t))
467 (loop
468 ;; The variables are rebound each time through the loop because the
469 ;; values of frame-standard-input et al. might be changed by a command.
470 (let* ((*standard-input* (or (frame-standard-input frame)
471 *standard-input*))
472 (*standard-output* (or (frame-standard-output frame)
473 *standard-output*))
474 (query-io (frame-query-io frame))
475 (*query-io* (or query-io *query-io*))
476 (*pointer-documentation-output*
477 (frame-pointer-documentation-output frame))
478 ;; during development, don't alter *error-output*
479 ;; (*error-output* (frame-error-output frame))
480 (*command-parser* command-parser)
481 (*command-unparser* command-unparser)
482 (*partial-command-parser* partial-command-parser)
483 (interactorp (typep *query-io* 'interactor-pane)))
484 (restart-case
485 (progn
486 (redisplay-frame-panes frame :force-p first-time)
487 (setq first-time nil)
488 (if query-io
489 ;; For frames with an interactor:
490 (progn
491 ;; Hide cursor, so we don't need to toggle it during
492 ;; command output.
493 (setf (cursor-visibility (stream-text-cursor *query-io*))
494 nil)
495 (when (and prompt interactorp)
496 (with-text-style (*query-io* +default-prompt-style+)
497 (if (stringp prompt)
498 (write-string prompt *query-io*)
499 (funcall prompt *query-io* frame))
500 (finish-output *query-io*)))
501 (let ((command (read-frame-command frame
502 :stream *query-io*)))
503 (when interactorp
504 (fresh-line *query-io*))
505 (when command
506 (execute-frame-command frame command))
507 (when interactorp
508 (fresh-line *query-io*))))
509 ;; Frames without an interactor:
510 (let ((command (read-frame-command frame :stream nil)))
511 (when command (execute-frame-command frame command)))))
512 (abort ()
513 :report "Return to application command loop"
514 (if interactorp
515 (format *query-io* "~&Command aborted.~&")
516 (beep))))))))
517
518 (defmethod read-frame-command :around ((frame application-frame)
519 &key (stream *standard-input*))
520 (with-input-context ('menu-item)
521 (object)
522 (call-next-method)
523 (menu-item
524 (let ((command (command-menu-item-value object))
525 (table (frame-command-table frame)))
526 (unless (listp command)
527 (setq command (partial-command-from-name command table)))
528 (if (and (typep stream 'interactor-pane)
529 (partial-command-p command))
530 (command-line-read-remaining-arguments-for-partial-command
531 table stream command 0)
532 command)))))
533
534 (defmethod read-frame-command ((frame application-frame)
535 &key (stream *standard-input*))
536 ;; The following is the correct interpretation according to the spec.
537 ;; I think it is terribly counterintuitive and want to look into
538 ;; what existing CLIMs do before giving in to it.
539 ;; If we do things as the spec says, command accelerators will
540 ;; appear to not work, confusing new users.
541 #+NIL (read-command (frame-command-table frame) :use-keystrokes nil :stream stream)
542 (if stream
543 (read-command (frame-command-table frame) :use-keystrokes t :stream stream)
544 (simple-event-loop frame)))
545
546 (define-event-class execute-command-event (window-manager-event)
547 ((sheet :initarg :sheet :reader event-sheet)
548 (command :initarg :command :reader execute-command-event-command)))
549
550 (defmethod execute-frame-command ((frame application-frame) command)
551 ;; ### FIXME: I'd like a different method than checking for
552 ;; *application-frame* to decide, which process processes which
553 ;; frames command loop. Perhaps looking ath the process slot?
554 ;; --GB 2005-11-28
555 (cond ((eq *application-frame* frame)
556 (apply (command-name command) (command-arguments command)))
557 (t
558 (let ((eq (sheet-event-queue (frame-top-level-sheet frame))))
559 (event-queue-append eq (make-instance 'execute-command-event
560 :sheet frame
561 :command command))))))
562
563 (defmethod handle-event ((frame application-frame) (event execute-command-event))
564 (execute-frame-command frame (execute-command-event-command event)))
565
566 (defmethod command-enabled (command-name (frame standard-application-frame))
567 (and (command-accessible-in-command-table-p command-name
568 (frame-command-table frame))
569 (not (member command-name (disabled-commands frame)))))
570
571 (defmethod (setf command-enabled)
572 (enabled command-name (frame standard-application-frame))
573 (unless (command-accessible-in-command-table-p command-name
574 (frame-command-table frame))
575 (return-from command-enabled nil))
576 (with-accessors ((disabled-commands disabled-commands))
577 frame
578 (if enabled
579 (progn
580 (setf disabled-commands (delete command-name disabled-commands))
581 (note-command-enabled (frame-manager frame)
582 frame
583 command-name)
584 enabled)
585 (progn
586 (pushnew command-name disabled-commands)
587 (note-command-disabled (frame-manager frame)
588 frame
589 command-name)
590 nil))))
591
592 (defmethod make-pane-1 :around (fm (frame standard-application-frame) type
593 &rest args
594 &key (input-buffer nil input-buffer-p)
595 (name nil namep)
596 &allow-other-keys)
597 (declare (ignore name input-buffer))
598 "Default input-buffer to the frame event queue."
599 (let ((pane (if input-buffer-p
600 (call-next-method)
601 (apply #'call-next-method fm frame type
602 :input-buffer (frame-event-queue frame)
603 args))))
604 (when namep
605 (push pane (frame-named-panes frame)))
606 pane))
607
608 (defmethod adopt-frame ((fm frame-manager) (frame application-frame))
609 (setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
610 (setf (frame-manager frame) fm)
611 (setf (port frame) (frame-manager-port fm))
612 (setf (graft frame) (find-graft :port (port frame)))
613 (let* ((*application-frame* frame)
614 (t-l-s (make-pane-1 fm frame 'top-level-sheet-pane
615 :name 'top-level-sheet
616 ;; enabling should be left to enable-frame
617 :enabled-p nil))
618 #+clim-mp (event-queue (sheet-event-queue t-l-s)))
619 (setf (slot-value frame 'top-level-sheet) t-l-s)
620 (generate-panes fm frame)
621 (setf (slot-value frame 'state) :disabled)
622 #+clim-mp
623 (when (typep event-queue 'port-event-queue)
624 (setf (event-queue-port event-queue)
625 (frame-manager-port fm)))
626 frame))
627
628 (defmethod disown-frame ((fm frame-manager) (frame application-frame))
629 #+CLIM-MP
630 (let* ((t-l-s (frame-top-level-sheet frame))
631 (queue (sheet-event-queue t-l-s)))
632 (when (typep queue 'port-event-queue)
633 (setf (event-queue-port queue) nil)))
634 (setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
635 (sheet-disown-child (graft frame) (frame-top-level-sheet frame))
636 (setf (%frame-manager frame) nil)
637 (setf (slot-value frame 'state) :disowned)
638 (port-force-output (frame-manager-port fm))
639 frame)
640
641 (defmethod enable-frame ((frame application-frame))
642 (setf (sheet-enabled-p (frame-top-level-sheet frame)) t)
643 (setf (slot-value frame 'state) :enabled)
644 (note-frame-enabled (frame-manager frame) frame))
645
646 (defmethod disable-frame ((frame application-frame))
647 (let ((t-l-s (frame-top-level-sheet frame)))
648 (setf (sheet-enabled-p t-l-s) nil)
649 (when (port t-l-s)
650 (port-force-output (port t-l-s))))
651 (setf (slot-value frame 'state) :disabled)
652 (note-frame-disabled (frame-manager frame) frame))
653
654 (defmethod destroy-frame ((frame application-frame))
655 (when (eq (frame-state frame) :enabled)
656 (disable-frame frame))
657 (disown-frame (frame-manager frame) frame))
658
659 (defmethod raise-frame ((frame application-frame))
660 (raise-sheet (frame-top-level-sheet frame)))
661
662 (defmethod bury-frame ((frame application-frame))
663 (bury-sheet (frame-top-level-sheet frame)))
664
665 (defmethod note-frame-enabled ((fm frame-manager) frame)
666 (declare (ignore frame))
667 t)
668
669 (defmethod note-frame-disabled ((fm frame-manager) frame)
670 (declare (ignore frame))
671 t)
672
673 (defun map-over-frames (function &key port frame-manager)
674 (cond (frame-manager
675 (mapc function (frame-manager-frames frame-manager)))
676 (port
677 (loop for manager in (frame-managers port)
678 do (map-over-frames function :frame-manager manager)))
679 (t (loop for p in *all-ports*
680 do (map-over-frames function :port p)))))
681
682 (defvar *pane-realizer* nil)
683
684 (defmacro with-look-and-feel-realization ((frame-manager frame) &body body)
685 `(let ((*pane-realizer* ,frame-manager)
686 (*application-frame* ,frame))
687 (locally
688 ,@body)))
689
690 ; The menu-bar code in the following two functions is incorrect.
691 ; it needs to be moved to somewhere after the backend, since
692 ; it depends on the backend chosen.
693 ;
694 ; This hack slaps a menu-bar into the start of the application-frame,
695 ; in such a way that it is hard to find.
696 ;
697 ; FIXME
698 (defun make-single-pane-generate-panes-form (class-name menu-bar pane)
699 `(progn
700 (defmethod generate-panes ((fm frame-manager) (frame ,class-name))
701 ;; v-- hey, how can this be?
702 (with-look-and-feel-realization (fm frame)
703 (let ((pane ,(cond
704 ((eq menu-bar t)
705 `(vertically () (clim-internals::make-menu-bar
706 ',class-name)
707 ,pane))
708 ((consp menu-bar)
709 `(vertically () (clim-internals::make-menu-bar
710 (make-command-table nil
711 :menu ',menu-bar))
712 ,pane))
713 (menu-bar
714 `(vertically () (clim-internals::make-menu-bar
715 ',menu-bar)
716 ,pane))
717 ;; The form below is unreachable with (listp
718 ;; menu-bar) instead of (consp menu-bar) above
719 ;; --GB
720 (t pane))))
721 (setf (slot-value frame 'panes) pane))))
722 (defmethod frame-all-layouts ((frame ,class-name))
723 nil)))
724
725 (defun find-pane-for-layout (name frame)
726 (cdr (assoc name (frame-panes-for-layout frame) :test #'eq)))
727
728 (defun save-pane-for-layout (name pane frame)
729 (push (cons name pane) (frame-panes-for-layout frame))
730 pane)
731
732 (defun coerce-pane-name (pane name)
733 (when pane
734 (setf (slot-value pane 'name) name)
735 (push pane (frame-named-panes (pane-frame pane))))
736 pane)
737
738 (defun do-pane-creation-form (name form)
739 (cond
740 ((and (= (length form) 1)
741 (listp (first form)))
742 `(coerce-pane-name ,(first form) ',name))
743 ((keywordp (first form))
744 (let ((maker (intern (concatenate 'string
745 (symbol-name '#:make-clim-)
746 (symbol-name (first form))
747 (symbol-name '#:-pane))
748 :clim)))
749 (if (fboundp maker)
750 `(,maker :name ',name ,@(cdr form))
751 `(make-pane ',(first form)
752 :name ',name ,@(cdr form)))))
753 (t `(make-pane ',(first form) :name ',name ,@(cdr form)))))
754
755 (defun make-panes-generate-panes-form (class-name menu-bar panes layouts
756 pointer-documentation)
757 (when pointer-documentation
758 (setf panes (append panes
759 '((%pointer-documentation%
760 pointer-documentation-pane)))))
761 `(progn
762 (defmethod generate-panes ((fm frame-manager) (frame ,class-name))
763 (let ((*application-frame* frame))
764 (with-look-and-feel-realization (fm frame)
765 (let ,(loop
766 for (name . form) in panes
767 collect `(,name (or (find-pane-for-layout ',name frame)
768 (save-pane-for-layout
769 ',name
770 ,(do-pane-creation-form name form)
771 frame))))
772 ;; [BTS] added this, but is not sure that this is correct for
773 ;; adding a menu-bar transparently, should also only be done
774 ;; where the exterior window system does not support menus
775 ,(if (or menu-bar pointer-documentation)
776 `(setf (slot-value frame 'panes)
777 (ecase (frame-current-layout frame)
778 ,@(mapcar (lambda (layout)
779 `(,(first layout)
780 (vertically ()
781 ,@(cond
782 ((eq menu-bar t)
783 `((clim-internals::make-menu-bar
784 ',class-name)))
785 ((consp menu-bar)
786 `((clim-internals::make-menu-bar
787 (make-command-table
788 nil
789 :menu ',menu-bar))))
790 (menu-bar
791 `((clim-internals::make-menu-bar
792 ',menu-bar)))
793 (t nil))
794 ,@(rest layout)
795 ,@(when pointer-documentation
796 '(%pointer-documentation%)))))
797 layouts)))
798 `(setf (slot-value frame 'panes)
799 (ecase (frame-current-layout frame)
800 ,@layouts)))))))
801 (defmethod frame-all-layouts ((frame ,class-name))
802 ',(mapcar #'car layouts))))
803
804 (defmacro define-application-frame (name superclasses slots &rest options)
805 (if (null superclasses)
806 (setq superclasses '(standard-application-frame)))
807 (let ((pane nil)
808 (panes nil)
809 (layouts nil)
810 (current-layout nil)
811 (command-table (list name))
812 (menu-bar t)
813 (disabled-commands nil)
814 (command-definer t)
815 (top-level '(default-frame-top-level))
816 (others nil)
817 (pointer-documentation nil)
818 (geometry nil)
819 (user-default-initargs nil)
820 (frame-arg (gensym "FRAME-ARG")))
821 (loop for (prop . values) in options
822 do (case prop
823 (:pane (setq pane (first values)))
824 (:panes (setq panes values))
825 (:layouts (setq layouts values))
826 (:command-table (setq command-table (first values)))
827 (:menu-bar (setq menu-bar (if (listp values)
828 (first values)
829 values)))
830 (:disabled-commands (setq disabled-commands values))
831 (:command-definer (setq command-definer (first values)))
832 (:top-level (setq top-level (first values)))
833 (:pointer-documentation (setq pointer-documentation (car values)))
834 (:geometry (setq geometry values))
835 (:default-initargs (setq user-default-initargs values))
836 (t (push (cons prop values) others))))
837 (when (eq command-definer t)
838 (setf command-definer
839 (intern (concatenate 'string
840 (symbol-name '#:define-)
841 (symbol-name name)
842 (symbol-name '#:-command)))))
843 (if (or (and pane panes)
844 (and pane layouts))
845 (error ":pane cannot be specified along with either :panes or :layouts"))
846 (if pane
847 (setq panes (list 'single-pane pane)
848 layouts `((:default ,(car pane)))))
849 (setq current-layout (first (first layouts)))
850 `(progn
851 (defclass ,name ,superclasses
852 ,slots
853 (:default-initargs
854 :name ',name
855 :pretty-name ,(string-capitalize name)
856 :command-table (find-command-table ',(first command-table))
857 :disabled-commands ',disabled-commands
858 :menu-bar ',menu-bar
859 :current-layout ',current-layout
860 :layouts ',layouts
861 :top-level (list ',(car top-level) ,@(cdr top-level))
862 :top-level-lambda (lambda (,frame-arg)
863 (,(car top-level) ,frame-arg
864 ,@(cdr top-level)))
865 ,@geometry
866 ,@user-default-initargs)
867 ,@others)
868 ,(if pane
869 (make-single-pane-generate-panes-form name menu-bar pane)
870 (make-panes-generate-panes-form name menu-bar panes layouts
871 pointer-documentation))
872 ,@(if command-table
873 `((define-command-table ,@command-table)))
874 ,@(if command-definer
875 `((defmacro ,command-definer (name-and-options arguments &rest body)
876 (let ((name (if (listp name-and-options) (first name-and-options) name-and-options))
877 (options (if (listp name-and-options) (cdr name-and-options) nil))
878 (command-table ',(first command-table)))
879 `(define-command (,name :command-table ,command-table ,@options) ,arguments ,@body))))))))
880
881 (defun make-application-frame (frame-name
882 &rest options
883 &key (pretty-name
884 (string-capitalize frame-name))
885 (frame-manager nil frame-manager-p)
886 enable
887 (state nil state-supplied-p)
888 save-under (frame-class frame-name)
889 &allow-other-keys)
890 (declare (ignore save-under))
891 (with-keywords-removed (options (:pretty-name :frame-manager :enable :state
892 :save-under :frame-class))
893 (let ((frame (apply #'make-instance frame-class
894 :name frame-name
895 :pretty-name pretty-name
896 options)))
897 (when frame-manager-p
898 (adopt-frame frame-manager frame))
899 (cond ((or enable (eq state :enabled))
900 (enable-frame frame))
901 ((and (eq state :disowned)
902 (not (eq (frame-state frame) :disowned)))
903 (disown-frame (frame-manager frame) frame))
904 (state-supplied-p
905 (warn ":state ~S not supported yet." state)))
906 frame)))
907
908 ;;; From Franz Users Guide
909
910 (defun find-application-frame (frame-name &rest initargs
911 &key (create t) (activate t)
912 (own-process *multiprocessing-p*) port
913 frame-manager frame-class
914 &allow-other-keys)
915 (declare (ignorable frame-class))
916 (let ((frame (unless (eq create :force)
917 (block
918 found-frame
919 (map-over-frames
920 #'(lambda (frame)
921 (when (eq (frame-name frame) frame-name)
922 (return-from found-frame frame)))
923 :port port
924 :frame-manager frame-manager)))))
925 (unless (or frame create)
926 (return-from find-application-frame nil))
927 (unless frame
928 (with-keywords-removed (initargs (:create :activate :own-process))
929 (setq frame (apply #'make-application-frame frame-name initargs))))
930 (when (and frame activate)
931 (cond ((frame-process frame)
932 (raise-frame frame))
933 (own-process
934 (clim-sys:make-process #'(lambda ()
935 (run-frame-top-level frame))
936 :name (format nil "~A" frame-name)))
937 (t (run-frame-top-level frame))))
938 frame))
939
940
941
942 ;;; Menu frame class
943
944 (defclass menu-frame ()
945 ((left :initform 0 :initarg :left)
946 (top :initform 0 :initarg :top)
947 (min-width :initform nil :initarg :min-width)
948 (top-level-sheet :initform nil :reader frame-top-level-sheet)
949 (panes :reader frame-panes :initarg :panes)
950 (graft :initform nil :accessor graft)
951 (manager :initform nil :accessor frame-manager)))
952
953 (defclass menu-unmanaged-top-level-sheet-pane (unmanaged-top-level-sheet-pane)
954 ())
955
956 (defmethod adopt-frame ((fm frame-manager) (frame menu-frame))
957 (setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
958 (setf (frame-manager frame) fm)
959 (let* ((t-l-s (make-pane-1 fm *application-frame*
960 'menu-unmanaged-top-level-sheet-pane
961 :name 'top-level-sheet)))
962 (setf (slot-value frame 'top-level-sheet) t-l-s)
963 (sheet-adopt-child t-l-s (frame-panes frame))
964 (let ((graft (find-graft :port (frame-manager-port fm))))
965 (sheet-adopt-child graft t-l-s)
966 (setf (graft frame) graft))
967 (let ((pre-space (compose-space t-l-s))
968 (frame-min-width (slot-value frame 'min-width)))
969 (multiple-value-bind (width min-width max-width height min-height max-height)
970 (space-requirement-components pre-space)
971 (flet ((foomax (x y) (max (or x 1) (or y 1))))
972 (let ((space (make-space-requirement :min-width (foomax frame-min-width min-width)
973 :width (foomax frame-min-width width)
974 :max-width (foomax frame-min-width max-width)
975 :min-height min-height
976 :height height
977 :max-height max-height)))
978 (allocate-space (frame-panes frame)
979 (space-requirement-width space)
980 (space-requirement-height space))
981 (setf (sheet-region t-l-s)
982 (make-bounding-rectangle 0 0
983 (space-requirement-width space)
984 (space-requirement-height space))))
985 (setf (sheet-transformation t-l-s)
986 (make-translation-transformation (slot-value frame 'left)
987 (slot-value frame 'top))))))))
988
989 (defmethod disown-frame ((fm frame-manager) (frame menu-frame))
990 (setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
991 (sheet-disown-child (graft frame) (frame-top-level-sheet frame))
992 (setf (frame-manager frame) nil))
993
994 (defun make-menu-frame (pane &key (left 0) (top 0) (min-width 1))
995 (make-instance 'menu-frame :panes pane :left left :top top :min-width min-width))
996
997 ;;; Frames and presentations
998 (defmethod frame-maintain-presentation-histories
999 ((frame standard-application-frame))
1000 (if (find-pane-of-type (frame-panes frame) 'interactor-pane)
1001 t
1002 nil))
1003
1004 (defmethod frame-find-innermost-applicable-presentation
1005 ((frame standard-application-frame) input-context stream x y
1006 &key event)
1007 (find-innermost-applicable-presentation input-context stream
1008 x y
1009 :frame frame :event event))
1010
1011 (defmethod frame-input-context-button-press-handler
1012 ((frame standard-application-frame)
1013 (stream output-recording-stream)
1014 button-press-event)
1015 (let ((presentation (find-innermost-applicable-presentation
1016 *input-context*
1017 stream
1018 (pointer-event-x button-press-event)
1019 (pointer-event-y button-press-event)
1020 :frame frame
1021 :event button-press-event)))
1022 (when presentation
1023 (throw-highlighted-presentation presentation
1024 *input-context*
1025 button-press-event))))
1026
1027 (defmethod frame-input-context-button-press-handler
1028 ((frame standard-application-frame) stream button-press-event)
1029 (declare (ignore stream button-press-event))
1030 nil)
1031
1032 (defgeneric frame-update-pointer-documentation
1033 (frame input-context stream event))
1034
1035 (defconstant +button-documentation+ '((#.+pointer-left-button+ "L")
1036 (#.+pointer-middle-button+ "M")
1037 (#.+pointer-right-button+ "R")
1038 (#.+pointer-wheel-up+ "WheelUp")
1039 (#.+pointer-wheel-down+ "WheelDown")))
1040
1041 (defconstant +modifier-documentation+
1042 '((#.+shift-key+ "sh" "Shift")
1043 (#.+control-key+ "c" "Control")
1044 (#.+meta-key+ "m" "Meta")
1045 (#.+super-key+ "s" "Super")
1046 (#.+hyper-key+ "h" "Hyper")))
1047
1048 ;;; Give a coherent order to sets of modifier combinations. Multi-key combos
1049 ;;; come after single keys.
1050
1051 (defun cmp-modifiers (a b)
1052 (let ((cnt-a (logcount a))
1053 (cnt-b (logcount b)))
1054 (cond ((eql cnt-a cnt-b)
1055 (< a b))
1056 (t (< cnt-a cnt-b)))))
1057
1058 (defun print-modifiers (stream modifiers style)
1059 (if (zerop modifiers)
1060 (when (eq style :long)
1061 (write-string "<nothing>" stream))
1062 (loop with trailing = nil
1063 for (bit short long) in +modifier-documentation+
1064 when (logtest bit modifiers)
1065 do (progn
1066 (format stream "~:[~;-~]~A" trailing (if (eq style :short)
1067 short
1068 long))
1069 (setq trailing t)))))
1070
1071 ;;; XXX Warning: Changing rapidly!
1072 ;;;
1073 ;;; We don't actually want to print out the translator documentation and redraw
1074 ;;; the pointer documentation window on every motion event. So, we compute a
1075 ;;; state object (basically modifier state and a list of the applicable
1076 ;;; presentation, translator and input context on each mouse button),
1077 ;;; compare it to the previous state object, and only write out documentation
1078 ;;; if they are different. I suppose it's possible that this state object
1079 ;;; doesn't capture all possible documentation changes -- the doc generator is
1080 ;;; a function, after all -- but that's just tough.
1081 ;;;
1082 ;;; It would be nice to evolve this into a protocol so that elements other than
1083 ;;; presentations -- menu choices, for example -- could influence pointer
1084 ;;; documentation window.
1085
1086 (defgeneric frame-compute-pointer-documentation-state
1087 (frame input-context stream event)
1088 (:documentation
1089 "Compute a state object that will be used to generate pointer documentation."))
1090
1091 (defmethod frame-compute-pointer-documentation-state
1092 ((frame standard-application-frame) input-context stream event)
1093 (let* ((current-modifier (event-modifier-state event))
1094 (x (device-event-x event))
1095 (y (device-event-y event))
1096 (new-translators
1097 (loop for (button) in +button-documentation+
1098 for context-list = (multiple-value-list
1099 (find-innermost-presentation-context
1100 input-context
1101 stream
1102 x y
1103 :modifier-state current-modifier
1104 :button button))
1105 when (car context-list)
1106 collect (cons button context-list))))
1107 (list current-modifier new-translators)))
1108
1109 (defgeneric frame-compare-pointer-documentation-state
1110 (frame input-context stream old-state new-state))
1111
1112 (defmethod frame-compare-pointer-documentation-state
1113 ((frame standard-application-frame) input-context stream
1114 old-state new-state)
1115 (declare (ignore input-context stream))
1116 (equal old-state new-state))
1117
1118 (defun record-on-display (stream record)
1119 "Return true if `record' is part of the output history of
1120 `stream', false otherwise."
1121 (labels ((worker (record)
1122 (or (eq record (stream-output-history stream))
1123 (and (not (null (output-record-parent record)))
1124 (worker (output-record-parent record))))))
1125 (worker record)))
1126
1127 (defgeneric frame-print-pointer-documentation
1128 (frame input-context stream state event))
1129
1130 (defmethod frame-print-pointer-documentation
1131 ((frame standard-application-frame) input-context stream state event)
1132 (unless state
1133 (return-from frame-print-pointer-documentation nil))
1134 (destructuring-bind (current-modifier new-translators)
1135 state
1136 (let ((x (device-event-x event))
1137 (y (device-event-y event))
1138 (pstream *pointer-documentation-output*))
1139 (if (null new-translators)
1140 (when (and (background-message pstream)
1141 (not (record-on-display pstream (background-message pstream))))
1142 (cond ((> (get-universal-time)
1143 (+ (background-message-time pstream)
1144 *background-message-minimum-lifetime*))
1145 (setf (background-message pstream) nil))
1146 (t
1147 (setf (output-record-parent (background-message pstream)) nil)
1148 (stream-add-output-record pstream (background-message pstream))
1149 (replay (background-message pstream) pstream))))
1150 (loop for (button presentation translator context)
1151 in new-translators
1152 for name = (cadr (assoc button +button-documentation+))
1153 for first-one = t then nil
1154 do (progn
1155 (unless first-one
1156 (write-string "; " pstream))
1157 (unless (zerop current-modifier)
1158 (print-modifiers pstream current-modifier :short)
1159 (write-string "-" pstream))
1160 (format pstream "~A: " name)
1161 (document-presentation-translator translator
1162 presentation
1163 (input-context-type context)
1164 *application-frame*
1165 event
1166 stream
1167 x y
1168 :stream pstream
1169 :documentation-type
1170 :pointer))
1171 finally (when new-translators
1172 (write-char #\. pstream))))
1173 ;; Wasteful to do this after doing
1174 ;; find-innermost-presentation-context above... look at doing this
1175 ;; first and then doing the innermost test.
1176 (let ((all-translators (find-applicable-translators
1177 (stream-output-history stream)
1178 input-context
1179 *application-frame*
1180 stream
1181 x y
1182 :for-menu t))
1183 (other-modifiers nil))
1184 (loop for (translator) in all-translators
1185 for gesture = (gesture translator)
1186 unless (eq gesture t)
1187 do (loop for (name type modifier) in gesture
1188 unless (eql modifier current-modifier)
1189 do (pushnew modifier other-modifiers)))
1190 (when other-modifiers
1191 (setf other-modifiers (sort other-modifiers #'cmp-modifiers))
1192 (terpri pstream)
1193 (write-string "To see other commands, press " pstream)
1194 (loop for modifier-tail on other-modifiers
1195 for (modifier) = modifier-tail
1196 for count from 0
1197 do (progn
1198 (if (null (cdr modifier-tail))
1199 (progn
1200 (when (> count 1)
1201 (write-char #\, pstream))
1202 (when (> count 0)
1203 (write-string " or " pstream)))
1204 (when (> count 0)
1205 (write-string ", " pstream)))
1206 (print-modifiers pstream modifier :long)))
1207 (write-char #\. pstream))))))
1208
1209 (defmethod frame-update-pointer-documentation
1210 ((frame standard-application-frame) input-context stream event)
1211 (when *pointer-documentation-output*
1212 (with-accessors ((frame-documentation-state frame-documentation-state)
1213 (documentation-record documentation-record))
1214 frame
1215 (setf frame-documentation-state
1216 (frame-compute-pointer-documentation-state frame
1217 input-context
1218 stream
1219 event))
1220 ;; These ugly special bindings work around the fact that the outer
1221 ;; updating-output form closes over its body and allow the inner
1222 ;; form to see the correct, current values of those variables.
1223 (let ((%input-context% input-context)
1224 (%stream% stream)
1225 (%doc-state% frame-documentation-state)
1226 (%event% event))
1227 (declare (special %input-context% %stream% %doc-state% %event&))
1228 (if (and documentation-record
1229 (output-record-parent documentation-record))
1230 (redisplay documentation-record *pointer-documentation-output*)
1231 (progn
1232 (window-clear *pointer-documentation-output*)
1233 (setf documentation-record
1234 (updating-output (*pointer-documentation-output*)
1235 (updating-output (*pointer-documentation-output*
1236 :cache-value %doc-state%
1237 :cache-test #'equal)
1238 (frame-print-pointer-documentation frame
1239 %input-context%
1240 %stream%
1241 %doc-state%
1242 %event%))))))))))
1243
1244 (defgeneric invoke-with-output-to-pointer-documentation (frame continuation)
1245 (:documentation "Invoke `continuation' with a single argument -
1246 a stream that the continuation can write to, the output of which
1247 will be used as the background message of the pointer
1248 documentation pane of `frame'. If the pointer-documentation of
1249 `frame' is not a `pointer-documentation-pane', `continuation'
1250 will not be called."))
1251
1252 (defmethod invoke-with-output-to-pointer-documentation
1253 ((frame standard-application-frame) continuation)
1254 (with-accessors ((pointer-documentation frame-pointer-documentation-output)) frame
1255 (when (typep pointer-documentation 'pointer-documentation-pane)
1256 (setf (background-message pointer-documentation)
1257 (with-output-to-output-record (pointer-documentation)
1258 (funcall continuation pointer-documentation))
1259 (background-message-time pointer-documentation) (get-universal-time)))))
1260
1261 (defmacro with-output-to-pointer-documentation ((stream frame) &body body)
1262 "Bind `stream' to the pointer-documentation pane of `frame' and
1263 capture the output of `body' on `stream' as the background
1264 message of the pointer documentation pane. If `frame' does not
1265 have a `pointer-documentation-pane' as pointer documentation,
1266 `body' will not be evaluated."
1267 `(invoke-with-output-to-pointer-documentation
1268 ,frame #'(lambda (,stream)
1269 ,@body)))
1270
1271 ;;; A hook for applications to draw random strings in the
1272 ;;; *pointer-documentation-output* without screwing up the real pointer
1273 ;;; documentation too badly.
1274
1275 (defun frame-display-pointer-documentation-string (frame string)
1276 (with-output-to-pointer-documentation (stream frame)
1277 (write-string string stream)))
1278
1279 (defmethod frame-input-context-track-pointer
1280 ((frame standard-application-frame)
1281 input-context
1282 (stream output-recording-stream) event)
1283 (declare (ignore input-context event))
1284 nil)
1285
1286 (defmethod frame-input-context-track-pointer
1287 ((frame standard-application-frame) input-context stream event)
1288 (declare (ignore input-context stream event))
1289 nil)
1290
1291 (defun frame-highlight-at-position (frame stream x y modifier input-context
1292 &key (highlight t))
1293 "Given stream x,y; key modifiers; input-context, find the applicable
1294 presentation and maybe highlight it."
1295 (flet ((maybe-unhighlight (presentation)
1296 (when (and (frame-hilited-presentation frame)
1297 (or (not highlight)
1298 (not (eq presentation
1299 (car (frame-hilited-presentation frame))))))
1300 (highlight-presentation-1 (car (frame-hilited-presentation frame))
1301 (cdr (frame-hilited-presentation frame))
1302 :unhighlight)
1303 (setf (frame-hilited-presentation frame) nil))))
1304 (if (output-recording-stream-p stream)
1305 (let ((presentation (find-innermost-applicable-presentation
1306 input-context
1307 stream
1308 x y
1309 :frame frame
1310 :modifier-state modifier)))
1311 (maybe-unhighlight presentation)
1312 (when (and presentation
1313 highlight
1314 (not (eq presentation
1315 (car (frame-hilited-presentation frame)))))
1316 (setf (frame-hilited-presentation frame)
1317 (cons presentation stream))
1318 (highlight-presentation-1 presentation stream :highlight))
1319 presentation)
1320 (progn
1321 (maybe-unhighlight nil)
1322 nil))))
1323
1324 (defmethod frame-input-context-track-pointer :before
1325 ((frame standard-application-frame) input-context
1326 (stream output-recording-stream) event)
1327 (frame-highlight-at-position frame stream
1328 (device-event-x event)
1329 (device-event-y event)
1330 (event-modifier-state event)
1331 input-context)
1332 (frame-update-pointer-documentation frame input-context stream event))
1333
1334 (defun simple-event-loop (&optional (frame *application-frame*))
1335 "An simple event loop for applications that want all events to be handled by
1336 handle-event methods"
1337 (let ((queue (frame-event-queue frame)))
1338 (loop for event = (event-queue-read queue)
1339 ;; EVENT-QUEUE-READ in single-process mode calls PROCESS-NEXT-EVENT itself.
1340 do (handle-event (event-sheet event) event))))
1341
1342 ;;; Am I missing something? Does this need to do more? - moore
1343 (defmacro with-application-frame ((frame) &body body)
1344 `(let ((,frame *application-frame*))
1345 ,@body))
1346
1347 (defmethod note-input-focus-changed (pane state)
1348 (declare (ignore pane state)))
1349
1350 (defmethod (setf client-setting) (value frame setting)
1351 (setf (getf (client-settings frame) setting) value))
1352
1353 (defmethod reset-frame (frame &rest client-settings)
1354 (loop for (setting value) on client-settings by #'cddr
1355 do (setf (client-setting frame setting) value)))
1356
1357 ;;; tracking-pointer stuff related to presentations
1358
1359 (defclass frame-tracking-pointer-state (tracking-pointer-state)
1360 ((presentation-handler :reader presentation-handler :initarg :presentation)
1361 (presentation-button-release-handler
1362 :reader presentation-button-release-handler
1363 :initarg :presentation-button-release)
1364 (presentation-button-press-handler :reader presentation-button-press-handler
1365 :initarg :presentation-button-press)
1366 (applicable-presentation :accessor applicable-presentation :initform nil)
1367 (input-context :reader input-context)
1368 (highlight :reader highlight))
1369 (:default-initargs :presentation nil
1370 :presentation-button-press nil
1371 :presentation-button-release nil
1372 :context-type t))
1373
1374 (defmethod initialize-instance :after
1375 ((obj frame-tracking-pointer-state)
1376 &key presentation presentation-button-press presentation-button-release
1377 (highlight nil highlightp) context-type
1378 multiple-window)
1379 (declare (ignore multiple-window))
1380 (let ((presentation-clauses-p (or presentation
1381 presentation-button-press
1382 presentation-button-release)))
1383 (setf (slot-value obj 'highlight) (if highlightp
1384 highlight
1385 presentation-clauses-p))
1386 (setf (slot-value obj 'input-context)
1387 (if (or presentation-clauses-p highlight)
1388 (make-fake-input-context context-type)
1389 nil))))
1390
1391 (defmethod make-tracking-pointer-state
1392 ((frame standard-application-frame) sheet args)
1393 (declare (ignore sheet))
1394 (apply #'make-instance 'frame-tracking-pointer-state
1395 args))
1396
1397 (defmethod tracking-pointer-loop :before
1398 ((state frame-tracking-pointer-state) frame sheet &rest args)
1399 (declare (ignore args))
1400 (if (highlight state)
1401 (highlight-current-presentation frame (input-context state))
1402 (let ((hilited (frame-hilited-presentation frame)))
1403 (when hilited
1404 (highlight-presentation-1 (car hilited)
1405 (cdr hilited)
1406 :unhighlight)))))
1407
1408 ;;; Poor man's find-applicable-translators. tracking-pointer doesn't want to
1409 ;;; see any results from presentation translators.
1410 ;;;
1411 ;;; XXX I don't see why not (even though I wrote the above comment :) and
1412 ;;; Classic CLIM seems to agree. -- moore
1413 (defun highlight-for-tracking-pointer (frame stream event input-context
1414 highlight)
1415 (let ((presentation nil)
1416 (current-hilited (frame-hilited-presentation frame)))
1417 (when (output-recording-stream-p stream)
1418 ;; XXX Massive hack to prevent the presentation action for completions
1419 ;; from being applicable. After the .9.2.2 release that action will have
1420 ;; a more restrictive context type.
1421 (let ((*completion-possibilities-continuation* nil))
1422 (setq presentation (find-innermost-applicable-presentation
1423 input-context
1424 stream
1425 (device-event-x event)
1426 (device-event-y event)
1427 :frame frame))))
1428 (when (and current-hilited (not (eq (car current-hilited) presentation)))
1429 (highlight-presentation-1 (car current-hilited)
1430 (cdr current-hilited)
1431 :unhighlight))
1432 (when (and presentation highlight)
1433 (setf (frame-hilited-presentation frame) (cons presentation stream))
1434 (highlight-presentation-1 presentation stream :highlight))
1435 presentation))
1436
1437 (defmethod tracking-pointer-loop-step :before
1438 ((state frame-tracking-pointer-state) (event pointer-event) x y)
1439 (declare (ignore x y))
1440 (when (input-context state)
1441 (let ((stream (event-sheet event)))
1442 (setf (applicable-presentation state)
1443 (highlight-for-tracking-pointer *application-frame* stream
1444 event
1445 (input-context state)
1446 (highlight state))))))
1447
1448
1449 (macrolet ((frob (event handler)
1450 `(defmethod tracking-pointer-loop-step
1451 ((state frame-tracking-pointer-state) (event ,event) x y)
1452 (let ((handler (,handler state))
1453 (presentation (applicable-presentation state)))
1454 (if (and handler presentation)
1455 (funcall handler :presentation presentation
1456 :event event
1457 :window (event-sheet event)
1458 :x x :y y)
1459 (call-next-method))))))
1460 (frob pointer-motion-event presentation-handler)
1461 (frob pointer-button-press-event presentation-button-press-handler)
1462 (frob pointer-button-release-event presentation-button-release-handler))
1463
1464 (defun make-drag-bounding (old-highlighting new-highlighting
1465 old-presentation new-presentation)
1466 (let (x1 y1 x2 y2)
1467 (flet ((union-with-bounds (rect)
1468 (cond ((null rect)
1469 nil)
1470 ((null x1)
1471 (setf (values x1 y1 x2 y2) (bounding-rectangle* rect)))
1472 (t (with-bounding-rectangle* (r-x1 r-y1 r-x2 r-y2)
1473 rect
1474 (setf (values x1 y1 x2 y2)
1475 (bound-rectangles x1 y1 x2 y2
1476 r-x1 r-y1 r-x2 r-y2)))))))
1477 (union-with-bounds old-highlighting)
1478 (union-with-bounds new-highlighting)
1479 (union-with-bounds old-presentation)
1480 (union-with-bounds new-presentation)
1481 (values x1 y1 x2 y2))))
1482
1483 (defun make-drag-and-drop-feedback-function (from-presentation)
1484 (multiple-value-bind (record-x record-y)
1485 (output-record-position from-presentation)
1486 (let ((current-to-presentation nil)
1487 (current-from-higlighting nil))
1488 (lambda (frame from-presentation to-presentation initial-x initial-y
1489 x y event)
1490 (let ((dx (- record-x initial-x))
1491 (dy (- record-y initial-y)))
1492 (typecase event
1493 (null
1494 ())))))))
1495
1496 (defmethod frame-drag-and-drop-feedback
1497 ((frame standard-application-frame) from-presentation stream
1498 initial-x initial-y x y state)
1499 (with-bounding-rectangle* (fp-x1 fp-y1 fp-x2 fp-y2)
1500 from-presentation
1501 ;; Offset from origin of presentation is preserved throughout
1502 (let* ((x-off (- fp-x1 initial-x))
1503 (y-off (- fp-y1 initial-y))
1504 (hilite-x1 (+ x-off x))
1505 (hilite-y1 (+ y-off y))
1506 (hilite-x2 (+ hilite-x1 (- fp-x2 fp-x1)))
1507 (hilite-y2 (+ hilite-y1 (- fp-y2 fp-y1))))
1508 (with-identity-transformation (stream)
1509 (ecase state
1510 (:highlight
1511 (with-output-recording-options (stream :record nil)
1512 (draw-rectangle* stream hilite-x1 hilite-y1 hilite-x2 hilite-y2
1513 :filled nil :line-dashes #(4 4))))
1514 (:unhighlight
1515 (with-double-buffering
1516 ((stream hilite-x1 hilite-y1 (1+ hilite-x2) (1+ hilite-y2))
1517 (buffer-rectangle))
1518 (stream-replay stream buffer-rectangle))))))))
1519
1520 (defmethod frame-drag-and-drop-highlighting
1521 ((frame standard-application-frame) to-presentation stream state)
1522 (highlight-presentation-1 to-presentation stream state))
1523
1524 (defun frame-drag-and-drop (translator-name command-table
1525 from-presentation context-type frame event window
1526 x y)
1527 (declare (ignore command-table))
1528 (let* ((*dragged-presentation* from-presentation)
1529 (*dragged-object* (presentation-object from-presentation))
1530 (translators (mapcan (lambda (trans)
1531 (and (typep trans 'drag-n-drop-translator)
1532 (funcall (tester trans)
1533 (presentation-object
1534 from-presentation)
1535 :presentation from-presentation
1536 :context-type context-type
1537 :frame frame
1538 :window window
1539 :x x
1540 :y y
1541 :event event)
1542 (list trans)))
1543 (find-presentation-translators
1544 (presentation-type from-presentation)
1545 context-type
1546 (frame-command-table frame))))
1547 ;; Try to run the feedback and highlight functions of the translator
1548 ;; that got us here.
1549 (translator (or (find translator-name translators :key #'name)
1550 (car translators)))
1551 (initial-feedback-fn (feedback translator))
1552 (initial-hilite-fn (highlighting translator))
1553 (destination-presentation nil)
1554 (initial-x x)
1555 (initial-y y)
1556 (last-presentation nil)
1557 (feedback-activated nil)
1558 (feedback-fn initial-feedback-fn)
1559 (hilite-fn initial-hilite-fn)
1560 (last-event nil))
1561 ;; We shouldn't need to use find-innermost-presentation-match
1562 ;; This repeats what tracking-pointer has already done, but what are you
1563 ;; gonna do?
1564 (flet ((find-dest-translator (presentation window x y)
1565 (loop for translator in translators
1566 when (and (presentation-subtypep
1567 (presentation-type presentation)
1568 (destination-ptype translator))
1569 (test-presentation-translator translator
1570 presentation
1571 context-type frame
1572 window x y))
1573 do (return-from find-dest-translator translator))
1574 nil)
1575 (do-feedback (window x y state)
1576 (funcall feedback-fn frame from-presentation window
1577 initial-x initial-y x y state))
1578 (do-hilite (presentation window state)
1579 (funcall hilite-fn frame presentation window state))
1580 (last-window ()
1581 (event-sheet last-event))
1582 (last-x ()
1583 (pointer-event-x last-event))
1584 (last-y ()
1585 (pointer-event-y last-event)))
1586 ;; :highlight nil will cause the presentation that is the source of the
1587 ;; dragged object to be unhighlighted initially.
1588 (block do-tracking
1589 (tracking-pointer (window :context-type `(or ,(mapcar #'from-type
1590 translators))
1591 :highlight nil
1592 :multiple-window nil) ;XXX
1593 (:presentation (&key presentation window event x y)
1594 (let ((dest-translator (find-dest-translator presentation window
1595 x y)))
1596 (when feedback-activated
1597 (do-feedback (last-window) (last-x) (last-y) :unhighlight))
1598 (setq feedback-activated t
1599 last-event event)
1600 (when last-presentation
1601 (do-hilite last-presentation (last-window) :unhighlight))
1602 (setq last-presentation presentation
1603 feedback-fn (feedback dest-translator)
1604 hilite-fn (highlighting dest-translator))
1605 (do-hilite presentation window :highlight)
1606 (do-feedback window x y :highlight)
1607 (document-drag-n-drop dest-translator presentation
1608 context-type frame event window
1609 x y)))
1610 (:pointer-motion (&key event window x y)
1611 (when feedback-activated
1612 (do-feedback (last-window) (last-x) (last-y) :unhighlight))
1613 (setq feedback-activated t
1614 last-event event)
1615 (when last-presentation
1616 (do-hilite last-presentation (last-window) :unhighlight))
1617 (setq last-presentation nil)
1618 (do-feedback window x y :highlight)
1619 (document-drag-n-drop translator nil
1620 context-type frame event window
1621 x y))
1622 ;; XXX only support finish-on-release for now.
1623 #-(and)(:presentation-button-press ())
1624 (:presentation-button-release (&key presentation event)
1625 (setq destination-presentation presentation
1626 last-event event)
1627 (return-from do-tracking nil))
1628 #-(and)(:button-press ())
1629 (:button-release (&key event)
1630 (setq last-event event)
1631 (return-from do-tracking nil))))
1632 ;;
1633 ;; XXX Assumes x y from :button-release are the same as for the preceding
1634 ;; button-motion; is that correct?
1635 (when feedback-activated
1636 (do-feedback (last-window) (last-x) (last-y) :unhighlight))
1637 (when last-presentation
1638 (do-hilite last-presentation (last-window) :unhighlight))
1639 (if destination-presentation
1640 (let ((final-translator (find-dest-translator destination-presentation
1641 (last-window)
1642 (last-x)
1643 (last-y))))
1644 (if final-translator
1645 (funcall (destination-translator final-translator)
1646 *dragged-object*
1647 :presentation *dragged-presentation*
1648 :destination-object (presentation-object
1649 destination-presentation)
1650 :destination-presentation destination-presentation
1651 :context-type context-type
1652 :frame frame
1653 :event event
1654 :window window
1655 :x x
1656 :y y)
1657 (values nil nil)))
1658 (values nil nil)))))
1659
1660 (defun document-drag-n-drop
1661 (translator presentation context-type frame event window x y)
1662 (when *pointer-documentation-output*
1663 (let ((s *pointer-documentation-output*))
1664 (window-clear s)
1665 (with-end-of-page-action (s :allow)
1666 (with-end-of-line-action (s :allow)
1667 (funcall (pointer-documentation translator)
1668 *dragged-object*
1669 :presentation *dragged-presentation*
1670 :destination-object (and presentation
1671 (presentation-object presentation))
1672 :destination-presentation presentation
1673 :context-type context-type
1674 :frame frame
1675 :event event
1676 :window window
1677 :x x
1678 :y y
1679 :stream s))))))
1680
1681
1682

  ViewVC Help
Powered by ViewVC 1.1.5