/[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.5 - (hide annotations)
Wed Jan 16 09:03:27 2008 UTC (6 years, 3 months ago) by thenriksen
Branch: MAIN
Changes since 1.4: +3 -11 lines
Fixed post-edit cursor positioning for Drei areas.
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     (with-system-redefinition-allowed
29     (when (and (fboundp 'interactive-stream-p)
30     (not (typep (fdefinition 'interactive-stream-p)
31     'generic-function)))
32     (fmakunbound 'interactive-stream-p))
33     (defgeneric interactive-stream-p (stream)
34     (:method (stream)
35     (cl:interactive-stream-p stream))))
36    
37     (defclass empty-input-mixin ()
38     ()
39     (:documentation "A mixin class used for detecting empty input"))
40    
41     (defclass standard-input-editing-stream (drei:drei-input-editing-mixin
42     empty-input-mixin
43     input-editing-stream
44     standard-encapsulating-stream)
45     ((scan-pointer :accessor stream-scan-pointer :initform 0)
46     (rescan-queued :accessor rescan-queued :initform nil)))
47    
48     (defmethod stream-accept ((stream standard-input-editing-stream) type
49     &rest args
50     &key (view (stream-default-view stream))
51     &allow-other-keys)
52     (apply #'prompt-for-accept stream type view args)
53     (apply #'accept-1 stream type args))
54    
55     ;;; Markers for noise strings in the input buffer.
56    
57     (defclass noise-string-property ()
58     ())
59    
60     (defclass noise-string-start-property (noise-string-property)
61     ())
62    
63     (defparameter *noise-string* (make-instance 'noise-string-property))
64    
65     (defparameter *noise-string-start*
66     (make-instance 'noise-string-start-property))
67    
68     (defgeneric activate-stream (stream gesture)
69     (:documentation "Cause the input editing stream STREAM to be
70     activated with GESTURE"))
71    
72     (defmethod activate-stream ((stream standard-input-editing-stream) gesture)
73     (setf (drei::activation-gesture stream) gesture))
74    
75     ;;; These helper functions take the arguments of ACCEPT so that they
76     ;;; can be used directly by ACCEPT.
77    
78     (defun make-activation-gestures
79     (&key (activation-gestures nil activation-gestures-p)
80     (additional-activation-gestures nil additional-activations-p)
81     (existing-activation-gestures *activation-gestures*)
82     &allow-other-keys)
83     (cond (additional-activations-p
84     (append additional-activation-gestures existing-activation-gestures))
85     (activation-gestures-p
86     activation-gestures)
87     (t (or existing-activation-gestures
88     *standard-activation-gestures*))))
89    
90     (defun make-delimiter-gestures
91     (&key (delimiter-gestures nil delimiter-gestures-p)
92     (additional-delimiter-gestures nil additional-delimiters-p)
93     (existing-delimiter-gestures *delimiter-gestures*)
94     &allow-other-keys)
95     (cond (additional-delimiters-p
96     (append additional-delimiter-gestures existing-delimiter-gestures))
97     (delimiter-gestures-p
98     delimiter-gestures)
99     (t existing-delimiter-gestures)))
100    
101     (define-condition rescan-condition (condition)
102     ())
103    
104     (defgeneric finalize (editing-stream input-sensitizer)
105     (:documentation "Do any cleanup on an editing stream, like turning off the
106     cursor, etc."))
107    
108     (defmethod finalize ((stream drei:drei-input-editing-mixin)
109     input-sensitizer)
110     (setf (cursor-visibility stream) nil)
111     (let ((real-stream (encapsulating-stream-stream stream))
112     (record (drei:drei-instance stream)))
113     (when input-sensitizer
114     (erase-output-record record real-stream)
115     (funcall input-sensitizer
116     real-stream
117     #'(lambda ()
118     (stream-add-output-record real-stream record)
119     (when (stream-drawing-p real-stream)
120     (replay record real-stream)))))
121 thenriksen 1.5 (setf (stream-cursor-position real-stream)
122     (values 0 (nth-value 3 (input-editing-stream-bounding-rectangle stream))))))
123 thenriksen 1.1
124     (defgeneric invoke-with-input-editing
125     (stream continuation input-sensitizer initial-contents class))
126    
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     (let ((editing-stream (make-instance class
154     :stream stream
155     :initial-contents initial-contents)))
156     (unwind-protect
157     (loop
158     (block rescan
159     (handler-bind ((rescan-condition
160     #'(lambda (c)
161     (declare (ignore c))
162     (reset-scan-pointer editing-stream)
163     (return-from rescan nil))))
164     (return-from invoke-with-input-editing
165     (funcall continuation editing-stream)))))
166     (finalize editing-stream input-sensitizer))))
167    
168     (defmethod immediate-rescan ((stream standard-input-editing-stream))
169     (unless (stream-rescanning-p stream)
170     (signal 'rescan-condition)))
171    
172     (defmethod queue-rescan ((stream standard-input-editing-stream))
173     (setf (rescan-queued stream) t))
174    
175     (defmethod rescan-if-necessary ((stream standard-input-editing-stream)
176     &optional inhibit-activation)
177     ;; FIXME:
178     (declare (ignore inhibit-activation))
179     (when (rescan-queued stream)
180     (setf (rescan-queued stream) nil)
181     (immediate-rescan stream)))
182    
183     (defmethod input-editing-stream-bounding-rectangle ((stream standard-input-editing-stream))
184 thenriksen 1.5 (bounding-rectangle* (view (drei:drei-instance stream))))
185 thenriksen 1.2
186     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187     ;;;
188     ;;; Presentation type history support
189     ;;;
190     ;;; Presentation histories are pretty underspecified, so we have to
191     ;;; rely on internal features and implement input-editor support in
192     ;;; CLIM-INTERNALS (Goatee does the same trick).
193    
194     (defun history-yank-next (stream input-buffer gesture numeric-argument)
195 thenriksen 1.3 (declare (ignore input-buffer gesture numeric-argument))
196 thenriksen 1.2 (let* ((accepting-type *active-history-type*)
197     (history (and accepting-type
198     (presentation-type-history accepting-type))))
199     (when history
200     (multiple-value-bind (object type)
201     (presentation-history-next history accepting-type)
202     (when type
203 thenriksen 1.4 (presentation-replace-input stream object type (stream-default-view stream)
204     :allow-other-keys t
205     :accept-result nil))))))
206 thenriksen 1.2
207     (defun history-yank-previous (stream input-buffer gesture numeric-argument)
208 thenriksen 1.3 (declare (ignore input-buffer gesture numeric-argument))
209 thenriksen 1.2 (let* ((accepting-type *active-history-type*)
210     (history (and accepting-type
211     (presentation-type-history accepting-type))))
212     (when history
213     (multiple-value-bind (object type)
214     (presentation-history-previous history accepting-type)
215     (when type
216 thenriksen 1.4 (presentation-replace-input stream object type (stream-default-view stream)
217     :allow-other-keys t
218     :accept-result nil))))))
219 thenriksen 1.2
220 thenriksen 1.3 (add-input-editor-command '((#\n :meta)) 'history-yank-next)
221 thenriksen 1.2
222 thenriksen 1.3 (add-input-editor-command '((#\p :meta)) 'history-yank-previous)

  ViewVC Help
Powered by ViewVC 1.1.5