[graphic-forms-cvs] r249 - in trunk: docs/manual src src/demos/textedit src/uitoolkit/widgets

junrue at common-lisp.net junrue at common-lisp.net
Wed Sep 6 05:08:07 UTC 2006


Author: junrue
Date: Wed Sep  6 01:08:05 2006
New Revision: 249

Modified:
   trunk/docs/manual/widget-functions.texinfo
   trunk/src/demos/textedit/textedit-window.lisp
   trunk/src/packages.lisp
   trunk/src/uitoolkit/widgets/edit.lisp
   trunk/src/uitoolkit/widgets/widget-generics.lisp
   trunk/src/uitoolkit/widgets/widget.lisp
Log:
API cleanup: collapsed selection-span and select-span into selected-span and associated setf function

Modified: trunk/docs/manual/widget-functions.texinfo
==============================================================================
--- trunk/docs/manual/widget-functions.texinfo	(original)
+++ trunk/docs/manual/widget-functions.texinfo	Wed Sep  6 01:08:05 2006
@@ -449,37 +449,56 @@
 or to the unselected state if @sc{nil}.
 @end deffn
 
+ at anchor{select-all}
 @deffn GenericFunction select-all self flag
-Sets the entire content of @code{self} to the selected state if
+Sets the entire content of @var{self} to the selected state if
 @var{flag} is not @sc{nil} or to the unselected state if @sc{nil}.
 @end deffn
 
- at anchor{select-items}
- at deffn GenericFunction select-items self indices flag
-Sets the @ref{item}s of @var{self}, each identified by a zero-based
-index from the @var{indices} @sc{list}, to the selected state if
- at var{flag} is not @sc{nil} or to the unselected state if @sc{nil}.
-This is the function to use when not all of the items in question
-are contiguous.
+ at anchor{selected-count}
+ at deffn GenericFunction selected-count self => integer
+Returns the number of @ref{item}s selected in @var{self}.
 @end deffn
 
- at anchor{select-span}
- at deffn GenericFunction select-span self span
-Sets the @ref{item}s of @var{self} that lie within @var{span} to
-the selected state. An existing selection's extent is modified
-to match the new @var{span}.
- at end deffn
+ at anchor{selected-items}
+ at deffn GenericFunction selected-items self => list
+(setf (@strong{selected-items} @var{self}) @var{list})
+
+Returns a @sc{list} containing subclasses of @ref{item} appropriate
+for @var{self} that correspond to selections made by the user, or
+ at sc{nil} if there are no selections. This function is defined only
+for @ref{widget}s whose notion of @emph{selection} is a set of
+item objects.
 
- at deffn GenericFunction selection-span self => @ref{span}
-Returns a span object describing the @var{start} and @var{end} of the
-selection within @var{self}. If there is no selection, this function
-returns @sc{nil}.
+The @sc{setf} function takes a @var{list} of item subclasses
+appropriate for @var{self} which identify the items in
+ at var{self} that should be selected. Passing @sc{nil} will unselect all
+items, which is equivalent to calling @ref{select-all} with @sc{nil}.
 @end deffn
 
+ at anchor{selected-p}
 @deffn GenericFunction selected-p self => boolean
 Returns T if @var{self} is in the selected state; @sc{nil} otherwise.
 @end deffn
 
+ at anchor{selected-span}
+ at deffn GenericFunction selected-span self => @var{object}, @var{span}
+(setf (@strong{selected-span} @var{self}) @var{span})
+
+Returns a @ref{span} describing a range of data within @var{self}
+that is in the selected state, as well as an @var{object} comprising
+the selected data. If there is no selection, this
+function returns @sc{nil} for both values. This function is defined
+only for @ref{widget}s whose notion of @emph{selection} is a
+contiguous range of simple data (e.g., characters in a string).
+
+The corresponding @sc{setf} function sets the content of
+ at var{self} whose indices lie within @var{span} to the selected
+state. An existing selection's extent is modified to match the
+new @var{span}. Passing @sc{nil} for @var{span} will unselect
+all content.
+ at end deffn
+
 @anchor{show}
 @deffn GenericFunction show self flag
 Causes the object to be visible or hidden on the screen, but not

