@@ -6,74 +6,340 @@ The above copyright notice and this permission notice shall be included in all c
66
77THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 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. */
88
9+
10+ /* Modified by Mr. Walls in 2025 - This version is a derivative Contributed under MIT */
911#import < Foundation/Foundation.h>
1012
11- @class NSScreen , NSMenu , NSMenuItem , NSWindow , NSEvent , NSView ;
13+ // FIXME: this probably goes elsewhere
14+ #ifndef OBJC_DESIGNATED_INITIALIZER
15+ // / Used to check for modern Objective-C attribute of objc_designated_initializer in compiler
16+ // / see https://clang.llvm.org/docs/AttributeReference.html#objc-designated-initializer
17+ #if __has_attribute(objc_designated_initializer)
18+ // / defined macro for adding the objc_designated_initializer attribute to objective-c constructors
19+ #define OBJC_DESIGNATED_INITIALIZER __attribute__ ((objc_designated_initializer))
20+ #else
21+ // / empty macro for skipping the objc_designated_initializer attribute on objective-c constructors
22+ // / still helps developers read code
23+ #define OBJC_DESIGNATED_INITIALIZER
24+ #endif /* !__has_attribute(objc_designated_initializer) */
25+ #endif /* !OBJC_DESIGNATED_INITIALIZER */
26+
27+ #if defined(__RAVYNOS__)
28+ #if !defined(NSMENU_RAVYN_OS_PATTERNS)
29+ // / Defined as "NSMainMenu".
30+ #define NSMENU_RAVYN_OS_PATTERN_MENU_TOP_NAME (NSString *)(@" NSMainMenu" )
31+ // / Defined as "NSApplicationMenu".
32+ #define NSMENU_RAVYN_OS_PATTERN_APPMENU_NAME (NSString *)(@" NSApplicationMenu" )
33+ // / Defined as "About %NewApplication%".
34+ #define NSMENU_RAVYN_OS_PATTERN_APPMENU_ABOUT_TITLE (NSString *)(@" About %@ " )
35+ // / Defined as "Preferences...".
36+ #define NSMENU_RAVYN_OS_PATTERN_APPMENU_PREFERENCES_TITLE (NSString *)(@" Preferences..." )
37+ // / Defined as "Hide %NewApplication%".
38+ #define NSMENU_RAVYN_OS_PATTERN_APPMENU_HIDE_SELF_TITLE (NSString *)(@" Hide %@ " )
39+ // / Defined as "Show %NewApplication%".
40+ #define NSMENU_RAVYN_OS_PATTERN_APPMENU_SHOW_SELF_TITLE (NSString *)(@" Show %@ " )
41+ // / Defined as "Hide Others".
42+ #define NSMENU_RAVYN_OS_PATTERN_APPMENU_HIDE_OTHERS_TITLE (NSString *)(@" Hide Others" )
43+ // / Defined as "Show All".
44+ #define NSMENU_RAVYN_OS_PATTERN_APPMENU_SHOW_ALL_TITLE (NSString *)(@" Show All" )
45+ // / Defined as "Quit %NewApplication%".
46+ #define NSMENU_RAVYN_OS_PATTERN_APPMENU_QUIT_TITLE (NSString *)(@" Quit %@ " )
47+ #endif /* !defined(NSMENU_RAVYN_OS_PATTERNS) */
48+ #endif /* !defined(__RAVYNOS__) */
49+
50+ @class NSEvent , NSView ;
51+ #if defined(NSFont)
52+ #if defined(__RAVYNOS__)
53+ #warning "NSMenu does not support Fonts in this implementation"
54+ #endif
55+ @class NSFont ;
56+ #endif
57+ // FIXME: also need to fix NSMenuItem.h
58+ #if !defined(NSMenuItem)
59+ #import < AppKit/NSMenuItem.h>
60+ @class NSMenuItem ;
61+ #endif
62+
63+ @class NSMenu ;
1264
1365@protocol NSMenuDelegate;
1466
15- @interface NSMenu : NSObject <NSCopying > {
16- NSMenu *_supermenu;
17- NSString *_title;
18- NSString *_name;
19- NSMutableArray *_itemArray;
20- BOOL _autoenablesItems;
21- id <NSMenuDelegate > _delegate;
22- int _DBusItemID;
67+ // FIXME: this probably goes elsewhere
68+ #if !defined(DBusInstanceID)
69+ typedef uint64_t DBusInstanceID;
70+ #endif
71+
72+ // TODO: mention no NSNull as menu is not a true collection
73+ // see more on null/nil: https://stackoverflow.com/questions/1564410/when-should-i-use-nil-and-null-in-objective-c
74+ // Coding is not expected to be storing null/nil data in this implementation
75+
76+ // FIXME: add APKIT_EXPORT macro here if defined
77+ // FIXME: should conform to NSUserInterfaceItemIdentification and accessibility stuff
78+ @interface NSMenu : NSObject <NSCopying , NSCoding > {
79+ @protected
80+ NSString *_title;
81+ @private
82+ #if !__has_feature(nullability)
83+ NSMenu *_supermenu;
84+ #if defined(__RAVYNOS__)
85+ NSString *_name;
86+ #endif /* !defined(__RAVYNOS__) */
87+ NSMutableArray *_itemArray;
88+ #if !__has_feature(objc_protocol_qualifier_mangling)
89+ id _delegate;
90+ #else
91+ id <NSMenuDelegate > _delegate;
92+ #endif
93+ #else /* __has_feature(nullability) */
94+ NSMenu * __nullable _supermenu;
95+ #if defined(__RAVYNOS__)
96+ NSString * __null_unspecified _name; // but can be empty string
97+ #endif /* !defined(__RAVYNOS__) */
98+ NSMutableArray * __null_unspecified _itemArray; // but can be empty array
99+ #if !__has_feature(objc_protocol_qualifier_mangling)
100+ id __nullable _delegate;
101+ #else
102+ id <NSMenuDelegate > __nullable _delegate;
103+ #endif
104+ #endif /* end !__has_feature(nullability) */
105+ #if defined(DBusInstanceID)
106+ DBusInstanceID _DBusItemID;
107+ #else
108+ uint64_t DBusInstanceID;
109+ #endif
110+ BOOL _autoenablesItems;
23111}
24112
113+ // TODO: implement class load to setup globals like menubar height and appearance, and legacy implementation of legacy menuZone api etc.
114+
25115+ (void )popUpContextMenu : (NSMenu *)menu withEvent : (NSEvent *)event forView : (NSView *)view ;
26116
27- - initWithTitle : (NSString *)title ;
117+ // / Designated initializer
118+ // /
119+ // / - Parameters:
120+ // / - title: The menu title `NSString`.
121+ // / Title should already be localized before being passed.
122+ // / If passed a nil title the title will be set to the zero-length string "".
123+ // /
124+ // / - Returns: The empty `NSMenu` with the given title.
125+ - (id )initWithTitle : (NSString *)title OBJC_DESIGNATED_INITIALIZER;
28126
127+ #if !__has_feature(nullability)
128+ #if __has_feature(objc_arc)
129+ @property (weak ) NSMenu *supermenu;
130+ @property (copy ) NSString *title;
131+ #else
132+ @property (assign ) NSMenu *supermenu;
133+ @property (retain ) NSString *title;
134+ #endif
29135- (NSMenu *)supermenu ;
30136- (NSString *)title ;
137+ #else
138+ #if __has_feature(objc_arc)
139+ @property (nullable , weak ) NSMenu *supermenu;
140+ @property (copy ) NSString *title;
141+ #else
142+ @property (nullable , assign ) NSMenu *supermenu;
143+ @property (nullable , retain ) NSString *title;
144+ #endif
145+ - (NSMenu * __nullable)supermenu ;
146+ - (NSString * __nullable)title ;
147+ #endif
31148- (int )numberOfItems ;
149+
150+ #if !__has_feature(nullability)
151+ #if __has_feature(objc_arc)
152+ @property (copy ) NSArray *itemArray;
153+ #else
154+ @property (retain ) NSArray *itemArray;
155+ #endif
32156- (NSArray *)itemArray ;
157+ - (void )setItemArray : (NSMutableArray *)newItemArray ;
158+ #else
159+ #if __has_feature(objc_arc)
160+ @property (copy ) __kindof NSArray *itemArray;
161+ #else
162+ @property (retain ) __kindof NSArray *itemArray;
163+ #endif
164+ - (NSArray * __nonnull)itemArray ;
165+ - (void )setItemArray : (__kindof NSArray * __nonnull)newItemArray ;
166+ #endif
33167- (BOOL )autoenablesItems ;
168+ #if defined(CGFLOAT_DEFINED) && CGFLOAT_DEFINED
169+ - (CGFloat)menuBarHeight ;
170+ #endif
34171
172+ #if !__has_feature(nullability)
35173- (NSMenuItem *)itemAtIndex : (int )index ;
36174- (NSMenuItem *)itemWithTag : (int )tag ;
37175- (NSMenuItem *)itemWithTitle : (NSString *)title ;
176+ #else
177+ - (NSMenuItem * __nullable)itemAtIndex : (int )index ;
178+ - (NSMenuItem * __nullable)itemWithTag : (int )tag ;
179+ - (NSMenuItem * __nullable)itemWithTitle : (NSString * __nullable)title ;
180+ #endif
38181
182+ #if defined(NSINTEGER_DEFINED) && NSINTEGER_DEFINED
183+ #warning "NSInteger is defined but NSMenu implements with int (incompatibility)"
184+ // /FIXME: developers expect this to use NSInteger (typically defined as a long, not an int)
185+ #endif
186+
187+ #if !__has_feature(nullability)
39188- (int )indexOfItem : (NSMenuItem *)item ;
189+ #else
190+ - (int )indexOfItem : (NSMenuItem * __nullable)item ;
191+ #endif
40192- (int )indexOfItemWithTag : (int )tag ;
193+ #if !__has_feature(nullability)
41194- (int )indexOfItemWithTitle : (NSString *)title ;
42- - (int )indexOfItemWithRepresentedObject :object;
195+ - (int )indexOfItemWithRepresentedObject : ( id ) object ;
43196- (int )indexOfItemWithTarget : (id )target andAction : (SEL )action ;
44197- (int )indexOfItemWithSubmenu : (NSMenu *)menu ;
198+ #else
199+ - (int )indexOfItemWithTitle : (NSString *__nullable)title ;
200+ - (int )indexOfItemWithRepresentedObject : (id __nullable)object ;
201+ - (int )indexOfItemWithTarget : (id __nullable)target andAction : (SEL __nullable)action ;
202+ - (int )indexOfItemWithSubmenu : (NSMenu * __nullable)menu ;
203+ #endif
45204
205+ #if !__has_feature(nullability)
46206- (void )setSupermenu : (NSMenu *)value ;
47207- (void )setTitle : (NSString *)title ;
208+ #else
209+ - (void )setSupermenu : (NSMenu * __nullable)value ;
210+ - (void )setTitle : (NSString * __nullable)title ;
211+ #endif
48212- (void )setAutoenablesItems : (BOOL )flag ;
49213
214+ #if !__has_feature(nullability)
50215- (void )addItem : (NSMenuItem *)item ;
51216- (NSMenuItem *)addItemWithTitle : (NSString *)title action : (SEL )action keyEquivalent : (NSString *)keyEquivalent ;
217+ #else
218+ - (void )addItem : (NSMenuItem *)item ;
219+ - (NSMenuItem *__null_unspecified)addItemWithTitle : (NSString * __null_unspecified)title action : (SEL __null_unspecified)action keyEquivalent : (NSString * __nullable)keyEquivalent ;
220+ #endif
52221
53- - (void )removeAllItems ; // private, don't use outside framework
222+ - (void )removeAllItems ; // TODO: add import guard for rayvnOS to ensure devs don't use outside framework (compatibility: MacOSX 10.5+ provides this but notes it should not be used outside framework)
223+ #if !__has_feature(nullability)
54224- (void )removeItem : (NSMenuItem *)item ;
225+ #else
226+ - (void )removeItem : (NSMenuItem * __nullable)item ;
227+ #endif
55228- (void )removeItemAtIndex : (int )index ;
56229
230+ #if !__has_feature(nullability)
57231- (void )insertItem : (NSMenuItem *)item atIndex : (int )index ;
58232- (NSMenuItem *)insertItemWithTitle : (NSString *)title action : (SEL )action keyEquivalent : (NSString *)keyEquivalent atIndex : (int )index ;
59233
60234- (void )setSubmenu : (NSMenu *)submenu forItem : (NSMenuItem *)item ;
235+ #else
236+ - (void )insertItem : (NSMenuItem * __nullable)item atIndex : (int )index ;
237+ - (NSMenuItem *)insertItemWithTitle : (NSString * __null_unspecified)title action : (SEL __null_unspecified)action keyEquivalent : (NSString * __nullable)keyEquivalent atIndex : (int )index ;
238+
239+ - (void )setSubmenu : (NSMenu * __null_unspecified)submenu forItem : (NSMenuItem * __null_unspecified)item ;
240+ #endif
61241
62242- (void )update ;
63243
244+ #if !__has_feature(nullability)
64245- (void )itemChanged : (NSMenuItem *)item ;
246+ #else
247+ - (void )itemChanged : (NSMenuItem * __nullable)item ;
248+ #endif
65249
66250- (BOOL )performKeyEquivalent : (NSEvent *)event ;
67251
252+ #if !__has_feature(objc_protocol_qualifier_mangling)
253+ #if !__has_feature(nullability)
254+ #if __has_feature(objc_arc)
255+ @property (weak ) id delegate;
256+ #else
257+ @property (assign ) id delegate;
258+ #endif /* !__has_feature(objc_arc) */
259+ - (void )setDelegate : (id )object ;
260+ - (id __nullable)delegate ;
261+ #else
262+ #if __has_feature(objc_arc)
263+ @property (nullable , weak ) id delegate;
264+ #else
265+ @property (nullable , assign ) id delegate;
266+ #endif /* !__has_feature(objc_arc) */
267+ - (void )setDelegate : (id __nullable)object ;
268+ - (id __nullable)delegate ;
269+ #endif /* end __has_feature(nullability) */
270+ #else
271+ #if !__has_feature(nullability)
272+ #if __has_feature(objc_arc)
273+ @property (weak ) id <NSMenuDelegate > delegate;
274+ #else
275+ @property (assign ) id <NSMenuDelegate > delegate;
276+ #endif /* !__has_feature(objc_arc) */
68277- (void )setDelegate : (id <NSMenuDelegate >)object ;
69278- (id <NSMenuDelegate >)delegate ;
279+ #else
280+ #if __has_feature(objc_arc)
281+ @property (nullable , weak ) id <NSMenuDelegate > delegate;
282+ #else
283+ @property (nullable , assign ) id <NSMenuDelegate > delegate;
284+ #endif /* !__has_feature(objc_arc) */
285+ - (id <NSMenuDelegate > __nullable)delegate ;
286+ - (void )setDelegate : (id <NSMenuDelegate > __nullable)object ;
287+ #endif /* end __has_feature(nullability) */
288+ #endif /* end __has_feature(objc_protocol_qualifier_mangling) */
289+
290+ #if defined(__RAVYNOS__)
291+
292+ #if !__has_feature(nullability)
293+ #if __has_feature(objc_arc)
294+ @property (weak ) NSString *_name;
295+ #else
296+ @property (assign ) NSString *title;
297+ #endif
298+ - (NSString *)_name ;
299+ - (NSMenu *)_menuWithName : (NSString *)name ;
300+ #else
301+ #if __has_feature(objc_arc)
302+ @property (nullable , weak ) NSString *_name; // FIXME: should probably be implemented as copy
303+ #else
304+ @property (nullable , assign ) NSString *title;
305+ #endif
306+ - (NSString *__nullable)_name ;
307+ - (NSMenu *__nullable)_menuWithName : (NSString *__nullable)name ;
308+ #endif
70309
310+ #endif /* !defined(__RAVYNOS__) */
311+
312+ #if __has_feature(objc_categories)
313+ @end
314+
315+ @interface NSMenu (MenuHelpers)
316+ #endif
317+ #if defined(__RAVYNOS__)
318+ /*
319+ Circa 2025
320+ Modification provided by Mr. Walls under MIT
321+ */
322+
323+ #if !__has_feature(nullability)
324+ +(NSMenu *)newMenuAsApplicationMenu : (NSString *)appName ;
325+ #else
326+ +(NSMenu * __nonnull)newMenuAsApplicationMenu : (NSString *)appName ;
327+ #endif /* end __has_feature(nullability) */
328+
329+ #endif /* !defined(__RAVYNOS__) */
71330@end
72331
73332@interface NSObject (NSMenu_validateItem)
74333- (BOOL )validateMenuItem : (NSMenuItem *)item ;
75334@end
76335
336+ #if !defined(NSScreen)
337+ #if defined(__RAVYNOS__)
338+ #warning "NSMenu does not support NSScreen in this implementation"
339+ #endif
340+ @class NSScreen ;
341+ #endif
342+
77343@protocol NSMenuDelegate <NSObject >
78344
79345@optional
0 commit comments