public virtual void Awake(NSArray rootObjects, IBObjectContainer objects, NSDictionary context) { NSEnumerator en; id obj; NSMutableArray topLevelObjects = (NSMutableArray)context.ObjectForKey((id)NS.NibTopLevelObjects); id owner = context.ObjectForKey(NS.NibOwner); id first = null; id app = null; // Get the file's owner and NSApplication object references... if (((NSCustomObject)rootObjects.ObjectAtIndex(1)).ClassName.IsEqualToString(@"FirstResponder")) first = ((NSCustomObject)rootObjects.ObjectAtIndex(1)).RealObject; else NS.Log(@"%s:first responder missing\n", "Awake"); if (((NSCustomObject)rootObjects.ObjectAtIndex(2)).ClassName.IsEqualToString(@"NSApplication")) app = ((NSCustomObject)rootObjects.ObjectAtIndex(2)).RealObject; else NS.Log(@"%s:NSApplication missing\n", "Awake"); // Use the owner as first root object ((NSCustomObject)rootObjects.ObjectAtIndex(0)).SetRealObject(owner); en = rootObjects.ObjectEnumerator(); while ((obj = en.NextObject()) != null) { if (obj.RespondsToSelector(new SEL("NibInstantiate"))) { obj = (id)Objc.MsgSend(obj, "NibInstantiate", null); } // IGNORE file's owner, first responder and NSApplication instances... if ((obj != null) && (obj != owner) && (obj != first) && (obj != app)) { topLevelObjects.AddObject(obj); // All top level objects must be released by the caller to avoid // leaking, unless they are going to be released by other nib // objects on behalf of the owner. //RETAIN(obj); } //FIXME //if ((obj.IsKindOfClass(NSMenu.Class)) && // (((NSMenu)obj _isMainMenu])) // { // // add the menu... // NSApp._setMainMenu(obj); // } } // Load connections and awaken objects Objc.MsgSend(objects, "NibInstantiate", null); }
public virtual void SetSubviews(NSArray newSubviews) { NSEnumerator en; NSView aView; NSMutableArray uniqNew = NSMutableArray.Array(); if (null == newSubviews) { NSException.Raise(@"NSInvalidArgumentException" ,@"Setting nil as new subviews."); } // Use a copy as we remove from the subviews array en = NSArray.ArrayWithArray(_sub_views).ObjectEnumerator(); while ((aView = (NSView)en.NextObject()) != null) { if (false == newSubviews.ContainsObject(aView)) { aView.RemoveFromSuperview(); } } en = newSubviews.ObjectEnumerator(); while ((aView = (NSView)en.NextObject()) != null) { id supersub = aView.Superview; if (supersub != null && supersub != this) { NSException.Raise(@"NSInvalidArgumentException" ,@"Superviews of new subviews must be either nil or receiver."); } if (uniqNew.ContainsObject(aView)) { NSException.Raise(@"NSInvalidArgumentException" ,@"Duplicated new subviews."); } if (false == _sub_views.ContainsObject(aView)) { this.AddSubview(aView); } uniqNew.AddObject(aView); } _sub_views = uniqNew; // The order of the subviews may have changed this.SetNeedsDisplay(true); }