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

Contents of /mcclim/frames.lisp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5