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

Contents of /mcclim/frames.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.70 - (hide annotations)
Sun Aug 24 09:21:15 2003 UTC (10 years, 7 months ago) by hefner1
Branch: MAIN
Changes since 1.69: +10 -0 lines
Implemented REDISPLAY-FRAME-PANES.
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 mikemac 1.1
9     ;;; This library is free software; you can redistribute it and/or
10     ;;; modify it under the terms of the GNU Library General Public
11     ;;; License as published by the Free Software Foundation; either
12     ;;; version 2 of the License, or (at your option) any later version.
13     ;;;
14     ;;; This library is distributed in the hope that it will be useful,
15     ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16     ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17     ;;; Library General Public License for more details.
18     ;;;
19     ;;; You should have received a copy of the GNU Library General Public
20     ;;; License along with this library; if not, write to the
21     ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22     ;;; Boston, MA 02111-1307 USA.
23    
24 mikemac 1.60 (in-package :clim-internals)
25 mikemac 1.1
26 gilbert 1.33 ;; *application-frame* is in decls.lisp
27 mikemac 1.1 (defvar *default-frame-manager* nil)
28    
29 cvs 1.5 ;;; Frame-Manager class
30    
31 gilbert 1.56 (define-protocol-class frame-manager ()
32 cvs 1.5 ((port :initarg :port
33     :reader frame-manager-port)
34     (frames :initform nil
35 brian 1.54 :reader frame-manager-frames)))
36 cvs 1.5
37     (defun find-frame-manager (&rest options &key port &allow-other-keys)
38     (declare (special *frame-manager*))
39     (if (boundp '*frame-manager*)
40     *frame-manager*
41     (if (and *default-frame-manager*
42     (frame-manager-p *default-frame-manager*))
43     *default-frame-manager*
44     (first (frame-managers (or port (apply #'find-port options)))))))
45    
46     (defmacro with-frame-manager ((frame-manager) &body body)
47 adejneka 1.43 `(let ((*frame-manager* ,frame-manager))
48 cvs 1.5 (declare (special *frame-manager*))
49 adejneka 1.43 (locally ,@body)))
50    
51 mikemac 1.1 ;;; Application-Frame class
52 moore 1.38 ;;; XXX All these slots should move to a mixin or to standard-application-frame.
53     ;;; -- moore
54 mikemac 1.1
55 gilbert 1.56 (define-protocol-class application-frame ()
56 mikemac 1.1 ((port :initform nil
57     :initarg :port
58     :accessor port)
59     (graft :initform nil
60     :initarg :graft
61     :accessor graft)
62     (name :initarg :name
63     :reader frame-name)
64     (pretty-name :initarg :pretty-name
65     :accessor frame-pretty-name)
66     (command-table :initarg :command-table
67     :initform nil
68     :accessor frame-command-table)
69     (disabled-commands :initarg :disabled-commands
70     :initform nil
71     :accessor frame-disabled-commands)
72     (pane :reader frame-pane)
73     (panes :initform nil
74     :reader frame-panes)
75     (layouts :initform nil
76     :initarg :layouts
77     :reader frame-layouts)
78     (current-layout :initform nil
79     :initarg :current-layout
80     :reader frame-current-layout)
81     (top-level-sheet :initform nil
82     :reader frame-top-level-sheet)
83     (menu-bar :initarg :menu-bar
84     :initform nil)
85     (calling-frame :initarg :calling-frame
86     :initform nil)
87     (state :initarg :state
88 moore 1.52 :initform :disowned
89     :reader frame-state)
90 mikemac 1.1 (manager :initform nil
91 adejneka 1.46 :reader frame-manager
92     :accessor %frame-manager)
93 hefner1 1.65 (keyboard-input-focus :initform nil
94     :accessor keyboard-input-focus)
95 mikemac 1.1 (properties :initarg :properties
96     :initform nil)
97     (top-level :initform '(default-frame-top-level)
98     :initarg :top-level
99     :reader frame-top-level)
100 moore 1.18 (hilited-presentation :initform nil
101     :initarg :hilited-presentation
102 mikemac 1.69 :accessor frame-hilited-presentation)
103     (user-supplied-geometry :initform nil
104     :initarg :user-supplied-geometry)))
105 mikemac 1.1
106 adejneka 1.13 ;;; Generic operations
107     ; (defgeneric frame-name (frame))
108     ; (defgeneric frame-pretty-name (frame))
109     ; (defgeneric (setf frame-pretty-name) (name frame))
110     ; (defgeneric frame-command-table (frame))
111     ; (defgeneric (setf frame-command-table) (command-table frame))
112     (defgeneric frame-standard-output (frame)
113     (:documentation
114     "Returns the stream that will be used for *standard-output* for the FRAME."))
115     (defgeneric frame-standard-input (frame)
116     (:documentation
117     "Returns the stream that will be used for *standard-input* for the FRAME."))
118     (defgeneric frame-query-io (frame)
119     (:documentation
120     "Returns the stream that will be used for *query-io* for the FRAME."))
121     (defgeneric frame-error-output (frame)
122     (:documentation
123     "Returns the stream that will be used for *error-output* for the FRAME."))
124     (defgeneric frame-pointer-documentation-output (frame)
125     (:documentation
126     "Returns the stream that will be used for *pointer-documentation-output*
127     for the FRAME."))
128     (defgeneric frame-calling-frame (frame)
129     (:documentation
130     "Returns the application frame that invoked the FRAME."))
131     (defgeneric frame-parent (frame)
132     (:documentation
133     "Returns the object that acts as the parent for the FRAME."))
134     ;(defgeneric frame-pane (frame) ; XXX Is it in Spec?
135     ; (:documentation
136     ; "Returns the pane that is the top-level pane in the current layout
137     ;of the FRAME's named panes."))
138     (defgeneric frame-top-level-sheet (frame)
139     (:documentation
140     "Returns the shhet that is the top-level sheet for the FRAME. This
141     is the sheet that has as its descendants all of the panes of the FRAME."))
142     (defgeneric frame-current-panes (frame)
143     (:documentation
144     "Returns a list of those named panes in the FRAME's current layout.
145     If there are no named panes, only the single, top level pane is returned."))
146     (defgeneric get-frame-pane (frame pane-name)
147     (:documentation
148     "Returns the named CLIM stream pane in the FRAME whose name is PANE-NAME."))
149     (defgeneric find-pane-named (frame pane-name)
150     (:documentation
151     "Returns the pane in the FRAME whose name is PANE-NAME."))
152     ;(defgeneric frame-current-layout (frame))
153     ;(defgeneric frame-all-layouts (frame)) ; XXX Is it in Spec?
154     (defgeneric layout-frame (frame &optional width height))
155 mikemac 1.22 (defgeneric frame-exit-frame (condition)
156     (:documentation
157     "Returns the frame that is being exited from associated with the
158     FRAME-EXIT condition."))
159 adejneka 1.13 (defgeneric frame-exit (frame) ; XXX Is it in Spec?
160     (:documentation
161     "Exits from the FRAME."))
162     (defgeneric pane-needs-redisplay (pane))
163     (defgeneric (setf pane-needs-redisplay) (value pane))
164     (defgeneric redisplay-frame-pane (frame pane &key force-p))
165     (defgeneric redisplay-frame-panes (frame &key force-p))
166     (defgeneric frame-replay (frame stream &optional region))
167     (defgeneric notify-user (frame message &key associated-window title
168     documentation exit-boxes name style text-style))
169     ;(defgeneric frame-properties (frame property))
170     ;(defgeneric (setf frame-properties) (value frame property))
171    
172 brian 1.54 ; extension
173     (defgeneric frame-schedule-timer-event (frame sheet delay token))
174 adejneka 1.13
175 hefner1 1.68 (defgeneric note-input-focus-changed (pane state)
176     (:documentation "Called when a pane receives or loses the keyboard
177     input focus. This is a McCLIM extension."))
178    
179 mikemac 1.1 (defclass standard-application-frame (application-frame)
180 moore 1.38 ((event-queue :initarg :frame-event-queue
181 hefner1 1.66 :initarg :input-buffer
182     :initform nil
183 moore 1.38 :accessor frame-event-queue
184     :documentation "The event queue that, by default, will be
185 moore 1.47 shared by all panes in the stream")
186     (documentation-state :accessor frame-documentation-state
187     :initform nil
188     :documentation "Used to keep of track of what
189     needs to be rendered in the pointer documentation frame.")))
190 moore 1.38
191     ;;; Support the :input-buffer initarg for compatibility with "real CLIM"
192    
193     (defmethod initialize-instance :after ((obj standard-application-frame)
194 hefner1 1.66 &key &allow-other-keys)
195     (unless (frame-event-queue obj)
196     (setf (frame-event-queue obj) (make-instance 'standard-event-queue))))
197 moore 1.38
198 mikemac 1.1
199     (defmethod (setf frame-manager) (fm (frame application-frame))
200     (let ((old-manager (frame-manager frame)))
201 adejneka 1.46 (setf (%frame-manager frame) nil)
202 mikemac 1.1 (when old-manager
203     (disown-frame old-manager frame)
204     (setf (slot-value frame 'panes) nil)
205     (setf (slot-value frame 'layouts) nil))
206 adejneka 1.46 (setf (%frame-manager frame) fm)))
207 mikemac 1.1
208     (defmethod (setf frame-current-layout) (name (frame application-frame))
209     (declare (ignore name))
210     (generate-panes (frame-manager frame) frame))
211    
212     (defmethod generate-panes :before (fm (frame application-frame))
213     (declare (ignore fm))
214     (when (and (slot-boundp frame 'pane)
215     (frame-pane frame))
216     (sheet-disown-child (frame-top-level-sheet frame) (frame-pane frame))))
217    
218     (defmethod generate-panes :after (fm (frame application-frame))
219     (declare (ignore fm))
220     (sheet-adopt-child (frame-top-level-sheet frame) (frame-pane frame))
221 cvs 1.5 (sheet-adopt-child (graft frame) (frame-top-level-sheet frame))
222 mikemac 1.69 (let* ((space (compose-space (frame-top-level-sheet frame)))
223     (bbox (or (slot-value frame 'user-supplied-geometry)
224     (make-bounding-rectangle 0 0
225     (space-requirement-width space)
226     (space-requirement-height space)))))
227 cvs 1.5 ;; automatically generates a window-configuation-event
228     ;; which then calls allocate-space
229 gilbert 1.39 ;;
230     ;; Not any longer, we turn of CONFIGURE-NOTIFY events until the
231     ;; window is mapped and do the space allocation now, so that all
232     ;; sheets will have their correct geometry at once. --GB
233 mikemac 1.1 (setf (sheet-region (frame-top-level-sheet frame))
234 mikemac 1.69 bbox)
235 gilbert 1.39 (allocate-space (frame-top-level-sheet frame)
236 mikemac 1.69 (bounding-rectangle-width bbox)
237     (bounding-rectangle-height bbox))
238     ))
239 mikemac 1.1
240     (defmethod layout-frame ((frame application-frame) &optional width height)
241     (let ((pane (frame-pane frame)))
242     (if (and width (not height))
243     (error "LAYOUT-FRAME must be called with both WIDTH and HEIGHT or neither"))
244     (if (and (null width) (null height))
245 hatchond 1.11 (let ((space (compose-space pane)))
246 mikemac 1.1 (setq width (space-requirement-width space))
247     (setq height (space-requirement-height space))))
248 gilbert 1.63 (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 mikemac 1.1 (allocate-space pane width height)))
253    
254 adejneka 1.13 (defun find-pane-if (predicate panes)
255     "Returns a pane satisfying PREDICATE in the forest growing from PANES"
256 moore 1.27 (loop for pane in panes
257     do (map-over-sheets #'(lambda (p)
258     (when (funcall predicate p)
259     (return-from find-pane-if p)))
260     pane)
261     finally (return nil)))
262    
263 adejneka 1.13 (defun find-pane-of-type (panes type)
264     (find-pane-if #'(lambda (pane) (typep pane type)) panes))
265 adejneka 1.40
266 adejneka 1.13 (defmethod frame-current-panes ((frame application-frame))
267     (find-pane-if #'(lambda (pane) (pane-name pane))
268     (frame-current-layout frame)))
269    
270     (defmethod get-frame-pane ((frame application-frame) pane-name)
271     (find-pane-if #'(lambda (pane)
272     (and (typep pane 'clim-stream-pane)
273     (eq pane-name
274     (pane-name pane))))
275     (frame-panes frame)))
276    
277     (defmethod find-pane-named ((frame application-frame) pane-name)
278     (find-pane-if #'(lambda (pane)
279     (eq pane-name
280     (pane-name pane)))
281     (frame-panes frame)))
282    
283 mikemac 1.1 (defmethod frame-standard-output ((frame application-frame))
284 cvs 1.6 (or (find-pane-of-type (frame-panes frame) 'application-pane)
285     (find-pane-of-type (frame-panes frame) 'interactor-pane)))
286 mikemac 1.1
287     (defmethod frame-standard-input ((frame application-frame))
288 cvs 1.6 (or (find-pane-of-type (frame-panes frame) 'interactor-pane)
289 mikemac 1.1 (frame-standard-output frame)))
290    
291     (defmethod frame-query-io ((frame application-frame))
292     (or (frame-standard-input frame)
293     (frame-standard-output frame)))
294    
295     (defmethod frame-error-output ((frame application-frame))
296     (frame-standard-output frame))
297    
298     (defvar *pointer-documentation-output* nil)
299    
300     (defmethod frame-pointer-documentation-output ((frame application-frame))
301 adejneka 1.13 (find-pane-of-type (frame-panes frame) 'pointer-documentation-pane))
302 mikemac 1.1
303 hefner1 1.70 (defmethod redisplay-frame-panes ((frame application-frame) &key force-p)
304     (map-over-sheets
305     (lambda (sheet)
306     (when (typep sheet 'pane)
307     (when (and (typep sheet 'clim-stream-pane)
308     (not (eq :no-clear (pane-redisplay-needed sheet))))
309     (window-clear sheet))
310     (redisplay-frame-pane frame sheet :force-p force-p)))
311     (frame-top-level-sheet frame)))
312    
313 mikemac 1.1 ;;; Command loop interface
314    
315 mikemac 1.22 (define-condition frame-exit (condition)
316 moore 1.26 ((frame :initarg :frame :reader %frame-exit-frame)))
317 mikemac 1.22
318 hefner1 1.66 ;; I make the assumption here that the contents of *application-frame* is
319     ;; the frame the top-level loop is running. With the introduction of
320     ;; window-stream frames that may be sharing the event queue with the main
321     ;; application frame, we need to discriminate between them here to avoid
322     ;; shutting down the application at the wrong time.
323     ;; ...
324     ;; A better way to do this would be to make the handler bound in
325     ;; run-frame-top-level check whether the frame signalled is the one
326     ;; it was invoked on.. -- Hefner
327    
328 mikemac 1.22 (defmethod frame-exit ((frame standard-application-frame))
329 hefner1 1.66 (if (eq *application-frame* frame)
330     (signal 'frame-exit :frame frame)
331     (disown-frame (frame-manager frame) frame)))
332 moore 1.26
333     (defmethod frame-exit-frame ((c frame-exit))
334     (%frame-exit-frame c))
335 mikemac 1.22
336 moore 1.59 (defmethod redisplay-frame-pane ((frame application-frame) pane &key force-p)
337     (declare (ignore pane force-p))
338     nil)
339    
340 adejneka 1.44 (defmethod run-frame-top-level ((frame application-frame) &key &allow-other-keys)
341 mikemac 1.22 (handler-bind ((frame-exit #'(lambda (condition)
342 gilbert 1.31 (declare (ignore condition))
343 mikemac 1.22 (return-from run-frame-top-level nil))))
344     (apply (first (frame-top-level frame)) frame (rest (frame-top-level frame)))))
345 mikemac 1.1
346 adejneka 1.44 (defmethod run-frame-top-level :around ((frame application-frame) &key)
347 mikemac 1.1 (let ((*application-frame* frame)
348     (*input-context* nil)
349     (*input-wait-test* nil)
350     (*input-wait-handler* nil)
351 moore 1.52 (*pointer-button-press-handler* nil)
352     (original-state (frame-state frame)))
353 mikemac 1.1 (declare (special *input-context* *input-wait-test* *input-wait-handler*
354     *pointer-button-press-handler*))
355 moore 1.52 (when (eq (frame-state frame) :disowned)
356     (adopt-frame (or (frame-manager frame) (find-frame-manager))
357     frame))
358     (unless (or (eq (frame-state frame) :enabled)
359     (eq (frame-state frame) :shrunk))
360     (enable-frame frame))
361 moore 1.24 (let ((query-io (frame-query-io frame)))
362 moore 1.52 (unwind-protect
363     (if query-io
364 hefner1 1.66 (with-input-focus (query-io)
365 moore 1.52 (call-next-method))
366     (call-next-method))
367     (case original-state
368     (:disabled
369     (disable-frame frame))
370     (:disowned
371     (disown-frame (frame-manager frame) frame)))))))
372 mikemac 1.1
373     (defmethod default-frame-top-level
374     ((frame application-frame)
375     &key (command-parser 'command-line-command-parser)
376     (command-unparser 'command-line-command-unparser)
377     (partial-command-parser
378     'command-line-read-remaining-arguments-for-partial-command)
379 moore 1.35 (prompt "Command: "))
380 mikemac 1.20 (loop
381     (let ((*standard-input* (frame-standard-input frame))
382     (*standard-output* (frame-standard-output frame))
383     (*query-io* (frame-query-io frame))
384 moore 1.47 (*pointer-documentation-output* (frame-pointer-documentation-output
385     frame))
386 mikemac 1.20 ;; during development, don't alter *error-output*
387 gilbert 1.39 ;; (*error-output* (frame-error-output frame))
388 mikemac 1.20 (*command-parser* command-parser)
389     (*command-unparser* command-unparser)
390     (*partial-command-parser* partial-command-parser)
391 gilbert 1.39 (prompt-style (make-text-style :fix :italic :normal)))
392 mikemac 1.20 (map-over-sheets #'(lambda (pane)
393 moore 1.59 (multiple-value-bind (redisplayp clearp)
394     (pane-needs-redisplay pane)
395     (when redisplayp
396     (when (and clearp
397     (or (not (pane-incremental-redisplay
398     pane))
399     (not *enable-updating-output*)))
400     (window-clear pane))
401     (redisplay-frame-pane frame pane)
402     (unless (eq redisplayp :command-loop)
403     (setf (pane-needs-redisplay pane) nil)))))
404 mikemac 1.20 (frame-top-level-sheet frame))
405     (when *standard-input*
406 hefner1 1.68 ;; We don't need to turn the cursor on here, as Goatee has its own
407     ;; cursor which will appear. In fact, as a sane interface policy,
408     ;; leave it off by default, and hopefully this doesn't violate the spec.
409     (setf (cursor-visibility (stream-text-cursor *standard-input*)) nil)
410 mikemac 1.21 (when prompt
411     (with-text-style (*standard-input* prompt-style)
412     (if (stringp prompt)
413 moore 1.35 (write-string prompt *standard-input*)
414     (funcall prompt *standard-input* frame))
415 adejneka 1.40 (finish-output *standard-input*)))
416 moore 1.35 (let ((command (read-frame-command frame)))
417     (fresh-line *standard-input*)
418     (when command
419     (execute-frame-command frame command))
420     (fresh-line *standard-input*))))))
421    
422 mikemac 1.1
423 moore 1.64 (defmethod read-frame-command ((frame application-frame)
424     &key (stream *standard-input*))
425     (with-input-context ('menu-item)
426     (object)
427     ;; Is this the intended behavior of interactor-panes
428     ;; (vs. application panes)?
429     (if (typep stream 'interactor-pane)
430     (read-command (frame-command-table frame) :stream stream)
431     (loop (read-gesture :stream stream)))
432     (menu-item
433     (let ((command (command-menu-item-value object)))
434     (if (listp command)
435     command
436     (list command))))))
437    
438 mikemac 1.1
439     (defmethod execute-frame-command ((frame application-frame) command)
440 moore 1.35 (apply (command-name command) (command-arguments command)))
441    
442 mikemac 1.1 (defmethod make-pane-1 ((fm frame-manager) (frame application-frame) type &rest args)
443     `(make-pane-1 ,fm ,frame ',type ,@args))
444 moore 1.38
445     (defmethod make-pane-1 :around (fm (frame standard-application-frame) type
446     &rest args
447 moore 1.51 &key (input-buffer nil input-buffer-p)
448     &allow-other-keys)
449 moore 1.38 "Default input-buffer to the frame event queue."
450     (if input-buffer-p
451     (call-next-method)
452     (apply #'call-next-method fm frame type
453     :input-buffer (frame-event-queue frame)
454     args)))
455 mikemac 1.1
456     (defmethod adopt-frame ((fm frame-manager) (frame application-frame))
457     (setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
458     (setf (frame-manager frame) fm)
459 moore 1.52 (setf (port frame) (frame-manager-port fm))
460     (setf (graft frame) (find-graft :port (port frame)))
461 mikemac 1.1 (let* ((*application-frame* frame)
462 cvs 1.4 (t-l-s (make-pane-1 fm frame 'top-level-sheet-pane
463 moore 1.52 :name 'top-level-sheet
464     ;; enabling should be left to enable-frame
465     :enabled-p nil)))
466 mikemac 1.1 (setf (slot-value frame 'top-level-sheet) t-l-s)
467 moore 1.52 (generate-panes fm frame)
468     (setf (slot-value frame 'state) :disabled)
469     frame))
470 brian 1.28
471 mikemac 1.1 (defmethod disown-frame ((fm frame-manager) (frame application-frame))
472     (setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
473     (sheet-disown-child (graft frame) (frame-top-level-sheet frame))
474 moore 1.52 (setf (%frame-manager frame) nil)
475     (setf (slot-value frame 'state) :disowned)
476     frame)
477    
478     (defgeneric enable-frame (frame))
479     (defgeneric disable-frame (frame))
480    
481     (defgeneric note-frame-enabled (frame-manager frame))
482     (defgeneric note-frame-disbled (frame-manager frame))
483    
484     (defmethod enable-frame ((frame application-frame))
485     (setf (sheet-enabled-p (frame-top-level-sheet frame)) t)
486     (setf (slot-value frame 'state) :enabled)
487     (note-frame-enabled (frame-manager frame) frame))
488    
489     (defmethod disable-frame ((frame application-frame))
490     (setf (sheet-enabled-p (frame-top-level-sheet frame)) nil)
491     (setf (slot-value frame 'state) :disabled)
492     (note-frame-disabled (frame-manager frame) frame))
493    
494     (defmethod note-frame-enabled ((fm frame-manager) frame)
495     (declare (ignore frame))
496     t)
497    
498     (defmethod note-frame-disabled ((fm frame-manager) frame)
499     t)
500 mikemac 1.1
501 cvs 1.8 (defvar *pane-realizer* nil)
502    
503 mikemac 1.1 (defmacro with-look-and-feel-realization ((frame-manager frame) &body body)
504 cvs 1.8 `(let ((*pane-realizer* ,frame-manager)
505     (*application-frame* ,frame))
506 adejneka 1.45 (locally
507     ,@body)))
508 mikemac 1.1
509 brian 1.28 ; The menu-bar code in the following two functions is incorrect.
510     ; it needs to be moved to somewhere after the backend, since
511     ; it depends on the backend chosen.
512     ;
513     ; This hack slaps a menu-bar into the start of the application-frame,
514     ; in such a way that it is hard to find.
515     ;
516     ; FIXME
517     (defun make-single-pane-generate-panes-form (class-name menu-bar pane)
518 mikemac 1.1 `(defmethod generate-panes ((fm frame-manager) (frame ,class-name))
519 brian 1.28 ; v-- hey, how can this be?
520 moore 1.17 (with-look-and-feel-realization (fm frame)
521 brian 1.28 (let ((pane ,(cond
522     ((eq menu-bar t)
523     `(vertically () (clim-internals::make-menu-bar
524     ',class-name)
525     ,pane))
526 brian 1.32 ((consp menu-bar)
527 brian 1.28 `(vertically () (clim-internals::make-menu-bar
528     (make-command-table nil
529     :menu ',menu-bar))
530     ,pane))
531     (menu-bar
532     `(vertically () (clim-internals::make-menu-bar
533     ',menu-bar)
534     ,pane))
535 gilbert 1.31 ;; The form below is unreachable with (listp
536     ;; menu-bar) instead of (consp menu-bar) above
537     ;; --GB
538 brian 1.28 (t pane))))
539     (setf (slot-value frame 'pane) pane)))))
540 mikemac 1.1
541 brian 1.28 ; could do with some refactoring [BTS] FIXME
542 moore 1.47 (defun make-panes-generate-panes-form (class-name menu-bar panes layouts
543     pointer-documentation)
544     (when pointer-documentation
545     (setf panes (append panes
546     '((%pointer-documentation%
547     pointer-documentation-pane)))))
548 mikemac 1.1 `(defmethod generate-panes ((fm frame-manager) (frame ,class-name))
549     (let ((*application-frame* frame))
550 cvs 1.8 (with-look-and-feel-realization (fm frame)
551     (let ,(loop for (name . form) in panes
552     collect `(,name (or (find-pane-named frame ',name)
553     (let ((pane
554     ,(cond
555     ((and (= (length form) 1)
556     (listp (first form)))
557     (first form))
558     ((keywordp (first form))
559     (let ((maker (intern (concatenate 'string
560 mikemac 1.62 (symbol-name '#:make-clim-)
561 cvs 1.8 (symbol-name (first form))
562 mikemac 1.62 (symbol-name '#:-pane))
563 mikemac 1.61 :clim)))
564 cvs 1.8 (if (fboundp maker)
565     `(,maker :name ',name ,@(cdr form))
566     `(make-pane ',(first form)
567     :name ',name ,@(cdr form)))))
568     (t `(make-pane ',(first form) :name ',name ,@(cdr form))))))
569 gilbert 1.19 ;; hmm?! --GB
570     (setf (slot-value pane 'name) ',name)
571     ;;
572 cvs 1.8 (push pane (slot-value frame 'panes))
573     pane))))
574 brian 1.28 ; [BTS] added this, but is not sure that this is correct for adding
575     ; a menu-bar transparently, should also only be done where the
576     ; exterior window system does not support menus
577 moore 1.47 ,(if (or menu-bar pointer-documentation)
578 brian 1.28 `(setf (slot-value frame 'pane)
579     (ecase (frame-current-layout frame)
580     ,@(mapcar (lambda (layout)
581 moore 1.47 `(,(first layout)
582     (vertically ()
583     ,@(cond
584     ((eq menu-bar t)
585     `((clim-internals::make-menu-bar
586     ',class-name)))
587     ((consp menu-bar)
588 gilbert 1.55 `((clim-internals::make-menu-bar
589 moore 1.47 (make-command-table
590     nil
591 gilbert 1.55 :menu ',menu-bar))))
592 moore 1.47 (menu-bar
593     `((clim-internals::make-menu-bar
594     ',menu-bar)))
595     (t nil))
596     ,@(rest layout)
597     ,@(when pointer-documentation
598     '(%pointer-documentation%)))))
599 brian 1.28 layouts)))
600     `(setf (slot-value frame 'pane)
601     (ecase (frame-current-layout frame)
602     ,@layouts))))))))
603 mikemac 1.1
604     (defmacro define-application-frame (name superclasses slots &rest options)
605     (if (null superclasses)
606     (setq superclasses '(standard-application-frame)))
607     (let ((pane nil)
608     (panes nil)
609     (layouts nil)
610     (current-layout nil)
611 mikemac 1.23 (command-table (list name))
612 mikemac 1.1 (menu-bar t)
613     (disabled-commands nil)
614     (command-definer t)
615     (top-level '(default-frame-top-level))
616     (others nil)
617 mikemac 1.61 (command-name (intern (concatenate 'string
618 mikemac 1.62 (symbol-name '#:define-)
619 mikemac 1.61 (symbol-name name)
620 mikemac 1.62 (symbol-name '#:-command))))
621 mikemac 1.69 (pointer-documentation nil)
622     (geometry nil))
623 mikemac 1.1 (loop for (prop . values) in options
624     do (case prop
625     (:pane (setq pane (first values)))
626     (:panes (setq panes values))
627     (:layouts (setq layouts values))
628     (:command-table (setq command-table (first values)))
629 brian 1.28 (:menu-bar (setq menu-bar (if (listp values)
630     (first values)
631     values)))
632 mikemac 1.1 (:disabled-commands (setq disabled-commands values))
633     (:command-definer (setq command-definer (first values)))
634     (:top-level (setq top-level (first values)))
635 moore 1.47 (:pointer-documentation (setq pointer-documentation (car values)))
636 mikemac 1.69 (:geometry (setq geometry values))
637 mikemac 1.1 (t (push (cons prop values) others))))
638     (if (or (and pane panes)
639     (and pane layouts))
640     (error ":pane cannot be specified along with either :panes or :layouts"))
641     (if pane
642     (setq panes (list 'single-pane pane)
643 moore 1.17 layouts `((:default ,(car pane)))))
644 mikemac 1.1 (setq current-layout (first (first layouts)))
645     `(progn
646     (defclass ,name ,superclasses
647     ,slots
648     (:default-initargs
649     :name ',name
650     :pretty-name ,(string-capitalize name)
651 mikemac 1.23 :command-table (find-command-table ',(first command-table))
652 mikemac 1.1 :disabled-commands ',disabled-commands
653 brian 1.28 :menu-bar ',menu-bar
654 mikemac 1.1 :current-layout ',current-layout
655     :layouts ',layouts
656     :top-level ',top-level
657     )
658     ,@others)
659 mikemac 1.69 ,@(if geometry
660     `((setf (get ',name 'application-frame-geometry) ',geometry)))
661 mikemac 1.1 ,(if pane
662 brian 1.28 (make-single-pane-generate-panes-form name menu-bar pane)
663 moore 1.47 (make-panes-generate-panes-form name menu-bar panes layouts
664     pointer-documentation))
665 mikemac 1.23 ,@(if command-table
666     `((define-command-table ,@command-table)))
667 mikemac 1.1 ,@(if command-definer
668     `((defmacro ,command-name (name-and-options arguements &rest body)
669     (let ((name (if (listp name-and-options) (first name-and-options) name-and-options))
670 mikemac 1.23 (options (if (listp name-and-options) (cdr name-and-options) nil))
671     (command-table ',(first command-table)))
672     `(define-command (,name :command-table ,command-table ,@options) ,arguements ,@body))))))))
673 mikemac 1.1
674 mikemac 1.69 (defun get-application-frame-geometry (name indicator)
675     (let ((geometry (get name 'application-frame-geometry)))
676     (if geometry
677     (getf geometry indicator nil))))
678    
679     (defun compose-user-supplied-geometry (left top right bottom width height)
680     (flet ((compute-range (min max diff)
681     (cond
682     ((and min max)
683     (values min max))
684     ((and min diff)
685     (values min (+ min diff)))
686     ((and max diff)
687     (values (- max diff) max))
688     (t
689     (values nil nil)))))
690     (multiple-value-bind (x1 x2) (compute-range left right width)
691     (multiple-value-bind (y1 y2) (compute-range top bottom height)
692     (if (and x1 x2 y1 y2)
693     (make-bounding-rectangle x1 y1 x2 y2)
694     nil)))))
695    
696 mikemac 1.1 (defun make-application-frame (frame-name
697     &rest options
698 moore 1.52 &key (pretty-name
699     (string-capitalize frame-name))
700     (frame-manager nil frame-manager-p)
701     enable
702     (state nil state-supplied-p)
703 mikemac 1.69 (left (get-application-frame-geometry frame-name :left))
704     (top (get-application-frame-geometry frame-name :top))
705     (right (get-application-frame-geometry frame-name :right))
706     (bottom (get-application-frame-geometry frame-name :bottom))
707     (width (get-application-frame-geometry frame-name :width))
708     (height (get-application-frame-geometry frame-name :height))
709 moore 1.52 save-under (frame-class frame-name)
710 mikemac 1.1 &allow-other-keys)
711 mikemac 1.69 (declare (ignore save-under))
712 moore 1.52 (with-keywords-removed (options (:pretty-name :frame-manager :enable :state
713     :left :top :right :bottom :width :height
714 moore 1.53 :save-under :frame-class))
715 moore 1.52 (let ((frame (apply #'make-instance frame-class
716 mikemac 1.69 :name frame-name
717     :pretty-name pretty-name
718     :user-supplied-geometry (compose-user-supplied-geometry
719     left top right bottom width height)
720     options)))
721 moore 1.52 (when frame-manager-p
722     (adopt-frame frame-manager frame))
723     (cond ((or enable (eq state :enabled))
724     (enable-frame frame))
725     ((and (eq state :disowned)
726     (not (eq (frame-state frame) :disowned)))
727     (disown-frame (frame-manager frame) frame))
728     (state-supplied-p
729     (warn ":state ~S not supported yet." state)))
730     frame)))
731 cvs 1.4
732 cvs 1.7 ;;; Menu frame class
733    
734     (defclass menu-frame ()
735     ((left :initform 0 :initarg :left)
736     (top :initform 0 :initarg :top)
737     (top-level-sheet :initform nil :reader frame-top-level-sheet)
738     (pane :reader frame-pane :initarg :pane)
739     (graft :initform nil :accessor graft)
740     (manager :initform nil :accessor frame-manager)))
741 adejneka 1.46
742 cvs 1.7 (defmethod adopt-frame ((fm frame-manager) (frame menu-frame))
743     (setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
744 adejneka 1.46 (setf (frame-manager frame) fm)
745 brian 1.54 (let* ((t-l-s (make-pane-1 fm *application-frame*
746     'unmanaged-top-level-sheet-pane
747 cvs 1.7 :name 'top-level-sheet)))
748     (setf (slot-value frame 'top-level-sheet) t-l-s)
749     (sheet-adopt-child t-l-s (frame-pane frame))
750     (let ((graft (find-graft :port (frame-manager-port fm))))
751     (sheet-adopt-child graft t-l-s)
752     (setf (graft frame) graft))
753 hatchond 1.11 (let ((space (compose-space t-l-s)))
754 cvs 1.7 (allocate-space (frame-pane frame)
755     (space-requirement-width space)
756     (space-requirement-height space))
757     (setf (sheet-region t-l-s)
758     (make-bounding-rectangle 0 0
759     (space-requirement-width space)
760     (space-requirement-height space))))
761     (setf (sheet-transformation t-l-s)
762     (make-translation-transformation (slot-value frame 'left)
763     (slot-value frame 'top)))))
764    
765     (defmethod disown-frame ((fm frame-manager) (frame menu-frame))
766     (setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
767     (sheet-disown-child (graft frame) (frame-top-level-sheet frame))
768     (setf (frame-manager frame) nil))
769    
770     (defun make-menu-frame (pane &key (left 0) (top 0))
771     (make-instance 'menu-frame :pane pane :left left :top top))
772 moore 1.18
773     ;;; Frames and presentations
774    
775     (defmethod frame-find-innermost-applicable-presentation
776     ((frame standard-application-frame) input-context stream x y
777     &key event)
778     (find-innermost-applicable-presentation input-context stream
779     x y
780     :frame frame :event event))
781    
782 adejneka 1.41 (defmethod frame-input-context-button-press-handler
783 moore 1.18 ((frame standard-application-frame)
784     (stream output-recording-stream)
785     button-press-event)
786     (let ((presentation (find-innermost-applicable-presentation
787     *input-context*
788     stream
789     (pointer-event-x button-press-event)
790     (pointer-event-y button-press-event)
791 moore 1.37 :frame frame
792     :event button-press-event)))
793 moore 1.18 (when presentation
794     (throw-highlighted-presentation presentation
795     *input-context*
796     button-press-event))))
797    
798     (defmethod frame-input-context-button-press-handler
799     ((frame standard-application-frame) stream button-press-event)
800 mikemac 1.36 (declare (ignore stream button-press-event))
801 moore 1.27 nil)
802 moore 1.18
803 moore 1.47 (defgeneric frame-update-pointer-documentation
804     (frame input-context stream event))
805    
806     (defconstant +button-documentation+ '((#.+pointer-left-button+ "L")
807     (#.+pointer-middle-button+ "M")
808     (#.+pointer-right-button+ "R")))
809    
810 moore 1.48 (defconstant +modifier-documentation+
811     '((#.+shift-key+ "sh" "Shift")
812     (#.+control-key+ "c" "Control")
813     (#.+meta-key+ "m" "Meta")
814     (#.+super-key+ "s" "Super")
815     (#.+hyper-key+ "h" "Hyper")))
816    
817     ;;; Give a coherent order to sets of modifier combinations. Multi-key combos
818     ;;; come after single keys.
819    
820     (defun cmp-modifiers (a b)
821     (let ((cnt-a (logcount a))
822     (cnt-b (logcount b)))
823     (cond ((eql cnt-a cnt-b)
824     (< a b))
825     (t (< cnt-a cnt-b)))))
826    
827     (defun print-modifiers (stream modifiers style)
828 moore 1.49 (if (zerop modifiers)
829     (when (eq style :long)
830     (write-string "<nothing>" stream))
831     (loop with trailing = nil
832     for (bit short long) in +modifier-documentation+
833     when (logtest bit modifiers)
834     do (progn
835     (format stream "~:[~;-~]~A" trailing (if (eq style :short)
836     short
837     long))
838     (setq trailing t)))))
839 moore 1.48
840    
841     ;;; We don't actually want to print out the translator documentation and redraw
842     ;;; the pointer documentation window on every motion event. So, we compute a
843     ;;; state object (basically modifier state and a list of the applicable
844     ;;; presentation, translator and input context on each mouse button),
845     ;;; compare it to the previous state object, and only write out documentation
846     ;;; if they are different. I suppose it's possible that this state object
847     ;;; doesn't capture all possible documentation changes -- the doc generator is
848     ;;; a function, after all -- but that's just tough.
849     ;;;
850     ;;; It would be nice to evolve this into a protocol so that elements other than
851     ;;; presentations -- menu choices, for example -- could influence pointer
852     ;;; documentation window.
853    
854 moore 1.50 (defgeneric frame-compute-pointer-documentation-state
855     (frame input-context stream event)
856     (:documentation
857     "Compute a state object that will be used to generate pointer documentation."))
858    
859     (defmethod frame-compute-pointer-documentation-state
860     ((frame standard-application-frame) input-context stream event)
861     (let* ((current-modifier (event-modifier-state event))
862     (x (device-event-x event))
863     (y (device-event-y event))
864     (new-translators
865     (loop for (button) in +button-documentation+
866     for context-list = (multiple-value-list
867     (find-innermost-presentation-context
868     input-context
869     stream
870     x y
871     :modifier-state current-modifier
872     :button button))
873     when (car context-list)
874     collect (cons button context-list))))
875     (list current-modifier new-translators)))
876    
877     (defgeneric frame-compare-pointer-documentation-state
878     (frame input-context stream old-state new-state))
879    
880     (defmethod frame-compare-pointer-documentation-state
881     ((frame standard-application-frame) input-context stream
882     old-state new-state)
883     (equal old-state new-state))
884    
885     (defgeneric frame-print-pointer-documentation
886     (frame input-context stream state event))
887    
888     (defmethod frame-print-pointer-documentation
889     ((frame standard-application-frame) input-context stream state event)
890     (unless state
891     (return-from frame-print-pointer-documentation nil))
892     (destructuring-bind (current-modifier new-translators)
893     state
894     (let ((x (device-event-x event))
895     (y (device-event-y event))
896     (pstream *pointer-documentation-output*))
897     (loop for (button presentation translator context)
898     in new-translators
899     for name = (cadr (assoc button +button-documentation+))
900     for first-one = t then nil
901     do (progn
902     (unless first-one
903     (write-string "; " pstream))
904     (unless (zerop current-modifier)
905     (print-modifiers pstream current-modifier :short)
906     (write-string "-" pstream))
907     (format pstream "~A: " name)
908     (document-presentation-translator translator
909     presentation
910     (input-context-type context)
911     *application-frame*
912     event
913     stream
914     x y
915     :stream pstream
916     :documentation-type
917     :pointer))
918     finally (when new-translators
919     (write-char #\. pstream)))
920     ;; Wasteful to do this after doing
921     ;; find-innermost-presentation-context above... look at doing this
922     ;; first and then doing the innermost test.
923     (let ((all-translators (find-applicable-translators
924     (stream-output-history stream)
925     input-context
926     *application-frame*
927     stream
928     x y
929     :for-menu t))
930     (other-modifiers nil))
931     (loop for (translator) in all-translators
932     for gesture = (gesture translator)
933     unless (eq gesture t)
934     do (loop for (name type modifier) in gesture
935     unless (eql modifier current-modifier)
936     do (pushnew modifier other-modifiers)))
937     (when other-modifiers
938     (setf other-modifiers (sort other-modifiers #'cmp-modifiers))
939     (terpri pstream)
940     (write-string "To see other commands, press " pstream)
941     (loop for modifier-tail on other-modifiers
942     for (modifier) = modifier-tail
943     for count from 0
944     do (progn
945     (if (null (cdr modifier-tail))
946     (progn
947     (when (> count 1)
948     (write-char #\, pstream))
949     (when (> count 0)
950     (write-string " or " pstream)))
951     (when (> count 0)
952     (write-string ", " pstream)))
953     (print-modifiers pstream modifier :long)))
954     (write-char #\. pstream))))))
955    
956 moore 1.47 (defmethod frame-update-pointer-documentation
957     ((frame standard-application-frame) input-context stream event)
958     (when *pointer-documentation-output*
959     (with-accessors ((frame-documentation-state frame-documentation-state))
960     frame
961 moore 1.50 (let ((new-state (frame-compute-pointer-documentation-state frame
962     input-context
963     stream
964     event)))
965     (unless (frame-compare-pointer-documentation-state
966     frame
967     input-context
968     stream
969     frame-documentation-state
970     new-state)
971     (window-clear *pointer-documentation-output*)
972     (frame-print-pointer-documentation frame
973     input-context
974     stream
975     new-state
976     event)
977     (setq frame-documentation-state new-state))))))
978 moore 1.47
979 moore 1.18 (defmethod frame-input-context-track-pointer
980     ((frame standard-application-frame)
981     input-context
982     (stream output-recording-stream) event)
983     (declare (ignore input-context event))
984     nil)
985    
986     (defmethod frame-input-context-track-pointer
987     ((frame standard-application-frame) input-context stream event)
988 mikemac 1.36 (declare (ignore input-context stream event))
989 moore 1.27 nil)
990 moore 1.18
991     (defmethod frame-input-context-track-pointer :before
992     ((frame standard-application-frame) input-context stream event)
993 moore 1.47 (flet ((maybe-unhighlight (presentation)
994     (when (and (frame-hilited-presentation frame)
995     (not (eq presentation
996     (car (frame-hilited-presentation frame)))))
997     (highlight-presentation-1 (car (frame-hilited-presentation frame))
998     (cdr (frame-hilited-presentation frame))
999     :unhighlight))))
1000 moore 1.18 (if (output-recording-stream-p stream)
1001     (let ((presentation (find-innermost-applicable-presentation
1002     input-context
1003     stream
1004 moore 1.50 (device-event-x event)
1005     (device-event-y event)
1006 moore 1.37 :frame frame
1007     :modifier-state (event-modifier-state event))))
1008 moore 1.47 (maybe-unhighlight presentation)
1009 moore 1.34 (if presentation
1010     (when (not (eq presentation
1011     (car (frame-hilited-presentation frame))))
1012     (setf (frame-hilited-presentation frame)
1013     (cons presentation stream))
1014     (highlight-presentation-1 presentation stream :highlight))
1015 moore 1.47 (setf (frame-hilited-presentation frame) nil)))
1016     (progn
1017     (maybe-unhighlight nil)
1018     (setf (frame-hilited-presentation frame) nil))))
1019     (frame-update-pointer-documentation frame input-context stream event))
1020 moore 1.27
1021     (defun simple-event-loop ()
1022     "An simple event loop for applications that want all events to be handled by
1023     handle-event methods"
1024 adejneka 1.41 (let ((queue (frame-event-queue *application-frame*)))
1025     (loop for event = (event-queue-read queue)
1026     ;; EVENT-QUEUE-READ in single-process mode calls PROCESS-NEXT-EVENT itself.
1027     do (handle-event (event-sheet event) event))))
1028 moore 1.57
1029     ;;; Am I missing something? Does this need to do more? - moore
1030     (defmacro with-application-frame ((frame) &body body)
1031     `(let ((,frame *application-frame*))
1032     ,@body))
1033 hefner1 1.67
1034 hefner1 1.68
1035     (defmethod note-input-focus-changed (pane state)
1036     (declare (ignore pane state)))
1037    
1038 hefner1 1.67 (defmethod (setf keyboard-input-focus) :after (focus frame)
1039     (set-port-keyboard-focus focus (port frame)))
1040 hefner1 1.68

  ViewVC Help
Powered by ViewVC 1.1.5