Maintaining Z-Order while hiding NSViews
Maintaining Z-Order while hiding NSViews
- Subject: Maintaining Z-Order while hiding NSViews
- From: David Elliott <email@hidden>
- Date: Tue, 19 Aug 2003 19:10:11 -0400
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.