/[mcclim]/mcclim/input-editing-drei.lisp
ViewVC logotype

Contents of /mcclim/input-editing-drei.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations)
Wed Jan 30 22:29:07 2008 UTC (6 years, 2 months ago) by thenriksen
Branch: MAIN
Changes since 1.9: +6 -21 lines
Try to centralise the with-input-editing logic a bit.

Make with-input-editing work for input-editing-streams.
1 thenriksen 1.1 ;;; -*- Mode: Lisp; Package: CLIM-INTERNALS -*-
2    
3     ;;; (c) copyright 2001 by
4     ;;; Tim Moore (moore@bricoworks.com)
5     ;;; (c) copyright 2006 by
6     ;; Troels Henriksen (athas@sigkill.dk)
7    
8     ;;; This library is free software; you can redistribute it and/or
9     ;;; modify it under the terms of the GNU Library General Public
10     ;;; License as published by the Free Software Foundation; either
11     ;;; version 2 of the License, or (at your option) any later version.
12     ;;;
13     ;;; This library is distributed in the hope that it will be useful,
14     ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15     ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16     ;;; Library General Public License for more details.
17     ;;;
18     ;;; You should have received a copy of the GNU Library General Public
19     ;;; License along with this library; if not, write to the
20     ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21     ;;; Boston, MA 02111-1307 USA.
22    
23     ;;; Finalize input editing code by defining the stuff that actually
24     ;;; needs a working Drei loaded.
25    
26     (in-package :clim-internals)
27    
28     (defclass empty-input-mixin ()
29     ()
30     (:documentation "A mixin class used for detecting empty input"))
31    
32     (defclass standard-input-editing-stream (drei:drei-input-editing-mixin
33     empty-input-mixin
34     input-editing-stream
35     standard-encapsulating-stream)
36     ((scan-pointer :accessor stream-scan-pointer :initform 0)
37 thenriksen 1.6 (rescan-queued :accessor rescan-queued :initform nil))
38     (:documentation "The instantiable class that implements CLIM's
39     standard input editor. This is the class of stream created by
40     calling `with-input-editing'.
41    
42     Members of this class are mutable."))
43 thenriksen 1.1
44 thenriksen 1.7 (defmethod interactive-stream-p ((stream standard-input-editing-stream))
45     t)
46    
47 thenriksen 1.1 (defmethod stream-accept ((stream standard-input-editing-stream) type
48     &rest args
49     &key (view (stream-default-view stream))
50     &allow-other-keys)
51     (apply #'prompt-for-accept stream type view args)
52     (apply #'accept-1 stream type args))
53    
54     ;;; Markers for noise strings in the input buffer.
55    
56     (defclass noise-string-property ()
57     ())
58    
59     (defclass noise-string-start-property (noise-string-property)
60     ())
61    
62     (defparameter *noise-string* (make-instance 'noise-string-property))
63    
64     (defparameter *noise-string-start*
65     (make-instance 'noise-string-start-property))
66    
67     (defgeneric activate-stream (stream gesture)
68     (:documentation "Cause the input editing stream STREAM to be
69     activated with GESTURE"))
70    
71     (defmethod activate-stream ((stream standard-input-editing-stream) gesture)
72     (setf (drei::activation-gesture stream) gesture))
73    
74     ;;; These helper functions take the arguments of ACCEPT so that they
75     ;;; can be used directly by ACCEPT.
76    
77     (defun make-activation-gestures
78     (&key (activation-gestures nil activation-gestures-p)
79     (additional-activation-gestures nil additional-activations-p)
80     (existing-activation-gestures *activation-gestures*)
81     &allow-other-keys)
82     (cond (additional-activations-p
83     (append additional-activation-gestures existing-activation-gestures))
84     (activation-gestures-p
85     activation-gestures)
86     (t (or existing-activation-gestures
87     *standard-activation-gestures*))))
88    
89     (defun make-delimiter-gestures
90     (&key (delimiter-gestures nil delimiter-gestures-p)
91     (additional-delimiter-gestures nil additional-delimiters-p)
92     (existing-delimiter-gestures *delimiter-gestures*)
93     &allow-other-keys)
94     (cond (additional-delimiters-p
95     (append additional-delimiter-gestures existing-delimiter-gestures))
96     (delimiter-gestures-p
97     delimiter-gestures)
98     (t existing-delimiter-gestures)))
99    
100     (define-condition rescan-condition (condition)
101     ())
102    
103     (defgeneric finalize (editing-stream input-sensitizer)
104     (:documentation "Do any cleanup on an editing stream, like turning off the
105     cursor, etc."))
106    
107     (defmethod finalize ((stream drei:drei-input-editing-mixin)
108     input-sensitizer)
109     (setf (cursor-visibility stream) nil)
110     (let ((real-stream (encapsulating-stream-stream stream))
111     (record (drei:drei-instance stream)))
112 thenriksen 1.8 (cond (input-sensitizer
113     (erase-output-record record real-stream)
114     (funcall input-sensitizer
115     real-stream
116     #'(lambda ()
117     (stream-add-output-record real-stream record)
118     (when (stream-drawing-p real-stream)
119     (replay record real-stream)))))
120     ;; We still want to replay it for the cursor visibility
121     ;; change...
122     ((stream-drawing-p real-stream)
123     (replay record real-stream) ))
124 thenriksen 1.5 (setf (stream-cursor-position real-stream)
125     (values 0 (nth-value 3 (input-editing-stream-bounding-rectangle stream))))))
126 thenriksen 1.1
127     (defmethod invoke-with-input-editing :around ((stream extended-output-stream)
128     continuation
129     input-sensitizer
130     initial-contents
131     class)
132     (declare (ignore continuation input-sensitizer initial-contents class))
133     (letf (((cursor-visibility (stream-text-cursor stream)) nil))
134     (call-next-method)))
135    
136     (defmethod invoke-with-input-editing :around (stream
137     continuation
138     input-sensitizer
139     initial-contents
140     class)
141     (declare (ignore continuation input-sensitizer initial-contents class))
142     (with-activation-gestures (*standard-activation-gestures*)
143     (call-next-method)))
144    
145     ;; XXX: We are supposed to implement input editing for all
146     ;; "interactive streams", but that's not really reasonable. We only
147     ;; care about `clim-stream-pane's, at least for Drei, currently.
148     (defmethod invoke-with-input-editing ((stream clim-stream-pane)
149     continuation
150     input-sensitizer
151     initial-contents
152     class)
153 thenriksen 1.10 (let ((editing-stream (make-instance class :stream stream)))
154     (unwind-protect (with-input-editing (editing-stream
155     :input-sensitizer input-sensitizer
156     :initial-contents initial-contents
157     :class class)
158     (funcall continuation editing-stream))
159 thenriksen 1.1 (finalize editing-stream input-sensitizer))))
160    
161     (defmethod immediate-rescan ((stream standard-input-editing-stream))
162     (unless (stream-rescanning-p stream)
163     (signal 'rescan-condition)))
164    
165     (defmethod queue-rescan ((stream standard-input-editing-stream))
166     (setf (rescan-queued stream) t))
167    
168     (defmethod rescan-if-necessary ((stream standard-input-editing-stream)
169     &optional inhibit-activation)
170     ;; FIXME:
171     (declare (ignore inhibit-activation))
172     (when (rescan-queued stream)
173     (setf (rescan-queued stream) nil)
174     (immediate-rescan stream)))
175    
176     (defmethod input-editing-stream-bounding-rectangle ((stream standard-input-editing-stream))
177 thenriksen 1.5 (bounding-rectangle* (view (drei:drei-instance stream))))
178 thenriksen 1.2
179     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
180     ;;;
181     ;;; Presentation type history support
182     ;;;
183     ;;; Presentation histories are pretty underspecified, so we have to
184     ;;; rely on internal features and implement input-editor support in
185     ;;; CLIM-INTERNALS (Goatee does the same trick).
186    
187     (defun history-yank-next (stream input-buffer gesture numeric-argument)
188 thenriksen 1.3 (declare (ignore input-buffer gesture numeric-argument))
189 thenriksen 1.2 (let* ((accepting-type *active-history-type*)
190     (history (and accepting-type
191     (presentation-type-history accepting-type))))
192     (when history
193     (multiple-value-bind (object type)
194     (presentation-history-next history accepting-type)
195     (when type
196 thenriksen 1.4 (presentation-replace-input stream object type (stream-default-view stream)
197     :allow-other-keys t
198     :accept-result nil))))))
199 thenriksen 1.2
200     (defun history-yank-previous (stream input-buffer gesture numeric-argument)
201 thenriksen 1.3 (declare (ignore input-buffer gesture numeric-argument))
202 thenriksen 1.2 (let* ((accepting-type *active-history-type*)
203     (history (and accepting-type
204     (presentation-type-history accepting-type))))
205     (when history
206     (multiple-value-bind (object type)
207     (presentation-history-previous history accepting-type)
208     (when type
209 thenriksen 1.4 (presentation-replace-input stream object type (stream-default-view stream)
210     :allow-other-keys t
211     :accept-result nil))))))
212 thenriksen 1.2
213 thenriksen 1.3 (add-input-editor-command '((#\n :meta)) 'history-yank-next)
214 thenriksen 1.2
215 thenriksen 1.3 (add-input-editor-command '((#\p :meta)) 'history-yank-previous)

  ViewVC Help
Powered by ViewVC 1.1.5