From 1efc3b97de6b23226c8d0f19f275aa75a8b1ca9b Mon Sep 17 00:00:00 2001 From: Ariel Abreu Date: Fri, 13 Oct 2023 10:08:54 -0400 Subject: [PATCH] Implement `NSUserInterfaceItemIdentification` --- AppKit/CMakeLists.txt | 1 + AppKit/NSCell.m | 3 +++ AppKit/NSMenu.subproj/NSMenu.m | 3 +++ AppKit/NSMenu.subproj/NSMenuItem.m | 3 +++ AppKit/NSTableColumn.m | 14 +++----------- AppKit/NSUserInterfaceItemIdentification.m | 18 ++++++++++++++++++ AppKit/NSView.m | 4 ++++ AppKit/NSViewController.m | 8 ++++++++ AppKit/NSWindow.m | 3 +++ AppKit/include/AppKit/NSCell.h | 4 +++- AppKit/include/AppKit/NSMenu.h | 4 +++- AppKit/include/AppKit/NSMenuItem.h | 4 +++- AppKit/include/AppKit/NSTableColumn.h | 9 ++++----- .../AppKit/NSUserInterfaceItemIdentification.h | 12 ++++++++++++ AppKit/include/AppKit/NSView.h | 4 +++- AppKit/include/AppKit/NSViewController.h | 4 +++- AppKit/include/AppKit/NSWindow.h | 5 ++++- AppKit/nib.subproj/NSWindowTemplate.h | 1 + AppKit/nib.subproj/NSWindowTemplate.m | 5 ++++- 19 files changed, 86 insertions(+), 23 deletions(-) create mode 100644 AppKit/NSUserInterfaceItemIdentification.m diff --git a/AppKit/CMakeLists.txt b/AppKit/CMakeLists.txt index 6cf8695a..48a6e230 100644 --- a/AppKit/CMakeLists.txt +++ b/AppKit/CMakeLists.txt @@ -449,6 +449,7 @@ set(AppKit_sources NSSwitch.m NSTextFinder.m NSScrubber.m + NSUserInterfaceItemIdentification.m ) set_source_files_properties(${AppKit_sources} LANGUAGE C) diff --git a/AppKit/NSCell.m b/AppKit/NSCell.m index 169f7bb5..d996b543 100644 --- a/AppKit/NSCell.m +++ b/AppKit/NSCell.m @@ -38,6 +38,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ @implementation NSCell +@synthesize identifier = _identifier; + #pragma mark - #pragma mark Class Methods @@ -265,6 +267,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ [_image release]; [_formatter release]; [_representedObject release]; + [_identifier release]; [super dealloc]; } diff --git a/AppKit/NSMenu.subproj/NSMenu.m b/AppKit/NSMenu.subproj/NSMenu.m index f1b3bfe7..725aaa90 100644 --- a/AppKit/NSMenu.subproj/NSMenu.m +++ b/AppKit/NSMenu.subproj/NSMenu.m @@ -37,6 +37,8 @@ NSString *const _NSWindowsMenuName = @"Window"; @implementation NSMenu +@synthesize identifier = _identifier; + + (void) popUpContextMenu: (NSMenu *) menu withEvent: (NSEvent *) event forView: (NSView *) view @@ -167,6 +169,7 @@ NSString *const _NSWindowsMenuName = @"Window"; [_itemArray makeObjectsPerformSelector: @selector(_setMenu:) withObject: nil]; [_itemArray release]; + [_identifier release]; [super dealloc]; } diff --git a/AppKit/NSMenu.subproj/NSMenuItem.m b/AppKit/NSMenu.subproj/NSMenuItem.m index 6ccd0307..0ba12a2c 100644 --- a/AppKit/NSMenu.subproj/NSMenuItem.m +++ b/AppKit/NSMenu.subproj/NSMenuItem.m @@ -30,6 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ @implementation NSMenuItem +@synthesize identifier = _identifier; + + (NSMenuItem *) separatorItem { return [[[self alloc] initWithTitle: nil action: NULL keyEquivalent: nil] autorelease]; @@ -110,6 +112,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ [_mixedStateImage release]; [_offStateImage release]; [_representedObject release]; + [_identifier release]; [super dealloc]; } diff --git a/AppKit/NSTableColumn.m b/AppKit/NSTableColumn.m index d9afc27e..95093be5 100644 --- a/AppKit/NSTableColumn.m +++ b/AppKit/NSTableColumn.m @@ -32,6 +32,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ @implementation NSTableColumn +@synthesize identifier = _identifier; + - (void) encodeWithCoder: (NSCoder *) coder { NSUnimplementedMethod(); } @@ -60,7 +62,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // NSOutlineView needs to programmatically instantiated as IB/WOF4 doesn't have // an editor for it.. also theoretically -dealloc could've crashed as the cell // prototypes weren't initialized at all... -- initWithIdentifier: identifier { +- (instancetype) initWithIdentifier: (NSUserInterfaceItemIdentifier) identifier { _identifier = [identifier retain]; _width = 100.0; _minWidth = 10.0; @@ -91,10 +93,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ _width, _minWidth, _maxWidth]; } -- (id) identifier { - return _identifier; -} - - (NSTableView *) tableView { return _tableView; } @@ -135,12 +133,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ return _resizingMask; } -- (void) setIdentifier: (id) identifier { - identifier = [identifier retain]; - [_identifier release]; - _identifier = identifier; -} - - (void) setTableView: (NSTableView *) tableView { _tableView = tableView; } diff --git a/AppKit/NSUserInterfaceItemIdentification.m b/AppKit/NSUserInterfaceItemIdentification.m new file mode 100644 index 00000000..d7057e8b --- /dev/null +++ b/AppKit/NSUserInterfaceItemIdentification.m @@ -0,0 +1,18 @@ +#import + +@implementation NSObject (NSUserInterfaceItemIdentification) + +- (NSUserInterfaceItemIdentifier) userInterfaceItemIdentifier { + if ([self respondsToSelector: @selector(identifier)]) { + return [self identifier]; + } + return nil; +} + +- (void) setUserInterfaceItemIdentifier: (NSUserInterfaceItemIdentifier) userInterfaceItemIdentifier { + if ([self respondsToSelector: @selector(setIdentifier:)]) { + [self setIdentifier: userInterfaceItemIdentifier]; + } +} + +@end diff --git a/AppKit/NSView.m b/AppKit/NSView.m index bb3adf8f..56ee2b3d 100644 --- a/AppKit/NSView.m +++ b/AppKit/NSView.m @@ -69,6 +69,8 @@ const NSViewFullScreenModeOptionKey NSFullScreenModeApplicationPresentationOptio @implementation NSView +@synthesize identifier = _identifier; + static BOOL NSViewLayersEnabled = YES; static BOOL NSShowAllViews = NO; @@ -408,6 +410,8 @@ typedef struct __VFlags { [_layerContext invalidate]; [_layerContext release]; + [_identifier release]; + [super dealloc]; } diff --git a/AppKit/NSViewController.m b/AppKit/NSViewController.m index 6de05480..27ccda2c 100644 --- a/AppKit/NSViewController.m +++ b/AppKit/NSViewController.m @@ -5,6 +5,8 @@ @implementation NSViewController +@synthesize identifier = _identifier; + - initWithNibName: (NSString *) name bundle: (NSBundle *) bundle { _nibName = [name copy]; _nibBundle = [bundle retain]; @@ -24,6 +26,12 @@ return self; } +- (void) dealloc { + [_identifier release]; + + [super dealloc]; +} + - (NSString *) nibName { return _nibName; } diff --git a/AppKit/NSWindow.m b/AppKit/NSWindow.m index bb49aabc..7fb7a604 100644 --- a/AppKit/NSWindow.m +++ b/AppKit/NSWindow.m @@ -206,6 +206,8 @@ NSInteger NSBitsPerPixelFromDepth(NSWindowDepth depth) { @implementation NSWindow +@synthesize identifier = _identifier; + static BOOL _allowsAutomaticWindowTabbing; + (NSWindowDepth) defaultDepthLimit { @@ -416,6 +418,7 @@ static BOOL _allowsAutomaticWindowTabbing; _platformWindow = nil; [_threadToContext release]; [_undoManager release]; + [_identifier release]; [super dealloc]; } diff --git a/AppKit/include/AppKit/NSCell.h b/AppKit/include/AppKit/NSCell.h index d3c7685b..9e2ce643 100644 --- a/AppKit/include/AppKit/NSCell.h +++ b/AppKit/include/AppKit/NSCell.h @@ -20,6 +20,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import #import #import +#import @class NSFont, NSImage, NSView; @@ -95,7 +96,7 @@ enum { NSCellHitTrackableArea = 0x04, }; -@interface NSCell : NSObject { +@interface NSCell : NSObject { NSControlStateValue _state; NSFont *_font; NSInteger _entryType; @@ -112,6 +113,7 @@ enum { NSLineBreakMode _lineBreakMode; NSBackgroundStyle _backgroundStyle; NSUInteger _cFlags; // required for Xcode + NSUserInterfaceItemIdentifier _identifier; BOOL _isEnabled; BOOL _isEditable; diff --git a/AppKit/include/AppKit/NSMenu.h b/AppKit/include/AppKit/NSMenu.h index 05ec5bb2..3b28e8ac 100644 --- a/AppKit/include/AppKit/NSMenu.h +++ b/AppKit/include/AppKit/NSMenu.h @@ -19,6 +19,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import #import +#import @class NSScreen, NSMenu, NSMenuItem, NSWindow, NSEvent, NSView; @@ -27,13 +28,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ APPKIT_EXPORT const NSNotificationName NSMenuDidBeginTrackingNotification; APPKIT_EXPORT const NSNotificationName NSMenuDidEndTrackingNotification; -@interface NSMenu : NSObject { +@interface NSMenu : NSObject { NSMenu *_supermenu; NSString *_title; NSString *_name; NSMutableArray *_itemArray; BOOL _autoenablesItems; id _delegate; + NSUserInterfaceItemIdentifier _identifier; } + (void) popUpContextMenu: (NSMenu *) menu diff --git a/AppKit/include/AppKit/NSMenuItem.h b/AppKit/include/AppKit/NSMenuItem.h index 77956fa7..e9cc8332 100644 --- a/AppKit/include/AppKit/NSMenuItem.h +++ b/AppKit/include/AppKit/NSMenuItem.h @@ -20,10 +20,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import #import #import +#import @class NSMenu, NSImage, NSAttributedString; -@interface NSMenuItem : NSObject { +@interface NSMenuItem : NSObject { NSMenu *_menu; NSString *_title; NSAttributedString *_atitle; @@ -44,6 +45,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ NSImage *_onStateImage; NSImage *_offStateImage; NSImage *_mixedStateImage; + NSUserInterfaceItemIdentifier _identifier; } + (NSMenuItem *) separatorItem; diff --git a/AppKit/include/AppKit/NSTableColumn.h b/AppKit/include/AppKit/NSTableColumn.h index 0c3d41f7..08a13a2d 100644 --- a/AppKit/include/AppKit/NSTableColumn.h +++ b/AppKit/include/AppKit/NSTableColumn.h @@ -18,6 +18,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import +#import @class NSTableView, NSCell; @@ -27,8 +28,8 @@ enum { NSTableColumnUserResizingMask = 0x02, }; -@interface NSTableColumn : NSObject { - id _identifier; +@interface NSTableColumn : NSObject { + NSUserInterfaceItemIdentifier _identifier; NSTableView *_tableView; NSCell *_headerCell; NSCell *_dataCell; @@ -42,9 +43,8 @@ enum { NSSortDescriptor *_sortDescriptorPrototype; } -- initWithIdentifier: identifier; +- (instancetype) initWithIdentifier: (NSUserInterfaceItemIdentifier) identifier; -- identifier; - (NSTableView *) tableView; - (id) headerCell; - (id) dataCell; @@ -57,7 +57,6 @@ enum { - (BOOL) isEditable; - (NSUInteger) resizingMask; -- (void) setIdentifier: identifier; - (void) setTableView: (NSTableView *) tableView; - (void) setHeaderCell: (NSCell *) cell; - (void) setDataCell: (NSCell *) cell; diff --git a/AppKit/include/AppKit/NSUserInterfaceItemIdentification.h b/AppKit/include/AppKit/NSUserInterfaceItemIdentification.h index 617325ac..6febce67 100644 --- a/AppKit/include/AppKit/NSUserInterfaceItemIdentification.h +++ b/AppKit/include/AppKit/NSUserInterfaceItemIdentification.h @@ -1,3 +1,15 @@ +#import + +typedef NSString* NSUserInterfaceItemIdentifier; + @protocol NSUserInterfaceItemIdentification +@property(copy) NSUserInterfaceItemIdentifier identifier; + +@end + +@interface NSObject (NSUserInterfaceItemIdentification) + +@property(copy) NSUserInterfaceItemIdentifier userInterfaceItemIdentifier; + @end diff --git a/AppKit/include/AppKit/NSView.h b/AppKit/include/AppKit/NSView.h index 305401bc..a16d67eb 100644 --- a/AppKit/include/AppKit/NSView.h +++ b/AppKit/include/AppKit/NSView.h @@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import #import #import +#import @class NSWindow, NSMenu, NSMenuItem, NSCursor, NSClipView, NSPasteboard, NSTextInputContext, NSImage, NSBitmapImageRep, NSScrollView, @@ -82,7 +83,7 @@ APPKIT_EXPORT const NSNotificationName NSViewGlobalFrameDidChangeNotification; APPKIT_EXPORT const NSViewFullScreenModeOptionKey NSFullScreenModeApplicationPresentationOptions; -@interface NSView : NSResponder { +@interface NSView : NSResponder { NSRect _frame; NSRect _bounds; NSWindow *_window; @@ -127,6 +128,7 @@ APPKIT_EXPORT const NSViewFullScreenModeOptionKey NSFullScreenModeApplicationPre CALayerContext *_layerContext; id __remove; + NSUserInterfaceItemIdentifier _identifier; } + (NSView *) focusView; diff --git a/AppKit/include/AppKit/NSViewController.h b/AppKit/include/AppKit/NSViewController.h index d31e3b47..7d002469 100644 --- a/AppKit/include/AppKit/NSViewController.h +++ b/AppKit/include/AppKit/NSViewController.h @@ -1,13 +1,15 @@ #import +#import @class NSView; -@interface NSViewController : NSResponder { +@interface NSViewController : NSResponder { NSString *_nibName; NSBundle *_nibBundle; id _representedObject; NSString *_title; NSView *_view; + NSUserInterfaceItemIdentifier _identifier; } - initWithNibName: (NSString *) name bundle: (NSBundle *) bundle; diff --git a/AppKit/include/AppKit/NSWindow.h b/AppKit/include/AppKit/NSWindow.h index 81808372..1e484cba 100644 --- a/AppKit/include/AppKit/NSWindow.h +++ b/AppKit/include/AppKit/NSWindow.h @@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import #import #import +#import @class NSView, NSEvent, NSColor, NSColorSpace, NSCursor, NSImage, NSScreen, NSText, NSTextView, CGWindow, NSPasteboard, NSSheetContext, @@ -145,7 +146,7 @@ APPKIT_EXPORT const NSNotificationName NSWindowWillEnterFullScreenNotification; APPKIT_EXPORT const NSNotificationName NSWindowWillExitFullScreenNotification; APPKIT_EXPORT const NSNotificationName NSWindowDidExposeNotification; -@interface NSWindow : NSResponder { +@interface NSWindow : NSResponder { NSRect _frame; NSWindowStyleMask _styleMask; NSBackingStoreType _backingType; @@ -241,6 +242,8 @@ APPKIT_EXPORT const NSNotificationName NSWindowDidExposeNotification; NSRect _savedFrame; NSPoint _mouseDownLocationInWindow; + + NSUserInterfaceItemIdentifier _identifier; } @property(class) BOOL allowsAutomaticWindowTabbing; diff --git a/AppKit/nib.subproj/NSWindowTemplate.h b/AppKit/nib.subproj/NSWindowTemplate.h index e1e64dae..38a80047 100644 --- a/AppKit/nib.subproj/NSWindowTemplate.h +++ b/AppKit/nib.subproj/NSWindowTemplate.h @@ -38,6 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ NSString *_windowTitle; NSView *windowView; NSString *_windowAutosave; + NSUserInterfaceItemIdentifier _identifier; } @end diff --git a/AppKit/nib.subproj/NSWindowTemplate.m b/AppKit/nib.subproj/NSWindowTemplate.m index ea655892..20b32f2b 100644 --- a/AppKit/nib.subproj/NSWindowTemplate.m +++ b/AppKit/nib.subproj/NSWindowTemplate.m @@ -29,7 +29,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ @implementation NSWindowTemplate -- initWithCoder: (NSCoder *) coder { +@synthesize identifier = _identifier; + +- (instancetype) initWithCoder: (NSCoder *) coder { if ([coder allowsKeyedCoding]) { NSKeyedUnarchiver *keyed = (NSKeyedUnarchiver *) coder; @@ -69,6 +71,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ [_windowTitle release]; [windowView release]; [_windowAutosave release]; + [_identifier release]; [super dealloc]; }