diff --git a/ChangeLog b/ChangeLog index c2459b439..b76381f5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-12-28 19:33 Gregory John Casamento + + * Headers/AppKit/NSMenuItem.h: Added documentation for many + of the methods in NSMenuItem. + * Source/GSNibTemplates.m: Further refinements on the earlier + memory leak fix. + 2003-12-25 00:03 Gregory John Casamento * Source/NSDataLinkPanel.m: Changed to use the correct method diff --git a/Headers/AppKit/NSMenuItem.h b/Headers/AppKit/NSMenuItem.h index 8174cf0a8..8a1ca4b8e 100644 --- a/Headers/AppKit/NSMenuItem.h +++ b/Headers/AppKit/NSMenuItem.h @@ -44,50 +44,280 @@ */ @protocol NSMenuItem +/** +

Returns a seperator. This is just a blank menu item which serves + to divide the menu into seperate parts. +

+ */ + (id) separatorItem; + +/** +

+ Sets a flag that, when set to YES, objects of this class will use user defined key equivalents. +

+ */ + (void) setUsesUserKeyEquivalents: (BOOL)flag; + +/** +

Returns a flag which indicates if the receiver will use user defined + key equivalents. +

+ */ + (BOOL) usesUserKeyEquivalents; +/** +

+ Returns the action of the receiver. +

+ */ - (SEL) action; + +/** +

+ Returns a boolean indicating if the receiver has a sub menu. +

+ */ - (BOOL) hasSubmenu; + +/** +

+ Returns the image to be displayed in the receiver. +

+ */ - (NSImage*) image; + +/** +

+ Initializes the receiver with aString as the title. + The method called with the menu is selected is represented by aSelector. + The key equivalent which can be used to invoke this menu item is represented by + charCode. +

+ */ - (id) initWithTitle: (NSString*)aString action: (SEL)aSelector keyEquivalent: (NSString*)charCode; + +/** +

+ Returns YES if the receiver is enabled. +

+ */ - (BOOL) isEnabled; + +/** +

+ Returns a boolean indicating if the receiver is a separator. +

+ */ - (BOOL) isSeparatorItem; + +/** +

+ Returns the key equivalent of the receiver. +

+ */ - (NSString*) keyEquivalent; + +/** +

+ Returns the key equivalent mask. +

+ */ - (unsigned int) keyEquivalentModifierMask; + +/** +

+ Returns the menu to which this menu item is connected. +

+ */ - (NSMenu*) menu; + +/** +

+ Returns the image to be displayed when the receiver is in the "Mixed" state. +

+ */ - (NSImage*) mixedStateImage; - (NSString*) mnemonic; - (unsigned) mnemonicLocation; + +/** +

+ Returns the image to be displayed when the receiver is in the "Off" state. +

+ */ - (NSImage*) offStateImage; + +/** +

+ Returns the image to be displayed when the receiver is in the "On" state. +

+ */ - (NSImage*) onStateImage; + +/** +

+ Returns the object represented by the reciever. +

+ */ - (id) representedObject; + +/** +

+ Sets the action as aSelector on the receiver. +

+ */ - (void) setAction: (SEL)aSelector; + +/** +

+ Set the receiver to be enabled. +

+ */ - (void) setEnabled: (BOOL)flag; + +/** +

+ Sets the image to be displayed in the receiver. +

+ */ - (void) setImage: (NSImage*)menuImage; + +/** +

+ Sets the key equivalent of the receiver. +

+ */ - (void) setKeyEquivalent: (NSString*)aKeyEquivalent; + +/** +

+ Sets the modfier for the key equivalent. These masks indicate if the + key equivalent requires ALT, Control or other key modifiers. +

+ */ - (void) setKeyEquivalentModifierMask: (unsigned int)mask; + +/** +

Sets the menu which this item belongs to. This method does not retain the + object represented by menu. +

+ */ - (void) setMenu: (NSMenu*)menu; + +/** +

+ Sets the image to be displayed when the receiver is in the "Mixed" state. +

+ */ - (void) setMixedStateImage: (NSImage*)image; - (void) setMnemonicLocation: (unsigned) location; + +/** +

+ Sets the image to be displayed when the receiver is in the "Off" state. +

+ */ - (void) setOffStateImage: (NSImage*)image; + +/** +

+ Sets the image to be displayed when the receiver is in the "On" state. +

+ */ - (void) setOnStateImage: (NSImage*)image; + +/** +

+ Sets the object represented by the reciever to anObject. +

+ */ - (void) setRepresentedObject: (id)anObject; + +/** +

+ Sets the state of the the receiver. +

+ */ - (void) setState: (int)state; + +/** +

+ Sets the submenu of the receiver. This method does retain the + submenu object. +

+ */ - (void) setSubmenu: (NSMenu*)submenu; + +/** +

+ Sets the tag of the reciever as anInt. +

+ */ - (void) setTag: (int)anInt; + +/** +

+ Sets the target as anObject on the receiver. +

+ */ - (void) setTarget: (id)anObject; + +/** +

+ Sets the title of the menu, represented by aString. +

+ */ - (void) setTitle: (NSString*)aString; - (void) setTitleWithMnemonic: (NSString*)stringWithAmpersand; + +/** +

+ Returns the state of the receiver. +

+ */ - (int) state; +/** +

+ Returns the attached submenu. +

+ */ - (NSMenu*) submenu; + +/** +

+ Returns the tag of the receiver. +

+ */ - (int) tag; + +/** +

+ Returns the target of the receiver. +

+ */ - (id) target; + +/** +

+ Returns the menu's title. +

+ */ - (NSString*) title; + +/** +

+ Returns the user defined key equivalent modifier. +

+ */ - (unsigned int) userKeyEquivalentModifierMask; + +/** +

+ Returns the key equivalent defined by the users defaults. +

+ */ - (NSString*) userKeyEquivalent; @end diff --git a/Source/GSNibTemplates.m b/Source/GSNibTemplates.m index 9efd9e493..bbccd2e62 100644 --- a/Source/GSNibTemplates.m +++ b/Source/GSNibTemplates.m @@ -42,16 +42,17 @@ #include #include #include -#include "AppKit/NSMenu.h" -#include "AppKit/NSControl.h" -#include "AppKit/NSImage.h" -#include "AppKit/NSSound.h" -#include "AppKit/NSView.h" -#include "AppKit/NSTextView.h" -#include "AppKit/NSWindow.h" +#include +#include +#include +#include +#include +#include #include #include #include +#include +#include #include #include @@ -163,19 +164,20 @@ static const int currentVersion = 1; // GSNibItem version number... while ((key = [enumerator nextObject]) != nil) { if ([context objectForKey: key] == nil || - ([key isEqualToString: @"NSOwner"] && // we want to send the message to the owner - [key isEqualToString: @"NSWindowsMenu"] == NO && // we don't want to send a message to these menus twice, - [key isEqualToString: @"NSServicesMenu"] == NO && // if they're custom classes. - [key isEqualToString: @"NSVisible"] == NO && // also exclude any other special parts of the nameTable. - [key isEqualToString: @"NSDeferred"] == NO && - [key isEqualToString: @"NSTopLevelObjects"] == NO)) + [key isEqualToString: @"NSOwner"]) // we want to send the message to the owner { - id o; - - o = [nameTable objectForKey: key]; - if ([o respondsToSelector: @selector(awakeFromNib)]) + if([key isEqualToString: @"NSWindowsMenu"] == NO && // we don't want to send a message to these menus twice, + [key isEqualToString: @"NSServicesMenu"] == NO && // if they're custom classes. + [key isEqualToString: @"NSVisible"] == NO && // also exclude any other special parts of the nameTable. + [key isEqualToString: @"NSDeferred"] == NO && + [key isEqualToString: @"NSTopLevelObjects"] == NO && + [key isEqualToString: @"GSCustomClassMap"] == NO) { - [o awakeFromNib]; + id o = [nameTable objectForKey: key]; + if ([o respondsToSelector: @selector(awakeFromNib)]) + { + [o awakeFromNib]; + } } } } @@ -203,21 +205,28 @@ static const int currentVersion = 1; // GSNibItem version number... enumerator = [nameTable keyEnumerator]; while ((key = [enumerator nextObject]) != nil) { - if ([context objectForKey: key] == nil || - ([key isEqualToString: @"NSOwner"] == NO && // dont retain the owner. - [key isEqualToString: @"NSWindowsMenu"] == NO && // exclude special sections. - [key isEqualToString: @"NSServicesMenu"] == NO && - [key isEqualToString: @"NSVisible"] == NO && - [key isEqualToString: @"NSDeferred"] == NO && - [key isEqualToString: @"NSTopLevelObjects"] == NO)) + if ([context objectForKey: key] == nil && + [key isEqualToString: @"NSWindowsMenu"] == NO && // exclude special sections. + [key isEqualToString: @"NSServicesMenu"] == NO && + [key isEqualToString: @"NSVisible"] == NO && + [key isEqualToString: @"NSDeferred"] == NO && + [key isEqualToString: @"NSTopLevelObjects"] == NO && + [key isEqualToString: @"GSCustomClassMap"] == NO) { - id o = [nameTable objectForKey: key]; + id o = [nameTable objectForKey: key]; // RETAIN all top-level items... if (([o isKindOfClass: [NSMenu class]] == YES && [key isEqualToString: @"NSMenu"] == YES) || // the main menu... ([o isKindOfClass: [NSWindow class]] == YES) || // any windows... - ([o isKindOfClass: [NSObject class]] == YES && - [o isKindOfClass: [NSView class]] == NO)) // any objects which are not views.. + ([o isKindOfClass: [NSObject class]] == YES && // any controllers... + [o isKindOfClass: [NSCell class]] == NO && // no cells + [o isKindOfClass: [NSMenu class]] == NO && // no menus, they're handled above + [o isKindOfClass: [NSMenuItem class]] == NO && // no menu items + [o isKindOfClass: [NSTableColumn class]] == NO && // no table columns + [o isKindOfClass: [NSTabViewItem class]] == NO && // no table columns + [o isKindOfClass: [NSWindow class]] == NO && // no tab view items + [o isKindOfClass: [NSView class]] == NO // no tab view items + )) { if(topLevelObjects == nil) { @@ -236,7 +245,7 @@ static const int currentVersion = 1; // GSNibItem version number... } } } - + /* * See if there are objects that should be made visible. */ @@ -363,15 +372,19 @@ static const int currentVersion = 1; // GSNibItem version number... obj = [cls allocWithZone: [self zone]]; if (theFrame.size.height > 0 && theFrame.size.width > 0) - obj = [obj initWithFrame: theFrame]; + { + obj = [obj initWithFrame: theFrame]; + } else - obj = [obj init]; + { + obj = [obj init]; + } if ([obj respondsToSelector: @selector(setAutoresizingMask:)]) { [obj setAutoresizingMask: mask]; } - + RELEASE(self); return obj; } @@ -392,10 +405,14 @@ static const int currentVersion = 1; // GSNibItem version number... obj = [cls allocWithZone: [self zone]]; if (theFrame.size.height > 0 && theFrame.size.width > 0) - obj = [obj initWithFrame: theFrame]; + { + obj = [obj initWithFrame: theFrame]; + } else - obj = [obj init]; - + { + obj = [obj init]; + } + RELEASE(self); return obj; }