Modified: trunk/src/demos/textedit/textedit-window.lisp
==============================================================================
--- trunk/src/demos/textedit/textedit-window.lisp	(original)
+++ trunk/src/demos/textedit/textedit-window.lisp	Wed Sep  6 01:08:05 2006
@@ -98,17 +98,19 @@
   (unless *textedit-control*
     (return-from manage-textedit-edit-menu nil))
   (let ((items (gfw:items-of menu))
-        (text (gfw:text *textedit-control*))
-        (text-sel (gfw:selection-span *textedit-control*)))
-    (gfw:enable (elt items 0) (gfw:undo-available-p *textedit-control*))
-    (gfw:enable (elt items 2) text-sel)
-    (gfw:enable (elt items 3) text-sel)
-    (gfw:enable (elt items 4) (gfw:text-for-pasting-p *textedit-control*))
-    (gfw:enable (elt items 5) text-sel)
-    (gfw:enable (elt items 12) (and (> (length text) 0)
-                                    (or (null text-sel)
-                                        (> (gfs:span-start text-sel) 0)
-                                        (< (gfs:span-end text-sel) (length text)))))))
+        (text (gfw:text *textedit-control*)))
+    (multiple-value-bind (sub-text text-sel)
+        (gfw:selected-span *textedit-control*)
+      (declare (ignore sub-text))
+      (gfw:enable (elt items 0) (gfw:undo-available-p *textedit-control*))
+      (gfw:enable (elt items 2) text-sel)
+      (gfw:enable (elt items 3) text-sel)
+      (gfw:enable (elt items 4) (gfw:text-for-pasting-p *textedit-control*))
+      (gfw:enable (elt items 5) text-sel)
+      (gfw:enable (elt items 12) (and (> (length text) 0)
+                                      (or (null text-sel)
+                                          (> (gfs:span-start text-sel) 0)
+                                          (< (gfs:span-end text-sel) (length text))))))))
 
 (defun textedit-edit-copy (disp item)
   (declare (ignore disp item))

Modified: trunk/src/packages.lisp
==============================================================================
--- trunk/src/packages.lisp	(original)
+++ trunk/src/packages.lisp	Wed Sep  6 01:08:05 2006
@@ -487,12 +487,10 @@
     #:scroll
     #:select
     #:select-all
-    #:select-items
+    #:selected-count
+    #:selected-items
     #:selected-p
-    #:selection-count
-    #:selection-index
-    #:selection-indices
-    #:selection-span
+    #:selected-span
     #:show
     #:show-column
     #:show-header

Modified: trunk/src/uitoolkit/widgets/edit.lisp
==============================================================================
--- trunk/src/uitoolkit/widgets/edit.lisp	(original)
+++ trunk/src/uitoolkit/widgets/edit.lisp	Wed Sep  6 01:08:05 2006
@@ -133,13 +133,7 @@
     (gfs::send-message (gfs:handle self) gfs::+em-setsel+ 0 (length (text self)))
     (gfs::send-message (gfs:handle self) gfs::+em-setsel+ 0 0)))
 
-(defmethod select-span ((self edit) (span gfs:span))
-  (with-drawing-disabled (self)
-    (let ((hwnd (gfs:handle self)))
-      (gfs::send-message hwnd gfs::+em-setsel+ 1 1)
-      (gfs::send-message hwnd gfs::+em-setsel+ (gfs:span-start span) (gfs:span-end span)))))
-
-(defmethod selection-span ((self edit))
+(defmethod selected-span ((self edit))
   (cffi:with-foreign-object (start-ptr :unsigned-long)
     (cffi:with-foreign-object (end-ptr :unsigned-long)
       (gfs::send-message (gfs:handle self)
@@ -147,8 +141,17 @@
                          (cffi:pointer-address start-ptr)
                          (cffi:pointer-address end-ptr))
       (let ((start (cffi:mem-ref start-ptr :unsigned-long))
-            (end (cffi:mem-ref end-ptr :unsigned-long)))
-        (if (= start end) nil (gfs:make-span :start start :end end))))))
+            (end (cffi:mem-ref end-ptr :unsigned-long))
+            (str (text self)))
+        (if (= start end)
+          (values nil nil)
+          (values (subseq str start end) (gfs:make-span :start start :end end)))))))
+
+(defmethod (setf selected-span) ((span gfs:span) (self edit))
+  (with-drawing-disabled (self)
+    (let ((hwnd (gfs:handle self)))
+      (gfs::send-message hwnd gfs::+em-setsel+ 1 1)
+      (gfs::send-message hwnd gfs::+em-setsel+ (gfs:span-start span) (gfs:span-end span)))))
 
 (defmethod text ((self edit))
   (get-widget-text self))

