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

Contents of /mcclim/frames.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.105 - (hide annotations)
Wed Feb 2 11:33:58 2005 UTC (9 years, 2 months ago) by tmoore
Branch: MAIN
Changes since 1.104: +33 -2 lines
Hammered on with-room-for-graphics. It should now leave the cursor in
the right place and do the right thing with respect to recording
options.

Changed with-drawing-options to not rebind its medium argument at all.

Added :label and :scroll-bars arguments to with-menu which are
currently ignored.
1 mikemac 1.1 ;;; -*- Mode: Lisp; Package: CLIM-INTERNALS -*-
2    
3     ;;; (c) copyright 1998,1999,2000 by Michael McDonald (mikemac@mikemac.com)
4 cvs 1.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 gilbert 1.95 ;;; (c) copyright 2004 by
9     ;;; Gilbert Baumann <unk6@rz.uni-karlsruhe.de>
10 mikemac 1.1
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 mikemac 1.60 (in-package :clim-internals)
27 mikemac 1.1
28 gilbert 1.33 ;; *application-frame* is in decls.lisp
29 mikemac 1.1 (defvar *default-frame-manager* nil)
30    
31 cvs 1.5 ;;; Frame-Manager class
32    
33 gilbert 1.56 (define-protocol-class frame-manager ()
34 cvs 1.5 ((port :initarg :port
35     :reader frame-manager-port)
36     (frames :initform nil
37 brian 1.54 :reader frame-manager-frames)))
38 cvs 1.5
39     (defun find-frame-manager (&rest options &key port &allow-other-keys)
40     (declare (special *frame-manager*))
41     (if (boundp '*frame-manager*)
42     *frame-manager*
43     (if (and *default-frame-manager*
44     (frame-manager-p *default-frame-manager*))
45     *default-frame-manager*
46     (first (frame-managers (or port (apply #'find-port options)))))))
47    
48     (defmacro with-frame-manager ((frame-manager) &body body)
49 adejneka 1.43 `(let ((*frame-manager* ,frame-manager))
50 cvs 1.5 (declare (special *frame-manager*))
51 adejneka 1.43 (locally ,@body)))
52    
53 moore 1.94 ;;; XXX These should force the redisplay of the menu bar. They don't
54     ;;; yet.
55    
56     (defmethod note-command-enabled (frame-manager frame command-name)
57     (declare (ignore frame-manager frame command-name))
58     nil)
59    
60     (defmethod note-command-disabled (frame-manager frame command-name)
61     (declare (ignore frame-manager frame command-name))
62     nil)
63    
64 mikemac 1.1 ;;; Application-Frame class
65 moore 1.38 ;;; XXX All these slots should move to a mixin or to standard-application-frame.
66     ;;; -- moore
67 mikemac 1.1
68 adejneka 1.13 ;;; Generic operations
69 moore 1.90 (defgeneric frame-name (frame))
70     (defgeneric frame-pretty-name (frame))
71     (defgeneric (setf frame-pretty-name) (name frame))
72     (defgeneric frame-command-table (frame))
73     (defgeneric (setf frame-command-table) (command-table frame))
74 adejneka 1.13 (defgeneric frame-standard-output (frame)
75     (:documentation
76     "Returns the stream that will be used for *standard-output* for the FRAME."))
77     (defgeneric frame-standard-input (frame)
78     (:documentation
79     "Returns the stream that will be used for *standard-input* for the FRAME."))
80     (defgeneric frame-query-io (frame)
81     (:documentation
82     "Returns the stream that will be used for *query-io* for the FRAME."))
83     (defgeneric frame-error-output (frame)
84     (:documentation
85     "Returns the stream that will be used for *error-output* for the FRAME."))
86     (defgeneric frame-pointer-documentation-output (frame)
87     (:documentation
88     "Returns the stream that will be used for *pointer-documentation-output*
89     for the FRAME."))
90     (defgeneric frame-calling-frame (frame)
91     (:documentation
92     "Returns the application frame that invoked the FRAME."))
93     (defgeneric frame-parent (frame)
94     (:documentation
95     "Returns the object that acts as the parent for the FRAME."))
96 moore 1.90 (defgeneric frame-panes (frame)
97     (:documentation
98     "Returns the pane that is the top-level pane in the current layout
99     of the FRAME's named panes."))
100 adejneka 1.13 (defgeneric frame-top-level-sheet (frame)
101     (:documentation
102     "Returns the shhet that is the top-level sheet for the FRAME. This
103     is the sheet that has as its descendants all of the panes of the FRAME."))
104     (defgeneric frame-current-panes (frame)
105     (:documentation
106     "Returns a list of those named panes in the FRAME's current layout.
107     If there are no named panes, only the single, top level pane is returned."))
108     (defgeneric get-frame-pane (frame pane-name)
109     (:documentation
110     "Returns the named CLIM stream pane in the FRAME whose name is PANE-NAME."))
111     (defgeneric find-pane-named (frame pane-name)
112     (:documentation
113     "Returns the pane in the FRAME whose name is PANE-NAME."))
114 moore 1.90 (defgeneric frame-current-layout (frame))
115     (defgeneric (setf frame-current-layout) (layout frame))
116     (defgeneric frame-all-layouts (frame))
117 adejneka 1.13 (defgeneric layout-frame (frame &optional width height))
118 mikemac 1.22 (defgeneric frame-exit-frame (condition)
119     (:documentation
120     "Returns the frame that is being exited from associated with the
121     FRAME-EXIT condition."))
122 moore 1.90 (defgeneric frame-exit (frame)
123 adejneka 1.13 (:documentation
124     "Exits from the FRAME."))
125     (defgeneric pane-needs-redisplay (pane))
126     (defgeneric (setf pane-needs-redisplay) (value pane))
127     (defgeneric redisplay-frame-pane (frame pane &key force-p))
128     (defgeneric redisplay-frame-panes (frame &key force-p))
129     (defgeneric frame-replay (frame stream &optional region))
130     (defgeneric notify-user (frame message &key associated-window title
131     documentation exit-boxes name style text-style))
132 moore 1.82 (defgeneric frame-properties (frame property))
133     (defgeneric (setf frame-properties) (value frame property))
134     (defgeneric (setf client-setting) (value frame setting))
135 moore 1.83 (defgeneric reset-frame (frame &rest client-settings))
136 moore 1.88 (defgeneric frame-maintain-presentation-histories (frame))
137 adejneka 1.13
138 brian 1.54 ; extension
139     (defgeneric frame-schedule-timer-event (frame sheet delay token))
140 adejneka 1.13
141 hefner1 1.68 (defgeneric note-input-focus-changed (pane state)
142     (:documentation "Called when a pane receives or loses the keyboard
143     input focus. This is a McCLIM extension."))
144    
145 moore 1.90 (define-protocol-class application-frame ()
146     ((port :initform nil
147     :initarg :port
148     :accessor port)
149     (graft :initform nil
150     :initarg :graft
151     :accessor graft)
152     (name :initarg :name
153     :reader frame-name)
154     (pretty-name :initarg :pretty-name
155     :accessor frame-pretty-name)
156     (command-table :initarg :command-table
157     :initform nil
158     :accessor frame-command-table)
159     (disabled-commands :initarg :disabled-commands
160     :initform nil
161     :accessor frame-disabled-commands)
162     (named-panes :accessor frame-named-panes :initform nil)
163     (panes :initform nil :reader frame-panes
164     :documentation "The tree of panes in the current layout.")
165     (layouts :initform nil
166     :initarg :layouts
167     :reader frame-layouts)
168     (current-layout :initform nil
169     :initarg :current-layout
170     :accessor frame-current-layout)
171     (panes-for-layout :initform nil :accessor frame-panes-for-layout
172     :documentation "alist of names and panes (as returned by make-pane)")
173     (top-level-sheet :initform nil
174     :reader frame-top-level-sheet)
175     (menu-bar :initarg :menu-bar
176     :initform nil)
177     (calling-frame :initarg :calling-frame
178     :initform nil)
179     (state :initarg :state
180     :initform :disowned
181     :reader frame-state)
182     (manager :initform nil
183     :reader frame-manager
184     :accessor %frame-manager)
185     (keyboard-input-focus :initform nil
186     :accessor keyboard-input-focus)
187     (properties :accessor %frame-properties
188     :initarg :properties
189     :initform nil)
190     (top-level :initform '(default-frame-top-level)
191     :initarg :top-level
192     :reader frame-top-level)
193     (top-level-lambda :initarg :top-level-lambda
194     :reader frame-top-level-lambda)
195     (hilited-presentation :initform nil
196     :initarg :hilited-presentation
197     :accessor frame-hilited-presentation)
198     (user-supplied-geometry :initform nil
199 gilbert 1.95 :initarg :user-supplied-geometry
200     :documentation "plist of defaulted :left, :top, :bottom, :right, :width and :height options.")
201 moore 1.90 (process :reader frame-process :initform (current-process))
202     (client-settings :accessor client-settings :initform nil)))
203    
204 gilbert 1.95 (defmethod frame-geometry ((frame application-frame))
205     (slot-value frame 'user-supplied-geometry))
206    
207     (defmethod frame-geometry* ((frame application-frame))
208     "-> width height &optional top left"
209     (let ((pane (frame-top-level-sheet frame)))
210     (destructuring-bind (&key left top right bottom width height) (frame-geometry frame)
211     ;; Find width and height from looking at the respective options
212     ;; first, then at left/right and top/bottom and finally at what
213     ;; compose-space says.
214     (setf width (or width
215     (and left right (- right left))
216     (space-requirement-width (compose-space pane))))
217     (setf height (or height
218     (and top bottom (- bottom top))
219     (space-requirement-height (compose-space pane))))
220     ;; See if a position is wanted and return left, top.
221     (setf left (or left
222     (and right (- right width))))
223     (setf top (or top
224     (and bottom (- bottom height))))
225     (values width height left top))))
226    
227 moore 1.89 (defclass standard-application-frame (application-frame
228     presentation-history-mixin)
229 moore 1.38 ((event-queue :initarg :frame-event-queue
230 hefner1 1.66 :initarg :input-buffer
231     :initform nil
232 moore 1.38 :accessor frame-event-queue
233     :documentation "The event queue that, by default, will be
234 moore 1.47 shared by all panes in the stream")
235     (documentation-state :accessor frame-documentation-state
236     :initform nil
237     :documentation "Used to keep of track of what
238 moore 1.89 needs to be rendered in the pointer documentation frame.")
239     (calling-frame :reader frame-calling-frame
240     :initarg :calling-frame
241     :initform nil
242     :documentation "The frame that is the parent of this
243 moore 1.94 frame, if any")
244     (disabled-commands :accessor disabled-commands
245     :initform nil
246     :documentation "A list of command names that have been
247     disabled in this frame")))
248 moore 1.38
249     ;;; Support the :input-buffer initarg for compatibility with "real CLIM"
250    
251     (defmethod initialize-instance :after ((obj standard-application-frame)
252 moore 1.89 &key &allow-other-keys)
253     (when (and (frame-calling-frame obj)
254     (null (frame-event-queue obj)))
255     (setf (frame-event-queue obj)
256     (frame-event-queue (frame-calling-frame obj))))
257 hefner1 1.66 (unless (frame-event-queue obj)
258 hefner1 1.72 (setf (frame-event-queue obj)
259 hefner1 1.79 (make-instance 'port-event-queue))))
260 mikemac 1.1
261     (defmethod (setf frame-manager) (fm (frame application-frame))
262     (let ((old-manager (frame-manager frame)))
263 adejneka 1.46 (setf (%frame-manager frame) nil)
264 mikemac 1.1 (when old-manager
265     (disown-frame old-manager frame)
266     (setf (slot-value frame 'panes) nil)
267     (setf (slot-value frame 'layouts) nil))
268 adejneka 1.46 (setf (%frame-manager frame) fm)))
269 mikemac 1.1
270 moore 1.90 (define-condition frame-layout-changed (condition)
271     ((frame :initarg :frame :reader frame-layout-changed-frame)))
272    
273     (defmethod (setf frame-current-layout) :after (name (frame application-frame))
274 mikemac 1.1 (declare (ignore name))
275 moore 1.90 (generate-panes (frame-manager frame) frame)
276     (signal 'frame-layout-changed :frame frame))
277 mikemac 1.1
278     (defmethod generate-panes :before (fm (frame application-frame))
279     (declare (ignore fm))
280 moore 1.101 (when (and (frame-panes frame)
281     (eq (sheet-parent (frame-panes frame))
282     (frame-top-level-sheet frame)))
283 moore 1.90 (sheet-disown-child (frame-top-level-sheet frame) (frame-panes frame)))
284     (loop
285     for (nil . pane) in (frame-panes-for-layout frame)
286     for parent = (sheet-parent pane)
287     if parent
288     do (sheet-disown-child parent pane)))
289 mikemac 1.1
290     (defmethod generate-panes :after (fm (frame application-frame))
291     (declare (ignore fm))
292 moore 1.90 (sheet-adopt-child (frame-top-level-sheet frame) (frame-panes frame))
293     (unless (sheet-parent (frame-top-level-sheet frame))
294     (sheet-adopt-child (graft frame) (frame-top-level-sheet frame)))
295 gilbert 1.95 ;; Find the size of the new frame
296     (multiple-value-bind (w h x y) (frame-geometry* frame)
297 cvs 1.5 ;; automatically generates a window-configuation-event
298     ;; which then calls allocate-space
299 gilbert 1.39 ;;
300     ;; Not any longer, we turn of CONFIGURE-NOTIFY events until the
301     ;; window is mapped and do the space allocation now, so that all
302     ;; sheets will have their correct geometry at once. --GB
303 mikemac 1.1 (setf (sheet-region (frame-top-level-sheet frame))
304 gilbert 1.95 (make-bounding-rectangle 0 0 w h))
305     (allocate-space (frame-top-level-sheet frame) w h) ))
306 mikemac 1.1
307     (defmethod layout-frame ((frame application-frame) &optional width height)
308 moore 1.90 (let ((pane (frame-panes frame)))
309 mikemac 1.1 (if (and width (not height))
310     (error "LAYOUT-FRAME must be called with both WIDTH and HEIGHT or neither"))
311     (if (and (null width) (null height))
312 gilbert 1.95 (let ((space (compose-space pane))) ;I guess, this might be wrong. --GB 2004-06-01
313 mikemac 1.1 (setq width (space-requirement-width space))
314     (setq height (space-requirement-height space))))
315 gilbert 1.63 (let ((tpl-sheet (frame-top-level-sheet frame)))
316     (unless (and (= width (bounding-rectangle-width tpl-sheet))
317     (= height (bounding-rectangle-height tpl-sheet)))
318     (resize-sheet (frame-top-level-sheet frame) width height)))
319 mikemac 1.1 (allocate-space pane width height)))
320    
321 adejneka 1.13 (defun find-pane-if (predicate panes)
322     "Returns a pane satisfying PREDICATE in the forest growing from PANES"
323 moore 1.90 (map-over-sheets #'(lambda (p)
324     (when (funcall predicate p)
325     (return-from find-pane-if p)))
326     panes)
327     nil)
328 moore 1.27
329 adejneka 1.13 (defun find-pane-of-type (panes type)
330     (find-pane-if #'(lambda (pane) (typep pane type)) panes))
331 adejneka 1.40
332 moore 1.90 ;;; There are several ways to do this; this isn't particularly efficient, but
333     ;;; it shouldn't matter much. If it does, it might be better to map over the
334     ;;; panes in frame-named-panes looking for panes with parents.
335 adejneka 1.13 (defmethod frame-current-panes ((frame application-frame))
336 moore 1.90 (let ((panes nil)
337     (named-panes (frame-named-panes frame)))
338     (map-over-sheets #'(lambda (p)
339     (when (member p named-panes)
340     (push p panes)))
341     (frame-panes frame))
342     panes))
343 adejneka 1.13
344     (defmethod get-frame-pane ((frame application-frame) pane-name)
345 moore 1.90 (let ((pane (find-pane-named frame pane-name)))
346     (if (typep pane 'clim-stream-pane)
347     pane
348     nil)))
349 adejneka 1.13
350     (defmethod find-pane-named ((frame application-frame) pane-name)
351 moore 1.90 (find pane-name (frame-named-panes frame) :key #'pane-name))
352 adejneka 1.13
353 mikemac 1.1 (defmethod frame-standard-output ((frame application-frame))
354 cvs 1.6 (or (find-pane-of-type (frame-panes frame) 'application-pane)
355     (find-pane-of-type (frame-panes frame) 'interactor-pane)))
356 mikemac 1.1
357     (defmethod frame-standard-input ((frame application-frame))
358 cvs 1.6 (or (find-pane-of-type (frame-panes frame) 'interactor-pane)
359 mikemac 1.1 (frame-standard-output frame)))
360    
361     (defmethod frame-query-io ((frame application-frame))
362     (or (frame-standard-input frame)
363     (frame-standard-output frame)))
364    
365     (defmethod frame-error-output ((frame application-frame))
366     (frame-standard-output frame))
367    
368     (defvar *pointer-documentation-output* nil)
369    
370     (defmethod frame-pointer-documentation-output ((frame application-frame))
371 adejneka 1.13 (find-pane-of-type (frame-panes frame) 'pointer-documentation-pane))
372 mikemac 1.1
373 moore 1.93 #+nil
374 hefner1 1.70 (defmethod redisplay-frame-panes ((frame application-frame) &key force-p)
375     (map-over-sheets
376     (lambda (sheet)
377     (when (typep sheet 'pane)
378     (when (and (typep sheet 'clim-stream-pane)
379     (not (eq :no-clear (pane-redisplay-needed sheet))))
380     (window-clear sheet))
381     (redisplay-frame-pane frame sheet :force-p force-p)))
382     (frame-top-level-sheet frame)))
383    
384 moore 1.93 (defmethod redisplay-frame-panes ((frame application-frame) &key force-p)
385     (map-over-sheets (lambda (sheet)
386     (redisplay-frame-pane frame sheet :force-p force-p))
387     (frame-top-level-sheet frame)))
388    
389    
390 moore 1.82 (defmethod frame-replay (frame stream &optional region)
391     (declare (ignore frame))
392     (stream-replay stream region))
393    
394     (defmethod frame-properties ((frame application-frame) property)
395     (getf (%frame-properties frame) property))
396    
397     (defmethod (setf frame-properties) (value (frame application-frame) property)
398     (setf (getf (%frame-properties frame) property) value))
399    
400 mikemac 1.1 ;;; Command loop interface
401    
402 mikemac 1.22 (define-condition frame-exit (condition)
403 moore 1.26 ((frame :initarg :frame :reader %frame-exit-frame)))
404 mikemac 1.22
405 hefner1 1.66 ;; I make the assumption here that the contents of *application-frame* is
406     ;; the frame the top-level loop is running. With the introduction of
407     ;; window-stream frames that may be sharing the event queue with the main
408     ;; application frame, we need to discriminate between them here to avoid
409     ;; shutting down the application at the wrong time.
410     ;; ...
411     ;; A better way to do this would be to make the handler bound in
412     ;; run-frame-top-level check whether the frame signalled is the one
413     ;; it was invoked on.. -- Hefner
414    
415 mikemac 1.22 (defmethod frame-exit ((frame standard-application-frame))
416 hefner1 1.66 (if (eq *application-frame* frame)
417     (signal 'frame-exit :frame frame)
418     (disown-frame (frame-manager frame) frame)))
419 moore 1.26
420     (defmethod frame-exit-frame ((c frame-exit))
421     (%frame-exit-frame c))
422 mikemac 1.22
423 moore 1.59 (defmethod redisplay-frame-pane ((frame application-frame) pane &key force-p)
424     (declare (ignore pane force-p))
425     nil)
426    
427 moore 1.93 (defmethod redisplay-frame-pane :around ((frame application-frame) pane
428     &key force-p)
429     (multiple-value-bind (redisplayp clearp)
430     (pane-needs-redisplay pane)
431     (when force-p
432     (setq redisplayp (or redisplayp t)
433     clearp t))
434     (when redisplayp
435     (let ((hilited (frame-hilited-presentation frame)))
436     (when hilited
437     (highlight-presentation-1 (car hilited) (cdr hilited) :unhighlight)
438     (setf (frame-hilited-presentation frame) nil)))
439     (when clearp
440     (window-clear pane))
441     (call-next-method)
442 strandh 1.97 (unless (or (eq redisplayp :command-loop) (eq redisplayp :no-clear))
443 moore 1.93 (setf (pane-needs-redisplay pane) nil)))))
444    
445 moore 1.90 (defmethod run-frame-top-level ((frame application-frame)
446     &key &allow-other-keys)
447     (handler-case
448     (funcall (frame-top-level-lambda frame) frame)
449     (frame-exit ()
450     nil)))
451 mikemac 1.1
452 adejneka 1.44 (defmethod run-frame-top-level :around ((frame application-frame) &key)
453 mikemac 1.1 (let ((*application-frame* frame)
454     (*input-context* nil)
455     (*input-wait-test* nil)
456     (*input-wait-handler* nil)
457 moore 1.52 (*pointer-button-press-handler* nil)
458     (original-state (frame-state frame)))
459 mikemac 1.1 (declare (special *input-context* *input-wait-test* *input-wait-handler*
460     *pointer-button-press-handler*))
461 hefner1 1.74 (when (eq (frame-state frame) :disowned) ; Adopt frame into frame manager
462 moore 1.52 (adopt-frame (or (frame-manager frame) (find-frame-manager))
463     frame))
464     (unless (or (eq (frame-state frame) :enabled)
465     (eq (frame-state frame) :shrunk))
466     (enable-frame frame))
467 moore 1.90 (unwind-protect
468     (loop
469     for query-io = (frame-query-io frame)
470     for *default-frame-manager* = (frame-manager frame)
471     do (handler-case
472     (return (if query-io
473     (with-input-focus (query-io)
474     (call-next-method))
475     (call-next-method)))
476     (frame-layout-changed () nil)))
477     (let ((fm (frame-manager frame)))
478     (case original-state
479     (:disabled
480     (disable-frame frame))
481     (:disowned
482     (disown-frame fm frame)))))))
483 mikemac 1.1
484 moore 1.75 ;;; Defined in incremental-redisplay.lisp
485     (defvar *enable-updating-output*)
486    
487 moore 1.93 #+nil
488 hefner1 1.71 (defun redisplay-changed-panes (frame)
489     (map-over-sheets #'(lambda (pane)
490     (multiple-value-bind (redisplayp clearp)
491     (pane-needs-redisplay pane)
492     (when redisplayp
493     (when (and clearp
494     (or (not (pane-incremental-redisplay
495     pane))
496     (not *enable-updating-output*)))
497     (window-clear pane))
498     (redisplay-frame-pane frame pane)
499     (unless (eq redisplayp :command-loop)
500     (setf (pane-needs-redisplay pane) nil)))))
501     (frame-top-level-sheet frame)))
502    
503 moore 1.85 (defparameter +default-prompt-style+ (make-text-style :fix :italic :normal))
504    
505 mikemac 1.1 (defmethod default-frame-top-level
506     ((frame application-frame)
507     &key (command-parser 'command-line-command-parser)
508     (command-unparser 'command-line-command-unparser)
509     (partial-command-parser
510     'command-line-read-remaining-arguments-for-partial-command)
511 moore 1.35 (prompt "Command: "))
512 moore 1.93 ;; Give each pane a fresh start first time through.
513     (let ((first-time t))
514     (loop
515     ;; The variables are rebound each time through the loop because the
516     ;; values of frame-standard-input et al. might be changed by a command.
517     (let* ((*standard-input* (or (frame-standard-input frame)
518     *standard-input*))
519     (*standard-output* (or (frame-standard-output frame)
520     *standard-output*))
521     (query-io (frame-query-io frame))
522     (*query-io* (or query-io *query-io*))
523     (*pointer-documentation-output*
524     (frame-pointer-documentation-output frame))
525     ;; during development, don't alter *error-output*
526     ;; (*error-output* (frame-error-output frame))
527     (*command-parser* command-parser)
528     (*command-unparser* command-unparser)
529     (*partial-command-parser* partial-command-parser)
530     (interactorp (typep *query-io* 'interactor-pane)))
531     (restart-case
532     (progn
533     (redisplay-frame-panes frame :force-p first-time)
534     (setq first-time nil)
535     (if query-io
536 hefner1 1.96 ;; We don't need to turn the cursor on here, as Goatee has its own
537     ;; cursor which will appear. In fact, leaving it on causes much
538     ;; bit flipping and slows command output somewhat. So, leave it
539     ;; off by default, and hope this doesn't violate the spec.
540 hefner1 1.100 (progn
541 moore 1.93 (setf (cursor-visibility (stream-text-cursor *query-io*))
542     nil)
543     (when (and prompt interactorp)
544     (with-text-style (*query-io* +default-prompt-style+)
545     (if (stringp prompt)
546     (write-string prompt *query-io*)
547     (funcall prompt *query-io* frame))
548     (finish-output *query-io*)))
549     (let ((command (read-frame-command frame
550     :stream *query-io*)))
551     (when interactorp
552     (fresh-line *query-io*))
553     (when command
554     (execute-frame-command frame command))
555     (when interactorp
556     (fresh-line *query-io*))))
557     (simple-event-loop)))
558     (abort ()
559     :report "Return to application command loop"
560     (if interactorp
561     (format *query-io* "~&Command aborted.~&")
562     (beep))))))))
563 moore 1.85
564 moore 1.87 (defmethod read-frame-command :around ((frame application-frame)
565 hefner1 1.100 &key (stream *standard-input*))
566 moore 1.64 (with-input-context ('menu-item)
567 moore 1.92 (object)
568     (call-next-method)
569 moore 1.64 (menu-item
570     (let ((command (command-menu-item-value object)))
571 moore 1.92 (unless (listp command)
572 hefner1 1.100 (setq command (list command)))
573 moore 1.92 (if (and (typep stream 'interactor-pane)
574     (member *unsupplied-argument-marker* command :test #'eq))
575     (command-line-read-remaining-arguments-for-partial-command
576     (frame-command-table frame) stream command 0)
577     command)))))
578 moore 1.64
579 moore 1.87 (defmethod read-frame-command ((frame application-frame)
580     &key (stream *standard-input*))
581 hefner1 1.100 (read-command (frame-command-table frame) :use-keystrokes t :stream stream))
582 mikemac 1.1
583     (defmethod execute-frame-command ((frame application-frame) command)
584 moore 1.35 (apply (command-name command) (command-arguments command)))
585 moore 1.94
586     (defmethod command-enabled (command-name (frame standard-application-frame))
587     (and (command-accessible-in-command-table-p command-name
588     (frame-command-table frame))
589     (not (member command-name (disabled-commands frame)))))
590    
591     (defmethod (setf command-enabled)
592     (enabled command-name (frame standard-application-frame))
593     (unless (command-accessible-in-command-table-p command-name
594     (frame-command-table frame))
595     (return-from command-enabled nil))
596     (with-accessors ((disabled-commands disabled-commands))
597     frame
598     (if enabled
599     (progn
600     (setf disabled-commands (delete command-name disabled-commands))
601     (note-command-enabled (frame-manager frame)
602     frame
603     command-name)
604     enabled)
605     (progn
606     (pushnew command-name disabled-commands)
607     (note-command-disabled (frame-manager frame)
608     frame
609     command-name)
610     nil))))
611    
612 moore 1.35
613 moore 1.38 (defmethod make-pane-1 :around (fm (frame standard-application-frame) type
614     &rest args
615 moore 1.51 &key (input-buffer nil input-buffer-p)
616 moore 1.90 (name nil namep)
617 moore 1.51 &allow-other-keys)
618 moore 1.90 (declare (ignore name input-buffer))
619 moore 1.38 "Default input-buffer to the frame event queue."
620 moore 1.90 (let ((pane (if input-buffer-p
621     (call-next-method)
622     (apply #'call-next-method fm frame type
623     :input-buffer (frame-event-queue frame)
624     args))))
625     (when namep
626     (push pane (frame-named-panes frame)))
627 mikemac 1.91 pane))
628 mikemac 1.1
629     (defmethod adopt-frame ((fm frame-manager) (frame application-frame))
630     (setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
631     (setf (frame-manager frame) fm)
632 moore 1.52 (setf (port frame) (frame-manager-port fm))
633     (setf (graft frame) (find-graft :port (port frame)))
634 mikemac 1.1 (let* ((*application-frame* frame)
635 cvs 1.4 (t-l-s (make-pane-1 fm frame 'top-level-sheet-pane
636 moore 1.52 :name 'top-level-sheet
637     ;; enabling should be left to enable-frame
638 hefner1 1.79 :enabled-p nil))
639 hefner1 1.80 #+clim-mp (event-queue (sheet-event-queue t-l-s)))
640 mikemac 1.1 (setf (slot-value frame 'top-level-sheet) t-l-s)
641 moore 1.52 (generate-panes fm frame)
642     (setf (slot-value frame 'state) :disabled)
643 hefner1 1.80 #+clim-mp
644 hefner1 1.79 (when (typep event-queue 'port-event-queue)
645     (setf (event-queue-port event-queue)
646     (frame-manager-port fm)))
647 moore 1.52 frame))
648 brian 1.28
649 mikemac 1.1 (defmethod disown-frame ((fm frame-manager) (frame application-frame))
650 hefner1 1.84 #+CLIM-MP
651 hefner1 1.79 (let* ((t-l-s (frame-top-level-sheet frame))
652     (queue (sheet-event-queue t-l-s)))
653     (when (typep queue 'port-event-queue)
654     (setf (event-queue-port queue) nil)))
655 mikemac 1.1 (setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
656     (sheet-disown-child (graft frame) (frame-top-level-sheet frame))
657 moore 1.52 (setf (%frame-manager frame) nil)
658     (setf (slot-value frame 'state) :disowned)
659 hefner1 1.79 (port-force-output (frame-manager-port fm))
660 moore 1.52 frame)
661    
662     (defgeneric enable-frame (frame))
663     (defgeneric disable-frame (frame))
664    
665     (defgeneric note-frame-enabled (frame-manager frame))
666     (defgeneric note-frame-disbled (frame-manager frame))
667    
668     (defmethod enable-frame ((frame application-frame))
669     (setf (sheet-enabled-p (frame-top-level-sheet frame)) t)
670     (setf (slot-value frame 'state) :enabled)
671     (note-frame-enabled (frame-manager frame) frame))
672    
673     (defmethod disable-frame ((frame application-frame))
674     (setf (sheet-enabled-p (frame-top-level-sheet frame)) nil)
675     (setf (slot-value frame 'state) :disabled)
676     (note-frame-disabled (frame-manager frame) frame))
677    
678     (defmethod note-frame-enabled ((fm frame-manager) frame)
679     (declare (ignore frame))
680     t)
681    
682     (defmethod note-frame-disabled ((fm frame-manager) frame)
683 moore 1.75 (declare (ignore frame))
684 moore 1.52 t)
685 mikemac 1.1
686 cvs 1.8 (defvar *pane-realizer* nil)
687    
688 mikemac 1.1 (defmacro with-look-and-feel-realization ((frame-manager frame) &body body)
689 cvs 1.8 `(let ((*pane-realizer* ,frame-manager)
690     (*application-frame* ,frame))
691 adejneka 1.45 (locally
692     ,@body)))
693 mikemac 1.1
694 brian 1.28 ; The menu-bar code in the following two functions is incorrect.
695     ; it needs to be moved to somewhere after the backend, since
696     ; it depends on the backend chosen.
697     ;
698     ; This hack slaps a menu-bar into the start of the application-frame,
699     ; in such a way that it is hard to find.
700     ;
701     ; FIXME
702     (defun make-single-pane-generate-panes-form (class-name menu-bar pane)
703 moore 1.90 `(progn
704     (defmethod generate-panes ((fm frame-manager) (frame ,class-name))
705     ;; v-- hey, how can this be?
706     (with-look-and-feel-realization (fm frame)
707     (let ((pane ,(cond
708     ((eq menu-bar t)
709     `(vertically () (clim-internals::make-menu-bar
710 brian 1.28 ',class-name)
711 moore 1.90 ,pane))
712     ((consp menu-bar)
713     `(vertically () (clim-internals::make-menu-bar
714 brian 1.28 (make-command-table nil
715 moore 1.90 :menu ',menu-bar))
716     ,pane))
717     (menu-bar
718     `(vertically () (clim-internals::make-menu-bar
719     ',menu-bar)
720     ,pane))
721     ;; The form below is unreachable with (listp
722     ;; menu-bar) instead of (consp menu-bar) above
723     ;; --GB
724     (t pane))))
725     (setf (slot-value frame 'panes) pane))))
726     (defmethod frame-all-layouts ((frame ,class-name))
727     nil)))
728    
729     (defun find-pane-for-layout (name frame)
730     (cdr (assoc name (frame-panes-for-layout frame) :test #'eq)))
731    
732     (defun save-pane-for-layout (name pane frame)
733     (push (cons name pane) (frame-panes-for-layout frame))
734     pane)
735    
736 hefner1 1.96 (defun coerce-pane-name (pane name)
737     (when pane
738     (setf (slot-value pane 'name) name)
739     (push pane (frame-named-panes (pane-frame pane))))
740     pane)
741    
742     (defun do-pane-creation-form (name form)
743 moore 1.90 (cond
744     ((and (= (length form) 1)
745     (listp (first form)))
746 hefner1 1.96 `(coerce-pane-name ,(first form) ',name))
747 moore 1.90 ((keywordp (first form))
748     (let ((maker (intern (concatenate 'string
749     (symbol-name '#:make-clim-)
750     (symbol-name (first form))
751     (symbol-name '#:-pane))
752     :clim)))
753     (if (fboundp maker)
754     `(,maker :name ',name ,@(cdr form))
755     `(make-pane ',(first form)
756     :name ',name ,@(cdr form)))))
757     (t `(make-pane ',(first form) :name ',name ,@(cdr form)))))
758 mikemac 1.1
759 moore 1.47 (defun make-panes-generate-panes-form (class-name menu-bar panes layouts
760     pointer-documentation)
761     (when pointer-documentation
762     (setf panes (append panes
763     '((%pointer-documentation%
764     pointer-documentation-pane)))))
765 moore 1.90 `(progn
766     (defmethod generate-panes ((fm frame-manager) (frame ,class-name))
767     (let ((*application-frame* frame))
768     (with-look-and-feel-realization (fm frame)
769     (let ,(loop
770     for (name . form) in panes
771     collect `(,name (or (find-pane-for-layout ',name frame)
772     (save-pane-for-layout
773     ',name
774     ,(do-pane-creation-form name form)
775     frame))))
776     ;; [BTS] added this, but is not sure that this is correct for
777     ;; adding a menu-bar transparently, should also only be done
778     ;; where the exterior window system does not support menus
779     ,(if (or menu-bar pointer-documentation)
780     `(setf (slot-value frame 'panes)
781     (ecase (frame-current-layout frame)
782     ,@(mapcar (lambda (layout)
783     `(,(first layout)
784     (vertically ()
785     ,@(cond
786     ((eq menu-bar t)
787     `((clim-internals::make-menu-bar
788     ',class-name)))
789     ((consp menu-bar)
790     `((clim-internals::make-menu-bar
791     (make-command-table
792     nil
793     :menu ',menu-bar))))
794     (menu-bar
795     `((clim-internals::make-menu-bar
796     ',menu-bar)))
797     (t nil))
798     ,@(rest layout)
799     ,@(when pointer-documentation
800     '(%pointer-documentation%)))))
801     layouts)))
802     `(setf (slot-value frame 'panes)
803     (ecase (frame-current-layout frame)
804     ,@layouts)))))))
805     (defmethod frame-all-layouts ((frame ,class-name))
806     ',(mapcar #'car layouts))))
807 mikemac 1.1
808     (defmacro define-application-frame (name superclasses slots &rest options)
809     (if (null superclasses)
810     (setq superclasses '(standard-application-frame)))
811     (let ((pane nil)
812     (panes nil)
813     (layouts nil)
814     (current-layout nil)
815 mikemac 1.23 (command-table (list name))
816 mikemac 1.1 (menu-bar t)
817     (disabled-commands nil)
818     (command-definer t)
819     (top-level '(default-frame-top-level))
820 hefner1 1.86 (others nil)
821 mikemac 1.69 (pointer-documentation nil)
822 moore 1.87 (geometry nil)
823     (frame-arg (gensym "FRAME-ARG")))
824 mikemac 1.1 (loop for (prop . values) in options
825     do (case prop
826     (:pane (setq pane (first values)))
827     (:panes (setq panes values))
828     (:layouts (setq layouts values))
829     (:command-table (setq command-table (first values)))
830 brian 1.28 (:menu-bar (setq menu-bar (if (listp values)
831     (first values)
832     values)))
833 mikemac 1.1 (:disabled-commands (setq disabled-commands values))
834     (:command-definer (setq command-definer (first values)))
835     (:top-level (setq top-level (first values)))
836 moore 1.47 (:pointer-documentation (setq pointer-documentation (car values)))
837 mikemac 1.69 (:geometry (setq geometry values))
838 mikemac 1.1 (t (push (cons prop values) others))))
839 hefner1 1.86 (when (eq command-definer t)
840     (setf command-definer
841     (intern (concatenate 'string
842     (symbol-name '#:define-)
843     (symbol-name name)
844     (symbol-name '#:-command)))))
845 mikemac 1.1 (if (or (and pane panes)
846     (and pane layouts))
847     (error ":pane cannot be specified along with either :panes or :layouts"))
848     (if pane
849     (setq panes (list 'single-pane pane)
850 moore 1.17 layouts `((:default ,(car pane)))))
851 mikemac 1.1 (setq current-layout (first (first layouts)))
852     `(progn
853 gilbert 1.95 (defclass ,name ,superclasses
854     ,slots
855     (:default-initargs
856     :name ',name
857     :pretty-name ,(string-capitalize name)
858     :command-table (find-command-table ',(first command-table))
859     :disabled-commands ',disabled-commands
860     :menu-bar ',menu-bar
861     :current-layout ',current-layout
862     :layouts ',layouts
863     :top-level (list ',(car top-level) ,@(cdr top-level))
864     :top-level-lambda (lambda (,frame-arg)
865     (,(car top-level) ,frame-arg
866     ,@(cdr top-level))))
867     ,@others)
868     ;; We alway set the frame class default geometry, so that the
869     ;; user can undo the effect of a specified :geometry option.
870     ;; --GB 2004-06-01
871     (setf (get ',name 'application-frame-geometry) ',geometry)
872     ,(if pane
873     (make-single-pane-generate-panes-form name menu-bar pane)
874     (make-panes-generate-panes-form name menu-bar panes layouts
875     pointer-documentation))
876     ,@(if command-table
877     `((define-command-table ,@command-table)))
878     ,@(if command-definer
879     `((defmacro ,command-definer (name-and-options arguements &rest body)
880     (let ((name (if (listp name-and-options) (first name-and-options) name-and-options))
881     (options (if (listp name-and-options) (cdr name-and-options) nil))
882     (command-table ',(first command-table)))
883     `(define-command (,name :command-table ,command-table ,@options) ,arguements ,@body))))))))
884    
885     (defun get-application-frame-class-geometry (name indicator)
886     (getf (get name 'application-frame-geometry) indicator nil))
887 mikemac 1.69
888 mikemac 1.1 (defun make-application-frame (frame-name
889     &rest options
890 moore 1.52 &key (pretty-name
891     (string-capitalize frame-name))
892     (frame-manager nil frame-manager-p)
893     enable
894     (state nil state-supplied-p)
895 gilbert 1.95 (left (get-application-frame-class-geometry frame-name :left))
896     (top (get-application-frame-class-geometry frame-name :top))
897     (right (get-application-frame-class-geometry frame-name :right))
898     (bottom (get-application-frame-class-geometry frame-name :bottom))
899     (width (get-application-frame-class-geometry frame-name :width))
900     (height (get-application-frame-class-geometry frame-name :height))
901 moore 1.52 save-under (frame-class frame-name)
902 mikemac 1.1 &allow-other-keys)
903 mikemac 1.69 (declare (ignore save-under))
904 moore 1.52 (with-keywords-removed (options (:pretty-name :frame-manager :enable :state
905     :left :top :right :bottom :width :height
906 moore 1.53 :save-under :frame-class))
907 moore 1.52 (let ((frame (apply #'make-instance frame-class
908 mikemac 1.69 :name frame-name
909     :pretty-name pretty-name
910 gilbert 1.95 :user-supplied-geometry
911     (list :left left :top top
912     :right right :bottom bottom
913     :width width :height height)
914 mikemac 1.69 options)))
915 moore 1.52 (when frame-manager-p
916     (adopt-frame frame-manager frame))
917     (cond ((or enable (eq state :enabled))
918     (enable-frame frame))
919     ((and (eq state :disowned)
920     (not (eq (frame-state frame) :disowned)))
921     (disown-frame (frame-manager frame) frame))
922     (state-supplied-p
923     (warn ":state ~S not supported yet." state)))
924     frame)))
925 cvs 1.4
926 cvs 1.7 ;;; Menu frame class
927    
928     (defclass menu-frame ()
929     ((left :initform 0 :initarg :left)
930     (top :initform 0 :initarg :top)
931 hefner1 1.103 (min-width :initform nil :initarg :min-width)
932 cvs 1.7 (top-level-sheet :initform nil :reader frame-top-level-sheet)
933 moore 1.90 (panes :reader frame-panes :initarg :panes)
934 cvs 1.7 (graft :initform nil :accessor graft)
935     (manager :initform nil :accessor frame-manager)))
936 adejneka 1.46
937 cvs 1.7 (defmethod adopt-frame ((fm frame-manager) (frame menu-frame))
938     (setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
939 adejneka 1.46 (setf (frame-manager frame) fm)
940 brian 1.54 (let* ((t-l-s (make-pane-1 fm *application-frame*
941     'unmanaged-top-level-sheet-pane
942 cvs 1.7 :name 'top-level-sheet)))
943     (setf (slot-value frame 'top-level-sheet) t-l-s)
944 moore 1.90 (sheet-adopt-child t-l-s (frame-panes frame))
945 cvs 1.7 (let ((graft (find-graft :port (frame-manager-port fm))))
946     (sheet-adopt-child graft t-l-s)
947     (setf (graft frame) graft))
948 hefner1 1.103 (let ((pre-space (compose-space t-l-s))
949     (frame-min-width (slot-value frame 'min-width)))
950     (multiple-value-bind (width min-width max-width height min-height max-height)
951     (space-requirement-components pre-space)
952     (flet ((foomax (x y) (max (or x 1) (or y 1))))
953     (let ((space (make-space-requirement :min-width (foomax frame-min-width min-width)
954     :width (foomax frame-min-width width)
955     :max-width (foomax frame-min-width max-width)
956     :min-height min-height
957     :height height
958     :max-height max-height)))
959     (allocate-space (frame-panes frame)
960     (space-requirement-width space)
961     (space-requirement-height space))
962     (setf (sheet-region t-l-s)
963     (make-bounding-rectangle 0 0
964     (space-requirement-width space)
965     (space-requirement-height space))))
966     (setf (sheet-transformation t-l-s)
967     (make-translation-transformation (slot-value frame 'left)
968     (slot-value frame 'top))))))))
969 cvs 1.7
970     (defmethod disown-frame ((fm frame-manager) (frame menu-frame))
971     (setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
972     (sheet-disown-child (graft frame) (frame-top-level-sheet frame))
973     (setf (frame-manager frame) nil))
974    
975 hefner1 1.103 (defun make-menu-frame (pane &key (left 0) (top 0) (min-width 1))
976     (make-instance 'menu-frame :panes pane :left left :top top :min-width min-width))
977 moore 1.18
978     ;;; Frames and presentations
979 moore 1.88 (defmethod frame-maintain-presentation-histories
980     ((frame standard-application-frame))
981     (if (find-pane-of-type (frame-panes frame) 'interactor-pane)
982     t
983     nil))
984 moore 1.18
985     (defmethod frame-find-innermost-applicable-presentation
986     ((frame standard-application-frame) input-context stream x y
987     &key event)
988     (find-innermost-applicable-presentation input-context stream
989     x y
990     :frame frame :event event))
991    
992 adejneka 1.41 (defmethod frame-input-context-button-press-handler
993 moore 1.18 ((frame standard-application-frame)
994     (stream output-recording-stream)
995     button-press-event)
996     (let ((presentation (find-innermost-applicable-presentation
997     *input-context*
998     stream
999     (pointer-event-x button-press-event)
1000     (pointer-event-y button-press-event)
1001 moore 1.37 :frame frame
1002     :event button-press-event)))
1003 moore 1.18 (when presentation
1004     (throw-highlighted-presentation presentation
1005     *input-context*
1006     button-press-event))))
1007    
1008     (defmethod frame-input-context-button-press-handler
1009     ((frame standard-application-frame) stream button-press-event)
1010 mikemac 1.36 (declare (ignore stream button-press-event))
1011 moore 1.27 nil)
1012 moore 1.18
1013 moore 1.47 (defgeneric frame-update-pointer-documentation
1014     (frame input-context stream event))
1015    
1016     (defconstant +button-documentation+ '((#.+pointer-left-button+ "L")
1017     (#.+pointer-middle-button+ "M")
1018 hefner1 1.96 (#.+pointer-right-button+ "R")
1019     (#.+pointer-wheel-up+ "WheelUp")
1020     (#.+pointer-wheel-down+ "WheelDown")))
1021 moore 1.47
1022 moore 1.48 (defconstant +modifier-documentation+
1023     '((#.+shift-key+ "sh" "Shift")
1024     (#.+control-key+ "c" "Control")
1025     (#.+meta-key+ "m" "Meta")
1026     (#.+super-key+ "s" "Super")
1027     (#.+hyper-key+ "h" "Hyper")))
1028    
1029     ;;; Give a coherent order to sets of modifier combinations. Multi-key combos
1030     ;;; come after single keys.
1031    
1032     (defun cmp-modifiers (a b)
1033     (let ((cnt-a (logcount a))
1034     (cnt-b (logcount b)))
1035     (cond ((eql cnt-a cnt-b)
1036     (< a b))
1037     (t (< cnt-a cnt-b)))))
1038    
1039     (defun print-modifiers (stream modifiers style)
1040 moore 1.49 (if (zerop modifiers)
1041     (when (eq style :long)
1042     (write-string "<nothing>" stream))
1043     (loop with trailing = nil
1044     for (bit short long) in +modifier-documentation+
1045     when (logtest bit modifiers)
1046     do (progn
1047     (format stream "~:[~;-~]~A" trailing (if (eq style :short)
1048     short
1049     long))
1050     (setq trailing t)))))
1051 moore 1.48
1052    
1053     ;;; We don't actually want to print out the translator documentation and redraw
1054     ;;; the pointer documentation window on every motion event. So, we compute a
1055     ;;; state object (basically modifier state and a list of the applicable
1056     ;;; presentation, translator and input context on each mouse button),
1057     ;;; compare it to the previous state object, and only write out documentation
1058     ;;; if they are different. I suppose it's possible that this state object
1059     ;;; doesn't capture all possible documentation changes -- the doc generator is
1060     ;;; a function, after all -- but that's just tough.
1061     ;;;
1062     ;;; It would be nice to evolve this into a protocol so that elements other than
1063     ;;; presentations -- menu choices, for example -- could influence pointer
1064     ;;; documentation window.
1065    
1066 moore 1.50 (defgeneric frame-compute-pointer-documentation-state
1067     (frame input-context stream event)
1068     (:documentation
1069     "Compute a state object that will be used to generate pointer documentation."))
1070    
1071     (defmethod frame-compute-pointer-documentation-state
1072     ((frame standard-application-frame) input-context stream event)
1073     (let* ((current-modifier (event-modifier-state event))
1074     (x (device-event-x event))
1075     (y (device-event-y event))
1076     (new-translators
1077     (loop for (button) in +button-documentation+
1078     for context-list = (multiple-value-list
1079     (find-innermost-presentation-context
1080     input-context
1081     stream
1082     x y
1083     :modifier-state current-modifier
1084     :button button))
1085     when (car context-list)
1086     collect (cons button context-list))))
1087     (list current-modifier new-translators)))
1088    
1089     (defgeneric frame-compare-pointer-documentation-state
1090     (frame input-context stream old-state new-state))
1091    
1092     (defmethod frame-compare-pointer-documentation-state
1093     ((frame standard-application-frame) input-context stream
1094     old-state new-state)
1095 moore 1.78 (declare (ignore input-context stream))
1096 moore 1.50 (equal old-state new-state))
1097    
1098     (defgeneric frame-print-pointer-documentation
1099     (frame input-context stream state event))
1100    
1101     (defmethod frame-print-pointer-documentation
1102     ((frame standard-application-frame) input-context stream state event)
1103     (unless state
1104     (return-from frame-print-pointer-documentation nil))
1105     (destructuring-bind (current-modifier new-translators)
1106     state
1107     (let ((x (device-event-x event))
1108     (y (device-event-y event))
1109     (pstream *pointer-documentation-output*))
1110     (loop for (button presentation translator context)
1111     in new-translators
1112     for name = (cadr (assoc button +button-documentation+))
1113     for first-one = t then nil
1114     do (progn
1115     (unless first-one
1116     (write-string "; " pstream))
1117     (unless (zerop current-modifier)
1118     (print-modifiers pstream current-modifier :short)
1119     (write-string "-" pstream))
1120     (format pstream "~A: " name)
1121     (document-presentation-translator translator
1122     presentation
1123     (input-context-type context)
1124     *application-frame*
1125     event
1126     stream
1127     x y
1128     :stream pstream
1129     :documentation-type
1130     :pointer))
1131     finally (when new-translators
1132     (write-char #\. pstream)))
1133     ;; Wasteful to do this after doing
1134     ;; find-innermost-presentation-context above... look at doing this
1135     ;; first and then doing the innermost test.
1136     (let ((all-translators (find-applicable-translators
1137     (stream-output-history stream)
1138     input-context
1139     *application-frame*
1140     stream
1141     x y
1142     :for-menu t))
1143     (other-modifiers nil))
1144     (loop for (translator) in all-translators
1145     for gesture = (gesture translator)
1146     unless (eq gesture t)
1147     do (loop for (name type modifier) in gesture
1148     unless (eql modifier current-modifier)
1149     do (pushnew modifier other-modifiers)))
1150     (when other-modifiers
1151     (setf other-modifiers (sort other-modifiers #'cmp-modifiers))
1152     (terpri pstream)
1153     (write-string "To see other commands, press " pstream)
1154     (loop for modifier-tail on other-modifiers
1155     for (modifier) = modifier-tail
1156     for count from 0
1157     do (progn
1158     (if (null (cdr modifier-tail))
1159     (progn
1160     (when (> count 1)
1161     (write-char #\, pstream))
1162     (when (> count 0)
1163     (write-string " or " pstream)))
1164     (when (> count 0)
1165     (write-string ", " pstream)))
1166     (print-modifiers pstream modifier :long)))
1167     (write-char #\. pstream))))))
1168    
1169 moore 1.47 (defmethod frame-update-pointer-documentation
1170     ((frame standard-application-frame) input-context stream event)
1171     (when *pointer-documentation-output*
1172     (with-accessors ((frame-documentation-state frame-documentation-state))
1173     frame
1174 moore 1.50 (let ((new-state (frame-compute-pointer-documentation-state frame
1175     input-context
1176     stream
1177     event)))
1178     (unless (frame-compare-pointer-documentation-state
1179     frame
1180     input-context
1181     stream
1182     frame-documentation-state
1183     new-state)
1184     (window-clear *pointer-documentation-output*)
1185     (frame-print-pointer-documentation frame
1186     input-context
1187     stream
1188     new-state
1189     event)
1190     (setq frame-documentation-state new-state))))))
1191 moore 1.47
1192 moore 1.78 ;;; A hook for applications to draw random strings in the
1193     ;;; *pointer-documentation-output* without screwing up the real pointer
1194     ;;; documentation too badly.
1195    
1196     (defgeneric frame-display-pointer-documentation-string
1197     (frame documentation-stream string))
1198    
1199     (defmethod frame-display-pointer-documentation-string
1200     ((frame standard-application-frame) documentation-stream string)
1201     (when *pointer-documentation-output*
1202     (with-accessors ((frame-documentation-state frame-documentation-state))
1203     frame
1204     (unless (frame-compare-pointer-documentation-state
1205     frame nil documentation-stream frame-documentation-state string)
1206     (window-clear documentation-stream)
1207     (write-string string documentation-stream)
1208     (setq frame-documentation-state string)))))
1209    
1210 moore 1.18 (defmethod frame-input-context-track-pointer
1211     ((frame standard-application-frame)
1212     input-context
1213     (stream output-recording-stream) event)
1214     (declare (ignore input-context event))
1215     nil)
1216    
1217     (defmethod frame-input-context-track-pointer
1218     ((frame standard-application-frame) input-context stream event)
1219 mikemac 1.36 (declare (ignore input-context stream event))
1220 moore 1.27 nil)
1221 moore 1.18
1222 moore 1.98 (defun frame-highlight-at-position (frame stream x y modifier input-context
1223     &key (highlight t))
1224     "Given stream x,y; key modifiers; input-context, find the applicable
1225     presentation and maybe highlight it."
1226 moore 1.47 (flet ((maybe-unhighlight (presentation)
1227     (when (and (frame-hilited-presentation frame)
1228 moore 1.98 (or (not highlight)
1229     (not (eq presentation
1230     (car (frame-hilited-presentation frame))))))
1231 moore 1.47 (highlight-presentation-1 (car (frame-hilited-presentation frame))
1232     (cdr (frame-hilited-presentation frame))
1233 moore 1.98 :unhighlight)
1234     (setf (frame-hilited-presentation frame) nil))))
1235 moore 1.18 (if (output-recording-stream-p stream)
1236     (let ((presentation (find-innermost-applicable-presentation
1237     input-context
1238 hefner1 1.76 stream
1239     x y
1240 moore 1.37 :frame frame
1241 hefner1 1.76 :modifier-state modifier)))
1242 moore 1.47 (maybe-unhighlight presentation)
1243 moore 1.98 (when (and presentation
1244     highlight
1245     (not (eq presentation
1246     (car (frame-hilited-presentation frame)))))
1247     (setf (frame-hilited-presentation frame)
1248     (cons presentation stream))
1249     (highlight-presentation-1 presentation stream :highlight))
1250     presentation)
1251 moore 1.47 (progn
1252     (maybe-unhighlight nil)
1253 moore 1.98 nil))))
1254 moore 1.78
1255 hefner1 1.76 (defmethod frame-input-context-track-pointer :before
1256     ((frame standard-application-frame) input-context
1257     (stream output-recording-stream) event)
1258     (frame-highlight-at-position frame stream
1259     (device-event-x event)
1260     (device-event-y event)
1261     (event-modifier-state event)
1262     input-context)
1263 moore 1.47 (frame-update-pointer-documentation frame input-context stream event))
1264 moore 1.27
1265     (defun simple-event-loop ()
1266     "An simple event loop for applications that want all events to be handled by
1267     handle-event methods"
1268 adejneka 1.41 (let ((queue (frame-event-queue *application-frame*)))
1269     (loop for event = (event-queue-read queue)
1270     ;; EVENT-QUEUE-READ in single-process mode calls PROCESS-NEXT-EVENT itself.
1271     do (handle-event (event-sheet event) event))))
1272 moore 1.57
1273     ;;; Am I missing something? Does this need to do more? - moore
1274     (defmacro with-application-frame ((frame) &body body)
1275     `(let ((,frame *application-frame*))
1276     ,@body))
1277 hefner1 1.67
1278 hefner1 1.68
1279     (defmethod note-input-focus-changed (pane state)
1280     (declare (ignore pane state)))
1281    
1282 hefner1 1.67 (defmethod (setf keyboard-input-focus) :after (focus frame)
1283     (set-port-keyboard-focus focus (port frame)))
1284 hefner1 1.68
1285 moore 1.82 (defmethod (setf client-setting) (value frame setting)
1286     (setf (getf (client-settings frame) setting) value))
1287 moore 1.81
1288 moore 1.82 (defmethod reset-frame (frame &rest client-settings)
1289     (loop for (setting value) on client-settings by #'cddr
1290     do (setf (client-setting frame setting) value)))
1291 moore 1.98
1292     ;;; tracking-pointer stuff related to presentations
1293    
1294     (defclass frame-tracking-pointer-state (tracking-pointer-state)
1295     ((presentation-handler :reader presentation-handler :initarg :presentation)
1296     (presentation-button-release-handler
1297     :reader presentation-button-release-handler
1298     :initarg :presentation-button-release)
1299     (presentation-button-press-handler :reader presentation-button-press-handler
1300     :initarg :presentation-button-press)
1301     (applicable-presentation :accessor applicable-presentation :initform nil)
1302     (input-context :reader input-context)
1303     (highlight :reader highlight))
1304     (:default-initargs :presentation nil
1305     :presentation-button-press nil
1306     :presentation-button-release nil
1307     :context-type t))
1308    
1309     (defmethod initialize-instance :after
1310     ((obj frame-tracking-pointer-state)
1311     &key presentation presentation-button-press presentation-button-release
1312 moore 1.99 (highlight nil highlightp) context-type
1313     multiple-window)
1314     (declare (ignore multiple-window))
1315 moore 1.98 (setf (slot-value obj 'highlight) (if highlightp
1316     highlight
1317     (or presentation
1318     presentation-button-press
1319     presentation-button-release)))
1320     (setf (slot-value obj 'input-context)
1321     (make-fake-input-context context-type)))
1322    
1323     (defmethod make-tracking-pointer-state
1324     ((frame standard-application-frame) sheet args)
1325     (declare (ignore sheet))
1326     (apply #'make-instance 'frame-tracking-pointer-state
1327     args))
1328    
1329     (defmethod tracking-pointer-loop :before
1330     ((state frame-tracking-pointer-state) frame sheet &rest args)
1331     (declare (ignore args))
1332     (if (highlight state)
1333     (highlight-current-presentation frame (input-context state))
1334     (let ((hilited (frame-hilited-presentation frame)))
1335     (when hilited
1336     (highlight-presentation-1 (car hilited)
1337     (cdr hilited)
1338     :unhighlight)))))
1339    
1340 tmoore 1.104 ;;; Poor man's find-applicable-translators. tracking-pointer doesn't want to
1341     ;;; see any results from presentation translators.
1342    
1343     (defun highlight-for-tracking-pointer (frame stream x y input-context)
1344     (let ((context-ptype (input-context-type (car input-context)))
1345     (presentation nil)
1346     (current-hilited (frame-hilited-presentation frame)))
1347     (if (output-recording-stream-p stream)
1348     (progn
1349     (block found-presentation
1350     (flet ((do-presentation (p)
1351     (when (presentation-subtypep (presentation-type p)
1352     context-ptype)
1353     (setq presentation p)
1354     (return-from found-presentation nil))))
1355     (declare (dynamic-extent #'do-presentation))
1356     (map-over-presentations-containing-position
1357     #'do-presentation (stream-output-history stream) x y)))
1358     (when (and current-hilited
1359     (not (eq (car current-hilited) presentation)))
1360     (highlight-presentation-1 (car current-hilited)
1361     (cdr current-hilited)
1362     :unhighlight))
1363     (if presentation
1364     (progn
1365     (setf (frame-hilited-presentation frame)
1366     (cons presentation stream))
1367     (highlight-presentation-1 presentation stream :highlight)))
1368     presentation))))
1369    
1370 moore 1.98 (defmethod tracking-pointer-loop-step :before
1371     ((state frame-tracking-pointer-state) (event pointer-event) x y)
1372     (declare (ignore x y))
1373     (when (highlight state)
1374     (let ((stream (event-sheet event)))
1375     (setf (applicable-presentation state)
1376 tmoore 1.104 (highlight-for-tracking-pointer *application-frame* stream
1377     (device-event-x event)
1378     (device-event-y event)
1379     (input-context state))))))
1380    
1381 moore 1.98
1382     (macrolet ((frob (event handler)
1383     `(defmethod tracking-pointer-loop-step
1384     ((state frame-tracking-pointer-state) (event ,event) x y)
1385     (let ((handler (,handler state))
1386     (presentation (applicable-presentation state)))
1387     (if (and handler presentation)
1388     (funcall handler :presentation presentation
1389 hefner1 1.102 :event event
1390 moore 1.98 :window (event-sheet event)
1391     :x x :y y)
1392     (call-next-method))))))
1393     (frob pointer-motion-event presentation-handler)
1394     (frob pointer-button-press-event presentation-button-press-handler)
1395     (frob pointer-button-release-event presentation-button-release-handler))
1396    
1397 tmoore 1.105 (defun make-drag-bounding (old-highlighting new-highlighting
1398     old-presentation new-presentation)
1399     (let (x1 y1 x2 y2)
1400     (flet ((union-with-bounds (rect)
1401     (cond ((null rect)
1402     nil)
1403     ((null x1)
1404     (setf (values x1 y1 x2 y2) (bounding-rectangle* rect)))
1405     (t (with-bounding-rectangle* (r-x1 r-y1 r-x2 r-y2)
1406     rect
1407     (setf (values x1 y1 x2 y2)
1408     (bound-rectangles x1 y1 x2 y2
1409     r-x1 r-y1 r-x2 r-y2)))))))
1410     (union-with-bounds old-highlighting)
1411     (union-with-bounds new-highlighting)
1412     (union-with-bounds old-presentation)
1413     (union-with-bounds new-presentation)
1414     (values x1 y1 x2 y2))))
1415    
1416     (defun make-drag-and-drop-feedback-function (from-presentation)
1417     (multiple-value-bind (record-x record-y)
1418     (output-record-position from-presentation)
1419     (let ((current-to-presentation nil)
1420     (current-from-higlighting nil))
1421     (lambda (frame from-presentation to-presentation initial-x initial-y
1422     x y event)
1423     (let ((dx (- record-x initial-x))
1424     (dy (- record-y initial-y)))
1425     (typecase event
1426     (null
1427     ())))))))
1428 moore 1.98
1429     (defun frame-drag (translator-name command-table object presentation
1430     context-type frame event window x y)
1431     (let* ((translator (gethash translator-name
1432     (translators (presentation-translators
1433     (find-command-table
1434     command-table)))))
1435     (tester (tester translator))
1436     (drag-type (from-type translator))
1437     (feedback-fn (feedback translator))
1438     (hilite-fn (highlighting translator))
1439     (drag-c-type `(drag-over ))
1440     (drag-context (make-fake-input-context drag-c-type))
1441     (*dragged-object* object)
1442     (destination-object nil))
1443     (multiple-value-bind (x0 y0)
1444     (stream-pointer-position window)
1445     (funcall feedback-fn *application-frame* object window
1446     x0 y0 x0 y0 :highlight)
1447     (tracking-pointer (window :context-type drag-c-type :highlight nil)
1448     (:pointer-motion (&key event x y)
1449     (multiple-value-bind (presentation translator)
1450 tmoore 1.105 (find-innermost-presentation-match drag-context window
1451     x y :event event)))))))

  ViewVC Help
Powered by ViewVC 1.1.5