[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Views vs. Windows
- To: info-mcl@ministry.cambridge.apple.com
- Subject: Re: Views vs. Windows
- From: korcuska@ils.nwu.edu (Michael Korcuska)
- Date: 17 Feb 1994 16:59:43 GMT
- Followup-to: comp.lang.lisp.mcl
- Newsgroups: comp.lang.lisp.mcl
- Organization: Institute for the Learning Sciences
- References: <2ju3sg$nfm@anaxagoras.ils.nwu.edu>
In article <2ju3sg$nfm@anaxagoras.ils.nwu.edu>,
allender@aristotle.ils.nwu.edu (Allender ) wrote:
> Say you have two overlapping views in a window. Is there any way to change
> which view is topmost after the views have been added to the window?
>
> We'd like to be able to change which view is topmost without doing a
> remove-subviews and an add-subviews.
>
Funny we're doing this via this newsgroup, isn't it?
Here's a view-mixin class which maintains a separate list of subviews in
that view. The methods view-draw-contents and view-click-event-handler are
shadowed to use that list instead of the view-subviews vector. This is
necessary because the view-subviews vectore "should never be changed
directly".
(defclass object-manager-vm ()
((subview-order :reader subview-order
:initform nil)))
(defmethod add-subviews :after ((sov object-manager-vm) &rest subviews)
(setf (slot-value sov 'subview-order)
(append (subview-order sov) subviews)))
(defmethod remove-subviews :before ((sov object-manager-vm) &rest subviews)
(setf (slot-value sov 'subview-order)
(remove-if #'(lambda (item)
(member item subviews))
(subview-order sov))))
(defmethod view-draw-contents ((sov object-manager-vm))
(mapc #'view-draw-contents (subview-order sov)))
(defmethod view-click-event-handler ((sov object-manager-vm) where)
(loop for item in (reverse (subview-order sov))
when (point-in-click-region-p item where)
return (view-click-event-handler item where)))
And here's some functions which you might find useful in changing the order
of subviews. These could probably be written more efficiently, but
hey...you get what you pay for (and I'm a grad student these days).
(defun item-to-front (item lis)
(when (member item lis)
(nth-to-front (position item lis) lis)))
(defun item-to-back (item lis)
(when (member item lis)
(nth-to-back (position item lis) lis)))
(defun nth-to-front (n lis)
(append (list (nth n lis))
(subseq lis 0 n)
(subseq lis (1+ n))))
(defun nth-to-back (n lis)
(append (subseq lis 0 n)
(subseq lis (1+ n))
(list (nth n lis))))
Enjoy.
--
Michael Korcuska
Institute for the Learning Sciences
Northwestern University
korcuska@ils.nwu.edu