+static void
+dump_view_tree (NSView* view, int depth)
+{
+ NSArray* subviews = [view subviews];
+ unsigned long cnt = [subviews count];
+
+ for (int d = 0; d < depth; d++) {
+ cerr << '\t';
+ }
+ NSRect frame = [view frame];
+ cerr << " view @ " << frame.origin.x << ", " << frame.origin.y
+ << ' ' << frame.size.width << " x " << frame.size.height
+ << endl;
+
+ for (unsigned long i = 0; i < cnt; ++i) {
+ NSView* subview = [subviews objectAtIndex:i];
+ dump_view_tree (subview, depth+1);
+ }
+}
+
+@implementation NotificationObject
+
+- (NotificationObject*) initWithPluginUI: (AUPluginUI*) apluginui andCocoaParent: (NSWindow*) cp andTopLevelParent: (NSWindow*) tlp
+{
+ self = [ super init ];
+
+ if (self) {
+ plugin_ui = apluginui;
+ top_level_parent = tlp;
+
+ if (cp) {
+ cocoa_parent = cp;
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(cocoaParentActivationHandler:)
+ name:NSWindowDidBecomeMainNotification
+ object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(cocoaParentBecameKeyHandler:)
+ name:NSWindowDidBecomeKeyNotification
+ object:nil];
+ }
+ }
+
+ return self;
+}
+
+- (void)cocoaParentActivationHandler:(NSNotification *)notification
+{
+ NSWindow* notification_window = (NSWindow *)[notification object];
+
+ if (top_level_parent == notification_window || cocoa_parent == notification_window) {
+ if ([notification_window isMainWindow]) {
+ plugin_ui->activate();
+ } else {
+ plugin_ui->deactivate();
+ }
+ }
+}
+
+- (void)cocoaParentBecameKeyHandler:(NSNotification *)notification
+{
+ NSWindow* notification_window = (NSWindow *)[notification object];
+
+ if (top_level_parent == notification_window || cocoa_parent == notification_window) {
+ if ([notification_window isKeyWindow]) {
+ plugin_ui->activate();
+ } else {
+ plugin_ui->deactivate();
+ }
+ }
+}
+
+- (void)auViewResized:(NSNotification *)notification;
+{
+ (void) notification; // stop complaints about unusued argument
+ plugin_ui->cocoa_view_resized();
+}
+
+@end
+