Several of you have expressed an interest in writing an AU Custom Cocoa View that can resize itself. I am pleased to announce that we have investigated this issue and instead of creating a new API, decided to make use of the cocoa facilities already built-in to AppKit:
AU View Resizing
If an AU View needs to resize itself (to show additional content, or implement a disclosure view), it should simply call the NSView -setFrameSize: selector with its new size. It is important that the view does not directly resize its window, or attempt to change its origin. The position of the view and size of the window are managed by the host and should not be changed by the view.
Host Responsibilities
The host needs to be aware that a view that it is hosted may change size in response to user interaction. When setFrameSize: is called on the view, the host's window will receive a NSViewFrameDidChangeNotification. The host must register a listener for this notification and resize its window in response. If the host cannot or does not want to resize the window to a size that is large enough to completely contain the AU View, it must place the view in an NSScrollView.
There are a couple of subtleties that must be considered here:
1) If the host (or user) changes the size of the window, this can cause the view size to change (depending on the autoresizing mask). The host needs to be aware of sizing changes originating in the view versus changes that are a result of sizing the window. This can be accomplished by utilizing the window delegate methods -windowWillResize:toSize: and -windowDidResize: to manage a flag that can be tested in the notification method for the NSViewFrameDidChangeNotification and thereby filtering out window-based view size changes.
2) The host needs to be aware that changing the size of the window in response to the NSViewFrameDidChangeNotification can cause the view size to change depending on the autoresizing mask of the view. The host may need to cache the autoresizing mask of the view, set it to NSViewNotSizable, resize the window, and then reset the autoresizing mask of the view once the window has been sized. (AU Lab does not currently do this, but the next version will.)
Example
I have written an example AU based on the FilterDemo AU that is included with the latest SDK. Due to size constraints, I can't post the component (340K) to the list, but if anyone wants me to send them the example, I would be happy to do so via email. Just send me a private email.
The example AU Unit has two buttons that can be pressed to change the size of the view. Pressing the button simply calls [self setFrameSize: size] where size is the new size of the view.
Note that this AU will work correctly in AU Lab 1.0.1 (which ships as part of the XCode 2.1 developer tools). If you are a host developer, you may use this component to test with. A future version of the SDK may include a better example and include source code.
Thank you all for your patience and interest in this matter. If anyone wants any further clarification, or the sample, please let me know and I would be happy to provide it.
Thanks,
Michael