Re: Maintaining Z-Order while hiding NSViews
Re: Maintaining Z-Order while hiding NSViews
- Subject: Re: Maintaining Z-Order while hiding NSViews
- From: publiclook <email@hidden>
- Date: Tue, 19 Aug 2003 23:32:42 -0400
Add a category to NSView and override -display and -displayInRect: to
not call -drawRect: if the view should not be currently visible. You
can store a single dictionary of flags using the views as the kesy and
storing isVisble bools. Add -isVisible and -setIsVisible: methods to
NSView that get and set the isVisible flag. If the view isn't
currently visible, an overriden -hitTest: can return NO so mouse events
wont be swallowed.
All of this has been discussed in this list before including lots of
good reasons to never hide views.
On Tuesday, August 19, 2003, at 07:10 PM, David Elliott wrote:
Hello,
In a number of windowing toolkits there is the concept of hiding a
view from the user while keeping it in the same position in the window
hierarchy. wxWindows is one of those toolkits. As far as I can tell,
Cocoa has no such facilities.
In order to mimic the hide/show behavior I have created an additional
NSView which I refer to as the "dummy" NSView. I give the dummy the
same size and position as the window that will be hidden then use use
replaceSubview:With: to replace the NSView to be hidden with the dummy
view. I have some things set up which ensure that the dummy and real
views keep consistent sizes.
Recently, I've run into a bit of a problem. The dummy view isn't
visible (since it never draws anything) but it still catches mouse
events. The mouse events are apparently forwarded to its superview by
Cocoa and so normally you'd never even know it's there. However, if
the parent mouse handler releases the dummy view then all hell breaks
loose because the mouse handler for the dummy view hasn't finished > yet!
So now I'm wondering if I'm approaching this problem from the right
angle. I've a couple ideas on how to do this:
1) Make the dummy's frame rect an NSZeroRect (is this even allowed!?)
2) Failing zero size being allowed, give the dummy a 1x1 size and
position it at -10000,-10000 or something ridiculous like that.
3) Avoid the dummy altogether. Instead, remove the NSView outright
instead of replacing it with a dummy. Upon adding it back, sort the
superview's subviews appropriately.
Of those, #1 is probably the most ideal. I get to maintain Z-Order
and by giving the dummy zero size it cannot possibly receive mouse
events. #2 scares me in the event where the superviews coordinate
system is shifted for some reason. #3 bothers me because I have to
try to figure out how I should sort the views.
Perhaps someone has a better idea? In the meantime I'm going to try
#1 and see how it works.
-Dave
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.