Modified: trunk/src/uitoolkit/widgets/widget-generics.lisp
==============================================================================
--- trunk/src/uitoolkit/widgets/widget-generics.lisp	(original)
+++ trunk/src/uitoolkit/widgets/widget-generics.lisp	Wed Sep  6 01:08:05 2006
@@ -327,26 +327,23 @@
 (defgeneric select-all (self flag)
   (:documentation "Set all items of this object into (or out of) the selected state."))
 
-(defgeneric select-items (self indices flag)
-  (:documentation "Set items of self, each identified by a zero-based index, into (or out of) the selected state."))
+(defgeneric selected-count (self)
+  (:documentation "Returns the number of this object's items that are selected."))
+
+(defgeneric selected-items (self)
+  (:documentation "Returns a list of item subclasses representing selected items in self, or nil if no items are selected."))
 
-(defgeneric select-span (self span)
-  (:documentation "Set items of self that lie within span into the selected state."))
+(defgeneric (setf selected-items) (items self)
+  (:documentation "Updates self's visual display such that the specified items are selected."))
 
 (defgeneric selected-p (self)
   (:documentation "Returns T if the object is in the selected state; nil otherwise."))
 
-(defgeneric selection-count (self)
-  (:documentation "Returns the number of this object's items that are selected."))
-
-(defgeneric selection-index (self)
-  (:documentation "Returns the zero-based index of the currently-selected item, or nil if no item is selected."))
-
-(defgeneric selection-indices (self)
-  (:documentation "Returns a list of zero-based indices identifying the selected items within this object."))
+(defgeneric selected-span (self)
+  (:documentation "Returns a span describing the range of data selected in self, and the selected data."))
 
-(defgeneric selection-span (self)
-  (:documentation "Returns a span object describing the start and end indices of the selection within self."))
+(defgeneric (setf selected-span) (span self)
+  (:documentation "Updates self's visual display such that the data within span is selected."))
 
 (defgeneric show (self flag)
   (:documentation "Causes the object to be visible or hidden on the screen, but not necessarily top-most in the display z-order."))

Modified: trunk/src/uitoolkit/widgets/widget.lisp
==============================================================================
--- trunk/src/uitoolkit/widgets/widget.lisp	(original)
+++ trunk/src/uitoolkit/widgets/widget.lisp	Wed Sep  6 01:08:05 2006
@@ -343,13 +343,16 @@
   (if (gfs:disposed-p self)
     (error 'gfs:disposed-error)))
 
-(defmethod select-items :before ((self widget) items flag)
-  (declare (ignore items flag))
+(defmethod selected-count :before ((self widget))
   (if (gfs:disposed-p self)
     (error 'gfs:disposed-error)))
 
-(defmethod select-span :before ((self widget) span)
-  (declare (ignore span))
+(defmethod selected-items :before ((self widget))
+  (if (gfs:disposed-p self)
+    (error 'gfs:disposed-error)))
+
+(defmethod (setf selected-items) :before (items (self widget))
+  (declare (ignore items))
   (if (gfs:disposed-p self)
     (error 'gfs:disposed-error)))
 
@@ -360,7 +363,15 @@
 (defmethod selected-p ((self widget))
   nil)
 
-(defmethod selection-span :before ((self widget))
+(defmethod selected-span :before ((self widget))
+  (if (gfs:disposed-p self)
+    (error 'gfs:disposed-error)))
+
+(defmethod selected-span ((self widget))
+  nil)
+
+(defmethod (setf selected-span) :before (span (self widget))
+  (declare (ignore span))
   (if (gfs:disposed-p self)
     (error 'gfs:disposed-error)))
 



More information about the Graphic-forms-cvs mailing list