/[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.11 - (hide annotations)
Thu Jan 31 19:17:57 2008 UTC (6 years, 2 months ago) by thenriksen
Branch: MAIN
Changes since 1.10: +1 -22 lines
Moved some input-editing functions around.

The typeout area is now cleared at the end of an input-editing session.
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     (defmethod finalize ((stream drei:drei-input-editing-mixin)
104     input-sensitizer)
105 thenriksen 1.11 (call-next-method)
106 thenriksen 1.1 (setf (cursor-visibility stream) nil)
107     (let ((real-stream (encapsulating-stream-stream stream))
108     (record (drei:drei-instance stream)))
109 thenriksen 1.8 (cond (input-sensitizer
110     (erase-output-record record real-stream)
111     (funcall input-sensitizer
112     real-stream
113     #'(lambda ()
114     (stream-add-output-record real-stream record)
115     (when (stream-drawing-p real-stream)
116     (replay record real-stream)))))
117     ;; We still want to replay it for the cursor visibility
118     ;; change...
119     ((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     ;; XXX: We are supposed to implement input editing for all
125     ;; "interactive streams", but that's not really reasonable. We only
126     ;; care about `clim-stream-pane's, at least for Drei, currently.
127     (defmethod invoke-with-input-editing ((stream clim-stream-pane)
128     continuation
129     input-sensitizer
130     initial-contents
131     class)
132 thenriksen 1.10 (let ((editing-stream (make-instance class :stream stream)))
133     (unwind-protect (with-input-editing (editing-stream
134     :input-sensitizer input-sensitizer
135     :initial-contents initial-contents
136     :class class)
137     (funcall continuation editing-stream))
138 thenriksen 1.1 (finalize editing-stream input-sensitizer))))
139    
140     (defmethod immediate-rescan ((stream standard-input-editing-stream))
141     (unless (stream-rescanning-p stream)
142     (signal 'rescan-condition)))
143    
144     (defmethod queue-rescan ((stream standard-input-editing-stream))
145     (setf (rescan-queued stream) t))
146    
147     (defmethod rescan-if-necessary ((stream standard-input-editing-stream)
148     &optional inhibit-activation)
149     ;; FIXME:
150     (declare (ignore inhibit-activation))
151     (when (rescan-queued stream)
152     (setf (rescan-queued stream) nil)
153     (immediate-rescan stream)))
154    
155     (defmethod input-editing-stream-bounding-rectangle ((stream standard-input-editing-stream))
156 thenriksen 1.5 (bounding-rectangle* (view (drei:drei-instance stream))))
157 thenriksen 1.2
158     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
159     ;;;
160     ;;; Presentation type history support
161     ;;;
162     ;;; Presentation histories are pretty underspecified, so we have to
163     ;;; rely on internal features and implement input-editor support in
164     ;;; CLIM-INTERNALS (Goatee does the same trick).
165    
166     (defun history-yank-next (stream input-buffer gesture numeric-argument)
167 thenriksen 1.3 (declare (ignore input-buffer gesture numeric-argument))
168 thenriksen 1.2 (let* ((accepting-type *active-history-type*)
169     (history (and accepting-type
170     (presentation-type-history accepting-type))))
171     (when history
172     (multiple-value-bind (object type)
173     (presentation-history-next history accepting-type)
174     (when type
175 thenriksen 1.4 (presentation-replace-input stream object type (stream-default-view stream)
176     :allow-other-keys t
177     :accept-result nil))))))
178 thenriksen 1.2
179     (defun history-yank-previous (stream input-buffer gesture numeric-argument)
180 thenriksen 1.3 (declare (ignore input-buffer gesture numeric-argument))
181 thenriksen 1.2 (let* ((accepting-type *active-history-type*)
182     (history (and accepting-type
183     (presentation-type-history accepting-type))))
184     (when history
185     (multiple-value-bind (object type)
186     (presentation-history-previous history accepting-type)
187     (when type
188 thenriksen 1.4 (presentation-replace-input stream object type (stream-default-view stream)
189     :allow-other-keys t
190     :accept-result nil))))))
191 thenriksen 1.2
192 thenriksen 1.3 (add-input-editor-command '((#\n :meta)) 'history-yank-next)
193 thenriksen 1.2
194 thenriksen 1.3 (add-input-editor-command '((#\p :meta)) 'history-yank-previous)

  ViewVC Help
Powered by ViewVC 1.1.5