Changeset main,46 for main/widget/textbox.lisp
- Timestamp:
- 11/12/2007 07:08:49 PM (19 years ago)
- branch-nick:
- tui
- revision id:
- dsowen@tux-20071112190849-f4iha3mmvx2nskce
- File:
-
- 1 edited
-
main/widget/textbox.lisp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
main/widget/textbox.lisp
r44 r46 10 10 (defclass textbox (widget scroll insertion-point) 11 11 ((data :initarg :data) 12 (window :initarg :window))) 12 (window :initarg :window) 13 (active :type boolean :initform nil))) 13 14 14 15 … … 28 29 29 30 (defmethod draw ((textbox textbox)) 30 (with-slots (data window scroll) textbox 31 (with-slots (data window scroll inactive-background active-background active) 32 textbox 33 (setf (background window) (if active 34 active-background 35 inactive-background)) 31 36 (erase window) 32 37 (add-clipped-string window 0 (- scroll) (text data)) … … 58 63 59 64 60 (defun create-textbox (parent-window y x data width) 65 (defun create-textbox (parent-window y x data width &key 66 (inactive-background '(#\Space 0)) 67 (active-background '(#\Space 0))) 61 68 (let* ((window (tui-window::create-subwindow parent-window 1 width y x)) 62 (inst (make-instance 'textbox :data data :window window))) 69 (inst (make-instance 'textbox 70 :data data 71 :window window 72 :inactive-background inactive-background 73 :active-background active-background))) 63 74 (draw inst) 64 75 inst)) … … 79 90 80 91 (defmethod activate ((textbox textbox) &optional (callback 'nothing)) 81 (with-slots (data window) textbox 82 (cdk::c-keypad (window-pointer window) t) 83 (setf (insertion-point textbox) :end) 84 (loop 85 (let ((key (read-key window))) 86 (case key 87 (:key-left (decf (insertion-point textbox))) 88 (:key-right (incf (insertion-point textbox))) 89 (:key-home (setf (insertion-point textbox) 0)) 90 (:key-end (setf (insertion-point textbox) :end)) 91 (:key-backspace 92 (multiple-value-bind (left right) (split textbox) 93 (when (string/= left "") 94 (setf left (subseq left 0 (1- (length left)))) 95 (setf (text data) (concatenate 'string left right)) 96 (decf (insertion-point textbox))))) 97 (:key-dc 98 (multiple-value-bind (left right) (split textbox) 99 (when (string/= right "") 100 (setf right (subseq right 1)) 101 (setf (text data) (concatenate 'string left right)) 102 (setf (insertion-point textbox) (insertion-point textbox))))) 103 (t 104 (if (or (keywordp key) 105 (member key '(#\Return #\Newline #\Tab #\Esc))) 106 (let ((r (funcall callback key))) 107 (when r 108 (setf (insertion-point textbox) 0) 109 (return-from activate r))) 110 (multiple-value-bind (left right) (split textbox) 111 (setf (text data) 112 (concatenate 'string left (string key) right)) 113 (incf (insertion-point textbox)))))))))) 92 (with-slots (data window active) textbox 93 (setf active t) 94 (unwind-protect 95 (progn 96 (cdk::c-keypad (window-pointer window) t) 97 (setf (insertion-point textbox) :end) 98 (loop 99 (let ((key (read-key window))) 100 (case key 101 (:key-left (decf (insertion-point textbox))) 102 (:key-right (incf (insertion-point textbox))) 103 (:key-home (setf (insertion-point textbox) 0)) 104 (:key-end (setf (insertion-point textbox) :end)) 105 (:key-backspace 106 (multiple-value-bind (left right) (split textbox) 107 (when (string/= left "") 108 (setf left (subseq left 0 (1- (length left)))) 109 (setf (text data) (concatenate 'string left right)) 110 (decf (insertion-point textbox))))) 111 (:key-dc 112 (multiple-value-bind (left right) (split textbox) 113 (when (string/= right "") 114 (setf right (subseq right 1)) 115 (setf (text data) (concatenate 'string left right)) 116 (setf (insertion-point textbox) 117 (insertion-point textbox))))) 118 (t 119 (if (or (keywordp key) 120 (member key '(#\Return #\Newline #\Tab #\Esc))) 121 (let ((r (funcall callback key))) 122 (when r 123 (setf (insertion-point textbox) 0) 124 (return-from activate r))) 125 (multiple-value-bind (left right) (split textbox) 126 (setf (text data) 127 (concatenate 'string left (string key) right)) 128 (incf (insertion-point textbox))))))))) 129 (setf active nil))))
Note: See TracChangeset
for help on using the changeset viewer.
