-
Notifications
You must be signed in to change notification settings - Fork 6
/
frames.lisp
1692 lines (1545 loc) · 65.6 KB
/
frames.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; -*- Mode: Lisp; Package: CLIM-INTERNALS -*-
;;; (c) copyright 1998,1999,2000 by Michael McDonald ([email protected])
;;; (c) copyright 2000 by
;;; Iban Hatchondo ([email protected])
;;; Julien Boninfante ([email protected])
;;; Robert Strandh ([email protected])
;;; (c) copyright 2004 by
;;; Gilbert Baumann <[email protected]>
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
;;; License as published by the Free Software Foundation; either
;;; version 2 of the License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; Library General Public License for more details.
;;;
;;; You should have received a copy of the GNU Library General Public
;;; License along with this library; if not, write to the
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;;; Boston, MA 02111-1307 USA.
(in-package :clim-internals)
;; *application-frame* is in decls.lisp
(defvar *default-frame-manager* nil)
;;; Frame-Manager class
;; FIXME: The spec says the port must "conform to options".
;; I've added a check that the ports match, but we've no
;; protocol for testing the other options. -Hefner
(defun find-frame-manager (&rest options &key port &allow-other-keys)
(declare (special *frame-manager*))
(if (and (boundp '*frame-manager*)
(or (null port) (eql port (port *frame-manager*))))
*frame-manager*
(if (and *default-frame-manager*
(frame-manager-p *default-frame-manager*)
(or (null port) (eql port (port *default-frame-manager*))))
*default-frame-manager*
(first (frame-managers (or port (apply #'find-port options)))))))
(defmacro with-frame-manager ((frame-manager) &body body)
`(let ((*frame-manager* ,frame-manager))
(declare (special *frame-manager*))
(locally ,@body)))
;;; XXX These should force the redisplay of the menu bar. They don't
;;; yet.
(defmethod note-command-enabled (frame-manager frame command-name)
(declare (ignore frame-manager frame command-name))
nil)
(defmethod note-command-disabled (frame-manager frame command-name)
(declare (ignore frame-manager frame command-name))
nil)
;;; Application-Frame class
;;; XXX All these slots should move to a mixin or to standard-application-frame.
;;; -- moore
; extension
(defgeneric frame-schedule-timer-event (frame sheet delay token))
(defgeneric note-input-focus-changed (pane state)
(:documentation "Called when a pane receives or loses the keyboard
input focus. This is a McCLIM extension."))
(defclass standard-application-frame (application-frame
presentation-history-mixin)
((port :initform nil
:initarg :port
:accessor port)
(graft :initform nil
:initarg :graft
:accessor graft)
(name :initarg :name
:reader frame-name)
(pretty-name :initarg :pretty-name
:accessor frame-pretty-name)
(command-table :initarg :command-table
:initform nil
:accessor frame-command-table)
(named-panes :accessor frame-named-panes :initform nil)
(panes :initform nil :reader frame-panes
:documentation "The tree of panes in the current layout.")
(layouts :initform nil
:initarg :layouts
:reader frame-layouts)
(current-layout :initform nil
:initarg :current-layout
:accessor frame-current-layout)
(panes-for-layout :initform nil :accessor frame-panes-for-layout
:documentation "alist of names and panes (as returned by make-pane)")
(top-level-sheet :initform nil
:reader frame-top-level-sheet)
(menu-bar :initarg :menu-bar
:initform nil)
(state :initarg :state
:initform :disowned
:reader frame-state)
(manager :initform nil
:reader frame-manager
:accessor %frame-manager)
(properties :accessor %frame-properties
:initarg :properties
:initform nil)
(top-level :initform '(default-frame-top-level)
:initarg :top-level
:reader frame-top-level)
(top-level-lambda :initarg :top-level-lambda
:reader frame-top-level-lambda)
(hilited-presentation :initform nil
:initarg :hilited-presentation
:accessor frame-hilited-presentation)
(process :accessor frame-process :initform nil)
(client-settings :accessor client-settings :initform nil)
(event-queue :initarg :frame-event-queue
:initarg :input-buffer
:initform nil
:accessor frame-event-queue
:documentation "The event queue that, by default, will be
shared by all panes in the stream")
(documentation-state :accessor frame-documentation-state
:initform nil
:documentation "Used to keep of track of what
needs to be rendered in the pointer documentation frame.")
(calling-frame :reader frame-calling-frame
:initarg :calling-frame
:initform nil
:documentation "The frame that is the parent of this
frame, if any")
(disabled-commands :accessor disabled-commands
:accessor frame-disabled-commands
:initarg :disabled-commands
:initform nil
:documentation "A list of command names that have been
disabled in this frame")
(documentation-record :accessor documentation-record
:initform nil
:documentation "updating output record for pointer
documentation produced by presentations.")
(geometry-left :accessor geometry-left
:initarg :left
:initform nil)
(geometry-right :accessor geometry-right
:initarg :right
:initform nil)
(geometry-top :accessor geometry-top
:initarg :top
:initform nil)
(geometry-bottom :accessor geometry-bottom
:initarg :bottom
:initform nil)
(geometry-width :accessor geometry-width
:initarg :width
:initform nil)
(geometry-height :accessor geometry-height
:initarg :height
:initform nil)))
(defmethod frame-geometry* ((frame standard-application-frame))
"-> width height &optional top left"
(let ((pane (frame-top-level-sheet frame)))
;(destructuring-bind (&key left top right bottom width height) (frame-geometry frame)
(with-slots (geometry-left geometry-top geometry-right
geometry-bottom geometry-width
geometry-height) frame
;; Find width and height from looking at the respective options
;; first, then at left/right and top/bottom and finally at what
;; compose-space says.
(let* ((width (or geometry-width
(and geometry-left geometry-right
(- geometry-right geometry-left))
(space-requirement-width (compose-space pane))))
(height (or geometry-height
(and geometry-top geometry-bottom (- geometry-bottom geometry-top))
(space-requirement-height (compose-space pane))))
;; See if a position is wanted and return left, top.
(left (or geometry-left
(and geometry-right (- geometry-right geometry-width))))
(top (or geometry-top
(and geometry-bottom (- geometry-bottom geometry-height)))))
(values width height left top)))))
;;; Support the :input-buffer initarg for compatibility with "real CLIM"
(defmethod initialize-instance :after ((obj standard-application-frame)
&key &allow-other-keys)
(when (and (frame-calling-frame obj)
(null (frame-event-queue obj)))
(setf (frame-event-queue obj)
(frame-event-queue (frame-calling-frame obj))))
(unless (frame-event-queue obj)
(setf (frame-event-queue obj)
(make-instance 'port-event-queue))))
(defmethod (setf frame-manager) (fm (frame application-frame))
(let ((old-manager (frame-manager frame)))
(setf (%frame-manager frame) nil)
(when old-manager
(disown-frame old-manager frame)
(setf (slot-value frame 'panes) nil)
(setf (slot-value frame 'layouts) nil))
(setf (%frame-manager frame) fm)))
(define-condition frame-layout-changed (condition)
((frame :initarg :frame :reader frame-layout-changed-frame)))
(defmethod (setf frame-current-layout) :after (name (frame application-frame))
(declare (ignore name))
(when (frame-manager frame)
(generate-panes (frame-manager frame) frame)
(multiple-value-bind (w h) (frame-geometry* frame)
(layout-frame frame w h))
(signal 'frame-layout-changed :frame frame)))
(defmethod generate-panes :before (fm (frame application-frame))
(declare (ignore fm))
(when (and (frame-panes frame)
(eq (sheet-parent (frame-panes frame))
(frame-top-level-sheet frame)))
(sheet-disown-child (frame-top-level-sheet frame) (frame-panes frame)))
(loop
for (nil . pane) in (frame-panes-for-layout frame)
for parent = (sheet-parent pane)
if parent
do (sheet-disown-child parent pane)))
(defmethod generate-panes :after (fm (frame application-frame))
(declare (ignore fm))
(sheet-adopt-child (frame-top-level-sheet frame) (frame-panes frame))
(unless (sheet-parent (frame-top-level-sheet frame))
(sheet-adopt-child (graft frame) (frame-top-level-sheet frame)))
;; Find the size of the new frame
(multiple-value-bind (w h x y) (frame-geometry* frame)
(declare (ignore x y))
;; automatically generates a window-configuation-event
;; which then calls allocate-space
;;
;; Not any longer, we turn off CONFIGURE-NOTIFY events until the
;; window is mapped and do the space allocation now, so that all
;; sheets will have their correct geometry at once. --GB
(setf (sheet-region (frame-top-level-sheet frame))
(make-bounding-rectangle 0 0 w h))
(allocate-space (frame-top-level-sheet frame) w h) ))
(defmethod layout-frame ((frame application-frame) &optional width height)
(let ((pane (frame-panes frame)))
(when (and (or width height)
(not (and width height)))
(error "LAYOUT-FRAME must be called with both WIDTH and HEIGHT or neither"))
(if (and (null width) (null height))
(let ((space (compose-space pane))) ;I guess, this might be wrong. --GB 2004-06-01
(setq width (space-requirement-width space))
(setq height (space-requirement-height space))))
(let ((tpl-sheet (frame-top-level-sheet frame)))
(unless (and (= width (bounding-rectangle-width tpl-sheet))
(= height (bounding-rectangle-height tpl-sheet)))
(resize-sheet (frame-top-level-sheet frame) width height)))
(allocate-space pane width height)))
(defun find-pane-if (predicate panes)
"Returns a pane satisfying PREDICATE in the forest growing from PANES"
(map-over-sheets #'(lambda (p)
(when (funcall predicate p)
(return-from find-pane-if p)))
panes)
nil)
(defun find-pane-of-type (panes type)
(find-pane-if #'(lambda (pane) (typep pane type)) panes))
;;; There are several ways to do this; this isn't particularly efficient, but
;;; it shouldn't matter much. If it does, it might be better to map over the
;;; panes in frame-named-panes looking for panes with parents.
(defmethod frame-current-panes ((frame application-frame))
(let ((panes nil)
(named-panes (frame-named-panes frame)))
(map-over-sheets #'(lambda (p)
(when (member p named-panes)
(push p panes)))
(frame-panes frame))
panes))
(defmethod get-frame-pane ((frame application-frame) pane-name)
(let ((pane (find-pane-named frame pane-name)))
(if (typep pane 'clim-stream-pane)
pane
nil)))
(defmethod find-pane-named ((frame application-frame) pane-name)
(find pane-name (frame-named-panes frame) :key #'pane-name))
(defmethod frame-standard-output ((frame application-frame))
(or (find-pane-of-type (frame-panes frame) 'application-pane)
(find-pane-of-type (frame-panes frame) 'interactor-pane)))
(defmethod frame-standard-input ((frame application-frame))
(or (find-pane-of-type (frame-panes frame) 'interactor-pane)
(frame-standard-output frame)))
(defmethod frame-query-io ((frame application-frame))
(or (frame-standard-input frame)
(frame-standard-output frame)))
(defmethod frame-error-output ((frame application-frame))
(frame-standard-output frame))
(defvar *pointer-documentation-output* nil)
(defmethod frame-pointer-documentation-output ((frame application-frame))
(find-pane-of-type (frame-panes frame) 'pointer-documentation-pane))
#+nil
(defmethod redisplay-frame-panes ((frame application-frame) &key force-p)
(map-over-sheets
(lambda (sheet)
(when (typep sheet 'pane)
(when (and (typep sheet 'clim-stream-pane)
(not (eq :no-clear (pane-redisplay-needed sheet))))
(window-clear sheet))
(redisplay-frame-pane frame sheet :force-p force-p)))
(frame-top-level-sheet frame)))
(defmethod redisplay-frame-panes ((frame application-frame) &key force-p)
(map-over-sheets (lambda (sheet)
(redisplay-frame-pane frame sheet :force-p force-p))
(frame-top-level-sheet frame)))
(defmethod frame-replay (frame stream &optional region)
(declare (ignore frame))
(stream-replay stream region))
(defmethod frame-properties ((frame application-frame) property)
(getf (%frame-properties frame) property))
(defmethod (setf frame-properties) (value (frame application-frame) property)
(setf (getf (%frame-properties frame) property) value))
;;; Command loop interface
(define-condition frame-exit (condition)
((frame :initarg :frame :reader %frame-exit-frame)))
;; I make the assumption here that the contents of *application-frame* is
;; the frame the top-level loop is running. With the introduction of
;; window-stream frames that may be sharing the event queue with the main
;; application frame, we need to discriminate between them here to avoid
;; shutting down the application at the wrong time.
;; ...
;; A better way to do this would be to make the handler bound in
;; run-frame-top-level check whether the frame signalled is the one
;; it was invoked on.. -- Hefner
(defmethod frame-exit ((frame standard-application-frame))
(if (eq *application-frame* frame)
(signal 'frame-exit :frame frame)
(disown-frame (frame-manager frame) frame)))
(defmethod frame-exit-frame ((c frame-exit))
(%frame-exit-frame c))
(defmethod redisplay-frame-pane ((frame application-frame) pane &key force-p)
(declare (ignore pane force-p))
nil)
(defgeneric medium-invoke-with-possible-double-buffering (frame pane medium continuation))
(defmethod medium-invoke-with-possible-double-buffering (frame pane medium continuation)
(funcall continuation))
(defgeneric invoke-with-possible-double-buffering (frame pane continuation))
(defmethod invoke-with-possible-double-buffering (frame pane continuation)
(declare (ignore frame pane))
(funcall continuation))
(defmethod invoke-with-possible-double-buffering (frame (pane sheet-with-medium-mixin) continuation)
(medium-invoke-with-possible-double-buffering frame pane (sheet-medium pane) continuation))
(defmacro with-possible-double-buffering ((frame pane) &body body)
`(invoke-with-possible-double-buffering ,frame ,pane (lambda () ,@body)))
(defmethod redisplay-frame-pane :around ((frame application-frame) pane
&key force-p)
(let ((pane-object (if (typep pane 'pane)
pane
(find-pane-named frame pane))))
(restart-case
(multiple-value-bind (redisplayp clearp)
(pane-needs-redisplay pane-object)
(when force-p
(setq redisplayp (or redisplayp t)
clearp t))
(when redisplayp
(let ((hilited (frame-hilited-presentation frame)))
(when hilited
(highlight-presentation-1 (car hilited) (cdr hilited) :unhighlight)
(setf (frame-hilited-presentation frame) nil)))
(with-possible-double-buffering (frame pane-object)
(when clearp
(window-clear pane-object))
(call-next-method))
(unless (or (eq redisplayp :command-loop) (eq redisplayp :no-clear))
(setf (pane-needs-redisplay pane-object) nil))))
(clear-pane-try-again ()
:report "Clear the output history of the pane and reattempt forceful redisplay"
(window-clear pane)
(redisplay-frame-pane frame pane :force-p t))
(clear-pane ()
:report "Clear the output history of the pane, but don't redisplay"
(window-clear pane))
(skip-redisplay ()
:report "Skip this redisplay"))))
(defmethod run-frame-top-level ((frame application-frame)
&key &allow-other-keys)
(letf (((frame-process frame) (current-process)))
(handler-case
(funcall (frame-top-level-lambda frame) frame)
(frame-exit ()
nil))))
(defmethod run-frame-top-level :around ((frame application-frame) &key)
(let ((*application-frame* frame)
(*input-context* nil)
(*input-wait-test* nil)
(*input-wait-handler* nil)
(*pointer-button-press-handler* nil)
(original-state (frame-state frame)))
(declare (special *input-context* *input-wait-test* *input-wait-handler*
*pointer-button-press-handler*))
(when (eq (frame-state frame) :disowned) ; Adopt frame into frame manager
(adopt-frame (or (frame-manager frame) (find-frame-manager))
frame))
(unless (or (eq (frame-state frame) :enabled)
(eq (frame-state frame) :shrunk))
(enable-frame frame))
(unwind-protect
(loop
for query-io = (frame-query-io frame)
for *default-frame-manager* = (frame-manager frame)
do (handler-case
(return (if query-io
(with-input-focus (query-io)
(call-next-method))
(call-next-method)))
(frame-layout-changed () nil)))
(let ((fm (frame-manager frame)))
(case original-state
(:disabled
(disable-frame frame))
(:disowned
(disown-frame fm frame)))))))
(defparameter +default-prompt-style+ (make-text-style :sans-serif :bold :normal))
(defmethod default-frame-top-level
((frame application-frame)
&key (command-parser 'command-line-command-parser)
(command-unparser 'command-line-command-unparser)
(partial-command-parser
'command-line-read-remaining-arguments-for-partial-command)
(prompt "Command: "))
;; Give each pane a fresh start first time through.
(let ((first-time t))
(loop
;; The variables are rebound each time through the loop because the
;; values of frame-standard-input et al. might be changed by a command.
(let* ((*standard-input* (or (frame-standard-input frame)
*standard-input*))
(*standard-output* (or (frame-standard-output frame)
*standard-output*))
(query-io (frame-query-io frame))
(*query-io* (or query-io *query-io*))
(*pointer-documentation-output*
(frame-pointer-documentation-output frame))
;; during development, don't alter *error-output*
;; (*error-output* (frame-error-output frame))
(*command-parser* command-parser)
(*command-unparser* command-unparser)
(*partial-command-parser* partial-command-parser)
(interactorp (typep *query-io* 'interactor-pane)))
(restart-case
(progn
(redisplay-frame-panes frame :force-p first-time)
(setq first-time nil)
(if query-io
;; For frames with an interactor:
(progn
;; Hide cursor, so we don't need to toggle it during
;; command output.
(setf (cursor-visibility (stream-text-cursor *query-io*))
nil)
(when (and prompt interactorp)
(with-text-style (*query-io* +default-prompt-style+)
(if (stringp prompt)
(write-string prompt *query-io*)
(funcall prompt *query-io* frame))
(force-output *query-io*)))
(let ((command (read-frame-command frame
:stream *query-io*)))
(when interactorp
(fresh-line *query-io*))
(when command
(execute-frame-command frame command))
(when interactorp
(fresh-line *query-io*))))
;; Frames without an interactor:
(let ((command (read-frame-command frame :stream nil)))
(when command (execute-frame-command frame command)))))
(abort ()
:report "Return to application command loop"
(if interactorp
(format *query-io* "~&Command aborted.~&")
(beep))))))))
(defmethod read-frame-command :around ((frame application-frame)
&key (stream *standard-input*))
(with-input-context ('menu-item)
(object)
(call-next-method)
(menu-item
(let ((command (command-menu-item-value object))
(table (frame-command-table frame)))
(unless (listp command)
(setq command (partial-command-from-name command table)))
(if (partial-command-p command)
(funcall *partial-command-parser* table stream command 0)
command)))))
(defmethod read-frame-command ((frame application-frame)
&key (stream *standard-input*))
;; The following is the correct interpretation according to the spec.
;; I think it is terribly counterintuitive and want to look into
;; what existing CLIMs do before giving in to it.
;; If we do things as the spec says, command accelerators will
;; appear to not work, confusing new users.
#+NIL (read-command (frame-command-table frame) :use-keystrokes nil :stream stream)
(if stream
(read-command (frame-command-table frame) :use-keystrokes t :stream stream)
(simple-event-loop frame)))
(define-event-class execute-command-event (window-manager-event)
((sheet :initarg :sheet :reader event-sheet)
(command :initarg :command :reader execute-command-event-command)))
(defmethod execute-frame-command ((frame application-frame) command)
;; ### FIXME: I'd like a different method than checking for
;; *application-frame* to decide, which process processes which
;; frames command loop. Perhaps looking ath the process slot?
;; --GB 2005-11-28
(cond ((eq *application-frame* frame)
(restart-case
(apply (command-name command) (command-arguments command))
(try-again ()
:report (lambda (stream)
(format stream "Try executing the command ~A again"
(command-name command)))
(execute-frame-command frame command))))
(t
(let ((eq (sheet-event-queue (frame-top-level-sheet frame))))
(event-queue-append eq (make-instance 'execute-command-event
:sheet frame
:command command))))))
(defmethod handle-event ((frame application-frame) (event execute-command-event))
(execute-frame-command frame (execute-command-event-command event)))
(defmethod command-enabled (command-name (frame standard-application-frame))
(and (command-accessible-in-command-table-p command-name
(frame-command-table frame))
(not (member command-name (disabled-commands frame)))))
(defmethod (setf command-enabled)
(enabled command-name (frame standard-application-frame))
(unless (command-accessible-in-command-table-p command-name
(frame-command-table frame))
(return-from command-enabled nil))
(with-accessors ((disabled-commands disabled-commands))
frame
(if enabled
(progn
(setf disabled-commands (delete command-name disabled-commands))
(note-command-enabled (frame-manager frame)
frame
command-name)
enabled)
(progn
(pushnew command-name disabled-commands)
(note-command-disabled (frame-manager frame)
frame
command-name)
nil))))
(defmethod make-pane-1 :around (fm (frame standard-application-frame) type
&rest args
&key (input-buffer nil input-buffer-p)
(name nil namep)
&allow-other-keys)
(declare (ignore name input-buffer))
"Default input-buffer to the frame event queue."
(let ((pane (if input-buffer-p
(call-next-method)
(apply #'call-next-method fm frame type
:input-buffer (frame-event-queue frame)
args))))
(when namep
(push pane (frame-named-panes frame)))
pane))
(defmethod adopt-frame ((fm frame-manager) (frame application-frame))
(setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
(setf (frame-manager frame) fm)
(setf (port frame) (port fm))
(setf (graft frame) (find-graft :port (port frame)))
(let* ((*application-frame* frame)
(t-l-s (make-pane-1 fm frame 'top-level-sheet-pane
:name 'top-level-sheet
;; enabling should be left to enable-frame
:enabled-p nil))
#+clim-mp (event-queue (sheet-event-queue t-l-s)))
(setf (slot-value frame 'top-level-sheet) t-l-s)
(generate-panes fm frame)
(setf (slot-value frame 'state) :disabled)
#+clim-mp
(when (typep event-queue 'port-event-queue)
(setf (event-queue-port event-queue) (port fm)))
frame))
(defmethod disown-frame ((fm frame-manager) (frame application-frame))
#+CLIM-MP
(let* ((t-l-s (frame-top-level-sheet frame))
(queue (sheet-event-queue t-l-s)))
(when (typep queue 'port-event-queue)
(setf (event-queue-port queue) nil)))
(setf (slot-value fm 'frames) (remove frame (slot-value fm 'frames)))
(sheet-disown-child (graft frame) (frame-top-level-sheet frame))
(setf (%frame-manager frame) nil)
(setf (slot-value frame 'state) :disowned)
(port-force-output (port fm))
frame)
(defmethod enable-frame ((frame application-frame))
(setf (sheet-enabled-p (frame-top-level-sheet frame)) t)
(setf (slot-value frame 'state) :enabled)
(note-frame-enabled (frame-manager frame) frame))
(defmethod disable-frame ((frame application-frame))
(let ((t-l-s (frame-top-level-sheet frame)))
(setf (sheet-enabled-p t-l-s) nil)
(when (port t-l-s)
(port-force-output (port t-l-s))))
(setf (slot-value frame 'state) :disabled)
(note-frame-disabled (frame-manager frame) frame))
(defmethod destroy-frame ((frame application-frame))
(when (eq (frame-state frame) :enabled)
(disable-frame frame))
(disown-frame (frame-manager frame) frame))
(defmethod raise-frame ((frame application-frame))
(raise-sheet (frame-top-level-sheet frame)))
(defmethod bury-frame ((frame application-frame))
(bury-sheet (frame-top-level-sheet frame)))
(defmethod note-frame-enabled ((fm frame-manager) frame)
(declare (ignore frame))
t)
(defmethod note-frame-disabled ((fm frame-manager) frame)
(declare (ignore frame))
t)
(defun map-over-frames (function &key port frame-manager)
(cond (frame-manager
(mapc function (frame-manager-frames frame-manager)))
(port
(loop for manager in (frame-managers port)
do (map-over-frames function :frame-manager manager)))
(t (loop for p in *all-ports*
do (map-over-frames function :port p)))))
(defvar *pane-realizer* nil)
(defmacro with-look-and-feel-realization ((frame-manager frame) &body body)
`(let ((*pane-realizer* ,frame-manager)
(*application-frame* ,frame))
(locally
,@body)))
; The menu-bar code in the following two functions is incorrect.
; it needs to be moved to somewhere after the backend, since
; it depends on the backend chosen.
;
; This hack slaps a menu-bar into the start of the application-frame,
; in such a way that it is hard to find.
;
; FIXME
(defun make-single-pane-generate-panes-form (class-name menu-bar pane)
`(progn
(defmethod generate-panes ((fm frame-manager) (frame ,class-name))
;; v-- hey, how can this be?
(with-look-and-feel-realization (fm frame)
(let ((pane ,(cond
((eq menu-bar t)
`(vertically () (clim-internals::make-menu-bar
',class-name)
,pane))
((consp menu-bar)
`(vertically () (clim-internals::make-menu-bar
(make-command-table nil
:menu ',menu-bar))
,pane))
(menu-bar
`(vertically () (clim-internals::make-menu-bar
',menu-bar)
,pane))
;; The form below is unreachable with (listp
;; menu-bar) instead of (consp menu-bar) above
;; --GB
(t pane))))
(setf (slot-value frame 'panes) pane))))
(defmethod frame-all-layouts ((frame ,class-name))
nil)))
(defun find-pane-for-layout (name frame)
(cdr (assoc name (frame-panes-for-layout frame) :test #'eq)))
(defun save-pane-for-layout (name pane frame)
(push (cons name pane) (frame-panes-for-layout frame))
pane)
(defun coerce-pane-name (pane name)
(when pane
(setf (slot-value pane 'name) name)
(push pane (frame-named-panes (pane-frame pane))))
pane)
(defun do-pane-creation-form (name form)
(cond
((and (= (length form) 1)
(listp (first form)))
`(coerce-pane-name ,(first form) ',name))
((keywordp (first form))
(let ((maker (intern (concatenate 'string
(symbol-name '#:make-clim-)
(symbol-name (first form))
(symbol-name '#:-pane))
:clim)))
(if (fboundp maker)
`(,maker :name ',name ,@(cdr form))
`(make-pane ',(first form)
:name ',name ,@(cdr form)))))
(t `(make-pane ',(first form) :name ',name ,@(cdr form)))))
(defun make-panes-generate-panes-form (class-name menu-bar panes layouts
pointer-documentation)
(when pointer-documentation
(setf panes (append panes
'((%pointer-documentation%
pointer-documentation-pane)))))
`(progn
(defmethod generate-panes ((fm frame-manager) (frame ,class-name))
(let ((*application-frame* frame))
(with-look-and-feel-realization (fm frame)
(let ,(loop
for (name . form) in panes
collect `(,name (or (find-pane-for-layout ',name frame)
(save-pane-for-layout
',name
,(do-pane-creation-form name form)
frame))))
;; [BTS] added this, but is not sure that this is correct for
;; adding a menu-bar transparently, should also only be done
;; where the exterior window system does not support menus
,(if (or menu-bar pointer-documentation)
`(setf (slot-value frame 'panes)
(ecase (frame-current-layout frame)
,@(mapcar (lambda (layout)
`(,(first layout)
(vertically ()
,@(cond
((eq menu-bar t)
`((clim-internals::make-menu-bar
',class-name)))
((consp menu-bar)
`((clim-internals::make-menu-bar
(make-command-table
nil
:menu ',menu-bar))))
(menu-bar
`((clim-internals::make-menu-bar
',menu-bar)))
(t nil))
,@(rest layout)
,@(when pointer-documentation
'(%pointer-documentation%)))))
layouts)))
`(setf (slot-value frame 'panes)
(ecase (frame-current-layout frame)
,@layouts)))))))
(defmethod frame-all-layouts ((frame ,class-name))
',(mapcar #'car layouts))))
(defmacro define-application-frame (name superclasses slots &rest options)
(if (null superclasses)
(setq superclasses '(standard-application-frame)))
(let ((pane nil)
(panes nil)
(layouts nil)
(current-layout nil)
(command-table (list name))
(menu-bar t)
(disabled-commands nil)
(command-definer t)
(top-level '(default-frame-top-level))
(others nil)
(pointer-documentation nil)
(geometry nil)
(user-default-initargs nil)
(frame-arg (gensym "FRAME-ARG")))
(loop for (prop . values) in options
do (case prop
(:pane (setq pane (first values)))
(:panes (setq panes values))
(:layouts (setq layouts values))
(:command-table (setq command-table (first values)))
(:menu-bar (setq menu-bar (if (listp values)
(first values)
values)))
(:disabled-commands (setq disabled-commands values))
(:command-definer (setq command-definer (first values)))
(:top-level (setq top-level (first values)))
(:pointer-documentation (setq pointer-documentation (car values)))
(:geometry (setq geometry values))
(:default-initargs (setq user-default-initargs values))
(t (push (cons prop values) others))))
(when (eq command-definer t)
(setf command-definer
(intern (concatenate 'string
(symbol-name '#:define-)
(symbol-name name)
(symbol-name '#:-command)))))
(if (or (and pane panes)
(and pane layouts))
(error ":pane cannot be specified along with either :panes or :layouts"))
(if pane
(setq panes (list 'single-pane pane)
layouts `((:default ,(car pane)))))
(setq current-layout (first (first layouts)))
`(progn
(defclass ,name ,superclasses
,slots
(:default-initargs
:name ',name
:pretty-name ,(string-capitalize name)
:command-table (find-command-table ',(first command-table))
:disabled-commands ',disabled-commands
:menu-bar ',menu-bar
:current-layout ',current-layout
:layouts ',layouts
:top-level (list ',(car top-level) ,@(cdr top-level))
:top-level-lambda (lambda (,frame-arg)
(,(car top-level) ,frame-arg
,@(cdr top-level)))
,@geometry
,@user-default-initargs)
,@others)
,(if pane
(make-single-pane-generate-panes-form name menu-bar pane)
(make-panes-generate-panes-form name menu-bar panes layouts
pointer-documentation))
,@(if command-table
`((define-command-table ,@command-table)))
,@(if command-definer
`((defmacro ,command-definer (name-and-options arguments &rest body)
(let ((name (if (listp name-and-options) (first name-and-options) name-and-options))
(options (if (listp name-and-options) (cdr name-and-options) nil))
(command-table ',(first command-table)))
`(define-command (,name :command-table ,command-table ,@options) ,arguments ,@body))))))))
(defun make-application-frame (frame-name
&rest options
&key (pretty-name
(string-capitalize frame-name))
(frame-manager nil frame-manager-p)
enable
(state nil state-supplied-p)
save-under (frame-class frame-name)
&allow-other-keys)
(declare (ignore save-under))
(with-keywords-removed (options (:pretty-name :frame-manager :enable :state
:save-under :frame-class))
(let ((frame (apply #'make-instance frame-class
:name frame-name
:pretty-name pretty-name
options)))
(when frame-manager-p
(adopt-frame frame-manager frame))
(cond ((or enable (eq state :enabled))
(enable-frame frame))
((and (eq state :disowned)
(not (eq (frame-state frame) :disowned)))
(disown-frame (frame-manager frame) frame))
(state-supplied-p
(warn ":state ~S not supported yet." state)))
frame)))
;;; From Franz Users Guide
(defun find-application-frame (frame-name &rest initargs
&key (create t) (activate t)
(own-process *multiprocessing-p*) port
frame-manager frame-class
&allow-other-keys)
(declare (ignorable frame-class))
(let ((frame (unless (eq create :force)
(block
found-frame
(map-over-frames
#'(lambda (frame)
(when (eq (frame-name frame) frame-name)
(return-from found-frame frame)))
:port port
:frame-manager frame-manager)))))
(unless (or frame create)
(return-from find-application-frame nil))
(unless frame
(with-keywords-removed (initargs (:create :activate :own-process))
(setq frame (apply #'make-application-frame frame-name initargs))))
(when (and frame activate)
(cond ((frame-process frame)
(raise-frame frame))
(own-process
(clim-sys:make-process #'(lambda ()
(run-frame-top-level frame))
:name (format nil "~A" frame-name)))
(t (run-frame-top-level frame))))
frame))
;;; Menu frame class
(defclass menu-frame ()
((left :initform 0 :initarg :left)
(top :initform 0 :initarg :top)
(min-width :initform nil :initarg :min-width)
(top-level-sheet :initform nil :reader frame-top-level-sheet)
(panes :reader frame-panes :initarg :panes)
(graft :initform nil :accessor graft)
(manager :initform nil :accessor frame-manager)))
(defclass menu-unmanaged-top-level-sheet-pane (unmanaged-top-level-sheet-pane)
())
(defmethod adopt-frame ((fm frame-manager) (frame menu-frame))
(setf (slot-value fm 'frames) (cons frame (slot-value fm 'frames)))
(setf (frame-manager frame) fm)
(let* ((t-l-s (make-pane-1 fm *application-frame*
'menu-unmanaged-top-level-sheet-pane
:name 'top-level-sheet)))
(setf (slot-value frame 'top-level-sheet) t-l-s)
(sheet-adopt-child t-l-s (frame-panes frame))
(let ((graft (find-graft :port (port fm))))
(sheet-adopt-child graft t-l-s)
(setf (graft frame) graft))
(let ((pre-space (compose-space t-l-s))
(frame-min-width (slot-value frame 'min-width)))
(multiple-value-bind (width min-width max-width height min-height max-height)
(space-requirement-components pre-space)
(flet ((foomax (x y) (max (or x 1) (or y 1))))
(let ((space (make-space-requirement :min-width (foomax frame-min-width min-width)
:width (foomax frame-min-width width)
:max-width (foomax frame-min-width max-width)
:min-height min-height
:height height
:max-height max-height)))
(allocate-space (frame-panes frame)
(space-requirement-width space)
(space-requirement-height space))
(setf (sheet-region t-l-s)
(make-bounding-rectangle 0 0
(space-requirement-width space)
(space-requirement-height space))))
(setf (sheet-transformation t-l-s)
(make-translation-transformation (slot-value frame 'left)
(slot-value frame 'top))))))))
(defmethod disown-frame ((fm frame-manager) (frame menu-frame))