/[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.13 - (show annotations)
Mon Feb 4 19:06:17 2008 UTC (6 years, 2 months ago) by thenriksen
Branch: MAIN
CVS Tags: McCLIM-0-9-6, HEAD
Changes since 1.12: +1 -1 lines
Fixed some random input-editor bugs.
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 standard-input-editing-mixin
35 input-editing-stream
36 standard-encapsulating-stream)
37 ((scan-pointer :accessor stream-scan-pointer :initform 0)
38 (rescan-queued :accessor rescan-queued :initform nil))
39 (:documentation "The instantiable class that implements CLIM's
40 standard input editor. This is the class of stream created by
41 calling `with-input-editing'.
42
43 Members of this class are mutable."))
44
45 (defmethod interactive-stream-p ((stream standard-input-editing-stream))
46 t)
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 (defmethod finalize ((stream drei:drei-input-editing-mixin)
105 input-sensitizer)
106 (call-next-method)
107 (setf (cursor-visibility stream) nil)
108 (let ((real-stream (encapsulating-stream-stream stream))
109 (record (drei:drei-instance stream)))
110 (cond (input-sensitizer
111 (erase-output-record record real-stream)
112 (funcall input-sensitizer
113 real-stream
114 #'(lambda ()
115 (stream-add-output-record real-stream record)
116 (when (stream-drawing-p real-stream)
117 (replay record real-stream)))))
118 ;; We still want to replay it for the cursor visibility
119 ;; change...
120 ((stream-drawing-p real-stream)
121 (replay record real-stream) ))
122 (setf (stream-cursor-position real-stream)
123 (values 0 (bounding-rectangle-max-y (input-editing-stream-output-record stream))))))
124
125 ;; XXX: We are supposed to implement input editing for all
126 ;; "interactive streams", but that's not really reasonable. We only
127 ;; care about `clim-stream-pane's, at least for Drei, currently.
128 (defmethod invoke-with-input-editing ((stream clim-stream-pane)
129 continuation
130 input-sensitizer
131 initial-contents
132 class)
133 (let ((editing-stream (make-instance class :stream stream)))
134 (unwind-protect (with-input-editing (editing-stream
135 :input-sensitizer input-sensitizer
136 :initial-contents initial-contents
137 :class class)
138 (input-editing-rescan-loop editing-stream continuation))
139 (finalize editing-stream input-sensitizer))))
140
141 (defmethod immediate-rescan ((stream standard-input-editing-stream))
142 (unless (stream-rescanning-p stream)
143 (signal 'rescan-condition)))
144
145 (defmethod queue-rescan ((stream standard-input-editing-stream))
146 (setf (rescan-queued stream) t))
147
148 (defmethod rescan-if-necessary ((stream standard-input-editing-stream)
149 &optional inhibit-activation)
150 ;; FIXME:
151 (declare (ignore inhibit-activation))
152 (when (rescan-queued stream)
153 (setf (rescan-queued stream) nil)
154 (immediate-rescan stream)))
155
156 (defmethod input-editing-stream-output-record ((stream standard-input-editing-stream))
157 (drei:drei-instance stream))
158
159 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
160 ;;;
161 ;;; Presentation type history support
162 ;;;
163 ;;; Presentation histories are pretty underspecified, so we have to
164 ;;; rely on internal features and implement input-editor support in
165 ;;; CLIM-INTERNALS (Goatee does the same trick).
166
167 (defun history-yank-next (stream input-buffer gesture numeric-argument)
168 (declare (ignore input-buffer gesture numeric-argument))
169 (let* ((accepting-type *active-history-type*)
170 (history (and accepting-type
171 (presentation-type-history accepting-type))))
172 (when history
173 (multiple-value-bind (object type)
174 (presentation-history-next history accepting-type)
175 (when type
176 (presentation-replace-input stream object type (stream-default-view stream)
177 :allow-other-keys t
178 :accept-result nil))))))
179
180 (defun history-yank-previous (stream input-buffer gesture numeric-argument)
181 (declare (ignore input-buffer gesture numeric-argument))
182 (let* ((accepting-type *active-history-type*)
183 (history (and accepting-type
184 (presentation-type-history accepting-type))))
185 (when history
186 (multiple-value-bind (object type)
187 (presentation-history-previous history accepting-type)
188 (when type
189 (presentation-replace-input stream object type (stream-default-view stream)
190 :allow-other-keys t
191 :accept-result nil))))))
192
193 (add-input-editor-command '((#\n :meta)) 'history-yank-next)
194
195 (add-input-editor-command '((#\p :meta)) 'history-yank-previous)

  ViewVC Help
Powered by ViewVC 1.1.5